mirror of https://github.com/axmolengine/axmol.git
Merge pull request #2231 from sbc100/physics_fixes
fixed #2055: Physics fixes. 1) Fix CCPhysicsSprite getPosition variants … CCPhysicsSprite was overriding only some of the getPosition methods on a node resulting in, for example, getPositionX and getPositionY not working for physics nodes. This change also makes this overloads shared between box2d and chipmunk implementations. 2) Fix typo in make-all-linux-project.sh 3) The ENABLE_BOX2D/ENABLE_CHIPMUNK defines were previously hardcoded in the Makefiles. Now you get chipmunk by default on both platforms and can enble Box2D by setting USE_BOX2D in your environment. Also remove erroneous -D__CC_PLATFORM_FILEUTILS_CPP__ and -D__CC_PLATFORM_IMAGE_CPP__ from linux Makefiles. These should never be defined globally like this.
This commit is contained in:
commit
bf4344a53f
|
@ -308,21 +308,21 @@ public:
|
|||
* @param x X coordinate for position
|
||||
* @param y Y coordinate for position
|
||||
*/
|
||||
void setPosition(float x, float y);
|
||||
virtual void setPosition(float x, float y);
|
||||
/**
|
||||
* Gets position in a more efficient way, returns two number instead of a CCPoint object
|
||||
*
|
||||
* @see setPosition(float, float)
|
||||
*/
|
||||
void getPosition(float* x, float* y);
|
||||
virtual void getPosition(float* x, float* y);
|
||||
/**
|
||||
* Gets/Sets x or y coordinate individually for position.
|
||||
* These methods are used in Lua and Javascript Bindings
|
||||
*/
|
||||
void setPositionX(float x);
|
||||
float getPositionX(void);
|
||||
void setPositionY(float y);
|
||||
float getPositionY(void);
|
||||
virtual void setPositionX(float x);
|
||||
virtual float getPositionX(void);
|
||||
virtual void setPositionY(float y);
|
||||
virtual float getPositionY(void);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,9 +9,6 @@ INCLUDES += \
|
|||
-I../../external/chipmunk/include/chipmunk \
|
||||
-I../../extensions/network \
|
||||
|
||||
DEFINES += -D__CC_PLATFORM_FILEUTILS_CPP__
|
||||
DEFINES += -DCC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
|
||||
SOURCES = ../actions/CCAction.cpp \
|
||||
../actions/CCActionCamera.cpp \
|
||||
../actions/CCActionEase.cpp \
|
||||
|
|
|
@ -8,6 +8,12 @@ ARFLAGS = cr
|
|||
|
||||
DEFINES += -DLINUX
|
||||
|
||||
ifdef USE_BOX2D
|
||||
DEFINES += -DCC_ENABLE_BOX2D_INTEGRATION
|
||||
else
|
||||
DEFINES += -DCC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
endif
|
||||
|
||||
THIS_MAKEFILE := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
|
||||
ifndef COCOS_ROOT
|
||||
COCOS_ROOT := $(realpath $(dir $(THIS_MAKEFILE))/../..)
|
||||
|
|
|
@ -137,8 +137,6 @@ CXXFLAGS += -Wno-sequence-point
|
|||
|
||||
TARGET = $(LIB_DIR)/libcocos2d.a
|
||||
|
||||
DEFINES += -DCC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECTS) $(CORE_MAKEFILE_LIST)
|
||||
|
|
|
@ -18,13 +18,15 @@ THIS_MAKEFILE := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
|
|||
# The top level of the cocos2dx-x source tree. The parent Makefile will
|
||||
# often define this, but in case is doesn't we can find it relative to
|
||||
# THIS_MAKEFILE
|
||||
COCOS_ROOT ?= $(realpath $(dir $(THIS_MAKEFILE))/../..)
|
||||
COCOS_SRC = $(COCOS_ROOT)/cocos2dx
|
||||
ifndef COCOS_ROOT
|
||||
COCOS_ROOT := $(realpath $(dir $(THIS_MAKEFILE))/../..)
|
||||
endif
|
||||
COCOS_SRC := $(COCOS_ROOT)/cocos2dx
|
||||
|
||||
ifeq ($(NACL_ARCH), i686)
|
||||
ARCH_DIR=$(NACL_LIBC)_x86_32
|
||||
ARCH_DIR := $(NACL_LIBC)_x86_32
|
||||
else
|
||||
ARCH_DIR=$(NACL_LIBC)_$(NACL_ARCH)
|
||||
ARCH_DIR := $(NACL_LIBC)_$(NACL_ARCH)
|
||||
endif
|
||||
|
||||
NACLPORTS_ROOT ?= $(NACL_SDK_ROOT)/ports
|
||||
|
@ -33,6 +35,12 @@ OUT_DIR ?= obj
|
|||
OBJ_DIR ?= $(OUT_DIR)/$(NACL_ARCH)
|
||||
LIB_DIR ?= $(COCOS_ROOT)/lib/nacl/$(ARCH_DIR)
|
||||
|
||||
ifdef USE_BOX2D
|
||||
DEFINES += -DCC_ENABLE_BOX2D_INTEGRATION
|
||||
else
|
||||
DEFINES += -DCC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
endif
|
||||
|
||||
INCLUDES += -I$(COCOS_SRC) \
|
||||
-I$(COCOS_SRC)/cocoa \
|
||||
-I$(COCOS_SRC)/include \
|
||||
|
|
|
@ -42,16 +42,9 @@
|
|||
#include "network/HttpClient.h"
|
||||
|
||||
// Physics integration
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION || CC_ENABLE_BOX2D_INTEGRATION
|
||||
#include "physics_nodes/CCPhysicsDebugNode.h"
|
||||
#include "physics_nodes/CCPhysicsSprite.h"
|
||||
#endif
|
||||
|
||||
#if CC_ENABLE_BOX2D_INTEGRATION
|
||||
#include "physics_nodes/CCPhysicsDebugNode.h"
|
||||
#include "physics_nodes/CCPhysicsSprite.h"
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __COCOS2D_EXT_H__ */
|
||||
|
||||
|
|
|
@ -164,6 +164,31 @@ void CCPhysicsSprite::setIgnoreBodyRotation(bool bIgnoreBodyRotation)
|
|||
m_bIgnoreBodyRotation = bIgnoreBodyRotation;
|
||||
}
|
||||
|
||||
// Override the setters and getters to always reflect the body's properties.
|
||||
const CCPoint& CCPhysicsSprite::getPosition()
|
||||
{
|
||||
updatePosFromPhysics();
|
||||
return CCNode::getPosition();
|
||||
}
|
||||
|
||||
void CCPhysicsSprite::getPosition(float* x, float* y)
|
||||
{
|
||||
updatePosFromPhysics();
|
||||
return CCNode::getPosition(x, y);
|
||||
}
|
||||
|
||||
float CCPhysicsSprite::getPositionX()
|
||||
{
|
||||
updatePosFromPhysics();
|
||||
return m_obPosition.x;
|
||||
}
|
||||
|
||||
float CCPhysicsSprite::getPositionY()
|
||||
{
|
||||
updatePosFromPhysics();
|
||||
return m_obPosition.y;
|
||||
}
|
||||
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
|
||||
cpBody* CCPhysicsSprite::getCPBody() const
|
||||
|
@ -176,12 +201,10 @@ void CCPhysicsSprite::setCPBody(cpBody *pBody)
|
|||
m_pCPBody = pBody;
|
||||
}
|
||||
|
||||
// Override the setters and getters to always reflect the body's properties.
|
||||
const CCPoint& CCPhysicsSprite::getPosition()
|
||||
void CCPhysicsSprite::updatePosFromPhysics()
|
||||
{
|
||||
cpVect cpPos = cpBodyGetPos(m_pCPBody);
|
||||
m_obPosition = ccp(cpPos.x, cpPos.y);
|
||||
return m_obPosition;
|
||||
}
|
||||
|
||||
void CCPhysicsSprite::setPosition(const CCPoint &pos)
|
||||
|
@ -251,14 +274,12 @@ void CCPhysicsSprite::setPTMRatio(float fRatio)
|
|||
}
|
||||
|
||||
// Override the setters and getters to always reflect the body's properties.
|
||||
const CCPoint& CCPhysicsSprite::getPosition()
|
||||
void CCPhysicsSprite::updatePosFromPhysics()
|
||||
{
|
||||
b2Vec2 pos = m_pB2Body->GetPosition();
|
||||
|
||||
float x = pos.x * m_fPTMRatio;
|
||||
float y = pos.y * m_fPTMRatio;
|
||||
m_obPosition = ccp(x,y);
|
||||
return m_obPosition;
|
||||
}
|
||||
|
||||
void CCPhysicsSprite::setPosition(const CCPoint &pos)
|
||||
|
|
|
@ -27,10 +27,11 @@
|
|||
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
#include "chipmunk.h"
|
||||
|
||||
#elif CC_ENABLE_BOX2D_INTEGRATION
|
||||
class b2Body;
|
||||
#endif // CC_ENABLE_BOX2D_INTEGRATION
|
||||
#else // CC_ENABLE_BOX2D_INTEGRATION
|
||||
#error "You must define either CC_ENABLE_CHIPMUNK_INTEGRATION or CC_ENABLE_BOX2D_INTEGRATION to use CCPhysicsSprite.h"
|
||||
#endif
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
/** A CCSprite subclass that is bound to a physics body.
|
||||
|
@ -38,7 +39,7 @@ NS_CC_EXT_BEGIN
|
|||
- Chipmunk: Preprocessor macro CC_ENABLE_CHIPMUNK_INTEGRATION should be defined
|
||||
- Objective-Chipmunk: Preprocessor macro CC_ENABLE_CHIPMUNK_INTEGRATION should be defined
|
||||
- Box2d: Preprocessor macro CC_ENABLE_BOX2D_INTEGRATION should be defined
|
||||
|
||||
|
||||
Features and Limitations:
|
||||
- Scale and Skew properties are ignored.
|
||||
- Position and rotation are going to updated from the physics body
|
||||
|
@ -51,10 +52,10 @@ protected:
|
|||
bool m_bIgnoreBodyRotation;
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
cpBody *m_pCPBody;
|
||||
|
||||
|
||||
#elif CC_ENABLE_BOX2D_INTEGRATION
|
||||
b2Body *m_pB2Body;
|
||||
|
||||
|
||||
// Pixels to Meters ratio
|
||||
float m_fPTMRatio;
|
||||
#endif // CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
|
@ -95,40 +96,35 @@ public:
|
|||
static CCPhysicsSprite* create(const char *pszFileName, const CCRect& rect);
|
||||
|
||||
virtual bool isDirty();
|
||||
|
||||
|
||||
/** Keep the sprite's rotation separate from the body. */
|
||||
bool isIgnoreBodyRotation() const;
|
||||
void setIgnoreBodyRotation(bool bIgnoreBodyRotation);
|
||||
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
|
||||
|
||||
virtual const CCPoint& getPosition();
|
||||
virtual void getPosition(float* x, float* y);
|
||||
virtual float getPositionX();
|
||||
virtual float getPositionY();
|
||||
virtual void setPosition(const CCPoint &position);
|
||||
virtual float getRotation();
|
||||
virtual void setRotation(float fRotation);
|
||||
virtual CCAffineTransform nodeToParentTransform();
|
||||
|
||||
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
/** Body accessor when using regular Chipmunk */
|
||||
cpBody* getCPBody() const;
|
||||
void setCPBody(cpBody *pBody);
|
||||
|
||||
#elif CC_ENABLE_BOX2D_INTEGRATION
|
||||
|
||||
virtual const CCPoint& getPosition();
|
||||
virtual void setPosition(const CCPoint &position);
|
||||
virtual float getRotation();
|
||||
virtual void setRotation(float fRotation);
|
||||
virtual CCAffineTransform nodeToParentTransform();
|
||||
|
||||
/** Body accessor when using box2d */
|
||||
b2Body* getB2Body() const;
|
||||
void setB2Body(b2Body *pBody);
|
||||
|
||||
|
||||
float getPTMRatio() const;
|
||||
void setPTMRatio(float fPTMRatio);
|
||||
|
||||
#endif // CC_ENABLE_BOX2D_INTEGRATION
|
||||
|
||||
|
||||
protected:
|
||||
void updatePosFromPhysics();
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -10,9 +10,6 @@ INCLUDES = -I$(COCOS_ROOT)/external \
|
|||
-I../GUI/CCControlExtension \
|
||||
-I../network
|
||||
|
||||
DEFINES += -DCC_ENABLE_CHIPMUNK_INTEGRATION=1
|
||||
DEFINES += -D__CC_PLATFORM_IMAGE_CPP__
|
||||
|
||||
SOURCES = ../CCBReader/CCBFileLoader.cpp \
|
||||
../CCBReader/CCMenuItemImageLoader.cpp \
|
||||
../CCBReader/CCBReader.cpp \
|
||||
|
|
|
@ -45,8 +45,8 @@ cd $(dirname ${BASH_SOURCE[0]})
|
|||
|
||||
export MAKEFLAGS=-j10
|
||||
|
||||
make PROJECT=linux DEBUG=1 clean
|
||||
make PROJECT=linux DEBUG=0 clean
|
||||
make PLATFORM=linux DEBUG=1 clean
|
||||
make PLATFORM=linux DEBUG=0 clean
|
||||
|
||||
make PROJECT=linux DEBUG=1 all
|
||||
make PROJECT=linux DEBUG=0 all
|
||||
make PLATFORM=linux DEBUG=1 all
|
||||
make PLATFORM=linux DEBUG=0 all
|
||||
|
|
|
@ -110,8 +110,6 @@ STATICLIBS += \
|
|||
$(LIB_DIR)/libbox2d.a \
|
||||
$(LIB_DIR)/libchipmunk.a
|
||||
|
||||
DEFINES += -DCC_ENABLE_CHIPMUNK_INTEGRATION=1
|
||||
|
||||
####### Build rules
|
||||
$(TARGET): $(OBJECTS) $(STATICLIBS) $(COCOS_LIBS) $(CORE_MAKEFILE_LIST)
|
||||
@mkdir -p $(@D)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
DEFINES += -DCC_ENABLE_BOX2D_INTEGRATION
|
||||
|
||||
COCOS_ROOT = ../../../..
|
||||
COCOS2DX_PATH = $(COCOS_ROOT)/cocos2dx
|
||||
|
||||
|
|
Loading…
Reference in New Issue