File indexing completed on 2025-08-03 03:49:57

0001 /*
0002 * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
0003 *
0004 * This software is provided 'as-is', without any express or implied
0005 * warranty.  In no event will the authors be held liable for any damages
0006 * arising from the use of this software.
0007 * Permission is granted to anyone to use this software for any purpose,
0008 * including commercial applications, and to alter it and redistribute it
0009 * freely, subject to the following restrictions:
0010 * 1. The origin of this software must not be misrepresented; you must not
0011 * claim that you wrote the original software. If you use this software
0012 * in a product, an acknowledgment in the product documentation would be
0013 * appreciated but is not required.
0014 * 2. Altered source versions must be plainly marked as such, and must not be
0015 * misrepresented as being the original software.
0016 * 3. This notice may not be removed or altered from any source distribution.
0017 */
0018 
0019 #ifndef B2_CONTACT_SOLVER_H
0020 #define B2_CONTACT_SOLVER_H
0021 
0022 #include <Box2D/Common/b2Math.h>
0023 #include <Box2D/Collision/b2Collision.h>
0024 #include <Box2D/Dynamics/b2Island.h>
0025 
0026 class b2Contact;
0027 class b2Body;
0028 class b2StackAllocator;
0029 
0030 struct b2ContactConstraintPoint
0031 {
0032     b2Vec2 localPoint;
0033     b2Vec2 rA;
0034     b2Vec2 rB;
0035     qreal normalImpulse;
0036     qreal tangentImpulse;
0037     qreal normalMass;
0038     qreal tangentMass;
0039     qreal velocityBias;
0040 };
0041 
0042 struct b2ContactConstraint
0043 {
0044     b2ContactConstraintPoint points[b2_maxManifoldPoints];
0045     b2Vec2 localNormal;
0046     b2Vec2 localPoint;
0047     b2Vec2 normal;
0048     b2Mat22 normalMass;
0049     b2Mat22 K;
0050     b2Body* bodyA;
0051     b2Body* bodyB;
0052     b2Manifold::Type type;
0053     qreal radiusA, radiusB;
0054     qreal friction;
0055     qreal restitution;
0056     int32 pointCount;
0057     b2Manifold* manifold;
0058 };
0059 
0060 struct b2ContactSolverDef
0061 {
0062     b2Contact** contacts;
0063     int32 count;
0064     b2StackAllocator* allocator;
0065     qreal impulseRatio;
0066     bool warmStarting;
0067 };
0068 
0069 class b2ContactSolver
0070 {
0071 public:
0072     b2ContactSolver(b2ContactSolverDef* def);
0073     ~b2ContactSolver();
0074 
0075     void InitializeVelocityConstraints();
0076 
0077     void WarmStart();
0078     void SolveVelocityConstraints();
0079     void StoreImpulses();
0080 
0081     bool SolvePositionConstraints(qreal baumgarte);
0082     bool SolveTOIPositionConstraints(qreal baumgarte, const b2Body* toiBodyA, const b2Body* toiBodyB);
0083 
0084     b2StackAllocator* m_allocator;
0085     b2ContactConstraint* m_constraints;
0086     int m_count;
0087 };
0088 
0089 #endif
0090