Warning, file /education/gcompris/external/qml-box2d/Box2D/Dynamics/b2Body.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org 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_BODY_H 0020 #define B2_BODY_H 0021 0022 #include <Box2D/Common/b2Math.h> 0023 #include <Box2D/Collision/Shapes/b2Shape.h> 0024 #include <memory> 0025 0026 class b2Fixture; 0027 class b2Joint; 0028 class b2Contact; 0029 class b2Controller; 0030 class b2World; 0031 struct b2FixtureDef; 0032 struct b2JointEdge; 0033 struct b2ContactEdge; 0034 0035 /// The body type. 0036 /// static: zero mass, zero velocity, may be manually moved 0037 /// kinematic: zero mass, non-zero velocity set by user, moved by solver 0038 /// dynamic: positive mass, non-zero velocity determined by forces, moved by solver 0039 enum b2BodyType 0040 { 0041 b2_staticBody = 0, 0042 b2_kinematicBody, 0043 b2_dynamicBody 0044 0045 // TODO_ERIN 0046 //b2_bulletBody, 0047 }; 0048 0049 /// A body definition holds all the data needed to construct a rigid body. 0050 /// You can safely re-use body definitions. Shapes are added to a body after construction. 0051 struct b2BodyDef 0052 { 0053 /// This constructor sets the body definition default values. 0054 b2BodyDef() 0055 { 0056 userData = NULL; 0057 position.Set(0.0f, 0.0f); 0058 angle = 0.0f; 0059 linearVelocity.Set(0.0f, 0.0f); 0060 angularVelocity = 0.0f; 0061 linearDamping = 0.0f; 0062 angularDamping = 0.0f; 0063 allowSleep = true; 0064 awake = true; 0065 fixedRotation = false; 0066 bullet = false; 0067 type = b2_staticBody; 0068 active = true; 0069 gravityScale = 1.0f; 0070 } 0071 0072 /// The body type: static, kinematic, or dynamic. 0073 /// Note: if a dynamic body would have zero mass, the mass is set to one. 0074 b2BodyType type; 0075 0076 /// The world position of the body. Avoid creating bodies at the origin 0077 /// since this can lead to many overlapping shapes. 0078 b2Vec2 position; 0079 0080 /// The world angle of the body in radians. 0081 float32 angle; 0082 0083 /// The linear velocity of the body's origin in world co-ordinates. 0084 b2Vec2 linearVelocity; 0085 0086 /// The angular velocity of the body. 0087 float32 angularVelocity; 0088 0089 /// Linear damping is use to reduce the linear velocity. The damping parameter 0090 /// can be larger than 1.0f but the damping effect becomes sensitive to the 0091 /// time step when the damping parameter is large. 0092 float32 linearDamping; 0093 0094 /// Angular damping is use to reduce the angular velocity. The damping parameter 0095 /// can be larger than 1.0f but the damping effect becomes sensitive to the 0096 /// time step when the damping parameter is large. 0097 float32 angularDamping; 0098 0099 /// Set this flag to false if this body should never fall asleep. Note that 0100 /// this increases CPU usage. 0101 bool allowSleep; 0102 0103 /// Is this body initially awake or sleeping? 0104 bool awake; 0105 0106 /// Should this body be prevented from rotating? Useful for characters. 0107 bool fixedRotation; 0108 0109 /// Is this a fast moving body that should be prevented from tunneling through 0110 /// other moving bodies? Note that all bodies are prevented from tunneling through 0111 /// kinematic and static bodies. This setting is only considered on dynamic bodies. 0112 /// @warning You should use this flag sparingly since it increases processing time. 0113 bool bullet; 0114 0115 /// Does this body start out active? 0116 bool active; 0117 0118 /// Use this to store application specific body data. 0119 void* userData; 0120 0121 /// Scale the gravity applied to this body. 0122 float32 gravityScale; 0123 }; 0124 0125 /// A rigid body. These are created via b2World::CreateBody. 0126 class b2Body 0127 { 0128 public: 0129 /// Creates a fixture and attach it to this body. Use this function if you need 0130 /// to set some fixture parameters, like friction. Otherwise you can create the 0131 /// fixture directly from a shape. 0132 /// If the density is non-zero, this function automatically updates the mass of the body. 0133 /// Contacts are not created until the next time step. 0134 /// @param def the fixture definition. 0135 /// @warning This function is locked during callbacks. 0136 b2Fixture* CreateFixture(const b2FixtureDef* def); 0137 0138 /// Creates a fixture from a shape and attach it to this body. 0139 /// This is a convenience function. Use b2FixtureDef if you need to set parameters 0140 /// like friction, restitution, user data, or filtering. 0141 /// If the density is non-zero, this function automatically updates the mass of the body. 0142 /// @param shape the shape to be cloned. 0143 /// @param density the shape density (set to zero for static bodies). 0144 /// @warning This function is locked during callbacks. 0145 b2Fixture* CreateFixture(const b2Shape* shape, float32 density); 0146 0147 /// Destroy a fixture. This removes the fixture from the broad-phase and 0148 /// destroys all contacts associated with this fixture. This will 0149 /// automatically adjust the mass of the body if the body is dynamic and the 0150 /// fixture has positive density. 0151 /// All fixtures attached to a body are implicitly destroyed when the body is destroyed. 0152 /// @param fixture the fixture to be removed. 0153 /// @warning This function is locked during callbacks. 0154 void DestroyFixture(b2Fixture* fixture); 0155 0156 /// Set the position of the body's origin and rotation. 0157 /// Manipulating a body's transform may cause non-physical behavior. 0158 /// Note: contacts are updated on the next call to b2World::Step. 0159 /// @param position the world position of the body's local origin. 0160 /// @param angle the world rotation in radians. 0161 void SetTransform(const b2Vec2& position, float32 angle); 0162 0163 /// Get the body transform for the body's origin. 0164 /// @return the world transform of the body's origin. 0165 const b2Transform& GetTransform() const; 0166 0167 /// Get the world body origin position. 0168 /// @return the world position of the body's origin. 0169 const b2Vec2& GetPosition() const; 0170 0171 /// Get the angle in radians. 0172 /// @return the current world rotation angle in radians. 0173 float32 GetAngle() const; 0174 0175 /// Get the world position of the center of mass. 0176 const b2Vec2& GetWorldCenter() const; 0177 0178 /// Get the local position of the center of mass. 0179 const b2Vec2& GetLocalCenter() const; 0180 0181 /// Set the linear velocity of the center of mass. 0182 /// @param v the new linear velocity of the center of mass. 0183 void SetLinearVelocity(const b2Vec2& v); 0184 0185 /// Get the linear velocity of the center of mass. 0186 /// @return the linear velocity of the center of mass. 0187 const b2Vec2& GetLinearVelocity() const; 0188 0189 /// Set the angular velocity. 0190 /// @param omega the new angular velocity in radians/second. 0191 void SetAngularVelocity(float32 omega); 0192 0193 /// Get the angular velocity. 0194 /// @return the angular velocity in radians/second. 0195 float32 GetAngularVelocity() const; 0196 0197 /// Apply a force at a world point. If the force is not 0198 /// applied at the center of mass, it will generate a torque and 0199 /// affect the angular velocity. This wakes up the body. 0200 /// @param force the world force vector, usually in Newtons (N). 0201 /// @param point the world position of the point of application. 0202 /// @param wake also wake up the body 0203 void ApplyForce(const b2Vec2& force, const b2Vec2& point, bool wake); 0204 0205 /// Apply a force to the center of mass. This wakes up the body. 0206 /// @param force the world force vector, usually in Newtons (N). 0207 /// @param wake also wake up the body 0208 void ApplyForceToCenter(const b2Vec2& force, bool wake); 0209 0210 /// Apply a torque. This affects the angular velocity 0211 /// without affecting the linear velocity of the center of mass. 0212 /// This wakes up the body. 0213 /// @param torque about the z-axis (out of the screen), usually in N-m. 0214 /// @param wake also wake up the body 0215 void ApplyTorque(float32 torque, bool wake); 0216 0217 /// Apply an impulse at a point. This immediately modifies the velocity. 0218 /// It also modifies the angular velocity if the point of application 0219 /// is not at the center of mass. This wakes up the body. 0220 /// @param impulse the world impulse vector, usually in N-seconds or kg-m/s. 0221 /// @param point the world position of the point of application. 0222 /// @param wake also wake up the body 0223 void ApplyLinearImpulse(const b2Vec2& impulse, const b2Vec2& point, bool wake); 0224 0225 /// Apply an angular impulse. 0226 /// @param impulse the angular impulse in units of kg*m*m/s 0227 /// @param wake also wake up the body 0228 void ApplyAngularImpulse(float32 impulse, bool wake); 0229 0230 /// Get the total mass of the body. 0231 /// @return the mass, usually in kilograms (kg). 0232 float32 GetMass() const; 0233 0234 /// Get the rotational inertia of the body about the local origin. 0235 /// @return the rotational inertia, usually in kg-m^2. 0236 float32 GetInertia() const; 0237 0238 /// Get the mass data of the body. 0239 /// @return a struct containing the mass, inertia and center of the body. 0240 void GetMassData(b2MassData* data) const; 0241 0242 /// Set the mass properties to override the mass properties of the fixtures. 0243 /// Note that this changes the center of mass position. 0244 /// Note that creating or destroying fixtures can also alter the mass. 0245 /// This function has no effect if the body isn't dynamic. 0246 /// @param massData the mass properties. 0247 void SetMassData(const b2MassData* data); 0248 0249 /// This resets the mass properties to the sum of the mass properties of the fixtures. 0250 /// This normally does not need to be called unless you called SetMassData to override 0251 /// the mass and you later want to reset the mass. 0252 void ResetMassData(); 0253 0254 /// Get the world coordinates of a point given the local coordinates. 0255 /// @param localPoint a point on the body measured relative the the body's origin. 0256 /// @return the same point expressed in world coordinates. 0257 b2Vec2 GetWorldPoint(const b2Vec2& localPoint) const; 0258 0259 /// Get the world coordinates of a vector given the local coordinates. 0260 /// @param localVector a vector fixed in the body. 0261 /// @return the same vector expressed in world coordinates. 0262 b2Vec2 GetWorldVector(const b2Vec2& localVector) const; 0263 0264 /// Gets a local point relative to the body's origin given a world point. 0265 /// @param a point in world coordinates. 0266 /// @return the corresponding local point relative to the body's origin. 0267 b2Vec2 GetLocalPoint(const b2Vec2& worldPoint) const; 0268 0269 /// Gets a local vector given a world vector. 0270 /// @param a vector in world coordinates. 0271 /// @return the corresponding local vector. 0272 b2Vec2 GetLocalVector(const b2Vec2& worldVector) const; 0273 0274 /// Get the world linear velocity of a world point attached to this body. 0275 /// @param a point in world coordinates. 0276 /// @return the world velocity of a point. 0277 b2Vec2 GetLinearVelocityFromWorldPoint(const b2Vec2& worldPoint) const; 0278 0279 /// Get the world velocity of a local point. 0280 /// @param a point in local coordinates. 0281 /// @return the world velocity of a point. 0282 b2Vec2 GetLinearVelocityFromLocalPoint(const b2Vec2& localPoint) const; 0283 0284 /// Get the linear damping of the body. 0285 float32 GetLinearDamping() const; 0286 0287 /// Set the linear damping of the body. 0288 void SetLinearDamping(float32 linearDamping); 0289 0290 /// Get the angular damping of the body. 0291 float32 GetAngularDamping() const; 0292 0293 /// Set the angular damping of the body. 0294 void SetAngularDamping(float32 angularDamping); 0295 0296 /// Get the gravity scale of the body. 0297 float32 GetGravityScale() const; 0298 0299 /// Set the gravity scale of the body. 0300 void SetGravityScale(float32 scale); 0301 0302 /// Set the type of this body. This may alter the mass and velocity. 0303 void SetType(b2BodyType type); 0304 0305 /// Get the type of this body. 0306 b2BodyType GetType() const; 0307 0308 /// Should this body be treated like a bullet for continuous collision detection? 0309 void SetBullet(bool flag); 0310 0311 /// Is this body treated like a bullet for continuous collision detection? 0312 bool IsBullet() const; 0313 0314 /// You can disable sleeping on this body. If you disable sleeping, the 0315 /// body will be woken. 0316 void SetSleepingAllowed(bool flag); 0317 0318 /// Is this body allowed to sleep 0319 bool IsSleepingAllowed() const; 0320 0321 /// Set the sleep state of the body. A sleeping body has very 0322 /// low CPU cost. 0323 /// @param flag set to true to wake the body, false to put it to sleep. 0324 void SetAwake(bool flag); 0325 0326 /// Get the sleeping state of this body. 0327 /// @return true if the body is awake. 0328 bool IsAwake() const; 0329 0330 /// Set the active state of the body. An inactive body is not 0331 /// simulated and cannot be collided with or woken up. 0332 /// If you pass a flag of true, all fixtures will be added to the 0333 /// broad-phase. 0334 /// If you pass a flag of false, all fixtures will be removed from 0335 /// the broad-phase and all contacts will be destroyed. 0336 /// Fixtures and joints are otherwise unaffected. You may continue 0337 /// to create/destroy fixtures and joints on inactive bodies. 0338 /// Fixtures on an inactive body are implicitly inactive and will 0339 /// not participate in collisions, ray-casts, or queries. 0340 /// Joints connected to an inactive body are implicitly inactive. 0341 /// An inactive body is still owned by a b2World object and remains 0342 /// in the body list. 0343 void SetActive(bool flag); 0344 0345 /// Get the active state of the body. 0346 bool IsActive() const; 0347 0348 /// Set this body to have fixed rotation. This causes the mass 0349 /// to be reset. 0350 void SetFixedRotation(bool flag); 0351 0352 /// Does this body have fixed rotation? 0353 bool IsFixedRotation() const; 0354 0355 /// Get the list of all fixtures attached to this body. 0356 b2Fixture* GetFixtureList(); 0357 const b2Fixture* GetFixtureList() const; 0358 0359 /// Get the list of all joints attached to this body. 0360 b2JointEdge* GetJointList(); 0361 const b2JointEdge* GetJointList() const; 0362 0363 /// Get the list of all contacts attached to this body. 0364 /// @warning this list changes during the time step and you may 0365 /// miss some collisions if you don't use b2ContactListener. 0366 b2ContactEdge* GetContactList(); 0367 const b2ContactEdge* GetContactList() const; 0368 0369 /// Get the next body in the world's body list. 0370 b2Body* GetNext(); 0371 const b2Body* GetNext() const; 0372 0373 /// Get the user data pointer that was provided in the body definition. 0374 void* GetUserData() const; 0375 0376 /// Set the user data. Use this to store your application specific data. 0377 void SetUserData(void* data); 0378 0379 /// Get the parent world of this body. 0380 b2World* GetWorld(); 0381 const b2World* GetWorld() const; 0382 0383 /// Dump this body to a log file 0384 void Dump(); 0385 0386 private: 0387 0388 friend class b2World; 0389 friend class b2Island; 0390 friend class b2ContactManager; 0391 friend class b2ContactSolver; 0392 friend class b2Contact; 0393 0394 friend class b2DistanceJoint; 0395 friend class b2FrictionJoint; 0396 friend class b2GearJoint; 0397 friend class b2MotorJoint; 0398 friend class b2MouseJoint; 0399 friend class b2PrismaticJoint; 0400 friend class b2PulleyJoint; 0401 friend class b2RevoluteJoint; 0402 friend class b2RopeJoint; 0403 friend class b2WeldJoint; 0404 friend class b2WheelJoint; 0405 0406 // m_flags 0407 enum 0408 { 0409 e_islandFlag = 0x0001, 0410 e_awakeFlag = 0x0002, 0411 e_autoSleepFlag = 0x0004, 0412 e_bulletFlag = 0x0008, 0413 e_fixedRotationFlag = 0x0010, 0414 e_activeFlag = 0x0020, 0415 e_toiFlag = 0x0040 0416 }; 0417 0418 b2Body(const b2BodyDef* bd, b2World* world); 0419 ~b2Body(); 0420 0421 void SynchronizeFixtures(); 0422 void SynchronizeTransform(); 0423 0424 // This is used to prevent connected bodies from colliding. 0425 // It may lie, depending on the collideConnected flag. 0426 bool ShouldCollide(const b2Body* other) const; 0427 0428 void Advance(float32 t); 0429 0430 b2BodyType m_type; 0431 0432 uint16 m_flags; 0433 0434 int32 m_islandIndex; 0435 0436 b2Transform m_xf; // the body origin transform 0437 b2Sweep m_sweep; // the swept motion for CCD 0438 0439 b2Vec2 m_linearVelocity; 0440 float32 m_angularVelocity; 0441 0442 b2Vec2 m_force; 0443 float32 m_torque; 0444 0445 b2World* m_world; 0446 b2Body* m_prev; 0447 b2Body* m_next; 0448 0449 b2Fixture* m_fixtureList; 0450 int32 m_fixtureCount; 0451 0452 b2JointEdge* m_jointList; 0453 b2ContactEdge* m_contactList; 0454 0455 float32 m_mass, m_invMass; 0456 0457 // Rotational inertia about the center of mass. 0458 float32 m_I, m_invI; 0459 0460 float32 m_linearDamping; 0461 float32 m_angularDamping; 0462 float32 m_gravityScale; 0463 0464 float32 m_sleepTime; 0465 0466 void* m_userData; 0467 }; 0468 0469 inline b2BodyType b2Body::GetType() const 0470 { 0471 return m_type; 0472 } 0473 0474 inline const b2Transform& b2Body::GetTransform() const 0475 { 0476 return m_xf; 0477 } 0478 0479 inline const b2Vec2& b2Body::GetPosition() const 0480 { 0481 return m_xf.p; 0482 } 0483 0484 inline float32 b2Body::GetAngle() const 0485 { 0486 return m_sweep.a; 0487 } 0488 0489 inline const b2Vec2& b2Body::GetWorldCenter() const 0490 { 0491 return m_sweep.c; 0492 } 0493 0494 inline const b2Vec2& b2Body::GetLocalCenter() const 0495 { 0496 return m_sweep.localCenter; 0497 } 0498 0499 inline void b2Body::SetLinearVelocity(const b2Vec2& v) 0500 { 0501 if (m_type == b2_staticBody) 0502 { 0503 return; 0504 } 0505 0506 if (b2Dot(v,v) > 0.0f) 0507 { 0508 SetAwake(true); 0509 } 0510 0511 m_linearVelocity = v; 0512 } 0513 0514 inline const b2Vec2& b2Body::GetLinearVelocity() const 0515 { 0516 return m_linearVelocity; 0517 } 0518 0519 inline void b2Body::SetAngularVelocity(float32 w) 0520 { 0521 if (m_type == b2_staticBody) 0522 { 0523 return; 0524 } 0525 0526 if (w * w > 0.0f) 0527 { 0528 SetAwake(true); 0529 } 0530 0531 m_angularVelocity = w; 0532 } 0533 0534 inline float32 b2Body::GetAngularVelocity() const 0535 { 0536 return m_angularVelocity; 0537 } 0538 0539 inline float32 b2Body::GetMass() const 0540 { 0541 return m_mass; 0542 } 0543 0544 inline float32 b2Body::GetInertia() const 0545 { 0546 return m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter); 0547 } 0548 0549 inline void b2Body::GetMassData(b2MassData* data) const 0550 { 0551 data->mass = m_mass; 0552 data->I = m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter); 0553 data->center = m_sweep.localCenter; 0554 } 0555 0556 inline b2Vec2 b2Body::GetWorldPoint(const b2Vec2& localPoint) const 0557 { 0558 return b2Mul(m_xf, localPoint); 0559 } 0560 0561 inline b2Vec2 b2Body::GetWorldVector(const b2Vec2& localVector) const 0562 { 0563 return b2Mul(m_xf.q, localVector); 0564 } 0565 0566 inline b2Vec2 b2Body::GetLocalPoint(const b2Vec2& worldPoint) const 0567 { 0568 return b2MulT(m_xf, worldPoint); 0569 } 0570 0571 inline b2Vec2 b2Body::GetLocalVector(const b2Vec2& worldVector) const 0572 { 0573 return b2MulT(m_xf.q, worldVector); 0574 } 0575 0576 inline b2Vec2 b2Body::GetLinearVelocityFromWorldPoint(const b2Vec2& worldPoint) const 0577 { 0578 return m_linearVelocity + b2Cross(m_angularVelocity, worldPoint - m_sweep.c); 0579 } 0580 0581 inline b2Vec2 b2Body::GetLinearVelocityFromLocalPoint(const b2Vec2& localPoint) const 0582 { 0583 return GetLinearVelocityFromWorldPoint(GetWorldPoint(localPoint)); 0584 } 0585 0586 inline float32 b2Body::GetLinearDamping() const 0587 { 0588 return m_linearDamping; 0589 } 0590 0591 inline void b2Body::SetLinearDamping(float32 linearDamping) 0592 { 0593 m_linearDamping = linearDamping; 0594 } 0595 0596 inline float32 b2Body::GetAngularDamping() const 0597 { 0598 return m_angularDamping; 0599 } 0600 0601 inline void b2Body::SetAngularDamping(float32 angularDamping) 0602 { 0603 m_angularDamping = angularDamping; 0604 } 0605 0606 inline float32 b2Body::GetGravityScale() const 0607 { 0608 return m_gravityScale; 0609 } 0610 0611 inline void b2Body::SetGravityScale(float32 scale) 0612 { 0613 m_gravityScale = scale; 0614 } 0615 0616 inline void b2Body::SetBullet(bool flag) 0617 { 0618 if (flag) 0619 { 0620 m_flags |= e_bulletFlag; 0621 } 0622 else 0623 { 0624 m_flags &= ~e_bulletFlag; 0625 } 0626 } 0627 0628 inline bool b2Body::IsBullet() const 0629 { 0630 return (m_flags & e_bulletFlag) == e_bulletFlag; 0631 } 0632 0633 inline void b2Body::SetAwake(bool flag) 0634 { 0635 if (flag) 0636 { 0637 if ((m_flags & e_awakeFlag) == 0) 0638 { 0639 m_flags |= e_awakeFlag; 0640 m_sleepTime = 0.0f; 0641 } 0642 } 0643 else 0644 { 0645 m_flags &= ~e_awakeFlag; 0646 m_sleepTime = 0.0f; 0647 m_linearVelocity.SetZero(); 0648 m_angularVelocity = 0.0f; 0649 m_force.SetZero(); 0650 m_torque = 0.0f; 0651 } 0652 } 0653 0654 inline bool b2Body::IsAwake() const 0655 { 0656 return (m_flags & e_awakeFlag) == e_awakeFlag; 0657 } 0658 0659 inline bool b2Body::IsActive() const 0660 { 0661 return (m_flags & e_activeFlag) == e_activeFlag; 0662 } 0663 0664 inline bool b2Body::IsFixedRotation() const 0665 { 0666 return (m_flags & e_fixedRotationFlag) == e_fixedRotationFlag; 0667 } 0668 0669 inline void b2Body::SetSleepingAllowed(bool flag) 0670 { 0671 if (flag) 0672 { 0673 m_flags |= e_autoSleepFlag; 0674 } 0675 else 0676 { 0677 m_flags &= ~e_autoSleepFlag; 0678 SetAwake(true); 0679 } 0680 } 0681 0682 inline bool b2Body::IsSleepingAllowed() const 0683 { 0684 return (m_flags & e_autoSleepFlag) == e_autoSleepFlag; 0685 } 0686 0687 inline b2Fixture* b2Body::GetFixtureList() 0688 { 0689 return m_fixtureList; 0690 } 0691 0692 inline const b2Fixture* b2Body::GetFixtureList() const 0693 { 0694 return m_fixtureList; 0695 } 0696 0697 inline b2JointEdge* b2Body::GetJointList() 0698 { 0699 return m_jointList; 0700 } 0701 0702 inline const b2JointEdge* b2Body::GetJointList() const 0703 { 0704 return m_jointList; 0705 } 0706 0707 inline b2ContactEdge* b2Body::GetContactList() 0708 { 0709 return m_contactList; 0710 } 0711 0712 inline const b2ContactEdge* b2Body::GetContactList() const 0713 { 0714 return m_contactList; 0715 } 0716 0717 inline b2Body* b2Body::GetNext() 0718 { 0719 return m_next; 0720 } 0721 0722 inline const b2Body* b2Body::GetNext() const 0723 { 0724 return m_next; 0725 } 0726 0727 inline void b2Body::SetUserData(void* data) 0728 { 0729 m_userData = data; 0730 } 0731 0732 inline void* b2Body::GetUserData() const 0733 { 0734 return m_userData; 0735 } 0736 0737 inline void b2Body::ApplyForce(const b2Vec2& force, const b2Vec2& point, bool wake) 0738 { 0739 if (m_type != b2_dynamicBody) 0740 { 0741 return; 0742 } 0743 0744 if (wake && (m_flags & e_awakeFlag) == 0) 0745 { 0746 SetAwake(true); 0747 } 0748 0749 // Don't accumulate a force if the body is sleeping. 0750 if (m_flags & e_awakeFlag) 0751 { 0752 m_force += force; 0753 m_torque += b2Cross(point - m_sweep.c, force); 0754 } 0755 } 0756 0757 inline void b2Body::ApplyForceToCenter(const b2Vec2& force, bool wake) 0758 { 0759 if (m_type != b2_dynamicBody) 0760 { 0761 return; 0762 } 0763 0764 if (wake && (m_flags & e_awakeFlag) == 0) 0765 { 0766 SetAwake(true); 0767 } 0768 0769 // Don't accumulate a force if the body is sleeping 0770 if (m_flags & e_awakeFlag) 0771 { 0772 m_force += force; 0773 } 0774 } 0775 0776 inline void b2Body::ApplyTorque(float32 torque, bool wake) 0777 { 0778 if (m_type != b2_dynamicBody) 0779 { 0780 return; 0781 } 0782 0783 if (wake && (m_flags & e_awakeFlag) == 0) 0784 { 0785 SetAwake(true); 0786 } 0787 0788 // Don't accumulate a force if the body is sleeping 0789 if (m_flags & e_awakeFlag) 0790 { 0791 m_torque += torque; 0792 } 0793 } 0794 0795 inline void b2Body::ApplyLinearImpulse(const b2Vec2& impulse, const b2Vec2& point, bool wake) 0796 { 0797 if (m_type != b2_dynamicBody) 0798 { 0799 return; 0800 } 0801 0802 if (wake && (m_flags & e_awakeFlag) == 0) 0803 { 0804 SetAwake(true); 0805 } 0806 0807 // Don't accumulate velocity if the body is sleeping 0808 if (m_flags & e_awakeFlag) 0809 { 0810 m_linearVelocity += m_invMass * impulse; 0811 m_angularVelocity += m_invI * b2Cross(point - m_sweep.c, impulse); 0812 } 0813 } 0814 0815 inline void b2Body::ApplyAngularImpulse(float32 impulse, bool wake) 0816 { 0817 if (m_type != b2_dynamicBody) 0818 { 0819 return; 0820 } 0821 0822 if (wake && (m_flags & e_awakeFlag) == 0) 0823 { 0824 SetAwake(true); 0825 } 0826 0827 // Don't accumulate velocity if the body is sleeping 0828 if (m_flags & e_awakeFlag) 0829 { 0830 m_angularVelocity += m_invI * impulse; 0831 } 0832 } 0833 0834 inline void b2Body::SynchronizeTransform() 0835 { 0836 m_xf.q.Set(m_sweep.a); 0837 m_xf.p = m_sweep.c - b2Mul(m_xf.q, m_sweep.localCenter); 0838 } 0839 0840 inline void b2Body::Advance(float32 alpha) 0841 { 0842 // Advance to the new safe time. This doesn't sync the broad-phase. 0843 m_sweep.Advance(alpha); 0844 m_sweep.c = m_sweep.c0; 0845 m_sweep.a = m_sweep.a0; 0846 m_xf.q.Set(m_sweep.a); 0847 m_xf.p = m_sweep.c - b2Mul(m_xf.q, m_sweep.localCenter); 0848 } 0849 0850 inline b2World* b2Body::GetWorld() 0851 { 0852 return m_world; 0853 } 0854 0855 inline const b2World* b2Body::GetWorld() const 0856 { 0857 return m_world; 0858 } 0859 0860 #endif