Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 21st, 2010 | Syntax: C++ | Size: 1.84 KB | Hits: 54 | Expires: Never
Copy text to clipboard
  1. #ifndef HAN_MATH_AXIS_H
  2. #define HAN_MATH_AXIS_H
  3.  
  4. #include <han/math/mathdef.h>
  5. #include <han/math/vectorn.h>
  6.  
  7. HAN_BEGIN_NAMESPACE
  8.  
  9. struct HAN_ALIGN(16) AxisAngle
  10. {
  11.   AxisAngle()
  12.   {
  13.     const float defaultAxis[] = { 0.f, 0.f, 1.f };
  14.     mAngle = Radians(0.0f);
  15.     mAxis = defaultAxis;
  16.   }
  17.  
  18.   AxisAngle(const AxisAngle &aa)
  19.   {
  20.     mAngle = aa.mAngle;
  21.     mAxis = aa.mAxis;
  22.   }
  23.  
  24.   AxisAngle(const VectorN<3> &v3)
  25.   {
  26.     mAngle = Radians(0.f);
  27.     VectorN<3> temp = v3.normalized();
  28.     temp.store(mAxis);
  29.   }
  30.  
  31.   AxisAngle(const VectorN<4> &v4)
  32.   {
  33.     mAngle = Radians(v4[3]);
  34.     VectorN<3> temp; temp[0] = v4[0];
  35.     temp[1] = v4[1]; temp[2] = v4[2];
  36.     temp.normalize(); temp.store(mAxis);
  37.   }
  38.  
  39.   AxisAngle &operator=(const AxisAngle &aa)
  40.   { mAngle = aa.angle(); aa.axis(mAxis); }
  41.  
  42.   const Radians& angle() const
  43.   { return mAngle; }
  44.  
  45.   void setAngle(const AxisAngle &aa)
  46.   { mAngle = aa.mAngle; }
  47.   void setAngle(const Radians &angle)
  48.   { mAngle = angle; }
  49.  
  50.   VectorN<3> axis() const
  51.   { return VectorN<3>(mAxis); }
  52.  
  53.   void axis(VectorN<3> &result) const
  54.   { result = mAxis; }
  55.   void axis(float *result) const
  56.   { result[0] = mAxis[0]; result[1] = mAxis[1]; result[2] = mAxis[2]; }
  57.   void axis(float &x, float &y, float &z) const
  58.   { x = mAxis[0]; y = mAxis[1]; z = mAxis[2]; }
  59.  
  60.   void setAxis(const AxisAngle &aa)
  61.   { mAxis = aa.mAxis; }
  62.  
  63.   void setAxis(const VectorN<3> &axis)
  64.   {
  65.     VectorN<3> v = axis.normalized();
  66.     v.store(mAxis);
  67.   }
  68.   void setAxis(float x, float y, float z)
  69.   {
  70.     VectorN<3> v; v[0] = x; v[1] = y; v[2] = z;
  71.     v.normalize(); v.store(mAxis);
  72.   }
  73.  
  74.   void setAxis(float *xyz)
  75.   {
  76.     VectorN<3> v; v.load(xyz);
  77.     v.normalize(); v.store(mAxis);
  78.   }
  79.  
  80.  
  81.   /* data */
  82.   float mAxis[3]; /* UNIT VECTOR */
  83.   Radians mAngle;
  84. };
  85.  
  86. HAN_END_NAMESPACE
  87.  
  88. #endif