Game Development Community

Trouble Scaling

by Juan Sanchez · in Torque X 3D · 01/30/2009 (7:19 pm) · 7 replies

I'm having trouble getting a static model to scale properly in Torque X.
I create it, rotate it by 45 degrees on its Y axis then I want to scale it up on its Z axis but I just don't get the results I expect.
Not sure how to explain but it seems scaling is completely ignoring the rotation I just applied.
By the way I'm applying rotation and scale values to the T3DStaticGeometryComponent of the object on creation like so.
// add a static component
T3DStaticGeometryComponent static_Component = new T3DStaticGeometryComponent();
static_Component.Position = new Vector3(0.0f, 0.0f, 0.0f);
static_Component.Rotation = Quaternion.CreateFromYawPitchRoll(MathHelper.ToRadians(45.0f), 0.0f, 0.0f);
static_Component.Scale = new Vector3(1.0f, 1.0f, 3.0f);
static_Component.SceneGroup = "staticObj";
static_Obj.Components.AddComponent(static_Component);

I hope this image can explain better.

img91.imageshack.us/img91/3756/txscaleissuecs2.jpg
What am I doing wrong?
Any help is greatly appreciated.

#1
01/30/2009 (7:23 pm)
Kinda sounds like you've entered the wonderful world of 3D matrix transformations. Sometimes, the order of operations makes a difference. Try mixing up the order, like: scale, then rotate, then position.

John K.
www.envygames.com
#2
01/30/2009 (7:33 pm)
Wow I just posted and already got a reply!
Thanks for the tip John. Unfortunately changing the order did not seem to have any effect.

Has anyone come across this with TorqueX, or am I a rare case here?
#3
01/31/2009 (3:07 pm)
You are gonna have to use Matrices to set this properly. I'll be back online later and can post an example that performs the same transformation using Matrix class static methods, such as Matrix.CreateFromYawPitchRoll().

John K.
www.envggames.com
#4
01/31/2009 (5:56 pm)
Thanks again for your help John.

I'm a bit confused here tho.
Is it a bug in the engine code or am I just doing it wrong?
I mean all I'm doing is creating an object then setting its transformation values. I'm an artist by trade so maybe I'm just used to the way 3d modeling apps behave.

But either way if there is a lesson to be learned here then I'm ready to learn it. Looking forward to your sample.
#5
02/01/2009 (7:55 pm)
I don't think it's a problem with Torque X, it's just a problem with how vertices are transformed and why 3D programming is much morte painful than 2D programming.

John K.
www.envygames.com
#6
02/02/2009 (3:09 am)
The engine code is currently set to rotate/translate, THEN scale a T3DStaticGeometryComponent. Applied to your case, the engine code rotates 45 degrees then scales then model in worldspace z.

I am not sure why anyone would ever want to apply the scales like that. The way to do it like you ask, the way the default probably should be, is already coded in for us.

Open T3DTransform.cs, do a find and replace ONLY in this file.

replace all of the:
ApplyPreScale
with:
ApplyPostScale

then replace all of the:
GetPreScale
with:
GetPostScale

Let me know if that does it for ya.

Cheers,
Jim
#7
02/02/2009 (4:54 pm)
Yes! you are awesome buddy.
Thanks a million.

If I can ever do a favor for you, you just let me know.

-Juan