T3D 1.2 - mObjToWorld doesn't properly store objects rotation
by Lukas Joergensen · in Torque 3D Professional · 07/28/2012 (12:42 pm) · 5 replies
I have brought this up a couple of times, tried to find a logical error or the cause of this.
I have described the problem in these two threads:
http://www.garagegames.com/community/forums/viewthread/130941
http://www.garagegames.com/community/forums/viewthread/131014/1#comment-831344
As you might have seen, when I use my MeshEmitter on skinmeshes, it works fine. But when I use it on static meshes, the rotation is off.

Now I have researched it thoroughly and it seems to be because when I retrieve the mVertexData from the static meshes it returns the objectspace coordinates. And the mObjToWorld transform matrix does not rotate the vertices properly.
Using alternative rotation functions, I were able to get the proper rotation for the static objects.
This is the proper rotate function:
And this is the one for rotating the tower and the one for the plane:
Which seems right based on how the gismo is turned when turning on objectcoordinates.
Now, I thought that when I would rotate the point with the mObjToWorld matrix it would be transformed from object coordinates to world coordinates, this doesn't seem to be the case.
Maybe I am just handling this completely wrong but the threads I have found on transforming objectspace coordinates to world space coordinates says it should just be rotated via a mulP to convert it from objectspace to worldspace.
I have described the problem in these two threads:
http://www.garagegames.com/community/forums/viewthread/130941
http://www.garagegames.com/community/forums/viewthread/131014/1#comment-831344
As you might have seen, when I use my MeshEmitter on skinmeshes, it works fine. But when I use it on static meshes, the rotation is off.

Now I have researched it thoroughly and it seems to be because when I retrieve the mVertexData from the static meshes it returns the objectspace coordinates. And the mObjToWorld transform matrix does not rotate the vertices properly.
Using alternative rotation functions, I were able to get the proper rotation for the static objects.
This is the proper rotate function:
Point3F* MeshEmitter::rotate(MatrixF trans, Point3F p)
{
Point3F* r = new Point3F();
r->x = p.x * trans[0] + p.y * trans[1] + p.z * trans[2];
r->y = p.x * trans[4] + p.y * trans[5] + p.z * trans[6];
r->z = p.x * trans[8] + p.y * trans[9] + p.z * trans[10];
return r;
}And this is the one for rotating the tower and the one for the plane:
Point3F* MeshEmitter::TSrotate(MatrixF trans, Point3F p)
{
Point3F* r = new Point3F();
//Plane
r->x = p.y * trans[0] + p.z * trans[1] + p.x * trans[2];
r->y = p.y * trans[4] + p.z * trans[5] + p.x * trans[6];
r->z = p.y * trans[8] + p.z * trans[9] + p.x * trans[10];
//Tower
r->x = p.x * trans[0] + p.z * trans[1] + p.y * trans[2];
r->y = p.x * trans[4] + p.z * trans[5] + p.y * trans[6];
r->z = p.x * trans[8] + p.z * trans[9] + p.y * trans[10];
return r;
}Which seems right based on how the gismo is turned when turning on objectcoordinates.
Now, I thought that when I would rotate the point with the mObjToWorld matrix it would be transformed from object coordinates to world coordinates, this doesn't seem to be the case.
Maybe I am just handling this completely wrong but the threads I have found on transforming objectspace coordinates to world space coordinates says it should just be rotated via a mulP to convert it from objectspace to worldspace.
About the author
IPS Bundle available at: https://www.winterleafentertainment.com/Products/IPS.aspx
#2
Now that you've found that, can we expect to see particle systems for animated meshes too ? :)
07/30/2012 (10:50 am)
Beat me to it. Every mesh has a root node transform that gets applied to the verts.Now that you've found that, can we expect to see particle systems for animated meshes too ? :)
#3
It has worked with animated meshes all the time! The culprit was the static meshes!
But now that I've fixed it I am working on documentation and code cleaning and the update will soon go live!
After this final IPS Lite update I will work on the IPS Full version, more info on this is coming soon but I ensure you it will be a greater pack than you can imagine ;)
07/30/2012 (10:55 am)
What do you mean with animated meshes?It has worked with animated meshes all the time! The culprit was the static meshes!
But now that I've fixed it I am working on documentation and code cleaning and the update will soon go live!
After this final IPS Lite update I will work on the IPS Full version, more info on this is coming soon but I ensure you it will be a greater pack than you can imagine ;)
#4
07/30/2012 (11:04 am)
Ah, ok I didn't realise that you already had the animated meshes working. I must make time to check this out properly, as you seem to be making some great progress with it.
#5
07/30/2012 (11:29 am)
Since you have same axis aligned ortho transforms, it is not necessarily that mObjToWorld to apply rotation,but only translation.
Torque Owner Lukas Joergensen
WinterLeaf Entertainment
And it is working properly for my models now. Can't tell if it will work for all models but atleast it's some kind of a fix..