Box2D: Box2D/Box2D/Dynamics/b2Island.h Source File

- Main Page
- Classes
- Files

- File List
- File Members

# Box2D/Box2D/Dynamics/b2Island.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_ISLAND_H
    00020 #define B2_ISLAND_H
    00021
    00022 #include <Box2D/Common/b2Math.h>
    00023 #include <Box2D/Dynamics/b2Body.h>
    00024 #include <Box2D/Dynamics/b2TimeStep.h>
    00025
    00026 class b2Contact;
    00027 class b2Joint;
    00028 class b2StackAllocator;
    00029 class b2ContactListener;
    00030 struct b2ContactConstraint;
    00031
    00033 struct b2Position
    00034 {
    00035         b2Vec2 x;
    00036         float32 a;
    00037 };
    00038
    00040 struct b2Velocity
    00041 {
    00042         b2Vec2 v;
    00043         float32 w;
    00044 };
    00045
    00047 class b2Island
    00048 {
    00049 public:
    00050         b2Island(int32 bodyCapacity, int32 contactCapacity, int32 jointCapacity,
    00051                         b2StackAllocator* allocator, b2ContactListener* listener);
    00052         ~b2Island();
    00053
    00054         void Clear()
    00055         {
    00056                 m_bodyCount = 0;
    00057                 m_contactCount = 0;
    00058                 m_jointCount = 0;
    00059         }
    00060
    00061         void Solve(const b2TimeStep& step, const b2Vec2& gravity, bool allowSleep);
    00062
    00063         void Add(b2Body* body)
    00064         {
    00065                 b2Assert(m_bodyCount < m_bodyCapacity);
    00066                 body->m_islandIndex = m_bodyCount;
    00067                 m_bodies[m_bodyCount++] = body;
    00068         }
    00069
    00070         void Add(b2Contact* contact)
    00071         {
    00072                 b2Assert(m_contactCount < m_contactCapacity);
    00073                 m_contacts[m_contactCount++] = contact;
    00074         }
    00075
    00076         void Add(b2Joint* joint)
    00077         {
    00078                 b2Assert(m_jointCount < m_jointCapacity);
    00079                 m_joints[m_jointCount++] = joint;
    00080         }
    00081
    00082         void Report(const b2ContactConstraint* constraints);
    00083
    00084         b2StackAllocator* m_allocator;
    00085         b2ContactListener* m_listener;
    00086
    00087         b2Body** m_bodies;
    00088         b2Contact** m_contacts;
    00089         b2Joint** m_joints;
    00090
    00091         b2Position* m_positions;
    00092         b2Velocity* m_velocities;
    00093
    00094         int32 m_bodyCount;
    00095         int32 m_jointCount;
    00096         int32 m_contactCount;
    00097
    00098         int32 m_bodyCapacity;
    00099         int32 m_contactCapacity;
    00100         int32 m_jointCapacity;
    00101
    00102         int32 m_positionIterationCount;
    00103 };
    00104
    00105 #endif