tags:

views:

65

answers:

2

At the moment am using JOGL for a ball detection program I have been told to make the balls disappear once they get to close to one another.

    //this is the method from the main class
    public void display(GLAutoDrawable drawable) {
    GL gl = drawable.getGL();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glColor3f(1.0f, 1.0f, 1.0f);
    glut.glutWireCube(2.0f * limit);
    for (int i = 0; i < ball.length; ++i)
    {
    ball[i].display(gl);        
    }
    for (int i = 0; i < ball.length; ++i)
    {
    ball[i].moveRandomly();
    }
    //this is the method from the auxiliary class 
    for (int i = 0; i < ball.length; ++i)
    {
      for (int j = 0; j < ball.length; ++j)
      {
        if (ball[i].distanceFrom(ball[j]) <= 10)
        {

        }
      }
    }
}

  void display(GL gl) {

    gl.glLoadIdentity();
    gl.glTranslatef(position[0], position[1], position[2]);
    gl.glColor3fv(colour, 0);
    glut.glutSolidSphere(radius, 10, 10);
    //glut.glutSolidTeapot(radius);
}

I tried doing this to no avail the balls disappear all at once, I also tried decreasing the radius with the same results, any sort of point in the right direction would be much appreciated.

A: 

I have more questions than help at the moment.

First, how many balls do you have?

This line bothers me:

if(ballGone == false)
{
    glut.glutSolidSphere(radius, 10, 10);
}

If ballGone is false then the ball isn't displayed, but that would imply there is only one ball, so when it is set to false no balls will be displayed.

According to here: http://www.cs.umd.edu/~meesh/kmconroy/JOGLTutorial/ my concern should be justified:

Display is very similar to java.awt.Component.paint() in that it is called each time the canvas needs to be redraw/repainted/redisplayed

So, you may want to look at how you will redraw and make certain that each object that doesn't have a state set to false will be drawn.

James Black
There are a total of ten balls in the program and these balls are being drawn by the display method which has been placed in a auxiliary method and then called in another also called display, I will add both methods to the question
death the kid
I wish I felt like upvotes for comedy were OK cause if so, you would get one for "First, how many balls do you have?".
Jeremy Roberts
+2  A: 

The reason they're all disappearing is that each ball is being compared to itself.

Add this in the inner loop before the if statement (this is a quick fix):

if (i == j) continue;
Jon Seigel
+1 - I skipped over the fact that he was comparing balls to each other.
James Black
Thanks for the help man much appreciated >_<
death the kid