Changeset 3681 in orxonox.OLD for orxonox/branches/textEngine/src/camera.cc
- Timestamp:
- Mar 30, 2005, 9:02:23 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/textEngine/src/camera.cc
r3365 r3681 17 17 18 18 #include "camera.h" 19 19 20 #include "world.h" 20 21 #include "world_entity.h" 22 #include "vector.h" 21 23 22 24 using namespace std; 23 25 26 //////////// 27 // CAMERA // 28 //////////// 29 24 30 /** 25 31 \brief creates a Camera 26 27 This standard constructor sets all parameters to zero28 32 */ 29 Camera::Camera (World* world)33 Camera::Camera(void) 30 34 { 31 this->world = world; 32 this->bound = NULL; 33 /* give it some physical live */ 34 this->m = 10; 35 this->a = new Vector(0.0, 0.0, 0.0); 36 this->v = new Vector(0.0, 0.0, 0.0); 37 this->fs = new Vector(0.0, 0.0, 0.0); 38 this->cameraMode = NORMAL; 39 this->deltaTime = 3000.0; 40 this->cameraOffset = 1.0; 41 this->cameraOffsetZ = 10.0; 42 this->t = 0.0; 35 this->setClassName("Camera"); 36 this->target = new CameraTarget(); 43 37 38 this->setFovy(90); 39 this->setAspectRatio(1.2f); 40 this->setClipRegion(.1, 2000); 44 41 45 this->set Drawable (false);42 this->setViewMode(VIEW_NORMAL); 46 43 } 47 44 … … 49 46 \brief default destructor 50 47 */ 51 Camera::~Camera ()48 Camera::~Camera(void) 52 49 { 53 50 } 54 51 55 52 /** 56 \brief time based actualisation of camera parameters 57 \param deltaT: The amount of time that has passed in milliseconds 58 59 This is called by the World in every time_slice, use it to do fancy time dependant effects (such 60 as smooth camera movement or swaying). 53 \brief focuses the Camera onto a Target 54 \param target the new PNode the Camera should look at. 61 55 */ 62 void Camera:: timeSlice (Uint32 deltaT)56 void Camera::lookAt(PNode* target) 63 57 { 64 if( this->t <= deltaTime) 65 {this->t += deltaT;} 66 //printf("time is: t=%f\n", t ); 67 updateDesiredPlace(); 68 //jump(NULL); 58 this->target->setParent(target); 69 59 } 70 60 71 61 /** 72 \brief this calculates the location where the track wants the camera to be 73 74 This refreshes the placement the camera should have according to the 75 bound entity's position on the track. 62 \returns The PNode of the Target (from there you can get position and so on 76 63 */ 77 void Camera::updateDesiredPlace ()64 PNode* Camera::getTarget(void) 78 65 { 79 switch(cameraMode) 80 { 81 82 case ELLIPTICAL: 83 { 84 /* 85 //r = actual_place.r 86 Orxonox *orx = Orxonox::getInstance(); 87 Location lookat; 88 Placement plFocus; 89 if( bound != NULL) 90 { 91 bound->getLookat (&lookat); 92 orx->getWorld()->calcCameraPos (&lookat, &plFocus); 93 Quaternion *fr; 94 if(t < 20.0) 95 { 96 Vector *start = new Vector(0.0, 1.0, 0.0); 97 r = *(new Vector(0.0, 5.0, 0.0)); 98 99 Vector up(0.0, 0.0, 1.0); 100 101 Vector op(1.0, 0.0, 0.0); 102 float angle = angleDeg(op, *start); 103 printf("angle is: %f\n", angle); 104 105 //if in one plane 106 from = new Quaternion(angle, up); 107 108 //from = new Quaternion(*start, *up); 109 //&from = &plFocus.w; 110 //fr = &plFocus.w; real quaternion use 111 66 return (PNode*)this->target; 67 } 112 68 113 69 114 Vector vDirection(1.0, 0.0, 0.0); 115 //vDirection = plFocus.w.apply(vDirection); 116 to = new Quaternion(vDirection, *start); 117 res = new Quaternion(); 118 } 119 //printf("vector r = %f, %f, %f\n",r.x, r.y, r.z ); 120 rAbs = r.len(); 121 if(t < 30) 122 { 123 ka = rAbs / deltaTime*deltaTime; 124 } 70 /** 71 \brief sets a new AspectRatio 72 \param aspectRatio the new aspect ratio to set (width / height) 73 */ 74 void Camera::setAspectRatio(float aspectRatio) 75 { 76 this->aspectRatio = aspectRatio; 77 } 125 78 126 res->quatSlerp(to, from, t/deltaTime, res); 79 /** 80 \brief sets the Field of View to fofy 81 \param fovy new field of view factor (in degrees) 82 */ 83 void Camera::setFovy(float fovy) 84 { 85 this->fovy = fovy; 86 } 127 87 128 Vector ursp(0.0, 0.0, 0.0); 129 desiredPlace.r = ursp - res->apply(r); 88 /** 89 \brief Sets a new clipping region 90 \param nearClip The near clip plane 91 \param farClip The far clip plane 92 */ 93 void Camera::setClipRegion(float nearClip, float farClip) 94 { 95 this->nearClip = nearClip; 96 this->farClip = farClip; 97 } 130 98 131 printf("desired place is: %f, %f, %f\n", desiredPlace.r.x, desiredPlace.r.y, desiredPlace.r.z); 132 //plLastBPlace = *bound->get_placement(); 133 134 } 135 */ 136 } 99 void Camera::setViewMode(ViewMode mode) 100 { 101 switch (mode) 102 { 103 default: 104 case VIEW_NORMAL: 105 this->toFovy = 60.0; 106 this->toRelCoor = Vector(-10, 5, 0); 137 107 break; 138 case SMOTH_FOLLOW: 139 { 140 /* 141 Placement *plBound = bound->getPlacement(); 142 Location lcBound; 143 if(bound != null) 144 { 145 bound->getLookat(&lcBound); 146 Vector vDirection(0.0, 0.0, 1.0); 147 vDirection = plBound->w.apply(vDirection); 148 desiredPlace.r = (vDirection * ((lcBound.dist-10.0))) + Vector(0,0,5.0); 149 } 150 */ 151 break; 152 } 153 /* this is a camera mode that tries just to follow the entity. */ 154 case STICKY: 155 { 156 /* 157 if(bound != null) 158 { 159 Placement *plBound = bound->getPlacement(); 160 Vector vDirection(0.0, 0.0, 1.0); 161 Vector eclipticOffset(0.0, 0.0, 5.0); 162 vDirection = plBound->w.apply(vDirection); 163 desiredPlace.r = plBound->r - vDirection*10 + eclipticOffset; 164 } 165 */ 166 break; 167 } 168 /* the camera is handled like an entity and rolls on the track */ 169 case NORMAL: 170 if( bound != NULL && world != NULL ) 171 { 172 //FIXME: camera should be made via relative coordinates 173 Vector* cameraOffset = new Vector (-10, 5, 0); 174 this->setRelCoor (cameraOffset); 175 } 176 else 177 { 178 /* 179 desiredPlace.r = Vector (0,0,0); 180 desiredPlace.w = Quaternion (); 181 */ 182 } 108 case VIEW_BEHIND: 109 this->toFovy = 120.0; 110 this->toRelCoor = Vector(-7, 0, 0); 183 111 break; 112 case VIEW_FRONT: 113 this->toFovy = 95.0; 114 this->toRelCoor = Vector(12, 5, 0); 115 break; 116 case VIEW_LEFT: 117 this->toFovy = 90; 118 this->toRelCoor = Vector(0, 2, -10); 119 break; 120 case VIEW_RIGHT: 121 this->toFovy = 90; 122 this->toRelCoor = Vector(0, 2, 10); 123 break; 124 case VIEW_TOP: 125 this->toFovy= 120; 126 this->toRelCoor = Vector(0, 4, 0); 184 127 } 185 128 } 129 130 131 /** 132 \brief Updates the position of the camera. 133 \param dt The time that elapsed. 134 */ 135 void Camera::tick(float dt) 136 { 137 dt /= 500; 138 float tmpFovy = (this->toFovy - this->fovy) * dt; 139 if (tmpFovy > .001) 140 this->fovy += (this->toFovy - this->fovy) * dt; 141 Vector tmpPos = (this->toRelCoor - *this->getRelCoor()) * dt; 142 if (tmpPos.len() >= .001) 143 { 144 tmpPos = tmpPos + *this->getRelCoor(); 145 this->setRelCoor(&tmpPos); 146 } 147 } 148 186 149 187 150 /** … … 193 156 void Camera::apply () 194 157 { 158 // switching to Projection Matrix 195 159 glMatrixMode (GL_PROJECTION); 196 160 glLoadIdentity (); 197 // view198 // TO DO: implement options for frustum generation199 //glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 250.0);200 gluPerspective(60, 1.2f, 0.1, 250);201 202 //Vector up(0,0,1);203 //Vector dir(1,0,0);204 //Quaternion q(dir,up);205 //float matrix[4][4];206 //q.conjugate().matrix (matrix);207 //glMultMatrixf ((float*)matrix);208 //glTranslatef (10,0,-5);209 //210 //dir = Vector(-1,-1,0);211 //q = Quaternion( dir, up);212 //glMatrixMode (GL_MODELVIEW);213 //glLoadIdentity ();214 //q.matrix (matrix);215 //glMultMatrixf ((float*)matrix);216 //glTranslatef (2,2,0);217 //218 //glBegin(GL_TRIANGLES);219 //glColor3f(1,0,0);220 //glVertex3f(0,0,0.5);221 //glColor3f(0,1,0);222 //glVertex3f(-0.5,0,-1);223 //glColor3f(0,0,1);224 //glVertex3f(0.5,0,-1);225 //glEnd();226 161 227 // ===== first camera control calculation option 228 // rotation 229 float matrix[4][4]; 230 //this->absDirection.conjugate().matrix (matrix); 231 /* orientation and */ 232 //glMultMatrixf ((float*)matrix); 162 // setting up the perspective 163 gluPerspective(this->fovy, 164 this->aspectRatio, 165 this->nearClip, 166 this->farClip); 233 167 234 /* translation */ 235 //glTranslatef (this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z ); 168 // speed-up feature 169 Vector cameraPosition = this->getAbsCoor(); 170 Vector targetPosition = this->target->getAbsCoor(); 171 Vector up = Vector(0, 1, 0); 172 up = this->getAbsDir().apply(up); 236 173 174 // Setting the Camera Eye, lookAt and up Vectors 175 gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z, 176 targetPosition.x, targetPosition.y, targetPosition.z, 177 up.x, up.y, up.z); 237 178 238 // ===== second camera control calculation option 239 240 gluLookAt(this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z, 241 this->parent->getAbsCoor ().x, this->parent->getAbsCoor ().y, this->parent->getAbsCoor ().z, 242 0.0, 1.0, 0.0); 243 244 179 // switching back to Modeling Matrix 245 180 glMatrixMode (GL_MODELVIEW); 246 glLoadIdentity ();247 181 } 248 182 249 183 250 184 251 /** 252 \brief bind the camera to an entity 253 \param entity: The enitity to bind the camera to 254 255 This sets the focus of the camera to the given entity. This means that it will use the given WorldEntity's 256 Location and get_lookat() to determine the viewpoint the camera will render from. 257 Note that you cannot bind a camera to a free entity. 258 */ 259 void Camera::bind (WorldEntity* entity) 185 /////////////////// 186 // CAMERA-TARGET // 187 /////////////////// 188 189 190 CameraTarget::CameraTarget() 260 191 { 261 if( entity != NULL) 262 { 263 if( entity->isFree()) printf("Cannot bind camera to free entity"); 264 else 265 { 266 this->bound = entity; 267 } 268 } 192 this->setClassName("CameraTarget"); 193 this->setMode(PNODE_MOVEMENT); 269 194 } 270 195 196 CameraTarget::~CameraTarget() 197 { 271 198 272 void Camera::setWorld(World* world)273 {274 this->world = world;275 199 } 276 277 278 /**279 \brief destroy, reset the camera so that it doesn't perform anything anymore280 281 */282 void Camera::destroy()283 {284 this->bound = NULL;285 this->world = NULL;286 }
Note: See TracChangeset
for help on using the changeset viewer.