Thread: How to find relative translation...

1. How to find relative translation...

My question is about the math involved in scene graphs and how they determine relative translations..

Say I have a node in my tree that is the terrain, positioned at 0, 0, 0.

What mathematical equation do I use to find the transformation variables for a dwarf which is located relatively to the above node...

I know you have to take the terrains transformation matrix, which should read out 0, 0, 0 to gltranslate... but do I add the dwarf's transformation matrix to find his relative location, or multiply it?

I havn't taken any math classes in over 2 years and I admit I'm a bit rusty with my algebra.

I'll show you the code I have...

Code:
```class CDOFNode : public CSceneNode
{
public:

CDOFNode()
{
}

~CDOFNode() { }

void Update()
{

glPushMatrix();
this->FinalMatrix = LocalMatrix * ParentNode->FinalMatrix;

CSceneNode::Update();
glPopMatrix();
}

void Initialize( Vector4 translation) // Updates local matrix
{
LocalMatrix.Translation(translation);
}

private:

Matrix4 LocalMatrix;
};```
This doesn't work at all, seeing as how when my program runs I get polygons all over the screen, kinda like a kaleidoscope. I ran the debug and it's obvious that my FinalMatrix is not what it should be.

Any help?

2. I think you are confusing matrix chains for use in bone and skeletal systems with transformation matrices used for positioning objects. If you want to position an object at x,y,z then you create a translation matrix that will translate the object to x,y,z.

For D3D:
1,0,0,x
0,1,0,y
0,0,1,z
0,0,0,1

Code:
```void CGameObject::TransformObject(D3DXVECTOR3 vecWorldPos,
D3DXVECTOR3 vecScale,
D3DXVECTOR3 vecLocalRot)

{

//Setup matrix variables
D3DXMATRIX matWorld,matTrans,matLocalRot,matScale;

//Setup model space or local rotation matrix
D3DXMatrixRotationYawPitchRoll(&matLocalRot,vecLocalRot.x,vecLocalRot.y,vecLocalRot.z);

//Setup scaling matrix
D3DXMatrixScale(&matScale,vecScale.x,vecScale.y,vecScale.z);

//Setup translation matrix  (moves object to its world position)
D3DXMatrixTranslation(&matTrans,vecWorldPos.x,vecWorldPos.y,vecWorldPos.z);

//Create final world matrix
matWorld=matScale*matLocalRot*matTrans);

//Use shared D3D device pointer to set world transform
m_spDevice->SetTransform(D3DTS_WORLD,&matWorld);
}```
This method is not foolproof as it does not take into account gimbal lock. A more correct approach would either be to use axis-angle rotations or quaternions to avoid the gimbal lock issue. In my system I have a special class called COrient3D which is responsible for all 3D orientations and representations. Every object has it's own COrient3D object which makes handling rotations centralized to one particular class.

3. For D3D:
1,0,0,x
0,1,0,y
0,0,1,z
0,0,0,1
And for GL, remember to transpose that matrix.

4. Yeah um, I know what a translation matrix looks like, but what I want to know is.

How do I find another matrices relative location to a matrix?

Like lets say we have our orc model, he is carrying a battle axe that is relative in translation to the orcs hand. Is this an addition operation? Or a multiplication operation?

5. Like lets say we have our orc model, he is carrying a battle axe that is relative in translation to the orcs hand. Is this an addition operation? Or a multiplication operation?
Multiplication. Not a whole lot can be done by adding matricies.

6. You would find the location of the orcs hand in model space relative to 0,0,0. Translate the axe by that amount in model space, transform anything needed in model space, and then transform to world space. If you translate the axe to the center of the character in world space, or the character's position, the axe will be in the correct position.

How to implement this is up to you. If you can throw the axe or the weapons then doing it this way does not provide a good way to unchain objects from their parents. So I would create a matrix stack. The local translation matrix for the objects would be the location of the orcs hand in model space relative to 0,0,0. Once you transform the character then all you need to do is transform the axe using the model space matrix and concatenate it with the world matrix of the character.