1 | #include "Visualization.h"
|
---|
2 | #include "glInterface.h"
|
---|
3 | #include "Camera.h"
|
---|
4 | #include "SceneEntity.h"
|
---|
5 | #include "Bvh.h"
|
---|
6 | #include <stack>
|
---|
7 |
|
---|
8 |
|
---|
9 | using namespace std;
|
---|
10 |
|
---|
11 |
|
---|
12 | namespace CHCDemo
|
---|
13 | {
|
---|
14 |
|
---|
15 | /******************************************************/
|
---|
16 | /* Vizualization implementation */
|
---|
17 | /******************************************************/
|
---|
18 |
|
---|
19 |
|
---|
20 | Visualization::Visualization(Bvh *bvh,
|
---|
21 | Camera *camera,
|
---|
22 | Camera *vizCamera,
|
---|
23 | RenderState *renderState):
|
---|
24 | mBvh(bvh), mCamera(camera), mVizCamera(vizCamera), mRenderState(renderState)
|
---|
25 | {
|
---|
26 | }
|
---|
27 |
|
---|
28 |
|
---|
29 | void Visualization::SetHierarchy(Bvh *bvh)
|
---|
30 | {
|
---|
31 | mBvh = bvh;
|
---|
32 | }
|
---|
33 |
|
---|
34 |
|
---|
35 | void Visualization::SetRenderState(RenderState *state)
|
---|
36 | {
|
---|
37 | mRenderState = state;
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | void Visualization::Render()
|
---|
42 | {
|
---|
43 | stack<BvhNode *> tStack;
|
---|
44 | tStack.push(mBvh->GetRoot());
|
---|
45 |
|
---|
46 | while (!tStack.empty())
|
---|
47 | {
|
---|
48 | BvhNode *node = tStack.top();
|
---|
49 | tStack.pop();
|
---|
50 |
|
---|
51 | if (!node->IsLeaf())
|
---|
52 | {
|
---|
53 | BvhInterior *interior = static_cast<BvhInterior *>(node);
|
---|
54 |
|
---|
55 | tStack.push(interior->GetFront());
|
---|
56 | tStack.push(interior->GetBack());
|
---|
57 | }
|
---|
58 | else
|
---|
59 | {
|
---|
60 | //leaves.push_back(static_cast<BvhLeaf *>(node));
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | void Visualization::RenderBox(const AxisAlignedBox3 &box)
|
---|
67 | {
|
---|
68 | glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
---|
69 | glDisable(GL_CULL_FACE);
|
---|
70 | glColor3f(1.0f, 0.0f, 0.0f);
|
---|
71 |
|
---|
72 | glBegin(GL_QUADS);
|
---|
73 | glVertex3f(box.Min().x, box.Max().y, box.Min().z);
|
---|
74 | glVertex3f(box.Max().x, box.Max().y, box.Min().z);
|
---|
75 | glVertex3f(box.Max().x, box.Min().y, box.Min().z);
|
---|
76 | glVertex3f(box.Min().x, box.Min().y, box.Min().z);
|
---|
77 | glEnd();
|
---|
78 |
|
---|
79 | glBegin(GL_QUADS);
|
---|
80 | glVertex3f(box.Min().x, box.Min().y, box.Max().z);
|
---|
81 | glVertex3f(box.Max().x, box.Min().y, box.Max().z);
|
---|
82 | glVertex3f(box.Max().x, box.Max().y, box.Max().z);
|
---|
83 | glVertex3f(box.Min().x, box.Max().y, box.Max().z);
|
---|
84 | glEnd();
|
---|
85 |
|
---|
86 | glBegin(GL_QUADS);
|
---|
87 | glVertex3f(box.Max().x, box.Min().y, box.Min().z);
|
---|
88 | glVertex3f(box.Max().x, box.Min().y, box.Max().z);
|
---|
89 | glVertex3f(box.Max().x, box.Max().y, box.Max().z);
|
---|
90 | glVertex3f(box.Max().x, box.Max().y, box.Min().z);
|
---|
91 | glEnd();
|
---|
92 |
|
---|
93 | glBegin(GL_QUADS);
|
---|
94 | glVertex3f(box.Min().x, box.Min().y, box.Min().z);
|
---|
95 | glVertex3f(box.Min().x, box.Min().y, box.Max().z);
|
---|
96 | glVertex3f(box.Min().x, box.Max().y, box.Max().z);
|
---|
97 | glVertex3f(box.Min().x, box.Max().y, box.Min().z);
|
---|
98 | glEnd();
|
---|
99 |
|
---|
100 | glBegin(GL_QUADS);
|
---|
101 | glVertex3f(box.Min().x, box.Min().y, box.Min().z);
|
---|
102 | glVertex3f(box.Max().x, box.Min().y, box.Min().z);
|
---|
103 | glVertex3f(box.Max().x, box.Min().y, box.Max().z);
|
---|
104 | glVertex3f(box.Min().x, box.Min().y, box.Max().z);
|
---|
105 | glEnd();
|
---|
106 |
|
---|
107 | glBegin(GL_QUADS);
|
---|
108 | glVertex3f(box.Min().x, box.Max().y, box.Min().z);
|
---|
109 | glVertex3f(box.Max().x, box.Max().y, box.Min().z);
|
---|
110 | glVertex3f(box.Max().x, box.Max().y, box.Max().z);
|
---|
111 | glVertex3f(box.Min().x, box.Max().y, box.Max().z);
|
---|
112 | glEnd();
|
---|
113 |
|
---|
114 | glEnable(GL_CULL_FACE);
|
---|
115 |
|
---|
116 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | void Visualization::RenderFrustum()
|
---|
121 | {
|
---|
122 | Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr;
|
---|
123 | mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr);
|
---|
124 |
|
---|
125 | glLineWidth(2);
|
---|
126 |
|
---|
127 | glBegin(GL_LINE_LOOP);
|
---|
128 | glVertex3d(fbl.x, fbl.y, fbl.z);
|
---|
129 | glVertex3d(fbr.x, fbr.y, fbr.z);
|
---|
130 | glVertex3d(ftr.x, ftr.y, ftr.z);
|
---|
131 | glVertex3d(ftl.x, ftl.y, ftl.z);
|
---|
132 | glEnd();
|
---|
133 |
|
---|
134 | glBegin(GL_LINE_LOOP);
|
---|
135 | glVertex3d(nbl.x, nbl.y, nbl.z);
|
---|
136 | glVertex3d(nbr.x, nbr.y, nbr.z);
|
---|
137 | glVertex3d(ntr.x, ntr.y, ntr.z);
|
---|
138 | glVertex3d(ntl.x, ntl.y, ntl.z);
|
---|
139 | glEnd();
|
---|
140 |
|
---|
141 | glBegin(GL_LINE_LOOP);
|
---|
142 | glVertex3d(fbl.x, fbl.y, fbl.z);
|
---|
143 | glVertex3d(ftl.x, ftl.y, ftl.z);
|
---|
144 | glVertex3d(ntl.x, ntl.y, ntl.z);
|
---|
145 | glVertex3d(nbl.x, nbl.y, nbl.z);
|
---|
146 | glEnd();
|
---|
147 |
|
---|
148 | glBegin(GL_LINE_LOOP);
|
---|
149 | glVertex3d(fbr.x, fbr.y, fbr.z);
|
---|
150 | glVertex3d(ftr.x, ftr.y, ftr.z);
|
---|
151 | glVertex3d(ntr.x, ntr.y, ntr.z);
|
---|
152 | glVertex3d(nbr.x, nbr.y, nbr.z);
|
---|
153 | glEnd();
|
---|
154 |
|
---|
155 | glBegin(GL_LINE_LOOP);
|
---|
156 | glVertex3d(fbr.x, fbr.y, fbr.z);
|
---|
157 | glVertex3d(fbl.x, fbl.y, fbl.z);
|
---|
158 | glVertex3d(nbl.x, nbl.y, nbl.z);
|
---|
159 | glVertex3d(nbr.x, nbr.y, nbr.z);
|
---|
160 | glEnd();
|
---|
161 |
|
---|
162 | glBegin(GL_LINE_LOOP);
|
---|
163 | glVertex3d(ftr.x, ftr.y, ftr.z);
|
---|
164 | glVertex3d(ftl.x, ftl.y, ftl.z);
|
---|
165 | glVertex3d(ntl.x, ntl.y, ntl.z);
|
---|
166 | glVertex3d(ntr.x, ntr.y, ntr.z);
|
---|
167 | glEnd();
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | } |
---|