Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

2d collision detection teaser

  • 27-12-2010 11:28PM
    #1
    Registered Users, Registered Users 2 Posts: 627 ✭✭✭


    Hey, I'm having trouble understanding a piece of Math I came across and am looking for help. Bare with me as its interpreted through programming.
    The three vectors at the start are the position of the player, and each end of a line that is used for a collision. I dont understand the use of the cross product as its 2d nor the assignment of "dr",I understand the math but not its use in these circumstances. Delta is the main source of confusion so any help would be cool.

    Cheers

    Vector planePt1(landscape.xPos,landscape.yPos);
    Vector planePt2(landscape.xPos[i+1],landscape.yPos[i+1]);
    Vector player(this->pos.x,this->pos.y);
    x1 = planePt1.x - player.x;
    y1 = planePt1.y - player.y;
    x2 = planePt2.x - player.x;
    y2 = planePt2.y - player.y;
    dx = x2 - x1;
    dy = y2 - y1;
    dr = sqrtf(powf(dx, 2) + powf(dy, 2));//length of dxy
    D = x1*y2 - x2*y1;//Cross product of x1y1x2y2
    delta = powf(radiusOfPlayer*0.9,2)*powf(dr,2) - powf(D,2);

    //Collision detected
    if (delta >=0 )


Comments

  • Registered Users, Registered Users 2 Posts: 171 ✭✭conorcan2


    Dboy85 wrote: »
    dr = sqrtf(powf(dx, 2) + powf(dy, 2));//length of dxy
    [/COLOR]
    .

    Given two points, each denoted by x/y co-ordinates, you can get the length of the line between them with this formula.


  • Registered Users, Registered Users 2 Posts: 627 ✭✭✭Dboy85


    conorcan2 wrote: »
    .

    Given two points, each denoted by x/y co-ordinates, you can get the length of the line between them with this formula.

    Yeah I understand the Math and formula but the reasoning behind it is the problem.


Advertisement