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.setRotationAxis(m_WorldOrientation.getAngle(), m_WorldOrientation.getAxis());

    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];


    // Draw current object

  • 1
    \$\begingroup\$ Why can't you use shaders? If you are learning OpenGL you should be using shaders, otherwise you won't use any of your knowledge in the real world. \$\endgroup\$ – Luke B. Nov 30 '14 at 15:43
  • \$\begingroup\$ In Blender don't need Shaders for local/world transform like position, orientation and scale. in Blender each object has worldPosition, localPosition, without Shaders. See \$\endgroup\$ – WalbertiEvaristo Nov 30 '14 at 17:31
  • \$\begingroup\$ Are you sure you know what shaders are? You can store local position as long as you transform it to world space when you render. Is that what you want to know? How to go from local to global in a hierarchy? \$\endgroup\$ – Luke B. Nov 30 '14 at 18:13
  • \$\begingroup\$ Yes, in my program each object has "worldPosition worldOrientation and Worldscale" as access variables. The problem is that are global changes, I want to implement "localPosition, localOrientation ..." I do not know how to apply the world and the local in the matrix for later use glMultMatrix. Sorry for the English, I'm using Google Translator \$\endgroup\$ – WalbertiEvaristo Nov 30 '14 at 18:32
  • \$\begingroup\$ Can you explain the 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\$ – Trevor Powell May 30 '15 at 1:43

You should:

  • bind the shader with the modelview matrix for transforming the first object
  • bind the buffer with the vertex data for the first object
  • draw
  • bind the shader with the modelview matrix for transforming the second object (or use the same shader and change only matrix through uniform)
  • bind buffer with the vertex data for the second object
  • draw

similar question

  • \$\begingroup\$ Thanks, but I need to do this without using shaders. \$\endgroup\$ – WalbertiEvaristo Nov 30 '14 at 14:55
  • \$\begingroup\$ then you can use glPushMatrix and glPopMatrix (youtube.com/watch?v=WYD6zDiI_3A) ... but nowadays you should be uisng shaders \$\endgroup\$ – user867308 Nov 30 '14 at 15:55
  • \$\begingroup\$ I already did. What I want is to replace the function translate by variables, eg object->m_LocalPosition Vecto3 = (0, 1, 0) instead object->translate (Vector3 (0, 1, 0), true) \$\endgroup\$ – WalbertiEvaristo Nov 30 '14 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.