Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  a renderer problem  (Read 708 times)
0 Members and 1 Guest are viewing this topic.
Offline grego5

JGO n00b
*

Posts: 5


Java games rock!


« on: 2004-07-31 13: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
Offline Chman

Sr. Member
**

Posts: 344


Nothing more that... Java games are cool !


« Reply #1 on: 2004-07-31 16:09:45 »

I haven't ran your code because of my lake of time, but the thing you get is absolutly normal.

You can try to change you gluPerspective method to :

1  
glu.gluPerspective((float)52.0,(float)width/(float)height,(float)0.1,(float)1000.0);

but it's not recommanded if you are using some advanced opengl functions...

Chman
Offline Mithrandir

Sr. Member
**

Posts: 463
Medals: 1


Cut from being on the bleeding edge too long


« Reply #2 on: 2004-08-01 08:39:24 »

All you are doing is hitting the front clipping plane when you get close. That results in some of the object being clipped, resulting in the "black" area. If you'd changed the clear colour, then you'd see whatever colour you'd set.

The site for 3D Graphics information http://www.j3d.org/
Aviatrix3D JOGL Scenegraph http://aviatrix3d.j3d.org/
Programming is essentially a markup language surrounding mathematical formulae and thus, should not be patentable.
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.085 seconds with 21 queries.