more math & testing
This commit is contained in:
@@ -27,15 +27,15 @@ void Transform::CreateTransform(float* out, bx::Vec3 pos, bx::Quaternion rot, bx
|
||||
bx::mtxMul(out, buf, tMat);
|
||||
}
|
||||
|
||||
void Transform::Translate(bx::Vec3 offset)
|
||||
void Transform::Translate(Vec3 offset)
|
||||
{
|
||||
Position = bx::add(Position, offset);
|
||||
Position = bx::add(Position, {offset.x, offset.y, offset.z});
|
||||
}
|
||||
|
||||
void Transform::TranslateLocal(bx::Vec3 offset)
|
||||
void Transform::TranslateLocal(Vec3 offset)
|
||||
{
|
||||
bx::Vec3 localOffset = GlobalToLocalDirection(offset);
|
||||
Position = bx::add(Position, localOffset);
|
||||
Vec3 localOffset = GlobalToLocalDirection(offset);
|
||||
Position = bx::add(Position, {localOffset.x, localOffset.y, localOffset.z});
|
||||
}
|
||||
|
||||
void Transform::Rotate(bx::Vec3 rotation)
|
||||
@@ -56,17 +56,17 @@ void Transform::RotateLocal(bx::Vec3 rotation)
|
||||
bx::memCopy(Rotation.M, temp, sizeof(temp));
|
||||
}
|
||||
|
||||
bx::Vec3 Transform::Right() const
|
||||
Vec3 Transform::Right() const
|
||||
{
|
||||
return {M.M[0], M.M[1], M.M[2]};
|
||||
}
|
||||
|
||||
bx::Vec3 Transform::Up() const
|
||||
Vec3 Transform::Up() const
|
||||
{
|
||||
return {M.M[4], M.M[5], M.M[6]};
|
||||
}
|
||||
|
||||
bx::Vec3 Transform::Forward() const
|
||||
Vec3 Transform::Forward() const
|
||||
{
|
||||
return {M.M[8], M.M[9], M.M[10]};
|
||||
}
|
||||
@@ -120,7 +120,7 @@ namespace Game
|
||||
return reinterpret_cast<void*>(ptrAligned);
|
||||
}
|
||||
} // namespace Game
|
||||
bx::Vec3 Transform::GlobalToLocalDirection(bx::Vec3 global)
|
||||
Vec3 Transform::GlobalToLocalDirection(Vec3 global)
|
||||
{
|
||||
UpdateMatrix();
|
||||
float in[4]{global.x, global.y, global.z, 0.0f};
|
||||
@@ -136,7 +136,7 @@ bx::Vec3 Transform::GlobalToLocalPoint(bx::Vec3 global)
|
||||
bx::vec4MulMtx(out, in, MI.M);
|
||||
return {out[0], out[1], out[2]};
|
||||
}
|
||||
bx::Vec3 Transform::LocalToGlobalDirection(bx::Vec3 local)
|
||||
Vec3 Transform::LocalToGlobalDirection(Vec3 local)
|
||||
{
|
||||
UpdateMatrix();
|
||||
float in[4]{local.x, local.y, local.z, 0.0f};
|
||||
@@ -152,3 +152,23 @@ bx::Vec3 Transform::LocalToGlobalPoint(bx::Vec3 local)
|
||||
bx::vec4MulMtx(out, in, M.M);
|
||||
return {out[0], out[1], out[2]};
|
||||
}
|
||||
void Transform::SetPosition(Vec3 pos)
|
||||
{
|
||||
Position = {pos.x, pos.y, pos.z};
|
||||
}
|
||||
Vec3 Transform::GetPosition()
|
||||
{
|
||||
return {Position.x, Position.y, Position.z};
|
||||
}
|
||||
Mat4 Mat4::Inverse()
|
||||
{
|
||||
Mat4 result;
|
||||
bx::mtxInverse(result.M, M);
|
||||
return result;
|
||||
}
|
||||
Mat4 Mat4::Transpose()
|
||||
{
|
||||
Mat4 result;
|
||||
bx::mtxTranspose(result.M, M);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user