- Main Page
- Classes
- Files

- File List
- File Members

# Box2D/Box2D/Dynamics/b2Fixture.h

Go to the documentation of this file.

    00001 /*
    00002 * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
    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_FIXTURE_H
    00020 #define B2_FIXTURE_H
    00021
    00022 #include <Box2D/Dynamics/b2Body.h>
    00023 #include <Box2D/Collision/b2Collision.h>
    00024 #include <Box2D/Collision/Shapes/b2Shape.h>
    00025
    00026 class b2BlockAllocator;
    00027 class b2Body;
    00028 class b2BroadPhase;
    00029
    00031 struct b2Filter
    00032 {
    00034         uint16 categoryBits;
    00035
    00038         uint16 maskBits;
    00039
    00043         int16 groupIndex;
    00044 };
    00045
    00048 struct b2FixtureDef
    00049 {
    00051         b2FixtureDef()
    00052         {
    00053                 shape = NULL;
    00054                 userData = NULL;
    00055                 friction = 0.2f;
    00056                 restitution = 0.0f;
    00057                 density = 0.0f;
    00058                 filter.categoryBits = 0x0001;
    00059                 filter.maskBits = 0xFFFF;
    00060                 filter.groupIndex = 0;
    00061                 isSensor = false;
    00062         }
    00063
    00064         virtual ~b2FixtureDef() {}
    00065
    00068         const b2Shape* shape;
    00069
    00071         void* userData;
    00072
    00074         float32 friction;
    00075
    00077         float32 restitution;
    00078
    00080         float32 density;
    00081
    00084         bool isSensor;
    00085
    00087         b2Filter filter;
    00088 };
    00089
    00090
    00096 class b2Fixture
    00097 {
    00098 public:
    00101         b2Shape::Type GetType() const;
    00102
    00106         b2Shape* GetShape();
    00107         const b2Shape* GetShape() const;
    00108
    00110         void SetSensor(bool sensor);
    00111
    00114         bool IsSensor() const;
    00115
    00118         void SetFilterData(const b2Filter& filter);
    00119
    00121         const b2Filter& GetFilterData() const;
    00122
    00125         b2Body* GetBody();
    00126         const b2Body* GetBody() const;
    00127
    00130         b2Fixture* GetNext();
    00131         const b2Fixture* GetNext() const;
    00132
    00135         void* GetUserData() const;
    00136
    00138         void SetUserData(void* data);
    00139
    00143         bool TestPoint(const b2Vec2& p) const;
    00144
    00148         bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const;
    00149
    00153         void GetMassData(b2MassData* massData) const;
    00154
    00157         void SetDensity(float32 density);
    00158
    00160         float32 GetDensity() const;
    00161
    00163         float32 GetFriction() const;
    00164
    00166         void SetFriction(float32 friction);
    00167
    00169         float32 GetRestitution() const;
    00170
    00172         void SetRestitution(float32 restitution);
    00173
    00177         const b2AABB& GetAABB() const;
    00178
    00179 protected:
    00180
    00181         friend class b2Body;
    00182         friend class b2World;
    00183         friend class b2Contact;
    00184         friend class b2ContactManager;
    00185
    00186         b2Fixture();
    00187         ~b2Fixture();
    00188
    00189         // We need separation create/destroy functions from the constructor/destructor because
    00190         // the destructor cannot access the allocator (no destructor arguments allowed by C++).
    00191         void Create(b2BlockAllocator* allocator, b2Body* body, const b2FixtureDef* def);
    00192         void Destroy(b2BlockAllocator* allocator);
    00193
    00194         // These support body activation/deactivation.
    00195         void CreateProxy(b2BroadPhase* broadPhase, const b2Transform& xf);
    00196         void DestroyProxy(b2BroadPhase* broadPhase);
    00197
    00198         void Synchronize(b2BroadPhase* broadPhase, const b2Transform& xf1, const b2Transform& xf2);
    00199
    00200         b2AABB m_aabb;
    00201
    00202         float32 m_density;
    00203
    00204         b2Fixture* m_next;
    00205         b2Body* m_body;
    00206
    00207         b2Shape* m_shape;
    00208
    00209         float32 m_friction;
    00210         float32 m_restitution;
    00211
    00212         int32 m_proxyId;
    00213         b2Filter m_filter;
    00214
    00215         bool m_isSensor;
    00216
    00217         void* m_userData;
    00218 };
    00219
    00220 inline b2Shape::Type b2Fixture::GetType() const
    00221 {
    00222         return m_shape->GetType();
    00223 }
    00224
    00225 inline b2Shape* b2Fixture::GetShape()
    00226 {
    00227         return m_shape;
    00228 }
    00229
    00230 inline const b2Shape* b2Fixture::GetShape() const
    00231 {
    00232         return m_shape;
    00233 }
    00234
    00235 inline bool b2Fixture::IsSensor() const
    00236 {
    00237         return m_isSensor;
    00238 }
    00239
    00240 inline const b2Filter& b2Fixture::GetFilterData() const
    00241 {
    00242         return m_filter;
    00243 }
    00244
    00245 inline void* b2Fixture::GetUserData() const
    00246 {
    00247         return m_userData;
    00248 }
    00249
    00250 inline void b2Fixture::SetUserData(void* data)
    00251 {
    00252         m_userData = data;
    00253 }
    00254
    00255 inline b2Body* b2Fixture::GetBody()
    00256 {
    00257         return m_body;
    00258 }
    00259
    00260 inline const b2Body* b2Fixture::GetBody() const
    00261 {
    00262         return m_body;
    00263 }
    00264
    00265 inline b2Fixture* b2Fixture::GetNext()
    00266 {
    00267         return m_next;
    00268 }
    00269
    00270 inline const b2Fixture* b2Fixture::GetNext() const
    00271 {
    00272         return m_next;
    00273 }
    00274
    00275 inline void b2Fixture::SetDensity(float32 density)
    00276 {
    00277         b2Assert(b2IsValid(density) && density >= 0.0f);
    00278         m_density = density;
    00279 }
    00280
    00281 inline float32 b2Fixture::GetDensity() const
    00282 {
    00283         return m_density;
    00284 }
    00285
    00286 inline float32 b2Fixture::GetFriction() const
    00287 {
    00288         return m_friction;
    00289 }
    00290
    00291 inline void b2Fixture::SetFriction(float32 friction)
    00292 {
    00293         m_friction = friction;
    00294 }
    00295
    00296 inline float32 b2Fixture::GetRestitution() const
    00297 {
    00298         return m_restitution;
    00299 }
    00300
    00301 inline void b2Fixture::SetRestitution(float32 restitution)
    00302 {
    00303         m_restitution = restitution;
    00304 }
    00305
    00306 inline bool b2Fixture::TestPoint(const b2Vec2& p) const
    00307 {
    00308         return m_shape->TestPoint(m_body->GetTransform(), p);
    00309 }
    00310
    00311 inline bool b2Fixture::RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const
    00312 {
    00313         return m_shape->RayCast(output, input, m_body->GetTransform());
    00314 }
    00315
    00316 inline void b2Fixture::GetMassData(b2MassData* massData) const
    00317 {
    00318         m_shape->ComputeMass(massData, m_density);
    00319 }
    00320
    00321 inline const b2AABB& b2Fixture::GetAABB() const
    00322 {
    00323         return m_aabb;
    00324 }
    00325
    00326 #endif