2 BobToolz plugin for GtkRadiant
\r
3 Copyright (C) 2001 Gordon Biggans
\r
5 This library is free software; you can redistribute it and/or
\r
6 modify it under the terms of the GNU Lesser General Public
\r
7 License as published by the Free Software Foundation; either
\r
8 version 2.1 of the License, or (at your option) any later version.
\r
10 This library is distributed in the hope that it will be useful,
\r
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
13 Lesser General Public License for more details.
\r
15 You should have received a copy of the GNU Lesser General Public
\r
16 License along with this library; if not, write to the Free Software
\r
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 // BobView.cpp: implementation of the DBobView class.
\r
22 //////////////////////////////////////////////////////////////////////
\r
25 #include "DBobView.h"
\r
26 #include "DListener.h"
\r
28 #include "funchandlers.h"
\r
30 //////////////////////////////////////////////////////////////////////
\r
31 // Construction/Destruction
\r
32 //////////////////////////////////////////////////////////////////////
\r
34 DBobView::DBobView()
\r
44 boundingShow = BOUNDS_APEX;
\r
47 DBobView::~DBobView()
\r
52 // oops forgot to remove our eyes, was causing access violation when it tried
\r
53 // to talk to it's parent
\r
63 //////////////////////////////////////////////////////////////////////
\r
65 //////////////////////////////////////////////////////////////////////
\r
67 void DBobView::Draw2D(VIEWTYPE vt)
\r
72 g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
\r
74 g_QglTable.m_pfn_qglDisable(GL_BLEND);
\r
75 g_QglTable.m_pfn_qglEnable(GL_LINE_SMOOTH);
\r
77 g_QglTable.m_pfn_qglPushMatrix();
\r
84 g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
\r
87 g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
\r
88 g_QglTable.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
\r
92 g_QglTable.m_pfn_qglLineWidth(1.0f);
\r
93 g_QglTable.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 1.0f);
\r
97 g_QglTable.m_pfn_qglBegin(GL_LINE_STRIP);
\r
99 for(i = 0; i < nPathCount; i++)
\r
100 g_QglTable.m_pfn_qglVertex3fv(path[i]);
\r
102 g_QglTable.m_pfn_qglEnd();
\r
107 // for the bounding box stuff
\r
108 g_QglTable.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f);
\r
110 g_QglTable.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
\r
112 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
\r
114 for ( i = 0; i < nPathCount; i++ )
\r
115 g_QglTable.m_pfn_qglVertex3fv( path[i] );
\r
117 g_QglTable.m_pfn_qglEnd();
\r
121 g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
\r
122 g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
\r
124 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
\r
126 for ( i = 0; i < nPathCount; i++ )
\r
127 g_QglTable.m_pfn_qglVertex3fv( path[i] );
\r
129 g_QglTable.m_pfn_qglEnd();
\r
133 g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
\r
134 g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
\r
136 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
\r
138 for ( i = 0; i < nPathCount; i++ )
\r
139 g_QglTable.m_pfn_qglVertex3fv( path[i] );
\r
141 g_QglTable.m_pfn_qglEnd();
\r
143 // ----------------
\r
145 g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
\r
147 /* g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
\r
149 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
\r
151 if ( boundingShow == BOUNDS_ALL )
\r
153 for ( i = 0; i < nPathCount; i++ )
\r
154 g_QglTable.m_pfn_qglVertex3fv( path[i] );
\r
156 else if ( boundingShow == BOUNDS_APEX )
\r
158 for ( i = (nPathCount/4); i < (nPathCount/4) * 3; i++ )
\r
159 g_QglTable.m_pfn_qglVertex3fv( path[i] );
\r
162 g_QglTable.m_pfn_qglEnd();*/ // djbob: er, um doesn't really seem to do anyhting
\r
167 g_QglTable.m_pfn_qglPopMatrix();
\r
169 g_QglTable.m_pfn_qglPopAttrib();
\r
172 void DBobView::Draw3D()
\r
177 g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
\r
179 g_QglTable.m_pfn_qglDisable(GL_BLEND);
\r
180 g_QglTable.m_pfn_qglEnable(GL_LINE_SMOOTH);
\r
182 g_QglTable.m_pfn_qglLineWidth(1.0f);
\r
183 g_QglTable.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 1.0f);
\r
185 g_QglTable.m_pfn_qglBegin(GL_LINE_STRIP);
\r
187 for(int i = 0; i < nPathCount; i++)
\r
188 g_QglTable.m_pfn_qglVertex3fv(path[i]);
\r
190 g_QglTable.m_pfn_qglEnd();
\r
195 // ahhh -- a nice C&P job :)
\r
196 // for the bounding box stuff
\r
197 g_QglTable.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f);
\r
199 g_QglTable.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
\r
201 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
\r
204 for ( i = 0; i < nPathCount; i++ )
\r
205 g_QglTable.m_pfn_qglVertex3fv( path[i] );
\r
207 g_QglTable.m_pfn_qglEnd();
\r
211 g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
\r
212 g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
\r
214 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
\r
216 for ( i = 0; i < nPathCount; i++ )
\r
217 g_QglTable.m_pfn_qglVertex3fv( path[i] );
\r
219 g_QglTable.m_pfn_qglEnd();
\r
223 g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
\r
224 g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
\r
226 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
\r
228 for ( i = 0; i < nPathCount; i++ )
\r
229 g_QglTable.m_pfn_qglVertex3fv( path[i] );
\r
231 g_QglTable.m_pfn_qglEnd();
\r
233 // ----------------
\r
235 g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
\r
236 g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
\r
238 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
\r
240 for ( i = 0; i < nPathCount; i++ )
\r
241 g_QglTable.m_pfn_qglVertex3fv( path[i] );
\r
243 g_QglTable.m_pfn_qglEnd();
\r
247 g_QglTable.m_pfn_qglPopAttrib();
\r
250 void DBobView::Register()
\r
252 g_QglTable.m_pfnHookGL2DWindow( this );
\r
253 g_QglTable.m_pfnHookGL3DWindow( this );
\r
257 void DBobView::UnRegister()
\r
259 g_QglTable.m_pfnUnHookGL2DWindow( this );
\r
260 g_QglTable.m_pfnUnHookGL3DWindow( this );
\r
264 void DBobView::SetPath(vec3_t *pPath)
\r
272 #define LOCAL_GRAVITY -800.0f
\r
274 bool DBobView::CalculateTrajectory(vec3_t start, vec3_t apex, float multiplier, int points, float varGravity)
\r
276 if(apex[2] <= start[2])
\r
281 // ----think q3a actually would allow these
\r
282 //scrub that, coz the plugin wont :]
\r
284 vec3_t dist, speed;
\r
285 VectorSubtract(apex, start, dist);
\r
287 vec_t speed_z = (float)sqrt(-2*LOCAL_GRAVITY*dist[2]);
\r
288 float flight_time = -speed_z/LOCAL_GRAVITY;
\r
291 VectorScale(dist, 1/flight_time, speed);
\r
292 speed[2] = speed_z;
\r
294 // Sys_Printf("Speed: (%.4f %.4f %.4f)\n", speed[0], speed[1], speed[2]);
\r
296 vec3_t* pPath = new vec3_t[points];
\r
298 float interval = multiplier*flight_time/points;
\r
299 for(int i = 0; i < points; i++)
\r
301 float ltime = interval*i;
\r
303 VectorScale(speed, ltime, pPath[i]);
\r
304 VectorAdd(pPath[i], start, pPath[i]);
\r
306 // could do this all with vectors
\r
307 // vGrav = {0, 0, -800.0f}
\r
308 // VectorScale(vGrav, 0.5f*ltime*ltime, vAdd);
\r
309 // VectorScale(speed, ltime, pPath[i]);
\r
310 // _VectorAdd(pPath[i], start, pPath[i])
\r
311 // _VectorAdd(pPath[i], vAdd, pPath[i])
\r
313 pPath[i][2] = start[2] + (speed_z*ltime) + (varGravity*0.5f*ltime*ltime);
\r
320 void DBobView::Begin(const char* trigger, const char *target, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra)
\r
322 strcpy(entTrigger, trigger);
\r
323 strcpy(entTarget, target);
\r
325 fMultiplier = multiplier;
\r
326 fVarGravity = varGravity;
\r
327 nPathCount = points;
\r
328 m_bShowExtra = bShowExtra;
\r
336 eyes = new DListener;
\r
337 eyes->parent = this;
\r
343 Sys_ERROR("Initialization Failure in DBobView::Begin");
\r
348 bool DBobView::UpdatePath()
\r
350 vec3_t start, apex;
\r
352 if(GetEntityCentre(entTrigger, start))
\r
354 if(GetEntityCentre(entTarget, apex))
\r
356 CalculateTrajectory(start, apex, fMultiplier, nPathCount, fVarGravity);
\r