Page 2 of 2

Re: Lua integration question

Posted: Tue Feb 24, 2009 5:53 pm
by xavier
scratchyrice wrote: C++ vs Assembly gives REAL benefits. Yes Q's may be faster, But will we notice it in reality?
Sorry, again, this tells me you haven't ever had to do any optimization of your code. You'll notice the difference between 27 FP multiply/adds and 16, when rotation is one of your hotspots. So will your users -- that could be the difference between 30fps and 60.
That being said, I can understand why it is used in engines such as ogre, As small performance impacts like that are very important. But higher up, like when using the ogre engine to make a game, No-one want the hastle of Q's - Or at least i don't. Like, If i wanted to make an object point east, In euler angles, we can instantly say (Using ogre's coord system) that if we rotate the object, about the x axis -90, The object will face east. With Q's where would i start? I would have to learn precisely how it works - spending years of my life - to be able to make that very usefull type of judgement. It's just not worth it in the long run... For most applications.
FWIW, at a high level -- if you are working with Ogre scene nodes or cameras, and rotating them in any way...you are using Quaternions at a high level. Ogre has simply abstracted them for you behind what *look* like Euler angles (yaw, pitch, roll).

You don't have to understand them, as mentioned -- you just use them. Trust me, no one who uses Quaternions in practice does anything other than what Ogre (which took its maths library code mostly from another game engine project) does: abstract the calculations away behind a more intuitive interface.

Re: Lua integration question

Posted: Tue Feb 24, 2009 5:55 pm
by xavier
scratchyrice wrote:
I don't know, I find axis/angle rotation a lot more imaginative/intuitive than Euler angles. And constructing a quaternion from axis/angle is very straight-forward. In fact, you don't even have to know, because any sensible Quaternion class provides the relevant conversion functions for you. Not understanding the maths behind quaternions doesn't mean you can't use them
Indeed, But as i just said, If you're converting from angles anyway, does it not defeat the purpose?
No. Again, the reason you don't get gimbal lock when using Ogre for your editor, is because it uses Quaternions internally.

Re: Lua integration question

Posted: Tue Feb 24, 2009 5:57 pm
by jacmoe
scratchyrice wrote:If you're converting from angles anyway, does it not defeat the purpose?
Why?
Convert between representations as much as you like (within reason, of course).
Matrices, Euler angles and quaternions each have their uses, strengths, weaknesses, advantages.
Noone is telling you to use quaternions exclusively. *That* would be l33tist. :)

Re: Lua integration question

Posted: Tue Feb 24, 2009 6:00 pm
by xavier
Also, I get the feeling that you believe people are working with the w, x, y, and z components directly -- that would be insane, no one is doing that. Everyone in the world has a Quaternion class that looks a lot like Ogre's, and that's what they use.

Re: Lua integration question

Posted: Tue Feb 24, 2009 6:10 pm
by scratchyrice
Also, I get the feeling that you believe people are working with the w, x, y, and z components directly -- that would be insane, no one is doing that. Everyone in the world has a Quaternion class that looks a lot like Ogre's, and that's what they use.
Ah i see, So what im doing is usual?

Code: Select all

		//Set the ogre scene node rotation
		ogreSceneNode->setOrientation(Ogre::Quaternion( Ogre::Degree(angleLocal.y) , Ogre::Vector3::UNIT_Y ) * Ogre::Quaternion( Ogre::Degree(angleLocal.x) , Ogre::Vector3::UNIT_X ) * Ogre::Quaternion( Ogre::Degree(angleLocal.z) , Ogre::Vector3::UNIT_Z ) );		
If so, Then i make peace with the ogre Q system.

Cheers

Scratchy

Re: Lua integration question

Posted: Tue Feb 24, 2009 7:10 pm
by CABAListic
scratchyrice wrote: Indeed, But as i just said, If you're converting from angles anyway, does it not defeat the purpose?
Not angles, axis/angle, i. e. one vector3 for the axis and one angle around that axis. Constructing a Quaternion from that is way simpler than constructing a 3x3 rotation matrix.

Re: Lua integration question

Posted: Tue Feb 24, 2009 7:16 pm
by xavier
scratchyrice wrote:
Also, I get the feeling that you believe people are working with the w, x, y, and z components directly -- that would be insane, no one is doing that. Everyone in the world has a Quaternion class that looks a lot like Ogre's, and that's what they use.
Ah i see, So what im doing is usual?
Yeah. :)

People use the Quaternion representation of a rotation for all of the "pro" reasons that Greg the Ranter gave in that link (his "con" reasons really are not all that compelling).

Not necessarily in order:
- They are lighter (fewer components to store)
- They are faster (fewer multiplications)
- Operations on them have unique and interesting properties that make them useful in computational geometry.

Trust me, you don't have to understand Hamiltonian mathematics to use them. All that you need to know is that
- they represent a rotation around an arbitrary axis in space;
- you can convert between quaternion form, and angle/axis and rotation-matrix form;
- multiplying Qa * Qb adds the rotation of Qb to the rotation of Qa
- multiplying Qa * inv(Qb) subtracts the rotation of Qb from Qa

If you want to know more, I recommend

http://www.j3d.org/matrix_faq/matrfaq_latest.html

Re: Lua integration question

Posted: Tue Feb 24, 2009 7:48 pm
by scratchyrice
Yeah.

People use the Quaternion representation of a rotation for all of the "pro" reasons that Greg the Ranter gave in that link (his "con" reasons really are not all that compelling).

Not necessarily in order:
- They are lighter (fewer components to store)
- They are faster (fewer multiplications)
- Operations on them have unique and interesting properties that make them useful in computational geometry.

Trust me, you don't have to understand Hamiltonian mathematics to use them. All that you need to know is that
- they represent a rotation around an arbitrary axis in space;
- you can convert between quaternion form, and angle/axis and rotation-matrix form;
- multiplying Qa * Qb adds the rotation of Qb to the rotation of Qa
- multiplying Qa * inv(Qb) subtracts the rotation of Qb from Qa

If you want to know more, I recommend
Thanks a lot. This has cleared things up. I was under the impression that you people actually knew how Q's worked, And used them in their raw form (I cant even spell it lol).

Cheers

Scratchy

Re: Lua integration question

Posted: Tue Feb 24, 2009 9:09 pm
by Kojack
Well, I do kind of know how they work, since I teach a 3d mathematics subject which includes quaternions. But I never go into the 4 dimensional complex number crap, there's easier ways to understand them without ever bothering with i j k stuff. :)

An example of euler not being useful:
Put a sphere on the ground plane. Give it a velocity in a random direction along the plane. Now make it roll in the same direction.
With eulers, you can't (unless the velocity is axis aligned so you can just pitch or just roll). With quaternions it's easy:

Code: Select all

Quaternion(Degree(360*deltaTime),Vector3(velocity.z, 0, -velocity.x));    // make a quaternion around the perpendicular vector to the velocity
ball->setOrientation(ball->getorientation() * roll);
You can change direction of movement as often as you want, the ball will keep rolling correctly.

(Note: that's just off the top of my head, it might make them rotate backwards. I'm too tired to actually type it in)

Eulers still have their place, they are pretty handy for things which follow a rigid set of rotations, like cameras (usually you don't want a camera to roll, just pitch and yaw).


Octonions, on the other hand, are just insane. :)
(8 dimensional numbers. Boost supports them)

Re: Lua integration question

Posted: Tue Feb 24, 2009 10:06 pm
by xavier
scratchyrice wrote: Thanks a lot. This has cleared things up. I was under the impression that you people actually knew how Q's worked, And used them in their raw form (I cant even spell it lol).
Well, many people (perhaps most) that use them, know how they work...they just use classes that implement the details. ;)

For example, the w component of a quaternion is just the cosine of 1/2 the angle of rotation. And the x, y, and z components are simply the components of the axis of rotation, each multiplied by the sin of 1/2 the angle of rotation. The rest of it (the multiplying by each other, and against vectors, and to/from other representations) is just formulaic steps that are readily available on the Interwebs.

Re: Lua integration question

Posted: Tue Feb 24, 2009 10:33 pm
by scratchyrice
For example, the w component of a quaternion is just the cosine of 1/2 the angle of rotation. And the x, y, and z components are simply the components of the axis of rotation, each multiplied by the sin of 1/2 the angle of rotation. The rest of it (the multiplying by each other, and against vectors, and to/from other representations) is just formulaic steps that are readily available on the Interwebs.
Now you see thats the problem, Thats all mathematics, It means nothing whatsoever to me.

Im slowly learning this stuff, But i just have a lot lot less motivation to do so, than getting on with coding a game.

Cheers

Scratchy

Re: Lua integration question

Posted: Tue Feb 24, 2009 10:41 pm
by xavier
scratchyrice wrote:
For example, the w component of a quaternion is just the cosine of 1/2 the angle of rotation. And the x, y, and z components are simply the components of the axis of rotation, each multiplied by the sin of 1/2 the angle of rotation. The rest of it (the multiplying by each other, and against vectors, and to/from other representations) is just formulaic steps that are readily available on the Interwebs.
Now you see thats the problem, Thats all mathematics, It means nothing whatsoever to me.

Im slowly learning this stuff, But i just have a lot lot less motivation to do so, than getting on with coding a game.

Cheers

Scratchy
Nah, that's just a quickie introduction to where the component values come from, is all. As you know, you don't *need* to know that information to orient things in the world. ;)

Re: Lua integration question

Posted: Wed Feb 25, 2009 3:34 am
by nullsquared
I completely agree with xavier here.

I don't know jack about how quaternions internally work. Yet I use them all over the place, because they're extremely useful. Interpolation, rotating, rotations, and so much more. I can easily visualize quaternions in 3D space via the right-up-forward axises. When it comes to rotating via quaternions, I can also easily visually see it, rotating something around a given axis. Actually, most of this applies to 3x3 matrices, too - except, I find quaternions just easier to use and more generally understandable (probably because of Ogre::Quaternion). Besides, quaternions need less space than 3x3 matrices, and they need less arithmetic instructions to do the most important actions, such as rotating, etc. I can't even begin to visualize Euler angles, because you don't even know which axis is rotated on first without any explicit notifications.

Re: Lua integration question

Posted: Wed Feb 25, 2009 1:41 pm
by nikki
Complex numbers on the Argand plane for 2D. Quaternions extend that to 3D. Basically, all the funny ijk rules fix the signs, while the sine(theta / 2) * v and cos(theta / 2) give the maginitude.
Thats all mathematics, It means nothing whatsoever to me.
*slap*

;)

Re: Lua integration question

Posted: Wed Feb 25, 2009 5:06 pm
by michaelg1987
Lol, I let this topic be a day after I made it because my questions had been answered, I come back, it's two pages long, it was moved to the off topic forum, and people are fighting about the gaming industry.

Re: Lua integration question

Posted: Wed Feb 25, 2009 5:16 pm
by CABAListic
michaelg1987 wrote:Lol, I let this topic be a day after I made it because my questions had been answered, I come back, it's two pages long, it was moved to the off topic forum, and people are fighting about the gaming industry.
It's called the internet ;)

Re: Lua integration question

Posted: Wed Feb 25, 2009 6:05 pm
by scratchyrice
*slap*
- Lol, No seriously, I take considerably less interest in mathematics, than i do in logic programming. Obviously if I need to learn a certain aspect of mathematics, I will. But Q's are just something i cannot get my head around at the moment. I will probably learn it, When I start on making my own dx/opengl engine, As I understand they use them. But I'm trying to create a full project, In c++, using middle ware as a starter.

Cheers

Scratchy

Re: Lua integration question

Posted: Thu Feb 26, 2009 3:02 pm
by nikki
And speaking of scripting languages, you guys should check out ECL. Been playing with it lately. Very nice. I can now write scripts for individual instances of GameObjects for each event (collision, tick, keypress etc.) right within Blender's text editor (not that this is ECL-exclusive, just saying), while editing my level. Scripting is fun! :)

Re: Lua integration question

Posted: Sat Feb 28, 2009 6:48 pm
by nikki
Speaking of scripting languages (again), have any of you tried CINT? It's a C++ interpretter, and the binding part is automated through tools 'makecint' or 'rootcint'. I tried a little demo emedding app they have, it works, I added some of my own classes too. Haven't tried with anything complex yet though.