-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawModelUnit.cpp
More file actions
64 lines (51 loc) · 1.67 KB
/
Copy pathDrawModelUnit.cpp
File metadata and controls
64 lines (51 loc) · 1.67 KB
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
#include "DrawModelUnit.hpp"
#include "OrthoUnit.hpp"
#include "TextureUnit.hpp"
#include <GL/gl.h>
void ApplyTrans(const TTransformation& tran) {
glTranslatef(tran.pos.x, tran.pos.y, tran.pos.z);
glRotatef(tran.rot.x, 1, 0, 0);
glRotatef(tran.rot.y, 0, 1, 0);
glRotatef(tran.rot.z, 0, 0, 1);
glScalef(tran.sca.x, tran.sca.y, tran.sca.z);
}
void ToggleFaceMode() {
GLint frontFace;
glGetIntegerv(GL_FRONT_FACE, &frontFace);
if (frontFace == GL_CCW) glFrontFace(GL_CW);
else glFrontFace(GL_CCW);
}
void RenderTreeNode(const TModelTreeNode* node) {
if (!node) return;
glPushMatrix();
ApplyTrans(node->transf);
// Check for negative scaling which flips faces
bool toggle = node->transf.mustToggleFaces();
if (toggle) ToggleFaceMode();
if (node->texture == nullptr) {
glDisable(GL_TEXTURE_2D);
} else {
glEnable(GL_TEXTURE_2D);
node->texture->bind();
}
glColor3f(node->color.r, node->color.g, node->color.b);
if (node->graphicalElement.type == geMesh) {
if (node->graphicalElement.mesh) {
node->graphicalElement.mesh->Render();
}
} else if (node->graphicalElement.type == geModel) {
if (node->graphicalElement.model && node->graphicalElement.model->root) {
RenderTreeNode(node->graphicalElement.model->root.get());
}
}
for (const auto& child : node->children) {
RenderTreeNode(child.get());
}
if (toggle) ToggleFaceMode();
glPopMatrix();
}
void DrawRealTimeModel(TRealTimeModel* animator) {
if (animator && animator->getActualPose()) {
RenderTreeNode(animator->getActualPose());
}
}