-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mesh.h
157 lines (136 loc) · 4.39 KB
/
Mesh.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// @Begin License@
// This file is part of Coldest.
//
// Coldest is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Coldest is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Coldest. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright 2008-2012 Ben Nemec
// @End License@
#ifndef MESH_H
#define MESH_H
#include "MeshData.h"
#include "NTreeReader.h"
#include "Timer.h"
#include "types.h"
#include "ResourceManager.h"
#include "MeshNode.h"
#include "Triangle.h"
#include "Quad.h"
#include "VBO.h"
#include "FBO.h"
#include <SDL/SDL.h>
using std::list;
using std::map;
class Mesh
{
friend class MeshCache; // So the cache can reset internal timers
public:
Mesh(NTreeReader, ResourceManager&);
void Move(const Vector3&, const bool movetris = false);
void Rotate(const Vector3&, const bool movetris = false);
void Scale(const float&);
void ScaleZ(const float&);
const Vector3 GetPosition() const {return position;}
const Vector3 GetRotation() const {return rotation;}
string GetFile() const {return basefile;}
float GetAnimSpeed() const {return animspeed;}
float GetScale() const {return scale;}
string CurrentSound() {string retval = currentsound; currentsound = ""; return retval;}
void Render(Material* overridemat = NULL);
void SetAnimation(const int);
void Update(const Vector3& campos = Vector3(), bool noanimation = false);
void RenderImpostor(Mesh&, FBO&, const Vector3&);
void Add(Triangle&);
void Add(TrianglePtr);
void AddVertices(Triangle&);
void Add(Quad&);
void AddNoCopy(Quad&);
void Add(Mesh&);
void Clear(const bool cleartris = true);
void GenTangents();
void EnsureMaterials();
void Begin() {next = 0;}
bool HasNext() const {return next < NumTris();}
Triangle& Next() {++next; return meshdata.Tri(next - 1);}
size_t NumTris() const {return meshdata.NumTris();}
float GetHeight() {return height;}
float GetWidth() {return width;}
float GetSize() {return size;}
void SetState(const Vector3&, const Vector3&, const int, const int, const float);
void ReadState(Vector3&, Vector3&, int&, int&, float&, float&);
void SetAnimSpeed(const float);
void debug();
bool render;
bool dynamic;
bool collide;
bool terrain;
bool reverseanim;
bool occluder;
string name;
float dist;
float impdist;
Timer ImpTimer;
size_t impostorfbo;
unsigned int updatedelay;
float drawdistmult;
private:
void Load(const NTreeReader&);
void CalcBounds();
void ResetTriMaxDims();
void AdvanceAnimation();
int NextKeyFrame();
void UpdateTris(const Vector3& campos = Vector3(.003, .004, .005)); // Why these numbers? I suspect it was for debugging...
void GenVbo();
void GenVboData();
void GenIboData();
void BindAttribs();
void UnbindAttribs();
// Primary Mesh data
MeshData meshdata;
intvec vbosteps;
vector<void*> offsets;
intvec minindex, maxindex;
vector<Material*> materials;
vector<string> framesound;
#ifndef DEDICATED
VBO vbo;
#endif
// Mesh state
intvec frametime;
Vector3 position;
Vector3 rotation;
size_t next;
float size, height, width;
float scale;
string basefile;
// Flags
bool trismoved;
bool trischanged;
bool boundschanged;
bool updatevbo;
// Animation data
Timer animtimer;
int animtime;
int currkeyframe;
float animspeed;
int curranimation, nextanimation;
intvec numframes;
intvec startframe;
string currentsound;
};
typedef list<Mesh> Meshlist;
typedef map<int, MeshNodePtr> MeshNodeMap;
typedef shared_ptr<Mesh> MeshPtr;
// *** If you change this, do not forget to update objconvert! ***
const string objectfilever = "Version5";
#endif // MESH_H