29 #include "../../idlib/precompiled.h"
153 for (i=0; i <
count; i++) {
158 VectorMA (origin, d, direction, temp);
377 for (
float tension = 0.0
f; tension < 1.001f; tension += 0.1f) {
381 for (
int j = 0;
j < 4;
j++) {
409 for (
float tension = 0.0
f; tension < 1.001f; tension +=
granularity) {
413 for (
int j = 0;
j < 4;
j++) {
461 for (i = 0; i <
count; i++) {
470 for (i = 0; i <
count; i++) {
535 double distSoFar = 0.0;
542 distSoFar += temp.
Length();
543 double percent = distSoFar / dist;
544 percent *= totalTime;
558 case 0:
return (pow(1 - tension, 3)) / 6;
559 case 1:
return (3 * pow(tension, 3) - 6 * pow(tension, 2) + 4) / 6;
560 case 2:
return (-3 * pow(tension, 3) + 3 * pow(tension, 2) + 3 * tension + 1) / 6;
561 case 3:
return pow(tension, 3) / 6;
602 static idVec3 interpolatedPos;
612 float velocity = getVelocity(t);
613 float timePassed = t - lastTime;
619 float distToTravel = timePassed * velocity;
621 distSoFar += distToTravel;
622 float tempDistance = 0;
630 tempDistance += temp.
Length();
631 if (tempDistance >= distSoFar) {
641 double percent = (timeHi -
t) / (timeHi - timeLo);
644 v2 *= (1.0f - percent);
647 interpolatedPos =
v2;
649 return &interpolatedPos;
658 double percent = (timeHi -
t) / (timeHi - timeLo);
662 v2 *= (1.0f - percent);
665 interpolatedPos =
v2;
666 return &interpolatedPos;
692 if ( token ==
"}" ) {
696 if ( token ==
"(" ) {
706 if ( !key.
Icmp(
"granularity" ) ) {
709 else if ( !key.
Icmp(
"name" ) ) {
713 src->
Error(
"unknown spline list key: %s", key.
c_str() );
727 f->
Printf(
"\t\t%s {\n", p );
950 if (!cameraSpline.validTime()) {
953 double d = (double)segment / numSegments();
1013 memset(buff, 0,
sizeof(buff));
1014 strcpy(buff,
events[i]->getParam());
1015 const char *param1 = strtok(buff,
" \t,\0");
1016 const char *param2 = strtok(
NULL,
" \t,\0");
1035 if (numTargets == 0) {
1078 #define NUM_CCELERATION_SEGS 10
1093 events[
i]->setTriggered(
false);
1094 switch (
events[i]->getType()) {
1104 while (startTime <= 1000) {
1110 startTime += loopTime;
1114 long endTime = startTime + 1000;
1116 while (startTime < endTime) {
1122 startTime += loopTime;
1133 if (startTime < 0) {
1139 while (startTime <=
events[i]->getTime() - loopTime) {
1142 startTime += loopTime;
1146 startTime =
events[
i]->getTime() + atof(
events[i]->getParam()) * 1000;
1147 long endTime = startTime + 1000;
1149 while (startTime <= endTime) {
1152 startTime += loopTime;
1196 for (i = 0; i < waits.
Num(); i++) {
1204 for (i = 0; i < targets.
Num(); i++) {
1206 if (i < targets.
Num() - 1) {
1207 t =
events[targets[i+1]]->getTime();
1209 t = total - timeSoFar;
1248 if ( token ==
"}" ) {
1251 else if ( !token.
Icmp(
"time" ) ) {
1254 else if ( !token.
Icmp(
"camera_fixed") ) {
1258 else if ( !token.
Icmp(
"camera_interpolated") ) {
1262 else if ( !token.
Icmp(
"camera_spline") ) {
1266 else if ( !token.
Icmp(
"target_fixed") ) {
1271 else if ( !token.
Icmp(
"target_interpolated") ) {
1276 else if ( !token.
Icmp(
"target_spline") ) {
1281 else if ( !token.
Icmp(
"fov") ) {
1284 else if ( !token.
Icmp(
"event") ) {
1286 event->parse( src );
1290 src->
Error(
"unknown camera def: %s", token.
c_str() );
1334 f->
Printf(
"cameraPathDef { \n" );
1344 events[
i]->write( f,
"event" );
1454 if ( token ==
"}" ) {
1460 if ( !key.
Icmp(
"type" ) ) {
1463 else if ( !key.
Icmp(
"param" ) ) {
1466 else if ( !key.
Icmp(
"time" ) ) {
1470 src->
Error(
"unknown camera event key: %s", key.
c_str() );
1482 f->
Printf(
"\t%s {\n", name );
1483 f->
Printf(
"\t\ttype %d\n", static_cast<int>(
type) );
1544 if ( !key.
Icmp(
"time" ) ) {
1548 else if ( !key.
Icmp(
"type" ) ) {
1552 else if ( !key.
Icmp(
"velocity" ) ) {
1553 long t = atol(token);
1559 else if ( !key.
Icmp(
"baseVelocity" ) ) {
1563 else if ( !key.
Icmp(
"name" ) ) {
1568 else if ( !key.
Icmp(
"time" ) ) {
1573 src->
Error(
"unknown camera position key: %s", key.
c_str() );
1585 f->
Printf(
"\t\ttype %i\n", static_cast<int>(
type) );
1607 assert( index >= 0 && index < 2 );
1679 static idVec3 interpolatedPos;
1696 float distToTravel = timePassed * velocity;
1700 float distance = temp.
Length();
1705 if ( percent > 1.0
f ) {
1707 }
else if ( percent < 0.0
f ) {
1716 v1 *= (1.0f - percent);
1719 interpolatedPos =
v1;
1720 return &interpolatedPos;
1736 if ( token ==
"}" ) {
1740 if ( !token.
Icmp(
"startPos" ) ) {
1743 else if ( !token.
Icmp(
"endPos" ) ) {
1758 f->
Printf(
"\t%s {\n", p );
1782 if ( percent < 0.0
f ) {
1784 }
else if ( percent > 1.0
f ) {
1789 fov = startFOV + temp;
1819 if ( token ==
"}" ) {
1823 if ( !token.
Icmp(
"fov" ) ) {
1826 else if ( !token.
Icmp(
"startFOV" ) ) {
1829 else if ( !token.
Icmp(
"endFOV" ) ) {
1832 else if ( !token.
Icmp(
"time" ) ) {
1836 src->
Error(
"unknown camera FOV key: %s", token.
c_str() );
1848 f->
Printf(
"\t%s {\n", p );
1877 if ( token ==
"}" ) {
1881 if ( !token.
Icmp(
"pos" ) ) {
1896 f->
Printf(
"\t%s {\n", p );
1936 if ( token ==
"}" ) {
1939 if ( !token.
Icmp(
"target" ) ) {
1954 f->
Printf(
"\t%s {\n", p );
1966 static idVec3 interpolatedPos;
1975 float distToTravel = timePassed * velocity;
1980 double percent = (double)(
distSoFar) / tempDistance;
1982 double targetDistance = percent * tempDistance;
1985 double lastDistance1,lastDistance2;
1986 lastDistance1 = lastDistance2 = 0;
1992 for( i = 1; i <
count; i++) {
1995 tempDistance += temp.
Length();
1997 lastDistance1 = tempDistance;
1999 lastDistance2 = tempDistance;
2001 if (tempDistance >= targetDistance) {
2006 if (i >= count - 1) {
2012 double percent = (timeHi -
t) / (timeHi - timeLo);
2015 v2 *= (1.0f - percent);
2018 interpolatedPos =
v2;
2020 if (lastDistance1 > lastDistance2) {
2021 double d = lastDistance2;
2022 lastDistance2 = lastDistance1;
2028 double percent = (lastDistance2 - targetDistance) / (lastDistance2 - lastDistance1);
2029 v2 *= (1.0f - percent);
2032 interpolatedPos =
v2;
2035 return &interpolatedPos;
void Error(const char *str,...) const id_attribute((format(printf
void calcVelocity(float distance)
float calcSpline(int step, float tension)
virtual const idVec3 * getPosition(long t)
assert(prefInfo.fullscreenBtn)
void UnreadToken(idToken *token)
virtual void parse(idParser *src)
void updateSelection(const idVec3 &move)
static const char * positionStr[POSITION_COUNT]
virtual bool parseToken(const idStr &key, idParser *src)
static int sortEvents(const void *p1, const void *p2)
const idEventDef EV_Activate("activate","e")
void glLabeledPoint(idVec4 &color, idVec3 &point, float size, const char *label)
void setActiveTargetByName(const char *name)
const float * ToFloatPtr(void) const
idList< idVelocity * > velocities
void Set(const float x, const float y, const float z)
idEntity * FindEntity(const char *name) const
idCameraPosition * startNewCamera(idCameraPosition::positionType type)
int isPointSelected(int index)
int currentCameraPosition
int Sys_Milliseconds(void)
void debugLine(idVec4 &color, float x, float y, float z, float x2, float y2, float z2)
bool ProcessEvent(const idEventDef *ev)
idFileSystem * fileSystem
virtual idVec3 * getPoint(int index)
int selectPointByRay(const idVec3 &origin, const idVec3 &direction, bool single)
void addTarget(const char *name, idCameraPosition::positionType type)
static const char * eventStr[EVENT_COUNT]
idVec3 * getSelectedPoint(int index)
#define VectorAdd(a, b, c)
GLuint GLuint GLsizei GLenum type
int ExpectTokenString(const char *string)
void addVelocity(long start, long duration, float speed)
void parse(idParser *src)
virtual void start(long t)
void parse(idParser *src)
void addEvent(idCameraEvent::eventType t, const char *param, long time)
void write(idFile *f, const char *name)
virtual const idVec3 * getPosition(long t)
int Icmp(const char *text) const
void setActiveTarget(int index)
void parse(idParser *src)
void parse(idParser *src)
int ReadToken(idToken *token)
virtual const idVec3 * getPosition(long t)
GLfloat GLfloat GLfloat v2
const idVec3 * getPosition(long time)
GLuint GLuint GLsizei count
virtual void addPoint(const float x, const float y, const float z)
bool waitEvent(int index)
virtual void DebugLine(const idVec4 &color, const idVec3 &start, const idVec3 &end, const int lifetime=0, const bool depthTest=false)=0
void reset(float startfov, float endfov, int start, int len)
void save(const char *filename)
idList< idVec3 * > controlPoints
int Parse1DMatrix(int x, float *m)
void setColors(idVec4 &path, idVec4 &segment, idVec4 &control, idVec4 &active)
idList< double > splineTime
int selectPoint(int index, bool single)
idList< idCameraEvent * > events
void write(idFile *f, const char *name)
idCameraPosition * cameraPosition
void glBox(idVec4 &color, idVec3 &point, float size)
virtual idFile * OpenFileWrite(const char *relativePath, const char *basePath="fs_savepath")=0
static idCameraPosition * newFromType(idCameraPosition::positionType t)
bool load(const char *filename)
virtual void draw(bool editMode)
void setName(const char *p)
void startEdit(bool camera)
virtual void Printf(const char *fmt,...) id_attribute((format(printf
virtual void updateSelection(const idVec3 &move)
int ExpectAnyToken(idToken *token)
GLdouble GLdouble GLdouble y2
const float * ToFloatPtr(void) const
idCameraPosition * getActiveTarget()
virtual void clearVelocities()
float getVelocity(long t)
void getActiveSegmentInfo(int segment, idVec3 &origin, idVec3 &direction, float *fv)
void parse(idParser *src)
idVec3 * getSegmentPoint(int index)
void write(idFile *f, const char *name)
virtual idVec3 * getPoint(int index)
int Append(const type &obj)
int getSegmentTime(int index)
void parse(idParser *src)
const idVec3 * getPoint(int index)
void setSelectedPoint(idVec3 *p)
idList< int > selectedPoints
void initPosition(long startTime, long totalTime)
void Signal(signalNum_t signalnum)
void parse(idParser *src)
virtual void start(long t)
bool getCameraInfo(long time, idVec3 &origin, idVec3 &direction, float *fv)
GLsizei const GLcharARB const GLint * length
virtual void write(idFile *f, const char *name)
int ReadTokenOnLine(idToken *token)
const char * c_str(void) const
idCameraDef * g_splineList
idList< idCameraPosition * > targetPositions
virtual void start(long t)
#define VectorMA(v, s, b, o)
void write(idFile *f, const char *name)
char * va(const char *fmt,...)
virtual void CloseFile(idFile *f)=0
void write(idFile *f, const char *name)
virtual int Printf(const char *fmt,...) id_attribute((format(printf
virtual void setTime(long t)
bool Remove(const type &obj)
idList< idVec3 * > splinePoints
void write(idFile *f, const char *name)
idCameraPosition * getPositionObj()
void addPoint(const idVec3 &v)