git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / client / tankgraph / RenderGeoms.cpp
blobd712ead0a0285934a1fc0a07c1361e1e73488e68
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <tankgraph/RenderGeoms.h>
22 #include <target/TargetSpace.h>
23 #include <target/TargetContainer.h>
24 #include <target/TargetLife.h>
25 #include <client/ScorchedClient.h>
26 #include <graph/OptionsDisplay.h>
27 #include <engine/ActionController.h>
28 #include <GLEXT/GLState.h>
30 RenderGeoms *RenderGeoms::instance()
32 static RenderGeoms instance;
33 return &instance;
36 RenderGeoms::RenderGeoms()
40 RenderGeoms::~RenderGeoms()
44 void RenderGeoms::draw(const unsigned state)
46 if (OptionsDisplay::instance()->getDrawCollisionGeoms())
48 drawCollisionGeoms();
49 drawCollisionBounds();
52 if (OptionsDisplay::instance()->getDrawCollisionSpace())
54 drawTargetSpace();
58 void RenderGeoms::drawTargetSpace()
60 ScorchedClient::instance()->getContext().getTargetSpace().draw();
63 void RenderGeoms::drawCollisionBounds()
65 GLState glState(GLState::TEXTURE_OFF);
67 glColor3f(0.0f, 0.0f, 1.0f);
68 std::map<unsigned int, Target *> &targets =
69 ScorchedClient::instance()->getTargetContainer().getTargets();
70 std::map<unsigned int, Target *>::iterator itor;
71 for (itor = targets.begin();
72 itor != targets.end();
73 itor++)
75 Target *target = (*itor).second;
76 if (!target->getAlive())
78 continue;
81 Vector position = target->getLife().getFloatPosition();
82 Vector size = target->getLife().getAabbSize().asVector();
83 position[2] += size[2] / 2.0f;
85 double wid = size[0] + 0.1f;
86 double hgt = size[1] + 0.1f;
87 double dep = size[2] + 0.1f;
89 glPushMatrix();
90 glTranslated(position[0], position[1], position[2]);
91 glBegin(GL_LINE_LOOP);
92 // Top
93 glNormal3d(0,1,0);
94 glVertex3d(-wid/2,hgt/2,dep/2);
95 glVertex3d(wid/2,hgt/2,dep/2);
96 glVertex3d(wid/2,hgt/2,-dep/2);
97 glVertex3d(-wid/2,hgt/2,-dep/2);
98 glEnd();
99 glBegin(GL_LINE_LOOP);
100 // Back
101 glNormal3d(0,0,1);
102 glVertex3d(-wid/2,hgt/2,dep/2);
103 glVertex3d(-wid/2,-hgt/2,dep/2);
104 glVertex3d(wid/2,-hgt/2,dep/2);
105 glVertex3d(wid/2,hgt/2,dep/2);
106 glEnd();
107 glBegin(GL_LINE_LOOP);
108 // Front
109 glNormal3d(0,0,-1);
110 glVertex3d(-wid/2,hgt/2,-dep/2);
111 glVertex3d(wid/2,hgt/2,-dep/2);
112 glVertex3d(wid/2,-hgt/2,-dep/2);
113 glVertex3d(-wid/2,-hgt/2,-dep/2);
114 glEnd();
115 glBegin(GL_LINE_LOOP);
116 // Left
117 glNormal3d(1,0,0);
118 glVertex3d(wid/2,hgt/2,-dep/2);
119 glVertex3d(wid/2,hgt/2,dep/2);
120 glVertex3d(wid/2,-hgt/2,dep/2);
121 glVertex3d(wid/2,-hgt/2,-dep/2);
122 glEnd();
123 glBegin(GL_LINE_LOOP);
124 // Right
125 glNormal3d(-1,0,0);
126 glVertex3d(-wid/2,hgt/2,dep/2);
127 glVertex3d(-wid/2,hgt/2,-dep/2);
128 glVertex3d(-wid/2,-hgt/2,-dep/2);
129 glVertex3d(-wid/2,-hgt/2,dep/2);
130 glEnd();
131 glBegin(GL_LINE_LOOP);
132 // Bottom
133 glNormal3d(0,-1,0);
134 glVertex3d(-wid/2,-hgt/2,dep/2);
135 glVertex3d(-wid/2,-hgt/2,-dep/2);
136 glVertex3d(wid/2,-hgt/2,-dep/2);
137 glVertex3d(wid/2,-hgt/2,dep/2);
138 glEnd();
139 glPopMatrix();
143 void RenderGeoms::drawCollisionGeoms()
145 GLState glState(GLState::TEXTURE_OFF);
147 glColor3f(1.0f, 1.0f, 1.0f);
148 std::map<unsigned int, Target *> &targets =
149 ScorchedClient::instance()->getTargetContainer().getTargets();
150 std::map<unsigned int, Target *>::iterator itor;
151 for (itor = targets.begin();
152 itor != targets.end();
153 itor++)
155 Target *target = (*itor).second;
156 if (!target->getAlive())
158 continue;
161 if (target->getLife().getBoundingSphere())
163 Vector position = target->getLife().getFloatPosition();
164 Vector &size = target->getLife().getSize().asVector();
165 position[2] += size[2] / 2.0f;
166 float radius = MAX(MAX(size[0], size[1]), size[2]) / 2.0f;
168 static GLUquadric *obj = 0;
169 if (!obj)
171 obj = gluNewQuadric();
172 gluQuadricDrawStyle(obj, GLU_LINE);
175 glPushMatrix();
176 glTranslated(position[0], position[1], position[2]);
177 gluSphere(obj, radius, 6, 6);
178 glPopMatrix();
180 else
182 Vector position = target->getLife().getFloatPosition();
183 Vector &size = target->getLife().getSize().asVector();
184 position[2] += size[2] / 2.0f;
186 double wid = size[0];
187 double hgt = size[1];
188 double dep = size[2];
190 static float rotMatrix[16];
191 target->getLife().getQuaternion().getOpenGLRotationMatrix(rotMatrix);
193 glPushMatrix();
194 glTranslated(position[0], position[1], position[2]);
195 glMultMatrixf(rotMatrix);
196 glBegin(GL_LINE_LOOP);
197 // Top
198 glNormal3d(0,1,0);
199 glVertex3d(-wid/2,hgt/2,dep/2);
200 glVertex3d(wid/2,hgt/2,dep/2);
201 glVertex3d(wid/2,hgt/2,-dep/2);
202 glVertex3d(-wid/2,hgt/2,-dep/2);
203 glEnd();
204 glBegin(GL_LINE_LOOP);
205 // Back
206 glNormal3d(0,0,1);
207 glVertex3d(-wid/2,hgt/2,dep/2);
208 glVertex3d(-wid/2,-hgt/2,dep/2);
209 glVertex3d(wid/2,-hgt/2,dep/2);
210 glVertex3d(wid/2,hgt/2,dep/2);
211 glEnd();
212 glBegin(GL_LINE_LOOP);
213 // Front
214 glNormal3d(0,0,-1);
215 glVertex3d(-wid/2,hgt/2,-dep/2);
216 glVertex3d(wid/2,hgt/2,-dep/2);
217 glVertex3d(wid/2,-hgt/2,-dep/2);
218 glVertex3d(-wid/2,-hgt/2,-dep/2);
219 glEnd();
220 glBegin(GL_LINE_LOOP);
221 // Left
222 glNormal3d(1,0,0);
223 glVertex3d(wid/2,hgt/2,-dep/2);
224 glVertex3d(wid/2,hgt/2,dep/2);
225 glVertex3d(wid/2,-hgt/2,dep/2);
226 glVertex3d(wid/2,-hgt/2,-dep/2);
227 glEnd();
228 glBegin(GL_LINE_LOOP);
229 // Right
230 glNormal3d(-1,0,0);
231 glVertex3d(-wid/2,hgt/2,dep/2);
232 glVertex3d(-wid/2,hgt/2,-dep/2);
233 glVertex3d(-wid/2,-hgt/2,-dep/2);
234 glVertex3d(-wid/2,-hgt/2,dep/2);
235 glEnd();
236 glBegin(GL_LINE_LOOP);
237 // Bottom
238 glNormal3d(0,-1,0);
239 glVertex3d(-wid/2,-hgt/2,dep/2);
240 glVertex3d(-wid/2,-hgt/2,-dep/2);
241 glVertex3d(wid/2,-hgt/2,-dep/2);
242 glVertex3d(wid/2,-hgt/2,dep/2);
243 glEnd();
244 glPopMatrix();