VPN termux about China.net
OpenGL mouse
#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>
#include "OutText.h"
#include <QApplication>
enum
{
FULLSCREAN,
EXIT // wyjście
};
// położenie kursora myszki
#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};
struct point
{
GLfloat x;
GLfloat y;
}point, quad;
namespace glut {
void CreateList(void)
{
int c=127;
do
{
glNewList(LIST_OBJECT *c, GL_COMPILE);
{
c--;
glColor3f(1.0,1.0,.0);
glutSolidSphere(0.07,4,4);
glFlush ();
glEndList();
}
}while (c > 0);
}
void enemy()
{
int i=113;
quad.x=0.9;
quad.y=0.9;
point.x=0.9;
point.y=0.9;
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
{
if ( point.y<0.12)
{
point.y=quad.y;
point.x=point.x-0.12;
}
i--;
glPushMatrix();
glTranslatef(point.x ,point.y, 0.0);
glCallList(LIST_OBJECT *i);
glPopMatrix();
point.y=point.y-0.12;
if (((point.y-0.02)<kulka.y+d) && (kulka.x<d +(point.x-0.02) )&& ((point.x-0.02)<d+kulka.x) &&((kulka.y-0.02)<d+point.y) )
{
glDeleteLists(LIST_OBJECT *i, 1 );
}
}
while(i>0);
if(point.y==0 && point.x==0 )
{
OutText("win");
}
glFlush ();
}
};
namespace glut {
GLfloat x2 , y2=-0.7;
int button_state = GLUT_UP;
int button_x, button_y;
const GLdouble left = - 10.0;
const GLdouble right = 10.0;
const GLdouble bottom = - 10.0;
const GLdouble top = 10.0;
const GLdouble near = 50.0;
const GLdouble far = 70.0;
int menu = 0;
void drawBall2(GLfloat x2, GLfloat y2)
{
glColor3f(1.0,0.0,.0);
glPushMatrix();
glTranslatef(x2, y2,0.0);
glutSolidSphere(d,20,20);
glPopMatrix();
}
void MouseButton( int button, int state, int x, int y )
{
if( button == GLUT_LEFT_BUTTON )
{
// zapamiętanie stanu lewego przycisku myszki
button_state = state;
// zapamiętanie położenia kursora myszki
if( state == GLUT_DOWN )
{
button_x = x;
button_y = y;
}
}
}
void MouseMotion( int x, int y )
{
if( button_state == GLUT_DOWN )
{
glut::x2 += 0.7 *( right - left ) / glutGet( GLUT_WINDOW_WIDTH ) *( x - button_x );
button_x = x;
glut::y2 += 0.7 *( top - bottom ) / glutGet( GLUT_WINDOW_HEIGHT ) *( button_y - y );
button_y = y;
glutPostRedisplay();
}
}
void keyboard (unsigned char key, int x, int y )
{
switch (key) {
case 'd':
x2=x2+0.1;
glutPostRedisplay();
break;
case 'a':
x2=x2-0.1;
glutPostRedisplay();
break;
case 'w':
y2=y2+0.1;
glutPostRedisplay();
break;
case 's':
y2=y2-0.1;
glutPostRedisplay();
break;
case 'q':
menu =menu+ 1;
break;
glutPostRedisplay();
break;
}
}
};
//p.
namespace glut { //class
void drawBall1()
{
glColor3f(0.0,1.0,.0);
glPushMatrix();
glTranslatef(kulka.x,kulka.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<d + glut::y2) && (kulka.x <d +glut::x2 )&& (glut::x2-kulka.x<d) )
{
speed.y=-speed.y;
}
}
};
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel(GL_SMOOTH);
glColor3f(1,0,0);
int w, h;
glut::drawBall2(glut::x2, glut::y2);
glut:: drawBall1();
glut::enemy();
glut::update();
OutText("win"); //TEKST in glut
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
}
void SpecialKeys( int key, int x, int y )
{
switch( key )
{
// kursor w lewo
case GLUT_KEY_LEFT:
glut::x2 -= 0.7;
break;
// kursor w górę
case GLUT_KEY_UP:
break;
// kursor w prawo
case GLUT_KEY_RIGHT:
glut::x2 += 0.7;
break;
// kursor w dół
case GLUT_KEY_DOWN:
break;
}
}
void Menu( int value )
{
switch( value )
{
case FULLSCREAN:
glutFullScreen();
display();
break;
case EXIT:
exit( 0 );
}
}
int main(int argc,char **argv) //kopjuj wklej p.
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(400,400);
// utworzenie głównego okna programu
#ifdef WIN32
glutCreateWindow( "Przekształcenia" );
#else
glutCreateWindow( "Przeksztalcenia" );
#endif
initRendering();
glut::CreateList();
glutReshapeFunc(reshape);
glutKeyboardFunc(glut::keyboard);
glutTimerFunc(0, Timer, 0);
glutDisplayFunc(display);
glutMotionFunc( glut::MouseMotion );
glutPassiveMotionFunc( glut::MouseMotion );
glutMouseFunc( glut::MouseButton );
glutSpecialFunc( SpecialKeys );
// utworzenie podmenu - aspekt obrazu
int MenuAspect = glutCreateMenu( Menu );
#ifdef WIN32
glutCreateMenu( Menu );
glutAddSubMenu( "full", FULLSCREAN );
#elseif
glutAddMenuEntry( "full", FULLSCREAN );
#elseif
glutAddMenuEntry( "Wyjście", EXIT );
#else
glutAddMenuEntry( "Wyjscie", EXIT );
#endif
// określenie przycisku myszki obsługującego menu podręczne
glutAttachMenu( GLUT_RIGHT_BUTTON );
glutMainLoop();
return 0;
}
Subscribe to:
Posts (Atom)
No comments:
Post a Comment