Hey everybody,
thanks in advance to anyone who is willing to help me, I’m really struggling “a bit” with some (I guess) basic stuff….I have a problem concerning the camera placement (aka „scene transformation“) and the transformation of coordinate systems and it seems that I make some wrong transformations or do them in the wrong order… The situation is as follows:
I have modeled a scene in 3DSMax, let’s say this scene contains a teapot at (500 / 200 / 100) (no rotations) and a free camera at (700 / 1800 / 850 ) with the rotations ( 110 / 45 / 0).
Now, I want to recreate the exact same scene with the same camera-view in OpenGL ( via Jogl in java to be precise, but I guess this doesn’t matter here). The input parameters should be the coordinates from 3DSMax, and the render-view should render the same picture (same perspective etc) as the 3DSMax version.
Until now, I have had an implementation via the “glLookAt” – method (with the coordinate origin as target) and a transformation method to change the coordinate system from 3dsmax to opengl:
protected void transformTo3DSMax(GL gl){
double [] transformmatrix = { 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1};
gl.glMultMatrixd(transformmatrix,0);
}
Then I also have separate functions for the individual objects I want to render, in each of those I call the “transformTo3DSMax”, for example
public void drawMarker(GL gl, double x, double y, double z) {
gl.glPushMatrix();
//do translations and rotations here
//paint object with glu.FooBar() here
transformTo3DSMax(gl;
gl.glPopMatrix();
}
Also the method to set the camera perspective usesthe transform method:
protected void setEye(GL gl){
gl.glLoadIdentity();
glu.gluLookAt(cam_pos.getX(), cam_pos.getY(), cam_pos.getZ(), //position eye
LOOKAT.getX(), LOOKAT.getY(), LOOKAT.getZ(), //look at
up_vector.getX(), up_vector.getY(), up_vector.getZ()); //up vector
transformTo3DSMax(gl);
}
Using these methods, the rendering is correct, the coordinates are transformed correctly ( so the transform matrix must be correct) .
The point is, I want to set the camera “freely”, that means I want to be able to enter the transformation but also the single x y and z angles from 3dsmax. Which basically means I have to get rid of the gluLookAt method and replace it by a method in which I rotate and translate the whole scene ( if I got it right).
So my plan was as follows: Replace the the setEye method by:
protected void setEye(GL gl, tx, ty, tz, r_x,r_y,r_z){
gl.glLoadIdentity();
gl.glTranslated(-t_x, -t_y, -t_z);
gl.glRotated(r_x, 1, 0, 0);
gl.glRotated(r_y, 0, 1, 0);
gl.glRotated(r_z, 0, 0, 1);
transformTo3DSMax(gl);
}
This method should have been the very first that is called in the display method from OpenGL, and I thought it would prepare the whole matrix stack in a way, that every matrix operation afterwards ( for example painting markers, circles, teapots) gets the camera perspective I also have in 3dsmax. But for whatever reason, this doesn’t seem to work. I tried many different combinations of rotations and transformations in the setEye method, but every single one of them produced a wrong perspective / render output -_-
If anyone got my problem – can you tell me where my fault is, or is there any good tutorial how I can place a camera freely in combination with a coordinate transformation?
Thanks a lot!
Binom