Trackball rotation - is it possible in Irrlicht?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Robert Y.
Posts: 212
Joined: Sun Jan 28, 2007 11:23 pm

Trackball rotation - is it possible in Irrlicht?

Post by Robert Y. »

After reading most of the forum and the documentation (both are pretty darn good, btw) I still am stuck with one thing I'm trying to do.
I'm writing my own mesh viewer and try to rotate my model with a mouse. The problem is that the setRotation function is RELATIVE to the MODEL. If I move my mouse up, I want to rotate the model around the WORLD X-axis (so the part of the model that is at the top of the screen will move away from me) and if I move the mouse to the left, the part of the model that is currently left will move away from me, and the part on the right will rotate towards to me (so around the WORLD y-axis.

There is nice code available on the net (trackball.cpp) to do this with quaternions, but in Irrlicht I can't find a function to rotate my model in WORLD space ???? The closest functions I can find is getAbsoluteTransformation and getHorizontalAngle(), but they just get the info and I want to do the opposite: 'setAbsoluteTransformation'.

Most engines I used thus far, have absolute rotation functions (for instance Quest3D and Truevsion3d). Have I finally found something Irrlicht can't do??? I hope not, as this is really of vital importance for my project... Or is there a clever way to use setRotation? Any help greatly appreciated...

To make more clear what I'm trying to do, see this page and run the demo:

Code: Select all

http://www.codeproject.com/opengl/glenabledview.asp
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

What you basically want is camera controls that work in spherical coordinates. I wrote some code here for doing just that. I believe that the original author created his own camera type for doing this, so you should be able to find it by searching.

Travis
Robert Y.
Posts: 212
Joined: Sun Jan 28, 2007 11:23 pm

Post by Robert Y. »

Thanks Vitek! It is almost what I need, using the camera in this way is a very clever solution! Now, why didn't I get that idea :roll: ?

In your code you write about preventing gimbal lock by adjusting the up-vector (?). Which vector do you mean by that?

Anyway, this community rocks!!!
sdi2000
Posts: 129
Joined: Thu Aug 25, 2005 12:19 pm
Location: Berlin, DE
Contact:

Post by sdi2000 »

the upvector declare which side of a cam is up
vector(0,1,0) this is the standard view. Y is up.
with a manipulating the upvector u can easy simulate a roll effect of a flight plane and so on
nice weekend ya :D
Robert Y.
Posts: 212
Joined: Sun Jan 28, 2007 11:23 pm

Post by Robert Y. »

Thanks for the explanation! Will have a look at this...

And a nice weekend to you!
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

I love these "is it possible with irrlicht" threads.

programming and science are hand in hand.

In science nothing is impossible only improbable.

Meaning magic is real we just don't know how to do it and you need tools.

you know how in loony tunes anything is possible?
thats real life believe it or not. the world is round my friends.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Midnight wrote:the world is round my friends.
Lies.
Robert Y.
Posts: 212
Joined: Sun Jan 28, 2007 11:23 pm

Post by Robert Y. »

Should I change the subject to "Trackball rotation - is it probable in Irrlicht?" then? :wink: :lol:
Robert Y.
Posts: 212
Joined: Sun Jan 28, 2007 11:23 pm

Re: Trackball rotation - is it possible in Irrlicht?

Post by Robert Y. »

Hi Guys,
I have been working on a lot of other stuff, while checking this forum once in a while. Finally, I started working on my irrlicht project again. I have checked the forum if someone came up with a method to implement an arcball/trackball in Irrlicht, but it seems it is still not possible / probable ;) ? Now and then it is mentioned on this forum, but it seems everyone who tries gets stuck with it.
The orbit camera is a great solution if you want to rotate a single object, but I want to be able to reposition/manipulate and freely rotate several independent objects in one scene, while the other objects remain unchanged. Changing the camera view, will change the position of all other objects.
I have tried using quaternions, but the final problem is to set the model rotation according to WORLD space using the resulting matrix. Has anybody already come up with a method to implement the arcball / trackball or a getAbsoluteTransformation() function?
Any help greatly appreciated...

Best regards, Robert
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Trackball rotation - is it possible in Irrlicht?

Post by smso »

Parent the model scene node to an empty node (which has no parent) and rotate the empty node.

Code: Select all

scene::ISceneNode* model = ...
scene::ISceneNode* rootEmpty  = smgr->addEmptySceneNode(0);
 
model->setParent(rootEmpty);
model->setPosition(...);
 
rootEmpty->setRotation(...);





Regards
smso
Robert Y.
Posts: 212
Joined: Sun Jan 28, 2007 11:23 pm

Re: Trackball rotation - is it possible in Irrlicht?

Post by Robert Y. »

Hi smso,

Thank you for your reply. Unfortunately that doesn't seem the answer: the problem is that I can do quaternion math to avoid gimbal lock, but it seems impossible to set the model orientation to the according quaternion matrix. The setRotation function uses Euler angles, which will result in gimbal lock.

It is possible to get the orientation of a model with the getAbsoluteTransformation() function. I can then rotate the matrix using quaternion math. But there is (as fas as I know) no way to set the model orientation according to my new matrix (i.e. the setAbsoluteTransformation() function is not available in the Irrlicht SDK). Is there a way around this?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Trackball rotation - is it possible in Irrlicht?

Post by serengeor »

Well you get a reference to the transformation, so you can change it directly. The question is if it will go back to it's original transform after 'OnAnimate' is called.
Working on game: Marrbles (Currently stopped).
Robert Y.
Posts: 212
Joined: Sun Jan 28, 2007 11:23 pm

Re: Trackball rotation - is it possible in Irrlicht?

Post by Robert Y. »

Hi Serengeor,

I highly doubt that this will work. If I remember correctly, I already tried that some years ago. But anyway will look into it, it would indeed be the easiest solution...
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Trackball rotation - is it possible in Irrlicht?

Post by serengeor »

Oh wait, now that I looked again, it returns const reference, so you can't really change it :/

Is it really necessary to set matrix directly to avoid gimbal lock? I remember I used quaternions from bullet physics and irrlichts vectors (wrote function to convert quat angles to irrlicht vector) and it worked well without causing gimbal locks.
Working on game: Marrbles (Currently stopped).
Post Reply