Here's my program. The floats x and y draw the ball at 0,0 as that is their constant values. gltranslatef then translates up 0.1 in the positive y direction every time the animation loop comes around. This results in the ball slowly moving up the window until it dissapears. Printf then prints the values of x and y every time to show that they are always 0.
My problem is that if my original coordinates are 0,0 then I can't use those to detect collisions because I use gltranslatef for movement instead of just writing new coordinates every time.
So gltranslatef only tells me that it has move 0.1 in the positive y direction.
I don't understand how to detect collisions when there is no way (that I know of) of knowing the coordinates of the ball in the window, thus not being able to know if it is colliding with the top or a certain point.
This is certainly not pong, but it does simulate how I've understood a ball should move when animated.
My code:
Code:
#include <glut.h>
#include <stdio.h>
float x,y;
void colors(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glColor3f(1.0,1.0,1.0);
glPointSize(5);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glTranslatef(0.0,0.1,0.0);
glBegin(GL_POINTS);
glVertex2f(0.0,0.0);
glEnd();
glutSwapBuffers();
}
void update(void)
{
glutPostRedisplay();
printf("%f\n\n%f\n\n", x , y);
glutTimerFunc(500,update,0);
}
int main(int argc, char **argv)
{
x = 0.0;
y = 0.0;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(100,100);
glutCreateWindow("Moving Ball");
glutDisplayFunc(display);
colors();
glutTimerFunc(500,update,0);
glutMainLoop();
}
Thanks for this - this forum is too kind .