LWJGL math classes

Started by K.I.L.E.R, October 01, 2005, 14:05:53

Previous topic - Next topic

K.I.L.E.R

Now that I am FAR more aquinted(Taking the class on OGL, read a lot from the book, etc...) with 3D graphics (specifically OGL).

I need to know that I'm using the quaterion in LWJGL right, I have my own classes on Quats and matrices and stuff but LWJGL has it too.

I'm going to use LWJGL's classes due to them being optimised(I hope) while mine weren't, I was created destination objects left and right(look inside LWJGL quaterion class to get the joke).

If I'm rotating towards an object, is this how you would do it?

public void rotateTowards(float angle, Vector4f direction)
	{
		curObjQuat.set(curSpatial.getX(), curSpatial.getY(), curSpatial.getZ());
		tmpObjQuat.set(direction.x, direction.y, direction.z, angle);
		
		Quaternion.mul(curObjQuat, tmpObjQuat, destQuat);
		
		curSpatial.setCoords(curObjQuat.getX(), curObjQuat.getY(), curObjQuat.getZ());
	}


Also why doesn't LWJGL have a 2 tuple(angleOfRotation, vector) for quats and place w value first?

K.I.L.E.R

I have another suggestion:

buff = (FloatBuffer)BufferUtils.createFloatBuffer(16).put(new float[] {
				 1, 0, 0, 0,
				 0, 1, 0, 0,
				 0, 0, 1, 0,
				 0, 0, 0, 1,
		 }).flip();
		 
		 m.load(buff);
		 
		 m.rotate((float) Math.toRadians(45), new Vector3f(0, 0, 1));
		 buff.clear();
		 m.store(buff);
		 buff.flip();


Would be nicer if I didn't have to clear my buffer and re-insert elements of a matrix back into it.

m.store(buff) should automatically rewind the matrix.

Less of a pain.

Instead of waiting I've just created my own handler class to do what it needs to do.

SimpleMatrixOps.Store(matrix4f, fBuff);
		SimpleMatrixOps.rotate(45, new Vector3f(0, 0, 1));
		SimpleMatrixOps.translate(new Vector3f(0, 0, 1));
		SimpleMatrixOps.clear();