I have been working on a component based engine with nested game objects each with there own transformation's. Each game object calculates its position in the world based on its parents world transformation multipled by there own local one (ModelsWorldTransform = ParentsWorldTransform * LocalTransform).

This all works great until I attach the camera component to a model and in this scenario, as the model the camera is attached to moves away from the origin, the camera moves in the opposite direction to the movement whitest still seeming like it is in the correct position according to its mat4.

All local transformations are stored in a mat4 rather then three vec3's for position, rotation and scale to save on calculations each update having to generate new mat4's.

Transformation Component Update Code

m_world_transformation = m_local_transformation;
// If we have a parent object
if (m_parent_transform_component)
    m_world_transformation = m_parent_transform_component->GetWorldTransformation() * m_world_transformation;

Camers position buffer being updated

BufferData.view = m_transformation_component->GetWorldTransformation();

I'm not sure what i'm missing, if anyone has any sugestions that would be apreatiated.

  • \$\begingroup\$ How are you calculating the camera's position and what are you putting in the translation component of its matrix? \$\endgroup\$
    – Casey
    Jul 12, 2018 at 16:21
  • \$\begingroup\$ The Camera object has two components, the Transformation and the Camera. The transformation is calculating the cameras position and returning it to the camera through the above code "m_transformation_component->GetWorldTransformation()" and the translation component of the camera is (0,0,-15) \$\endgroup\$
    – 0xen
    Jul 12, 2018 at 16:31
  • 1
    \$\begingroup\$ Sounds like you're using the camera's location in your view matrix instead of the inverse \$\endgroup\$
    – tkausl
    Jul 12, 2018 at 16:33
  • \$\begingroup\$ @tkausl That seems to have done the trick, I change the line of code to "glm::inverse(m_transformation_component->GetWorldTransformation());" and changed the cameras position from (0,0,-15) to (0,0,15) and it all works as expected now. \$\endgroup\$
    – 0xen
    Jul 12, 2018 at 16:38


You must log in to answer this question.

Browse other questions tagged .