OpenGL Some question: moving object, draw a ball, bouncing ball

This topic is 3554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi all. i've some trouble in opengl. 1) how i can automaticaly move a object? i.e. i would that my ball is moving into my window?. if i modify the value of the matrix using translatematix i didn't see anything because the display is done too fast. there is a method to move the object? 2) how i can draw a ball? i've seen the gluSphere, there's some problem using this function? i try this code, but dosen't work.
    private void drawBall(GL gl) {
ArrayList etas = new ArrayList();
ArrayList fis = new ArrayList();
int mslice = 10;
int nslice = 50;
double eta;
double fi;
ArrayList<Vertex3d> vertex = new ArrayList<Vertex3d>();
for (int i = 0; i < nslice - 1; i++) {
eta = ((2 * Math.PI) / nslice) * i;
}
for (int j = 0; j < mslice; j++) {
fi = -1 * (Math.PI / 2) + (Math.PI / mslice) * j;
}
for (int j = 0; j < fis.size(); j++) {
for (int i = 0; i < etas.size(); i++) {
eta = Double.valueOf("" + etas.get(i)).doubleValue();
fi = Double.valueOf("" + fis.get(j)).doubleValue();
Vertex3d v = new Vertex3d(Math.cos(eta) * Math.sin(fi), Math.sin(eta) * Math.sin(fi), Math.cos(fi));
}
}
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glBegin(GL.GL_TRIANGLES);
for (int i = 0; i < nslice; i++) {
int j = 0;
gl.glVertex3d(vertex.get(j).x, vertex.get(j).y, vertex.get(j).z);
gl.glVertex3d(vertex.get(j + i + 1).x, vertex.get(j + i + 1).y, vertex.get(j + i + 1).z);
gl.glVertex3d(vertex.get(j + i + 1 + 1).x, vertex.get(j + i + 1 + 1).y, vertex.get(j + i + 1 + 1).z);
gl.glVertex3d(vertex.get(j).x, vertex.get(j).y, vertex.get(j).z);
gl.glVertex3d(vertex.get(j + 1 + (nslice - 1)).x, vertex.get(j + 1 + (nslice - 1)).y, vertex.get(j + 1 + (nslice - 1)).z);
gl.glVertex3d(vertex.get(j + 1).x, vertex.get(j + 1).y, vertex.get(j + 1).z);

}
gl.glEnd();
gl.glColor3f(0.0f, 1.0f, 0.0f);
for (int i = 0; i < nslice - 1; i++) {
for (int j = 1; j < mslice; j++) {
gl.glVertex3d(vertex.get(j + i).x, vertex.get(j + i).y, vertex.get(j + i).z);
gl.glVertex3d(vertex.get(j + i + 1).x, vertex.get(j + i + 1).y, vertex.get(j + i + 1).z);
gl.glVertex3d(vertex.get(j + nslice + i + 1).x, vertex.get(j + nslice + i + 1).y, vertex.get(j + nslice + i + 1).z);
gl.glVertex3d(vertex.get(j + nslice + i).x, vertex.get(j + nslice + i).y, vertex.get(j + nslice + i).z);
gl.glVertex3d(vertex.get(j + (nslice - 1)).x, vertex.get(j + (nslice - 1)).y, vertex.get(j + (nslice - 1)).z);
gl.glVertex3d(vertex.get(j + 0).x, vertex.get(j + 0).y, vertex.get(j + 0).z);
gl.glVertex3d(vertex.get(j + nslice).x, vertex.get(j + nslice).y, vertex.get(j + nslice).z);
gl.glVertex3d(vertex.get(j + nslice + (nslice - 1)).x, vertex.get(j + nslice + (nslice - 1)).y, vertex.get(j + nslice + (nslice - 1)).z);

}
}
gl.glEnd();
}

3) someone of you have code about bouncing ball (java preferd). thanks.

1. 1
2. 2
Rutin
22
3. 3
JoeJ
18
4. 4
5. 5

• 17
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631726
• Total Posts
3001910
×