Changeset 2551 in orxonox.OLD for orxonox/trunk/src/camera.cc
- Timestamp:
- Oct 11, 2004, 12:53:43 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/camera.cc
r2190 r2551 29 29 Camera::Camera () 30 30 { 31 bound = NULL; 31 bound = NULL; 32 /* give it some physical live */ 33 m = 10; 34 a = new Vector(0.0, 0.0, 0.0); 35 v = new Vector(0.0, 0.0, 0.0); 36 fs = new Vector(0.0, 0.0, 0.0); 37 cameraMode = NORMAL; 38 39 deltaTime = 3000.0; 40 cameraOffset = 1.0; 41 cameraOffsetZ = 10.0; 42 t = 0.0; 43 44 actual_place.r.x = 0.0; 45 actual_place.r.y = 10.0; 46 actual_place.r.z = -5.0; 32 47 } 33 48 … … 48 63 void Camera::time_slice (Uint32 deltaT) 49 64 { 50 update_desired_place (); 51 jump (NULL); 52 } 53 54 /** 55 \brief this calculates the location where the track wants the camera to be 56 57 This refreshes the placement the camera should have according to the bound entity's position on the track. 65 if(t <= deltaTime) 66 {t += deltaT;} 67 //printf("time is: t=%f\n", t ); 68 update_desired_place (); 69 jump (NULL); 70 } 71 72 /** 73 \brief this calculates the location where the track wants the camera to be 74 75 This refreshes the placement the camera should have according to the 76 bound entity's position on the track. 58 77 */ 59 78 void Camera::update_desired_place () 60 79 { 61 Orxonox *orx = Orxonox::getInstance(); 62 Location lookat; 80 switch(cameraMode) 81 { 82 83 case ELLIPTICAL: 84 { 85 //r = actual_place.r 86 Orxonox *orx = Orxonox::getInstance(); 87 Location lookat; 88 Placement plFocus; 89 if( bound != NULL) 90 { 91 bound->get_lookat (&lookat); 92 orx->get_world()->calc_camera_pos (&lookat, &plFocus); 93 Quaternion *fr; 94 if(t < 20.0) 95 { 96 Vector *start = new Vector(0.0, 1.0, 0.0); 97 //r = /*actual_place.r*/ *start - plFocus.r; 98 r = *(new Vector(0.0, 5.0, 0.0)); 99 100 Vector up(0.0, 0.0, 1.0); 63 101 64 if( bound != NULL) 65 { 66 bound->get_lookat (&lookat); 67 orx->get_world()->calc_camera_pos (&lookat, &desired_place); 68 } 69 else 70 { 71 desired_place.r = Vector (0,0,0); 72 desired_place.w = Quaternion (); 73 } 74 } 75 76 /** 77 \brief initialize rendering perspective according to this camera 78 79 This is called immediately before the a rendering cycle starts, it sets all global rendering options as 80 well as the GL_PROJECTION matrix according to the camera. 102 Vector op(1.0, 0.0, 0.0); 103 float angle = angle_deg(op, *start); 104 printf("angle is: %f\n", angle); 105 106 //if in one plane 107 from = new Quaternion(angle, up); 108 109 //from = new Quaternion(*start, *up); 110 //&from = &plFocus.w; 111 //fr = &plFocus.w; real quaternion use 112 113 114 115 Vector vDirection(1.0, 0.0, 0.0); 116 //vDirection = plFocus.w.apply(vDirection); 117 to = new Quaternion(vDirection, *start); 118 res = new Quaternion(); 119 } 120 //printf("vector r = %f, %f, %f\n",r.x, r.y, r.z ); 121 rAbs = r.len(); 122 if(t < 30.0) /* FIXME!!*/ 123 { 124 ka = rAbs / deltaTime*deltaTime; 125 } 126 /* this is the new length of the vector */ 127 //float len = ka * powf((deltaTime - t), 2); 128 129 /* calc the rotation */ 130 /* 131 Vector axis(0.0, 0.0, 1.0); 132 if(t < 30.0) 133 a0 = PI/4 - atanf(fabs(r.x) / fabs(r.y)); 134 printf("a0 = %f\n", a0); 135 float angle = a0/deltaTime * (deltaTime - t); 136 printf("angle is: %f\n", angle); 137 Quaternion q(angle, axis); 138 */ 139 //r = q.apply(r); 140 //r = r * (len/r.len()); 141 142 //res->quatSlerp(from, to, t/deltaTime, res); 143 res->quatSlerp(to, from, t/deltaTime, res); 144 145 Vector ursp(0.0, 0.0, 0.0); 146 desired_place.r = /*plFocus.r -*/ ursp - res->apply(r); 147 148 printf("desired place is: %f, %f, %f\n", desired_place.r.x, desired_place.r.y, desired_place.r.z); 149 //plLastBPlace = *bound->get_placement(); 150 } 151 } 152 break; 153 case SMOTH_FOLLOW: 154 { 155 Placement *plBound = bound->get_placement(); 156 Location lcBound; 157 if(bound != null) 158 { 159 bound->get_lookat(&lcBound); 160 Vector vDirection(0.0, 0.0, 1.0); 161 vDirection = plBound->w.apply(vDirection); 162 desired_place.r = (vDirection * ((lcBound.dist-10.0)/* / l*/)) + Vector(0,0,5.0); 163 } 164 break; 165 } 166 /* this is a camera mode that tries just to follow the entity. */ 167 case STICKY: 168 { 169 if(bound != null) 170 { 171 Placement *plBound = bound->get_placement(); 172 Vector vDirection(0.0, 0.0, 1.0); 173 Vector eclipticOffset(0.0, 0.0, 5.0); 174 vDirection = plBound->w.apply(vDirection); 175 desired_place.r = plBound->r - vDirection*10 + eclipticOffset; 176 } 177 break; 178 } 179 /* the camera is handled like an entity and rolls on the track */ 180 case NORMAL: 181 Orxonox *orx = Orxonox::getInstance(); 182 Location lookat; 183 if( bound != NULL) 184 { 185 bound->get_lookat (&lookat); 186 orx->get_world()->calc_camera_pos (&lookat, &desired_place); 187 } 188 else 189 { 190 desired_place.r = Vector (0,0,0); 191 desired_place.w = Quaternion (); 192 } 193 break; 194 } 195 } 196 197 /** 198 \brief initialize rendering perspective according to this camera 199 200 This is called immediately before the rendering cycle starts, it sets all global 201 rendering options as well as the GL_PROJECTION matrix according to the camera. 81 202 */ 82 203 void Camera::apply () 83 204 { 84 205 glMatrixMode (GL_PROJECTION); 85 206 glLoadIdentity (); 86 // view 87 // TO DO: implement options for frustum generation 88 glFrustum( -1.0,1.0,-1.0,1.0,1.5,250.0); 89 //Vector up(0,0,1); 90 //Vector dir(1,0,0); 91 //Quaternion q(dir,up); 92 //float matrix[4][4]; 93 //q.conjugate().matrix (matrix); 94 //glMultMatrixf ((float*)matrix); 95 //glTranslatef (10,0,-5); 96 // 97 //dir = Vector(-1,-1,0); 98 //q = Quaternion( dir, up); 99 //glMatrixMode (GL_MODELVIEW); 100 //glLoadIdentity (); 101 //q.matrix (matrix); 102 //glMultMatrixf ((float*)matrix); 103 //glTranslatef (2,2,0); 104 // 105 //glBegin(GL_TRIANGLES); 106 //glColor3f(1,0,0); 107 //glVertex3f(0,0,0.5); 108 //glColor3f(0,1,0); 109 //glVertex3f(-0.5,0,-1); 110 //glColor3f(0,0,1); 111 //glVertex3f(0.5,0,-1); 112 //glEnd(); 113 114 // rotation 207 // view 208 // TO DO: implement options for frustum generation 209 glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 250.0); 210 //Vector up(0,0,1); 211 //Vector dir(1,0,0); 212 //Quaternion q(dir,up); 213 //float matrix[4][4]; 214 //q.conjugate().matrix (matrix); 215 //glMultMatrixf ((float*)matrix); 216 //glTranslatef (10,0,-5); 217 // 218 //dir = Vector(-1,-1,0); 219 //q = Quaternion( dir, up); 220 //glMatrixMode (GL_MODELVIEW); 221 //glLoadIdentity (); 222 //q.matrix (matrix); 223 //glMultMatrixf ((float*)matrix); 224 //glTranslatef (2,2,0); 225 // 226 //glBegin(GL_TRIANGLES); 227 //glColor3f(1,0,0); 228 //glVertex3f(0,0,0.5); 229 //glColor3f(0,1,0); 230 //glVertex3f(-0.5,0,-1); 231 //glColor3f(0,0,1); 232 //glVertex3f(0.5,0,-1); 233 //glEnd(); 234 235 // ===== first camera control calculation option 236 // rotation 115 237 float matrix[4][4]; 116 238 actual_place.w.conjugate().matrix (matrix); 239 /* orientation and */ 117 240 glMultMatrixf ((float*)matrix); 118 // translation241 /* translation */ 119 242 glTranslatef (-actual_place.r.x, -actual_place.r.y,- actual_place.r.z); 120 243 //Placement *plBound = bound->get_placement(); 244 245 // ===== second camera control calculation option 246 /* 247 gluLookAt(actual_place.r.x, actual_place.r.y, actual_place.r.z, 248 plBound->r.x, plBound->r.y, plBound->r.z, 249 0.0, 0.0, 1.0); 250 */ 251 121 252 glMatrixMode (GL_MODELVIEW); 122 253 glLoadIdentity (); 123 124 printf("Camera@%f/%f/%f\n",actual_place.r.x,actual_place.r.y,actual_place.r.z);125 Vector unique(1,0,0);126 Vector test = actual_place.w.apply (unique);127 printf("Camera&%f/%f/%f\n", test.x, test.y, test.z);128 254 } 129 255 … … 136 262 void Camera::jump (Placement* plc = NULL) 137 263 { 138 if( plc == NULL) 139 { 140 actual_place = desired_place; 141 } 142 else 143 { 144 desired_place = *plc; 145 actual_place = *plc; 146 } 264 if( plc == NULL) 265 { 266 actual_place = desired_place; 267 //printf("Camera|jump: camer@ %f, %f, %f\n\n", actual_place.r.x, actual_place.r.y, actual_place.r.z); 268 } 269 else 270 { 271 desired_place = *plc; 272 actual_place = *plc; 273 } 147 274 } 148 275 … … 157 284 void Camera::bind (WorldEntity* entity) 158 285 { 159 if( entity != NULL) 286 if( entity != NULL) 287 { 288 if( entity->isFree ()) printf("Cannot bind camera to free entity"); 289 else 160 290 { 161 if( entity->isFree ()) printf("Cannot bind camera to free entity");162 else bound = entity;163 164 } 291 bound = entity; 292 } 293 } 294 }
Note: See TracChangeset
for help on using the changeset viewer.