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

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

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

Post 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.
Last edited by Rabid Mantis on Thu Jun 02, 2005 11:22 am, edited 3 times in total.
X_for_Extra
Posts: 69
Joined: Mon May 23, 2005 4:42 pm

Post by X_for_Extra »

Take a look at the localRotation function:
http://www.irrforge.org/index.php/Custo ... ra_control
Should put something witty here I suppose.
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

Post 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.
Last edited by Rabid Mantis on Mon May 30, 2005 9:33 am, edited 1 time in total.
X_for_Extra
Posts: 69
Joined: Mon May 23, 2005 4:42 pm

Post 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.
Should put something witty here I suppose.
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

Post 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?
Shlangton

Post 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.
Galaxy613
Posts: 20
Joined: Wed Jun 01, 2005 12:46 am
Location: USA, VA
Contact:

Post 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? :?:
Shlangton

Post 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.
Galaxy613
Posts: 20
Joined: Wed Jun 01, 2005 12:46 am
Location: USA, VA
Contact:

Post 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?) :)
Image
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

Post 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!
Galaxy613
Posts: 20
Joined: Wed Jun 01, 2005 12:46 am
Location: USA, VA
Contact:

Post by Galaxy613 »

Neat stuff AND no pivots to mess with! :)
Image
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

Post 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.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Post Reply