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 //////////////////////////////////////////////////////////////////////
43 boundingShow = BOUNDS_APEX;
46 DBobView::~DBobView(){
51 // oops forgot to remove our eyes, was causing access violation when it tried
52 // to talk to it's parent
64 //////////////////////////////////////////////////////////////////////
66 //////////////////////////////////////////////////////////////////////
68 void DBobView::Draw2D( VIEWTYPE vt ){
73 g_QglTable.m_pfn_qglPushAttrib( GL_ALL_ATTRIB_BITS );
75 g_QglTable.m_pfn_qglDisable( GL_BLEND );
76 g_QglTable.m_pfn_qglEnable( GL_LINE_SMOOTH );
78 g_QglTable.m_pfn_qglPushMatrix();
85 g_QglTable.m_pfn_qglRotatef( 270.0f, 1.0f, 0.0f, 0.0f );
88 g_QglTable.m_pfn_qglRotatef( 270.0f, 1.0f, 0.0f, 0.0f );
89 g_QglTable.m_pfn_qglRotatef( 270.0f, 0.0f, 0.0f, 1.0f );
93 g_QglTable.m_pfn_qglLineWidth( 1.0f );
94 g_QglTable.m_pfn_qglColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
98 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
100 for ( i = 0; i < nPathCount; i++ )
101 g_QglTable.m_pfn_qglVertex3fv( path[i] );
103 g_QglTable.m_pfn_qglEnd();
105 if ( m_bShowExtra ) {
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();
192 if ( m_bShowExtra ) {
194 // ahhh -- a nice C&P job :)
195 // for the bounding box stuff
196 g_QglTable.m_pfn_qglColor4f( 0.25f, 0.75f, 0.75f, 1.0f );
198 g_QglTable.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
200 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
203 for ( i = 0; i < nPathCount; i++ )
204 g_QglTable.m_pfn_qglVertex3fv( path[i] );
206 g_QglTable.m_pfn_qglEnd();
210 g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
211 g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
213 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
215 for ( i = 0; i < nPathCount; i++ )
216 g_QglTable.m_pfn_qglVertex3fv( path[i] );
218 g_QglTable.m_pfn_qglEnd();
222 g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
223 g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
225 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
227 for ( i = 0; i < nPathCount; i++ )
228 g_QglTable.m_pfn_qglVertex3fv( path[i] );
230 g_QglTable.m_pfn_qglEnd();
234 g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
235 g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
237 g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
239 for ( i = 0; i < nPathCount; i++ )
240 g_QglTable.m_pfn_qglVertex3fv( path[i] );
242 g_QglTable.m_pfn_qglEnd();
246 g_QglTable.m_pfn_qglPopAttrib();
249 void DBobView::Register(){
250 g_QglTable.m_pfnHookGL2DWindow( this );
251 g_QglTable.m_pfnHookGL3DWindow( this );
255 void DBobView::UnRegister(){
256 g_QglTable.m_pfnUnHookGL2DWindow( this );
257 g_QglTable.m_pfnUnHookGL3DWindow( this );
261 void DBobView::SetPath( vec3_t *pPath ){
269 #define LOCAL_GRAVITY -800.0f
271 bool DBobView::CalculateTrajectory( vec3_t start, vec3_t apex, float multiplier, int points, float varGravity ){
272 if ( apex[2] <= start[2] ) {
276 // ----think q3a actually would allow these
277 //scrub that, coz the plugin wont :]
280 VectorSubtract( apex, start, dist );
282 vec_t speed_z = (float)sqrt( -2 * LOCAL_GRAVITY * dist[2] );
283 float flight_time = -speed_z / LOCAL_GRAVITY;
286 VectorScale( dist, 1 / flight_time, speed );
289 // Sys_Printf("Speed: (%.4f %.4f %.4f)\n", speed[0], speed[1], speed[2]);
291 vec3_t* pPath = new vec3_t[points];
293 float interval = multiplier * flight_time / points;
294 for ( int i = 0; i < points; i++ )
296 float ltime = interval * i;
298 VectorScale( speed, ltime, pPath[i] );
299 VectorAdd( pPath[i], start, pPath[i] );
301 // could do this all with vectors
302 // vGrav = {0, 0, -800.0f}
303 // VectorScale(vGrav, 0.5f*ltime*ltime, vAdd);
304 // VectorScale(speed, ltime, pPath[i]);
305 // _VectorAdd(pPath[i], start, pPath[i])
306 // _VectorAdd(pPath[i], vAdd, pPath[i])
308 pPath[i][2] = start[2] + ( speed_z * ltime ) + ( varGravity * 0.5f * ltime * ltime );
315 void DBobView::Begin( const char* trigger, const char *target, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra ){
316 strcpy( entTrigger, trigger );
317 strcpy( entTarget, target );
319 fMultiplier = multiplier;
320 fVarGravity = varGravity;
322 m_bShowExtra = bShowExtra;
326 if ( UpdatePath() ) {
328 eyes = new DListener;
335 Sys_ERROR( "Initialization Failure in DBobView::Begin" );
340 bool DBobView::UpdatePath(){
343 if ( GetEntityCentre( entTrigger, start ) ) {
344 if ( GetEntityCentre( entTarget, apex ) ) {
345 CalculateTrajectory( start, apex, fMultiplier, nPathCount, fVarGravity );