Sign in to follow this  

transform and rotate

This topic is 3296 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hy. I'm still creating a collada importer. My first problem is when i must rotate a collada mesh,i have a collada rotation like this: <rotate>0.57735 0.57735 0.57735 -240</rotate> How i can rotate the mesh? 240 is the degrees ok, but the other components are the axes of the rotation? and how in directx i can rotate around an axes? the secod doubt is this: when i rotate or translate two mesh ,the second mesh inerith a rotation from the first mesh? in this case i have to apply a 0 coordinate matrix? thanks.

Share this post


Link to post
Share on other sites
Hi giugio,

use Quaternion,
with these you can rotate around a single axis and afterwards convert it into a rotation matrix (or euler angles, whatever you prefer), this you then can use for your rotation.
(Also the "games gems (1 or so)" should have a chapter about them)

gamedev ref:
quaternion

greets,
thaligar

Share this post


Link to post
Share on other sites
thanks a lot , and for this doubt?
Quote:
Original post by giugio
the secod doubt is this:
when i rotate or translate two mesh ,the second mesh inerith a rotation from the first mesh?
in this case i have to apply a 0 coordinate matrix?
thanks.


?

Share this post


Link to post
Share on other sites
What do you mean?

Normally each game object has its own World Matrix, so you have to scale-rotate-translate (in this order) everything alone.

Or maybe you're using some kind of engine that uses scene nodes? In this case everything that is applied to a parent node is applied to the child nodes.

Share this post


Link to post
Share on other sites
is a collada importer,and in the scene section there is a node element transformation for mesh.
but I have more than one mesh, i have 200 meshes, and 200 node transformation element.

Share this post


Link to post
Share on other sites
I don't know how those 200 meshes are arranged in your collada scene, but..
Let's say you have two meshes, two cubes.

If the second cube is somehow "linked" to the first, then you should:
Take the first cube matrix.
Apply it to the world matrix.
Render the first cube.
Take the world matrix as it is now.
Multiply it by the SECOND cube matrix.
Render the second cube.

If the two cubes are two independent meshes, then you just:
Take the first cube matrix.
Apply it to the world matrix.
Render the first cube.
Take the second cube matrix.
Apply it to the world matrix.
Render the second cube.

2 cents of advice: probably you should play a bit more with basic stuff like quaternions and matrix multiplication before adventuring into complex things like a collada importer :)

a.

Share this post


Link to post
Share on other sites
AFAIK, in COLLADA a node element may be marked with transform elements (like rotate) to define a co-ordinate frame of the node. The sequence of arcs (that's COLLADA's name of edges between the nodes) gone from the root until reaching the current node may hit as many co-ordinate frames as nodes are visited, since each node can have its own frame. The frame hit last before coming to the current node defines the parental frame.

Hence for each node the current global transform can be determined as usual by multiplying the current local transform (as given by the node's transform elements) with the parental global transform. This is what resle has described above.

However, as can be seen here, computing the current global transformation is done in a mixture of all allowed transform elements, and hence is best done by using matrices. Especially representing the rotation temporarily by a quaternion is a waste, but only a very small one (it requires just 5 more ADDs compared to directly converting axis/angle to matrix, if done right and I've counted the operations correctly).

Share this post


Link to post
Share on other sites
I'm not understand all , then the nodes in collada are linked(in the resle definition)?
And if i would display only 2 meshes i must apply all the transformations from the last to the displayed node?
Thanks.

Share this post


Link to post
Share on other sites
Giugio, since we're both from Italy, contact me over msn. Resle77 chiocciola hotmail punto com. So I can better explain everything to you in our native language.

a.

Share this post


Link to post
Share on other sites
i post the code:
this is the render loop:
I draw only 2 meshes of the 200 meshes vector m_AllMeshes

for(itMesh = m_AllMeshes.begin();itMesh != m_AllMeshes.end();itMesh++)
{
Device->SetMaterial(&mtrl);
CMeshBase* pmesh=((CMeshBase*)*itMesh);
if(pmesh->getName().find("F430-mesh")!=string::npos )
{
vRotationAxis->x = 0.57735f;
vRotationAxis->y = 0.57735f;
vRotationAxis->z = 0.57735f;

matr->LoadIdentity();
matr->RotateAxis(vRotationAxis,-240);
matr->Translate(0.642309f,-0.1489442f,0.442514f);


matr->Push();

Device->SetTransform(D3DTS_WORLDMATRIX(0), matr->GetTop());
pmesh->mesh->DrawSubset(0);
}
if(pmesh->getName().find("B-floor-mesh")!=string::npos)
{


matr->LoadIdentity();
matr->RotateAxis(vRotationAxis,-240);
matr->Translate(0.234062f, -1.04631f,0.148801f);


matr->Push();

Device->SetTransform(D3DTS_WORLDMATRIX(0), matr->GetTop());
pmesh->mesh->DrawSubset(0);

}
}



I call loadidentity before apply the transform and the rotation result is ok ,but there is an error in the location of the 2 meshes
i already test that the values of the translate is correct.
I must use translate or translatelocal?
thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by giugio
I'm read somewere that in collada in directx i must invert the z coordintate of translation, from Lhc to rhc.
is true?
I'm not familiar with COLLADA myself, but if it is OpenGL-oriented then it's quite likely you'll need to swap between LH and RH coordinate frames.

Usually it is fairly obvious when you've got this part right/wrong so give it a go with both and have a look [smile]


hth
Jack

Share this post


Link to post
Share on other sites
yeah.
I swap the y with the z and now y and z are correct.
The code is the same that i have posted , change only the swap of y and z.
The problem now is on the x coordinate is too big in the second mesh.

and ...
There is a measure unit in my collada file i must change anythings?

Share this post


Link to post
Share on other sites

This topic is 3296 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this