Changeset 3635 in orxonox.OLD for orxonox/trunk/src/camera.cc
- Timestamp:
- Mar 23, 2005, 12:24:48 AM (19 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.