Game Development Community

Rotation Problems?

by FruitBatInShades · in Torque Game Engine · 01/31/2005 (5:39 pm) · 18 replies

I have searched the forums and cannot find a conclusion :( I need to be able to rotate an object in X,Y and Z via code. The Item class only supports Z rotation. Does anyone have a class that supports rotation around all 3 axes or a way of implementing this behavior?

#1
01/31/2005 (5:54 pm)
Don't know whether this helps but I'm trying to rotate AI characters in Y. Unfortunately I don't think this will be possible without modifying native code as the rendering code for the player forces rotation in any axis other than Z to 0. The renderer method for the player is quite happy to rotate the player in any axis though so it's just a matter of rewriting the native code so rotations can be passed into it. All the changes look like they are going to end up being in player.cc.

My first attempt at this, last night, was to create a new variable in the player class called mPitch, set that when I detect the pitch needed to change and then use it in the render method when the transform matrix is created. This didn't work and at first I couldn't work out why. Eventually I realised it was becuase I was setting mPitch on the server instantiation of the object but reading it from the client instantiation. I'm going to look into this in a bit more depth tonight by studying the yaw implementation as a guide. Should be reasonably simple now that I've had a bit of sleep.
#2
02/03/2005 (7:52 am)
I'm not sure how much help this will be....Flying players and bots seem to have full range of motion (roll, pitch, yaw) I would start looking there.
#3
02/03/2005 (2:48 pm)
@FruitBat -

You're correct. The item class does not allow rotation in the X or Y axis. If you don't want to change the code, you could rotate the model itself, prior to exporting, or you could animate the model to rotate about the axis of interest. I know neither of these may be palatable. I'll put this on my list of 'look into' items and update this thread when I have an answer.


[HOW]EdM|EGTGE
#4
02/03/2005 (3:15 pm)
@Edward:
I need to be able to control it through script. I am throwing a grenade and I want to be able to control its behaviour during flight and when it hits the ground. All i need to do is have an item that allows rotation through the other axis. I have changed the code but it seems that Item::setTransform is never called as changes in that function never appear in game.
I'm assuming its passed up the hierarchy somewhere but I'm a newb and am a bit lost!
#5
02/03/2005 (5:14 pm)
@FruitBat

OK. I've looked into this and to make this work the way you want will require some engine coding. The item class is purposely designed to disallow rotation transforms via script. Even if you override all the code in:

void Item::setTransform(const MatrixF& mat)
{
   Point3F pos;
   mat.getColumn(3,&pos);
   MatrixF tmat;
   if (!mRotate) {
      // Forces all rotation to be around the z axis
      VectorF vec;
      mat.getColumn(1,&vec);
      tmat.set(EulerF(0,0,-mAtan(-vec.x,vec.y)));
   }
   else
      tmat.identity();
   tmat.setColumn(3,pos);	
   Parent::setTransform(tmat);
   if (!mStatic)
   {
      mAtRest = false;
      mAtRestCounter = 0;
   }
   setMaskBits(RotationMask | PositionMask | NoWarpMask);
}

, the mesh itself will still be rendered in a world aligned fashion. i.e. the mesh will try to align itself to the terrain/object below it (if the item is not static), and its rotation about all axis will not be transformed. However, the bounding box will be. i.e. The visible mesh doesn't transform, but the bounding box does. Not good.

In order to overcome this you'd have to modify the item rendering code too.

So, instead of going on and on, I suggest that you give the grenade a set of animations and play those animations while the items is in flight.

I've tried experiements on modifying item and I've played with projectiles, but projectiles too cannot be transformed.

Sorry!

[HOW]EdM|EGTGE

PS - To override the above function, do this:


void Item::setTransform(const MatrixF& mat)
{
   Parent::setTransform(mat);
   if (!mStatic)
   {
      mAtRest = false;
      mAtRestCounter = 0;
   }
   setMaskBits(RotationMask | PositionMask | NoWarpMask);
}

This is not generally a good idea and only gets you part way.
#6
02/03/2005 (5:17 pm)
One more thought. You might consider using the Rigid Shape resource as your grenades. It will support the bouncing etc and you can just rig the onCollision() the same as your grenade. If I get to it first, I'll let you know if this is a workable solution.

[HOW]EdM|EGTGE
#7
02/03/2005 (5:28 pm)
@Ed. can the transform be applied to projectiles?
#8
02/04/2005 (2:12 am)
@Edward: Thanks for looking into this, it seems a strange thing to be blocked, I know its heavy rendering but strange! I see if I can find out how to implement a rigid shape (newb remember :o)
#9
02/04/2005 (9:19 am)
Edit: removed double post.
#10
02/04/2005 (2:07 pm)
@Jerry

No/Yes.

No. Out of the box, from my own experiments, it seems that projectiles cannot be 'transformed' from script, other than at creation.

Yes. Anyone who is willing to recode the class could do so. :) (I think that is one of the most common thread responses out there.)

Fortunately, as I was investigating this, I was able to confirm a psuedo-bug that I'd once noticed before. For anyone who want's to see something odd, make a long projectile (mehs), then fire it at 0.01 meters per sec. make it live for about 80 seconds, and not fade. Open the inspector and you'll see that the bounding box does not match the mesh orientation.

@FruitBat

Well, the item class is special in that it serves a specific function, that of the pickup/powerup. Given that it needs to do certain things, like re-orient to the object below it. Having said that, it would be nice to extend the rotation ability of the item class so that the rotation can be programmed around more than one axis.

If you'll look at the code above you'll see where the rotation is forced to occur about Z. Very little coding would be required to make this true of all three axes. My suggestion, if you're up to it is to add additional datablock fields to control 'choice of axis' and 'angle of rotation'. If this is all beyond you for now, don't worry too much. I'm quite intrigued now and might write a small resource to do this. I do like the idea of allowing a wobbly rotation vs the current straight-up and down rotation.


[HOW]EdM|EGTGE
#11
02/05/2005 (5:23 am)
It is a common issue, if you could create a resource, maybe even a new class a lot of people would be happy :) By the way Edward, when is the ne EGTGE coming out :o)
#12
02/05/2005 (5:57 am)
Thanks Ed. Looks like I have some coding to do for my next game ;)
#13
02/05/2005 (6:22 am)
Edit: removed double post (WTF??)
#14
02/05/2005 (1:07 pm)
Jerry,

If you're looking to steer a projectile, there is a resource for that already:

Guided or Seeker Projectiles

Also, here are some other projectile behaviors you might be interested in:

Bullet Tracers
Configurable bounce object types for projectiles
Projectile ballistic coefficients (drag factors)
Projectiles affected by wind

I haven't gotten around to checking if any of the above (in part or in whole has made it into head already, so you should check before adding).

[HOW]EdM|EGTGE


PS - On double posts. That often happens if you submit a post, then do a refresh (F5) to check for a reply.
#15
02/05/2005 (1:13 pm)
Thanks Ed, I owe you a beer. I'll check those links out.
#17
03/11/2005 (5:13 pm)
Any progress on the creating of a new class of item that can be rotated on all three axes? I also would find this useful. Specifically something where there were functions to set pitch, yaw, and roll, as well as just being able to rotate them at all.
#18
03/12/2005 (11:04 pm)
@All and Any Who have been following this or waiting...

I'm sorry I was on Vacation and am only now getting back into Torqueing. I'll get something out soon and if I cannot I'll update this thread with the reason.

www.hallofworlds.com/how.ico Hall Of Worlds, LLC
EdM|EGTGE