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/RenderTracer.h>
22 #include <tank/TankContainer.h>
23 #include <GLEXT/GLTexture.h>
24 #include <image/ImageBitmap.h>
25 #include <client/ScorchedClient.h>
27 RenderTracer
*RenderTracer::instance_
= 0;
29 RenderTracer
*RenderTracer::instance()
31 if (!instance_
) instance_
= new RenderTracer
;
35 RenderTracer::RenderTracer() :
36 GameStateI("RenderTracer"),
37 current_(0), listNo_(0)
39 obj_
= gluNewQuadric();
42 RenderTracer::~RenderTracer()
44 gluDeleteQuadric(obj_
);
47 void RenderTracer::clearTracers()
51 current_
->lines
.clear();
52 current_
->points
.clear();
56 void RenderTracer::clearTracerLines()
60 current_
->lines
.clear();
64 void RenderTracer::draw(const unsigned state
)
66 Tank
*current
= ScorchedClient::instance()->getTankContainer().getCurrentTank();
70 current_
->tank
!= current
->getPlayerId())
72 std::map
<unsigned int, TraceEntry
>::iterator itor
=
73 traceEntries_
.find(current
->getPlayerId());
74 if (itor
== traceEntries_
.end())
76 TraceEntry
entry(current
->getPlayerId());
77 traceEntries_
[current
->getPlayerId()] = entry
;
78 current_
= &traceEntries_
[current
->getPlayerId()];
82 current_
= &(*itor
).second
;
85 if (current_
->points
.empty()) return;
87 glColor3fv(current
->getColor());
89 std::list
<Vector
>::iterator itor
= current_
->points
.begin();
90 std::list
<Vector
>::iterator itorend
= current_
->points
.end();
91 for (;itor
!= itorend
; itor
++)
96 std::list
<std::list
<TracerLinePoint
> >::iterator itor2
= current_
->lines
.begin();
97 std::list
<std::list
<TracerLinePoint
> >::iterator itorend2
= current_
->lines
.end();
98 for (;itor2
!= itorend2
; itor2
++)
100 drawSmokeTracer(*itor2
);
104 void RenderTracer::drawTracerEnd(Vector
&position
)
106 GLState
currentState(GLState::TEXTURE_OFF
| GLState::BLEND_OFF
);
109 glTranslatef(position
[0], position
[1], position
[2]);
112 glNewList(listNo_
= glGenLists(1), GL_COMPILE_AND_EXECUTE
);
113 gluSphere(obj_
, 0.5f
, 4, 2);
123 void RenderTracer::drawSmokeTracer(std::list
<TracerLinePoint
> &positions
)
125 GLState
currentState(GLState::TEXTURE_OFF
| GLState::BLEND_OFF
);
126 /*glEnable(GL_ALPHA_TEST);
128 static GLTexture arrowTexture;
129 if (!arrowTexture.textureValid())
131 std::string file1 = S3D::getDataFile("data/windows/arrow.bmp");
132 std::string file2 = S3D::getDataFile("data/windows/arrowi.bmp");
133 ImageBitmap bitmap(file1.c_str(), file2.c_str(), true);
134 arrowTexture.create(bitmap);
136 arrowTexture.draw();*/
138 // Draw twice (for front and back facing)
139 for (int i
=0; i
<2; i
++)
141 glBegin(GL_QUAD_STRIP
);
143 float totalDist
= 0.0f
;
144 std::list
<TracerLinePoint
>::iterator itor
= positions
.begin();
145 std::list
<TracerLinePoint
>::iterator itorend
= positions
.end();
146 for (;itor
!= itorend
; itor
++)
148 Vector
¤tPos
= (*itor
).position
;
149 Vector
&cross
= (*itor
).cross
;
150 if (itor
== positions
.begin()) lastPos
= currentPos
;
152 float dist
= (lastPos
- currentPos
).Magnitude();
157 glTexCoord2f(0.0f
, totalDist
);
158 glVertex3fv(currentPos
- cross
/ 2.0f
);
159 glTexCoord2f(1.0f
, totalDist
);
160 glVertex3fv(currentPos
+ cross
/ 2.0f
);
164 glTexCoord2f(0.0f
, totalDist
);
165 glVertex3fv(currentPos
+ cross
/ 2.0f
);
166 glTexCoord2f(1.0f
, totalDist
);
167 glVertex3fv(currentPos
- cross
/ 2.0f
);
173 glBegin(GL_QUAD_STRIP
);
176 totalDist
+= dist
/ 10.0f
;
177 lastPos
= currentPos
;
181 //glDisable(GL_ALPHA_TEST);
184 void RenderTracer::newGame()
186 traceEntries_
.clear();
190 void RenderTracer::addTracer(unsigned int tank
, Vector
&position
)
192 std::map
<unsigned int, TraceEntry
>::iterator itor
=
193 traceEntries_
.find(tank
);
194 if (itor
== traceEntries_
.end())
196 TraceEntry
entry(tank
);
197 entry
.points
.push_back(position
);
198 traceEntries_
[tank
] = entry
;
202 (*itor
).second
.points
.push_back(position
);
206 void RenderTracer::addSmokeTracer(unsigned int tank
,
207 Vector
&position
, std::list
<TracerLinePoint
> &positions
)
209 std::map
<unsigned int, TraceEntry
>::iterator itor
=
210 traceEntries_
.find(tank
);
211 if (itor
== traceEntries_
.end())
213 TraceEntry
entry(tank
);
214 entry
.lines
.push_back(positions
);
215 entry
.points
.push_back(position
);
216 traceEntries_
[tank
] = entry
;
220 (*itor
).second
.lines
.push_back(positions
);
221 (*itor
).second
.points
.push_back(position
);