Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 class b2Fixture;
00030
00032 struct b2Filter
00033 {
00034 b2Filter()
00035 {
00036 categoryBits = 0x0001;
00037 maskBits = 0xFFFF;
00038 groupIndex = 0;
00039 }
00040
00042 uint16 categoryBits;
00043
00046 uint16 maskBits;
00047
00051 int16 groupIndex;
00052 };
00053
00056 struct b2FixtureDef
00057 {
00059 b2FixtureDef()
00060 {
00061 shape = NULL;
00062 userData = NULL;
00063 friction = 0.2f;
00064 restitution = 0.0f;
00065 density = 0.0f;
00066 isSensor = false;
00067 }
00068
00071 const b2Shape* shape;
00072
00074 void* userData;
00075
00077 float32 friction;
00078
00080 float32 restitution;
00081
00083 float32 density;
00084
00087 bool isSensor;
00088
00090 b2Filter filter;
00091 };
00092
00094 struct b2FixtureProxy
00095 {
00096 b2AABB aabb;
00097 b2Fixture* fixture;
00098 int32 childIndex;
00099 int32 proxyId;
00100 };
00101
00107 class b2Fixture
00108 {
00109 public:
00112 b2Shape::Type GetType() const;
00113
00117 b2Shape* GetShape();
00118 const b2Shape* GetShape() const;
00119
00121 void SetSensor(bool sensor);
00122
00125 bool IsSensor() const;
00126
00130 void SetFilterData(const b2Filter& filter);
00131
00133 const b2Filter& GetFilterData() const;
00134
00136 void Refilter();
00137
00140 b2Body* GetBody();
00141 const b2Body* GetBody() const;
00142
00145 b2Fixture* GetNext();
00146 const b2Fixture* GetNext() const;
00147
00150 void* GetUserData() const;
00151
00153 void SetUserData(void* data);
00154
00157 bool TestPoint(const b2Vec2& p) const;
00158
00162 bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, int32 childIndex) const;
00163
00167 void GetMassData(b2MassData* massData) const;
00168
00171 void SetDensity(float32 density);
00172
00174 float32 GetDensity() const;
00175
00177 float32 GetFriction() const;
00178
00181 void SetFriction(float32 friction);
00182
00184 float32 GetRestitution() const;
00185
00188 void SetRestitution(float32 restitution);
00189
00193 const b2AABB& GetAABB(int32 childIndex) const;
00194
00196 void Dump(int32 bodyIndex);
00197
00198 protected:
00199
00200 friend class b2Body;
00201 friend class b2World;
00202 friend class b2Contact;
00203 friend class b2ContactManager;
00204
00205 b2Fixture();
00206
00207
00208
00209 void Create(b2BlockAllocator* allocator, b2Body* body, const b2FixtureDef* def);
00210 void Destroy(b2BlockAllocator* allocator);
00211
00212
00213 void CreateProxies(b2BroadPhase* broadPhase, const b2Transform& xf);
00214 void DestroyProxies(b2BroadPhase* broadPhase);
00215
00216 void Synchronize(b2BroadPhase* broadPhase, const b2Transform& xf1, const b2Transform& xf2);
00217
00218 float32 m_density;
00219
00220 b2Fixture* m_next;
00221 b2Body* m_body;
00222
00223 b2Shape* m_shape;
00224
00225 float32 m_friction;
00226 float32 m_restitution;
00227
00228 b2FixtureProxy* m_proxies;
00229 int32 m_proxyCount;
00230
00231 b2Filter m_filter;
00232
00233 bool m_isSensor;
00234
00235 void* m_userData;
00236 };
00237
00238 inline b2Shape::Type b2Fixture::GetType() const
00239 {
00240 return m_shape->GetType();
00241 }
00242
00243 inline b2Shape* b2Fixture::GetShape()
00244 {
00245 return m_shape;
00246 }
00247
00248 inline const b2Shape* b2Fixture::GetShape() const
00249 {
00250 return m_shape;
00251 }
00252
00253 inline bool b2Fixture::IsSensor() const
00254 {
00255 return m_isSensor;
00256 }
00257
00258 inline const b2Filter& b2Fixture::GetFilterData() const
00259 {
00260 return m_filter;
00261 }
00262
00263 inline void* b2Fixture::GetUserData() const
00264 {
00265 return m_userData;
00266 }
00267
00268 inline void b2Fixture::SetUserData(void* data)
00269 {
00270 m_userData = data;
00271 }
00272
00273 inline b2Body* b2Fixture::GetBody()
00274 {
00275 return m_body;
00276 }
00277
00278 inline const b2Body* b2Fixture::GetBody() const
00279 {
00280 return m_body;
00281 }
00282
00283 inline b2Fixture* b2Fixture::GetNext()
00284 {
00285 return m_next;
00286 }
00287
00288 inline const b2Fixture* b2Fixture::GetNext() const
00289 {
00290 return m_next;
00291 }
00292
00293 inline void b2Fixture::SetDensity(float32 density)
00294 {
00295 b2Assert(b2IsValid(density) && density >= 0.0f);
00296 m_density = density;
00297 }
00298
00299 inline float32 b2Fixture::GetDensity() const
00300 {
00301 return m_density;
00302 }
00303
00304 inline float32 b2Fixture::GetFriction() const
00305 {
00306 return m_friction;
00307 }
00308
00309 inline void b2Fixture::SetFriction(float32 friction)
00310 {
00311 m_friction = friction;
00312 }
00313
00314 inline float32 b2Fixture::GetRestitution() const
00315 {
00316 return m_restitution;
00317 }
00318
00319 inline void b2Fixture::SetRestitution(float32 restitution)
00320 {
00321 m_restitution = restitution;
00322 }
00323
00324 inline bool b2Fixture::TestPoint(const b2Vec2& p) const
00325 {
00326 return m_shape->TestPoint(m_body->GetTransform(), p);
00327 }
00328
00329 inline bool b2Fixture::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, int32 childIndex) const
00330 {
00331 return m_shape->RayCast(output, input, m_body->GetTransform(), childIndex);
00332 }
00333
00334 inline void b2Fixture::GetMassData(b2MassData* massData) const
00335 {
00336 m_shape->ComputeMass(massData, m_density);
00337 }
00338
00339 inline const b2AABB& b2Fixture::GetAABB(int32 childIndex) const
00340 {
00341 b2Assert(0 <= childIndex && childIndex < m_proxyCount);
00342 return m_proxies[childIndex].aabb;
00343 }
00344
00345 #endif