• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Collision Response and points of contact

1 post in this topic

Hi all,

I'm working on a prototype simulator in which 3d entities move and collide. Collisions can be totally elastic or totally inelastic. The collision detection is demanded to [url="http://www.cs.ubc.ca/~lloyd/java/vclip.html"]V-Clip[/url] which returns the normal to the collision and the closest points (contact points) and features.

I've searched the web for a collision response algorithm and the impulse-based one seems perfectly suited for my purposes. Here started the madness for me, since I've found different formulas and my geometry skills are not that high. I have tried two of formulas I've found buth seems that neither of them work properly. I've searched for ideas about what I'm missing but ended up writing this post. Thus, sorry for the over-abused argument! [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]

The implementation I've tried are based on [url="http://www.euclideanspace.com/physics/dynamics/collision/threed/index.htm"]this[/url] approach (in particular the "Code" section, rearranged for Java) and the [url="http://en.wikipedia.org/wiki/Collision_response#Impulse-Based_Reaction_Model"]wikipedia[/url] one.
Applying both I have strange behaviours even in basic simple cases. Consider for instance two cubes side by side. One simulate a wall, the other moves again the second with velocity (5,0,0). In a correct setting I would have a final velocity of (-5,0,0) for the moving object. Instead, I have values like (11,0,0) or (-0.8428571428571425, 0.0, 0.0) like I'm messing up things.

I've noticed that, despite correctly returning the faces of the cubes for such simple collision, V-Clip returns a vertex for each face (not the center of the face) as the collision point. Thus the vector offset is calculate w.r.t. a vertex instead of the center of the face. If I select (manually) as contact points the center of the shapes, the algorithm works correctly returning the right values. Since this behaviour seemed strange, I've tried another configuration: I rotated the first cube by 45° x-axis, z-axis so that the nearest point would be a vertex. In this case V-Clip returned the vertex coordinates (almost) and the corresponding point on the face (not a vertex!) with an (almost) coherent final velocity:
starting velocity: (5.9, 0.0, 0.0)
final velocity: (-5.977962556993951, 0.0, 0.0)

Is that the problem? I mean, is the first one a degenerative cases inherited by V-Clip way of working or I just obtained the right values by chance?? in other words, should I calculate the "correct point" to which apply the response? In the attempt to answer such question(s), I attach the Java code for the second implementation (the one based on wikipedia). I've added comments, so that it [i]should[/i] be understandable. Inertia tensor is returned by V-Clip in local frame, so I multiply the rotation matrix for the local frame Inertia tensor and then the result is multiplyed per the transpose of the rotation matrix. That should be the right way. In the final part, no operation is executed on the velocity of the second object as it is supposed be a wall (not moving, mass infinite). "Ptree1" and "Ptree2" are two PolyTree data structures for entity A and entity B, which contains features and transformation matrices from local frame to global frames, inertia tensor, center of mass and so on.

Any help, any clue, anything is really appreciated! Thanks in advance and sorry for the long post (I've tried to be as descriptive as possible).

[code] // INERTIA TENSOR1 = rot I_1_body rotT (Baraff)
Matrix3d m1 = new Matrix3d();
Matrix3d rot = new Matrix3d();
Matrix3d rotT = new Matrix3d(rot);
m1.mul(rot, m1);
m1.mul(m1, rotT);
// INERTIA TENSOR2 = rot I_2_body rotT (Baraff)
Matrix3d m2 = new Matrix3d();
Matrix3d rot2 = new Matrix3d();
Matrix3d rotT2 = new Matrix3d(rot2);
m2.mul(rot2, m2);
m2.mul(m2, rotT2);
// PTREE1 - mass 1, velocity (defined previously)
// PTREE2 - mass +inf velocity (0,0,0)
// COR and other data
double e = 1;
double ma = 1;
Vector3d vel2 = new Vector3d(); // motionless
double mb = Double.POSITIVE_INFINITY;
//Ra --> contact point offset w.r.t. center (center calculated in the local coordinates system and then translated)
Vector3d center1 = new Vector3d();
center1.x += ptree1.getTransform().m03;
center1.y += ptree1.getTransform().m13;
center1.z += ptree1.getTransform().m23;
Vector3d Ra = new Vector3d(drep.getClosestPair().pnt1); // contact point in global coordinates
Ra.sub(center1); // final offset for A
//Rb --> contact point offset w.r.t. center (center calculated in the local coordinates system and then translated)
Vector3d center2 = new Vector3d();
center2.x += ptree2.getTransform().m03;
center2.y += ptree2.getTransform().m13;
center2.z += ptree2.getTransform().m23;
Vector3d Rb = new Vector3d(drep.getClosestPair().pnt2); // contact point in global coordinates
Rb.sub(center2); // final offset for B
// calculate denominator of impulse j
// I_a-1 (Ra cross nrm) cross Ra
Vector3d nrm = new Vector3d();
nrm.normalize(drep.getClosestPair().nrml); //normal to the collision ---> returned by V-Clip
Vector3d angularVelChangea = new Vector3d();
angularVelChangea.cross(Ra, nrm);
Vector3d vaLinDueToR = new Vector3d();
vaLinDueToR.cross(angularVelChangea, Ra);
// I_b-1 (Rb cross nrm) cross Rb
Vector3d angularVelChangeb = new Vector3d();
angularVelChangeb.cross(Rb, nrm);
Vector3d vbLinDueToR = new Vector3d();
vbLinDueToR.cross(angularVelChangeb, Rb);
// final denominator following Wikipedia formulation (the dot product is split since it is distributive)
double scalar = 1 / ma + 1 / mb + vaLinDueToR.dot(nrm) + vbLinDueToR.dot(nrm);
// calculating numerator following wikipedia ---> -(1 + e) ((v_b + omega_b cross Rb) - (v_a + omega_a cross Ra)) dot nrm
Vector3d vellDiff = new Vector3d();
Vector3d omegaCrossRa = new Vector3d();
omegaCrossRa.cross(rottt, Ra); // rottt is the angular velocity of A in radiants
Vector3d velCopy = new Vector3d(vel); // vel is the velocity of A copied to calcuate its sum with the cross product of angular velocity with Ra!
//NOTHING for vel2 ---> it is motionless!
vellDiff.sub(vel2, velCopy);
double Jmod = -(e + 1) * vellDiff.dot(nrm) / scalar; //here the final j
//calculate inpulse for A and B
Vector3d J = new Vector3d(nrm); //set the normal
J.scale(Jmod); // product between normal and j
Vector3d ja = new Vector3d(J);
Vector3d jb = new Vector3d(J);
ja.scale(1 / ma); // product the mass
jb.scale(1 / mb); // product the mass
// new velocities

Share this post

Link to post
Share on other sites
Ok, I've solved my doubts and problems about the inertia tensor and, most importantly, correctly calculated it.
Basically, V-Clip returns the "second moment of area" which is also called inertia tensor. Such matrix can be converted to the (mass) inertia tensor simply by multiplying it for the factor "m / V" with "m" the mass and "V" the volume of the shape.

Thanks to this correction the velocities updated by the response are at least [i]not [/i]over the overall initial momentum [b]but[/b] the results still seem incorrect.

Before plaguing you with a long post (which would end unanswered like the previous one) I'll repost the same - stupid - question: since at the denominator of the impulse magnitude appears the offset of the shared contact point from the centers of mass, choosing the wrong contact point would end in a wrong response? I'm still thinking to limit cases such as parallel faces in which any point is exactly at the same (minimal) distance.

Any help is really appreciated. Thanks in advance.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0