Ch3 TurnShape Help
by Slacker · in Torque Game Engine · 08/07/2004 (8:06 am) · 3 replies
I'm new at TGE scripting, so if anyone can help me with this problem, I would greatly appreciate it. I typed in the turnshape script just like it said in the book, but everytime I try to rotate, the shape disappears. I played around with it using the echo function, and got this.
My insertshape function:
when I call this function, I get this:
Inserting Shape 1764
-90 -2 20 1 0 0 0 <====Result of %shape.getTransform() line. Note the values do not match the setTransform parameters above
So I modified the TurnShape function to this:
With the hard-coded values, the function works as intended. I also noticed that after the rotation, the 3 number set of rotation values stay at "0 0 1 x.xxxx". Weird.
Another note, when I go to the world editor inspector, the rotation value for the item is 1 0 0 0. When I go to try to change the value (say to 0 0 1 0 like in the book), it always reverts back to 1 0 0 0. I'm thinking somethin in the engine is doing this.
1. Does anyone know why the second set of 3 numbers got changed by itself upon insertion?
2. Is this why the shape disappears when I do a rotation with the original code from the book?
3. Is this an engine bug, or did I do something wrong? Any comments would be appreciated.
Sorry for the long post, I don't mean to be a smart alec, just want to share my experience with this problem and learn from any expert opinions from any veteran scriptors. Thanks
My insertshape function:
function InsertTestShape()
{
// An example function which creates a new TestShape object
%shape = new Item(){
datablock = TestShape;
rotation = "0 0 1 0"; };
MissionCleanup.add(%shape);
//Player setup
%shape.setTransform("-90 -2 20 0 0 1 0");
echo("Inserting Shape " @ %shape);
[b]echo(%shape.getTransform());[/b]
return %shape;
}when I call this function, I get this:
Inserting Shape 1764
-90 -2 20 1 0 0 0 <====Result of %shape.getTransform() line. Note the values do not match the setTransform parameters above
So I modified the TurnShape function to this:
function TurnShape(%shape, %angle)
{
%xfrm = %shape.getTransform();
%lx = getword(%xfrm,0); //first, get the current transform values
%ly = getword(%xfrm,1);
%lz = getword(%xfrm,2);
%rx = getword(%xfrm,3);
%ry = getword(%xfrm,4);
%rz = getword(%xfrm,5);
%angle += 1.0;
%rd = %angle; //set the rotation angle
//%shape.setTransform(%lx SPC %ly SPC %lz SPC %rx SPC %ry SPC %rz SPC %rd); //Original statement in the book
[b] %shape.setTransform(%lx SPC %ly SPC %lz SPC "0 0 1" SPC %rd); //New statement with hard-coded rotation axis[/b]
echo(%shape.getTransform());
}With the hard-coded values, the function works as intended. I also noticed that after the rotation, the 3 number set of rotation values stay at "0 0 1 x.xxxx". Weird.
Another note, when I go to the world editor inspector, the rotation value for the item is 1 0 0 0. When I go to try to change the value (say to 0 0 1 0 like in the book), it always reverts back to 1 0 0 0. I'm thinking somethin in the engine is doing this.
1. Does anyone know why the second set of 3 numbers got changed by itself upon insertion?
2. Is this why the shape disappears when I do a rotation with the original code from the book?
3. Is this an engine bug, or did I do something wrong? Any comments would be appreciated.
Sorry for the long post, I don't mean to be a smart alec, just want to share my experience with this problem and learn from any expert opinions from any veteran scriptors. Thanks
#2
Thanks for the reply. I'll re-read that section, hopefully it would shine some light on the subject. The reason I'm hesitant to proceed from this point is that subsequent chapters may build on this basic rotation concept, and if I don't get this right from the start, it would cause a domino-effect in the later chapters.
08/08/2004 (10:21 pm)
JV,Thanks for the reply. I'll re-read that section, hopefully it would shine some light on the subject. The reason I'm hesitant to proceed from this point is that subsequent chapters may build on this basic rotation concept, and if I don't get this right from the start, it would cause a domino-effect in the later chapters.
#3
Nah, they don't really - well, not at all. The next two chapters are weapons, gameplay, the player ... Chapter 6 is client/server. Chapter 7 is common code (start up guis, connection stuff,...). And after that, there is no more scripting until Ch 21 - where you do all the same scripting stuff again - this time for your game, "koob".
Anyway, if I were you, I would move on. GL. Joe
08/09/2004 (7:38 am)
"subsequent chapters may build on this basic rotation concept"Nah, they don't really - well, not at all. The next two chapters are weapons, gameplay, the player ... Chapter 6 is client/server. Chapter 7 is common code (start up guis, connection stuff,...). And after that, there is no more scripting until Ch 21 - where you do all the same scripting stuff again - this time for your game, "koob".
Anyway, if I were you, I would move on. GL. Joe
Torque Owner Joseph Villard
Default Studio Name
I saw this happen several times and I must admit, I was confused. This is what I decided (I have no idea if it is correct). If you look on pages 90-93 of the book, it discusses coordinate systems - RH, LH, local, world, blah, blah... Ken mentioned that when you go from local to world coords, the X and Z flip in Torque (see figures 3.4 and 3.5 and the discussoin of these). This is exactly what happened to me and it appears to be what is happenning to you, also.
So ... that leads me to conclude there might be a conversion from local to world coords somewhere in this process ... What do you think?
Joe