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 float32 tangentSpeed; 00055 int32 pointCount; 00056 int32 contactIndex; 00057 }; 00058 00059 struct b2ContactSolverDef 00060 { 00061 b2TimeStep step; 00062 b2Contact** contacts; 00063 int32 count; 00064 b2Position* positions; 00065 b2Velocity* velocities; 00066 b2StackAllocator* allocator; 00067 }; 00068 00069 class b2ContactSolver 00070 { 00071 public: 00072 b2ContactSolver(b2ContactSolverDef* def); 00073 ~b2ContactSolver(); 00074 00075 void InitializeVelocityConstraints(); 00076 00077 void WarmStart(); 00078 void SolveVelocityConstraints(); 00079 void StoreImpulses(); 00080 00081 bool SolvePositionConstraints(); 00082 bool SolveTOIPositionConstraints(int32 toiIndexA, int32 toiIndexB); 00083 00084 b2TimeStep m_step; 00085 b2Position* m_positions; 00086 b2Velocity* m_velocities; 00087 b2StackAllocator* m_allocator; 00088 b2ContactPositionConstraint* m_positionConstraints; 00089 b2ContactVelocityConstraint* m_velocityConstraints; 00090 b2Contact** m_contacts; 00091 int m_count; 00092 }; 00093 00094 #endif 00095