This commit is contained in:
Zengtudor 2024-09-01 21:02:07 +08:00
parent ee649c5a21
commit c69c6eaada
1 changed files with 22 additions and 9 deletions

View File

@ -11,6 +11,21 @@
const float POINT_SIZE = 32.0f;
class BouncyBall{
public:
int bx=0,by=0,bsx=5,bsy=7;
BouncyBall(int x,int y,int speedX,int speedY):bx(x),by(y),bsx(speedX),bsy(speedY){}
BouncyBall* update(){
bx+=bsx,by+=bsy;
if(bx>=1000||bx<=-1000){
bsx=-bsx;
}
if(by>=1000||by<=-1000){
bsy=-bsy;
}
return this;
}
};
void render(){
glBegin(GL_TRIANGLES);
@ -34,15 +49,12 @@ void render(){
speed=0.01f;
}
glColor3f(num/1.11f,1.0f-(num/1.12f),num/1.13f);
static int bx=0,by=0,bsx=5,bsy=7;
glVertex3f(float(bx)/1000.0f,float(by)/1000.0f,0.0f);
bx+=bsx,by+=bsy;
if(bx>=1000||bx<=-1000){
bsx=-bsx;
}
if(by>=1000||by<=-1000){
bsy=-bsy;
}
static BouncyBall b1(0,0,5,6),b2(500,70,3,-6),b3(-250,-100,-40,-25);
glVertex3f(float(b1.bx)/1000.0f,float(b1.by)/1000.0f,0.0f);
glVertex3f(float(b2.bx)/1000.0f,float(b2.by)/1000.0f,0.0f);
glVertex3f(float(b3.bx)/1000.0f,float(b3.by)/1000.0f,0.0f);
b1.update(),b2.update(),b3.update();
glEnd();
}
@ -86,5 +98,6 @@ int main(){
#include<Windows.h>
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
main();
return 0;
}
#endif