测试汽车对象相对于世界坐标的碰撞
我正在做一个 opengl C++ 停车场游戏。我想测试我的汽车对象的碰撞,我有 10 个汽车相对于世界坐标的末端顶点。并将它们分别存储在 x 和 y 的两个数组中,分别为 x[10] 和 y[10],所以现在假设我需要一条障碍线,汽车不应在其上方通过,并且结束坐标为 (x1, y1) 和(x2, y2),其中 y1=y2...我应该做什么?
我尝试这样做
int collision()
{
for(i=0;i<=10;i++)
{
if( y[i]>=y1)
{printf("\a");
return 1;}}
else return 0;
}
if( key == GLUT_KEY_UP) // up
{
glTranslatef(0.0,.1,0.0);
c=collision();
if(c==1)
goto l1;
glTranslatef(0.0,.1,0.0);
c=collision();
if(c==1)
goto l1;
glTranslatef(0.0,.1,0.0);
c=collision();
if(c==1)
goto l1;
glTranslatef(0.0,.1,0.0);
c=collision();
if(c==1)
goto l1;
glTranslatef(0.0,.1,0.0);
c=collision();
if(c==1)
{l1:
glTranslatef(0,-0.5,0);
}
}
上面是我的代码的一小部分......我没有得到准确的结果,它不起作用。 我是否可以为下键执行另一个碰撞功能?
I am doing an opengl C++ car parking game. I want to test collision of my car object I ve 10 end vertices of the car with respect to the world coordinates. And ve stored them separately in two arrays for x and y as x[10] and y[10], so now suppose I need to ve a barrier line above which the car shouldnt pass and ve end coordinates as (x1, y1) and (x2, y2), where y1=y2... what am I supposed to do?
I tried doing this
int collision()
{
for(i=0;i<=10;i++)
{
if( y[i]>=y1)
{printf("\a");
return 1;}}
else return 0;
}
if( key == GLUT_KEY_UP) // up
{
glTranslatef(0.0,.1,0.0);
c=collision();
if(c==1)
goto l1;
glTranslatef(0.0,.1,0.0);
c=collision();
if(c==1)
goto l1;
glTranslatef(0.0,.1,0.0);
c=collision();
if(c==1)
goto l1;
glTranslatef(0.0,.1,0.0);
c=collision();
if(c==1)
goto l1;
glTranslatef(0.0,.1,0.0);
c=collision();
if(c==1)
{l1:
glTranslatef(0,-0.5,0);
}
}
The above is a very small part of my code... I am not getting accurate results its not working.
And do I do a nother collision function for down key?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenGL 既不是数学,也不是几何,也不是碰撞检测,也不是物理库。它是一个绘图 API,它所做的就是在屏幕上绘制漂亮的图片。时期。
您需要的任何其他内容都必须自己实现或使用第三方库。
OpenGL is neiter a math, nor a geometry, nor a collision detection, nor a physics library. It's a drawing API, all it does is drawing nice pictures to the screen. Period.
Anything else you need you have to implement it yourself or use a 3rd party library for.