【发布时间】:2017-08-18 12:40:50
【问题描述】:
这是我的代码:
void Draw()
{
int x = 59;
int y = 500;
int temp = x;
int colour;
for (int i = 0; i < 9; ++i)
{
for (int j = 0; j < 10; ++j)
{
if (i % 2 == 0)
colour = 2;
else
colour = 3;
DrawRectangle(x, y, 65, 25, colors[colour]);
x += 67;
}
x = temp;
y -= 39;
}
DrawRectangle(tempx, 0, 85, 12, colors[5]);
DrawCircle(templx, temply, 10, colors[7]);
}
// This function will be called automatically by this frequency: 1000.0 / FPS
void Animate()
{
templx +=5;
temply +=5;
/*if(templx>350)
templx-=300;
if(temply>350)
temply-=300;*/
glutPostRedisplay(); // Once again call the Draw member function
}
// This function is called whenever the arrow keys on the keyboard are pressed...
//
我正在为这个项目使用 OpenGL。函数Draw() 用于打印积木、滑块和球。 Animate() 函数由代码中给出的频率自动调用。可以看出,我已经增加了templx 和temply 的值,但是当球越过极限时,球就会离开屏幕。如果球与桨或墙壁碰撞,我必须偏转球。我能做些什么来实现这一目标?我现在使用的所有条件都无法正常工作。
【问题讨论】: