1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
// insert cube.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
#include <set>
#include <xtree>
double delta = 0.001;
double s_x;
double s_y;
typedef std::deque<ball> balls;
balls balls_;
void spawner(){
//glPushMatrix();
glColor3f(0,1,0);
glTranslatef(s_x,s_y,0);
glBegin(GL_QUADS);
glVertex3f(-.1,.1,0);
glVertex3f(-.1,-.1,0);
glVertex3f(.1,-.1,0);
glVertex3f(.1,.1,0);
glEnd();
//glFlush();
//glPopMatrix();
}
// vector<ball>;//, Ball(320,240));
void keyboard(){
ball b;
//new ball;
if(GetAsyncKeyState(VK_SPACE)){
b.x = s_x;
balls_.push_back(b);
//ball::add(s_x,s_y);
};
if(GetAsyncKeyState(VK_UP)){
s_y = delta;
};
if(GetAsyncKeyState(VK_DOWN)){
s_y = -delta;
};
if(GetAsyncKeyState(VK_LEFT)){
s_x = -delta;
};
if(GetAsyncKeyState(VK_RIGHT)){
s_x = delta;
};
if(!GetAsyncKeyState(VK_UP)&&!GetAsyncKeyState(VK_DOWN)){
s_y = 0;
}
if(!GetAsyncKeyState(VK_LEFT)&&!GetAsyncKeyState(VK_RIGHT)){
s_x = 0;
}
//s_x = 0;
//s_y = 0;
}
void draw(){
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0,0,0,0);
keyboard();
spawner();
ball::mainloop();
//glEnd();
glFlush();
glutPostRedisplay();
}
int main(int iArgc, char* cppArgv[])
{
glutInit(&iArgc,cppArgv);
//glutInitWindowSize(1000,600);
ball::ball();
glutCreateWindow("HELLO");
glutDisplayFunc(draw);
glutMainLoop();
return 0;
}
| |