![]() |
Box2D
2.2.1
A 2D Physics Engine for Games
|
00001 /* 00002 * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 00003 * 00004 * This software is provided 'as-is', without any express or implied 00005 * warranty. In no event will the authors be held liable for any damages 00006 * arising from the use of this software. 00007 * Permission is granted to anyone to use this software for any purpose, 00008 * including commercial applications, and to alter it and redistribute it 00009 * freely, subject to the following restrictions: 00010 * 1. The origin of this software must not be misrepresented; you must not 00011 * claim that you wrote the original software. If you use this software 00012 * in a product, an acknowledgment in the product documentation would be 00013 * appreciated but is not required. 00014 * 2. Altered source versions must be plainly marked as such, and must not be 00015 * misrepresented as being the original software. 00016 * 3. This notice may not be removed or altered from any source distribution. 00017 */ 00018 00019 #ifndef B2_CONTACT_SOLVER_H 00020 #define B2_CONTACT_SOLVER_H 00021 00022 #include <Box2D/Common/b2Math.h> 00023 #include <Box2D/Collision/b2Collision.h> 00024 #include <Box2D/Dynamics/b2TimeStep.h> 00025 00026 class b2Contact; 00027 class b2Body; 00028 class b2StackAllocator; 00029 struct b2ContactPositionConstraint; 00030 00031 struct b2VelocityConstraintPoint 00032 { 00033 b2Vec2 rA; 00034 b2Vec2 rB; 00035 float32 normalImpulse; 00036 float32 tangentImpulse; 00037 float32 normalMass; 00038 float32 tangentMass; 00039 float32 velocityBias; 00040 }; 00041 00042 struct b2ContactVelocityConstraint 00043 { 00044 b2VelocityConstraintPoint points[b2_maxManifoldPoints]; 00045 b2Vec2 normal; 00046 b2Mat22 normalMass; 00047 b2Mat22 K; 00048 int32 indexA; 00049 int32 indexB; 00050 float32 invMassA, invMassB; 00051 float32 invIA, invIB; 00052 float32 friction; 00053 float32 restitution; 00054 int32 pointCount; 00055 int32 contactIndex; 00056 }; 00057 00058 struct b2ContactSolverDef 00059 { 00060 b2TimeStep step; 00061 b2Contact** contacts; 00062 int32 count; 00063 b2Position* positions; 00064 b2Velocity* velocities; 00065 b2StackAllocator* allocator; 00066 }; 00067 00068 class b2ContactSolver 00069 { 00070 public: 00071 b2ContactSolver(b2ContactSolverDef* def); 00072 ~b2ContactSolver(); 00073 00074 void InitializeVelocityConstraints(); 00075 00076 void WarmStart(); 00077 void SolveVelocityConstraints(); 00078 void StoreImpulses(); 00079 00080 bool SolvePositionConstraints(); 00081 bool SolveTOIPositionConstraints(int32 toiIndexA, int32 toiIndexB); 00082 00083 b2TimeStep m_step; 00084 b2Position* m_positions; 00085 b2Velocity* m_velocities; 00086 b2StackAllocator* m_allocator; 00087 b2ContactPositionConstraint* m_positionConstraints; 00088 b2ContactVelocityConstraint* m_velocityConstraints; 00089 b2Contact** m_contacts; 00090 int m_count; 00091 }; 00092 00093 #endif 00094