Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4122 in orxonox.OLD for orxonox/branches/heightMap/src/lib/math


Ignore:
Timestamp:
May 9, 2005, 11:29:19 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/heightMap: merged the Trunk back into branches/heightMap:
merged with Command
svn merge -r 3918:HEAD trunk branches/heightMap
conflicts resolved in favor of the Trunk

Location:
orxonox/branches/heightMap
Files:
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/heightMap

    • Property svn:externals
      •  

        old new  
        1 data http://svn.orxonox.ethz.ch/data
         1
  • orxonox/branches/heightMap/src/lib/math/vector.cc

    r3860 r4122  
    100100*/
    101101
    102 Vector* Vector::getNormalized()
     102Vector Vector::getNormalized()
    103103{
    104104  float l = len();
    105105  if(unlikely(l != 1.0))
    106106    {
    107       return this;
     107      return *this;
    108108    }
    109109  else if(unlikely(l == 0.0))
    110110    {
    111       return 0;
     111      return *this;
    112112    }
    113113
    114   return new Vector(x / l, y /l, z / l);
     114  return *this / l;
    115115}
    116116
     
    172172   \brief Outputs the values of the Vector
    173173*/
    174 void Vector::debug(void)
     174void Vector::debug(void) const
    175175{
    176176  PRINT(0)("Vector Debug information\n");
     
    435435/**
    436436   \brief performs a smooth move.
    437    \param from from where
    438    \param to to where
    439    \param t the time this transformation should take
    440    \param res The approximation-density
    441 */
    442 void Quaternion::quatSlerp(const Quaternion* from, const Quaternion* to, float t, Quaternion* res)
     437   \param from  where
     438   \param to where
     439   \param t the time this transformation should take value [0..1]
     440
     441   \returns the Result of the smooth move
     442*/
     443Quaternion quatSlerp(const Quaternion& from, const Quaternion& to, float t)
    443444{
    444445  float tol[4];
    445446  double omega, cosom, sinom, scale0, scale1;
    446   DELTA = 0.2;
    447 
    448   cosom = from->v.x * to->v.x + from->v.y * to->v.y + from->v.z * to->v.z + from->w * to->w;
     447  //  float DELTA = 0.2;
     448
     449  cosom = from.v.x * to.v.x + from.v.y * to.v.y + from.v.z * to.v.z + from.w * to.w;
    449450
    450451  if( cosom < 0.0 )
    451452    {
    452453      cosom = -cosom;
    453       tol[0] = -to->v.x;
    454       tol[1] = -to->v.y;
    455       tol[2] = -to->v.z;
    456       tol[3] = -to->w;
     454      tol[0] = -to.v.x;
     455      tol[1] = -to.v.y;
     456      tol[2] = -to.v.z;
     457      tol[3] = -to.w;
    457458    }
    458459  else
    459460    {
    460       tol[0] = to->v.x;
    461       tol[1] = to->v.y;
    462       tol[2] = to->v.z;
    463       tol[3] = to->w;
     461      tol[0] = to.v.x;
     462      tol[1] = to.v.y;
     463      tol[2] = to.v.z;
     464      tol[3] = to.w;
    464465    }
    465466 
    466467  //if( (1.0 - cosom) > DELTA )
    467468  //{
    468       omega = acos(cosom);
    469       sinom = sin(omega);
    470       scale0 = sin((1.0 - t) * omega) / sinom;
    471       scale1 = sin(t * omega) / sinom;
    472       //}
    473       /*
    474   else
     469  omega = acos(cosom);
     470  sinom = sin(omega);
     471  scale0 = sin((1.0 - t) * omega) / sinom;
     472  scale1 = sin(t * omega) / sinom;
     473  //}
     474  /*
     475    else
    475476    {
    476       scale0 = 1.0 - t;
    477       scale1 = t;
     477    scale0 = 1.0 - t;
     478    scale1 = t;
    478479    }
    479       */
    480   res->v.x = scale0 * from->v.x + scale1 * tol[0];
    481   res->v.y = scale0 * from->v.y + scale1 * tol[1];
    482   res->v.z = scale0 * from->v.z + scale1 * tol[2];
    483   res->w = scale0 * from->w + scale1 * tol[3];
     480  */
     481
     482
     483  /*
     484    Quaternion res;
     485    res.v.x = scale0 * from.v.x + scale1 * tol[0];
     486    res.v.y = scale0 * from.v.y + scale1 * tol[1];
     487    res.v.z = scale0 * from.v.z + scale1 * tol[2];
     488    res.w = scale0 * from.w + scale1 * tol[3];
     489  */
     490  return Quaternion(Vector(scale0 * from.v.x + scale1 * tol[0],
     491                           scale0 * from.v.y + scale1 * tol[1],
     492                           scale0 * from.v.z + scale1 * tol[2]),
     493                    scale0 * from.w + scale1 * tol[3]);
    484494}
    485495
  • orxonox/branches/heightMap/src/lib/math/vector.h

    r3860 r4122  
    3131
    3232  inline Vector operator+ (const Vector& v) const { return Vector(x + v.x, y + v.y, z + v.z); }
     33  inline const Vector& operator+= (const Vector& v) {this->x += v.x; this->y += v.y; this->z += v.z; return *this;}
    3334  inline Vector operator- (const Vector& v) const { return Vector(x - v.x, y - v.y, z - v.z); }
     35  inline const Vector& operator-= (const Vector& v) {this->x -= v.x; this->y -= v.y; this->z -= v.z; return *this;}
    3436  inline float operator* (const Vector& v) const { return x * v.x + y * v.y + z * v.z; }
     37  inline const Vector& operator*= (const Vector& v) {this->x *= v.x; this->y *= v.y; this->z *= v.z; return *this;}
    3538  inline Vector operator* (float f) const { return Vector(x * f, y * f, z * f); }
     39  inline const Vector& operator*= (float f) {this->x *= f; this->y *= f; this->z *= f; return *this;}
    3640  Vector operator/ (float f) const;
     41  inline const Vector& operator/= (float f) {this->x /= f; this->y /= f; this->z /= f; return *this;}
     42  inline const Vector& operator= (const Vector& v) {this->x = v.x; this->y = v.y; this->z = v.z; return *this;}
    3743  float dot (const Vector& v) const;
    38   inline Vector cross (const Vector& v) const {  return Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); }
     44  inline Vector cross (const Vector& v) const { return Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); }
    3945  void scale(const Vector& v);
    4046  inline float len() const { return sqrt (x*x+y*y+z*z); }
     
    5056                      z = z / l;
    5157                    }
    52   Vector* getNormalized();
     58  Vector getNormalized();
    5359  Vector abs();
    5460
    55   void debug();
     61  void debug() const;
    5662};
    5763
     
    7076 
    7177  inline Quaternion () { w = 1; v = Vector(0,0,0); }
    72   inline Quaternion (const Vector& b, float a) { w = a; v = b; }
     78  inline Quaternion (const Vector& v, float f) { this->w = f; this->v = v; }
    7379  Quaternion (float m[4][4]);
    7480  inline Quaternion (float angle, const Vector& axis) { w = cos(angle/2); v = axis * sin(angle/2); }
     
    7682  Quaternion (float roll, float pitch, float yaw);
    7783  Quaternion operator/ (const float& f) const;
     84  inline const Quaternion operator/= (const float& f) {*this = *this / f; return *this;}
    7885  Quaternion operator* (const float& f) const;
     86  inline const Quaternion operator*= (const float& f) {*this = *this * f; return *this;}
    7987  Quaternion operator* (const Quaternion& q) const;
     88  inline const Quaternion operator*= (const Quaternion& q) {*this = *this * q; return *this;}
    8089  inline Quaternion operator+ (const Quaternion& q) const { return Quaternion(q.v + v, q.w + w); }
     90  inline const Quaternion& operator+= (const Quaternion& q) {this->v += q.v; this->w += q.w; return *this;}
    8191  inline Quaternion operator- (const Quaternion& q) const { return Quaternion(q.v - v, q.w - w); }
     92  inline const Quaternion& operator-= (const Quaternion& q) {this->v -= q.v; this->w -= q.w; return *this;}
     93  inline Quaternion operator= (const Quaternion& q) {this->v = q.v; this->w = q.w; return *this;}
    8294  Quaternion conjugate () const {  Quaternion r(*this);
    8395  r.v = Vector() - r.v;
     
    8799  float norm () const;
    88100  void matrix (float m[4][4]) const;
    89   void quatSlerp(const Quaternion* from, const Quaternion* to, const float t, Quaternion* res);
    90101 
    91102  void debug();
    92  private:
    93   float DELTA;      //!< resolution of calculation
     103};
    94104
    95 };
     105Quaternion quatSlerp(const Quaternion& from, const Quaternion& to, float t);
     106
     107
    96108
    97109//! 3D rotation (OBSOLETE)
Note: See TracChangeset for help on using the changeset viewer.