Node) Render transform
by Daniel Buckmaster · in Torque Game Engine · 02/04/2008 (11:08 am) · 4 replies
I'm trying to write a simple function that returns the vector of a node in the model. In face, the function has mostly been written already - it's ShapeBase::getMountTransform. What I'm trying to do is a getNodeTransform that gives the transform of any node, passed by a string equating to the node's name.
The relative-to-shape node transform works great - all you have to do is read off shape->mNodeTransforms[index]. However, when I try to make the transform relative to the world, it gets messed up. For xsome reason, the z component of the forward vector is always zero - so there's no tilt at all. kind of sucks when I'm trying to use this code to spawn projectiles.
Here's my code:
The relative-to-shape node transform works great - all you have to do is read off shape->mNodeTransforms[index]. However, when I try to make the transform relative to the world, it gets messed up. For xsome reason, the z component of the forward vector is always zero - so there's no tilt at all. kind of sucks when I'm trying to use this code to spawn projectiles.
Here's my code:
void ShapeBase::getNodeTransform(S32 node, MatrixF* mat, bool relative)
{
if (node < 0)
{
*mat = mObjToWorld;
return;
}
MatrixF nodeTransform = mShapeInstance->mNodeTransforms[node];
if(relative)
*mat = nodeTransform;
else
{
Point3F pos = nodeTransform.getPosition();
pos.convolve(getScale());
nodeTransform.setPosition(pos);
mat->mul(mObjToWorld,nodeTransform);
}
}
void ShapeBase::getRenderNodeTransform(S32 node, MatrixF* mat, bool relative)
{
if (node < 0)
{
*mat = mObjToWorld;
return;
}
MatrixF nodeTransform = mShapeInstance->mNodeTransforms[node];
if(relative)
{
*mat = nodeTransform;
}
else
{
Point3F pos = nodeTransform.getPosition();
pos.convolve(getScale());
nodeTransform.setPosition(pos);
mat->mul(getRenderTransform(),nodeTransform);
}
}Note that other functions take strings for arguments - they just convert the node name to an S32 and call thse methods.About the author
Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!
#2
However, in interpolateTick, the matrices seem to be correct. For some reason, when my console function uses getRenderTransform, the messed-up values are used. I assume this is because interpolateTick works on ghosts, whereas processTick works on the server? Or maybe because the console function is resolved before an interpolateTick has happened, so it uses the values just set by processTick.
I tried to prove this by storing my own matrix - if I set this matrix's values only in interpolateTick and then used it to get the muzzle transform for projectiles, then it *should* have the right values.
Unfortunately, something went wrong and my matrix is always identity, despite it being set correctly in interpolateTick. Grr. Now I think about it, I'm gonna go change something...#
EDIT
Had a thought - could it be that getMountTransform doesn't account for animation in the nodes? Upon inspection of the method in a debug, this seems to be the case... How, then, does my weapon look as if it's in the character's hand?
02/06/2008 (6:08 am)
I've discovered the source of the flat transform matrices. Whenever the object's processTick is called, my calculations for setTransform (using the above methods and getMountTransform) are producing a matrix with no tilt.However, in interpolateTick, the matrices seem to be correct. For some reason, when my console function uses getRenderTransform, the messed-up values are used. I assume this is because interpolateTick works on ghosts, whereas processTick works on the server? Or maybe because the console function is resolved before an interpolateTick has happened, so it uses the values just set by processTick.
I tried to prove this by storing my own matrix - if I set this matrix's values only in interpolateTick and then used it to get the muzzle transform for projectiles, then it *should* have the right values.
Unfortunately, something went wrong and my matrix is always identity, despite it being set correctly in interpolateTick. Grr. Now I think about it, I'm gonna go change something...#
EDIT
Had a thought - could it be that getMountTransform doesn't account for animation in the nodes? Upon inspection of the method in a debug, this seems to be the case... How, then, does my weapon look as if it's in the character's hand?
#3
The problem seems to be moving - whatever I look at, it works fine, but something else seems to be playing up. Here are the facts:
-In interpolateTick, setRenderTransform is being passed correct values
-In processTick, setTransform is being passed dodgy values
-These dodgy values come from the same place as the correct values in interpolateTick
-This place is getNodeTransform - it uses the same method as getRenderNodeTransform, but using getRenderTransform instead of getTransform
(from here, it becomes less like facts...)
-It follows that getTransform is somehow getting screwed up. In the editor, the bounding box of the object always lacks tilt... hmm...
-Okay, so where is the object's transform getting screwed up?
02/10/2008 (11:55 am)
Yes, I am working on this problem just so I can bump this thread...The problem seems to be moving - whatever I look at, it works fine, but something else seems to be playing up. Here are the facts:
-In interpolateTick, setRenderTransform is being passed correct values
-In processTick, setTransform is being passed dodgy values
-These dodgy values come from the same place as the correct values in interpolateTick
-This place is getNodeTransform - it uses the same method as getRenderNodeTransform, but using getRenderTransform instead of getTransform
(from here, it becomes less like facts...)
-It follows that getTransform is somehow getting screwed up. In the editor, the bounding box of the object always lacks tilt... hmm...
-Okay, so where is the object's transform getting screwed up?
#4
That seems quite nasty to fix. Ramen-sama seems to suggest a good method, but he mentions it won't work when the object is off-screen. That's not very good when this code will be used by every AI player in the game for their weapons :P.
02/15/2008 (8:23 am)
Okay, this is now sort of starting to overlap with the node transform thread that's just bobbed to the top of the forum. After having a look at that, I've decided that the issue is the model on the server not animating. The client is animating, which is why the weapon renders in the right location - but on the server, where its actual transform is set, there is no animation in the mount node, so the transform lacks tilt.That seems quite nasty to fix. Ramen-sama seems to suggest a good method, but he mentions it won't work when the object is off-screen. That's not very good when this code will be used by every AI player in the game for their weapons :P.
Torque Owner Daniel Buckmaster
T3D Steering Committee
I'm puting breakpoints in the interpolateTick for the object, where I set its render transform. The matrices passed here make sense - they have the correct rotation for the object. However, when getRenderTransform is used in the methods above, it is returning some strange matrix with the correct pan and roll, but no tilt. Is there something that happens to mRenderTransform behind the scenes? It's fine when I put it in, but mangled when I get it out to use it...