I have a feeling that my favorite feature of Papervision3D is actually the most overlooked feature of Papervision3D. Not because it is insignificant or slow - but mostly because it can be a difficult concept to understand, and most Flash programmers don't come from heavy mathematical backgrounds.
If you failed to read the title and still aren't sure what I'm talking about, I'm talking about Quaternions. If you have never heard of them - do a quick google search. I won't bother going over the bare basics of them here - it is a heavily covered topic and I doubt I could do a better job in this post than what you will find on the web. I have put together a quick video, however, in which i explain just the very basics of how I went about getting the motion you see in the demo, and how you can use Quaternions in Papervision.
I tried to keep it short - but hopefully it will be helpful. Really the most important thing to know about using quaternions in Papervision is you simply need to multiply their matrix back into your transform matrix.
-
object.transform.calculateMultiply3x3(object.transform, quaternion.matrix);
As with all matrix math - order of operation is important - make sure you do transform * quaternion, not quaternion * transform. If you do it the second way, it won't be local to the object (but can still be very useful for some other things). Also make sure you do a 3x3 multiplication - as rotation only deals with 3x3 matrices.
and
Go get the source (I've included my model for you - yes, I made it myself, and no, I'm not a professional modeler).


15 Comments, Comment or Ping
Nice solid walk through that will really help a lot of us out.
August 2nd, 2008
Awesome Andy, just when i was playing with it, can’t be a better timing
August 2nd, 2008
this is very very usefull!!!
I just posted an item on http://www.nabble.com/camera%3A-hover-to-orbit-struggle-td18778894.html
and this…seems to be an answer to my problem…
Thx andy!
August 2nd, 2008
Great post. I’ve just found your site and found my self read every post. Thanks for sharing your PV3D knowledge.
August 4th, 2008
may you give us the editor name you used?
August 5th, 2008
@azad – I do all my work as pure AS3 in FlexBuilder (eclipse). You can also use FlashDevelop for Windows. If you want to use the projects in regular Flash, you will need to change asset types so that they are embedded in the flash file, or use the built in loaders in Pv3D.
August 9th, 2008
Thanks for this tutorial.
Can you tell me if quat are usefull to develop Rubik’sCube ??
August 24th, 2008
very cool! thanx andy!
October 3rd, 2008
Hi!
Could Quaternion class be used for solving two axes rotation problem you’ve describe in the article about wheel steering?
March 22nd, 2009
Thanks for this article, its helped me a lot however I have had one problem, I’m getting one object to look towards and follow another around in 3d using your method and it generally works but occasionally when the object gets too close the direction the following object goes kinda “flips” and starts trying to face away from the target object.
I traced out the angle and found that as the following object is facing away, it knows that it should turn around 180 degrees, so I assumed it was just a bug from trying to ease something bigger than a right angle or something, but when I set easing to 1 the method normally works, but occasionally the following object starts violently flipping around in all directions.
Would you be able to give me any ideas how to fix this? I’m basically using your lookAt function and moving the object with moveForward() and just getting the ray from the position of an object the player controls.
thanks
December 19th, 2009
Reply to “Quaternions in Papervision3D”