*
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
#ifndef ITransform_h__
|
||||
#define ITransform_h__
|
||||
#include "math/LifeMath.h"
|
||||
#include "delegate/Delegate.h"
|
||||
|
||||
namespace LifeCore
|
||||
{
|
||||
class ITransform
|
||||
{
|
||||
private:
|
||||
LifeMath::float3 position;
|
||||
LifeMath::Quaternion rotation;
|
||||
LifeMath::float3 scaling;
|
||||
LifeMath::float4x4 transform;
|
||||
bool valid;
|
||||
|
||||
public:
|
||||
EVENT(TransformEvent);
|
||||
TransformEvent Event_SetPosition;
|
||||
TransformEvent Event_SetRotation;
|
||||
TransformEvent Event_SetScaling;
|
||||
|
||||
void UpdateTransform()
|
||||
{
|
||||
LifeMath::float4x4 trans;
|
||||
Mat4x4Translation(position, trans);
|
||||
|
||||
LifeMath::float4x4 scale;
|
||||
Mat4x4Scaling(scaling, scale);
|
||||
|
||||
LifeMath::float4x4 rot;
|
||||
Mat4x4RotationQuaternion(rotation, rot);
|
||||
|
||||
transform = scale * rot * trans;
|
||||
valid = true;
|
||||
}
|
||||
bool IsValid()
|
||||
{
|
||||
return valid;
|
||||
}
|
||||
ITransform()
|
||||
:valid(false), position(0.0f, 0.0f, 0.0f), scaling(1.0f, 1.0f, 1.0f)
|
||||
{
|
||||
QuatSetAxisAngle(LifeMath::float3(0.0f, 0.0f, 0.0f), 0.0f, rotation);
|
||||
UpdateTransform();
|
||||
}
|
||||
~ITransform()
|
||||
{
|
||||
}
|
||||
const LifeMath::float4x4& GetMatrix()
|
||||
{
|
||||
if(!valid)
|
||||
UpdateTransform();
|
||||
return transform;
|
||||
}
|
||||
const LifeMath::float3& GetPosition() const
|
||||
{
|
||||
return position;
|
||||
}
|
||||
const LifeMath::float3& GetScaling() const
|
||||
{
|
||||
return scaling;
|
||||
}
|
||||
const LifeMath::Quaternion& GetRotation() const
|
||||
{
|
||||
return rotation;
|
||||
}
|
||||
|
||||
void SetMatrix(const LifeMath::float4x4& newTransform)
|
||||
{
|
||||
transform = newTransform;
|
||||
Mat4x4Decompose(transform, position, scaling, rotation);
|
||||
valid = true;
|
||||
}
|
||||
void SetPosition(const LifeMath::float3& _position)
|
||||
{
|
||||
if(position != _position)
|
||||
{
|
||||
position = _position;
|
||||
valid = false;
|
||||
Event_SetPosition.Invoke();
|
||||
}
|
||||
}
|
||||
void SetRotation(const LifeMath::Quaternion& _rotation)
|
||||
{
|
||||
if(rotation != _rotation)
|
||||
{
|
||||
rotation = _rotation;
|
||||
valid = false;
|
||||
Event_SetRotation.Invoke();
|
||||
}
|
||||
}
|
||||
void SetRotation(const LifeMath::float3& axis, float angle)
|
||||
{
|
||||
QuatSetAxisAngle(axis, angle, rotation);
|
||||
valid = false;
|
||||
Event_SetRotation.Invoke();
|
||||
}
|
||||
void SetAngles(const LifeMath::float3& angles)
|
||||
{
|
||||
printf("OMG! SetAngles isn't implemented!!");
|
||||
}
|
||||
void SetScaling(const LifeMath::float3& _scaling)
|
||||
{
|
||||
if(scaling != _scaling)
|
||||
{
|
||||
scaling = _scaling;
|
||||
valid = false;
|
||||
Event_SetScaling.Invoke();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // ITransform_h__
|
||||
Reference in New Issue
Block a user