Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

idCameraDef Class Reference

#include <splines.h>

Collaboration diagram for idCameraDef:

Collaboration graph
[legend]

Public Member Functions

void addEvent (idCameraEvent *event)
void addEvent (idCameraEvent::eventType t, const char *param, long time)
void addEvent (idCameraEvent *event)
void addEvent (idCameraEvent::eventType t, const char *param, long time)
void addTarget (const char *name, idCameraPosition::positionType type)
void addTarget (const char *name, idCameraPosition::positionType type)
void buildCamera ()
void buildCamera ()
void clear ()
void clear ()
void draw (bool editMode)
void getActiveSegmentInfo (int segment, idVec3_t &origin, idVec3_t &direction, float *fv)
void getActiveSegmentInfo (int segment, idVec3_t &origin, idVec3_t &direction, float *fv)
idCameraPositiongetActiveTarget (int index)
idCameraPositiongetActiveTarget ()
idCameraPositiongetActiveTarget (int index)
idCameraPositiongetActiveTarget ()
float getBaseTime ()
float getBaseTime ()
bool getCameraInfo (long time, float *origin, float *direction, float *fv)
bool getCameraInfo (long time, idVec3_t &origin, idVec3_t &direction, float *fv)
bool getCameraInfo (long time, float *origin, float *direction, float *fv)
bool getCameraInfo (long time, idVec3_t &origin, idVec3_t &direction, float *fv)
idCameraEventgetEvent (int index)
idCameraEventgetEvent (int index)
const char * getName ()
const char * getName ()
const idVec3_tgetPoint (int index)
const idVec3_tgetPoint (int index)
idCameraPositiongetPositionObj ()
idCameraPositiongetPositionObj ()
float getTotalTime ()
float getTotalTime ()
 idCameraDef ()
 idCameraDef ()
bool load (const char *filename)
qboolean load (const char *filename)
int numEvents ()
int numEvents ()
int numPoints ()
int numPoints ()
int numTargets ()
int numTargets ()
void parse (const char *(*text))
void parse (const char *(*text))
void save (const char *filename)
void save (const char *filename)
void setActiveTarget (int index)
void setActiveTarget (int index)
void setActiveTargetByName (const char *name)
void setActiveTargetByName (const char *name)
void setBaseTime (float f)
void setBaseTime (float f)
void setName (const char *p)
void setName (const char *p)
void setRunning (bool b)
void setRunning (bool b)
void startCamera (long t)
void startCamera (long t)
void startEdit (bool camera)
void startEdit (bool camera)
idCameraPositionstartNewCamera (idCameraPosition::positionType type)
idCameraPositionstartNewCamera (idCameraPosition::positionType type)
void stopCamera ()
void stopCamera ()
void stopEdit ()
void stopEdit ()
bool waitEvent (int index)
bool waitEvent (int index)
 ~idCameraDef ()
 ~idCameraDef ()

Static Public Member Functions

idCameraPositionnewFromType (idCameraPosition::positionType t)
idCameraPositionnewFromType (idCameraPosition::positionType t)
int sortEvents (const void *p1, const void *p2)
int sortEvents (const void *p1, const void *p2)

Protected Attributes

int activeTarget
float baseTime
bool cameraEdit
idCameraPositioncameraPosition
idCameraPositioncameraPosition
bool cameraRunning
int currentCameraPosition
bool editMode
idList< idCameraEvent * > events
idList< idCameraEvent * > events
idCameraFOV fov
idVec3_t lastDirection
idStr name
long startTime
idList< idCameraPosition * > targetPositions
idList< idCameraPosition * > targetPositions
float totalTime

Constructor & Destructor Documentation

idCameraDef  )  [inline]
 

Definition at line 842 of file splines.h.

00842                   {
00843         clear();
00844     }

~idCameraDef  )  [inline]
 

Definition at line 846 of file splines.h.

00846                    {
00847         clear();
00848     }

idCameraDef  )  [inline]
 

Definition at line 849 of file splines.h.

00849                   {
00850         clear();
00851     }

~idCameraDef  )  [inline]
 

Definition at line 853 of file splines.h.

00853                    {
00854         clear();
00855     }


Member Function Documentation

void addEvent idCameraEvent event  ) 
 

void addEvent idCameraEvent::eventType  t,
const char *  param,
long  time
 

void addEvent idCameraEvent event  ) 
 

Definition at line 784 of file splines.cpp.

References idList::Append(), and events.

00784                                                {
00785     events.Append(event);
00786     //events.Sort(&sortEvents);
00787 
00788 }

Here is the call graph for this function:

void addEvent idCameraEvent::eventType  t,
const char *  param,
long  time
 

Definition at line 789 of file splines.cpp.

References buildCamera(), param, t, and time().

Referenced by addTarget(), ON_BN_CLICKED(), and parse().

00789                                                                                  {
00790     addEvent(new idCameraEvent(t, param, time));
00791     buildCamera();
00792 }

Here is the call graph for this function:

void addTarget const char *  name,
idCameraPosition::positionType  type
 

void addTarget const char *  name,
idCameraPosition::positionType  type
 

Definition at line 1203 of file splines.cpp.

References activeTarget, addEvent(), idList::Append(), name, newFromType(), numTargets(), idCameraPosition::setName(), targetPositions, and type.

Referenced by CDlgCamera::OnBtnAddtarget().

01203                                                                                {
01204     //const char *text = (name == NULL) ? va("target0%d", numTargets()+1) : name; // TTimo: unused
01205     idCameraPosition *pos = newFromType(type);
01206     if (pos) {
01207         pos->setName(name);
01208         targetPositions.Append(pos);
01209         activeTarget = numTargets()-1;
01210         if (activeTarget == 0) {
01211             // first one
01212             addEvent(idCameraEvent::EVENT_TARGET, name, 0);
01213         }
01214     }
01215 }

Here is the call graph for this function:

void buildCamera  ) 
 

void buildCamera  ) 
 

Definition at line 558 of file splines.cpp.

References idCameraPosition::addVelocity(), idList::Append(), atof(), cameraPosition, events, getActiveTarget(), i, idList::Num(), setActiveTargetByName(), idCameraPosition::setTime(), t, and totalTime.

Referenced by addEvent(), getActiveSegmentInfo(), CDlgCamera::OnApply(), CDlgCamera::OnHScroll(), CMainFrame::OnSplinesLoad(), and startCamera().

00558                               {
00559     int i;
00560     //int lastSwitch = 0;
00561     idList<float> waits;
00562     idList<int> targets;
00563 
00564     totalTime = baseTime;
00565     cameraPosition->setTime(totalTime * 1000);
00566     // we have a base time layout for the path and the target path
00567     // now we need to layer on any wait or speed changes
00568     for (i = 0; i < events.Num(); i++) {
00569         //idCameraEvent *ev = events[i];
00570         events[i]->setTriggered(false);
00571         switch (events[i]->getType()) {
00572             case idCameraEvent::EVENT_TARGET : {
00573                 targets.Append(i);
00574                 break;
00575             }
00576             case idCameraEvent::EVENT_WAIT : {
00577                 waits.Append(atof(events[i]->getParam()));
00578                 cameraPosition->addVelocity(events[i]->getTime(), atof(events[i]->getParam()) * 1000, 0);
00579                 break;
00580             }
00581             case idCameraEvent::EVENT_TARGETWAIT : {
00582                 //targetWaits.Append(i);
00583                 break;
00584             }
00585             case idCameraEvent::EVENT_SPEED : {
00586 /*
00587                 // take the average delay between up to the next five segments
00588                 float adjust = atof(events[i]->getParam());
00589                 int index = events[i]->getSegment();
00590                 total = 0;
00591                 count = 0;
00592 
00593                 // get total amount of time over the remainder of the segment
00594                 for (j = index; j < cameraSpline.numSegments() - 1; j++) {
00595                     total += cameraSpline.getSegmentTime(j + 1) - cameraSpline.getSegmentTime(j);
00596                     count++;
00597                 }
00598 
00599                 // multiply that by the adjustment
00600                 double newTotal = total * adjust;
00601                 // what is the difference.. 
00602                 newTotal -= total;
00603                 totalTime += newTotal / 1000;
00604 
00605                 // per segment difference
00606                 newTotal /= count;
00607                 int additive = newTotal;
00608 
00609                 // now propogate that difference out to each segment
00610                 for (j = index; j < cameraSpline.numSegments(); j++) {
00611                     cameraSpline.addSegmentTime(j, additive);
00612                     additive += newTotal;
00613                 }
00614                 break;
00615 */
00616             }
00617     default: break; // FIXME: what about other idCameraEvent?
00618         }
00619     }
00620 
00621 
00622     for (i = 0; i < waits.Num(); i++) {
00623         totalTime += waits[i];
00624     }
00625 
00626     // on a new target switch, we need to take time to this point ( since last target switch ) 
00627     // and allocate it across the active target, then reset time to this point
00628     long timeSoFar = 0;
00629     long total = (int)(totalTime * 1000);
00630     for (i = 0; i < targets.Num(); i++) {
00631         long t;
00632         if (i < targets.Num() - 1) {
00633             t = events[targets[i+1]]->getTime();
00634         } else {
00635             t = total - timeSoFar;
00636         }
00637         // t is how much time to use for this target
00638         setActiveTargetByName(events[targets[i]]->getParam());
00639         getActiveTarget()->setTime(t);
00640         timeSoFar += t;
00641     }
00642 
00643     
00644 }

Here is the call graph for this function:

void clear  )  [inline]
 

Definition at line 816 of file splines.h.

References events, i, and name.

00816                  {
00817         currentCameraPosition = 0;
00818         cameraRunning = false;
00819         lastDirection.Zero();
00820         baseTime = 30;
00821         activeTarget = 0;
00822         name = "camera01";
00823         fov.setFOV(90);
00824         int i;
00825         for (i = 0; i < targetPositions.Num(); i++) {
00826             delete targetPositions[i];
00827         }
00828         for (i = 0; i < events.Num(); i++) {
00829             delete events[i];
00830         }
00831         delete cameraPosition;
00832         cameraPosition = NULL;
00833         events.Clear();
00834         targetPositions.Clear();
00835     }

void clear  )  [inline]
 

Definition at line 809 of file splines.h.

References events, i, and name.

Referenced by load(), loadCamera(), CDlgCamera::OnFileNew(), CDlgCamera::OnFileOpen(), and CMainFrame::OnSplinesMode().

00809                  {
00810         currentCameraPosition = 0;
00811         cameraRunning = false;
00812         lastDirection.Zero();
00813         baseTime = 30;
00814         activeTarget = 0;
00815         name = "camera01";
00816         fov.setFOV(90);
00817         int i;
00818         for (i = 0; i < targetPositions.Num(); i++) {
00819             delete targetPositions[i];
00820         }
00821         for (i = 0; i < events.Num(); i++) {
00822             delete events[i];
00823         }
00824         delete cameraPosition;
00825         cameraPosition = NULL;
00826         events.Clear();
00827         targetPositions.Clear();
00828     }

void draw bool  editMode  )  [inline]
 

Definition at line 968 of file splines.h.

References i.

Referenced by CCamWnd::Cam_Draw(), and CXYWnd::XY_Draw().

00968                              {
00969                 // gcc doesn't allow casting away from bools
00970                 // why?  I've no idea...
00971         if (cameraPosition) {
00972             cameraPosition->draw((bool)((editMode || cameraRunning) && cameraEdit));
00973             int count = targetPositions.Num();
00974             for (int i = 0; i < count; i++) {
00975                 targetPositions[i]->draw((bool)((editMode || cameraRunning) && i == activeTarget && !cameraEdit));
00976             }
00977         }
00978     }

void getActiveSegmentInfo int  segment,
idVec3_t origin,
idVec3_t direction,
float *  fv
 

void getActiveSegmentInfo int  segment,
idVec3_t origin,
idVec3_t direction,
float *  fv
 

Definition at line 448 of file splines.cpp.

References buildCamera(), d, getCameraInfo(), segment, and totalTime.

00448                                                                                                      {
00449 #if 0
00450     if (!cameraSpline.validTime()) {
00451         buildCamera();
00452     }
00453     double d = (double)segment / numSegments();
00454     getCameraInfo(d * totalTime * 1000, origin, direction, fov);
00455 #endif
00456 /*
00457     if (!cameraSpline.validTime()) {
00458         buildCamera();
00459     }
00460     origin = *cameraSpline.getSegmentPoint(segment);
00461     
00462 
00463     idVec3_t temp;
00464 
00465     int numTargets = getTargetSpline()->controlPoints.Num();
00466     int count = cameraSpline.splineTime.Num();
00467     if (numTargets == 0) {
00468         // follow the path
00469         if (cameraSpline.getActiveSegment() < count - 1) {
00470             temp = *cameraSpline.splinePoints[cameraSpline.getActiveSegment()+1];
00471         }
00472     } else if (numTargets == 1) {
00473         temp = *getTargetSpline()->controlPoints[0];
00474     } else {
00475         temp = *getTargetSpline()->getSegmentPoint(segment);
00476     }
00477 
00478     temp -= origin;
00479     temp.Normalize();
00480     direction = temp;
00481 */
00482 }

Here is the call graph for this function:

idCameraPosition* getActiveTarget int  index  )  [inline]
 

Definition at line 900 of file splines.h.

References NULL.

00900                                                  {
00901         if (targetPositions.Num() == 0) {
00902             addTarget(NULL, idCameraPosition::FIXED);
00903             return targetPositions[0];
00904         }
00905         return targetPositions[index];
00906     }

idCameraPosition* getActiveTarget  )  [inline]
 

Definition at line 893 of file splines.h.

References NULL.

00893                                         {
00894         if (targetPositions.Num() == 0) {
00895             addTarget(NULL, idCameraPosition::FIXED);
00896         }
00897         return targetPositions[activeTarget];
00898     }

idCameraPosition* getActiveTarget int  index  )  [inline]
 

Definition at line 895 of file splines.h.

References NULL.

00895                                                  {
00896         if (targetPositions.Num() == 0) {
00897             addTarget(NULL, idCameraPosition::FIXED);
00898             return targetPositions[0];
00899         }
00900         return targetPositions[index];
00901     }

idCameraPosition* getActiveTarget  )  [inline]
 

Definition at line 888 of file splines.h.

References NULL.

Referenced by buildCamera(), getCameraInfo(), CDlgCamera::OnSelchangeComboSplines(), and CDlgCamera::setupFromCamera().

00888                                         {
00889         if (targetPositions.Num() == 0) {
00890             addTarget(NULL, idCameraPosition::FIXED);
00891         }
00892         return targetPositions[activeTarget];
00893     }

float getBaseTime  )  [inline]
 

Definition at line 935 of file splines.h.

00935                         {
00936         return baseTime;
00937     }

float getBaseTime  )  [inline]
 

Definition at line 930 of file splines.h.

Referenced by CDlgCamera::setupFromCamera().

00930                         {
00931         return baseTime;
00932     }

bool getCameraInfo long  time,
float *  origin,
float *  direction,
float *  fv
[inline]
 

Definition at line 950 of file splines.h.

References b, getCameraInfo(), and time().

00950                                                                               {
00951         idVec3_t org, dir;
00952         org[0] = origin[0];
00953         org[1] = origin[1];
00954         org[2] = origin[2];
00955         dir[0] = direction[0];
00956         dir[1] = direction[1];
00957         dir[2] = direction[2];
00958         bool b = getCameraInfo(time, org, dir, fv);
00959         origin[0] = org[0];
00960         origin[1] = org[1];
00961         origin[2] = org[2];
00962         direction[0] = dir[0];
00963         direction[1] = dir[1];
00964         direction[2] = dir[2];
00965         return b;
00966     }

Here is the call graph for this function:

bool getCameraInfo long  time,
idVec3_t origin,
idVec3_t direction,
float *  fv
 

bool getCameraInfo long  time,
float *  origin,
float *  direction,
float *  fv
[inline]
 

Definition at line 945 of file splines.h.

References b, getCameraInfo(), and time().

00945                                                                               {
00946         idVec3_t org, dir;
00947         org[0] = origin[0];
00948         org[1] = origin[1];
00949         org[2] = origin[2];
00950         dir[0] = direction[0];
00951         dir[1] = direction[1];
00952         dir[2] = direction[2];
00953         bool b = getCameraInfo(time, org, dir, fv);
00954         origin[0] = org[0];
00955         origin[1] = org[1];
00956         origin[2] = org[2];
00957         direction[0] = dir[0];
00958         direction[1] = dir[1];
00959         direction[2] = dir[2];
00960         return b;
00961     }

Here is the call graph for this function:

bool getCameraInfo long  time,
idVec3_t origin,
idVec3_t direction,
float *  fv
 

Definition at line 484 of file splines.cpp.

References cameraPosition, events, fov, getActiveTarget(), idCameraFOV::getFOV(), idCameraPosition::getPosition(), i, idVec3_t::Normalize(), idList::Num(), numTargets(), setActiveTargetByName(), idCameraPosition::start(), startTime, targetPositions, and time().

Referenced by getActiveSegmentInfo(), getCameraInfo(), CDlgCamera::OnHScroll(), and CMainFrame::OnSplineTest().

00484                                                                                            {
00485 
00486 
00487     if ((time - startTime) / 1000 > totalTime) {
00488         return false;
00489     }
00490 
00491 
00492     for (int i = 0; i < events.Num(); i++) {
00493         if (time >= startTime + events[i]->getTime() && !events[i]->getTriggered()) {
00494             events[i]->setTriggered(true);
00495             if (events[i]->getType() == idCameraEvent::EVENT_TARGET) {
00496                 setActiveTargetByName(events[i]->getParam());
00497                 getActiveTarget()->start(startTime + events[i]->getTime());
00498                 //Com_Printf("Triggered event switch to target: %s\n",events[i]->getParam());
00499             } else if (events[i]->getType() == idCameraEvent::EVENT_TRIGGER) {
00500                 //idEntity *ent = NULL;
00501                 //ent = level.FindTarget( ent, events[i]->getParam());
00502                 //if (ent) {
00503                 //  ent->signal( SIG_TRIGGER );
00504                 //  ent->ProcessEvent( &EV_Activate, world );
00505                 //}
00506             } else if (events[i]->getType() == idCameraEvent::EVENT_FOV) {
00507                 //*fv = fov = atof(events[i]->getParam());
00508             } else if (events[i]->getType() == idCameraEvent::EVENT_STOP) {
00509                 return false;
00510             }
00511         }
00512     }
00513 
00514     origin = *cameraPosition->getPosition(time);
00515     
00516     *fv = fov.getFOV(time);
00517 
00518     idVec3_t temp = origin;
00519 
00520     int numTargets = targetPositions.Num();
00521     if (numTargets == 0) {
00522 /*
00523         // follow the path
00524         if (cameraSpline.getActiveSegment() < count - 1) {
00525             temp = *cameraSpline.splinePoints[cameraSpline.getActiveSegment()+1];
00526             if (temp == origin) {
00527                 int index = cameraSpline.getActiveSegment() + 2;
00528                 while (temp == origin && index < count - 1) {
00529                     temp = *cameraSpline.splinePoints[index++];
00530                 }
00531             }
00532         }
00533 */
00534     } else {
00535         temp = *getActiveTarget()->getPosition(time);
00536     }
00537     
00538     temp -= origin;
00539     temp.Normalize();
00540     direction = temp;
00541 
00542     return true;
00543 }

Here is the call graph for this function:

idCameraEvent* getEvent int  index  )  [inline]
 

Definition at line 867 of file splines.h.

References assert, and events.

00867                                        {
00868         assert(index >= 0 && index < events.Num());
00869         return events[index];
00870     }

idCameraEvent* getEvent int  index  )  [inline]
 

Definition at line 860 of file splines.h.

References assert, and events.

Referenced by CDlgCamera::setupFromCamera().

00860                                        {
00861         assert(index >= 0 && index < events.Num());
00862         return events[index];
00863     }

const char* getName  )  [inline]
 

Definition at line 1042 of file splines.h.

References name.

01042                           {
01043         return name.c_str();
01044     }

const char* getName  )  [inline]
 

Definition at line 1037 of file splines.h.

References name.

Referenced by CDlgCamera::setupFromCamera().

01037                           {
01038         return name.c_str();
01039     }

const idVec3_t* getPoint int  index  )  [inline]
 

Definition at line 1010 of file splines.h.

01010                                         {
01011         if (cameraEdit) {
01012             return cameraPosition->getPoint(index);
01013         }
01014         return getActiveTarget()->getPoint(index);
01015     }

const idVec3_t* getPoint int  index  )  [inline]
 

Definition at line 1005 of file splines.h.

01005                                         {
01006         if (cameraEdit) {
01007             return cameraPosition->getPoint(index);
01008         }
01009         return getActiveTarget()->getPoint(index);
01010     }

idCameraPosition* getPositionObj  )  [inline]
 

Definition at line 1050 of file splines.h.

01050                                        {
01051         if (cameraPosition == NULL) {
01052             cameraPosition = new idFixedPosition();
01053         }
01054         return cameraPosition;
01055     }

idCameraPosition* getPositionObj  )  [inline]
 

Definition at line 1045 of file splines.h.

Referenced by CDlgCamera::OnFileNew(), CDlgCamera::OnFileOpen(), CDlgCamera::OnSelchangeComboSplines(), CMainFrame::OnSplinesMode(), and CDlgCamera::setupFromCamera().

01045                                        {
01046         if (cameraPosition == NULL) {
01047             cameraPosition = new idFixedPosition();
01048         }
01049         return cameraPosition;
01050     }

float getTotalTime  )  [inline]
 

Definition at line 939 of file splines.h.

00939                          {
00940         return totalTime;
00941     }

float getTotalTime  )  [inline]
 

Definition at line 934 of file splines.h.

Referenced by CDlgCamera::OnApply(), CDlgCamera::OnHScroll(), CDlgCamera::OnSelchangeComboSplines(), CMainFrame::OnSplineTest(), and CDlgCamera::setupFromCamera().

00934                          {
00935         return totalTime;
00936     }

bool load const char *  filename  ) 
 

bool load const char *  filename  ) 
 

Definition at line 725 of file splines.cpp.

References clear(), Com_BeginParseSession(), Com_EndParseSession(), FS_FreeFile(), FS_ReadFile(), parse(), and qboolean.

Referenced by loadCamera(), CDlgCamera::OnFileOpen(), and CMainFrame::OnSplinesLoad().

00725                                                {
00726     char *buf;
00727     const char *buf_p;
00728     //int length = 
00729   FS_ReadFile( filename, (void **)&buf );
00730     if ( !buf ) {
00731         return qfalse;
00732     }
00733 
00734     clear();
00735     Com_BeginParseSession( filename );
00736     buf_p = buf;
00737     parse(&buf_p);
00738     Com_EndParseSession();
00739     FS_FreeFile( buf );
00740 
00741     return qtrue;
00742 }

Here is the call graph for this function: