2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // BobView.cpp: implementation of the DBobView class.
22 //////////////////////////////////////////////////////////////////////
26 #include "DListener.h"
28 #include "funchandlers.h"
30 #include "gtkr_list.h"
35 //////////////////////////////////////////////////////////////////////
36 // Construction/Destruction
37 //////////////////////////////////////////////////////////////////////
49 boundingShow = BOUNDS_APEX;
57 // oops forgot to remove our eyes, was causing access violation when it tried
58 // to talk to it's parent
68 //////////////////////////////////////////////////////////////////////
70 //////////////////////////////////////////////////////////////////////
72 void DBobView::Draw2D(VIEWTYPE vt)
77 __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
79 __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND);
80 __QGLTABLENAME.m_pfn_qglEnable(GL_LINE_SMOOTH);
82 __QGLTABLENAME.m_pfn_qglPushMatrix();
89 __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
92 __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
93 __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
97 __QGLTABLENAME.m_pfn_qglLineWidth(1.0f);
98 __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 1.0f);
102 __QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP);
104 for(i = 0; i < nPathCount; i++)
105 __QGLTABLENAME.m_pfn_qglVertex3fv(path[i]);
107 __QGLTABLENAME.m_pfn_qglEnd();
112 // for the bounding box stuff
113 __QGLTABLENAME.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f);
115 __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
117 __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
119 for ( i = 0; i < nPathCount; i++ )
120 __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
122 __QGLTABLENAME.m_pfn_qglEnd();
126 __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
127 __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
129 __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
131 for ( i = 0; i < nPathCount; i++ )
132 __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
134 __QGLTABLENAME.m_pfn_qglEnd();
138 __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
139 __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
141 __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
143 for ( i = 0; i < nPathCount; i++ )
144 __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
146 __QGLTABLENAME.m_pfn_qglEnd();
150 __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
152 /* __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
154 __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
156 if ( boundingShow == BOUNDS_ALL )
158 for ( i = 0; i < nPathCount; i++ )
159 __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
161 else if ( boundingShow == BOUNDS_APEX )
163 for ( i = (nPathCount/4); i < (nPathCount/4) * 3; i++ )
164 __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
167 __QGLTABLENAME.m_pfn_qglEnd();*/ // djbob: er, um doesn't really seem to do anyhting
172 __QGLTABLENAME.m_pfn_qglPopMatrix();
174 __QGLTABLENAME.m_pfn_qglPopAttrib();
177 void DBobView::Draw3D()
182 __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
184 __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND);
185 __QGLTABLENAME.m_pfn_qglEnable(GL_LINE_SMOOTH);
187 __QGLTABLENAME.m_pfn_qglLineWidth(1.0f);
188 __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 1.0f);
190 __QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP);
192 for(int i = 0; i < nPathCount; i++)
193 __QGLTABLENAME.m_pfn_qglVertex3fv(path[i]);
195 __QGLTABLENAME.m_pfn_qglEnd();
200 // ahhh -- a nice C&P job :)
201 // for the bounding box stuff
202 __QGLTABLENAME.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f);
204 __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
206 __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
209 for ( i = 0; i < nPathCount; i++ )
210 __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
212 __QGLTABLENAME.m_pfn_qglEnd();
216 __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
217 __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
219 __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
221 for ( i = 0; i < nPathCount; i++ )
222 __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
224 __QGLTABLENAME.m_pfn_qglEnd();
228 __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
229 __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
231 __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
233 for ( i = 0; i < nPathCount; i++ )
234 __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
236 __QGLTABLENAME.m_pfn_qglEnd();
240 __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
241 __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
243 __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
245 for ( i = 0; i < nPathCount; i++ )
246 __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
248 __QGLTABLENAME.m_pfn_qglEnd();
252 __QGLTABLENAME.m_pfn_qglPopAttrib();
255 void DBobView::Register()
257 __QGLTABLENAME.m_pfnHookGL2DWindow( this );
258 __QGLTABLENAME.m_pfnHookGL3DWindow( this );
262 void DBobView::UnRegister()
264 __QGLTABLENAME.m_pfnUnHookGL2DWindow( this );
265 __QGLTABLENAME.m_pfnUnHookGL3DWindow( this );
269 void DBobView::SetPath(vec3_t *pPath)
277 #define LOCAL_GRAVITY -800.0f
279 bool DBobView::CalculateTrajectory(vec3_t start, vec3_t apex, float multiplier, int points, float varGravity)
281 if(apex[2] <= start[2])
286 // ----think q3a actually would allow these
287 //scrub that, coz the plugin wont :]
290 VectorSubtract(apex, start, dist);
292 vec_t speed_z = (float)sqrt(-2*LOCAL_GRAVITY*dist[2]);
293 float flight_time = -speed_z/LOCAL_GRAVITY;
296 VectorScale(dist, 1/flight_time, speed);
299 // Sys_Printf("Speed: (%.4f %.4f %.4f)\n", speed[0], speed[1], speed[2]);
301 vec3_t* pPath = new vec3_t[points];
303 float interval = multiplier*flight_time/points;
304 for(int i = 0; i < points; i++)
306 float ltime = interval*i;
308 VectorScale(speed, ltime, pPath[i]);
309 VectorAdd(pPath[i], start, pPath[i]);
311 // could do this all with vectors
312 // vGrav = {0, 0, -800.0f}
313 // VectorScale(vGrav, 0.5f*ltime*ltime, vAdd);
314 // VectorScale(speed, ltime, pPath[i]);
315 // _VectorAdd(pPath[i], start, pPath[i])
316 // _VectorAdd(pPath[i], vAdd, pPath[i])
318 pPath[i][2] = start[2] + (speed_z*ltime) + (varGravity*0.5f*ltime*ltime);
325 void DBobView::Begin(const char* trigger, const char *target, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra)
327 strcpy(entTrigger, trigger);
328 strcpy(entTarget, target);
330 fMultiplier = multiplier;
331 fVarGravity = varGravity;
333 m_bShowExtra = bShowExtra;
341 eyes = new DListener;
348 Sys_ERROR("Initialization Failure in DBobView::Begin");
353 bool DBobView::UpdatePath()
357 if(GetEntityCentre(entTrigger, start))
359 if(GetEntityCentre(entTarget, apex))
361 CalculateTrajectory(start, apex, fMultiplier, nPathCount, fVarGravity);