2010-10-23 24 views
3

所以我有:Box2D的b2World類


class bc_Game 
{ 
public: 
//blah 
private: 
b2World world; 
}; 

bc_Game::bc_Game() 
{ 
//blah, defining variables used 
world = b2World(gravity, sleep); 
} 
 

現在,我只是得到 錯誤:調用 'b2World :: b2World()' 注意到沒有匹配功能:考生:b2World: :b2World(常量b2Vec2 &,布爾) 注:b2World :: b2World(常量b2World &)

我有不知道如何得到這個工作,我已經試過的std :: auto_ptr的,新b2World,我能想到的一切。

b2World是Box2D中的一部分,但在這裏不用...


/* 
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com 
* 
* This software is provided 'as-is', without any express or implied 
* warranty. In no event will the authors be held liable for any damages 
* arising from the use of this software. 
* Permission is granted to anyone to use this software for any purpose, 
* including commercial applications, and to alter it and redistribute it 
* freely, subject to the following restrictions: 
* 1. The origin of this software must not be misrepresented; you must not 
* claim that you wrote the original software. If you use this software 
* in a product, an acknowledgment in the product documentation would be 
* appreciated but is not required. 
* 2. Altered source versions must be plainly marked as such, and must not be 
* misrepresented as being the original software. 
* 3. This notice may not be removed or altered from any source distribution. 
*/ 

#ifndef B2_WORLD_H 
#define B2_WORLD_H 

#include 
#include 
#include 
#include 
#include 

struct b2AABB; 
struct b2BodyDef; 
struct b2JointDef; 
struct b2TimeStep; 
class b2Body; 
class b2Fixture; 
class b2Joint; 

/// The world class manages all physics entities, dynamic simulation, 
/// and asynchronous queries. The world also contains efficient memory 
/// management facilities. 
class b2World 
{ 
public: 
    /// Construct a world object. 
    /// @param gravity the world gravity vector. 
    /// @param doSleep improve performance by not simulating inactive bodies. 
    b2World(const b2Vec2& gravity, bool doSleep); 

    /// Destruct the world. All physics entities are destroyed and all heap memory is released. 
    ~b2World(); 

    /// Register a destruction listener. The listener is owned by you and must 
    /// remain in scope. 
    void SetDestructionListener(b2DestructionListener* listener); 

    /// Register a contact filter to provide specific control over collision. 
    /// Otherwise the default filter is used (b2_defaultFilter). The listener is 
    /// owned by you and must remain in scope. 
    void SetContactFilter(b2ContactFilter* filter); 

    /// Register a contact event listener. The listener is owned by you and must 
    /// remain in scope. 
    void SetContactListener(b2ContactListener* listener); 

    /// Register a routine for debug drawing. The debug draw functions are called 
    /// inside with b2World::DrawDebugData method. The debug draw object is owned 
    /// by you and must remain in scope. 
    void SetDebugDraw(b2DebugDraw* debugDraw); 

    /// Create a rigid body given a definition. No reference to the definition 
    /// is retained. 
    /// @warning This function is locked during callbacks. 
    b2Body* CreateBody(const b2BodyDef* def); 

    /// Destroy a rigid body given a definition. No reference to the definition 
    /// is retained. This function is locked during callbacks. 
    /// @warning This automatically deletes all associated shapes and joints. 
    /// @warning This function is locked during callbacks. 
    void DestroyBody(b2Body* body); 

    /// Create a joint to constrain bodies together. No reference to the definition 
    /// is retained. This may cause the connected bodies to cease colliding. 
    /// @warning This function is locked during callbacks. 
    b2Joint* CreateJoint(const b2JointDef* def); 

    /// Destroy a joint. This may cause the connected bodies to begin colliding. 
    /// @warning This function is locked during callbacks. 
    void DestroyJoint(b2Joint* joint); 

    /// Take a time step. This performs collision detection, integration, 
    /// and constraint solution. 
    /// @param timeStep the amount of time to simulate, this should not vary. 
    /// @param velocityIterations for the velocity constraint solver. 
    /// @param positionIterations for the position constraint solver. 
    void Step( float32 timeStep, 
       int32 velocityIterations, 
       int32 positionIterations); 

    /// Call this after you are done with time steps to clear the forces. You normally 
    /// call this after each call to Step, unless you are performing sub-steps. By default, 
    /// forces will be automatically cleared, so you don't need to call this function. 
    /// @see SetAutoClearForces 
    void ClearForces(); 

    /// Call this to draw shapes and other debug draw data. 
    void DrawDebugData(); 

    /// Query the world for all fixtures that potentially overlap the 
    /// provided AABB. 
    /// @param callback a user implemented callback class. 
    /// @param aabb the query box. 
    void QueryAABB(b2QueryCallback* callback, const b2AABB& aabb) const; 

    /// Ray-cast the world for all fixtures in the path of the ray. Your callback 
    /// controls whether you get the closest point, any point, or n-points. 
    /// The ray-cast ignores shapes that contain the starting point. 
    /// @param callback a user implemented callback class. 
    /// @param point1 the ray starting point 
    /// @param point2 the ray ending point 
    void RayCast(b2RayCastCallback* callback, const b2Vec2& point1, const b2Vec2& point2) const; 

    /// Get the world body list. With the returned body, use b2Body::GetNext to get 
    /// the next body in the world list. A NULL body indicates the end of the list. 
    /// @return the head of the world body list. 
    b2Body* GetBodyList(); 

    /// Get the world joint list. With the returned joint, use b2Joint::GetNext to get 
    /// the next joint in the world list. A NULL joint indicates the end of the list. 
    /// @return the head of the world joint list. 
    b2Joint* GetJointList(); 

    /// Get the world contact list. With the returned contact, use b2Contact::GetNext to get 
    /// the next contact in the world list. A NULL contact indicates the end of the list. 
    /// @return the head of the world contact list. 
    /// @warning contacts are 
    b2Contact* GetContactList(); 

    /// Enable/disable warm starting. For testing. 
    void SetWarmStarting(bool flag) { m_warmStarting = flag; } 

    /// Enable/disable continuous physics. For testing. 
    void SetContinuousPhysics(bool flag) { m_continuousPhysics = flag; } 

    /// Get the number of broad-phase proxies. 
    int32 GetProxyCount() const; 

    /// Get the number of bodies. 
    int32 GetBodyCount() const; 

    /// Get the number of joints. 
    int32 GetJointCount() const; 

    /// Get the number of contacts (each may have 0 or more contact points). 
    int32 GetContactCount() const; 

    /// Change the global gravity vector. 
    void SetGravity(const b2Vec2& gravity); 

    /// Get the global gravity vector. 
    b2Vec2 GetGravity() const; 

    /// Is the world locked (in the middle of a time step). 
    bool IsLocked() const; 

    /// Set flag to control automatic clearing of forces after each time step. 
    void SetAutoClearForces(bool flag); 

    /// Get the flag that controls automatic clearing of forces after each time step. 
    bool GetAutoClearForces() const; 

private: 

    // m_flags 
    enum 
    { 
     e_newFixture = 0x0001, 
     e_locked  = 0x0002, 
     e_clearForces = 0x0004, 
    }; 

    friend class b2Body; 
    friend class b2ContactManager; 
    friend class b2Controller; 

    void Solve(const b2TimeStep& step); 
    void SolveTOI(); 
    void SolveTOI(b2Body* body); 

    void DrawJoint(b2Joint* joint); 
    void DrawShape(b2Fixture* shape, const b2Transform& xf, const b2Color& color); 

    b2BlockAllocator m_blockAllocator; 
    b2StackAllocator m_stackAllocator; 

    int32 m_flags; 

    b2ContactManager m_contactManager; 

    b2Body* m_bodyList; 
    b2Joint* m_jointList; 

    int32 m_bodyCount; 
    int32 m_jointCount; 

    b2Vec2 m_gravity; 
    bool m_allowSleep; 

    b2Body* m_groundBody; 

    b2DestructionListener* m_destructionListener; 
    b2DebugDraw* m_debugDraw; 

    // This is used to compute the time step ratio to 
    // support a variable time step. 
    float32 m_inv_dt0; 

    // This is for debugging the solver. 
    bool m_warmStarting; 

    // This is for debugging the solver. 
    bool m_continuousPhysics; 
}; 

inline b2Body* b2World::GetBodyList() 
{ 
    return m_bodyList; 
} 

inline b2Joint* b2World::GetJointList() 
{ 
    return m_jointList; 
} 

inline b2Contact* b2World::GetContactList() 
{ 
    return m_contactManager.m_contactList; 
} 

inline int32 b2World::GetBodyCount() const 
{ 
    return m_bodyCount; 
} 

inline int32 b2World::GetJointCount() const 
{ 
    return m_jointCount; 
} 

inline int32 b2World::GetContactCount() const 
{ 
    return m_contactManager.m_contactCount; 
} 

inline void b2World::SetGravity(const b2Vec2& gravity) 
{ 
    m_gravity = gravity; 
} 

inline b2Vec2 b2World::GetGravity() const 
{ 
    return m_gravity; 
} 

inline bool b2World::IsLocked() const 
{ 
    return (m_flags & e_locked) == e_locked; 
} 

inline void b2World::SetAutoClearForces(bool flag) 
{ 
    if (flag) 
    { 
     m_flags |= e_clearForces; 
    } 
    else 
    { 
     m_flags &= ~e_clearForces; 
    } 
} 

/// Get the flag that controls automatic clearing of forces after each time step. 
inline bool b2World::GetAutoClearForces() const 
{ 
    return (m_flags & e_clearForces) == e_clearForces; 
} 

#endif 

回答

1

您需要可以提供一個默認的構造函數b2World,或者你需要在初始化列表中初始化世界:

bc_Game::bc_Game() :world(gravity, sleep) 
{ 
} 

雖然這也需要重力和睡眠。

+0

如果我這樣做,但我得到多個未定義的引用b2World()和〜b2World – Chris 2010-10-24 00:43:35

+0

@Chris - 如果你做什麼?提供一個默認的構造函數?讓我看看你的代碼。 b2World的頭文件和實現。 – 2010-10-24 00:48:50

+0

class bc_Game { public: bc_Game(b2Vec2 grav,bool sleep); private: bool bv_Running; bool bv_fullscreen; bool bv_firstrun; // Box2d變量 float box_timestep; int velocityIter; int posIter; b2Vec2 box_gravity; bool box_sleep; b2World box_world; }; – Chris 2010-10-24 01:00:05

5

Box2D最近更新。我正在重申一個教程,並注意到了這一點。但是,如果您查看頭文件,您會注意到新的默認構造函數僅接受重力。刪除睡眠變量。

YourVariable = new b2World(gravity);

會解決這個問題。我不知道對方正在做什麼,它們似乎重新定義了實際的頭部...這對於純粹的骨架引擎來說是個好主意,但是Box2D不是骨架引擎,它的功能是完全定義的,不要試圖重寫它作爲一個修復,除非你知道你的物理