Game Development Community

Chapter 3 questions.

by Alan · in Torque Game Engine · 01/13/2005 (8:58 pm) · 11 replies

Greetings,

I've read some posts on the moveshape and turnshape problems people have been occuring. At first I was expecting smooth transitions but after making a small time adjustment I did see the reality of the matter, I wasn't successful at really modifying the values for other transformations/rotations so I decided to move on to the animation version. Everything to the "T" is as it is printed in the book, yet I get a curious reaction when I activate the "DoAnimTest()" function. The heart drops down as usual, it shrinks in on itself, then seemingly disappears. I free'd the camera up using F8 and went beneath the world, sure enough the heart had shrunk in on itself so much it went beneat the world and was rotating upside down directly underneath the terrain surface.. and it was gigantor size. So I tried it again after slight modifications to what was written and the same result occured. It shrinks to nothingness then grows humongeous below the world as it rotates..

I'm curious to see if anyone else had this problem? If so how did you resolve it, and if you haven't experienced it are their common factors I should be on the look out for?

Thanks in advance for any help,
Alan

About the author


#1
01/14/2005 (2:42 am)
Hi,

Not that much further on in the book than ya, so cant pretend to know a great deal about it, but animshape.cs did exactly what it was supposed to for me when I typed it in. So the stuff from the book should work. Dunno if that helps you at all or just makes things worse??
#2
01/14/2005 (6:25 am)
Hi their Annraoi,

Thanks for your response, not exactly helpful except for I have on realization, perhaps what i THINK it should be doing is different what it really is. My impresion was that the object rotated in place?
I'm assuming now that that is NOT what is supposed to happen :).

Perhaps anyone having gotten farther in the book could mention whether or not with this set of functions it's possible to achieve my desired effect which is the heart staying the same size and just rotating in place?

Thanks in advance,
Alan
#3
01/14/2005 (8:08 pm)
Hi Alan, I am not quite sure if the .cs file you telling stated in the book is the one with missing schedule function. But I did remember that i can't make the animation work in that chapter also and I found that it doesn't iterate, so schedule function solved it.

-roger

PS.
after checking the companion CD, indeed in that chapter, schedule funtion is in the code.
#4
01/18/2005 (9:37 pm)
Greetings fellow Bookies!

Alan here again, and after much (I"m sure ridiculous) thought I came up with this latest design in my never ending quest to make the heart rotate through pure coding!

here's what I have..

//===============================================================
// animshape.cs
//
// defines a heart shaped object. allows insertion capability
// and then animates it.
//===============================================================

datablock ItemData(TestShape) // NO ERRORS TO REPORT
{
// Basic properties definition
shapeFile = "~/data/shapes/items/heart.dts";
mass = 1;
friction = 1;
};

function InsertTestShape()
{
%shape = new Item()
{
datablock = TestShape;
rotation = "0 0 1 0";
};

MissionCleanup.add(%shape);

// placing object and providing output to console

%shape.setTransform("-90 -2 20 0 0 1 0");
echo("ID " @ %shape);
return %shape;
}

function AnimShape(%shape)
{
%xfrm = %shape.getTransform(); // get the current position
%lx = getword(%xfrm,0);
%ly = getword(%xfrm,1);
%lz = getword(%xfrm,2);
%rx = getword(%xfrm,3);
%ry = getword(%xfrm,4);
%ry = getword(%xfrm,5);
while (%rx < 361)
{
if (%rx <= 359)
{
%rx = %rx++;
%shape.setTransform(%lx SPC %ly SPC %lz SPC %rx SPC "0 1 0");
}
else
{
%rx = 0;
%shape.setTransform(%lx SPC %ly SPC %lz SPC %rx SPC "0 1 0");
}
}
}

function DoAnimTest()
{
%as = InsertTestShape();
AnimShape(%as);
}




Now I can successfully load the heart dealy ..
the actual animshape() function is supposed to:
1) get the hearts position
2)check to see if the hearts %rx value (rotation along the
x axis) is below 359, if it is add 1 and insert this new %rx
value into the items position, if it's not below 359
then it is set to 0 and insert it into the %rx value of the items
position
3) as long as %rx is below 361 repeat step 2.

I'm THINKING that this would make the heart rotate, seeing as if gets it's current x value in it's circle of rotation and adds 1 onto it until it reaches 360, upon reaching 360 it resets to 0 making a seemingly liquid rotation by 1 degree at a time!
What am I missing! all that happens is my computer freezes when I run the doanimtest() on the heart I created using inserttestshape()!

I'm sure i'm making this WAAAAAAAAY too hard, but I just
want to make the little heart rotate nice and pretty , like a recovery heart should and I want to do it through the coding!
Thank in advance for any help in my on going quest!

Alan

// -EDIT

hmm it didn't save my code's tabbing and spacing, can I use HTML to preserve it in the future or is there another way to preserve rich text?

//
#5
01/23/2005 (10:24 am)
Hi Allan. Just got into the book myself this last week but will see if I can help anyway.

My take on the following variables:

%rx = getword(%xfrm,3);
%ry = getword(%xfrm,4);
%ry = getword(%xfrm,5);

is that they are actually the components of a vector that describes the rotation axis about which yet another variable (rd, the rotation angle) is applied. I think this for several reasons. The appearance of the rotation components in the transform argument list given as an example in line (apprx) 13 on page 112 as "0 0 1 0". This looks like one of the (many) ways to define a quaternion (i.e., AxisX, AxisY, AxisZ, RotationAngle). As well, the code for the rotate example itself uses a similar form, placing the actual rotation angle last in a quartet of arguments:

%shape.setTransform( %lx SPC %ly SPC %lz SPC %rx SPC %ry SPC %rz SPC %rd ) ;

Finally, I have been able to get the heart to spin about its z axis ( 0 0 1 rd) using this approach. rd I believe is in radians and (unfortunately) is a left-handed rotation about the z axis which is actually part of a right-handed triad. At least this is how it is working for me. My problem is getting the heart to rotate about an axis other than z.

I initially wondered if rx, ry, and rz were sequential axis rotations as well. The earlier chapters did, in fact describe rotations as sequential, body based Euler angle rotations. But my thinking at this point is that the transform in setTransform, actually uses something more like a quaternion (though I haven't been completely successful with this interpretation either).

Some modifications to the script code I have found that help me see what is happening follow:

%xform = %shape.getTransform() ;

echo( "Initial xform: " @ %xform ) ;

//... your transform modifications ...

%xform = %lx SPC %ly SPC %lz SPC %rx SPC %ry SPC %rz SPC %rd ;

echo( " Final xform: " @ %xform ) ;


%shape.setTransform( %xform ) ;

Hope some of this helps (and proves to be correct). I'm interested in any progress you might make.

Kristen.
#6
01/25/2005 (7:03 am)
Greetings,

hey Kristen thanks for your reply! I've been tinkering for a few days on it before I read your post and I'm happy to say I've got the heart on a nice smooth rotation and the code is very compact.
my only problem is this..
I use the schedule command to set up my rotation.
now what's interesting is that using the core outline of the example, you make a separate function for instantiating the heart in the world .. well ... what's odd is that then in the separate function for the animation when schedule updates %shape (and the only way it can get %shape is by running InsertTestShape() function) , it puts the shape in new, and only the rotation values i've put in are in incriment .. the effect is this .
it rotates smoothly about half way around and then wobbles back and forth .. through various console echo's i've determined that's what's happening.. it's not storing the old %shape value and updating it with schedule .. instead it's putting in the shape over and over again ..
I tried making %shape global .. so it could access it whenever and not have to redo the function (i.e. resetting the shape back to start) .. but that didn't work either .. I know it's kind of hard to help without out some code excerpts.. I'm going to get ahold of them and try to give some of my console output! you'll see what i mean ..

hehe, I think i'm learning and getting more familiar with what i've learned prior to this more so than if I were to have skipped it .. so I'm quite glad, and excited now that i'm very close thanks for your continued sympathetic posts :D.

Alan.
#7
01/26/2005 (7:33 am)
Side note, Items will only rotate about their z axes. The Item::setTransform method (inside the engine build) explicitely prevents x and y rotations; so no use in trying even though the text suggest you play with the input arguments. Found this out the hard way.

Quote:(and the only way it can get %shape is by running InsertTestShape() function)

In the book example I have, page 117, the "schedule" method is called with "%shape" which is a passed argument to "AnimShape", not a value returned from "InsertTestShape". I see "InsertTestShape" getting called just once from "DoAnimTest" which then passes the returned handle %as to "AnimShape". Guess I don't see the repeated calls to InsertTestShape. Maybe we are looking at different things. Let me know how you fare.
#8
02/01/2005 (1:47 pm)
I finally get what you were saying in that last comment! hehe I didn't think I could be that thick .. but then again I didn't pay much attention to it either! anyway. I can't get the heart to do exactly what I want right now but I'll put it down on my list of things to conquer as I gain more knowledge! At least I have identified the problem correctly! (which at this point doesn't bear explaining) now onto CH4!! (I just read the 3d audio and found it quite easy after all of my experimentation!).
Is it just me or does this book seem to be pretty thick with errors?

Alan
#9
02/02/2005 (10:52 pm)
Quote:Is it just me or does this book seem to be pretty thick with errors?

It's about normal for a first-edition technical book these days. As a writer myself, I really hate to say that, and it's not really the writer's fault. In the good old days, every book had a seriously anal chief editor, at least one copy editor and a technical review staff employed by the publisher. It's not that way anymore, which is why nearly every tech book published today is riddled with errors. Ken's is actually better than most.

If you want to see some really bad writing, check out PC PhD or other books by Myke Predko. Myke is a true tech wizard, but his writing is horrible and his examples are too error-ridden to use as published. His editorial staff was sound asleep when his manuscripts went through. I own two of Myke's books and I'm sure I will buy more for their content, but sometimes it hurts to try to read them.
#10
09/20/2005 (8:24 pm)
Actually, the settransform method will rotate an object around each and every axis, just not the heart. Try these on the pyramid and you will see it work just fine:

1359.settransform("0 0 0 1 0 0 0.5");
1359.settransform("0 0 0 0 1 0 0.5");
1359.settransform("0 0 0 0 0 1 0.5");

These commands give you rotation around the x, y and z axes respectively. Furthermore, if you change the normals to something besides "1", you discover these are rotation scales. For example:

1359.settransform("0 0 0 0.5 0 0 0.5"); gives you a 0.25 radian rotation about the x axis. And, for those who really want to know, positive z is clockwise, positive x and y are counterclockwise.

But the question remains: Why can we rotate the pyramid any way we want but can only rotate the heart around the z axis?

-MJL
#11
09/20/2005 (8:30 pm)
Here's a thought to follow up my pyramid testing.

The pyramid is a dif file. (A Quark interior)
The heart is not.

Maybe rotation abilities are different for interiors than for dts objects? (Which would really suck. I want my vehicles to flip through the air when they blow up.)