00001 package gui.OpenGL;
00002
00003 import java.awt.Dimension;
00004
00005 import javax.media.opengl.GL;
00006 import javax.media.opengl.glu.GLU;
00007
00008 import commandline.ImageStuff.util.Punt_3D;
00009 import commandline.ImageStuff.util.myVector;
00010
00011
00012
00013 public class Camera {
00014 private GL gl;
00015 private GLU glu;
00016 private Punt_3D eye,target;
00017 private myVector upward;
00018 Dimension dimension;
00019 boolean isOrthographic;
00020 public Camera(GL gl,GLU glu,Dimension dimension_of_the_screen) {
00021 this.gl=gl;
00022 this.glu=glu;
00023 this.dimension=dimension_of_the_screen;
00024 eye=new Punt_3D();
00025 target=new Punt_3D();
00026 upward=new myVector();
00027 this.setEye(0,0,-500);
00028 this.setTarget(0,0,0);
00029 this.setUpward(0,-1,0);
00030 isOrthographic=false;
00031 }
00032
00033 public void setEye(float x, float y, float z){
00034 eye.setX(x);
00035 eye.setY(y);
00036 eye.setZ(z);
00037 }
00038
00039 public void setTarget(float x,float y,float z){
00040 target.setX(x);
00041 target.setY(y);
00042 target.setZ(z);
00043 }
00044
00045 public void setUpward(float x, float y, float z){
00046 upward.setX(x);
00047 upward.setY(y);
00048 upward.setZ(z);
00049 upward.normeer();
00050 }
00051
00052 public Punt_3D getEye(){
00053 return this.eye;
00054
00055 }
00056
00057 public void setOrthograpics(boolean isOrthographic){
00058 this.isOrthographic=isOrthographic;
00059 }
00060
00061
00062 public boolean isOrthographic(){
00063 return this.isOrthographic;
00064 }
00065
00066 public void aim(){
00067
00068
00069 gl.glViewport(0, 0,(int) dimension.getWidth(),(int) dimension.getHeight());
00070 gl.glMatrixMode(GL.GL_PROJECTION);
00071 gl.glLoadIdentity();
00072
00073 if(isOrthographic){
00074 gl.glOrtho( -dimension.getWidth() ,
00075 dimension.getWidth() ,
00076 -dimension.getHeight() ,
00077 dimension.getHeight() ,
00078 8,
00079 65536);
00080
00081 }else{
00082 gl.glFrustum(
00083 -dimension.getWidth() / 64.0,
00084 dimension.getWidth() / 64.0,
00085 -dimension.getHeight() / 64.0,
00086 dimension.getHeight() / 64.0,
00087 8,
00088 65536);
00089 }
00090 glu.gluLookAt((double)eye.getX(),(double) eye.getY(),(double) eye.getZ(),
00091 (double) target.getX(), (double) target.getY(), (double)target.getZ(),
00092 (double)upward.getX(),(double) upward.getY(),(double)upward.getZ());
00093
00094
00095 }
00096
00097 }