PDA

View Full Version : Load identity write it out does not work properly



lolzoromg
03-15-2012, 11:43 AM
Hi there
I hava a code like this:

@Override
public void init(GLAutoDrawable glad) {
mesh = new Mesh("C:\\Users\\Judit\\Desktop\\Szakdoga_real\\quadCube .obj");
entities = new Entity[9];
for(int i = 0; i < 9; ++i){
//entities[i] = new Entity(mesh, path + 1 + ".jpg");
entities[i] = new Entity(mesh, path + (i+1) + ".jpg");
}

distance = 10;
u = -4.7f;
v = 1f;
eyeX = (float) (distance * Math.cos(u) * Math.sin(v));
eyeY = (float) (distance * Math.cos(v));
eyeZ = (float) (distance * Math.sin(u) * Math.sin(v));


glad.setGL(new DebugGL(glad.getGL()));
final GL gl = glad.getGL();
MOut.outMtx(gl);
...


and a class like this:

public class MOut {

public static void outMtx(GL gl){
double[] pos = new double[16];
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, pos, 15);
for(int i = 0; i < 16; ++i){
System.out.print(pos[i] + ", ");
if((i+1)%4 == 0){
System.out.println();
}
}
System.out.println();
System.out.println();
}
}
I make the GL object in init, than print it's elements out, than i get :
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 1
Intead of a 4x4 ident matrix. How could this be possible?


P.S.: i crossposted it to java gaming forum, but seems like it quite dead. Thanks

carsten neumann
03-15-2012, 12:15 PM
double[] pos = new double[16];
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, pos, 15);


Don't know the java bindings, so: what is the last argument to glGetDoublev (and why is it 15)? Surely the matrix has 16 elements?

lolzoromg
03-15-2012, 12:36 PM
i don't know there is no doc for it, i suppose the indexes of the array, becouse if i write 16 i get an error of out of bound

lolzoromg
03-15-2012, 01:47 PM
anyways, it's supposed to be work rigth? so something goes wrong elsewhere

carsten neumann
03-15-2012, 03:05 PM
Sounds to me like it's the offset into the pos array at which you want the values to be written, so it should be 0 - that is also consistent with the matrix you get when using 15 and the out of bounds error for 16.

lolzoromg
03-15-2012, 04:08 PM
holy [censored], you were right. thank you

V-man
03-15-2012, 04:55 PM
i don't know there is no doc for it, i suppose the indexes of the array, becouse if i write 16 i get an error of out of bound

No doc? That's impossible.

I did a search and the first hit gave me
http://www.java-tips.org/other-api-tips/jogl/how-to-use-gluunproject-in-jogl.html

and they have these lines
gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);