Thread: Bounce - Dealing With It

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    Bounce - Dealing With It

    I detect a collision between some object and another, and I get a normal to the surface where the collision occured, and the point of that collision. I try to sort of pretend that the velocity vector of the colliding object and the surface normal make like an 'angle of incidence'. And then I go farther and deal with that whole dealiothingy in put it into the context of a polar system sort of. Looks like this (multiplication operator does dot product):

    Code:
            double incidence = std::acos( -v_ball.getNormalized() * normal );
    
            // Into polar (theta, radius) form
            double theta = std::acos( -v_ball.getNormalized() * CVector(1, 0) ) + incidence * 2;
            double radius = v_ball.length();
    
            // Into cartesian x, y form
            CVector out = CVector( std::cos( theta ) * radius, std::sin( theta ) * radius );
            m_ball.setVelocity( out );
    So, basically my logic is like this. It's wrong I guess, because the ball goes all over the place unpredictably after the collision, but, it's my logic.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Given you know the normal vector of the surface and the velocity vector of the ball -

    Ball.VelocityVector*=Surface.Normal;

    Given both are expressed as unit or normalized vectors.
    Last edited by VirtualAce; 12-25-2006 at 04:03 AM.

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I ended up using the formula for vector reflection:

    http://www.cse.iitb.ac.in/~adityagp/final/node3.html

    ( v_ball.getNormalized() - 2 * ( v_ball.getNormalized() * normal ) * normal ) * v_ball.length();

    The multiplication operator denoting a dot product operation when operating on vectors there.

    >> Ball.VelocityVector*=Surface.Normal;

    What will that give me? It didn't seem to work in my program (even after scaling that vector)

  4. #4
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92
    I'm not sure if this works, might be worth a try though:

    Ball.vel = Ball.vel - 2 * absolute(normal) * ball.vel

    Worked for me on normal = (-1, 0) and (0, 1), not sure if it's the general case though.

    Good luck

    Wazaa

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  2. dealing with copyrights
    By JOsephPataki in forum Game Programming
    Replies: 2
    Last Post: 06-21-2003, 03:08 PM
  3. Dealing with directx units
    By Frog22 in forum Game Programming
    Replies: 2
    Last Post: 10-23-2002, 10:42 PM
  4. bounce angles
    By canine in forum Windows Programming
    Replies: 1
    Last Post: 09-04-2002, 09:47 PM
  5. Bounce around screen
    By Akilla in forum C++ Programming
    Replies: 1
    Last Post: 07-19-2002, 10:05 PM