LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: elias4444 on December 17, 2008, 15:53:44

Title: Vector3f rotation methods?
Post by: elias4444 on December 17, 2008, 15:53:44
Ok, I'm tired of looking for help on this in regular openGL forums to only hear someone say, "just use such-and-such C++ math library" that I can't use with LWJGL.  :-\

The problem: I'm setting up different types of bounding volumes. Specifically, let's talk about AABB. When you rotate something via glRotatef, it draws just right, but then you need to recompute the 8-points of the original bounding box and redetermine the max-min X, Y, and Z points. I have a method that works, but uses trig (lot's of Math.cos() calls). I've read that most people recommend using a transformation matrix to determine the new points instead, but I can't figure out how to do that in LWJGL.

I can setup a new matrix (via: new Matrix4f()), and rotate it (via: theMatrix.rotate(Math.toRadians(45), new Vector3f(1,0,0))). But I have no clue how to apply that matrix to my original point (contained as a Vector3f) to get a new, rotated Vector3f.

Could someone please post a code snippet for me?

Any help is appreciated!
Title: Re: Vector3f rotation methods?
Post by: princec on December 17, 2008, 16:00:19
Simply multiply the matrix by the point to get the transformed point.

Cas :)
Title: Re: Vector3f rotation methods?
Post by: elias4444 on December 17, 2008, 17:07:49
Yeah, it's that "simply" part that gets me every time.  :P

So, how do you multiply a matrix4f by a vector3f?  :-\
Title: Re: Vector3f rotation methods?
Post by: elias4444 on December 17, 2008, 17:21:07
Hey I found it!

Here's the answer... you CAN'T multiply a Matrix4f by a Vector3f!!!! BUT, you CAN multiply a Matrix4f by a Vector4f!!

:P

Thanks for the help Cas!
Title: Re: Vector3f rotation methods?
Post by: princec on December 17, 2008, 17:52:49
It's always the details isn't it :)

Cas :)