issue #2771: add physics files and entries.

This commit is contained in:
boyu0 2013-09-09 10:29:02 +08:00
parent 563450624f
commit 1d47737f45
17 changed files with 710 additions and 7 deletions

View File

@ -1 +1 @@
fd0dee451420604712c1327679395cd1faca91b6
cbb5290ea17f6020e0249818c08c9d94a17dd073

View File

@ -120,6 +120,7 @@ Node::Node(void)
, _isTransitionFinished(false)
, _updateScriptHandler(0)
, _componentContainer(NULL)
, _scene(nullptr)
{
// set default scheduler and actionManager
Director *director = Director::getInstance();
@ -588,6 +589,7 @@ void Node::addChild(Node *child, int zOrder, int tag)
child->_tag = tag;
child->setParent(this);
child->setScene(_scene);
child->setOrderOfArrival(s_globalOrderOfArrival++);
if( _running )
@ -1271,6 +1273,26 @@ void Node::removeAllComponents()
_componentContainer->removeAll();
}
void Node::setScene(Scene* scene)
{
_scene = scene;
}
Scene* Node::getScene()
{
return _scene;
}
void Node::setPhysicsBody(PhysicsBody* body)
{
_physicsBody = body;
}
PhysicsBody* Node::getPhysicsBody()
{
return _physicsBody;
}
// NodeRGBA
NodeRGBA::NodeRGBA()
: _displayedOpacity(255)

View File

@ -52,6 +52,8 @@ class ActionManager;
class Component;
class Dictionary;
class ComponentContainer;
class Scene;
class PhysicsBody;
/**
* @addtogroup base_nodes
@ -1300,6 +1302,35 @@ public:
*/
virtual void removeAllComponents();
/// @} end of component functions
/// @{
/// @name scene functions
/**
* set the scene the node belongs to
* DO NOT call it manually
*/
virtual void setScene(Scene* scene);
/**
* get the scene the node belongs to
*/
virtual Scene* getScene();
/// @} end of scene functions
/// @{
/// @name physics functions
/**
* set the PhysicsBody that let the node effect with physics
*/
virtual void setPhysicsBody(PhysicsBody* body);
/**
* get the PhysicsBody the node have
*/
PhysicsBody* getPhysicsBody();
/// @} end of physics functions
protected:
/// lazy allocs
@ -1378,6 +1409,9 @@ protected:
ccScriptType _scriptType; ///< type of script binding, lua or javascript
ComponentContainer *_componentContainer; ///< Dictionary of components
Scene* _scene; ///< the scene the node belongs to
PhysicsBody* _physicsBody; ///< the physicsBody the node have
};
@ -1425,6 +1459,7 @@ protected:
Color3B _realColor;
bool _cascadeColorEnabled;
bool _cascadeOpacityEnabled;
};
// end of base_node group

View File

@ -53,7 +53,7 @@ bool Scene::init()
return bRet;
}
Scene *Scene::create()
Scene *Scene::create(bool usePhysics/* = false*/)
{
Scene *pRet = new Scene();
if (pRet && pRet->init())
@ -68,4 +68,21 @@ Scene *Scene::create()
}
}
void Scene::addChild(Node* child)
{
Node::addChild(child);
}
void Scene::addChild(Node* child, int zOrder)
{
Node::addChild(child, zOrder);
}
void Scene::addChild(Node* child, int zOrder, int tag)
{
Node::addChild(child, zOrder, tag);
child->setScene(this);
}
NS_CC_END

View File

@ -31,6 +31,8 @@ THE SOFTWARE.
NS_CC_BEGIN
class PhysicsWorld;
/**
* @addtogroup scene
* @{
@ -50,13 +52,21 @@ class CC_DLL Scene : public Node
{
public:
/** creates a new Scene object */
static Scene *create(void);
static Scene *create(bool usePhysics = false);
Scene();
virtual ~Scene();
bool init();
virtual void addChild(Node* child) override;
virtual void addChild(Node* child, int zOrder) override;
virtual void addChild(Node* child, int zOrder, int tag) override;
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; }
protected:
PhysicsWorld* _physicsWorld;
};
// end of scene group

View File

@ -0,0 +1,24 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCPhysicsBody.h"

View File

@ -0,0 +1,100 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCPHYSICS_BODY_H__
#define __CCPHYSICS_BODY_H__
#include "CCObject.h"
#include "CCGeometry.h"
#include "CCPhysicsSetting.h"
NS_CC_BEGIN
class Node;
class PhysicsWorld;
class PhysicsFixture;
class PhysicsBody : public Object
{
public:
static PhysicsBody* createCircle(Point centre, float radius);
static PhysicsBody* createRectangle(Rect rect);
static PhysicsBody* createPolygon(Array* points);
static PhysicsBody* createEdgeSegment(Point x, Point y);
static PhysicsBody* createEdgeCircle(Point centre, float radius);
static PhysicsBody* createEdgeRectangle(Rect rect);
static PhysicsBody* createEdgePolygon(Array* points);
static PhysicsBody* createEdgeChain(Array* points);
virtual void applyForce(Point force);
virtual void applyForce(Point force, Point point);
virtual void applyImpulse(Point impulse);
virtual void applyImpulse(Point impulse, Point point);
virtual void applyTorque(float torque);
virtual void applyAngularImpulse(float impulse);
void addFixture(PhysicsFixture* fixture);
inline Array* getFixtures() { return _fixtures; }
void removeFixture(PhysicsFixture* fixture);
void removeAllFixtures();
inline PhysicsWorld* getWorld() { return _physicsWorld; }
inline Array* getJoints() { return _joints; }
void setCategoryBitmask(int bitmask);
inline int getCategoryBitmask() { return _categoryBitmask; }
void setContactTestBitmask(int bitmask);
inline int getContactTestBitmask() { return _contactTestBitmask; }
void setCollisionBitmask(int bitmask);
inline int getCollisionBitmask() { return _collisionBitmask; }
protected:
bool init();
protected:
PhysicsBody();
virtual ~PhysicsBody();
private:
float _mass;
float _density;
float _area;
float _friction;
Node* _node;
Point _velocity;
float _angularVelocity;
bool _resting;
int _categoryBitmask;
int _contactTestBitmask;
int _collisionBitmask;
Array* _joints;
Array* _fixtures;
PhysicsWorld* _physicsWorld;
};
NS_CC_END
#endif // __CCPHYSICS_BODY_H__

View File

@ -0,0 +1,23 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

View File

@ -0,0 +1,48 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCPHYSICS_CONTACTDELEGATE_H__
#define __CCPHYSICS_CONTACTDELEGATE_H__
#include "CCObject.h"
#include "CCGeometry.h"
#include "CCPhysicsSetting.h"
NS_CC_BEGIN
class PhysicsBody;
class PhysicsContactDelegate : public Object
{
public:
virtual void onContactBegin(PhysicsBody* bodyA, PhysicsBody* bodyB, float collisionImpulse, Point contactPoint);
virtual void onContactEnd(PhysicsBody* bodyA, PhysicsBody* bodyB, float collisionImpulse, Point contactPoint);
protected:
PhysicsContactDelegate();
virtual ~PhysicsContactDelegate();
};
NS_CC_END
#endif //__CCPHYSICS_CONTACTDELEGATE_H__

View File

@ -0,0 +1,23 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

View File

@ -0,0 +1,59 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCPHYSICS_FIXTURE_H__
#define __CCPHYSICS_FIXTURE_H__
#include "CCObject.h"
#include "CCGeometry.h"
#include "CCPhysicsSetting.h"
NS_CC_BEGIN
class PhysicsFixture : public Object
{
public:
static PhysicsFixture* createCircle(Point centre, float radius);
static PhysicsFixture* createRectangle(Rect rect);
static PhysicsFixture* createPolygon(Array* points);
static PhysicsFixture* createEdgeSegment(Point x, Point y);
static PhysicsFixture* createEdgeCircle(Point centre, float radius);
static PhysicsFixture* createEdgeRectangle(Rect rect);
static PhysicsFixture* createEdgePolygon(Array* points);
protected:
bool init();
protected:
PhysicsFixture();
virtual ~PhysicsFixture();
protected:
float _density;
float _friction;
};
NS_CC_END
#endif // __CCPHYSICS_FIXTURE_H__

View File

@ -0,0 +1,23 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

View File

@ -0,0 +1,114 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCPHYSICS_JOINT_H__
#define __CCPHYSICS_JOINT_H__
#include "CCObject.h"
#include "CCGeometry.h"
#include "CCPhysicsSetting.h"
NS_CC_BEGIN
class PhysicsBody;
class PhysicsJoint : public Object
{
protected:
PhysicsJoint();
virtual ~PhysicsJoint();
private:
PhysicsBody* _bodyA;
PhysicsBody* _bodyB;
};
class PhysicsJointFixed : public PhysicsJoint
{
public:
PhysicsJointFixed* create();
protected:
bool init();
protected:
PhysicsJointFixed();
~PhysicsJointFixed();
};
class PhysicsJointSliding : public PhysicsJoint
{
public:
PhysicsJointSliding* create();
protected:
bool init();
protected:
PhysicsJointSliding();
~PhysicsJointSliding();
};
class PhysicsJointSpring : public PhysicsJoint
{
public:
PhysicsJointSpring* create();
protected:
bool init();
protected:
PhysicsJointSpring();
~PhysicsJointSpring();
};
class PhysicsJointLimit : public PhysicsJoint
{
public:
PhysicsJointLimit* create();
protected:
bool init();
protected:
PhysicsJointLimit();
~PhysicsJointLimit();
};
class PhysicsJointPin : public PhysicsJoint
{
public:
PhysicsJointPin* create();
protected:
bool init();
protected:
PhysicsJointPin();
~PhysicsJointPin();
};
NS_CC_END
#endif // __CCPHYSICS_JOINT_H__

View File

@ -0,0 +1,40 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCPHYSICS_SETTING_H__
#define __CCPHYSICS_SETTING_H__
#define CC_PHYSICS_UNKNOWN 0
#define CC_PHYSICS_BOX2D 1
#define CC_PHYSICS_CHIPMUNK 2
#define CC_PHYSICS_ENGINE CC_PHYSICS_CHIPMUNK
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
#include "Box2D.h"
#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
#include "chipmunk.h"
#endif
#endif // __CCPHYSICS_SETTING_H__

View File

@ -0,0 +1,93 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCPhysicsWorld.h"
NS_CC_BEGIN
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
class PhysicsWorldInfo
{
public:
cpSpace* space;
public:
PhysicsWorldInfo();
~PhysicsWorldInfo();
};
PhysicsWorldInfo::PhysicsWorldInfo()
{
space = cpSpaceNew();
}
PhysicsWorldInfo::~PhysicsWorldInfo()
{
cpSpaceFree(space);
}
bool PhysicsWorld::init()
{
_worldInfo = new PhysicsWorldInfo();
cpSpaceSetGravity(_worldInfo->space, cpv(_gravity.x, _gravity.y));
return true;
}
#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
struct PhysicsInfo
{
};
#endif
PhysicsWorld* PhysicsWorld::create()
{
PhysicsWorld * physicsWorld = new PhysicsWorld();
if(physicsWorld && physicsWorld->init())
{
physicsWorld->autorelease();
return physicsWorld;
}
CC_SAFE_DELETE(physicsWorld);
return NULL;
}
PhysicsWorld::PhysicsWorld() :
_gravity(Point(0, -9.8)),
_speed(1.0)
{
}
PhysicsWorld::~PhysicsWorld()
{
CC_SAFE_DELETE(_worldInfo);
}
NS_CC_END

View File

@ -0,0 +1,72 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCPHYSICS_WORLD_H__
#define __CCPHYSICS_WORLD_H__
#include "CCObject.h"
#include "CCGeometry.h"
#include "CCPhysicsSetting.h"
NS_CC_BEGIN
class PhysicsBody;
class PhysicsJoint;
class PhysicsWorldInfo;
class PhysicsContactDelegate;
class PhysicsWorld : public Object
{
public:
static PhysicsWorld* create();
void addChild(PhysicsBody* body);
void addJoint(PhysicsJoint* joint);
void removeJoint(PhysicsJoint* joint);
void removeAllJoints();
Array* bodysAlongRay(Point start, Point end);
Array* bodysAtPoint(Point point);
Array* bodysInRect(Rect rect);
Array* getAllBody();
void registerContactDelegate(PhysicsContactDelegate* delegate);
protected:
bool init();
protected:
Point _gravity;
float _speed;
class PhysicsWorldInfo* _worldInfo;
protected:
PhysicsWorld();
virtual ~PhysicsWorld();
};
NS_CC_END
#endif // __CCPHYSICS_WORLD_H__

View File

@ -531,7 +531,7 @@ void TestBox2DDetector::onEnter()
armature2->setPosition(Point(VisibleRect::right().x - 30, VisibleRect::left().y));
addChild(armature2);
PhysicsWorld::sharedPhysicsWorld()->BoneColliderSignal.connect(this, &TestBox2DDetector::onHit);
extension::armature::PhysicsWorld::sharedPhysicsWorld()->BoneColliderSignal.connect(this, &TestBox2DDetector::onHit);
}
std::string TestBox2DDetector::title()
{
@ -543,7 +543,7 @@ void TestBox2DDetector::draw()
kmGLPushMatrix();
PhysicsWorld::sharedPhysicsWorld()->drawDebug();
extension::armature::PhysicsWorld::sharedPhysicsWorld()->drawDebug();
kmGLPopMatrix();
@ -551,7 +551,7 @@ void TestBox2DDetector::draw()
void TestBox2DDetector::update(float delta)
{
armature2->setVisible(true);
PhysicsWorld::sharedPhysicsWorld()->update(delta);
extension::armature::PhysicsWorld::sharedPhysicsWorld()->update(delta);
}
void TestBox2DDetector::onHit(Bone *bone, Bone *bone2)
{