Author Topic: Rotations, I hate em! Help, please :)  (Read 4207 times)

Offline mbowen89

  • byte
  • *
  • Posts: 20
    • View Profile
Rotations, I hate em! Help, please :)
« on: November 27, 2012, 03:18:57 am »
Ok, I have created my little smoke particle creator code, it's working decent enough... basically while the vehicle is at origin I set the smoke (a texture on x number of planes) to come out of where the exhaust is on top of tractor, works great. I can make it move with the tractor in a straight line easy enough, but getting it to rotate as the tractor rotates is the hard part... To make the tractor drive in the direction of its rotated angle, here is my code:

Code: [Select]
move_vector = vehicle.getXAxis();
move_vector.x = move_vector.x * delta_x;
move_vector.y = 0;
move_vector.z = move_vector.z * delta_x;
vehicle.translate(move_vector);
vehicle_wheels.translate(move_vector);

The wheels and tractor are imported together but are two objects. The tractors pivot point is the wheels original pivot point. (Does this pivot point translate as the wheels move by the way?)
Code: [Select]
for(int ii=1; ii<max_smoke; ii++) {
     smoke[ii].translate(move_vector);
}

That moves the smoke well enough that it's moving down the track with the tractor, however it's not being rotated to stay right over the exhaust pipe of tractor. I simply rotate the tractor with rotateY when I am rotating. With not changing the smokes pivot point, it just rotates around its own center of course, which doesnt help. Setting it's pivot point to the wheels makes it go crazy even when not trying to rotate it... so I am at a lost as to how to keep it right over the exhaust.

I wish there was a way to set something to the relative coordinates of the object, and not global world. There's not an easy way to do something like that is there? To always set it's position to be at a certain position on the tractor?

Thanks for any help! :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotations, I hate em! Help, please :)
« Reply #1 on: November 27, 2012, 07:22:28 am »
You actually don't have to deal with the rotations, at least not directly. You could attach a dummy object at the position of the exhaust in the initial state of the car and make it a child of the car. Then, add new smoke at the transformed center of that dummy. Another approach would be to calculate the exhaus position based on the vector returned by get?Axis() of the car.

Offline mbowen89

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Rotations, I hate em! Help, please :)
« Reply #2 on: November 27, 2012, 07:33:39 pm »
Is there no way to set an object's position? Do I have to use translate?

I was hoping I could do something like: smoke.setPosition(smoke_pipe.getTransformedCenter());

But that doesn't exist. So I will have to do some math to figure out where I need to translate it to?

Code: [Select]
smoke[i].translate(smoke_pipe.getTransformedCenter().x-smoke[i].getTransformedCenter().x, smoke_pipe.getTransformedCenter().y-smoke[i].getTransformedCenter().y, smoke_pipe.getTransformedCenter().z-smoke[i].getTransformedCenter().z);

That seems to have done the trick, sweet! I'll have to use these dummy objects more often... I still wish there was a way to just set the position to a vector, and not have to calculate the translation myself. No big deal if that is what has to be done... but is there a set position command?

Thanks as always!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotations, I hate em! Help, please :)
« Reply #3 on: November 27, 2012, 08:11:20 pm »
translate() IS a set position command, if you clear the translation before, i.e.

Code: [Select]
obj.clearTranslation();
obj.translate(....);

Offline mbowen89

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Rotations, I hate em! Help, please :)
« Reply #4 on: November 27, 2012, 08:40:10 pm »
That's... ingenious!!!  ;)

Thanks  ;D

Offline mbowen89

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Rotations, I hate em! Help, please :)
« Reply #5 on: January 14, 2013, 11:02:40 pm »
I will do my best to try and explain my question:

When rotating an object, you can say rotateX or rotateaxis and give the axis.

Using rotateX rotates the object around the "world" x axis. If the object was originally made in a way that when you rotateX it rotates around the worlds X axis, then that is ok.

But what if that object is somehow randomly rotated in who knows what angle, and you still want to rotate it around the objects "x axis"?

Now I know I can do that by getXaxis. But it get's the original x axis of when it was loaded into jPCT correct?

I attached two pics.

1. So I want to rotate this cylinder around the  worlds x axis because that is how it happens to be aligned when it is loaded in, right? so that is easy. I know the axis rotate around, X!

2. This cylinder has been rotated at some random angle and exported. If I tried to rotate around X axis, it would rotate very funny and not like the other one. So somehow I need to get the angle of its "x axis" although this information does not exist anymore, if I am correct. I would need to know from Blender what this axis is somehow and give that information to jPCT wouldn't I? That means if I have some object in a game, lets say a truck.  I rotate it easily because I know I built it facing into the xaxis. But what if I rotate it around as it's driving etc, and the player saves the game. I guess I need to "set" its axis somehow?

Hopefully that made sense, would really appreciate some help with understanding this.

Thanks



[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotations, I hate em! Help, please :)
« Reply #6 on: January 15, 2013, 08:17:20 am »
Just save and load the rotation matrix. Or maybe i don't understand the problem.... ???

Offline mbowen89

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Rotations, I hate em! Help, please :)
« Reply #7 on: January 15, 2013, 04:26:13 pm »
So you are saying that when I MAKE the model before exporting, I have to align it along whatever axis I want it to rotate around?

If I want to rotate that cylinder like it is in the second picture, and that is how it was exported... I dont have a rotation matrix to save....

Does that make sense?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotations, I hate em! Help, please :)
« Reply #8 on: January 16, 2013, 10:19:01 am »
Does that make sense?
I think so...i was thinking of something completely different first, so please ignore my first comment. I think that the best way to solve this is not to do it, i.e. don't rotate in Blender but in code.
Another idea: You could try to figure out the rotation axis based on loaded model's geometry i think, but you would have to make it rotate with the model yourself.

Offline mbowen89

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Rotations, I hate em! Help, please :)
« Reply #9 on: January 16, 2013, 04:33:24 pm »


Ok so here is a better example, the flaps on a plane.

If I design the plan so it is facing into X axis as shown in Blender.

I want to (in game) rotate the flaps around the red line labeled hinge line. This is not on a direct X, Y or Z axis.

How do I know what axis to rotate the flaps around?

Do I have to figure it out in Blender, and then do math on it when the object is moved around in the game world?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotations, I hate em! Help, please :)
« Reply #10 on: January 17, 2013, 07:42:08 am »
How do I know what axis to rotate the flaps around?

Do I have to figure it out in Blender, and then do math on it when the object is moved around in the game world?
Yes, you have to figure it out somehow. There's no magic method that tells you this. IF you are somehow able to detect two vertices that lie on this axis in your code, you could create the axis based on that, but it might be more trouble then just guessing the axis. Once you have it, you either have to transform it yourself, or you align a dummy object with it and change the objects' relation from

wing->flap to wing->dummy->flap

and then rotate the dummy around its z-axis to move the flap. Should work, i suppose...