   OBB response
  i have set up object bounding box collision detectionfor my 2D game but i have a problem now - how toproperly use physics between the objects - let''s callthem cars, cars should have no gravity, they are placedand driving on a top-down plane, they are supposed tohave momentum and mass and all standard physics -nothing advanced (i think)because it is happening in 2D there are no matrices usedso far because they would go slow i guess..so, i have googled about this but found just about nothinguseful - only more on obb collision DETECTIONhow comes that this lightspeed obb intersection tests haveno resources on response?  2D not 3D..   
  That''s because the response of a collision isn''t dependent upon what bounding volumes you''re using.Any sort of collision must obey the basic laws of physics. And I''m pretty sure Newton didn''t know a thing about video games.In other words, read a physics book; The same laws that apply for objects in nature, apply for objects in games.~Main ==Colt "MainRoach" McAnlisProgrammerwww.badheat.com/sinewave ;  i agree with that and i have stt up basic physics to drive the "car" around, but i have no idea how to do collisions - to apply car's collisioned forces and keep obb's separated.  [edited by - Delfi on February 4, 2004 5:02:55 PM];  in general, the collision system should return points of contact, with the normal at the point of contact. then, the physics system uses that to apply a proper amount of force and torque to make the objects bounce and spin. Along with the car's mass and inertia tensor. if you are talking about the separation axis aligned test, it can be used to find the collision points. or at least a good approximation of it. the way I do it is, scan through the various separation axes tested (for OBBs in 2D, that's 4 axes), and take the axis with the minimum penetration depth. That gives me the normal of intersection, and the penetration depth. but for a simple car racing game in 2D, you can just simply find the corners of an OBB that are inside the other OBB, and use these as points of contact, and find the segment of the OBB that is the closest to the point, to get the normal of collision. It's an approximation, but it's a start. actually, for a problem like this, instead of a point and normal of collision, find the pair of contacting points, on both objects. So, the points that are inside the other OBB, and the point on the OBB that is the closest to the point inside the OBB. That gives you points of contact for both objects, and the normal of collision and depth of penetration, all in one go. That's what some collision detection libraries rreturn, the 2 points of contact on the two objects. also, if you can't find a point inside an OBB, but the OBB intersect, it means that you have a very deep penetration, and in that case, the collision data you could extract from this would be meaningless. SO, you can backtrack the objects a few steps, intil the collision depth is not too deep, and you get points inside the other OBB.  [edited by - oliii on February 4, 2004 5:34:39 PM];  "but for a simple car racing game in 2D, you can just simply find the corners of an OBB that are inside the other OBB, and use these as points of contact, and find the segment of the OBB that is the closest to the point, to get the normal of collision. It''s an approximation, but it''s a start.actually, for a problem like this, instead of a point and normal of collision, find the pair of contacting points, on both objects. So, the points that are inside the other OBB, and the point on the OBB that is the closest to the point inside the OBB. That gives you points of contact for both objects, and the normal of collision and depth of penetration, all in one go. That''s what some collision detection libraries rreturn, the 2 points of contact on the two objects."  o_0 ?  do you have some generic formula to fidd the depth of penetration and normal? ;quote:Original post by Delfi  o_0 ? do you have some generic formula to fidd the depth of penetration and normal?  well, say you have the two points of collision. the point inside (Pin) the box, and the corresponding point at the surface (Psurf) of the box. the normal and depths are simplyVector xNormal = Psurf - Pin;float depth = xNormal.Length();xNormal /= depth;in the first instance, I said that I had an algo to find the depth and normal of collision. But it is not totally sufficient for your kind of physics. You also need the collision points as well (to make the cars spin). YOu can still use the first algorithm, and apply a force on both cars that would push the cars sideway. you can find the code hereat the bottom, there is a link to a demo which implements OBBs collision detection as well. All is in 3D though, but for 2D''s OBBs the concept is similar. Only, you have just 4 separation axis to consider, instead of 15.  ;  this works for pushing boxes apart, but it doesn''t produce any momentum rotational effects - ie hitting a car into front from side would apply some rotation to it and push it away.. ;  yes, that''s what I said. To get the collision points, you''d need to find the support points on both boxes, using the plane normal. in 2D, it''s easy. you are bound to find either, one support point on a box vs 2 support points on the other box (a support segment), or 2 support points on each box. That''s when a box is resting on the other, and two faces on the two boxes are parallel. Then, if it''s a support point versus a support segment, then the point of collision would be, the support point found, and the projection of the support point on the segment.    PAsup   + Q0    |  .  |. |    |.    | .|  PBsup1 +--.-------+--.--------------+ PBsup2  .Q1  .  | .   . |    .  .|   . .   | collision normal    v along the opposite of normal, support points for A is PAsupalong the   normal, support points for B are [PBsup1, PBsup2]Q0 is the support point PAsupQ1 is the projection of Q0 on segment [PBsup1, PBsup2]finaly, the contact is [Q0, Q1]if it is a support segment against a support segment, then you get something like this PAsup1   | Q1  PAsup2 |  +-----+---------------+Q2    |   |   Q0+---------------+-----------+  | PBsup1    | Q3   |    PBsup2| | ||| collision normal|v   along the opposite of normal, support points for A are [PAsup0, PAsup1]along the   normal, support points for B are [PBsup1, PBsup2]Q0 is PBsup1Q1 is the projection of Q0 on segment [PAsup1, PAsup2]Q2 is PASup2Q3 is the projection of Q2 on segment [PBsup1, PBsup2]finaly, the contacts are [Q1, Q0], [Q2, Q3].;  for segment vs segment, to get the points Q0, Q2, sort the points, PAsup1, PAsup2, PBsup1, PBsup2 along Vector(-Normal.y, Normal.x), and take the points that are in the middle. ;  this just doesn''t make any f* sense o_0  sorry.. but it seems that i am stupid or something.. 