Added construct funtions for Transform??? classes
This commit is contained in:
parent
444965aa28
commit
1fd9db0545
@ -19,8 +19,22 @@ namespace hgl
|
||||
|
||||
#define DEFINE_MATRIX(num) using Matrix##num##f=glm::mat##num; \
|
||||
const Matrix##num##f Identity##num##f=Matrix##num##f(1.0f); \
|
||||
inline bool IsIdentityMatrix(const Matrix##num##f &m){return(hgl_cmp(m,Identity##num##f)==0);} \
|
||||
inline int FastMatrixComp(const Matrix##num##f &m1,const Matrix##num##f &m2){return hgl_cmp(m1,m2);}
|
||||
inline bool IsIdentityMatrix(const Matrix##num##f &m){return(hgl_cmp(m,Identity##num##f)==0);} \
|
||||
inline bool IsNearlyEqual(const Matrix##num##f &m1,const Matrix##num##f &m2) \
|
||||
{ \
|
||||
float *f1=(float *)&m1;\
|
||||
float *f2=(float *)&m2;\
|
||||
\
|
||||
for(int i=0;i<sizeof(Matrix##num##f)/sizeof(float);i++) \
|
||||
{ \
|
||||
if(!IsNearlyEqual(*f1,*f2)) \
|
||||
return(false); \
|
||||
\
|
||||
++f1;++f2; \
|
||||
} \
|
||||
\
|
||||
return(true); \
|
||||
}
|
||||
|
||||
DEFINE_MATRIX(2)
|
||||
DEFINE_MATRIX(3)
|
||||
@ -206,19 +220,19 @@ namespace hgl
|
||||
return normalize(m*v);
|
||||
}
|
||||
|
||||
inline Matrix3f TransformMatrix(const Matrix3f &root,const Matrix3f &child)
|
||||
inline Matrix3f MatrixMult(const Matrix3f &parent,const Matrix3f &child)
|
||||
{
|
||||
return root*child;
|
||||
return parent*child;
|
||||
}
|
||||
|
||||
inline Matrix3f TransformMatrix(const Matrix4f &root,const Matrix3f &child)
|
||||
inline Matrix3f MatrixMult(const Matrix4f &parent,const Matrix3f &child)
|
||||
{
|
||||
return Matrix3f(root*Matrix4f(child));
|
||||
return Matrix3f(parent*Matrix4f(child));
|
||||
}
|
||||
|
||||
inline Matrix4f TransformMatrix(const Matrix4f &root,const Matrix4f &child)
|
||||
inline Matrix4f MatrixMult(const Matrix4f &parent,const Matrix4f &child)
|
||||
{
|
||||
return root*child;
|
||||
return parent*child;
|
||||
}
|
||||
|
||||
const Matrix4f GetRotateMatrix(const Vector3f &world_position,const Vector3f &old_direction,const Vector3f &new_direction);
|
||||
|
@ -73,6 +73,18 @@ namespace hgl
|
||||
|
||||
virtual constexpr const size_t GetTypeHash()const override { return hgl::GetTypeHash<TransformMatrix>(); }
|
||||
|
||||
public:
|
||||
|
||||
TransformMatrix() :TransformBase()
|
||||
{
|
||||
transform_matrix=Identity4f;
|
||||
}
|
||||
|
||||
TransformMatrix(const Matrix4f &mat) :TransformBase()
|
||||
{
|
||||
transform_matrix=mat;
|
||||
}
|
||||
|
||||
const Matrix4f &GetTransformMatrix()const { return transform_matrix; }
|
||||
|
||||
void SetTransformMatrix(const Matrix4f &mat)
|
||||
@ -98,6 +110,18 @@ namespace hgl
|
||||
|
||||
virtual constexpr const size_t GetTypeHash()const override{return hgl::GetTypeHash<TransformTranslate3f>();}
|
||||
|
||||
public:
|
||||
|
||||
TransformTranslate3f():TransformBase()
|
||||
{
|
||||
offset=ZeroVector3f;
|
||||
}
|
||||
|
||||
TransformTranslate3f(const Vector3f &o) :TransformBase()
|
||||
{
|
||||
offset=o;
|
||||
}
|
||||
|
||||
const Vector3f &GetOffset()const { return offset; }
|
||||
void SetOffset(const Vector3f &o)
|
||||
{
|
||||
@ -121,7 +145,9 @@ namespace hgl
|
||||
{
|
||||
mat=translate(offset);
|
||||
}
|
||||
};//class TransformTranslate
|
||||
};//class TransformTranslate3f
|
||||
|
||||
using TransformMove3f=TransformTranslate3f;
|
||||
|
||||
class TransformRotateQuat :public TransformBase
|
||||
{
|
||||
@ -131,6 +157,18 @@ namespace hgl
|
||||
|
||||
virtual constexpr const size_t GetTypeHash()const override{return hgl::GetTypeHash<TransformRotateQuat>();}
|
||||
|
||||
public:
|
||||
|
||||
TransformRotateQuat() :TransformBase()
|
||||
{
|
||||
quat=IdentityQuatf;
|
||||
}
|
||||
|
||||
TransformRotateQuat(const Quatf &q) :TransformBase()
|
||||
{
|
||||
quat=q;
|
||||
}
|
||||
|
||||
const Quatf &GetQuat()const { return quat; }
|
||||
void SetQuat(const Quatf &q)
|
||||
{
|
||||
@ -156,6 +194,20 @@ namespace hgl
|
||||
|
||||
virtual constexpr const size_t GetTypeHash()const override { return hgl::GetTypeHash<TransformRotateAxis>(); }
|
||||
|
||||
public:
|
||||
|
||||
TransformRotateAxis():TransformBase()
|
||||
{
|
||||
axis=ZeroVector3f;
|
||||
angle=0;
|
||||
}
|
||||
|
||||
TransformRotateAxis(const Vector3f &a,float ang) :TransformBase()
|
||||
{
|
||||
axis=a;
|
||||
angle=ang;
|
||||
}
|
||||
|
||||
const Vector3f &GetAxis()const { return axis; }
|
||||
const float GetAngle()const { return angle; }
|
||||
|
||||
@ -201,6 +253,18 @@ namespace hgl
|
||||
|
||||
virtual constexpr const size_t GetTypeHash()const override { return hgl::GetTypeHash<TransformRotateEuler>(); }
|
||||
|
||||
public:
|
||||
|
||||
TransformRotateEuler() :TransformBase()
|
||||
{
|
||||
euler=ZeroVector3f;
|
||||
}
|
||||
|
||||
TransformRotateEuler(const Vector3f &e) :TransformBase()
|
||||
{
|
||||
euler=e;
|
||||
}
|
||||
|
||||
const Vector3f &GetEuler()const { return euler; }
|
||||
|
||||
const float GetPitch()const { return euler.x; }
|
||||
@ -226,6 +290,18 @@ namespace hgl
|
||||
|
||||
virtual constexpr const size_t GetTypeHash()const override { return hgl::GetTypeHash<TransformScale3f>(); }
|
||||
|
||||
public:
|
||||
|
||||
TransformScale3f() :TransformBase()
|
||||
{
|
||||
scale3f=Vector3f(1,1,1);
|
||||
}
|
||||
|
||||
TransformScale3f(const Vector3f &s) :TransformBase()
|
||||
{
|
||||
scale3f=s;
|
||||
}
|
||||
|
||||
const Vector3f &GetScale()const { return scale3f; }
|
||||
void SetScale(const Vector3f &s)
|
||||
{
|
||||
@ -353,6 +429,73 @@ namespace hgl
|
||||
UpdateVersion();
|
||||
}
|
||||
|
||||
TransformTranslate3f *AddTranslate(const Vector3f &v)
|
||||
{
|
||||
TransformTranslate3f *tt=new TransformTranslate3f(v);
|
||||
|
||||
AddTransform(tt);
|
||||
|
||||
return tt;
|
||||
}
|
||||
|
||||
TransformMove3f *AddMove(const Vector3f &v){return AddTranslate(v); }
|
||||
|
||||
TransformRotateAxis *AddRotateAxis(const Vector3f &axis,const float angle)
|
||||
{
|
||||
TransformRotateAxis *tra=new TransformRotateAxis(axis,angle);
|
||||
|
||||
AddTransform(tra);
|
||||
|
||||
return tra;
|
||||
}
|
||||
|
||||
TransformRotateQuat *AddRotateQuat(const Quatf &q)
|
||||
{
|
||||
TransformRotateQuat *trq=new TransformRotateQuat(q);
|
||||
|
||||
AddTransform(trq);
|
||||
|
||||
return trq;
|
||||
}
|
||||
|
||||
TransformRotateEuler *AddRotateEuler(const Vector3f &euler)
|
||||
{
|
||||
TransformRotateEuler *tre=new TransformRotateEuler(euler);
|
||||
|
||||
AddTransform(tre);
|
||||
|
||||
return tre;
|
||||
}
|
||||
|
||||
TransformScale3f *AddScale(const Vector3f &v)
|
||||
{
|
||||
TransformScale3f *ts=new TransformScale3f(v);
|
||||
|
||||
AddTransform(ts);
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
||||
TransformLookAt *AddLookAt(const Vector3f &eye,const Vector3f ¢er,const Vector3f &up)
|
||||
{
|
||||
TransformLookAt *tla=new TransformLookAt;
|
||||
|
||||
tla->SetLookAt(eye,center,up);
|
||||
|
||||
AddTransform(tla);
|
||||
|
||||
return tla;
|
||||
}
|
||||
|
||||
TransformMatrix *AddMatrix(const Matrix4f &mat)
|
||||
{
|
||||
TransformMatrix *tm=new TransformMatrix(mat);
|
||||
|
||||
AddTransform(tm);
|
||||
|
||||
return tm;
|
||||
}
|
||||
|
||||
void RemoveTransform(TransformBase *tb)
|
||||
{
|
||||
if(!tb)
|
||||
|
Loading…
x
Reference in New Issue
Block a user