How to get turn pitch roll with Irrlicht

A forum to store posts deemed exceptionally wise and useful
Post Reply
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

How to get turn pitch roll with Irrlicht

Post by arras »

If you were trying to make flight or car simulator than you probably encoutered problem with setRotation() function. It uses so caled Euler angles. Here is way hove to get rid of it using matrix4 class. When writing this code I was largely inspired by Steve Baker's article at http://sjbaker.org/steve/omniv/eulers_are_evil.html

Code: Select all

vector3df r = node->getRotation(); //get current rotation (euler)
matrix4 m;
m.setRotationDegrees(r); //set firsth matrix to current rotation

//use one you need:
vector3df rp = vector3df(angle,0,0); //pitch
//vector3df rp = vector3df(0,angle,0); //turn
//vector3df rp = vector3df(0,0,angle); //roll

matrix4 mp;
mp.setRotationDegrees(rp); //set second matrix to rotation to add

m *= mp; //multipy them

r = m.getRotationDegrees(); //get rotation vector from matrix (euler)
node->setRotation(r); //rotate node 

There is bug in matrix4::getRotationDegrees() function, you have to apply this fix in order to get it right:
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=2234

Another bug in matrix4 class can be fixed like this:
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=2458
Last edited by arras on Mon Jul 12, 2004 7:22 pm, edited 1 time in total.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Arrr... I just found out that there is something wrong with pitch and roll when Y rotation is 0.0 or 180.0 ...but can't find reason.

EDIT:
It was bug in matrix4 class, above code works fine now...
Last edited by arras on Mon Jul 12, 2004 7:26 pm, edited 1 time in total.
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Why do you call the overloaded operators like this?

Code: Select all

m.operator*=(mp); 
Overloaded operators can be used like an operator on an intrinsic type

Code: Select all

m*=mp;
There's no need to call it like a function, that's the whole point of overloaded operators
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

I notices that two but I didn't want to say anything because I have done stupier things than that :D
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

:? well ..ti wasn't my intention, its just some stupid mistake I overlooked when copy and paste from diferent file and than repeated throught same metod again and again...

I decided to edit firsth post since originaly it was bit confusing...
kamikaze942
Posts: 52
Joined: Wed Mar 03, 2010 7:11 pm

Post by kamikaze942 »

hey, i know i've been bugging you on the forums, but let me ask you question




using your code from this post, my character which i call from animatedmeshscenenode->getmesh(),

he rotates relatively. what i mean by this is, when i look at him he doesn't stay put and rotate, he moves around in a circle. Using the getposition and printing the information out, it stays the same, but its obvious he isn't in the same position. How would i adjust this code to make him turn around himself. I have a camera node as well.
Kamikaze
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Can you set up test case (which shows your problem) and post code here while sending me your model you use for animated node?
kamikaze942
Posts: 52
Joined: Wed Mar 03, 2010 7:11 pm

Post by kamikaze942 »

figured it out. scaling problem
Kamikaze
Post Reply