- Timestamp:
- Mar 23, 2005, 12:24:48 AM (20 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/camera.cc
r3608 r3635 24 24 using namespace std; 25 25 26 //////////// 27 // CAMERA // 28 //////////// 29 26 30 /** 27 31 \brief creates a Camera 28 29 This standard constructor sets all parameters to zero30 32 */ 31 Camera::Camera (World* world)33 Camera::Camera(void) 32 34 { 33 this->world = world; 34 this->bound = NULL; 35 /* give it some physical live */ 36 this->m = 10; 37 this->a = new Vector(0.0, 0.0, 0.0); 38 this->v = new Vector(0.0, 0.0, 0.0); 39 this->fs = new Vector(0.0, 0.0, 0.0); 40 this->cameraMode = NORMAL; 41 this->deltaTime = 3000.0; 42 this->cameraOffset = 1.0; 43 this->cameraOffsetZ = 10.0; 44 this->t = 0.0; 45 46 47 this->setDrawable (false); 35 this->target = new CameraTarget(); 48 36 } 49 37 … … 51 39 \brief default destructor 52 40 */ 53 Camera::~Camera ()41 Camera::~Camera(void) 54 42 { 55 this->bound = NULL;56 this->world = NULL;57 43 58 44 } 59 45 60 46 /** 61 \brief time based actualisation of camera parameters 62 \param deltaT: The amount of time that has passed in milliseconds 63 64 This is called by the World in every time_slice, use it to do fancy time dependant effects (such 65 as smooth camera movement or swaying). 47 \brief focuses the Camera onto a Target 48 \param target the new PNode the Camera should look at. 66 49 */ 67 void Camera:: tick (Uint32 deltaT)50 void Camera::lookAt(PNode* target) 68 51 { 69 if( this->t <= deltaTime) 70 {this->t += deltaT;} 71 //printf("time is: t=%f\n", t ); 72 updateDesiredPlace(); 73 //jump(NULL); 52 this->target->setParent(target); 74 53 } 75 54 76 /** 77 \brief this calculates the location where the track wants the camera to be 78 79 This refreshes the placement the camera should have according to the 80 bound entity's position on the track. 81 */ 82 void Camera::updateDesiredPlace () 55 PNode* Camera::getTarget(void) 83 56 { 84 switch(cameraMode) 85 { 86 87 case ELLIPTICAL: 88 { 89 /* 90 //r = actual_place.r 91 Orxonox *orx = Orxonox::getInstance(); 92 Location lookat; 93 Placement plFocus; 94 if( bound != NULL) 95 { 96 bound->getLookat (&lookat); 97 orx->getWorld()->calcCameraPos (&lookat, &plFocus); 98 Quaternion *fr; 99 if(t < 20.0) 100 { 101 Vector *start = new Vector(0.0, 1.0, 0.0); 102 r = *(new Vector(0.0, 5.0, 0.0)); 103 104 Vector up(0.0, 0.0, 1.0); 105 106 Vector op(1.0, 0.0, 0.0); 107 float angle = angleDeg(op, *start); 108 printf("angle is: %f\n", angle); 109 110 //if in one plane 111 from = new Quaternion(angle, up); 112 113 //from = new Quaternion(*start, *up); 114 //&from = &plFocus.w; 115 //fr = &plFocus.w; real quaternion use 116 117 118 119 Vector vDirection(1.0, 0.0, 0.0); 120 //vDirection = plFocus.w.apply(vDirection); 121 to = new Quaternion(vDirection, *start); 122 res = new Quaternion(); 123 } 124 //printf("vector r = %f, %f, %f\n",r.x, r.y, r.z ); 125 rAbs = r.len(); 126 if(t < 30) 127 { 128 ka = rAbs / deltaTime*deltaTime; 129 } 130 131 res->quatSlerp(to, from, t/deltaTime, res); 132 133 Vector ursp(0.0, 0.0, 0.0); 134 desiredPlace.r = ursp - res->apply(r); 135 136 printf("desired place is: %f, %f, %f\n", desiredPlace.r.x, desiredPlace.r.y, desiredPlace.r.z); 137 //plLastBPlace = *bound->get_placement(); 138 139 } 140 */ 141 } 142 break; 143 case SMOTH_FOLLOW: 144 { 145 /* 146 Placement *plBound = bound->getPlacement(); 147 Location lcBound; 148 if(bound != null) 149 { 150 bound->getLookat(&lcBound); 151 Vector vDirection(0.0, 0.0, 1.0); 152 vDirection = plBound->w.apply(vDirection); 153 desiredPlace.r = (vDirection * ((lcBound.dist-10.0))) + Vector(0,0,5.0); 154 } 155 */ 156 break; 157 } 158 /* this is a camera mode that tries just to follow the entity. */ 159 case STICKY: 160 { 161 /* 162 if(bound != null) 163 { 164 Placement *plBound = bound->getPlacement(); 165 Vector vDirection(0.0, 0.0, 1.0); 166 Vector eclipticOffset(0.0, 0.0, 5.0); 167 vDirection = plBound->w.apply(vDirection); 168 desiredPlace.r = plBound->r - vDirection*10 + eclipticOffset; 169 } 170 */ 171 break; 172 } 173 /* the camera is handled like an entity and rolls on the track */ 174 case NORMAL: 175 if( bound != NULL && world != NULL ) 176 { 177 //FIXME: camera should be made via relative coordinates 178 Vector* cameraOffset = new Vector (-10, 5, 0); 179 this->setRelCoor (cameraOffset); 180 } 181 else 182 { 183 /* 184 desiredPlace.r = Vector (0,0,0); 185 desiredPlace.w = Quaternion (); 186 */ 187 } 188 break; 189 } 57 return (PNode*)this->target; 190 58 } 191 59 … … 200 68 glMatrixMode (GL_PROJECTION); 201 69 glLoadIdentity (); 202 // view 203 // TO DO: implement options for frustum generation 204 //glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 250.0); 70 205 71 gluPerspective(60, 1.2f, 0.1, 2000); 206 207 //Vector up(0,0,1); 208 //Vector dir(1,0,0); 209 //Quaternion q(dir,up); 210 //float matrix[4][4]; 211 //q.conjugate().matrix (matrix); 212 //glMultMatrixf ((float*)matrix); 213 //glTranslatef (10,0,-5); 214 // 215 //dir = Vector(-1,-1,0); 216 //q = Quaternion( dir, up); 217 //glMatrixMode (GL_MODELVIEW); 218 //glLoadIdentity (); 219 //q.matrix (matrix); 220 //glMultMatrixf ((float*)matrix); 221 //glTranslatef (2,2,0); 222 // 223 //glBegin(GL_TRIANGLES); 224 //glColor3f(1,0,0); 225 //glVertex3f(0,0,0.5); 226 //glColor3f(0,1,0); 227 //glVertex3f(-0.5,0,-1); 228 //glColor3f(0,0,1); 229 //glVertex3f(0.5,0,-1); 230 //glEnd(); 72 float matrix[4][4]; 231 73 232 // ===== first camera control calculation option 233 // rotation 234 float matrix[4][4]; 235 //this->absDirection.conjugate().matrix (matrix); 236 /* orientation and */ 237 //glMultMatrixf ((float*)matrix); 74 Vector cameraPosition = this->getAbsCoor(); 75 Vector targetPosition = this->target->getAbsCoor(); 238 76 239 /* translation */ 240 //glTranslatef (this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z ); 241 242 243 // ===== second camera control calculation option 244 245 Vector r = this->getAbsCoor(); 246 gluLookAt(r.x, r.y, r.z, 247 this->parent->getAbsCoor ().x, this->parent->getAbsCoor ().y, this->parent->getAbsCoor ().z, 77 gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z, 78 targetPosition.x, targetPosition.y, targetPosition.z, 248 79 0.0, 1.0, 0.0); 249 250 251 80 glMatrixMode (GL_MODELVIEW); 252 81 glLoadIdentity (); … … 255 84 256 85 257 /** 258 \brief bind the camera to an entity 259 \param entity: The enitity to bind the camera to 260 261 This sets the focus of the camera to the given entity. This means that it will use the given WorldEntity's 262 Location and get_lookat() to determine the viewpoint the camera will render from. 263 Note that you cannot bind a camera to a free entity. 264 */ 265 void Camera::bind (WorldEntity* entity) 86 /////////////////// 87 // CAMERA-TARGET // 88 /////////////////// 89 90 91 CameraTarget::CameraTarget() 266 92 { 267 if( entity != NULL) 268 { 269 if( entity->isFree()) printf("Cannot bind camera to free entity"); 270 else 271 { 272 this->bound = entity; 273 } 274 } 93 275 94 } 276 95 96 CameraTarget::~CameraTarget() 97 { 277 98 278 void Camera::setWorld(World* world)279 {280 this->world = world;281 99 } 282 283 -
orxonox/trunk/src/camera.h
r3608 r3635 7 7 #define _CAMERA_H 8 8 9 #include " world_entity.h"9 #include "p_node.h" 10 10 11 11 class World; 12 class CameraTarget; 13 12 14 13 15 //! Camera 14 16 /** 15 This class controls the viewpoint from which the World is rendered. To use the 16 Camera it has to be bound to a WorldEntity which serves as the reference focus 17 point. The Camera itself calls the WorldEntity::get_lookat() and 18 World::calc_camera_pos() functions to calculate the position it currently should 19 be in. 17 This class controls the viewpoint from which the World is rendered. 20 18 */ 21 22 enum CAMERA_MODE {NORMAL, SMOTH_FOLLOW, STICKY, ELLIPTICAL}; 23 24 class Camera : public WorldEntity { 19 class Camera : public PNode 20 { 25 21 private: 26 WorldEntity* bound; //!< the WorldEntity the Camera is bound to 27 World* world; 28 29 /* physical system - not needed yet */ 30 float m; //!< mass 31 Vector *fs; //!< seil-kraft 32 Vector *a; //!< acceleration 33 Vector *v; //!< velocity 34 35 /* elliptical camera mode variables */ 36 float cameraOffset; 37 float cameraOffsetZ; 38 float deltaTime; 39 float t; 40 Vector* r; 41 float rAbs; 42 float ka; 43 float a0; 44 45 Quaternion *from; 46 Quaternion *to; 47 Quaternion *res; 48 49 50 CAMERA_MODE cameraMode; //!< saves the camera mode: how the camera follows the entity 51 52 void updateDesiredPlace (); 22 CameraTarget* target; 53 23 54 24 public: 55 Camera (World* world); 56 virtual ~Camera (); 25 Camera(void); 26 virtual ~Camera(void); 27 28 void lookAt(PNode* target); 57 29 58 void tick (Uint32 deltaT);30 PNode* getTarget(); 59 31 void apply (); 60 void bind (WorldEntity* entity);61 62 void setWorld(World* world);63 64 32 }; 65 33 34 //! A CameraTarget is where the Camera is looking at. 35 class CameraTarget : public PNode 36 { 37 friend class Camera; //! 38 39 private: 40 CameraTarget(void); 41 42 public: 43 virtual ~CameraTarget(void); 44 }; 45 46 66 47 #endif /* _CAMERA_H */ -
orxonox/trunk/src/story_entities/world.cc
r3634 r3635 302 302 303 303 // bind camera 304 this->localCamera = new Camera( this);304 this->localCamera = new Camera(); 305 305 this->localCamera->setName ("camera"); 306 this->localCamera->bind (this->localPlayer); 306 this->localCamera->lookAt(this->localPlayer); 307 307 308 /*monitor progress*/ 308 309 this->glmis->step(); … … 366 367 367 368 // bind camera 368 this->localCamera = new Camera ( this);369 this->localCamera = new Camera (); 369 370 this->localCamera->setName ("camera"); 370 this->localCamera-> bind (myPlayer);371 this->localCamera->lookAt(this->localPlayer); 371 372 this->localPlayer->addChild (this->localCamera); 372 373 … … 749 750 750 751 /* update tick the rest */ 751 this->localCamera->tick(dt);752 752 this->trackManager->tick(dt); 753 753 }
Note: See TracChangeset
for help on using the changeset viewer.