Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

2d collision detection teaser

  • 27-12-2010 10: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