Page 1 of 1

Space flight rotation - 3d rts view.(SOLVED)

Posted: Fri May 27, 2005 8:47 am
by Rabid Mantis
setRotation works fine if i'm turning the ship left, right, up, or down (rotation.X and .Y), but when I roll the ship (rotation.Z) things get hairy. I'm viewing the ship from the outside and I want the X and Y rotation of the ship to be completely independant of the roll. Apparently when I use setRotation(), it sets the X and Y relative to the Z. That model works fine if you're INSIDE the ship controlling it.. I can't find any threads on how to do this. My goal is, if I use setRotation(rotation) rotation.X and rotation.Y will only affect the vertical and horizontal facing of the ship, and rotation.Z will roll the ship but not affect the facing. I imagine I'll have to perform some kind of transformation on "rotation" before I plug it into setRotation() but I'm not really sure how to do it.

Posted: Fri May 27, 2005 10:03 am
by X_for_Extra
Take a look at the localRotation function:
http://www.irrforge.org/index.php/Custo ... ra_control

Posted: Fri May 27, 2005 5:19 pm
by Rabid Mantis
Nope. I tried both of the rotations on that page, and neither work like I want. :cry:

I need to somehow roll the ship (rotate.Z) and then adjust the X and Y rotation as if Z were still 0.

Posted: Sat May 28, 2005 12:06 pm
by X_for_Extra
Well, then you plain have to do your own matrix rotations.

Take a look here:
http://www.cprogramming.com/tutorial/3d/rotation.html

I think you could solve half the problem by having an empty reference node aligned with the ship and use its translation for reference.

Posted: Mon May 30, 2005 9:39 am
by Rabid Mantis
I'm trying to figure it out but I don't have much experience with matrixes.I feel like I'm trying to re-invent the wheel... does nobody know how to do it? If I could have a second node to store the rotated ship and then adjust X and Y from there I'd know what to do... is there anything similar to node2 = node1->rotate(vect) or something like that?

Posted: Wed Jun 01, 2005 1:00 am
by Shlangton
Exactly no matter what programming language you use, you will encounter this rotation problem. Yes, it is also extremely hard tol solve the problem as well.

Posted: Wed Jun 01, 2005 1:06 am
by Galaxy613
Why must this be really hard? Couldn't you make a pivot and set the ship's model to child of the pivot and turn the pivot's X and Y but only change the ship's Z? :?:

Posted: Wed Jun 01, 2005 6:38 am
by Shlangton
I wish there was a premade function or an addom to irrlicht to have a rotation feature where you are not stuck in a gimple lock instead of trying to reinvent the wheel all over again.

Posted: Wed Jun 01, 2005 1:55 pm
by Galaxy613
Does IRRLicht has pivots? If it does it'll be damn easy.

Take this Blitz3D code for example:

Code: Select all

;Setup the window...
Graphics3D 800,600,0,2
SetBuffer BackBuffer()
;Create the Camera and a dummy light...
Camera = CreateCamera()
PositionEntity Camera,0,5,-10

Light = CreateLight()
;Create a pivot then parent it to a cube
Cube = CreatePivot()
RealCube = CreateCube(Cube)
ScaleEntity RealCube,1,0.5,2.5

While Not KeyHit(1)
	Cls
	;Press 1&2 to change the pitch of 'Cube'
	If KeyDown(2) Then TurnEntity Cube,1.0,0.0,0.0
	If KeyDown(3) Then TurnEntity Cube,-1.0,0.0,0.0
	;Press 3&4 to change the yaw of 'Cube'
	If KeyDown(4) Then TurnEntity Cube,0.0,1.0,0.0
	If KeyDown(5) Then TurnEntity Cube,0.0,-1.0,0.0
	;Press 5&6 to change the roll of 'RealCube'
	If KeyDown(6) Then TurnEntity RealCube,0.0,0.0,1.0
	If KeyDown(7) Then TurnEntity RealCube,0.0,0.0,-1.0
	
	UpdateWorld
	RenderWorld
	
	Flip
Wend
End
But sense for most people here it mean sqat, I compiled that code and uploaded it: http://subsoap.com/ck/IndieRoll.rar

So if there is such thing as a pivot in IRRLicht, then you are set. (For now?) :)

Posted: Wed Jun 01, 2005 9:46 pm
by Rabid Mantis
actually I figured out a real easy way to do it.


vector3df newvect(ships.rotation);
newvect.Z = 0;
ships.shellmodel->setRotation(newvect);



newvect = ships.rotation;
newvect.X = 0;
newvect.Y = 0;

matrix4 m = ships.shellmodel->getRelativeTransformation();
matrix4 n;
n.setRotationDegrees(newvect);
m *= n;
ships.shellmodel->setRotation( m.getRotationDegrees() );




It just took me a while to visualize it since I'm a rookie with matrices.

thanks for the help everyone!

Posted: Thu Jun 02, 2005 1:57 am
by Galaxy613
Neat stuff AND no pivots to mess with! :)

Posted: Tue Jun 14, 2005 9:43 am
by Rabid Mantis
Someone asked me to explain this better.

On the example I gave, it was using an array of struct SHIP as variables, so I'll change those into easy-to-use variables.

The original problem is that when you use setRotation, it can set the X and Y facing of your node fine, but if you roll it with Z, it throws off the facing because all three are applied at the same time.

this will let you use a vector (vector3df rotation) and apply it to your node so that rotation.Z rolls the node in place without altering it's x and y facing.
so first off, I set the facing of the node.

vector3df newvect(rotation);
newvect.Z = 0; //we don't want to roll yet, just set facing
node->setRotation(newvect);


Now we need to roll the node while keeping it's current X and Y rotation.

newvect = rotation;
newvect.X = 0; //facing is already set
newvect.Y = 0; //facing is already set

//we will roll with Z relative to the node's current facing
matrix4 m = node->getRelativeTransformation();

matrix4 n ;
n.setRotationDegrees(newvect); //set the amount of roll you want
m *= n; //matrix math
node->setRotation( m.getRotationDegrees() ); //sets the new rotation


this code will SET the facing and roll disregarding the previous rotation. If you want to rotate a certain amount from it's previous rotation, you'll need to change it up. I wrote this code for rotating models.... havent tried it on anything else, but you should be able to get it to work on other nodes like cameras.

Posted: Wed Jun 15, 2005 12:46 pm
by arras