2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 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
|
|
|
GtkRadiant 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 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 General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
#include "q_shared.h"
|
|
|
|
#include "splines.h"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
int FS_Write( const void *buffer, int len, fileHandle_t h );
|
|
|
|
int FS_ReadFile( const char *qpath, void **buffer );
|
|
|
|
void FS_FreeFile( void *buffer );
|
|
|
|
fileHandle_t FS_FOpenFileWrite( const char *filename );
|
|
|
|
void FS_FCloseFile( fileHandle_t f );
|
|
|
|
void Cbuf_AddText( const char *text );
|
2012-03-17 20:01:54 +00:00
|
|
|
void Cbuf_Execute( void );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float Q_fabs( float f ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
int tmp = *( int * ) &f;
|
2007-11-04 03:51:54 +00:00
|
|
|
tmp &= 0x7FFFFFFF;
|
2012-03-17 20:01:54 +00:00
|
|
|
return *( float * ) &tmp;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// (SA) making a list of cameras so I can use
|
|
|
|
// the splines as targets for other things.
|
|
|
|
// Certainly better ways to do this, but this lets
|
|
|
|
// me get underway quickly with ents that need spline
|
|
|
|
// targets.
|
|
|
|
#define MAX_CAMERAS 64
|
|
|
|
|
|
|
|
idCameraDef camera[MAX_CAMERAS];
|
|
|
|
|
|
|
|
extern "C" {
|
2012-03-17 20:01:54 +00:00
|
|
|
qboolean loadCamera( int camNum, const char *name ) {
|
|
|
|
if ( camNum < 0 || camNum >= MAX_CAMERAS ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
camera[camNum].clear();
|
2012-03-17 20:01:54 +00:00
|
|
|
return (qboolean)camera[camNum].load( name );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qboolean getCameraInfo( int camNum, int time, float *origin, float *angles, float *fov ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
idVec3 dir, org;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( camNum < 0 || camNum >= MAX_CAMERAS ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
org[0] = origin[0];
|
|
|
|
org[1] = origin[1];
|
|
|
|
org[2] = origin[2];
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( camera[camNum].getCameraInfo( time, org, dir, fov ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
origin[0] = org[0];
|
|
|
|
origin[1] = org[1];
|
|
|
|
origin[2] = org[2];
|
2012-03-17 20:01:54 +00:00
|
|
|
angles[1] = atan2( dir[1], dir[0] ) * 180 / 3.14159;
|
|
|
|
angles[0] = asin( dir[2] ) * 180 / 3.14159;
|
2007-11-04 03:51:54 +00:00
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void startCamera( int camNum, int time ) {
|
|
|
|
if ( camNum < 0 || camNum >= MAX_CAMERAS ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
camera[camNum].startCamera( time );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//#include "../shared/windings.h"
|
|
|
|
//#include "../qcommon/qcommon.h"
|
|
|
|
//#include "../sys/sys_public.h"
|
|
|
|
//#include "../game/game_entity.h"
|
|
|
|
|
|
|
|
idCameraDef splineList;
|
|
|
|
idCameraDef *g_splineList = &splineList;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
idVec3 idSplineList::zero( 0,0,0 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void glLabeledPoint( idVec3 &color, idVec3 &point, float size, const char *label ) {
|
|
|
|
qglColor3fv( color );
|
|
|
|
qglPointSize( size );
|
|
|
|
qglBegin( GL_POINTS );
|
|
|
|
qglVertex3fv( point );
|
2007-11-04 03:51:54 +00:00
|
|
|
qglEnd();
|
|
|
|
idVec3 v = point;
|
|
|
|
v.x += 1;
|
|
|
|
v.y += 1;
|
|
|
|
v.z += 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
qglRasterPos3fv( v );
|
|
|
|
qglCallLists( strlen( label ), GL_UNSIGNED_BYTE, label );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void glBox( idVec3 &color, idVec3 &point, float size ) {
|
|
|
|
idVec3 mins( point );
|
|
|
|
idVec3 maxs( point );
|
2007-11-04 03:51:54 +00:00
|
|
|
mins[0] -= size;
|
|
|
|
mins[1] += size;
|
|
|
|
mins[2] -= size;
|
|
|
|
maxs[0] += size;
|
|
|
|
maxs[1] -= size;
|
|
|
|
maxs[2] += size;
|
2012-03-17 20:01:54 +00:00
|
|
|
qglColor3fv( color );
|
|
|
|
qglBegin( GL_LINE_LOOP );
|
|
|
|
qglVertex3f( mins[0],mins[1],mins[2] );
|
|
|
|
qglVertex3f( maxs[0],mins[1],mins[2] );
|
|
|
|
qglVertex3f( maxs[0],maxs[1],mins[2] );
|
|
|
|
qglVertex3f( mins[0],maxs[1],mins[2] );
|
2007-11-04 03:51:54 +00:00
|
|
|
qglEnd();
|
2012-03-17 20:01:54 +00:00
|
|
|
qglBegin( GL_LINE_LOOP );
|
|
|
|
qglVertex3f( mins[0],mins[1],maxs[2] );
|
|
|
|
qglVertex3f( maxs[0],mins[1],maxs[2] );
|
|
|
|
qglVertex3f( maxs[0],maxs[1],maxs[2] );
|
|
|
|
qglVertex3f( mins[0],maxs[1],maxs[2] );
|
2007-11-04 03:51:54 +00:00
|
|
|
qglEnd();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qglBegin( GL_LINES );
|
|
|
|
qglVertex3f( mins[0],mins[1],mins[2] );
|
|
|
|
qglVertex3f( mins[0],mins[1],maxs[2] );
|
|
|
|
qglVertex3f( mins[0],maxs[1],maxs[2] );
|
|
|
|
qglVertex3f( mins[0],maxs[1],mins[2] );
|
|
|
|
qglVertex3f( maxs[0],mins[1],mins[2] );
|
|
|
|
qglVertex3f( maxs[0],mins[1],maxs[2] );
|
|
|
|
qglVertex3f( maxs[0],maxs[1],maxs[2] );
|
|
|
|
qglVertex3f( maxs[0],maxs[1],mins[2] );
|
2007-11-04 03:51:54 +00:00
|
|
|
qglEnd();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void splineTest() {
|
|
|
|
//g_splineList->load("p:/doom/base/maps/test_base1.camera");
|
|
|
|
}
|
|
|
|
|
|
|
|
void splineDraw() {
|
|
|
|
//g_splineList->addToRenderer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//extern void D_DebugLine( const idVec3 &color, const idVec3 &start, const idVec3 &end );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void debugLine( idVec3 &color, float x, float y, float z, float x2, float y2, float z2 ) {
|
|
|
|
idVec3 from( x, y, z );
|
|
|
|
idVec3 to( x2, y2, z2 );
|
2007-11-04 03:51:54 +00:00
|
|
|
//D_DebugLine(color, from, to);
|
|
|
|
}
|
|
|
|
|
|
|
|
void idSplineList::addToRenderer() {
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( controlPoints.Num() == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
idVec3 mins, maxs;
|
2012-03-17 20:01:54 +00:00
|
|
|
idVec3 yellow( 1.0, 1.0, 0 );
|
|
|
|
idVec3 white( 1.0, 1.0, 1.0 );
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; i < controlPoints.Num(); i++ ) {
|
|
|
|
VectorCopy( *controlPoints[i], mins );
|
|
|
|
VectorCopy( mins, maxs );
|
2007-11-04 03:51:54 +00:00
|
|
|
mins[0] -= 8;
|
|
|
|
mins[1] += 8;
|
|
|
|
mins[2] -= 8;
|
|
|
|
maxs[0] += 8;
|
|
|
|
maxs[1] -= 8;
|
|
|
|
maxs[2] += 8;
|
2012-03-17 20:01:54 +00:00
|
|
|
debugLine( yellow, mins[0], mins[1], mins[2], maxs[0], mins[1], mins[2] );
|
|
|
|
debugLine( yellow, maxs[0], mins[1], mins[2], maxs[0], maxs[1], mins[2] );
|
|
|
|
debugLine( yellow, maxs[0], maxs[1], mins[2], mins[0], maxs[1], mins[2] );
|
|
|
|
debugLine( yellow, mins[0], maxs[1], mins[2], mins[0], mins[1], mins[2] );
|
|
|
|
|
|
|
|
debugLine( yellow, mins[0], mins[1], maxs[2], maxs[0], mins[1], maxs[2] );
|
|
|
|
debugLine( yellow, maxs[0], mins[1], maxs[2], maxs[0], maxs[1], maxs[2] );
|
|
|
|
debugLine( yellow, maxs[0], maxs[1], maxs[2], mins[0], maxs[1], maxs[2] );
|
|
|
|
debugLine( yellow, mins[0], maxs[1], maxs[2], mins[0], mins[1], maxs[2] );
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int step = 0;
|
|
|
|
idVec3 step1;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 3; i < controlPoints.Num(); i++ ) {
|
|
|
|
for ( float tension = 0.0f; tension < 1.001f; tension += 0.1f ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
float x = 0;
|
|
|
|
float y = 0;
|
|
|
|
float z = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int j = 0; j < 4; j++ ) {
|
|
|
|
x += controlPoints[i - ( 3 - j )]->x * calcSpline( j, tension );
|
|
|
|
y += controlPoints[i - ( 3 - j )]->y * calcSpline( j, tension );
|
|
|
|
z += controlPoints[i - ( 3 - j )]->z * calcSpline( j, tension );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( step == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
step1[0] = x;
|
|
|
|
step1[1] = y;
|
|
|
|
step1[2] = z;
|
|
|
|
step = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
debugLine( white, step1[0], step1[1], step1[2], x, y, z );
|
2007-11-04 03:51:54 +00:00
|
|
|
step = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void idSplineList::buildSpline() {
|
|
|
|
//int start = Sys_Milliseconds();
|
|
|
|
clearSpline();
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = 3; i < controlPoints.Num(); i++ ) {
|
|
|
|
for ( float tension = 0.0f; tension < 1.001f; tension += granularity ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
float x = 0;
|
|
|
|
float y = 0;
|
|
|
|
float z = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int j = 0; j < 4; j++ ) {
|
|
|
|
x += controlPoints[i - ( 3 - j )]->x * calcSpline( j, tension );
|
|
|
|
y += controlPoints[i - ( 3 - j )]->y * calcSpline( j, tension );
|
|
|
|
z += controlPoints[i - ( 3 - j )]->z * calcSpline( j, tension );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
splinePoints.Append( new idVec3( x, y, z ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dirty = false;
|
|
|
|
//Com_Printf("Spline build took %f seconds\n", (float)(Sys_Milliseconds() - start) / 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idSplineList::draw( bool editMode ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
int i;
|
2012-03-17 20:01:54 +00:00
|
|
|
idVec4 yellow( 1, 1, 0, 1 );
|
|
|
|
|
|
|
|
if ( controlPoints.Num() == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dirty ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
buildSpline();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qglColor3fv( controlColor );
|
|
|
|
qglPointSize( 5 );
|
|
|
|
|
|
|
|
qglBegin( GL_POINTS );
|
|
|
|
for ( i = 0; i < controlPoints.Num(); i++ ) {
|
|
|
|
qglVertex3fv( *controlPoints[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
qglEnd();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( editMode ) {
|
|
|
|
for ( i = 0; i < controlPoints.Num(); i++ ) {
|
|
|
|
glBox( activeColor, *controlPoints[i], 4 );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Draw the curve
|
2012-03-17 20:01:54 +00:00
|
|
|
qglColor3fv( pathColor );
|
|
|
|
qglBegin( GL_LINE_STRIP );
|
2007-11-04 03:51:54 +00:00
|
|
|
int count = splinePoints.Num();
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < count; i++ ) {
|
|
|
|
qglVertex3fv( *splinePoints[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
qglEnd();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( editMode ) {
|
|
|
|
qglColor3fv( segmentColor );
|
|
|
|
qglPointSize( 3 );
|
|
|
|
qglBegin( GL_POINTS );
|
|
|
|
for ( i = 0; i < count; i++ ) {
|
|
|
|
qglVertex3fv( *splinePoints[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
qglEnd();
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( count > 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//assert(activeSegment >=0 && activeSegment < count);
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( activeSegment >= 0 && activeSegment < count ) {
|
|
|
|
glBox( activeColor, *splinePoints[activeSegment], 6 );
|
|
|
|
glBox( yellow, *splinePoints[activeSegment], 8 );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
float idSplineList::totalDistance() {
|
|
|
|
|
|
|
|
// FIXME: save dist and return
|
2012-03-17 20:01:54 +00:00
|
|
|
//
|
|
|
|
if ( controlPoints.Num() == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dirty ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
buildSpline();
|
|
|
|
}
|
|
|
|
|
|
|
|
float dist = 0.0;
|
|
|
|
idVec3 temp;
|
|
|
|
int count = splinePoints.Num();
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = 1; i < count; i++ ) {
|
|
|
|
temp = *splinePoints[i - 1];
|
2007-11-04 03:51:54 +00:00
|
|
|
temp -= *splinePoints[i];
|
|
|
|
dist += temp.Length();
|
|
|
|
}
|
|
|
|
return dist;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idSplineList::initPosition( long bt, long totalTime ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dirty ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
buildSpline();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( splinePoints.Num() == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
baseTime = bt;
|
|
|
|
time = totalTime;
|
|
|
|
|
|
|
|
// calc distance to travel ( this will soon be broken into time segments )
|
|
|
|
splineTime.Clear();
|
2012-03-17 20:01:54 +00:00
|
|
|
splineTime.Append( bt );
|
2007-11-04 03:51:54 +00:00
|
|
|
double dist = totalDistance();
|
|
|
|
double distSoFar = 0.0;
|
|
|
|
idVec3 temp;
|
|
|
|
int count = splinePoints.Num();
|
|
|
|
//for(int i = 2; i < count - 1; i++) {
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = 1; i < count; i++ ) {
|
|
|
|
temp = *splinePoints[i - 1];
|
2007-11-04 03:51:54 +00:00
|
|
|
temp -= *splinePoints[i];
|
|
|
|
distSoFar += temp.Length();
|
|
|
|
double percent = distSoFar / dist;
|
|
|
|
percent *= totalTime;
|
2012-03-17 20:01:54 +00:00
|
|
|
splineTime.Append( percent + bt );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
assert( splineTime.Num() == splinePoints.Num() );
|
2007-11-04 03:51:54 +00:00
|
|
|
activeSegment = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
float idSplineList::calcSpline( int step, float tension ) {
|
|
|
|
switch ( step ) {
|
|
|
|
case 0: return ( pow( 1 - tension, 3 ) ) / 6;
|
|
|
|
case 1: return ( 3 * pow( tension, 3 ) - 6 * pow( tension, 2 ) + 4 ) / 6;
|
|
|
|
case 2: return ( -3 * pow( tension, 3 ) + 3 * pow( tension, 2 ) + 3 * tension + 1 ) / 6;
|
|
|
|
case 3: return pow( tension, 3 ) / 6;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idSplineList::updateSelection( const idVec3 &move ) {
|
|
|
|
if ( selected ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
dirty = true;
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorAdd( *selected, move, *selected );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idSplineList::setSelectedPoint( idVec3 *p ) {
|
|
|
|
if ( p ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
p->Snap();
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = 0; i < controlPoints.Num(); i++ ) {
|
|
|
|
if ( *p == *controlPoints[i] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
selected = controlPoints[i];
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-04 03:51:54 +00:00
|
|
|
selected = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
const idVec3 *idSplineList::getPosition( long t ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
static idVec3 interpolatedPos;
|
|
|
|
|
|
|
|
int count = splineTime.Num();
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( count == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return &zero;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Com_Printf("Time: %d\n", t);
|
2012-03-17 20:01:54 +00:00
|
|
|
assert( splineTime.Num() == splinePoints.Num() );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( activeSegment < count ) {
|
|
|
|
if ( splineTime[activeSegment] >= t ) {
|
|
|
|
if ( activeSegment > 0 && activeSegment < count - 1 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
double timeHi = splineTime[activeSegment + 1];
|
|
|
|
double timeLo = splineTime[activeSegment - 1];
|
2012-03-17 20:01:54 +00:00
|
|
|
double percent = ( timeHi - t ) / ( timeHi - timeLo );
|
2007-11-04 03:51:54 +00:00
|
|
|
// pick two bounding points
|
2012-03-17 20:01:54 +00:00
|
|
|
idVec3 v1 = *splinePoints[activeSegment - 1];
|
|
|
|
idVec3 v2 = *splinePoints[activeSegment + 1];
|
|
|
|
v2 *= ( 1.0 - percent );
|
2007-11-04 03:51:54 +00:00
|
|
|
v1 *= percent;
|
|
|
|
v2 += v1;
|
|
|
|
interpolatedPos = v2;
|
|
|
|
return &interpolatedPos;
|
|
|
|
}
|
|
|
|
return splinePoints[activeSegment];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-04 03:51:54 +00:00
|
|
|
activeSegment++;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
return splinePoints[count - 1];
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idSplineList::parse( const char *( *text ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
const char *token;
|
|
|
|
//Com_MatchToken( text, "{" );
|
|
|
|
do {
|
|
|
|
token = Com_Parse( text );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( !token[0] ) {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !Q_stricmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
// if token is not a brace, it is a key for a key/value pair
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !token[0] || !Q_stricmp( token, "(" ) || !Q_stricmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Com_UngetToken();
|
2012-03-17 20:01:54 +00:00
|
|
|
idStr key = Com_ParseOnLine( text );
|
|
|
|
const char *token = Com_Parse( text );
|
|
|
|
if ( Q_stricmp( key.c_str(), "granularity" ) == 0 ) {
|
|
|
|
granularity = atof( token );
|
|
|
|
}
|
|
|
|
else if ( Q_stricmp( key.c_str(), "name" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
name = token;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
token = Com_Parse( text );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !Q_stricmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Com_UngetToken();
|
|
|
|
// read the control point
|
|
|
|
idVec3 point;
|
|
|
|
Com_Parse1DMatrix( text, 3, point );
|
2012-03-17 20:01:54 +00:00
|
|
|
addPoint( point.x, point.y, point.z );
|
|
|
|
} while ( 1 );
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
//Com_UngetToken();
|
|
|
|
//Com_MatchToken( text, "}" );
|
|
|
|
dirty = true;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idSplineList::write( fileHandle_t file, const char *p ) {
|
|
|
|
idStr s = va( "\t\t%s {\n", p );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
//s = va("\t\tname %s\n", name.c_str());
|
|
|
|
//FS_Write(s.c_str(), s.length(), file);
|
2012-03-17 20:01:54 +00:00
|
|
|
s = va( "\t\t\tgranularity %f\n", granularity );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
int count = controlPoints.Num();
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = 0; i < count; i++ ) {
|
|
|
|
s = va( "\t\t\t( %f %f %f )\n", controlPoints[i]->x, controlPoints[i]->y, controlPoints[i]->z );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
s = "\t\t}\n";
|
2012-03-17 20:01:54 +00:00
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraDef::getActiveSegmentInfo( int segment, idVec3 &origin, idVec3 &direction, float *fov ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#if 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !cameraSpline.validTime() ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
buildCamera();
|
|
|
|
}
|
|
|
|
double d = (double)segment / numSegments();
|
2012-03-17 20:01:54 +00:00
|
|
|
getCameraInfo( d * totalTime * 1000, origin, direction, fov );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
if (!cameraSpline.validTime()) {
|
|
|
|
buildCamera();
|
|
|
|
}
|
|
|
|
origin = *cameraSpline.getSegmentPoint(segment);
|
|
|
|
|
|
|
|
|
|
|
|
idVec3 temp;
|
|
|
|
|
|
|
|
int numTargets = getTargetSpline()->controlPoints.Num();
|
|
|
|
int count = cameraSpline.splineTime.Num();
|
|
|
|
if (numTargets == 0) {
|
|
|
|
// follow the path
|
|
|
|
if (cameraSpline.getActiveSegment() < count - 1) {
|
|
|
|
temp = *cameraSpline.splinePoints[cameraSpline.getActiveSegment()+1];
|
|
|
|
}
|
|
|
|
} else if (numTargets == 1) {
|
|
|
|
temp = *getTargetSpline()->controlPoints[0];
|
|
|
|
} else {
|
|
|
|
temp = *getTargetSpline()->getSegmentPoint(segment);
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
temp -= origin;
|
|
|
|
temp.Normalize();
|
|
|
|
direction = temp;
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool idCameraDef::getCameraInfo( long time, idVec3 &origin, idVec3 &direction, float *fv ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
char buff[1024];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( time - startTime ) / 1000 > totalTime ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = 0; i < events.Num(); i++ ) {
|
|
|
|
if ( time >= startTime + events[i]->getTime() && !events[i]->getTriggered() ) {
|
|
|
|
events[i]->setTriggered( true );
|
|
|
|
if ( events[i]->getType() == idCameraEvent::EVENT_TARGET ) {
|
|
|
|
setActiveTargetByName( events[i]->getParam() );
|
|
|
|
getActiveTarget()->start( startTime + events[i]->getTime() );
|
2007-11-04 03:51:54 +00:00
|
|
|
//Com_Printf("Triggered event switch to target: %s\n",events[i]->getParam());
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( events[i]->getType() == idCameraEvent::EVENT_TRIGGER ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//idEntity *ent = NULL;
|
|
|
|
//ent = level.FindTarget( ent, events[i]->getParam());
|
|
|
|
//if (ent) {
|
|
|
|
// ent->signal( SIG_TRIGGER );
|
|
|
|
// ent->ProcessEvent( &EV_Activate, world );
|
|
|
|
//}
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( events[i]->getType() == idCameraEvent::EVENT_FOV ) {
|
|
|
|
memset( buff, 0, sizeof( buff ) );
|
|
|
|
strcpy( buff, events[i]->getParam() );
|
|
|
|
const char *param1 = strtok( buff, " \t,\0" );
|
|
|
|
const char *param2 = strtok( NULL, " \t,\0" );
|
|
|
|
float len = ( param2 ) ? atof( param2 ) : 0;
|
|
|
|
float newfov = ( param1 ) ? atof( param1 ) : 90;
|
|
|
|
fov.reset( fov.getFOV( time ), newfov, time, len );
|
2007-11-04 03:51:54 +00:00
|
|
|
//*fv = fov = atof(events[i]->getParam());
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( events[i]->getType() == idCameraEvent::EVENT_FADEIN ) {
|
|
|
|
float time = atof( events[i]->getParam() );
|
|
|
|
Cbuf_AddText( va( "fade 0 0 0 0 %f", time ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
Cbuf_Execute();
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( events[i]->getType() == idCameraEvent::EVENT_FADEOUT ) {
|
|
|
|
float time = atof( events[i]->getParam() );
|
|
|
|
Cbuf_AddText( va( "fade 0 0 0 255 %f", time ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
Cbuf_Execute();
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( events[i]->getType() == idCameraEvent::EVENT_CAMERA ) {
|
|
|
|
memset( buff, 0, sizeof( buff ) );
|
|
|
|
strcpy( buff, events[i]->getParam() );
|
|
|
|
const char *param1 = strtok( buff, " \t,\0" );
|
|
|
|
const char *param2 = strtok( NULL, " \t,\0" );
|
|
|
|
|
|
|
|
if ( param2 ) {
|
|
|
|
loadCamera( atoi( param1 ), va( "cameras/%s.camera", param2 ) );
|
|
|
|
startCamera( time );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
loadCamera( 0, va( "cameras/%s.camera", events[i]->getParam() ) );
|
|
|
|
startCamera( time );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( events[i]->getType() == idCameraEvent::EVENT_STOP ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
origin = *cameraPosition->getPosition( time );
|
|
|
|
|
|
|
|
*fv = fov.getFOV( time );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
idVec3 temp = origin;
|
|
|
|
|
|
|
|
int numTargets = targetPositions.Num();
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numTargets == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
// follow the path
|
|
|
|
if (cameraSpline.getActiveSegment() < count - 1) {
|
|
|
|
temp = *cameraSpline.splinePoints[cameraSpline.getActiveSegment()+1];
|
|
|
|
if (temp == origin) {
|
|
|
|
int index = cameraSpline.getActiveSegment() + 2;
|
|
|
|
while (temp == origin && index < count - 1) {
|
|
|
|
temp = *cameraSpline.splinePoints[index++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ( getActiveTarget()->numPoints() > 0 ) {
|
|
|
|
temp = *getActiveTarget()->getPosition( time );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
temp -= origin;
|
|
|
|
temp.Normalize();
|
|
|
|
direction = temp;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool idCameraDef::waitEvent( int index ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//for (int i = 0; i < events.Num(); i++) {
|
|
|
|
// if (events[i]->getSegment() == index && events[i]->getType() == idCameraEvent::EVENT_WAIT) {
|
|
|
|
// return true;
|
|
|
|
// }
|
2012-03-17 20:01:54 +00:00
|
|
|
//}
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define NUM_CCELERATION_SEGS 10
|
|
|
|
#define CELL_AMT 5
|
|
|
|
|
|
|
|
void idCameraDef::buildCamera() {
|
|
|
|
int i;
|
|
|
|
idList<float> waits;
|
|
|
|
idList<int> targets;
|
|
|
|
|
|
|
|
totalTime = baseTime;
|
2012-03-17 20:01:54 +00:00
|
|
|
cameraPosition->setTime( (long)totalTime * 1000 );
|
2007-11-04 03:51:54 +00:00
|
|
|
// we have a base time layout for the path and the target path
|
|
|
|
// now we need to layer on any wait or speed changes
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < events.Num(); i++ ) {
|
|
|
|
events[i]->setTriggered( false );
|
|
|
|
switch ( events[i]->getType() ) {
|
|
|
|
case idCameraEvent::EVENT_TARGET: {
|
|
|
|
targets.Append( i );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case idCameraEvent::EVENT_FEATHER: {
|
|
|
|
long startTime = 0;
|
|
|
|
float speed = 0;
|
|
|
|
long loopTime = 10;
|
|
|
|
float stepGoal = cameraPosition->getBaseVelocity() / ( 1000 / loopTime );
|
|
|
|
while ( startTime <= 1000 ) {
|
|
|
|
cameraPosition->addVelocity( startTime, loopTime, speed );
|
|
|
|
speed += stepGoal;
|
|
|
|
if ( speed > cameraPosition->getBaseVelocity() ) {
|
|
|
|
speed = cameraPosition->getBaseVelocity();
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
startTime += loopTime;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
startTime = (long)( totalTime * 1000 - 1000 );
|
|
|
|
long endTime = startTime + 1000;
|
|
|
|
speed = cameraPosition->getBaseVelocity();
|
|
|
|
while ( startTime < endTime ) {
|
|
|
|
speed -= stepGoal;
|
|
|
|
if ( speed < 0 ) {
|
|
|
|
speed = 0;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
cameraPosition->addVelocity( startTime, loopTime, speed );
|
|
|
|
startTime += loopTime;
|
|
|
|
}
|
|
|
|
break;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
case idCameraEvent::EVENT_WAIT: {
|
|
|
|
waits.Append( atof( events[i]->getParam() ) );
|
|
|
|
|
|
|
|
//FIXME: this is quite hacky for Wolf E3, accel and decel needs
|
|
|
|
// do be parameter based etc..
|
|
|
|
long startTime = events[i]->getTime() - 1000;
|
|
|
|
if ( startTime < 0 ) {
|
|
|
|
startTime = 0;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
float speed = cameraPosition->getBaseVelocity();
|
|
|
|
long loopTime = 10;
|
|
|
|
float steps = speed / ( ( events[i]->getTime() - startTime ) / loopTime );
|
|
|
|
while ( startTime <= events[i]->getTime() - loopTime ) {
|
|
|
|
cameraPosition->addVelocity( startTime, loopTime, speed );
|
|
|
|
speed -= steps;
|
|
|
|
startTime += loopTime;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
cameraPosition->addVelocity( events[i]->getTime(), (long)atof( events[i]->getParam() ) * 1000, 0 );
|
|
|
|
|
|
|
|
startTime = (long)( events[i]->getTime() + atof( events[i]->getParam() ) * 1000 );
|
|
|
|
long endTime = startTime + 1000;
|
|
|
|
speed = 0;
|
|
|
|
while ( startTime <= endTime ) {
|
|
|
|
cameraPosition->addVelocity( startTime, loopTime, speed );
|
|
|
|
speed += steps;
|
|
|
|
startTime += loopTime;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case idCameraEvent::EVENT_TARGETWAIT: {
|
|
|
|
//targetWaits.Append(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case idCameraEvent::EVENT_SPEED: {
|
2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
// take the average delay between up to the next five segments
|
|
|
|
float adjust = atof(events[i]->getParam());
|
|
|
|
int index = events[i]->getSegment();
|
|
|
|
total = 0;
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
// get total amount of time over the remainder of the segment
|
|
|
|
for (j = index; j < cameraSpline.numSegments() - 1; j++) {
|
|
|
|
total += cameraSpline.getSegmentTime(j + 1) - cameraSpline.getSegmentTime(j);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// multiply that by the adjustment
|
|
|
|
double newTotal = total * adjust;
|
|
|
|
// what is the difference..
|
|
|
|
newTotal -= total;
|
|
|
|
totalTime += newTotal / 1000;
|
|
|
|
|
|
|
|
// per segment difference
|
|
|
|
newTotal /= count;
|
|
|
|
int additive = newTotal;
|
|
|
|
|
|
|
|
// now propogate that difference out to each segment
|
|
|
|
for (j = index; j < cameraSpline.numSegments(); j++) {
|
|
|
|
cameraSpline.addSegmentTime(j, additive);
|
|
|
|
additive += newTotal;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
}
|
2013-05-03 06:57:29 +00:00
|
|
|
default:
|
|
|
|
break;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < waits.Num(); i++ ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
totalTime += waits[i];
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// on a new target switch, we need to take time to this point ( since last target switch )
|
2007-11-04 03:51:54 +00:00
|
|
|
// and allocate it across the active target, then reset time to this point
|
|
|
|
long timeSoFar = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
long total = (long)( totalTime * 1000 );
|
|
|
|
for ( i = 0; i < targets.Num(); i++ ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
long t;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i < targets.Num() - 1 ) {
|
|
|
|
t = events[targets[i + 1]]->getTime();
|
|
|
|
}
|
|
|
|
else {
|
2007-11-04 03:51:54 +00:00
|
|
|
t = total - timeSoFar;
|
|
|
|
}
|
|
|
|
// t is how much time to use for this target
|
2012-03-17 20:01:54 +00:00
|
|
|
setActiveTargetByName( events[targets[i]]->getParam() );
|
|
|
|
getActiveTarget()->setTime( t );
|
2007-11-04 03:51:54 +00:00
|
|
|
timeSoFar += t;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraDef::startCamera( long t ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
cameraPosition->clearVelocities();
|
2012-03-17 20:01:54 +00:00
|
|
|
cameraPosition->start( t );
|
2007-11-04 03:51:54 +00:00
|
|
|
buildCamera();
|
2012-03-17 20:01:54 +00:00
|
|
|
fov.reset( 90, 90, t, 0 );
|
2007-11-04 03:51:54 +00:00
|
|
|
//for (int i = 0; i < targetPositions.Num(); i++) {
|
|
|
|
// targetPositions[i]->
|
|
|
|
//}
|
|
|
|
startTime = t;
|
|
|
|
cameraRunning = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraDef::parse( const char *( *text ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
const char *token;
|
2007-11-04 03:51:54 +00:00
|
|
|
do {
|
|
|
|
token = Com_Parse( text );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( !token[0] ) {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !Q_stricmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( Q_stricmp( token, "time" ) == 0 ) {
|
|
|
|
baseTime = Com_ParseFloat( text );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( Q_stricmp( token, "camera_fixed" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
cameraPosition = new idFixedPosition();
|
2012-03-17 20:01:54 +00:00
|
|
|
cameraPosition->parse( text );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( Q_stricmp( token, "camera_interpolated" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
cameraPosition = new idInterpolatedPosition();
|
2012-03-17 20:01:54 +00:00
|
|
|
cameraPosition->parse( text );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( Q_stricmp( token, "camera_spline" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
cameraPosition = new idSplinePosition();
|
2012-03-17 20:01:54 +00:00
|
|
|
cameraPosition->parse( text );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( Q_stricmp( token, "target_fixed" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
idFixedPosition *pos = new idFixedPosition();
|
2012-03-17 20:01:54 +00:00
|
|
|
pos->parse( text );
|
|
|
|
targetPositions.Append( pos );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( Q_stricmp( token, "target_interpolated" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
idInterpolatedPosition *pos = new idInterpolatedPosition();
|
2012-03-17 20:01:54 +00:00
|
|
|
pos->parse( text );
|
|
|
|
targetPositions.Append( pos );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( Q_stricmp( token, "target_spline" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
idSplinePosition *pos = new idSplinePosition();
|
2012-03-17 20:01:54 +00:00
|
|
|
pos->parse( text );
|
|
|
|
targetPositions.Append( pos );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( Q_stricmp( token, "fov" ) == 0 ) {
|
|
|
|
fov.parse( text );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( Q_stricmp( token, "event" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
idCameraEvent *event = new idCameraEvent();
|
2012-03-17 20:01:54 +00:00
|
|
|
event->parse( text );
|
|
|
|
addEvent( event );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
if ( !cameraPosition ) {
|
|
|
|
Com_Printf( "no camera position specified\n" );
|
|
|
|
// prevent a crash later on
|
|
|
|
cameraPosition = new idFixedPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
Com_UngetToken();
|
|
|
|
Com_MatchToken( text, "}" );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool idCameraDef::load( const char *filename ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
char *buf;
|
|
|
|
const char *buf_p;
|
2012-03-17 22:09:08 +00:00
|
|
|
|
|
|
|
FS_ReadFile( filename, (void **)&buf );
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( !buf ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear();
|
|
|
|
Com_BeginParseSession( filename );
|
|
|
|
buf_p = buf;
|
2012-03-17 20:01:54 +00:00
|
|
|
parse( &buf_p );
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_EndParseSession();
|
|
|
|
FS_FreeFile( buf );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraDef::save( const char *filename ) {
|
|
|
|
fileHandle_t file = FS_FOpenFileWrite( filename );
|
|
|
|
if ( file ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
int i;
|
2012-03-17 20:01:54 +00:00
|
|
|
idStr s = "cameraPathDef { \n";
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
|
|
|
s = va( "\ttime %f\n", baseTime );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cameraPosition->write( file, va( "camera_%s",cameraPosition->typeStr() ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numTargets(); i++ ) {
|
|
|
|
targetPositions[i]->write( file, va( "target_%s", targetPositions[i]->typeStr() ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < events.Num(); i++ ) {
|
|
|
|
events[i]->write( file, "event" );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fov.write( file, "fov" );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
s = "}\n";
|
2012-03-17 20:01:54 +00:00
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
FS_FCloseFile( file );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int idCameraDef::sortEvents( const void *p1, const void *p2 ) {
|
|
|
|
idCameraEvent *ev1 = (idCameraEvent*)( p1 );
|
|
|
|
idCameraEvent *ev2 = (idCameraEvent*)( p2 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ev1->getTime() > ev2->getTime() ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ev1->getTime() < ev2->getTime() ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
return 0;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraDef::addEvent( idCameraEvent *event ) {
|
|
|
|
events.Append( event );
|
2007-11-04 03:51:54 +00:00
|
|
|
//events.Sort(&sortEvents);
|
|
|
|
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraDef::addEvent( idCameraEvent::eventType t, const char *param, long time ) {
|
|
|
|
addEvent( new idCameraEvent( t, param, time ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
buildCamera();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraDef::removeEvent( int index ) {
|
|
|
|
events.RemoveIndex( index );
|
2007-11-04 03:51:54 +00:00
|
|
|
buildCamera();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *idCameraEvent::eventStr[] = {
|
|
|
|
"NA",
|
|
|
|
"WAIT",
|
|
|
|
"TARGETWAIT",
|
|
|
|
"SPEED",
|
|
|
|
"TARGET",
|
|
|
|
"SNAPTARGET",
|
|
|
|
"FOV",
|
|
|
|
"CMD",
|
|
|
|
"TRIGGER",
|
|
|
|
"STOP",
|
|
|
|
"CAMERA",
|
|
|
|
"FADEOUT",
|
|
|
|
"FADEIN",
|
|
|
|
"FEATHER"
|
|
|
|
};
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraEvent::parse( const char *( *text ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
const char *token;
|
|
|
|
Com_MatchToken( text, "{" );
|
|
|
|
do {
|
|
|
|
token = Com_Parse( text );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( !token[0] ) {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// here we may have to jump over brush epairs ( only used in editor )
|
|
|
|
do {
|
|
|
|
// if token is not a brace, it is a key for a key/value pair
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !token[0] || !strcmp( token, "(" ) || !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Com_UngetToken();
|
2012-03-17 20:01:54 +00:00
|
|
|
idStr key = Com_ParseOnLine( text );
|
|
|
|
const char *token = Com_Parse( text );
|
|
|
|
if ( Q_stricmp( key.c_str(), "type" ) == 0 ) {
|
|
|
|
type = static_cast<idCameraEvent::eventType>( atoi( token ) );
|
|
|
|
}
|
|
|
|
else if ( Q_stricmp( key.c_str(), "param" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
paramStr = token;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( Q_stricmp( key.c_str(), "time" ) == 0 ) {
|
|
|
|
time = atoi( token );
|
|
|
|
}
|
|
|
|
token = Com_Parse( text );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_UngetToken();
|
|
|
|
Com_MatchToken( text, "}" );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraEvent::write( fileHandle_t file, const char *name ) {
|
|
|
|
idStr s = va( "\t%s {\n", name );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
|
|
|
s = va( "\t\ttype %d\n", static_cast<int>( type ) );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
|
|
|
s = va( "\t\tparam \"%s\"\n", paramStr.c_str() );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
|
|
|
s = va( "\t\ttime %d\n", time );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
s = "\t}\n";
|
2012-03-17 20:01:54 +00:00
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *idCameraPosition::positionStr[] = {
|
|
|
|
"Fixed",
|
|
|
|
"Interpolated",
|
|
|
|
"Spline",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
const idVec3 *idInterpolatedPosition::getPosition( long t ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
static idVec3 interpolatedPos;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
float velocity = getVelocity( t );
|
2007-11-04 03:51:54 +00:00
|
|
|
float timePassed = t - lastTime;
|
|
|
|
lastTime = t;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// convert to seconds
|
2007-11-04 03:51:54 +00:00
|
|
|
timePassed /= 1000;
|
|
|
|
|
|
|
|
float distToTravel = timePassed * velocity;
|
|
|
|
|
|
|
|
idVec3 temp = startPos;
|
|
|
|
temp -= endPos;
|
|
|
|
float distance = temp.Length();
|
|
|
|
|
|
|
|
distSoFar += distToTravel;
|
2012-03-17 20:01:54 +00:00
|
|
|
float percent = (float)( distSoFar ) / distance;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( percent > 1.0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
percent = 1.0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( percent < 0.0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
percent = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the following line does a straigt calc on percentage of time
|
|
|
|
// float percent = (float)(startTime + time - t) / time;
|
|
|
|
|
|
|
|
idVec3 v1 = startPos;
|
|
|
|
idVec3 v2 = endPos;
|
2012-03-17 20:01:54 +00:00
|
|
|
v1 *= ( 1.0 - percent );
|
2007-11-04 03:51:54 +00:00
|
|
|
v2 *= percent;
|
|
|
|
v1 += v2;
|
|
|
|
interpolatedPos = v1;
|
|
|
|
return &interpolatedPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraFOV::parse( const char *( *text ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
const char *token;
|
|
|
|
Com_MatchToken( text, "{" );
|
|
|
|
do {
|
|
|
|
token = Com_Parse( text );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( !token[0] ) {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// here we may have to jump over brush epairs ( only used in editor )
|
|
|
|
do {
|
|
|
|
// if token is not a brace, it is a key for a key/value pair
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !token[0] || !strcmp( token, "(" ) || !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Com_UngetToken();
|
2012-03-17 20:01:54 +00:00
|
|
|
idStr key = Com_ParseOnLine( text );
|
|
|
|
const char *token = Com_Parse( text );
|
|
|
|
if ( Q_stricmp( key.c_str(), "fov" ) == 0 ) {
|
|
|
|
fov = atof( token );
|
|
|
|
}
|
|
|
|
else if ( Q_stricmp( key.c_str(), "startFOV" ) == 0 ) {
|
|
|
|
startFOV = atof( token );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( Q_stricmp( key.c_str(), "endFOV" ) == 0 ) {
|
|
|
|
endFOV = atof( token );
|
|
|
|
}
|
|
|
|
else if ( Q_stricmp( key.c_str(), "time" ) == 0 ) {
|
|
|
|
time = atoi( token );
|
|
|
|
}
|
|
|
|
token = Com_Parse( text );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_UngetToken();
|
|
|
|
Com_MatchToken( text, "}" );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool idCameraPosition::parseToken( const char *key, const char *( *text ) ) {
|
|
|
|
const char *token = Com_Parse( text );
|
|
|
|
if ( Q_stricmp( key, "time" ) == 0 ) {
|
|
|
|
time = atol( token );
|
2007-11-04 03:51:54 +00:00
|
|
|
return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( Q_stricmp( key, "type" ) == 0 ) {
|
|
|
|
type = static_cast<idCameraPosition::positionType>( atoi( token ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( Q_stricmp( key, "velocity" ) == 0 ) {
|
|
|
|
long t = atol( token );
|
|
|
|
token = Com_Parse( text );
|
|
|
|
long d = atol( token );
|
|
|
|
token = Com_Parse( text );
|
|
|
|
float s = atof( token );
|
|
|
|
addVelocity( t, d, s );
|
2007-11-04 03:51:54 +00:00
|
|
|
return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( Q_stricmp( key, "baseVelocity" ) == 0 ) {
|
|
|
|
baseVelocity = atof( token );
|
2007-11-04 03:51:54 +00:00
|
|
|
return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( Q_stricmp( key, "name" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
name = token;
|
|
|
|
return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( Q_stricmp( key, "time" ) == 0 ) {
|
|
|
|
time = atoi( token );
|
2007-11-04 03:51:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Com_UngetToken();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idFixedPosition::parse( const char *( *text ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
const char *token;
|
|
|
|
Com_MatchToken( text, "{" );
|
|
|
|
do {
|
|
|
|
token = Com_Parse( text );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( !token[0] ) {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// here we may have to jump over brush epairs ( only used in editor )
|
|
|
|
do {
|
|
|
|
// if token is not a brace, it is a key for a key/value pair
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !token[0] || !strcmp( token, "(" ) || !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Com_UngetToken();
|
2012-03-17 20:01:54 +00:00
|
|
|
idStr key = Com_ParseOnLine( text );
|
|
|
|
|
|
|
|
const char *token = Com_Parse( text );
|
|
|
|
if ( Q_stricmp( key.c_str(), "pos" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_UngetToken();
|
|
|
|
Com_Parse1DMatrix( text, 3, pos );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_UngetToken();
|
2012-03-17 20:01:54 +00:00
|
|
|
idCameraPosition::parseToken( key.c_str(), text );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
token = Com_Parse( text );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_UngetToken();
|
|
|
|
Com_MatchToken( text, "}" );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idInterpolatedPosition::parse( const char *( *text ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
const char *token;
|
|
|
|
Com_MatchToken( text, "{" );
|
|
|
|
do {
|
|
|
|
token = Com_Parse( text );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( !token[0] ) {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// here we may have to jump over brush epairs ( only used in editor )
|
|
|
|
do {
|
|
|
|
// if token is not a brace, it is a key for a key/value pair
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !token[0] || !strcmp( token, "(" ) || !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Com_UngetToken();
|
2012-03-17 20:01:54 +00:00
|
|
|
idStr key = Com_ParseOnLine( text );
|
|
|
|
|
|
|
|
const char *token = Com_Parse( text );
|
|
|
|
if ( Q_stricmp( key.c_str(), "startPos" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_UngetToken();
|
|
|
|
Com_Parse1DMatrix( text, 3, startPos );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( Q_stricmp( key.c_str(), "endPos" ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_UngetToken();
|
|
|
|
Com_Parse1DMatrix( text, 3, endPos );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_UngetToken();
|
2012-03-17 20:01:54 +00:00
|
|
|
idCameraPosition::parseToken( key.c_str(), text );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
token = Com_Parse( text );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_UngetToken();
|
|
|
|
Com_MatchToken( text, "}" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idSplinePosition::parse( const char *( *text ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
const char *token;
|
|
|
|
Com_MatchToken( text, "{" );
|
|
|
|
do {
|
|
|
|
token = Com_Parse( text );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( !token[0] ) {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// here we may have to jump over brush epairs ( only used in editor )
|
|
|
|
do {
|
|
|
|
// if token is not a brace, it is a key for a key/value pair
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !token[0] || !strcmp( token, "(" ) || !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Com_UngetToken();
|
2012-03-17 20:01:54 +00:00
|
|
|
idStr key = Com_ParseOnLine( text );
|
|
|
|
|
|
|
|
const char *token = Com_Parse( text );
|
|
|
|
if ( Q_stricmp( key.c_str(), "target" ) == 0 ) {
|
|
|
|
target.parse( text );
|
|
|
|
}
|
|
|
|
else {
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_UngetToken();
|
2012-03-17 20:01:54 +00:00
|
|
|
idCameraPosition::parseToken( key.c_str(), text );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
token = Com_Parse( text );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
Com_UngetToken();
|
|
|
|
Com_MatchToken( text, "}" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraFOV::write( fileHandle_t file, const char *p ) {
|
|
|
|
idStr s = va( "\t%s {\n", p );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
|
|
|
|
|
|
|
s = va( "\t\tfov %f\n", fov );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
s = va( "\t\tstartFOV %f\n", startFOV );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
s = va( "\t\tendFOV %f\n", endFOV );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
s = va( "\t\ttime %i\n", time );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
s = "\t}\n";
|
2012-03-17 20:01:54 +00:00
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraPosition::write( fileHandle_t file, const char *p ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
idStr s = va( "\t\ttime %i\n", time );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
s = va( "\t\ttype %i\n", static_cast<int>( type ) );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
s = va( "\t\tname %s\n", name.c_str() );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
s = va( "\t\tbaseVelocity %f\n", baseVelocity );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
|
|
|
|
|
|
|
for ( int i = 0; i < velocities.Num(); i++ ) {
|
|
|
|
s = va( "\t\tvelocity %i %i %f\n", velocities[i]->startTime, velocities[i]->time, velocities[i]->speed );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idFixedPosition::write( fileHandle_t file, const char *p ) {
|
|
|
|
idStr s = va( "\t%s {\n", p );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
|
|
|
idCameraPosition::write( file, p );
|
|
|
|
s = va( "\t\tpos ( %f %f %f )\n", pos.x, pos.y, pos.z );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
s = "\t}\n";
|
2012-03-17 20:01:54 +00:00
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idInterpolatedPosition::write( fileHandle_t file, const char *p ) {
|
|
|
|
idStr s = va( "\t%s {\n", p );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
|
|
|
idCameraPosition::write( file, p );
|
|
|
|
s = va( "\t\tstartPos ( %f %f %f )\n", startPos.x, startPos.y, startPos.z );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
|
|
|
s = va( "\t\tendPos ( %f %f %f )\n", endPos.x, endPos.y, endPos.z );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
s = "\t}\n";
|
2012-03-17 20:01:54 +00:00
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idSplinePosition::write( fileHandle_t file, const char *p ) {
|
|
|
|
idStr s = va( "\t%s {\n", p );
|
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
|
|
|
idCameraPosition::write( file, p );
|
|
|
|
target.write( file, "target" );
|
2007-11-04 03:51:54 +00:00
|
|
|
s = "\t}\n";
|
2012-03-17 20:01:54 +00:00
|
|
|
FS_Write( s.c_str(), s.length(), file );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void idCameraDef::addTarget( const char *name, idCameraPosition::positionType type ) {
|
|
|
|
idCameraPosition *pos = newFromType( type );
|
|
|
|
if ( pos ) {
|
|
|
|
pos->setName( name );
|
|
|
|
targetPositions.Append( pos );
|
|
|
|
activeTarget = numTargets() - 1;
|
|
|
|
if ( activeTarget == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
// first one
|
2012-03-17 20:01:54 +00:00
|
|
|
addEvent( idCameraEvent::EVENT_TARGET, name, 0 );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
const idVec3 *idSplinePosition::getPosition( long t ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
static idVec3 interpolatedPos;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
float velocity = getVelocity( t );
|
2007-11-04 03:51:54 +00:00
|
|
|
float timePassed = t - lastTime;
|
|
|
|
lastTime = t;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// convert to seconds
|
2007-11-04 03:51:54 +00:00
|
|
|
timePassed /= 1000;
|
|
|
|
|
|
|
|
float distToTravel = timePassed * velocity;
|
|
|
|
|
|
|
|
distSoFar += distToTravel;
|
|
|
|
double tempDistance = target.totalDistance();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
double percent = (double)( distSoFar ) / tempDistance;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
double targetDistance = percent * tempDistance;
|
|
|
|
tempDistance = 0;
|
|
|
|
|
|
|
|
double lastDistance1,lastDistance2;
|
|
|
|
lastDistance1 = lastDistance2 = 0;
|
|
|
|
idVec3 temp;
|
|
|
|
int count = target.numSegments();
|
|
|
|
int i;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 1; i < count; i++ ) {
|
|
|
|
temp = *target.getSegmentPoint( i - 1 );
|
|
|
|
temp -= *target.getSegmentPoint( i );
|
2007-11-04 03:51:54 +00:00
|
|
|
tempDistance += temp.Length();
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i & 1 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
lastDistance1 = tempDistance;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-04 03:51:54 +00:00
|
|
|
lastDistance2 = tempDistance;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( tempDistance >= targetDistance ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i >= count - 1 ) {
|
|
|
|
interpolatedPos = *target.getSegmentPoint( i - 1 );
|
|
|
|
}
|
|
|
|
else {
|
2007-11-04 03:51:54 +00:00
|
|
|
#if 0
|
2012-03-17 20:01:54 +00:00
|
|
|
double timeHi = target.getSegmentTime( i + 1 );
|
|
|
|
double timeLo = target.getSegmentTime( i - 1 );
|
|
|
|
double percent = ( timeHi - t ) / ( timeHi - timeLo );
|
|
|
|
idVec3 v1 = *target.getSegmentPoint( i - 1 );
|
|
|
|
idVec3 v2 = *target.getSegmentPoint( i + 1 );
|
|
|
|
v2 *= ( 1.0 - percent );
|
2007-11-04 03:51:54 +00:00
|
|
|
v1 *= percent;
|
|
|
|
v2 += v1;
|
|
|
|
interpolatedPos = v2;
|
|
|
|
#else
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( lastDistance1 > lastDistance2 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
double d = lastDistance2;
|
|
|
|
lastDistance2 = lastDistance1;
|
|
|
|
lastDistance1 = d;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
idVec3 v1 = *target.getSegmentPoint( i - 1 );
|
|
|
|
idVec3 v2 = *target.getSegmentPoint( i );
|
|
|
|
double percent = ( lastDistance2 - targetDistance ) / ( lastDistance2 - lastDistance1 );
|
|
|
|
v2 *= ( 1.0 - percent );
|
2007-11-04 03:51:54 +00:00
|
|
|
v1 *= percent;
|
|
|
|
v2 += v1;
|
|
|
|
interpolatedPos = v2;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return &interpolatedPos;
|
|
|
|
|
|
|
|
}
|