D3DXMATRIX inv; D3DXMatrixInverse(&inv, NULL, &m_matWorld); D3DXMATRIX local; local = *m_pCombineFrameMatrix * inv; D3DXVECTOR3 v = m_pOperator->GetRot(); // The trolley facing direction is opposite to the man's walking direction v = -v; D3DXQUATERNION q; D3DXMATRIX m; D3DXMatrixIdentity(&m); D3DXQuaternionRotationYawPitchRoll(&q, v.x, 0 , 0); D3DXMatrixTransformation(&m, NULL, NULL, NULL, NULL , &q, NULL); local *= m; m_matWorld = m_matWorld * local; still not working! please help.. The trolley is just flying around. Why is this happening?
D3DXMATRIX local;
// trolley's combined transformation, child of the hand of the operator
local = *m_pCombineFrameMatrix * inv;
D3DXVECTOR3 v = m_pOperator->GetRot();
// The trolley facing direction is opposite to the man's walking direction
v = -v;
D3DXQUATERNION q;
D3DXMATRIX m;
D3DXMatrixIdentity(&m);
D3DXQuaternionRotationYawPitchRoll(&q, v.x, 0 , 0);
D3DXMatrixTransformation(&m, NULL, NULL, NULL, NULL , &q, NULL);
local *= m;
m_matWorld = m_matWorld * local;
Still not working. Please help.. The trolley is just flying around.
Why is this happening?
Jack
the way that you multiply your transformation matrices matter.
the reason it is rotating about the world origin, is because you are translating it first, then you are rotating, so your code probably looks like this
Tried it. Doesn't work. Do I have to change other parts of my code base?
Also, unlike the sword and other weapon in any combat warrior games, I'd like to have the attached object to stay on the floor.
How can it be made possible?
D3DXMATRIX local;
// trolley's combined transformation, child of the hand of the operator
local = inv * *m_pCombineFrameMatrix;
D3DXVECTOR3 v = m_pOperator->GetRot();
// The trolley facing direction is opposite to the man's walking direction
v = -v;
D3DXQUATERNION q;
D3DXMATRIX m;
D3DXMatrixIdentity(&m);
D3DXQuaternionRotationYawPitchRoll(&q, v.x, 0 , 0);
D3DXMatrixTransformation(&m, NULL, NULL, NULL, NULL , &q, NULL);
local *= m;
// final output matrix
m_matWorld = local * m_matWorld;
Here are some changes using brute force.
The direction seems to be okay (not quite), the position is incorrect
Any further assistance is greatly appreciated
Thanks
I'm not sure what the goal is. However, here are some comments:
1. The shown code snippet let the positional transformation of m_matWorld as well as m_pCombineFrameMatrix undefined, although it is essential to know how translation is incorporated.
2. You should avoid incorporating scaling that way if possible. Scaling makes many things complicated.
3. The world matrix of a child node is computed as the product
world[sub]Child[/sub] := local[sub]Child[/sub] * world[sub]Parent[/sub]
(which may applied recursively if needed, e.g. a parent node may be a child of its own parent node).
4. If you want to use a local origin o for any transformation M, then shift the local origin temporarily to global 0: T(-o) * M * T(o) =: M'
where T denotes a translation matrix from the specified argument.
What I seem to be seeing, is you are still transforming before you rotate. You should set "local" to "m" first, THEN multiply it with "[font="CourierNew, monospace"]inv [/font][color="#666600"][font="CourierNew, monospace"]* [/font][color="#666600"][font="CourierNew, monospace"]*[/font][font="CourierNew, monospace"]m_pCombineFrameMatrix".
[/font]
I'm not sure if this is the problem or not, but you should try it:
updated code
[color="#880000"]// Make sure the trolley is on the floor, also keep it orthographical[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_11 [color="#666600"]=[color="#000000"] m_fSize[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_12 [color="#666600"]= [color="#006666"]0.0f[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_13 [color="#666600"]= [color="#006666"]0.0f[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_14 [color="#666600"]= [color="#006666"]0.0f[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_21 [color="#666600"]= [color="#006666"]0.0f[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_22 [color="#666600"]=[color="#000000"] m_fSize[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_23 [color="#666600"]= [color="#006666"]0.0f[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_24 [color="#666600"]= [color="#006666"]0.0f[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_31 [color="#666600"]= [color="#006666"]0.0f[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_32 [color="#666600"]= [color="#006666"]0.0f[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_33 [color="#666600"]=[color="#000000"] m_fSize[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_34 [color="#666600"]= [color="#006666"]0.0f[color="#666600"];[color="#000000"]
m_matWorld[color="#666600"].[color="#000000"]_44 [color="#666600"]= [color="#006666"]1.0f[color="#666600"];[color="#000000"]