VPN termux about China.net

Prymitive Asembly::glut



#ifdef __APPLE__
#include<GLUT/glut.h>
#include<openGL/openGL.h>

#else
#include<GL/glut.h>
#endif
#include <stdlib.h>
#include <string.h>
 #include <GL/gl.h>
#include <GL/glu.h>
#include<GL/glut.h>
//two player


#define  LIST_OBJECT  128


  //global                                                                                                              
GLfloat d = 0.1;
int refreshMillis = 30;

//end global
    



struct kulka
{     
            
GLfloat x;
GLfloat y ;

} kulka={0.0, -0.5} , wall= {1.0 , 1.0} , speed= {0.03, 0.04}, quad;
            
struct point
{
GLfloat x;
GLfloat y;
}point;


namespace glut {


void CreateList(void)
{


int c=128;
do{
 glNewList(LIST_OBJECT *c, GL_COMPILE);
{
c--;                                           
glColor3f(1.0,1.0,.0);

    glutSolidSphere(0.07,4,4);

asm ("call    glFlush \n");   //ASEMBLY GLUT
glEndList();

}
}while (c>0);
}

void enemy()
{


unsigned int i=129;


point.x=-0.9;
point.y=0.0;

glBegin(GL_LINE);
glVertex2f(-quad.x, quad.y);
glVertex2f(quad.x, quad.y);
glVertex2f(quad.x, 0.0);
glVertex2f(-quad.x, 0.0);
glEnd();



do
{
i--;
if ( (point.x>wall.x-0.12)&& (wall.y>=point.y))
{
point.y=point.y+0.12;
point.x=-wall.x+0.07;

}
 asm ("call    glPushMatrix \n");
glTranslatef(point.x ,point.y, 0.0);
  glCallList(LIST_OBJECT *i);
point.x=point.x+0.12;


 asm("call    glPopMatrix \n");        //ASEMBLY GLUT

 if (((point.y-0.12)<kulka.y+0.02) &&   (kulka.x<0.02 +(point.x-0.12) )&& ((point.x-0.12)<0.01+kulka.x) &&((kulka.y-0.12)<0.01+point.y)  )
{
glDeleteLists(LIST_OBJECT  *i , 1 );

}


}
while (i>0);

 asm ("call    glFlush \n");

}

};
namespace glut {

GLfloat x2 , y2=-0.7;
GLfloat x3 , y3=0.6;


void drawBall2(GLfloat x2,  GLfloat y2)
{

    glColor3f(1.0,0.0,.0);

     asm ("call glPushMatrix \n");
//ASEMBLY GLUT
    glTranslatef(x2, y2,0.0);

    glutSolidSphere(d,20,20);

    asm("call    glPopMatrix \n");
//ASEMBLY GLUT

}

void menu(GLfloat x3, GLfloat y3)
{
    glColor3f(1.0,0.0,.0);

    asm ("call    glPushMatrix \n");

    glTranslatef(x3, y3,0.0);

    glutSolidSphere(d,20,20);

asm("call    glPopMatrix \n");

}
void keyboard (unsigned char key, int x, int y )  
{



switch (key) {
case 'd':
x2=x2+0.1;
asm ("call glutPostRedisplay \n");
break;
case 'a':
x2=x2-0.1;
asm ("call glutPostRedisplay \n");
break;
case 'w':
y2=y2+0.1;
asm ("call glutPostRedisplay \n");
break;
case 's':
y2=y2-0.1;
asm ("call glutPostRedisplay \n");
break;
case 'l':
x3=x3+0.1;
asm ("call glutPostRedisplay \n");
break;
case 'j':
x3=x3-0.1;
asm ("call glutPostRedisplay \n");
break;
case 'i':
y3=y3+0.1;
asm ("call glutPostRedisplay \n");
break;
case 'k':
y3=y3-0.1;
asm ("call glutPostRedisplay \n");
break;
}
}

};
                                                        //p.

namespace glut {                //class


       



void drawBall1()
{

    glColor3f(0.0,1.0,.0);

    asm ("call    glPushMatrix \n");

    glTranslatef(kulka.x,kulka.y,0.0);

    glutSolidSphere(d,20,20);

    asm("call    glPopMatrix \n");
}


void update()
{

kulka.x+=speed.x;
kulka.y+=speed.y;
quad.x+=speed.x;
quad.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<d + glut::y2) && (kulka.x <d +glut::x2  )&& (glut::x2-kulka.x<d) )
{

speed.y=-speed.y;
}

if((  kulka.y<d + glut::y3) && (kulka.x <d +glut::x3 )&& (glut::x3-kulka.x<d) &&(glut::y3-kulka.y<d) )
{

speed.y=-speed.y;
}
}

};

void display()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();


 glShadeModel(GL_SMOOTH);
glColor3f(1,0,0);

glut::menu(glut::x3, glut::y3);
glut::drawBall2(glut::x2, glut::y2);   
glut:: drawBall1();
glut::update();
glut::enemy();

       
glutSwapBuffers();
}



void initRendering()
{
    glEnable(GL_DEPTH_TEST);   
  
 
}

void reshape(int w,int h)
{
  
     glViewport(0, 0, w, h);

 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();

glMatrixMode(GL_MODELVIEW);

   glLoadIdentity();


}             

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_SINGLE | GLUT_RGB);

    glutInitWindowSize(400,400);

    glutCreateWindow("gra Q");



  initRendering();
    glut::CreateList();

   
 glutReshapeFunc(reshape);
  glutKeyboardFunc(glut::keyboard);
glutTimerFunc(0, Timer, 0);
   glutDisplayFunc(display);
  asm ("call    glutMainLoop \n");


    return 0;

}

No comments:

Post a Comment