Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  Help with Surface-Of-Revolution  (Read 583 times)
0 Members and 1 Guest are viewing this topic.
Offline Master34

Junior Newbie




Java games rock!


« Posted 2005-04-02 02:47:10 »

I am trying to do a surface-of-revolution and display the object as a wireframe representation, rotating around and saving the points


It has no compile errors, but it has a runtime error in the black screen saying:

java.lang.NullPointerException
       at Rotation6$Renderer.display(Rotation6.java:205)
       at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.ja
va:74)
       at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:194)
       at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:192)
       at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:182)
       at net.java.games.jogl.GLCanvas.display(GLCanvas.java:82)
       at net.java.games.jogl.Animator$1.run(Animator.java:104)
       at java.lang.Thread.run(Thread.java:536)

how do I fix this problem?

-----------------------------------------------------------------------

here is the code




import java.awt.*;
import java.awt.event.*;
import java.nio.IntBuffer;
import net.java.games.jogl.*;
import net.java.games.jogl.util.*;



public class Rotation6

{


static Animator animator = null;



public static void main(String[] args)

{

Frame frame = new Frame("Rotation ");

GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

canvas.addGLEventListener(new Renderer());

frame.add(canvas);

frame.setSize(500, 500);

animator = new Animator(canvas);

frame.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

animator.stop();

System.exit(0);

}

});

frame.show();

animator.start();

canvas.requestFocus();



} // end main



static class Renderer implements GLEventListener, KeyListener {
 
 private float rtri = 0.0f;
 



public class wcPt3D {

     public float x, y, z;

     

     wcPt3D(float xcoord, float ycoord, float zcoord){

           x= xcoord;

           y= ycoord;
             
           z= zcoord;

    }

   

    wcPt3D( ){

    x = 0.0f;

    y = 0.0f;
   
    z = 0.0f;

     }
     
     

} // end wcpt3d



public void init(GLDrawable gLDrawable)

{

final GL gl = gLDrawable.getGL();

final GLU glu = gLDrawable.getGLU();



gl.glMatrixMode (GL.GL_PROJECTION);

gl.glClearColor (1.0f, 0.0f, 0.0f, 0.0f); //set background to white

gl.glClearDepth(1.0f); // Depth Buffer Setup

gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing

gl.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do

gl.glOrtho (-2.0, 2.0, -2.0, 2.0, -15.0, 15.0); // define drawing area
gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f);

gLDrawable.addKeyListener(this);

}







public void keyReleased(KeyEvent e) {}



public void keyTyped(KeyEvent e) {}




public void display(GLDrawable gLDrawable)

{

final GL gl = gLDrawable.getGL();

final GLU glu = gLDrawable.getGLU();



gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Set display window to color.

gl.glMatrixMode (GL.GL_MODELVIEW);



gl.glLoadIdentity();

gl.glRotatef(rtri, 0.0f, 2.0f, 0.0f);


gl.glBegin(GL.GL_LINES); //drawing using lines

wcPt3D[][] p1 = new wcPt3D[10][36];

float angle=0.0f;

     int i =0;
     

p1[0][0] =new wcPt3D (0.150f, 0.750f, 0.000f);
p1[1][0] =new wcPt3D (0.450f, 0.750f, 0.000f);
p1[2][0] =new wcPt3D (0.450f, 0.750f, 0.000f);
p1[3][0] =new wcPt3D (0.650f, 0.500f, 0.000f);
p1[4][0] =new wcPt3D (0.650f, 0.500f, 0.000f);
p1[5][0] =new wcPt3D (0.350f, 0.350f, 0.000f);
p1[6][0] =new wcPt3D (0.350f, 0.350f, 0.000f);
p1[7][0] =new wcPt3D (0.150f, 0.350f, 0.000f);
p1[8][0] =new wcPt3D (0.150f, 0.350f, 0.000f);
p1[9][0] =new wcPt3D (0.150f, 0.150f, 0.000f);

for (int row = 0; row < 36; row++) {
     gl.glBegin(GL.GL_LINES);
        
        for (int col = 0; col < 10; col++) {
           gl.glVertex3f(p1[row][col].x, p1[row][col].y, p1[row][col].z);



     }
gl.glEnd();
}



/*gl.glVertex3f(0.150f, 0.750f, 0.000f);
gl.glVertex3f(0.450f, 0.750f, 0.000f);
gl.glVertex3f(0.450f, 0.750f, 0.000f);
gl.glVertex3f(0.650f, 0.500f, 0.000f);
gl.glVertex3f(0.650f, 0.500f, 0.000f);
gl.glVertex3f(0.350f, 0.350f, 0.000f);
gl.glVertex3f(0.350f, 0.350f, 0.000f);
gl.glVertex3f(0.150f, 0.350f, 0.000f);
gl.glVertex3f(0.150f, 0.350f, 0.000f);
gl.glVertex3f(0.150f, 0.150f, 0.000f);
*/









gl.glEnd(); // Finished

rtri += 0.2f;

//}
gl.glFlush();
}

public void displayChanged(GLDrawable gLDrawable, boolean modeChanged, boolean deviceChanged)

{

}



public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height)

{



}
public void keyPressed(KeyEvent e)

{

if (e.getKeyCode() == KeyEvent.VK_ESCAPE)

animator.stop();

System.exit(0);

}

   




public void rotate3D (wcPt3D[][] p1)

{



float deg = 0;
float RadianAngle = (float)(180/Math.PI);
 
     for (int row = 0; row < 36; row++) {
     

     for (int col = 0; col < 10; col++) {
     
   float zp = p1[row][col].z * (float)Math.cos(deg * RadianAngle) - p1[row][col].x * (float)Math.sin(deg * RadianAngle);
   float xp = p1[row][col].z * (float)Math.sin(deg * RadianAngle) + p1[row][col].x * (float)Math.cos(deg * RadianAngle);
   float yp = p1[row][col].y;
     
 p1[row][col] = new wcPt3D(xp, yp, zp);

 
  deg += 10.0f;
 
   }
   
     }
          
    }
     
public void draw3D (wcPt3D[][] p1, GL gl)

{


for (int row = 0; row < 36; row++) {
     gl.glBegin(GL.GL_LINES);
        
        for (int col = 0; col < 10; col++) {
           gl.glVertex3f(p1[row][col].x, p1[row][col].y, p1[row][col].z);
   


     }
gl.glEnd();
}


}







}

}
Offline Vorax

Senior Member


Projects: 1


System shutting down in 5..4..3...


« Reply #1 - Posted 2005-04-02 03:18:08 »

In this code:

gl.glBegin(GL.GL_LINES); //drawing using lines

wcPt3D[][] p1 = new wcPt3D[10][36];

float angle=0.0f;

int i =0;


p1[0][0] =new wcPt3D (0.150f, 0.750f, 0.000f);
p1[1][0] =new wcPt3D (0.450f, 0.750f, 0.000f);
p1[2][0] =new wcPt3D (0.450f, 0.750f, 0.000f);
p1[3][0] =new wcPt3D (0.650f, 0.500f, 0.000f);
p1[4][0] =new wcPt3D (0.650f, 0.500f, 0.000f);
p1[5][0] =new wcPt3D (0.350f, 0.350f, 0.000f);
p1[6][0] =new wcPt3D (0.350f, 0.350f, 0.000f);
p1[7][0] =new wcPt3D (0.150f, 0.350f, 0.000f);
p1[8][0] =new wcPt3D (0.150f, 0.350f, 0.000f);
p1[9][0] =new wcPt3D (0.150f, 0.150f, 0.000f);

for (int row = 0; row < 36; row++) {
gl.glBegin(GL.GL_LINES);
   
   for (int col = 0; col < 10; col++) {
 gl.glVertex3f(p1[row][col].x, p1[row][col].y, p1[row][col].z);



}
gl.glEnd();

You have two glBegin calls, that won't work, remove the one inside the loop.


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.

pw (11 views)
2014-07-24 01:59:36

Riven (10 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
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

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24: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!