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 //////////////////////////////////////////////////////////////////////
31 // Construction/Destruction
32 //////////////////////////////////////////////////////////////////////
44 boundingShow = BOUNDS_APEX;
52 // oops forgot to remove our eyes, was causing access violation when it tried
53 // to talk to it's parent
63 //////////////////////////////////////////////////////////////////////
65 //////////////////////////////////////////////////////////////////////
67 void DBobView::Draw2D(VIEWTYPE vt)
72 g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
74 g_QglTable.m_pfn_qglDisable(GL_BLEND);
75 g_QglTable.m_pfn_qglEnable(GL_LINE_SMOOTH);
77 g_QglTable.m_pfn_qglPushMatrix();
84 g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
87 g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
88 g_QglTable.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
92 g_QglTable.m_pfn_qglLineWidth(1.0f);
93 g_QglTable.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 1.0f);
97 g_QglTable.m_pfn_qglBegin(GL_LINE_STRIP);
99 for(i = 0; i < nPathCount; i++)
100 g_QglTable.m_pfn_qglVertex3fv(path[i]);
102 g_QglTable.m_pfn_qglEnd();
107 // for the bounding box stuff
108 g_QglTable.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f);
110 g_QglTable.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
112 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
114 for ( i = 0; i < nPathCount; i++ )
115 g_QglTable.m_pfn_qglVertex3fv( path[i] );
117 g_QglTable.m_pfn_qglEnd();
121 g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
122 g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
124 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
126 for ( i = 0; i < nPathCount; i++ )
127 g_QglTable.m_pfn_qglVertex3fv( path[i] );
129 g_QglTable.m_pfn_qglEnd();
133 g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
134 g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
136 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
138 for ( i = 0; i < nPathCount; i++ )
139 g_QglTable.m_pfn_qglVertex3fv( path[i] );
141 g_QglTable.m_pfn_qglEnd();
145 g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
147 /* g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
149 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
151 if ( boundingShow == BOUNDS_ALL )
153 for ( i = 0; i < nPathCount; i++ )
154 g_QglTable.m_pfn_qglVertex3fv( path[i] );
156 else if ( boundingShow == BOUNDS_APEX )
158 for ( i = (nPathCount/4); i < (nPathCount/4) * 3; i++ )
159 g_QglTable.m_pfn_qglVertex3fv( path[i] );
162 g_QglTable.m_pfn_qglEnd();*/ // djbob: er, um doesn't really seem to do anyhting
167 g_QglTable.m_pfn_qglPopMatrix();
169 g_QglTable.m_pfn_qglPopAttrib();
172 void DBobView::Draw3D()
177 g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
179 g_QglTable.m_pfn_qglDisable(GL_BLEND);
180 g_QglTable.m_pfn_qglEnable(GL_LINE_SMOOTH);
182 g_QglTable.m_pfn_qglLineWidth(1.0f);
183 g_QglTable.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 1.0f);
185 g_QglTable.m_pfn_qglBegin(GL_LINE_STRIP);
187 for(int i = 0; i < nPathCount; i++)
188 g_QglTable.m_pfn_qglVertex3fv(path[i]);
190 g_QglTable.m_pfn_qglEnd();
195 // ahhh -- a nice C&P job :)
196 // for the bounding box stuff
197 g_QglTable.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f);
199 g_QglTable.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
201 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
204 for ( i = 0; i < nPathCount; i++ )
205 g_QglTable.m_pfn_qglVertex3fv( path[i] );
207 g_QglTable.m_pfn_qglEnd();
211 g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
212 g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
214 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
216 for ( i = 0; i < nPathCount; i++ )
217 g_QglTable.m_pfn_qglVertex3fv( path[i] );
219 g_QglTable.m_pfn_qglEnd();
223 g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
224 g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
226 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
228 for ( i = 0; i < nPathCount; i++ )
229 g_QglTable.m_pfn_qglVertex3fv( path[i] );
231 g_QglTable.m_pfn_qglEnd();
235 g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
236 g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
238 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
240 for ( i = 0; i < nPathCount; i++ )
241 g_QglTable.m_pfn_qglVertex3fv( path[i] );
243 g_QglTable.m_pfn_qglEnd();
247 g_QglTable.m_pfn_qglPopAttrib();
250 void DBobView::Register()
252 g_QglTable.m_pfnHookGL2DWindow( this );
253 g_QglTable.m_pfnHookGL3DWindow( this );
257 void DBobView::UnRegister()
259 g_QglTable.m_pfnUnHookGL2DWindow( this );
260 g_QglTable.m_pfnUnHookGL3DWindow( this );
264 void DBobView::SetPath(vec3_t *pPath)
272 #define LOCAL_GRAVITY -800.0f
274 bool DBobView::CalculateTrajectory(vec3_t start, vec3_t apex, float multiplier, int points, float varGravity)
276 if(apex[2] <= start[2])
281 // ----think q3a actually would allow these
282 //scrub that, coz the plugin wont :]
285 VectorSubtract(apex, start, dist);
287 vec_t speed_z = (float)sqrt(-2*LOCAL_GRAVITY*dist[2]);
288 float flight_time = -speed_z/LOCAL_GRAVITY;
291 VectorScale(dist, 1/flight_time, speed);
294 // Sys_Printf("Speed: (%.4f %.4f %.4f)\n", speed[0], speed[1], speed[2]);
296 vec3_t* pPath = new vec3_t[points];
298 float interval = multiplier*flight_time/points;
299 for(int i = 0; i < points; i++)
301 float ltime = interval*i;
303 VectorScale(speed, ltime, pPath[i]);
304 VectorAdd(pPath[i], start, pPath[i]);
306 // could do this all with vectors
307 // vGrav = {0, 0, -800.0f}
308 // VectorScale(vGrav, 0.5f*ltime*ltime, vAdd);
309 // VectorScale(speed, ltime, pPath[i]);
310 // _VectorAdd(pPath[i], start, pPath[i])
311 // _VectorAdd(pPath[i], vAdd, pPath[i])
313 pPath[i][2] = start[2] + (speed_z*ltime) + (varGravity*0.5f*ltime*ltime);
320 void DBobView::Begin(const char* trigger, const char *target, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra)
322 strcpy(entTrigger, trigger);
323 strcpy(entTarget, target);
325 fMultiplier = multiplier;
326 fVarGravity = varGravity;
328 m_bShowExtra = bShowExtra;
336 eyes = new DListener;
343 Sys_ERROR("Initialization Failure in DBobView::Begin");
348 bool DBobView::UpdatePath()
352 if(GetEntityCentre(entTrigger, start))
354 if(GetEntityCentre(entTarget, apex))
356 CalculateTrajectory(start, apex, fMultiplier, nPathCount, fVarGravity);