开发者

Testing collision of car object with respect to the world coordinates

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:
开发者_如何学GoglTranslatef(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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜