PaulR

12-18-2011, 07:46 PM

I've recently started using the OpenGL binding LWJGL for java and I'm having a few problems. I used to use C++ and was working through the OpenGL super bible 4th edition. Today I've been trying to translate the GLFrame.h file from the super bible example source code over to java, but I've realised that the LWJGL matrix functions, such as glMultMatrix and glLoadMatrix accept data types FloatBuffer, but I need them to work with Matrix4f, as that links into the rest of my file. Does anyone know a work around for this?

Thanks,

Paul

w00tguy123

12-19-2011, 02:48 AM

Isn't Matrix4f just a set of 4*4 float values? Why can't you put those values into a FloatBuffer and pass that to glLoadMatrix?

PaulR

12-19-2011, 11:47 AM

public void rotationMatrix(Matrix4f m,float fAngle,float x,float y,float z)

{

float xx,yy,zz,xy,yz,zx,xs,ys,zs,one_c;

float mag = (float) Math.sqrt(x * x + y * y + z * z);

float s = (float) Math.sin(fAngle);

float c = (float) Math.cos(fAngle);

if(mag == 0.0f)

{

m.setIdentity();

}

x /= mag;

y /= mag;

z /= mag;

xx = x * x;

yy = y * y;

zz = z * z;

xy = x * y;

yz = y * z;

zx = z * x;

xs = x * s;

ys = y * z;

zs = z * s;

one_c = 1.0f - c;

m.m00 = (one_c * xx) + c;

m.m01 = (one_c * xy) - zs;

m.m02 = (one_c * zx) + ys;

m.m03 = 0.0f;

m.m10 = (one_c * xy) + zs;

m.m11 = (one_c * yy) + c;

m.m12 = (one_c * yz) - xs;

m.m13 = 0.0f;

m.m20 = (one_c * zx) - ys;

m.m21 = (one_c * yz) + xs;

m.m22 = (one_c * zz) + c;

m.m23 = 0.0f;

m.m30 = 0.0f;

m.m31 = 0.0f;

m.m32 = 0.0f;

m.m33 = 1.0f;

}

public void rotateY(float delta)

{

Matrix4f rotMat = new Matrix4f();

rotationMatrix(rotMat,delta,vUp.getX(),vUp.getY(), vUp.getZ());

Vector3f newVect = new Vector3f();

newVect.setX(rotMat.m00 * vForward.getX() + rotMat.m10 * vForward.getY() + rotMat.m20 * vForward.getZ());

newVect.setY(rotMat.m01 * vForward.getX() + rotMat.m11 * vForward.getY() + rotMat.m21 * vForward.getZ());

newVect.setZ(rotMat.m02 * vForward.getX() + rotMat.m12 * vForward.getY() + rotMat.m22 * vForward.getZ());

vForward.setX(newVect.getX());

vForward.setY(newVect.getY());

vForward.setZ(newVect.getZ());

}

Thanks for your reply. I've been trying work with both really when I can.

The moveForward seems to work now, but I'm having a bit of trouble with the turning left/right character rotation on the Y axis. I've tried to copy them over as accurately as I can, but they seem to make the scene move forwards and down. So it's as if the scene is lowering and going forwards. I'm not very confident with the maths behind this to really know where the problem could be coming from. Can anybody spot any obvious errors I've made?

Thanks,

Paul

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.