How to create a 3D cartesian coordinate system

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)

It seems to me you’re generally on the right track. Judging from your existing applications you probably want to be using an orthographic projection and moving the camera around with the modelview matrix. One thing you may want to keep in mind is that generally you have to rotate and translate the modelview matrix in the opposite direction the camera is facing, since the “camera” doesn’t really move, but instead the universe moves around it. Aside from that it would probably be easiest if you came up with a small Java Web Startable or stand-alone example.

I put up an example of my new version which uses JOGL. Keep in mind this is extremely limited in functionality, and right now only one graphing feature works. If you go to Tools->Graphing Tools->Parametric Plotter->3D Parametric Plotter and then hit “Plot” and start dragging around and trying to rotate it, you’ll see how things stretch out of proportion (ignore the green/red/blue lines, those are just there so I can see which axis is which). The address is

http://amath.colorado.edu/java/jogl_test/index.html

Sorry it took me forever to respond to this again… finals had their say over how much I was able to work…