2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
BobToolz plugin for GtkRadiant
|
|
|
|
Copyright (C) 2001 Gordon Biggans
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
// BobView.cpp: implementation of the DBobView class.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "DBobView.h"
|
|
|
|
#include "DListener.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "funchandlers.h"
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Construction/Destruction
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
DBobView::DBobView(){
|
2007-11-04 03:51:54 +00:00
|
|
|
nPathCount = 0;
|
|
|
|
refCount = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
m_bHooked = FALSE;
|
|
|
|
|
|
|
|
path = NULL;
|
|
|
|
eyes = NULL;
|
|
|
|
|
|
|
|
boundingShow = BOUNDS_APEX;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
DBobView::~DBobView(){
|
|
|
|
if ( path ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
delete[] path;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
// oops forgot to remove our eyes, was causing access violation when it tried
|
|
|
|
// to talk to it's parent
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( eyes ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
delete eyes;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( m_bHooked ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
UnRegister();
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_PathView = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Implementation
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBobView::Draw2D( VIEWTYPE vt ){
|
|
|
|
if ( !path ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglPushAttrib( GL_ALL_ATTRIB_BITS );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglDisable( GL_BLEND );
|
|
|
|
g_QglTable.m_pfn_qglEnable( GL_LINE_SMOOTH );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglPushMatrix();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
switch ( vt )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
case XY:
|
|
|
|
break;
|
|
|
|
case XZ:
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglRotatef( 270.0f, 1.0f, 0.0f, 0.0f );
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
case YZ:
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglRotatef( 270.0f, 1.0f, 0.0f, 0.0f );
|
|
|
|
g_QglTable.m_pfn_qglRotatef( 270.0f, 0.0f, 0.0f, 1.0f );
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglLineWidth( 1.0f );
|
|
|
|
g_QglTable.m_pfn_qglColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < nPathCount; i++ )
|
|
|
|
g_QglTable.m_pfn_qglVertex3fv( path[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglEnd();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( m_bShowExtra ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
// +mars
|
|
|
|
// for the bounding box stuff
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglColor4f( 0.25f, 0.75f, 0.75f, 1.0f );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
|
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < nPathCount; i++ )
|
|
|
|
g_QglTable.m_pfn_qglVertex3fv( path[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglEnd();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// ---------------
|
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
|
|
|
|
g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < nPathCount; i++ )
|
|
|
|
g_QglTable.m_pfn_qglVertex3fv( path[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglEnd();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// --------------
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
|
|
|
|
g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < nPathCount; i++ )
|
|
|
|
g_QglTable.m_pfn_qglVertex3fv( path[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglEnd();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// ----------------
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
/* g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( boundingShow == BOUNDS_ALL )
|
|
|
|
{
|
|
|
|
for ( i = 0; i < nPathCount; i++ )
|
|
|
|
g_QglTable.m_pfn_qglVertex3fv( path[i] );
|
|
|
|
}
|
|
|
|
else if ( boundingShow == BOUNDS_APEX )
|
|
|
|
{
|
|
|
|
for ( i = (nPathCount/4); i < (nPathCount/4) * 3; i++ )
|
|
|
|
g_QglTable.m_pfn_qglVertex3fv( path[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglEnd();*/ // djbob: er, um doesn't really seem to do anyhting
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -mars
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
g_QglTable.m_pfn_qglPopMatrix();
|
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglPopAttrib();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBobView::Draw3D(){
|
|
|
|
if ( !path ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglPushAttrib( GL_ALL_ATTRIB_BITS );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglDisable( GL_BLEND );
|
|
|
|
g_QglTable.m_pfn_qglEnable( GL_LINE_SMOOTH );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglLineWidth( 1.0f );
|
|
|
|
g_QglTable.m_pfn_qglColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = 0; i < nPathCount; i++ )
|
|
|
|
g_QglTable.m_pfn_qglVertex3fv( path[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglEnd();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( m_bShowExtra ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
// +mars
|
|
|
|
// ahhh -- a nice C&P job :)
|
|
|
|
// for the bounding box stuff
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglColor4f( 0.25f, 0.75f, 0.75f, 1.0f );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
|
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
int i;
|
2007-11-04 03:51:54 +00:00
|
|
|
for ( i = 0; i < nPathCount; i++ )
|
|
|
|
g_QglTable.m_pfn_qglVertex3fv( path[i] );
|
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglEnd();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// ---------------
|
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
|
|
|
|
g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < nPathCount; i++ )
|
|
|
|
g_QglTable.m_pfn_qglVertex3fv( path[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglEnd();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// --------------
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
|
|
|
|
g_QglTable.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < nPathCount; i++ )
|
|
|
|
g_QglTable.m_pfn_qglVertex3fv( path[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglEnd();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// ----------------
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
|
|
|
|
g_QglTable.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglBegin( GL_LINE_STRIP );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < nPathCount; i++ )
|
|
|
|
g_QglTable.m_pfn_qglVertex3fv( path[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglEnd();
|
|
|
|
}
|
|
|
|
// -mars
|
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglPopAttrib();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBobView::Register(){
|
2007-11-04 03:51:54 +00:00
|
|
|
g_QglTable.m_pfnHookGL2DWindow( this );
|
|
|
|
g_QglTable.m_pfnHookGL3DWindow( this );
|
|
|
|
m_bHooked = TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBobView::UnRegister(){
|
2007-11-04 03:51:54 +00:00
|
|
|
g_QglTable.m_pfnUnHookGL2DWindow( this );
|
|
|
|
g_QglTable.m_pfnUnHookGL3DWindow( this );
|
|
|
|
m_bHooked = FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBobView::SetPath( vec3_t *pPath ){
|
|
|
|
if ( path ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
delete[] path;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
path = pPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LOCAL_GRAVITY -800.0f
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBobView::CalculateTrajectory( vec3_t start, vec3_t apex, float multiplier, int points, float varGravity ){
|
|
|
|
if ( apex[2] <= start[2] ) {
|
|
|
|
SetPath( NULL );
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
// ----think q3a actually would allow these
|
|
|
|
//scrub that, coz the plugin wont :]
|
|
|
|
|
|
|
|
vec3_t dist, speed;
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorSubtract( apex, start, dist );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
vec_t speed_z = (float)sqrt( -2 * LOCAL_GRAVITY * dist[2] );
|
|
|
|
float flight_time = -speed_z / LOCAL_GRAVITY;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorScale( dist, 1 / flight_time, speed );
|
2007-11-04 03:51:54 +00:00
|
|
|
speed[2] = speed_z;
|
|
|
|
|
|
|
|
// Sys_Printf("Speed: (%.4f %.4f %.4f)\n", speed[0], speed[1], speed[2]);
|
|
|
|
|
|
|
|
vec3_t* pPath = new vec3_t[points];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
float interval = multiplier * flight_time / points;
|
|
|
|
for ( int i = 0; i < points; i++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
float ltime = interval * i;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorScale( speed, ltime, pPath[i] );
|
|
|
|
VectorAdd( pPath[i], start, pPath[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
// could do this all with vectors
|
|
|
|
// vGrav = {0, 0, -800.0f}
|
|
|
|
// VectorScale(vGrav, 0.5f*ltime*ltime, vAdd);
|
|
|
|
// VectorScale(speed, ltime, pPath[i]);
|
|
|
|
// _VectorAdd(pPath[i], start, pPath[i])
|
|
|
|
// _VectorAdd(pPath[i], vAdd, pPath[i])
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
pPath[i][2] = start[2] + ( speed_z * ltime ) + ( varGravity * 0.5f * ltime * ltime );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SetPath( pPath );
|
2007-11-04 03:51:54 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBobView::Begin( const char* trigger, const char *target, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra ){
|
|
|
|
strcpy( entTrigger, trigger );
|
|
|
|
strcpy( entTarget, target );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
fMultiplier = multiplier;
|
|
|
|
fVarGravity = varGravity;
|
|
|
|
nPathCount = points;
|
|
|
|
m_bShowExtra = bShowExtra;
|
|
|
|
|
|
|
|
Register();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( UpdatePath() ) {
|
|
|
|
if ( !bNoUpdate ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
eyes = new DListener;
|
|
|
|
eyes->parent = this;
|
|
|
|
eyes->Register();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_ERROR( "Initialization Failure in DBobView::Begin" );
|
2007-11-04 03:51:54 +00:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBobView::UpdatePath(){
|
2007-11-04 03:51:54 +00:00
|
|
|
vec3_t start, apex;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( GetEntityCentre( entTrigger, start ) ) {
|
|
|
|
if ( GetEntityCentre( entTarget, apex ) ) {
|
|
|
|
CalculateTrajectory( start, apex, fMultiplier, nPathCount, fVarGravity );
|
2007-11-04 03:51:54 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|