Hello, Trienco,
To avoid misunderstanding (on my side), I'd like to get confirmed from you with a few things:
1) The Right/Up/Forward/Position correspond to the elements in the matrix:
R_0 R_1 R_2 P_X
U_0 U_1 U_2 P_Y
F_0 F_1 F_2 P_Z
0.0 0.0 0.0 1.0
2) What are the meanings of tx, ty, tz in this matrix operation?
float tx,ty,tz; float d[3]={pos[0]-Position[0], pos[1]-Position[1], pos[2]-Position[2]}; tx=d[0]*Right[0] + d[1]*Right[1] + d[2]*Right[2]; ty=d[0]*Up[0] + d[1]*Up[1] + d[2]*Up[2]; tz=d[0]*Forward[0] + d[1]*Forward[1] + d[2]*Forward[2];
3) For the elements of Right/Up/Forward, they now contain new values, or the same values as the one above? Transform is transform matrix, am I right?
Transform[12]=pos[0] - (tx*Right[0] + ty*Up[0] + tz*Forward[0]); Transform[13]=pos[1] - (tx*Right[1] + ty*Up[1] + tz*Forward[1]); Transform[14]=pos[2] - (tx*Right[2] + ty*Up[2] + tz*Forward[2]);
4) I tried some simpler method, but there's a shortcoming in this method, it now can rotate about the given point, but the location of the object has been lifted up some distance, how do I fix this?
protected void transform(GL gl) { double[] d = {mark.getX() - center_x, mark.getY() - center_y, mark.getZ() - center_z}; gl.glTranslated(0, 0, -distance); gl.glTranslated(d[0], d[1], d[2]); gl.glRotated(angleVer, 1, 0, 0); gl.glRotated(angleHor, 0, 1, 0); gl.glTranslated(-d[0], -d[1], -d[2]); gl.glTranslated(-center_x, -center_y, -center_z);}