#include "transform.h"
-#include <msp/geometry/affinetransform.h>
namespace Msp::Game {
write().values.scale = s;
}
-void Transform::update_world_matrix(const Transform *parent)
+void Transform::update_world_transform(const Transform *parent)
{
using Affine = Geometry::AffineTransform<float, 3>;
Data &d = write();
- d.local_matrix = Affine::translation(d.values.position)*
+ d.local_transform = Affine::translation(d.values.position)*
Affine::rotation(d.values.rotation)*Affine::scaling(d.values.scale);
if(parent)
- d.world_matrix = parent->get_world_matrix()*d.local_matrix;
+ d.world_transform = parent->get_world_transform()*d.local_transform;
else
- d.world_matrix = d.local_matrix;
+ d.world_transform = d.local_transform;
}
} // namespace Msp::Game
#ifndef MSP_GAME_TRANSFORM_H_
#define MSP_GAME_TRANSFORM_H_
+#include <msp/geometry/affinetransform.h>
#include <msp/geometry/quaternion.h>
#include <msp/linal/matrix.h>
#include <msp/linal/vector.h>
struct TransformData
{
TransformValues values;
- LinAl::Matrix<float, 4, 4> local_matrix = LinAl::Matrix<float, 4, 4>::identity();
- LinAl::Matrix<float, 4, 4> world_matrix = LinAl::Matrix<float, 4, 4>::identity();
+ Geometry::AffineTransform<float, 3> local_transform;
+ Geometry::AffineTransform<float, 3> world_transform;
};
class MSPGAME_API Transform: public BufferedComponent<TransformData>
const LinAl::Vector<float, 3> &get_position() const { return read().values.position; }
const Geometry::Quaternion<float> &get_rotation() const { return read().values.rotation; }
const LinAl::Vector<float, 3> &get_scale() const { return read().values.scale; }
- const LinAl::Matrix<float, 4, 4> &get_world_matrix() const { return read().world_matrix; }
+ const Geometry::AffineTransform<float, 3> &get_world_transform() const { return read().world_transform; }
- void update_world_matrix(const Transform *);
+ void update_world_transform(const Transform *);
};
} // namespace Msp::Game
rebuild_transform_order();
for(const ParentedTransform &t: transforms)
- t.transform->update_world_matrix(t.parent.get());
+ t.transform->update_world_transform(t.parent.get());
block(RDWR);
}
void LightEmitter::update_matrix()
{
- light->set_matrix(entity->get_transform()->get_world_matrix());
+ light->set_matrix(entity->get_transform()->get_world_transform().get_matrix());
}
} // namespace Msp::GameView
void MeshRenderer::update_matrix()
{
- instance.set_matrix(entity->get_transform()->get_world_matrix());
+ instance.set_matrix(entity->get_transform()->get_world_transform().get_matrix());
}
} // namespace Msp::GameView
{
Game::Handle<Game::Transform> transform = active_camera->get_entity()->get_transform();
if(transform)
- gl_camera.set_object_matrix(transform->get_world_matrix());
+ gl_camera.set_object_matrix(transform->get_world_transform().get_matrix());
else
gl_camera.set_object_matrix(GL::Matrix());
}
{
if(tracking_anchor)
{
- const GL::Matrix &anchor_matrix = tracking_anchor->get_entity()->get_transform()->get_world_matrix();
- vr_tracking->set_position(anchor_matrix*GL::Vector3(0.0f, 0.0f, 0.0f));
- vr_tracking->set_up_direction((anchor_matrix*GL::Vector4(0.0f, 0.0f, 1.0f, 0.0f)).slice<3>(0));
- vr_tracking->set_forward_direction((anchor_matrix*GL::Vector4(1.0f, 0.0f, 0.0f, 0.0f)).slice<3>(0));
+ const Geometry::AffineTransform<float, 3> &anchor_tr = tracking_anchor->get_entity()->get_transform()->get_world_transform();
+ vr_tracking->set_position(anchor_tr.transform(LinAl::Vector<float, 3>(0.0f, 0.0f, 0.0f)));
+ vr_tracking->set_up_direction(anchor_tr.transform_linear(LinAl::Vector<float, 3>(0.0f, 0.0f, 1.0f)));
+ vr_tracking->set_forward_direction(anchor_tr.transform_linear(LinAl::Vector<float, 3>(1.0f, 0.0f, 0.0f)));
}
vr_tracking->update_for_render();
}