//to be continued...
//key rebulid
//win.h
#ifdef __APPLE__
#include<GLUT/glut.h>
#include<openGL/openGL.h>
#else
#include<GL/glut.h>
#endif
#include <stdlib.h>
GLfloat d = 0.1;
GLfloat y2=-0.7f;
int refreshMillis = 30;
struct kulka
{
GLfloat x;
GLfloat y ;
} kulka , wall= {1.0 , 1.0} , speed= {0.04, 0.07};
struct player
{
GLfloat x;
GLfloat y;
};
struct point
{
GLfloat x;
GLfloat y;
};
void initRendering()
{
glEnable(GL_DEPTH_TEST);
}
void reshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
} //p.
void drawBall1()
{
glColor3f(0.0,1.0,.0);
glPushMatrix();
glTranslatef(kulka.x,kulka.y,0.0);
glutSolidSphere(d,20,20);
glPopMatrix();
}
void drawBall2(GLfloat * x2)
{
glColor3f(1.0,0.0,.0);
glPushMatrix();
glTranslatef(* x2,-0.7,0.0);
glutSolidSphere(d,20,20);
glPopMatrix();
}
void drawballs()
{
point point1, point2, point3, point4, point5, point6;
point1.x=0.5;
point1.y=0.7;
point2.x=-0.5;
point2.y=0.7;
point3.x=0.0;
point3.y=0.7;
glColor3f(1.0,1.0,.0);
glPushMatrix();
glTranslatef(point1.x,point1.y,0.0);
glutSolidSphere(d,20,20);
glPopMatrix();
glPushMatrix();
glTranslatef(point2.x,point2.y,0.0);
glutSolidSphere(d,20,20);
glPopMatrix();
glPushMatrix();
glTranslatef(point3.x,point3.y,0.0);
glutSolidSphere(d,20,20);
glPopMatrix();
}
void update()
{
kulka.x+=speed.x;
kulka.y+=speed.y;
if (kulka.x>wall.x)
{
speed.x=-speed.x;
}
if ( kulka.y>wall.y)
{
speed.y=-speed.y;
}
if(kulka.x<-wall.x)
{
speed.x=-speed.x;
}
if ( kulka.y<-wall.y)
{
speed.y=-speed.y;
}
}
void keyboard (unsigned char key, int x, int y ) //core dumpted p.
{
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);
GLfloat * x2;
update();
drawballs();
drawBall1(); //zielona
drawBall2(x2);
//czerwona
glutSwapBuffers();
}
void Timer(int value) //kopjuj wklej p.
{
glutPostRedisplay(); // Post a paint request to activate display()
glutTimerFunc(refreshMillis, Timer, 0); // subsequent timer call at milliseconds
}
int main(int argc,char **argv) //kopjuj wklej p.
{
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;
}
No comments:
Post a Comment