grego5
Junior Newbie
Java games rock!
|
 |
«
Posted
2004-07-31 19:33:29 » |
|
I am having a problem. I am just starting to play around with jogl. I created a filled polygon which represents a wall and created a camera using the glu.gluLookAt, but when I move my location close to this polygon, I get this huge black area that goes through the polygon. Why do I get that? Can someone run my code and see if they know why I am getting this black area running through the object that I don't think should be there? I don't know if it is my code or jogl. *****************one class******************* import net.java.games.jogl.*; import javax.swing.event.*; import java.awt.*; import javax.swing.*; import javax.swing.border.*; import java.awt.event.*; import javax.swing.JOptionPane; import javax.swing.event.*; import java.util.Random;
public class LabrynthFrame extends JFrame implements GLEventListener,KeyEventDispatcher { private int width=1030; private int height=900; private Labrynth labrynth=null; private GLCanvas canvas=null; private double eyex=0.0; private double eyey=0.0; private double eyez=4.5; private double centerx=0.0; private double centery=0.5; private double centerz=-100; private double upx=0.0; private double upy=1.0; private double upz=0.0; private double heading=270; public LabrynthFrame() { setTitle("The Labrynth"); setSize(width,height);
GLCapabilities capabilities = new GLCapabilities(); canvas=GLDrawableFactory.getFactory().createGLCanvas(capabilities); canvas.addGLEventListener(this);
this.getContentPane().add(canvas);
labrynth=new Labrynth(); setLocation(0,0); //the default location KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this); this.setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); Animator animator=new Animator(canvas); animator.start();
}
public void init (GLDrawable drawable) {
GL gl = drawable.getGL(); GLU glu=drawable.getGLU();
gl.glShadeModel(GL.GL_SMOOTH); gl.glEnable(GL.GL_DEPTH_TEST);
gl.glClearColor((float)0.0,(float)0.0,(float)0.0,(float)0.0);
gl.glViewport(0,0,width,height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective((float)52.0,(float)width/(float)height,(float)1.0,(float)1000.0); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); }
public void display (GLDrawable drawable) { GL gl = drawable.getGL(); GLU glu=drawable.getGLU(); gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix();
gl.glLoadIdentity(); glu.gluLookAt(eyex,eyey,eyez,centerx,centery,centerz,upx,upy,upz); labrynth.draw(drawable); gl.glPopMatrix();
gl.glFlush(); }
public void reshape (GLDrawable drawable, int i, int x, int width, int height) { } public void displayChanged (GLDrawable drawable, boolean modeChanged, boolean deviceChanged) { } public boolean dispatchKeyEvent(KeyEvent event) { double tempx=0.0; double tempy=0.0; double tempz=0.0; if(event.getID()==KeyEvent.KEY_PRESSED) {
switch(event.getKeyCode()) { case KeyEvent.VK_LEFT: heading--; if(heading<0) heading=360; if(heading>360) heading=0;
centerx=((Math.cos(Math.toRadians(heading)))*(100+eyex) ); centerz=( (Math.sin(Math.toRadians(heading)))*(100+eyez) );
break;
case KeyEvent.VK_RIGHT: heading++; if(heading<0) heading=360; if(heading>360) heading=0;
centerx=((Math.cos(Math.toRadians(heading)))*(100+eyex) ); centerz=( (Math.sin(Math.toRadians(heading)))*(100+eyez) );
break;
case KeyEvent.VK_UP: tempx=eyex; tempz=eyez; tempx+=(Math.cos(Math.toRadians(heading))); tempz+=(Math.sin(Math.toRadians(heading)));
eyex=tempx; eyez=tempz; } break;
case KeyEvent.VK_DOWN: tempx=eyex; tempz=eyez;
tempx-=(Math.cos(Math.toRadians(heading))); tempz-=(Math.sin(Math.toRadians(heading)));
if(!labrynth.collision(tempx,tempy,tempz)) { eyex=tempx; eyez=tempz; }
break;
default: break;
}//end switch statement
}//end event.getId
return false; //doesn't pass key pressed on to other listeners if true
}//end dispatch event key
}//end of LabrynthFrame class //***********************2nd class***** //The Labrynth game, this class contains the Dungeon //Created by Greg Dias
import net.java.games.jogl.*;
public class Labrynth { public Labrynth() { }//end Labrynth constructor
public void draw(GLDrawable drawable) {
GL gl = drawable.getGL(); (GL.GL_FRONT_AND_BACK,GL.GL_FILL);
gl.glBegin(gl.GL_POLYGON); gl.glColor3f((float).5,(float)0,(float)0); gl.glVertex3f((float)0,(float).5,(float).5); //top right point gl.glVertex3f((float)-3.5,(float).5,(float).5); //left point gl.glVertex3f((float)-3.5,(float).5,(float)3.5);//top front point gl.glVertex3f((float)-3.5,(float)-.5,(float)3.5);//bottom front point gl.glVertex3f((float)-3.5,(float)-.5,(float).5);//bottom back point gl.glVertex3f((float)0,(float)-.5,(float).5);
gl.glEnd(); }
}//end Labrynth class
|