absence_thelab

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/3deng/3dgeom.h	Thu Oct 23 01:46:07 2014 +0300
     1.3 @@ -0,0 +1,112 @@
     1.4 +#ifndef _3DGEOM_H_
     1.5 +#define _3DGEOM_H_
     1.6 +
     1.7 +#include <vector>
     1.8 +#include "n3dmath.h"
     1.9 +#include "3dengtypes.h"
    1.10 +#include "switches.h"
    1.11 +
    1.12 +struct TexCoord {
    1.13 +	float u, v;
    1.14 +
    1.15 +	TexCoord(float u = 0.0f, float v = 0.0f);
    1.16 +};
    1.17 +
    1.18 +class Triangle;	// fwd declaration
    1.19 +
    1.20 +class Vertex {
    1.21 +public:
    1.22 +	Vector3 pos;
    1.23 +	float BlendFactor;
    1.24 +	dword BlendIndex;
    1.25 +	Vector3 normal;
    1.26 +	dword color;
    1.27 +	TexCoord tex[4];
    1.28 +
    1.29 +	Vertex();
    1.30 +	Vertex(const Vector3 &position, float tu = 0.0f, float tv = 0.0f, dword color = 0x00ffffff);
    1.31 +
    1.32 +	void CalculateNormal(const Vertex *vbuffer, const Triangle *triangles, long trinum);
    1.33 +};
    1.34 +
    1.35 +
    1.36 +class Edge {
    1.37 +public:
    1.38 +	Index vertices[2];
    1.39 +	Index adjfaces[2];
    1.40 +
    1.41 +	Edge();
    1.42 +	Edge(Index v1, Index v2, Index af1 = 0, Index af2 = 0);
    1.43 +};
    1.44 +
    1.45 +
    1.46 +class Triangle {
    1.47 +public:
    1.48 +	Index vertices[3];
    1.49 +	Vector3 normal;
    1.50 +	dword SmoothingGroup;
    1.51 +
    1.52 +	Triangle(Index v1 = 0, Index v2 = 0, Index v3 = 0);
    1.53 +
    1.54 +	void CalculateNormal(Vertex *vbuffer, bool normalize=0);
    1.55 +};
    1.56 +
    1.57 +
    1.58 +enum TriMeshMode {TriMeshDynamic, TriMeshStatic};
    1.59 +
    1.60 +class GraphicsContext;
    1.61 +
    1.62 +class TriMesh {
    1.63 +private:
    1.64 +	GraphicsContext *gc;
    1.65 +
    1.66 +	// LOD arrays of vertex and triangle arrays for the mesh
    1.67 +	Vertex **varray;
    1.68 +	Triangle **triarray;
    1.69 +	// system managed copy of the data (probably on the video ram or something)
    1.70 +	VertexBuffer **vbuffer;
    1.71 +	IndexBuffer **ibuffer;
    1.72 +
    1.73 +	std::vector<dword> **AdjTriangles;
    1.74 +	bool *AdjValid;
    1.75 +	
    1.76 +	dword *VertexCount, *TriCount;
    1.77 +	byte Levels;
    1.78 +
    1.79 +	bool *BuffersValid;
    1.80 +	bool dynamic;
    1.81 +
    1.82 +	// synchronizes the system managed copy of vertices/indices with the local data
    1.83 +	bool UpdateSystemBuffers(byte level);
    1.84 +	void UpdateLODChain();
    1.85 +
    1.86 +public:
    1.87 +	TriMesh(byte LODLevels, GraphicsContext *gc = 0);
    1.88 +	TriMesh(const TriMesh &mesh);
    1.89 +	~TriMesh();
    1.90 +
    1.91 +	const TriMesh &operator =(const TriMesh &mesh);
    1.92 +
    1.93 +	const Vertex *GetVertexArray(byte level = 0) const;
    1.94 +	const Triangle *GetTriangleArray(byte level = 0) const;
    1.95 +	
    1.96 +	Vertex *GetModVertexArray();
    1.97 +	Triangle *GetModTriangleArray();
    1.98 +
    1.99 +	const VertexBuffer *GetVertexBuffer(byte level = 0) const;
   1.100 +	const IndexBuffer *GetIndexBuffer(byte level = 0) const;
   1.101 +
   1.102 +	dword GetVertexCount(byte level = 0) const;
   1.103 +	dword GetTriangleCount(byte level = 0) const;
   1.104 +	byte GetLevelCount() const;
   1.105 +
   1.106 +	void ChangeMode(TriMeshMode mode);
   1.107 +	void SetGraphicsContext(GraphicsContext *gc);
   1.108 +	void SetData(const Vertex *vdata, const Triangle *tridata, dword vcount, dword tricount);
   1.109 +
   1.110 +	void CalculateNormals();
   1.111 +	void CalculateNormalsFast();
   1.112 +	//void CalculateEdges();
   1.113 +};
   1.114 +
   1.115 +#endif	// _3DGEOM_H_
   1.116 \ No newline at end of file