Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9639 in orxonox.OLD for branches/proxy/src/lib/math/quaternion.cc


Ignore:
Timestamp:
Jul 31, 2006, 9:30:52 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: tmuch better lookAt implementation, so that the Turrets are really aiming at the designated target.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/lib/math/quaternion.cc

    r9110 r9639  
    336336  // check the diagonal
    337337  float tr = mat[0][0] + mat[1][1] + mat[2][2];
    338   if( tr > 0.0f) {
     338  if( tr > 0.0f)
     339  {
    339340    float s = (float)sqrtf(tr + 1.0f);
    340341    this->w = s * 0.5f;
     
    372373}
    373374
     375Quaternion Quaternion::lookAt(Vector from, Vector to, Vector up)
     376{
     377  Vector n = to - from;
     378  n.normalize();
     379  Vector v = n.cross(up);
     380  v.normalize();
     381  Vector u = v.cross(n);
     382
     383  float matrix[3][3];
     384  matrix[0][0] = v.x;
     385  matrix[0][1] = v.y;
     386  matrix[0][2] = v.z;
     387  matrix[1][0] = u.x;
     388  matrix[1][1] = u.y;
     389  matrix[1][2] = u.z;
     390  matrix[2][0] = -n.x;
     391  matrix[2][1] = -n.y;
     392  matrix[2][2] = -n.z;
     393
     394  Quaternion quat;
     395  quat.from3x3(matrix);
     396  return quat;
     397}
     398
     399
    374400/**
    375401 * @brief outputs some nice formated debug information about this quaternion
Note: See TracChangeset for help on using the changeset viewer.