Hello,
I’m working on a project with the applied math department at my school, and we are trying to convert our 3D graphics system over to JOGL. I’ve been trying for the longest time to get the perspectives and stuff set up, but I just can’t figure it out. The effect we’re trying to get is basically the exact same thing we have now (just with opengl for better graphics quality and speed). Our app can be found at:
http://amath.colorado.edu/java
View any of the 3D tools and you’ll find out what it is I’m trying to do. I really have no idea how to go about creating an effect similar to this, but here’s some code i’ve currently got:
// glDraw will be called by display() after setCamera() (below) and it will take care of all the rendering
public void glDraw(GL gl) {
GLU glu = new GLU();
// grab the maxima and minima of the graphics objects to draw in the coordinate sytem
double xmax = getXMax();
double ymax = getYMax();
double zmax = getZMax();
double xmin = getXMin();
double ymin = getYMin();
double zmin = getZMin();
//double center = (maxim+minim);
float xCenter = (float)(xmax+xmin)/2;
float yCenter = (float)(ymax+ymin)/2;
float zCenter = (float)(zmax+zmin)/2;
System.out.println("x:" + xCenter + ",y:" + yCenter + ",z:" +zCenter);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
// initially position the camera looking at the center from the top corner
glu.gluLookAt(xmax,ymax,zmax,0,0,0,0,0,1);
// angleX, angleY, and angleZ are determined from mouse movement in other methods
gl.glRotatef(angleX,1,0,0);
gl.glRotatef(angleY,0,1,0);
gl.glRotatef(angleZ,0,0,1);
gl.glTranslatef(-xCenter,-yCenter,-zCenter);
// this will draw the coordinate axes. they work, when i rotate them around the perspective gets all screwed
if (getAxesVisible())
boundary.glDraw(gl);
super.glDraw(gl);
}
public void setCamera(GL gl) {
System.out.println("Set 3D Camera");
int width = this.getWidth();
int height = this.getHeight();
GLU glu = new GLU();
double xmax = getXMax();
double ymax = getYMax();
double zmax = getZMax();
double xmin = getXMin();
double ymin = getYMin();
double zmin = getZMin();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(2*xmin,2*xmax,2*ymin,2*ymax,2*zmin,2*zmax);
} // setCamera()
I think the problem lies in when I rotate things, the orthographic projection doesn’t rotate too, so when the z axis is rotated so that it’s in the y (default) direction, since y was originally a different size (ie -10 to 10 as opposed to something much larger on the z-axis) the perspective is stretched out. I just don’t really understand how any of the 3D stuff works, and I’ve tried to go through a ton of tutorials, and while I understand the basics I don’t know it well enough to apply it to my specific problem. Please help however you can, and if you have more questions on how something’s supposed to work or what I’m trying to do please ask and I can provide the answer, though hopefully our goals are pretty clear from the product we’ve already got (above link)