I'm developing an OpenGL program where each object / entity contains m_WorldPosition, m_WorldOrientation, m_WorldScale and m_WorldTransform (Vector3, Quaternion, Vector3 and Matrix4f).
The problem is that these transformations are global. So I move, rotate and scale an object / entity I need to use a function that I did.
// C++
void HEntity::translate(const HVec3f& pos, const bool local)
{
if(local) {
m_WorldPosition += m_WorldOrientation.toMatrix3() * pos;
} else {
m_WorldPosition += pos;
}
m_NeedTransformUpdate = true;
}
I wanted to do the same as other software such as Blender or Unity3D 3D where each object / entity contains the variables position, localPosition, rotation, localRotation...
I want a similar system. Where I have the variables position, localPosition, orientation, localOrientation, scale, localScale. But I do not know how to apply it to matrix Each object / entity.
Below is the function to compute the matrix.
// C++
void HEntity::updateTransform()
{
m_WorldTransform.identity();
m_WorldTransform.setRotationAxis(m_WorldOrientation.getAngle(), m_WorldOrientation.getAxis());
m_WorldTransform.scale(m_WorldScaling);
m_WorldTransform.translate(m_WorldPosition);
if(m_pParent) {
m_WorldTransform = m_pParent->m_WorldTransform * m_WorldTransform;
}
}
And the game loop
// C++ - Game loop
HGameObject* object = NULL;
int index = 0;
for(; m_ObjectCount; index++)
{
object = m_pObjectList[index];
glMultMatrixf(object->m_WorldTransform.getTranspose());
// Draw current object
glPopMatrix();
}
m_WorldTransform = m_pParent->m_WorldTransform * m_WorldTransform;line in your code? Why are you adjusting your WORLD matrix by the parent's WORLD matrix, if they're WORLD matrices already? \$\endgroup\$