Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  a renderer problem  (Read 898 times)
0 Members and 1 Guest are viewing this topic.
Offline 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
Offline Chman

Junior Member




Nothing more that... Java games are cool !


« Reply #1 - Posted 2004-07-31 22: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

Senior Member




Cut from being on the bleeding edge too long


« Reply #2 - Posted 2004-08-01 14: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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (14 views)
2014-08-01 22:53:16

CogWheelz (14 views)
2014-08-01 22:51:43

CopyableCougar4 (15 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

Resources for WIP games
by CogWheelz
2014-08-01 18:19:50

List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!