2016-03-21 04:10:14 +00:00
|
|
|
#ifndef _MODEL_H_
|
|
|
|
#define _MODEL_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2017-09-30 19:05:04 +00:00
|
|
|
#include <string.h>
|
2016-03-21 04:10:14 +00:00
|
|
|
#include "Texture.h"
|
|
|
|
#include "Mat4.h"
|
|
|
|
|
|
|
|
namespace New3D {
|
|
|
|
|
2017-02-07 14:05:03 +00:00
|
|
|
struct ClipVertex
|
|
|
|
{
|
2017-08-19 20:06:31 +00:00
|
|
|
float pos[4];
|
2017-02-07 14:05:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ClipPoly
|
|
|
|
{
|
|
|
|
ClipVertex list[12]; // what's the max number we can hit for a triangle + 4 planes?
|
|
|
|
int count = 0;
|
|
|
|
};
|
|
|
|
|
2017-08-30 21:45:25 +00:00
|
|
|
struct Vertex // half vertex
|
2016-03-21 04:10:14 +00:00
|
|
|
{
|
2017-08-19 20:06:31 +00:00
|
|
|
float pos[4];
|
2016-03-21 04:10:14 +00:00
|
|
|
float normal[3];
|
|
|
|
float texcoords[2];
|
2017-08-19 20:06:31 +00:00
|
|
|
float fixedShade;
|
2016-03-21 04:10:14 +00:00
|
|
|
};
|
|
|
|
|
2017-08-30 21:45:25 +00:00
|
|
|
struct FVertex : Vertex // full vertex including face attributes
|
2016-03-21 04:10:14 +00:00
|
|
|
{
|
2017-08-30 21:45:25 +00:00
|
|
|
float faceNormal[3];
|
|
|
|
UINT8 faceColour[4];
|
|
|
|
|
|
|
|
FVertex& operator=(const Vertex& vertex)
|
|
|
|
{
|
|
|
|
memcpy(this, &vertex, sizeof(Vertex));
|
|
|
|
return *this;
|
|
|
|
}
|
2016-03-21 04:10:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct R3DPoly
|
|
|
|
{
|
|
|
|
Vertex v[4]; // just easier to have them as an array
|
|
|
|
float faceNormal[3]; // we need this to help work out poly winding, i assume the h/w uses this instead of calculating normals itself
|
2017-08-14 09:14:06 +00:00
|
|
|
UINT8 faceColour[4]; // per face colour
|
2016-03-21 04:10:14 +00:00
|
|
|
int number = 4;
|
|
|
|
};
|
|
|
|
|
2017-08-30 21:45:25 +00:00
|
|
|
struct Poly // our polys are always 3 triangles, unlike the real h/w
|
|
|
|
{
|
|
|
|
Poly() {}; // default
|
|
|
|
|
|
|
|
Poly(bool firstTriangle, const R3DPoly& r3dPoly) {
|
|
|
|
|
|
|
|
if (firstTriangle) {
|
|
|
|
p1 = r3dPoly.v[0];
|
|
|
|
p2 = r3dPoly.v[1];
|
|
|
|
p3 = r3dPoly.v[2];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p1 = r3dPoly.v[0];
|
|
|
|
p2 = r3dPoly.v[2];
|
|
|
|
p3 = r3dPoly.v[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy face attributes
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
p1.faceColour[i] = r3dPoly.faceColour[i];
|
|
|
|
p2.faceColour[i] = r3dPoly.faceColour[i];
|
|
|
|
p3.faceColour[i] = r3dPoly.faceColour[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
p1.faceNormal[i] = r3dPoly.faceNormal[i];
|
|
|
|
p2.faceNormal[i] = r3dPoly.faceNormal[i];
|
|
|
|
p3.faceNormal[i] = r3dPoly.faceNormal[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FVertex p1;
|
|
|
|
FVertex p2;
|
|
|
|
FVertex p3;
|
|
|
|
};
|
|
|
|
|
2016-03-21 04:10:14 +00:00
|
|
|
struct Mesh
|
|
|
|
{
|
2017-02-20 17:22:32 +00:00
|
|
|
//helper funcs
|
|
|
|
bool Render(bool alpha)
|
|
|
|
{
|
|
|
|
if (alpha) {
|
|
|
|
if (!textureAlpha && !polyAlpha) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-05-02 20:10:02 +00:00
|
|
|
if (polyAlpha) {
|
2017-02-20 17:22:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-26 22:44:26 +00:00
|
|
|
// texture
|
|
|
|
int format, x, y, width, height = 0;
|
|
|
|
bool mirrorU = false;
|
|
|
|
bool mirrorV = false;
|
2017-04-05 17:57:38 +00:00
|
|
|
bool inverted = false;
|
2016-03-21 04:10:14 +00:00
|
|
|
|
2016-12-09 14:13:46 +00:00
|
|
|
// microtexture
|
|
|
|
bool microTexture = false;
|
|
|
|
int microTextureID = 0;
|
|
|
|
float microTextureScale = 0;
|
|
|
|
|
2016-03-21 04:10:14 +00:00
|
|
|
// attributes
|
|
|
|
bool doubleSided = false;
|
|
|
|
bool textured = false;
|
|
|
|
bool polyAlpha = false; // specified in the rgba colour
|
|
|
|
bool textureAlpha = false; // use alpha in texture
|
|
|
|
bool alphaTest = false; // discard fragment based on alpha (ogl does this with fixed function)
|
|
|
|
bool clockWise = true; // we need to check if the matrix will change the winding
|
2016-05-27 19:30:40 +00:00
|
|
|
bool layered = false; // stencil poly
|
2017-02-20 17:22:32 +00:00
|
|
|
bool highPriority = false; // rendered over the top
|
2016-03-21 04:10:14 +00:00
|
|
|
|
2016-05-15 16:24:49 +00:00
|
|
|
// lighting
|
2017-08-14 09:14:06 +00:00
|
|
|
bool fixedShading = false;
|
2016-05-15 16:24:49 +00:00
|
|
|
bool lighting = false;
|
|
|
|
bool specular = false;
|
|
|
|
float shininess = 0;
|
2017-08-09 16:56:56 +00:00
|
|
|
float specularValue = 0;
|
2016-05-15 16:24:49 +00:00
|
|
|
|
|
|
|
// fog
|
2016-03-21 04:10:14 +00:00
|
|
|
float fogIntensity = 1.0f;
|
|
|
|
|
|
|
|
// opengl resources
|
|
|
|
int vboOffset = 0; // this will be calculated later
|
|
|
|
int triangleCount = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SortingMesh : public Mesh // This struct temporarily holds the model data, before it gets copied to the main buffer
|
|
|
|
{
|
|
|
|
std::vector<Poly> polys;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Model
|
|
|
|
{
|
2016-03-26 22:44:26 +00:00
|
|
|
std::shared_ptr<std::vector<Mesh>> meshes; // this reason why this is a shared ptr to an array, is that multiple models might use the same meshes
|
|
|
|
|
|
|
|
//which memory are we in
|
|
|
|
bool dynamic = true;
|
|
|
|
|
|
|
|
// texture offsets for model
|
|
|
|
int textureOffsetX = 0;
|
|
|
|
int textureOffsetY = 0;
|
2016-05-30 13:25:00 +00:00
|
|
|
int page = 0;
|
2016-03-21 04:10:14 +00:00
|
|
|
|
|
|
|
//matrices
|
|
|
|
float modelMat[16];
|
2017-07-29 16:30:30 +00:00
|
|
|
|
|
|
|
//model scale step 1.5+
|
|
|
|
float scale = 1.0f;
|
2016-03-21 04:10:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Viewport
|
|
|
|
{
|
2017-02-07 14:05:03 +00:00
|
|
|
int vpX; // these are the original hardware values
|
|
|
|
int vpY;
|
|
|
|
int vpWidth;
|
|
|
|
int vpHeight;
|
|
|
|
float angle_left;
|
|
|
|
float angle_right;
|
|
|
|
float angle_top;
|
|
|
|
float angle_bottom;
|
|
|
|
|
|
|
|
Mat4 projectionMatrix; // projection matrix, we will calc this later when we have scene near/far vals
|
|
|
|
|
2016-03-21 04:10:14 +00:00
|
|
|
float lightingParams[6]; // lighting parameters (see RenderViewport() and vertex shader)
|
2017-08-03 10:41:18 +00:00
|
|
|
bool sunClamp; // unknown how this is set
|
|
|
|
bool intensityClamp; // unknown how this is set
|
2016-03-21 04:10:14 +00:00
|
|
|
float spotEllipse[4]; // spotlight ellipse (see RenderViewport())
|
|
|
|
float spotRange[2]; // Z range
|
|
|
|
float spotColor[3]; // color
|
2017-04-02 21:03:59 +00:00
|
|
|
float fogParams[7]; // fog parameters (...)
|
2016-10-08 15:41:16 +00:00
|
|
|
float scrollFog; // a transparency value that determines if fog is blended over the bottom 2D layer
|
2018-01-15 21:27:21 +00:00
|
|
|
int losPosX, losPosY; // line of sight position
|
2016-03-21 04:10:14 +00:00
|
|
|
int x, y; // viewport coordinates (scaled and in OpenGL format)
|
|
|
|
int width, height; // viewport dimensions (scaled for display surface size)
|
2017-05-06 16:47:31 +00:00
|
|
|
int priority; // priority
|
|
|
|
int select; // viewport select?
|
|
|
|
int number; // viewport number
|
|
|
|
float spotFogColor[3]; // spotlight color on fog
|
2017-04-02 21:03:59 +00:00
|
|
|
float scrollAtt;
|
2017-08-14 09:14:06 +00:00
|
|
|
|
|
|
|
int hardwareStep; // not really a viewport param but will do here
|
2016-03-21 04:10:14 +00:00
|
|
|
};
|
|
|
|
|
2017-02-05 15:36:05 +00:00
|
|
|
enum class Clip { INSIDE, OUTSIDE, INTERCEPT, NOT_SET };
|
2016-06-16 20:05:29 +00:00
|
|
|
|
2016-03-21 04:10:14 +00:00
|
|
|
class NodeAttributes
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
NodeAttributes();
|
|
|
|
|
|
|
|
bool Push();
|
|
|
|
bool Pop();
|
|
|
|
bool StackLimit();
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
int currentTexOffsetX;
|
|
|
|
int currentTexOffsetY;
|
2016-06-10 10:18:47 +00:00
|
|
|
int currentPage;
|
2016-06-16 20:05:29 +00:00
|
|
|
Clip currentClipStatus;
|
2017-07-29 16:30:30 +00:00
|
|
|
float currentModelScale;
|
2016-03-21 04:10:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
struct NodeAttribs
|
|
|
|
{
|
|
|
|
int texOffsetX;
|
|
|
|
int texOffsetY;
|
2016-05-30 13:25:00 +00:00
|
|
|
int page;
|
2016-06-16 20:05:29 +00:00
|
|
|
Clip clip;
|
2017-07-29 16:30:30 +00:00
|
|
|
float modelScale;
|
2016-03-21 04:10:14 +00:00
|
|
|
};
|
|
|
|
std::vector<NodeAttribs> m_vecAttribs;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Node
|
|
|
|
{
|
|
|
|
Viewport viewport;
|
|
|
|
std::vector<Model> models;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // New3D
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|