GLfloat d = 0.1;
//core dumpted to rebulid
GLfloat wekt;
GLfloat wekt2;
int flag=1;
GLfloat x1=-0.0;
GLfloat y1 =0.0;
GLfloat y2=-0.7f;
int refreshMillis = 30;
GLfloat xSpeed = 0.002f; // Ball's speed in x and y directions
GLfloat ySpeed = 0.01f;
void initRendering()
{
glEnable(GL_DEPTH_TEST);
}
void reshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
void drawBall1()
{
glColor3f(0.0,0.0,1.0);
glPushMatrix();
glTranslatef(x1,y1,0.0);
glutSolidSphere(d,20,20);
glPopMatrix();
}
void drawBall2(GLfloat *x2)
{
glColor3f(1.0,0.0,.0);
glPushMatrix();
glTranslatef(*x2,y2,0.0);
glutSolidSphere(d,20,20);
glPopMatrix();
}
void update()
{
x1 += xSpeed;
y1 += ySpeed;
if( y1>1.0)
{
ySpeed= -ySpeed;
}
if (y1<-1.0)
{
ySpeed= -ySpeed;
}
if (x1<-1.0)
{
xSpeed= -xSpeed;
}
if (x1>1.0)
{
xSpeed= -xSpeed;
}
}
void keyboard (unsigned char key, int x, int y )
{
GLfloat *x2;
switch (key) {
case 'd':
*x2= *x2+0.1f;
glutPostRedisplay();
break;
case 'a':
*x2= *x2-0.1f;
glutPostRedisplay();
break;
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//glShadeModel(GL_SMOOTH);
drawBall1();
GLfloat *x2;
drawBall2(x2); //niebieska
update();
//colision
if(( y1-y2<d ) && (x1-*x2<d )&& (*x2-x1<d) )
{
ySpeed= -ySpeed;
}
glutSwapBuffers();
}
void Timer(int value) {
glutPostRedisplay(); // Post a paint request to activate display()
glutTimerFunc(refreshMillis, Timer, 0); // subsequent timer call at milliseconds
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowSize(400,400);
glutCreateWindow("gra Q");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutTimerFunc(0, Timer, 0);
initRendering();
glutMainLoop();
return 0;
}
//to be continue..
No comments:
Post a Comment