collision

This is a discussion on collision within the Game Programming forums, part of the General Programming Boards category; Ok, I'm making a racing game. I want to make a collision system so the cars will bounce off of ...

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    collision

    Ok, I'm making a racing game. I want to make a collision system so the cars will bounce off of each other realistically. The best I've come up with is to trade the direction and speed between any two cars when they collide, but this doesn't look right. Does anybody have a better method?
    Illusion and reality become impartiality and confidence.

  2. #2
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    well, excluding coming up with a total physics system, you can do a basic reflection algorithm which excluding mass and all, is basically what you have.

    Code:
    // NOTE : all the following vectors are unit length
    // R is a vector that will store the reflected vector
    // L is a vector that is to be reflected off of a surface
    // N is the normal vector representing the surface
    //  a period represents dot product 
    L *= -1;
    R =  2N(N . L) - L;
    someone with better drawing skills can give you a diagram.

    other than that, google for it.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Strangely it also looks like the formula for specular lighting.

  4. #4
    Banned
    Join Date
    May 2004
    Posts
    129
    How in depth do you want to go with this?

    For one, BladeRunner's equations do not work because it implies that *no kinetic energy is lost*, but in reality cars don't bounce off of each other with the same kinetic energy they had coming in towards the impact site. Also, you need to be able to resolve the normal of the collision. If you are using spheres, this is the unit vector that connects the centers of the spheres. If you are colliding their aligned bounding boxes, then you need to check for:

    vertex-vertex collisions
    vertex-edge collisions
    penetration collision

    in case 1, the normal is ambiguous so you can just make it cross through the centers of the boxes

    in case 2, the normal is the normal of the edge/plane that is being interacted with

    in case 3, you should separate the boxes and then determine if the interaction was vertex-vertex or vertex-edge (objects should never be allowed to penetrate in a physics simulation).

    edit

    Strangely it also looks like the formula for specular lighting.
    No, that equation has nothing to do with lighting per-se...all the equations do is reverse the normal component of the vector, nothing more...it just so happens that the collisions between photons and other objects are perfectly elastic, and subsequently no kinetic energy is ever lost, and the angle of incidence is equal to the angle of reflection.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Same idea, though. Unit reflected vector is the specular component.

  6. #6
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    For one, BladeRunner's equations do not work because it implies that *no kinetic energy is lost*
    *cough * *cough* I said that:

    excluding coming up with a total physics system, you can do a basic reflection algorithm which excluding mass and all, is basically what you have.
    I know all about linear/angular momentum in this situation(for example, this is why a huge 18-wheeler semi truck will plow through a car, not vice-versa).

    (objects should never be allowed to penetrate in a physics simulation)
    so much for bullets, thin/narrow objects(relative to what they are hitting) under the influence of heavy wind, needles ..... unless you are talking about when determining collisions they should never be allowed to penetrate?

    btw vVNation, I wouldn't mind talking to you about a physics engine that I am currently in the beginning stages of(see if I have everything down so far right), and I would also talk about your opengl implementation.
    Last edited by EvBladeRunnervE; 07-13-2004 at 12:04 PM.

  7. #7
    Banned
    Join Date
    May 2004
    Posts
    129
    Inter-penetrations aren't allowed to happen, period. You'll run into plenty of problems if you do.

    There's not a ton to talk about with the OpenGL implementation. Visit SGI's website, and look for their sample implementation. You can also find something called Mesa, which is another free OpenGL implementation. By reading through those thousands of lines of code, reading math books, and experimenting, I was able to create my own adaptations, and ultimately write about half of the implementation on my own. It really isn't that hard, but it is forced to ultimately run in software, not on your video card. This may represent a conundrum in your eyes, because you might be thinking "but OpenGL is supposed to be hardware accelerated, right?" Wrong. OpenGL is just an interface, nothing more.

  8. #8
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    This may represent a conundrum in your eyes, because you might be thinking "but OpenGL is supposed to be hardware accelerated, right?" Wrong. OpenGL is just an interface, nothing more.
    I know, I use mesa GL on my linux computer for the sole reason radon 9x00 series 3d hardware acceleration is a pain in the butt to get working.

    I presume you pretty much are programming what amounts to a software renderer interface.

  9. #9
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    Inter-penetrations aren't allowed to happen, period. You'll run into plenty of problems if you do
    I know that causes alot of problems.... the problem is, deforming polygons to enable penetration is pretty cpu intensive.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some collision handling fun
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 04-13-2008, 08:45 AM
  2. Collision Detection Problems
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 12-17-2006, 02:25 PM
  3. Collision Detection
    By Grantyt3 in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2005, 03:21 PM
  4. collision detection
    By DavidP in forum Game Programming
    Replies: 2
    Last Post: 05-11-2002, 01:31 PM
  5. Replies: 4
    Last Post: 05-03-2002, 09:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21