#ifndef HAN_MATH_AXIS_H
#define HAN_MATH_AXIS_H
#include <han/math/mathdef.h>
#include <han/math/vectorn.h>
HAN_BEGIN_NAMESPACE
struct HAN_ALIGN(16) AxisAngle
{
AxisAngle()
{
const float defaultAxis[] = { 0.f, 0.f, 1.f };
mAngle = Radians(0.0f);
mAxis = defaultAxis;
}
AxisAngle(const AxisAngle &aa)
{
mAngle = aa.mAngle;
mAxis = aa.mAxis;
}
AxisAngle(const VectorN<3> &v3)
{
mAngle = Radians(0.f);
VectorN<3> temp = v3.normalized();
temp.store(mAxis);
}
AxisAngle(const VectorN<4> &v4)
{
mAngle = Radians(v4[3]);
VectorN<3> temp; temp[0] = v4[0];
temp[1] = v4[1]; temp[2] = v4[2];
temp.normalize(); temp.store(mAxis);
}
AxisAngle &operator=(const AxisAngle &aa)
{ mAngle = aa.angle(); aa.axis(mAxis); }
const Radians& angle() const
{ return mAngle; }
void setAngle(const AxisAngle &aa)
{ mAngle = aa.mAngle; }
void setAngle(const Radians &angle)
{ mAngle = angle; }
VectorN<3> axis() const
{ return VectorN<3>(mAxis); }
void axis(VectorN<3> &result) const
{ result = mAxis; }
void axis(float *result) const
{ result[0] = mAxis[0]; result[1] = mAxis[1]; result[2] = mAxis[2]; }
void axis(float &x, float &y, float &z) const
{ x = mAxis[0]; y = mAxis[1]; z = mAxis[2]; }
void setAxis(const AxisAngle &aa)
{ mAxis = aa.mAxis; }
void setAxis(const VectorN<3> &axis)
{
VectorN<3> v = axis.normalized();
v.store(mAxis);
}
void setAxis(float x, float y, float z)
{
VectorN<3> v; v[0] = x; v[1] = y; v[2] = z;
v.normalize(); v.store(mAxis);
}
void setAxis(float *xyz)
{
VectorN<3> v; v.load(xyz);
v.normalize(); v.store(mAxis);
}
/* data */
float mAxis[3]; /* UNIT VECTOR */
Radians mAngle;
};
HAN_END_NAMESPACE
#endif