1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
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
;
36 RenderGeoms::RenderGeoms()
40 RenderGeoms::~RenderGeoms()
44 void RenderGeoms::draw(const unsigned state
)
46 if (OptionsDisplay::instance()->getDrawCollisionGeoms())
49 drawCollisionBounds();
52 if (OptionsDisplay::instance()->getDrawCollisionSpace())
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();
75 Target
*target
= (*itor
).second
;
76 if (!target
->getAlive())
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
;
90 glTranslated(position
[0], position
[1], position
[2]);
91 glBegin(GL_LINE_LOOP
);
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);
99 glBegin(GL_LINE_LOOP
);
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);
107 glBegin(GL_LINE_LOOP
);
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);
115 glBegin(GL_LINE_LOOP
);
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);
123 glBegin(GL_LINE_LOOP
);
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);
131 glBegin(GL_LINE_LOOP
);
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);
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();
155 Target
*target
= (*itor
).second
;
156 if (!target
->getAlive())
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;
171 obj
= gluNewQuadric();
172 gluQuadricDrawStyle(obj
, GLU_LINE
);
176 glTranslated(position
[0], position
[1], position
[2]);
177 gluSphere(obj
, radius
, 6, 6);
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
);
194 glTranslated(position
[0], position
[1], position
[2]);
195 glMultMatrixf(rotMatrix
);
196 glBegin(GL_LINE_LOOP
);
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);
204 glBegin(GL_LINE_LOOP
);
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);
212 glBegin(GL_LINE_LOOP
);
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);
220 glBegin(GL_LINE_LOOP
);
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);
228 glBegin(GL_LINE_LOOP
);
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);
236 glBegin(GL_LINE_LOOP
);
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);