LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: fbi on June 16, 2004, 15:54:41

Title: Quaternions?
Post by: fbi on June 16, 2004, 15:54:41
Hello everybody,
since I'm currently in the process of dealing with some quaternion stuff for my engine, I was wondering if anybody out there is interested into the same stuff.
If this is case, do you think would it be the case to include that into the next LWJGL release?  :)
Title: hmmmmmm
Post by: Fool Running on June 16, 2004, 19:47:40
Call me stupid :roll: , but what are quaternions? :)
Title: Quaternions?
Post by: anarchotron on June 16, 2004, 21:14:37
Quaternions are a way to represent a rotational transform without using a matrix.  I for one would like to have a nice Quaternion implementation to use in lwjgl.
Title: Pre-release
Post by: fbi on June 17, 2004, 10:17:52
Hi people,
you can take a look at the current version of the code at
Some notes:

1) I used the method negate to implement the conjugate operator, in order to be LWJGL-compliant  :D
2) I didn't implement a straight Euler-to-Quaternion conversion as it can be done via the axis-angle
3) I tried to be as tight as possible to the existent LWJGL API, keeping an eye to the javax.vecmath Quaternion implementation shipped with Java3D

Any comment is absolutely welcome  :wink:
Title: Quaternions?
Post by: fbi on June 17, 2004, 10:22:43
Oh sorry...damn hard programming...I forgot the URL!  :lol:
Here it is:  http://ant1.di.uniba.it/lwjgl/Quaternion.java
Title: SLERP
Post by: fbi on June 17, 2004, 10:24:36
Ok...I forgot to say that I'm going to implement SLERP, too  :)
Title: Quaternions?
Post by: aldacron on June 17, 2004, 12:53:50
Quaternions should not be in core LWJGL, IMO. That's the sort of thing that should be packaged up in a separate jar. IIRC Cas was talking about doing that with the Vector stuff some time ago.
Title: Quaternions?
Post by: indiana on June 17, 2004, 13:01:57
I'm using the seperate vecmath.jar from Java3D (it has nothing to do with Java3D though), which contains the javax.vecmath package, for all vector math. It also contains quaternion classes, you might want to take a look!

You can get vecmath-1.3.1.jar here:
http://www.twinklestone.de/stuff/vecmath-1.3.1.jar
Title: 2 answers in one
Post by: fbi on June 17, 2004, 13:15:40
Yeah...I took a look at it and some functions are adapted from that code even if they use a lot of redundant types (in my opinion, of course)  :)
Anyway I didn't think to include this as a part of the core...all in all a utils.jar seems to be a viable option.
Title: Quaternions?
Post by: princec on June 17, 2004, 13:31:24
All the vector stuff has now been moved to org.lwjgl.util.vector, which will be available as a separate jar of odds and sods.

Cas :)
Title: Quaternions?
Post by: fbi on June 17, 2004, 13:48:28
I know it very well...I'm using such a version indeed  :wink:
I was thinking that if quaternions stuff could be of any use, should be packed there  :)
Title: Quaternions?
Post by: spasi on June 17, 2004, 14:26:23
Sorry for the late reply (inet connection problems).

I'm more than interested in quats and I have an implementation in our project (heavily used in skeletal animation). A complete implementation would be great in the LWJGL vector package. Although I'm not using it (I had most of it implemented before it showed up), I might do sometime.

One note about all math packages: If you create an object behind my back I'm not going to use you! I'm not really familiar with the lwjgl vector package, but that is the main reason I don't use Java3D's (and preferred to do it myself). So the request I have is (for you and anyone responsible for the math package) to provide as many methods necessary to avoid having to create loads of new objects.

By the way, I can't download your code.
Title: Quaternions?
Post by: fbi on June 17, 2004, 14:44:39
Ok...Spasi...try to take a look at the actual code now (we experimented some connection problems in our department today)  :x
Tell me if the methods I created are enough for your format needs  :wink:
Title: Quaternions?
Post by: princec on June 17, 2004, 16:21:03
All the LWJGL vecmath code is designed so no objects are created. We'd like a compatible quaternion class.

Cas :)
Title: Quaternions?
Post by: fbi on June 17, 2004, 18:26:36
As you might notice this is guaranteed by the fact that Quaternion inherits from Vector4f and the fact that I took a look in depth at your code  :wink:
Title: Quaternions?
Post by: spasi on June 17, 2004, 19:35:07
Everything's nice, only a few functionality requests :roll: :

1) The SLERP you mentioned you'll implement.
2) Euler-to-Quaternion conversion would be welcome.
3) Methods to immediately transform (rotate) a vector by the quat and its inverse.
4) Quat inverse.
5) Matrix creation based on the quat rotations.
6) Matrix creation based on the quat rotations and a position vector.
Title: Quaternions?
Post by: princec on June 17, 2004, 21:30:00
I've committed it into CVS now.

Cas :)
Title: Quaternions?
Post by: fbi on June 18, 2004, 08:08:43
Ok guys...hopefully I will end up the task for today (SLERP was implemented yesterday night...so point 1) is always done Spasi)  :)
I will go on till this afternoon because today in my department there's absolutely nobody (possibly they are meditating for this evening Italian  footbal team match)  :wink:
Anyway some notes about your requests:

a) For the Point  3) I guess you mean the well known q*v*q^(-1) which transforms the vector v by means of q. Ain't it?!?
b) Point 5) is just quaternion-to-matrix conversion in my mind. Am I correct or do you mean something else?
c) If I was right for Point 5), Point 6) is just obtained by affecting the last column of the transformation matrix (the translation part of the 4x4 homogeneous matrix).

Can you give me some feedback on these?
Title: Quaternions?
Post by: fbi on June 18, 2004, 10:05:56
Ok people,
I added all the stuff mentioned by Spasi and I went a bit further, because I implemented conversion methods to and from euler angles, matrix (4f and 3f) and axis/angle (represented as a Vector4f).
I guess we should do a bit of test....but the stuff is quite complete right now  :wink:
Take a look at it at http://ant1.di.uniba.it/lwjgl/Quaternion.java (I renamed of course the old version).[/url][/b]
Title: Quaternions?
Post by: spasi on June 18, 2004, 14:46:07
You got everything right, great job!

OT: As for Euro 2K+4, everyone's ecstatic here in Greece too. We still can't believe we're so close to the next round! :shock:
Title: Quaternions?
Post by: fbi on June 18, 2004, 15:17:52
Thank you...quaternions were the first subject I covered in a computer graphics article ever  (I was 20 and I was a C++_only coder at that time) :D

P.S.= For Euro2K+4 we're still waiting...tonight is the night (at least for us...don't know if some people from Sweden think so)  :wink: