2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
32 extern void glBox(idVec4 &color, idVec3 &point, float size);
33 extern void glLabeledPoint(idVec4 &color, idVec3 &point, float size, const char *label);
36 class idPointListInterface {
38 idPointListInterface() { selectedPoints.Clear(); };
39 ~idPointListInterface() {};
41 virtual int numPoints() { return 0; }
42 virtual void addPoint( const float x, const float y, const float z ) {}
43 virtual void addPoint( const idVec3 &v ) {}
44 virtual void removePoint( int index ) {}
45 virtual idVec3 * getPoint( int index ) { return NULL; }
47 int numSelectedPoints() { return selectedPoints.Num(); }
48 idVec3 * getSelectedPoint( int index );
49 int selectPointByRay( const idVec3 &origin, const idVec3 &direction, bool single );
50 int isPointSelected( int index );
51 int selectPoint( int index, bool single );
54 virtual void updateSelection( const idVec3 &move );
58 idList<int> selectedPoints;
63 friend class idCamera;
67 idSplineList() { clear(); }
68 idSplineList( const char *p ) { clear(); name = p; }
69 ~idSplineList() { clear(); }
73 void parse( idParser *src );
74 void write( idFile *f, const char *name );
77 void initPosition( long startTime, long totalTime );
78 const idVec3 * getPosition( long time );
80 void draw( bool editMode );
83 void setSelectedPoint( idVec3 *p );
84 idVec3 * getSelectedPoint() { return selected; }
86 void addPoint( const idVec3 &v ) { controlPoints.Append(new idVec3(v) ); dirty = true; }
87 void addPoint( float x, float y, float z ) { controlPoints.Append(new idVec3(x, y, z)); dirty = true; }
89 void updateSelection(const idVec3 &move);
90 void startEdit() { editMode = true; }
91 void stopEdit() { editMode = false; }
93 void setGranularity( float f ) { granularity = f; }
94 float getGranularity() { return granularity; }
96 int numPoints() { return controlPoints.Num(); }
97 idVec3 * getPoint(int index) { assert(index >= 0 && index < controlPoints.Num()); return controlPoints[index]; }
98 idVec3 * getSegmentPoint(int index) { assert(index >= 0 && index < splinePoints.Num()); return splinePoints[index]; }
99 void setSegmentTime(int index, int time) { assert(index >= 0 && index < splinePoints.Num()); splineTime[index] = time; }
100 int getSegmentTime(int index) { assert(index >= 0 && index < splinePoints.Num()); return splineTime[index]; }
101 void addSegmentTime(int index, int time) { assert(index >= 0 && index < splinePoints.Num()); splineTime[index] += time; }
102 float totalDistance();
104 int getActiveSegment() { return activeSegment; }
105 void setActiveSegment( int i ) { /* assert(i >= 0 && (splinePoints.Num() > 0 && i < splinePoints.Num())); */ activeSegment = i; }
106 int numSegments() { return splinePoints.Num(); }
108 void setColors(idVec4 &path, idVec4 &segment, idVec4 &control, idVec4 &active);
110 const char * getName() { return name.c_str(); }
111 void setName( const char *p ) { name = p; }
114 void setTime( long t ) { time = t; }
115 void setBaseTime( long t ) { baseTime = t; }
119 float calcSpline(int step, float tension);
120 idList<idVec3*> controlPoints;
121 idList<idVec3*> splinePoints;
122 idList<double> splineTime;
124 idVec4 pathColor, segmentColor, controlColor, activeColor;
133 // time in milliseconds
134 // velocity where 1.0 equal rough walking speed
136 idVelocity( long start, long duration, float s ) { startTime = start; time = duration; speed = s; }
142 // can either be a look at or origin position for a camera
143 class idCameraPosition : public idPointListInterface {
146 idCameraPosition() { time = 0; name = "position"; }
147 idCameraPosition( const char *p ) { name = p; }
148 idCameraPosition( long t ) { time = t; }
149 virtual ~idCameraPosition() { clear(); }
151 // this can be done with RTTI syntax but i like the derived classes setting a type
152 // makes serialization a bit easier to see
161 virtual void clearVelocities();
162 virtual void clear() { editMode = false; time = 5000; clearVelocities(); }
163 virtual void start( long t ) { startTime = t; }
164 long getTime() { return time; }
165 virtual void setTime(long t) { time = t; }
166 float getVelocity( long t );
167 float getBaseVelocity() { return baseVelocity; }
168 void addVelocity( long start, long duration, float speed ) { velocities.Append(new idVelocity(start, duration, speed)); }
169 virtual const idVec3 *getPosition( long t ) { return NULL; }
170 virtual void draw( bool editMode ) {};
171 virtual void parse( idParser *src ) {};
172 virtual void write( idFile *f, const char *name);
173 virtual bool parseToken( const idStr &key, idParser *src );
174 const char * getName() { return name.c_str(); }
175 void setName( const char *p ) { name = p; }
176 virtual void startEdit() { editMode = true; }
177 virtual void stopEdit() { editMode = false; }
178 virtual void draw() {};
179 const char * typeStr() { return positionStr[static_cast<int>(type)]; }
180 void calcVelocity( float distance ) { float secs = (float)time / 1000; baseVelocity = distance / secs; }
183 static const char * positionStr[POSITION_COUNT];
189 idList<idVelocity*> velocities;
193 class idFixedPosition : public idCameraPosition {
196 idFixedPosition() : idCameraPosition() { init(); }
197 idFixedPosition(idVec3 p) : idCameraPosition() { init(); pos = p; }
198 ~idFixedPosition() { }
200 void init() { pos.Zero(); type = idCameraPosition::FIXED; }
202 virtual void addPoint( const idVec3 &v ) { pos = v; }
203 virtual void addPoint( const float x, const float y, const float z ) { pos.Set(x, y, z); }
204 virtual const idVec3 *getPosition( long t ) { return &pos; }
205 void parse( idParser *src );
206 void write( idFile *f, const char *name );
207 virtual int numPoints() { return 1; }
208 virtual idVec3 * getPoint( int index ) { assert( index == 0 ); return &pos; }
209 virtual void draw( bool editMode ) { glLabeledPoint(colorBlue, pos, (editMode) ? 5 : 3, "Fixed point"); }
215 class idInterpolatedPosition : public idCameraPosition {
217 idInterpolatedPosition() : idCameraPosition() { init(); }
218 idInterpolatedPosition( idVec3 start, idVec3 end, long time ) : idCameraPosition(time) { init(); startPos = start; endPos = end; }
219 ~idInterpolatedPosition() { }
221 void init() { type = idCameraPosition::INTERPOLATED; first = true; startPos.Zero(); endPos.Zero(); }
223 virtual const idVec3 *getPosition(long t);
224 void parse( idParser *src );
225 void write( idFile *f, const char *name );
226 virtual int numPoints() { return 2; }
227 virtual idVec3 * getPoint( int index );
228 virtual void addPoint( const float x, const float y, const float z );
229 virtual void addPoint( const idVec3 &v );
230 virtual void draw( bool editMode );
231 virtual void start( long t );
241 class idSplinePosition : public idCameraPosition {
244 idSplinePosition() : idCameraPosition() { init(); }
245 idSplinePosition( long time ) : idCameraPosition( time ) { init(); }
246 ~idSplinePosition() { }
248 void init() { type = idCameraPosition::SPLINE; }
249 virtual void start( long t );
250 virtual const idVec3 *getPosition( long t );
251 void addControlPoint( idVec3 &v ) { target.addPoint(v); }
252 void parse( idParser *src );
253 void write( idFile *f, const char *name );
254 virtual int numPoints() { return target.numPoints(); }
255 virtual idVec3 * getPoint( int index ) { return target.getPoint(index); }
256 virtual void addPoint( const idVec3 &v ) { target.addPoint( v ); }
257 virtual void draw( bool editMode ) { target.draw( editMode ); }
258 virtual void updateSelection( const idVec3 &move ) { idCameraPosition::updateSelection(move); target.buildSpline(); }
268 idCameraFOV() { time = 0; fov = 90; }
269 idCameraFOV( int v ) { time = 0; fov = v; }
270 idCameraFOV( int s, int e, long t ) { startFOV = s; endFOV = e; time = t; }
273 void SetFOV( float f ) { fov = f; }
274 float GetFOV( long t );
275 void start( long t ) { startTime = t; }
276 void reset( float startfov, float endfov, int start, int len );
277 void parse( idParser *src );
278 void write( idFile *f, const char *name );
289 class idCameraEvent {
309 idCameraEvent() { paramStr = ""; type = EVENT_NA; time = 0; }
310 idCameraEvent( eventType t, const char *param, long n ) { type = t; paramStr = param; time = n; }
313 eventType getType() { return type; }
314 const char * typeStr() { return eventStr[static_cast<int>(type)]; }
315 const char * getParam() { return paramStr.c_str(); }
316 long getTime() { return time; }
317 void setTime(long n) { time = n; }
318 void parse( idParser *src );
319 void write( idFile *f, const char *name );
320 void setTriggered( bool b ) { triggered = b; }
321 bool getTriggered() { return triggered; }
323 static const char * eventStr[EVENT_COUNT];
335 idCameraDef() { cameraPosition = NULL; clear(); }
336 ~idCameraDef() { clear(); }
339 idCameraPosition * startNewCamera(idCameraPosition::positionType type);
340 void addEvent( idCameraEvent::eventType t, const char *param, long time );
341 void addEvent( idCameraEvent *event );
342 static int sortEvents( const void *p1, const void *p2 );
343 int numEvents() { return events.Num(); }
344 idCameraEvent * getEvent(int index) { assert(index >= 0 && index < events.Num()); return events[index]; }
345 void parse( idParser *src );
346 bool load( const char *filename );
347 void save( const char *filename );
350 void addTarget( const char *name, idCameraPosition::positionType type );
352 idCameraPosition * getActiveTarget();
353 idCameraPosition * getActiveTarget( int index );
354 int numTargets() { return targetPositions.Num(); }
355 void setActiveTargetByName(const char *name);
356 void setActiveTarget( int index );
357 void setRunning( bool b ) { cameraRunning = b; }
358 void setBaseTime( float f ) { baseTime = f; }
359 float getBaseTime() { return baseTime; }
360 float getTotalTime() { return totalTime; }
361 void startCamera( long t );
362 void stopCamera() { cameraRunning = true; }
363 void getActiveSegmentInfo(int segment, idVec3 &origin, idVec3 &direction, float *fv);
364 bool getCameraInfo(long time, idVec3 &origin, idVec3 &direction, float *fv);
365 void draw( bool editMode );
367 const idVec3 * getPoint( int index );
369 void startEdit( bool camera );
370 bool waitEvent( int index );
371 const char * getName() { return name.c_str(); }
372 void setName( const char *p ) { name = p; }
373 idCameraPosition * getPositionObj();
375 static idCameraPosition *newFromType( idCameraPosition::positionType t );
379 int currentCameraPosition;
380 idVec3 lastDirection;
382 idCameraPosition * cameraPosition;
383 idList<idCameraPosition*> targetPositions;
384 idList<idCameraEvent*> events;
395 extern bool g_splineMode;
397 extern idCameraDef *g_splineList;
399 #endif /* !__SPLINES_H__ */