Jump to content
  • Advertisement

Irlan Robson

Member
  • Content Count

    634
  • Joined

  • Last visited

Community Reputation

4091 Excellent

About Irlan Robson

  • Rank
    Advanced Member

Personal Information

  • Role
    Programmer
  • Interests
    Business
    Education
    Programming

Recent Profile Visitors

22106 profile views
  1. For extracting the rotational part of a 3x3 matrix I use a quaternion based decomposition then convert the result back to a matrix: http://matthias-mueller-fischer.ch/publications/stablePolarDecomp.pdf This method solves a couple of simulation problems and it is extremelly easy to implement.
  2. Irlan Robson

    How do I stop sinking and sliding objects?

    It's difficult to guess what the problem is. It seems it is a numerical problem, maybe a division by zero, or maybe you're not initializing some variable. You will need to debug this. Pay attention to the compiler warnings. Again, my suggestion is to do spheres on plane because CD is like 10 lines of code in that case. It will be highly easy to debug this.
  3. Irlan Robson

    How do I stop sinking and sliding objects?

    You're just guessing! It can be anything. If you can't solve a problem then there is a simpler problem you can solve. Therefore, my suggestion is to simulate a vertical stack of spheres falling over a stationary plane under gravity. This is what I did a long time ago. Simulating AABBs can make you blindly debug rotations since they can't rotate. Spheres can rotate. Ensure the collision detection and contact generation code for spheres on a plane is working. Fortunately in collision detection you can visualize everything. Happily it's pretty easy to render a plane and a sphere. Be simple. You don't need to render textures or anything like this. After everything is working debug the contact solver. Your contact solver code seems to have no troubles. Then debug the friction solver. This is how engines are created. One feature at a time sorted by importance. Understand it, implement it, test it out, then debug it. It seems you're trying to solve multiple problems at once. Solve one problem at a time. Otherwise you're chasing waterfalls.
  4. Irlan Robson

    How do I stop sinking and sliding objects?

    Arbiter.h Fine AFAIK Arbiter.cpp Collision detection and contact creation code difficult to read due to DXMATH and likely bugged. Suggestion is to do spheres on a plane. Line 379: // accumulate Impulses XMVECTOR P = c->Pn * n + c->Pt * tangent[1]; Should be // apply impulses XMVECTOR P = c->Pn * n + c->Pt1 * tangent[0] + C->Pt2 * tangent[1]; There should be two impulses per contact point. One for each tangential direction (simply). World.h Fine AFAIK World.cpp Seems good The videos are still not showing up. Your posts are becoming a great mess. Use YouTube!
  5. Irlan Robson

    How do I stop sinking and sliding objects?

    Don't expect us to debug the code for you. The best we can do is sharing information and some code. Debug draw everything you can! This can be done by defining a simple global draw interface variable that you can call anywhere in your library. Draw the boxes Draw the SAT features Draw the Sutherland Hodgman Clipping polygon Draw the contact points, normals, and tangents Make a testbed. Each test draws something different. The videos above are not showing up for me too. Put them on YT and share as a private link!
  6. Irlan Robson

    How do I stop sinking and sliding objects?

    Are you solving one contact point? By looking at your stuff I don't think so... If that's the case, there are some bugs in your code, which is common for a newbie. Some fixes: 1. Your code is using the relative velocity at each iteration to compute the velocity bias. This is wrong. You should only use the initial relative velocity to compute the velocity bias. 2. Your code is multiplying the impulse vector by some scalar. This is called relaxation. This is not necessary. You're already adding the restitution to the velocity constraint if it falls bellow a threshold (-1). So no need to scale it up. 3. Your code is not warm starting the solver (applying the cached impulses) 4. You code is not accumulating the impulses. Neither it is clamping the new accumulated impulses. Then there can be a sign problem. If the contact normal always point from body A to body B (which is a good idea) then the velocity constraint is as such: float32 Cdot = b3Dot(vB - vA, m_normal); float32 impulse = -m_invK * (Cdot + m_velocityBias); b3Vec3 PA = -impulse * m_normal; b3Vec3 PB = -PA; // Apply impulses to bodies Your code should look something along these lines (pseudo): void Contact::InitializeVelocityConstraints() { // Evaluate C // Compute velocity bias // Compute effective mass } void Contact::WarmStart() { // Apply accumulated impulses } void Contact::SolveVelocityConstraints() { // Compute Cdot // Compute impulse // Accumulate and clamp impulses // Apply impulses } Then a simple simulation loop could be something like this: GenerateContacts(); IntegrateVelocities(); for each contact c c->InitializeVelocityConstraints(); c->WarmStart(); for each iteration for each contact c c->SolveVelocityConstraints(); IntegratePositions(); If you do the math you will realize that initializing and solving contact velocity constraints this way is equivalent to formulating a linear system (actually an LCP) and iteratively solving it using Projected Gauss Seidel. As I said in an earlier post, you should port exactly the solver code that is in whatever reliable engine using sequential impulses. I recommend Bounce Lite's because that is the solver you're trying to implement. Don't play around with alternatives. Unless you're solving a sphere on a plane, which is what I recoomended earlier. In this case you need only one impulse to bring the relative velocity at the contact point to a target value and don't need impulse caching at all.
  7. Irlan Robson

    3D Rigidbody Simulation

    The method I showed is just Euler's method applied to quaternions and a derivation can be found here: http://web.cs.iastate.edu/~cs577/handouts/quaternion.pdf I've been using this method for years without a single problem. Of course I normalize the quaternion after integration. This is fast. What you showed seems more like an alternative to Euler's method. And you said it is better than Euler's method. So do you have a proof for this? A paper maybe?
  8. Irlan Robson

    Add 'ground' to this physics system?

    Yes, I know. Sorry, issu diss! Dirk is correct. I was just being extremely sloppy in my post. For completeness, in general, we have the following pair of features which can build a separating axis. Achronyms for features: V = Vertex, E = Edge, F = Face. FV/FE/FF, VF/EF/FF, EE, and VV. Since VV only occurs if the shapes aren't actually penetrating, then you handle it in the FF case. FV/FE/VF/EF are handled by the FF case. You can visualize the axis generated by a feature pair by drawing a line between the closest points between the features of two separated convex hulls . You can find a good article on SAT in the book Game Physics Pearls. After a quick search I found this beautiful implementation by my friend Randy for OBB-OBB overlapping test and contact generation which uses the rotations as axes: https://github.com/RandyGaul/qu3e/blob/master/src/collision/q3Collide.cpp Maybe that's helpful.
  9. Irlan Robson

    Add 'ground' to this physics system?

    Edit: For two OBBs the possible separating axes are absolute local rotation vectors of the second OBB's frame expressed in the first OBB's frame and their cross product, not the absolute face directions.
  10. Irlan Robson

    Add 'ground' to this physics system?

    Simplifying the SAT and the contact creation code in Bounce Lite for two 3D OBBs is trivial. For two OOBs the possible separation axes are the absolute face directions of both OOBs and their cross product. You can get a more in depth explanation of the SAT for two OBBs in Christer's Real Time Collision Detection book, at page 101. Again, in order to testing things out I would first implement a sphere on a plane. Then add more spheres. Then you can add more shapes to your engine. If you have more questions regarding OBBs you should probably simple spin-off this topic into another thread for convenience.
  11. Irlan Robson

    Add 'ground' to this physics system?

    The box hull actually lives here: https://github.com/irlanrobson/bounce_lite/blob/master/include/bounce_lite/collision/shapes/box_hull.h
  12. Irlan Robson

    Add 'ground' to this physics system?

    Bounce Lite doesn't support only AABBs. It supports general convex hulls. A convex hull can be represented by a half-edge based polygonal mesh. This representation is extremely important if you want to optimize SAT for fast queries. Here how a convex hull is declared: https://github.com/irlanrobson/bounce_lite/blob/master/include/bounce_lite/collision/shapes/hull.h A box is a type of convex hull. Here's a compiled convex hull for a box: https://github.com/irlanrobson/bounce_lite/blob/master/include/bounce_lite/collision/shapes/hull.h The following file contains functions which uses SAT to test overlaps and generate contact points. https://github.com/irlanrobson/bounce_lite/blob/master/src/bounce_lite/dynamics/contacts/collide/collide.cpp All the clipping code resides in this file: https://github.com/irlanrobson/bounce_lite/blob/master/src/bounce_lite/dynamics/contacts/collide/clip.cpp Dirk gave a talk about the SAT back in 2013. This might get you introduced into this topic: http://box2d.org/files/GDC2013/DGregorius_GDC2013.zip
  13. Irlan Robson

    Add 'ground' to this physics system?

    A little bit off-topic, but just for completeness though. The function Dirk mentioned SetVelocityFromKeyframe() can be done by applying the finite difference method. If the two keyframed transforms corresponds to the center of mass and rotation transform of the associated body then the formulas for the linear and angular velocity applying one finite difference are: v = (c2 - c1) / dt w = (2 * (q2 - q1) * conjugate(q1)) / dt You need make sure the interpolated quaternion is along the shortest path between q1 and q2. So you need to check the polarity. This can be done by flipping the sign of one of the quaternions according to the sign of their dot product as we do in keyframe interpolation. Hence, our final quaternion formula can be: s = sign(dot(q1, q2)) w = (2 * (q2 - s * q1) * conjugate(s * q1)) / dt Then you set the linear and angular velocity of the kinematic body to the above before stepping a world.
  14. Irlan Robson

    Add 'ground' to this physics system?

    A good hint if you really want to implement this from scratch is to start simple. Begin with a sphere on a plane. Then add more spheres to test stacking. And there you go... These portions of code implements contact resolution. This is just a matter of looping over each contact sequentially solving velocity constraints. Note that this is not a naive impulse approach. This is a more mathematically correct way of applying impulses. Don't play around with some extreme simplifications or hacks around there such as the naive impulse approach if you really want to get this working reliably for multiple bodies. https://github.com/irlanrobson/bounce_lite/blob/master/src/bounce_lite/dynamics/contacts/contact_solver.cpp https://github.com/irlanrobson/bounce_lite/blob/master/src/bounce_lite/dynamics/contacts/contact.cpp All this code is called from an island. But you don't need islands in your simple engine. So you can skip this feature. https://github.com/irlanrobson/bounce_lite/blob/master/src/bounce_lite/dynamics/island.cpp With Box2D Lite and Bounce Lite and on the side you should be able to successfully implement you simple engine of dreams. Erin gave a nice talk about constraints in 2014. This should get you introduced to the topic. The accompanying material also contains some MATLAB code. http://box2d.org/files/GDC2014/GDC2014_ErinCatto.zip
  15. Irlan Robson

    Add 'ground' to this physics system?

    Did you check Bounce Lite? It's essentially a 3D port of Box2D Lite. Bounce Lite only supports impulse caching. Bounce supports impulse caching or contact re-clipping/rebuilding. Those are essential features in order to get a stable stacking using a small number of iterations. The latter being particularly important in 3D since the main problems here involve rotations. So basically in order for friction and stacking to work stably you need to cache impulses. Otherwise you will need lots of velocity constraint solver iterations since you don't have an initial guess. For deep contacts in 3D you also need frame coherence as mentioned above. Those are somewhat quite involving but is relatively easy to implement. Don't get desperate! Fortunately these are well understood and solved problems. All this is implemented in Bounce Lite and Bounce. You definitely need a reference code in order to get things working. Then you can add more features to your library. But please make sure you understand every aspect of the engine. It becomes much easier to debug something you can understand.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!