Changeset 2112 in orxonox.OLD for orxonox/branches/chris/src
- Timestamp:
- Jul 12, 2004, 10:28:25 PM (20 years ago)
- Location:
- orxonox/branches/chris/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/chris/src/camera.cc
r2100 r2112 30 30 { 31 31 bound = NULL; 32 desired_place.r = Vector (0,0,0);33 desired_place.w = Rotation (0,0,0);34 actual_place.r = Vector (0,0,0);35 actual_place.w = Rotation (0,0,0);36 32 } 37 33 … … 53 49 { 54 50 update_desired_place (); 51 jump (NULL); 55 52 } 56 53 … … 73 70 { 74 71 desired_place.r = Vector (0,0,0); 75 desired_place.w = Rotation (0,0,0);72 desired_place.w = Quaternion (); 76 73 } 77 74 } … … 86 83 { 87 84 glMatrixMode (GL_PROJECTION); 85 glLoadIdentity (); 88 86 // view 89 87 // TO DO: implement options for frustum generation 90 glFrustum( -1.0,1.0,-1.0,1.0,1.5,20.0); 88 glFrustum( -1.0,1.0,-1.0,1.0,1.5,250.0); 89 glRotatef(h,1,0,0); 90 glRotatef(h/2,0,1,0); 91 glRotatef(h/4,0,0,1); 92 h += 3; 93 // glRotatef(90,0,0,1); 91 94 // rotation 92 float matrix[ 16];93 actual_place.w. glmatrix (matrix);94 gl LoadMatrixf (matrix);95 float matrix[4][4]; 96 actual_place.w.conjugate().matrix (matrix); 97 glMultMatrixf ((float*)matrix); 95 98 // translation 96 glTranslatef ( actual_place.r.x, actual_place.r.y,actual_place.r.z);99 glTranslatef (-actual_place.r.x, -actual_place.r.y,- actual_place.r.z); 97 100 98 101 glMatrixMode (GL_MODELVIEW); 99 102 glLoadIdentity (); 103 104 printf("Camera@%f/%f/%f\n",actual_place.r.x,actual_place.r.y,actual_place.r.z); 105 Vector unique(1,0,0); 106 Vector test = actual_place.w.apply (unique); 107 printf("Camera&%f/%f/%f\n", test.x, test.y, test.z); 100 108 } 101 109 -
orxonox/branches/chris/src/camera.h
r2100 r2112 26 26 void update_desired_place (); 27 27 28 float h; 29 28 30 public: 29 31 Camera (); -
orxonox/branches/chris/src/collision.cc
r2100 r2112 180 180 bool r = false; 181 181 int ia, ib; 182 Vector mra = pa->r + rotate_vector( ta->m, pa->w);183 Vector mrb = pb->r + rotate_vector( tb->m, pb->w);182 Vector mra = pa->r + pa->w.apply(ta->m); 183 Vector mrb = pb->r + pb->w.apply(tb->m); 184 184 CC_Tree* use_a, *use_b; 185 185 … … 333 333 bool r = false; 334 334 int i; 335 Vector mr = p->r + rotate_vector( t->m, p->w);335 Vector mr = p->r + p->w.apply (t->m); 336 336 CC_Tree* use_t; 337 337 Vector* ips; -
orxonox/branches/chris/src/coordinates.h
r2014 r2112 18 18 float dist; //!< The distance that has already been traveled on the track 19 19 Vector pos; //!< The position relative to the offset marked by the distance already covered 20 Rotation rot; //!< The direction the object is heading (relative to track direction)20 Quaternion rot; //!< The direction the object is heading (relative to track direction) 21 21 } Location; 22 22 … … 28 28 { 29 29 Vector r; //!< Absolute x/y/z coordinates 30 Rotation w; //!< Absolute orientation30 Quaternion w; //!< Absolute orientation 31 31 } Placement; 32 32 -
orxonox/branches/chris/src/orxonox.cc
r2105 r2112 139 139 glClearColor(0.0, 0.0, 0.0, 0.0); 140 140 glEnable(GL_DEPTH_TEST); 141 glEnable(GL_COLOR); 141 142 glShadeModel(GL_FLAT); 142 143 -
orxonox/branches/chris/src/player.cc
r2105 r2112 33 33 void Player::post_spawn () 34 34 { 35 travel_speed = 1 .0;35 travel_speed = 10.0; 36 36 velocity = Vector(); 37 37 bUp = bDown = bLeft = bRight = bAscend = bDescend = false; … … 71 71 { 72 72 glMatrixMode(GL_MODELVIEW); 73 float matrix[ 16];74 get_placement()->w. glmatrix (matrix);75 glLoadMatrixf ( matrix);73 float matrix[4][4]; 74 get_placement()->w.matrix (matrix); 75 glLoadMatrixf ((float*)matrix); 76 76 77 77 glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z); … … 85 85 glVertex3f(-1,+0.5,0); 86 86 glEnd(); 87 88 printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z); 87 89 } 88 90 … … 90 92 { 91 93 *locbuf = *get_location(); 92 locbuf->dist += 5.0;94 //locbuf->dist += 5.0; 93 95 } 94 96 -
orxonox/branches/chris/src/track.cc
r2101 r2112 42 42 void Track::map_camera (Location* lookat, Placement* camplc) 43 43 { 44 printf("Track|Mapping camera: %d (%f)\n", lookat->part, lookat->dist); 44 45 Line trace(*offset, *end - *offset); 45 46 float l = trace.len (); 46 47 48 // camplc->r = *offset + Vector(0,0,0.5); 49 // camplc->w = Quaternion (trace.a, Vector(0,0,1)); 50 47 51 camplc->r = trace.r + (trace.a * ((lookat->dist-10.0) / l)) + Vector(0,0,5.0); 48 camplc->w = Rotation( (trace.r + (trace.a * ((lookat->dist) / l))) - camplc->r); 52 camplc->w = Quaternion((trace.r + (trace.a * ((lookat->dist) / l)) - camplc->r), Vector(0,0,1)); 53 49 54 } 50 55 51 56 bool Track::map_coords (Location* loc, Placement* plc) 52 57 { 58 printf("Track|Mapping coords: %d (%f)\n", loc->part, loc->dist); 53 59 Line trace(*offset, *end - *offset); 54 60 float l = trace.len (); … … 61 67 } 62 68 63 Rotation dir(trace.a);69 Quaternion dir(trace.a, Vector(0,0,1)); 64 70 65 plc->r = trace.r + (trace.a * ((loc->dist) / l)) + rotate_vector( loc->pos, dir);71 plc->r = trace.r + (trace.a * ((loc->dist) / l)) + dir.apply(loc->pos); 66 72 plc->w = dir * loc->rot; 67 73 -
orxonox/branches/chris/src/vector.cc
r2101 r2112 14 14 main-programmer: Christian Meyer 15 15 co-programmer: ... 16 17 Quaternion code borrowed from an Gamasutra article by Nick Bobick and Ken Shoemake 16 18 */ 17 19 … … 177 179 f = acos( v1 * v2 / (v1.len() * v2.len())); 178 180 return f * 180 / PI; 181 } 182 183 Quaternion::Quaternion () 184 { 185 w = 1; 186 v = Vector(0,0,0); 187 } 188 189 Quaternion::Quaternion (float angle, const Vector& axis) 190 { 191 w = cos(angle/2); 192 v = axis * sin(angle/2); 193 } 194 195 Quaternion::Quaternion (const Vector& dir, const Vector& up) 196 { 197 Vector z = dir; 198 z.normalize(); 199 Vector x = up.cross(z); 200 x.normalize(); 201 Vector y = z.cross(x); 202 203 float m[4][4]; 204 m[0][0] = x.x; 205 m[0][1] = x.y; 206 m[0][2] = x.z; 207 m[0][3] = 0; 208 m[1][0] = y.x; 209 m[1][1] = y.y; 210 m[1][2] = y.z; 211 m[1][3] = 0; 212 m[2][0] = z.x; 213 m[2][1] = z.y; 214 m[2][2] = z.z; 215 m[2][3] = 0; 216 m[3][0] = 0; 217 m[3][1] = 0; 218 m[3][2] = 0; 219 m[3][3] = 1; 220 221 *this = Quaternion (m); 222 } 223 224 Quaternion::Quaternion (float roll, float pitch, float yaw) 225 { 226 float cr, cp, cy, sr, sp, sy, cpcy, spsy; 227 228 // calculate trig identities 229 cr = cos(roll/2); 230 cp = cos(pitch/2); 231 cy = cos(yaw/2); 232 233 sr = sin(roll/2); 234 sp = sin(pitch/2); 235 sy = sin(yaw/2); 236 237 cpcy = cp * cy; 238 spsy = sp * sy; 239 240 w = cr * cpcy + sr * spsy; 241 v.x = sr * cpcy - cr * spsy; 242 v.y = cr * sp * cy + sr * cp * sy; 243 v.z = cr * cp * sy - sr * sp * cy; 244 } 245 246 Quaternion Quaternion::operator*(const Quaternion& q) const 247 { 248 float A, B, C, D, E, F, G, H; 249 Quaternion r; 250 251 A = (w + v.x)*(q.w + q.v.x); 252 B = (v.z - v.y)*(q.v.y - q.v.z); 253 C = (w - v.x)*(q.v.y + q.v.z); 254 D = (v.y + v.z)*(q.w - q.v.x); 255 E = (v.x + v.z)*(q.v.x + q.v.y); 256 F = (v.x - v.z)*(q.v.x - q.v.y); 257 G = (w + v.y)*(q.w - q.v.z); 258 H = (w - v.y)*(q.w + q.v.z); 259 260 r.w = B + (-E - F + G + H)/2; 261 r.v.x = A - (E + F + G + H)/2; 262 r.v.y = C + (E - F + G - H)/2; 263 r.v.z = D + (E - F - G + H)/2; 264 265 return r; 266 } 267 268 Quaternion Quaternion::operator+(const Quaternion& q) const 269 { 270 Quaternion r(*this); 271 r.w = r.w + q.w; 272 r.v = r.v + q.v; 273 return r; 274 } 275 276 Quaternion Quaternion::operator- (const Quaternion& q) const 277 { 278 Quaternion r(*this); 279 r.w = r.w - q.w; 280 r.v = r.v - q.v; 281 return r; 282 } 283 284 Vector Quaternion::apply (Vector& v) const 285 { 286 Quaternion q; 287 q.v = v; 288 q.w = 0; 289 q = *this * q * conjugate(); 290 return q.v; 291 } 292 293 Quaternion Quaternion::operator*(const float& f) const 294 { 295 Quaternion r(*this); 296 r.w = r.w*f; 297 r.v = r.v*f; 298 return r; 299 } 300 301 Quaternion Quaternion::operator/(const float& f) const 302 { 303 if( f == 0) return Quaternion(); 304 Quaternion r(*this); 305 r.w = r.w/f; 306 r.v = r.v/f; 307 return r; 308 } 309 310 Quaternion Quaternion::conjugate() const 311 { 312 Quaternion r(*this); 313 r.v = Vector() - r.v; 314 return r; 315 } 316 317 float Quaternion::norm() const 318 { 319 return w*w + v.x*v.x + v.y*v.y + v.z*v.z; 320 } 321 322 Quaternion Quaternion::inverse() const 323 { 324 float n = norm(); 325 if (n != 0) 326 { 327 return conjugate() / norm(); 328 } 329 else return Quaternion(); 330 } 331 332 void Quaternion::matrix (float m[4][4]) const 333 { 334 float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2; 335 336 // calculate coefficients 337 x2 = v.x + v.x; 338 y2 = v.y + v.y; 339 z2 = v.z + v.z; 340 xx = v.x * x2; xy = v.x * y2; xz = v.x * z2; 341 yy = v.y * y2; yz = v.y * z2; zz = v.z * z2; 342 wx = w * x2; wy = w * y2; wz = w * z2; 343 344 m[0][0] = 1.0 - (yy + zz); m[1][0] = xy - wz; 345 m[2][0] = xz + wy; m[3][0] = 0.0; 346 347 m[0][1] = xy + wz; m[1][1] = 1.0 - (xx + zz); 348 m[2][1] = yz - wx; m[3][1] = 0.0; 349 350 m[0][2] = xz - wy; m[1][2] = yz + wx; 351 m[2][2] = 1.0 - (xx + yy); m[3][2] = 0.0; 352 353 m[0][3] = 0; m[1][3] = 0; 354 m[2][3] = 0; m[3][3] = 1; 355 } 356 357 Quaternion::Quaternion (float m[4][4]) 358 { 359 360 float tr, s, q[4]; 361 int i, j, k; 362 363 int nxt[3] = {1, 2, 0}; 364 365 tr = m[0][0] + m[1][1] + m[2][2]; 366 367 // check the diagonal 368 if (tr > 0.0) 369 { 370 s = sqrt (tr + 1.0); 371 w = s / 2.0; 372 s = 0.5 / s; 373 v.x = (m[1][2] - m[2][1]) * s; 374 v.y = (m[2][0] - m[0][2]) * s; 375 v.z = (m[0][1] - m[1][0]) * s; 376 } 377 else 378 { 379 // diagonal is negative 380 i = 0; 381 if (m[1][1] > m[0][0]) i = 1; 382 if (m[2][2] > m[i][i]) i = 2; 383 j = nxt[i]; 384 k = nxt[j]; 385 386 s = sqrt ((m[i][i] - (m[j][j] + m[k][k])) + 1.0); 387 388 q[i] = s * 0.5; 389 390 if (s != 0.0) s = 0.5 / s; 391 392 q[3] = (m[j][k] - m[k][j]) * s; 393 q[j] = (m[i][j] + m[j][i]) * s; 394 q[k] = (m[i][k] + m[k][i]) * s; 395 396 v.x = q[0]; 397 v.y = q[1]; 398 v.z = q[2]; 399 w = q[3]; 400 } 179 401 } 180 402 -
orxonox/branches/chris/src/vector.h
r2100 r2112 36 36 float angle_rad (const Vector& v1, const Vector& v2); 37 37 38 //! 3D rotation 38 //! Quaternion 39 /** 40 Class to handle 3-dimensional rotation efficiently 41 */ 42 class Quaternion 43 { 44 public: 45 Vector v; 46 float w; 47 48 Quaternion (); 49 Quaternion (float m[4][4]); 50 Quaternion (float angle, const Vector& axis); 51 Quaternion (const Vector& dir, const Vector& up); 52 Quaternion (float roll, float pitch, float yaw); 53 54 Quaternion operator/ (const float& f) const; 55 Quaternion operator* (const float& f) const; 56 Quaternion operator* (const Quaternion& q) const; 57 Quaternion operator+ (const Quaternion& q) const; 58 Quaternion operator- (const Quaternion& q) const; 59 Quaternion conjugate () const; 60 Quaternion inverse () const; 61 Vector apply (Vector& f) const; 62 float norm () const; 63 void matrix (float m[4][4]) const; 64 }; 65 66 //! 3D rotation (OBSOLETE) 39 67 /** 40 68 Class to handle 3-dimensional rotations. -
orxonox/branches/chris/src/world.cc
r2104 r2112 90 90 l = l->get_next(); 91 91 } 92 93 // draw debug coord system 94 glLoadIdentity(); 95 glBegin(GL_LINES); 96 glColor3f(1,0,0); 97 /* for( float x = -128.0; x < 128.0; x += 5.0) 98 { 99 for( float y = -128.0; y < 128.0; y += 5.0) 100 { 101 glVertex3f(x,y,-128.0); 102 glVertex3f(x,y,128.0); 103 } 104 } 105 glColor3f(0,1,0); 106 for( float y = -128.0; y < 128.0; y += 5.0) 107 { 108 for( float z = -128.0; z < 128.0; z += 5.0) 109 { 110 glVertex3f(-128.0,y,z); 111 glVertex3f(128.0,y,z); 112 } 113 } 114 glColor3f(0,0,1); 115 for( float x = -128.0; x < 128.0; x += 5.0) 116 { 117 for( float z = -128.0; z < 128.0; z += 5.0) 118 { 119 glVertex3f(x,-128.0,z); 120 glVertex3f(x,128.0,z); 121 } 122 }*/ 123 //draw track 124 glColor3f(0,1,1); 125 for( int i = 0; i < tracklen; i++) 126 { 127 glVertex3f(pathnodes[i].x,pathnodes[i].y,pathnodes[i].z); 128 glVertex3f(pathnodes[(i+1)%tracklen].x,pathnodes[(i+1)%tracklen].y,pathnodes[(i+1)%tracklen].z); 129 } 130 glEnd(); 92 131 } 93 132 -
orxonox/branches/chris/src/world.h
r2101 r2112 50 50 zeroloc.part = 0; 51 51 zeroloc.pos = Vector(); 52 zeroloc.rot = Rotation();52 zeroloc.rot = Quaternion(); 53 53 loc = &zeroloc; 54 54 } -
orxonox/branches/chris/src/world_entity.cc
r2104 r2112 83 83 void WorldEntity::draw() 84 84 { 85 cout << "WorldEntity::draw()" << endl;85 printf("WorldEntity|draw()\n"); 86 86 } 87 87
Note: See TracChangeset
for help on using the changeset viewer.