absence_thelab

view src/3deng/3dgeom.h @ 0:1cffe3409164

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Oct 2014 01:46:07 +0300
parents
children
line source
1 #ifndef _3DGEOM_H_
2 #define _3DGEOM_H_
4 #include <vector>
5 #include "n3dmath.h"
6 #include "3dengtypes.h"
7 #include "switches.h"
9 struct TexCoord {
10 float u, v;
12 TexCoord(float u = 0.0f, float v = 0.0f);
13 };
15 class Triangle; // fwd declaration
17 class Vertex {
18 public:
19 Vector3 pos;
20 float BlendFactor;
21 dword BlendIndex;
22 Vector3 normal;
23 dword color;
24 TexCoord tex[4];
26 Vertex();
27 Vertex(const Vector3 &position, float tu = 0.0f, float tv = 0.0f, dword color = 0x00ffffff);
29 void CalculateNormal(const Vertex *vbuffer, const Triangle *triangles, long trinum);
30 };
33 class Edge {
34 public:
35 Index vertices[2];
36 Index adjfaces[2];
38 Edge();
39 Edge(Index v1, Index v2, Index af1 = 0, Index af2 = 0);
40 };
43 class Triangle {
44 public:
45 Index vertices[3];
46 Vector3 normal;
47 dword SmoothingGroup;
49 Triangle(Index v1 = 0, Index v2 = 0, Index v3 = 0);
51 void CalculateNormal(Vertex *vbuffer, bool normalize=0);
52 };
55 enum TriMeshMode {TriMeshDynamic, TriMeshStatic};
57 class GraphicsContext;
59 class TriMesh {
60 private:
61 GraphicsContext *gc;
63 // LOD arrays of vertex and triangle arrays for the mesh
64 Vertex **varray;
65 Triangle **triarray;
66 // system managed copy of the data (probably on the video ram or something)
67 VertexBuffer **vbuffer;
68 IndexBuffer **ibuffer;
70 std::vector<dword> **AdjTriangles;
71 bool *AdjValid;
73 dword *VertexCount, *TriCount;
74 byte Levels;
76 bool *BuffersValid;
77 bool dynamic;
79 // synchronizes the system managed copy of vertices/indices with the local data
80 bool UpdateSystemBuffers(byte level);
81 void UpdateLODChain();
83 public:
84 TriMesh(byte LODLevels, GraphicsContext *gc = 0);
85 TriMesh(const TriMesh &mesh);
86 ~TriMesh();
88 const TriMesh &operator =(const TriMesh &mesh);
90 const Vertex *GetVertexArray(byte level = 0) const;
91 const Triangle *GetTriangleArray(byte level = 0) const;
93 Vertex *GetModVertexArray();
94 Triangle *GetModTriangleArray();
96 const VertexBuffer *GetVertexBuffer(byte level = 0) const;
97 const IndexBuffer *GetIndexBuffer(byte level = 0) const;
99 dword GetVertexCount(byte level = 0) const;
100 dword GetTriangleCount(byte level = 0) const;
101 byte GetLevelCount() const;
103 void ChangeMode(TriMeshMode mode);
104 void SetGraphicsContext(GraphicsContext *gc);
105 void SetData(const Vertex *vdata, const Triangle *tridata, dword vcount, dword tricount);
107 void CalculateNormals();
108 void CalculateNormalsFast();
109 //void CalculateEdges();
110 };
112 #endif // _3DGEOM_H_