mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' into newRenderer
Conflicts: build/cocos2d_libs.xcodeproj/project.pbxproj
This commit is contained in:
commit
fbadb3329a
1
AUTHORS
1
AUTHORS
|
@ -93,6 +93,7 @@ Developers:
|
|||
martell
|
||||
use tinyxml2 to replace libxml2
|
||||
Added Mingw-crt Support without breaking VS SDK
|
||||
CMake support for windows.
|
||||
|
||||
mchinen
|
||||
fix emulator issue for OpenGL ES 2.0 on Android
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
cocos2d-x-3.0beta0 ?? 2013
|
||||
[All]
|
||||
[NEW] Upgrated Box2D to 2.3.0
|
||||
[NEW] Added ThreadHelper, ThreadHelper::runOnGLThread() simplify invoking engine codes and OpenGL ES commands in a thread other then gl thread.
|
||||
[NEW] Added tga format support again.
|
||||
[Android]
|
||||
[NEW] build/android-build.sh: add supporting to generate .apk file
|
||||
[FIX] XMLHttpRequest receives wrong binary array.
|
||||
[NEW] Bindings-generator supports to bind 'unsigned long'.
|
||||
[FIX] 'Test Frame Event' of TestJavascript/CocoStudioArmatureTest Crashes.
|
||||
[Windows]
|
||||
[NEW] CMake support for windows.
|
||||
|
||||
cocos2d-x-3.0alpha1 Nov.19 2013
|
||||
[all platforms]
|
||||
[DOC] Added RELEASE_NOTES and CODING_STYLE.md files
|
||||
|
|
174
CMakeLists.txt
174
CMakeLists.txt
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project (Cocos2dx)
|
||||
|
||||
# The version number
|
||||
|
@ -7,6 +7,26 @@ set(Cocos2dxSamples_VERSION_MINOR 0)
|
|||
|
||||
include(build/BuildHelpers.CMakeLists.txt)
|
||||
|
||||
if(WIN32 OR APPLE)
|
||||
|
||||
option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
|
||||
option(USE_BOX2D "Use box2d for physics library" OFF)
|
||||
option(DEBUG_MODE "Debug or release?" ON)
|
||||
option(BUILD_LIBS_LUA "Build lua libraries" OFF)
|
||||
option(BUILD_GUI "Build GUI library" OFF)
|
||||
option(BUILD_NETWORK "Build network library" OFF)
|
||||
option(BUILD_EXTENSIONS "Build extension library" OFF)
|
||||
option(BUILD_EDITOR_SPINE "Build editor support for spine" OFF)
|
||||
option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" OFF)
|
||||
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" OFF)
|
||||
|
||||
option(BUILD_HelloCpp "Only build HelloCpp sample" ON)
|
||||
option(BUILD_TestCpp "Only build TestCpp sample" OFF)
|
||||
option(BUILD_HelloLua "Only build HelloLua sample" OFF)
|
||||
option(BUILD_TestLua "Only build TestLua sample" OFF)
|
||||
|
||||
else()#temp
|
||||
|
||||
option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
|
||||
option(USE_BOX2D "Use box2d for physics library" OFF)
|
||||
option(DEBUG_MODE "Debug or release?" ON)
|
||||
|
@ -24,6 +44,8 @@ option(BUILD_TestCpp "Only build TestCpp sample" ON)
|
|||
option(BUILD_HelloLua "Only build HelloLua sample" ON)
|
||||
option(BUILD_TestLua "Only build TestLua sample" ON)
|
||||
|
||||
endif()#temp
|
||||
|
||||
|
||||
if(DEBUG_MODE)
|
||||
set(CMAKE_BUILD_TYPE DEBUG)
|
||||
|
@ -31,18 +53,47 @@ else(DEBUG_MODE)
|
|||
set(CMAKE_BUILD_TYPE RELEASE)
|
||||
endif(DEBUG_MODE)
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1")
|
||||
set(CMAKE_C_FLAGS_DEBUG "-DCOCOS2D_DEBUG=1")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
||||
|
||||
if(WIN32)
|
||||
ADD_DEFINITIONS (-D_USRDLL -DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32)
|
||||
|
||||
if(MSVC)
|
||||
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS
|
||||
-D_SCL_SECURE_NO_WARNINGS
|
||||
-wd4251 -wd4244 -wd4334
|
||||
-wd4005 -wd4820 -wd4710
|
||||
-wd4514 -wd4056 -wd4996 -wd4099)
|
||||
else(MSVC)#MINGW
|
||||
|
||||
endif(MSVC)
|
||||
elseif(APPLE)
|
||||
|
||||
|
||||
else()#Linux
|
||||
ADD_DEFINITIONS(-DLINUX)
|
||||
endif()
|
||||
|
||||
|
||||
if(NOT MSVC)# all gcc
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
||||
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c99")
|
||||
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11")
|
||||
endif()
|
||||
|
||||
if(MINGW)
|
||||
add_definitions(-DGLEW_STATIC)
|
||||
endif()
|
||||
|
||||
|
||||
if(USE_CHIPMUNK)
|
||||
message("Using chipmunk ...")
|
||||
add_definitions(-DLINUX -DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
|
||||
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
|
||||
elseif(USE_BOX2D)
|
||||
message("Using box2d ...")
|
||||
add_definitions(-DLINUX -DCC_ENABLE_BOX2D_INTEGRATION=1)
|
||||
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
|
||||
else(USE_CHIPMUNK)
|
||||
message(FATAL_ERROR "Must choose a physics library.")
|
||||
endif(USE_CHIPMUNK)
|
||||
|
@ -54,40 +105,93 @@ else()
|
|||
set(ARCH_DIR "32-bit")
|
||||
endif()
|
||||
|
||||
if(WIN32) # Win32
|
||||
set(PLATFORM_FOLDER win32)
|
||||
elseif(APPLE)# osx or ios
|
||||
set(PLATFORM_FOLDER mac)
|
||||
else() # Assume Linux
|
||||
set(PLATFORM_FOLDER linux)
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
.
|
||||
cocos
|
||||
cocos/audio/include
|
||||
cocos/2d
|
||||
cocos/2d/platform
|
||||
cocos/2d/platform/linux
|
||||
cocos/base
|
||||
cocos/physics
|
||||
cocos/editor-support
|
||||
cocos/math/kazmath/include
|
||||
extensions
|
||||
external
|
||||
external/jpeg/include/linux
|
||||
external/tiff/include/linux
|
||||
external/webp/include/linux
|
||||
external/glfw3/include/linux
|
||||
external/curl/include/linux/${ARCH_DIR}
|
||||
external/tinyxml2
|
||||
external/unzip
|
||||
external/chipmunk/include/chipmunk
|
||||
external/freetype2/include/linux
|
||||
external/linux-specific/fmod/include/${ARCH_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/audio/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/2d
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/2d/platform
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/base
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/physics
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/editor-support
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/math/kazmath/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/extensions
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/unzip
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/include/chipmunk
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/2d/platform/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/webp/include/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/include/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER}
|
||||
)
|
||||
|
||||
link_directories(
|
||||
/usr/local/lib
|
||||
${CMAKE_SOURCE_DIR}/external/jpeg/prebuilt/linux/${ARCH_DIR}
|
||||
${CMAKE_SOURCE_DIR}/external/tiff/prebuilt/linux/${ARCH_DIR}
|
||||
${CMAKE_SOURCE_DIR}/external/webp/prebuilt/linux/${ARCH_DIR}
|
||||
${CMAKE_SOURCE_DIR}/external/freetype2/prebuilt/linux/${ARCH_DIR}
|
||||
${CMAKE_SOURCE_DIR}/external/curl/prebuilt/linux/${ARCH_DIR}
|
||||
${CMAKE_SOURCE_DIR}/external/linux-specific/fmod/prebuilt/${ARCH_DIR}
|
||||
)
|
||||
if(WIN32)
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/gles/include/OGLES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/icon/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/zlib/include
|
||||
external/curl/include/${PLATFORM_FOLDER}
|
||||
)
|
||||
elseif(APPLE)
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER}
|
||||
)
|
||||
else()
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/fmod/include/${ARCH_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER}/${ARCH_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
if(WIN32)
|
||||
|
||||
if(NOT MINGW)
|
||||
link_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/prebuilt/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/icon/prebuilt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/zlib/prebuilt
|
||||
)
|
||||
endif()
|
||||
|
||||
link_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/gles/prebuilt
|
||||
)
|
||||
|
||||
elseif(APPLE)
|
||||
|
||||
else()
|
||||
|
||||
link_directories(
|
||||
/usr/local/lib
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/fmod/prebuilt/${ARCH_DIR}
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
# kazmath
|
||||
|
|
|
@ -1 +1 @@
|
|||
a5d82b59c287429e558e99fdb693f7507bd381cb
|
||||
b07400e8b509b42a418e61d158d09a07ec990937
|
|
@ -1 +1 @@
|
|||
3590d3bd90fa4e11c382ff2a848b66ea507dede0
|
||||
8c5c95fe879dacb32589bb48ad003c25b53f8a50
|
|
@ -0,0 +1,8 @@
|
|||
@echo off
|
||||
SETLOCAL
|
||||
|
||||
:start
|
||||
mkdir win32-msvc-vs2010-x86
|
||||
cd win32-msvc-vs2010-x86
|
||||
cmake -G "Visual Studio 10" ../..
|
||||
pause
|
|
@ -0,0 +1,8 @@
|
|||
@echo off
|
||||
SETLOCAL
|
||||
|
||||
:start
|
||||
mkdir win32-msvc-vs2012-x86
|
||||
cd win32-msvc-vs2012-x86
|
||||
cmake -G "Visual Studio 11" ../..
|
||||
pause
|
|
@ -0,0 +1,8 @@
|
|||
@echo off
|
||||
SETLOCAL
|
||||
|
||||
:start
|
||||
mkdir win32-msvc-vs2013-x86
|
||||
cd win32-msvc-vs2013-x86
|
||||
cmake -G "Visual Studio 12" ../..
|
||||
pause
|
|
@ -39,13 +39,13 @@ CCEventAcceleration.cpp \
|
|||
CCEventCustom.cpp \
|
||||
CCEventDispatcher.cpp \
|
||||
CCEventKeyboard.cpp \
|
||||
CCEventMouse.cpp \
|
||||
CCEventListenerMouse.cpp \
|
||||
CCEventListener.cpp \
|
||||
CCEventListenerAcceleration.cpp \
|
||||
CCEventListenerCustom.cpp \
|
||||
CCEventListenerKeyboard.cpp \
|
||||
CCEventListenerMouse.cpp \
|
||||
CCEventListenerTouch.cpp \
|
||||
CCEventMouse.cpp \
|
||||
CCEventTouch.cpp \
|
||||
CCFont.cpp \
|
||||
CCFontAtlas.cpp \
|
||||
|
@ -149,11 +149,6 @@ platform/CCThread.cpp \
|
|||
../physics/CCPhysicsJoint.cpp \
|
||||
../physics/CCPhysicsShape.cpp \
|
||||
../physics/CCPhysicsWorld.cpp \
|
||||
../physics/box2d/CCPhysicsBodyInfo_box2d.cpp \
|
||||
../physics/box2d/CCPhysicsContactInfo_box2d.cpp \
|
||||
../physics/box2d/CCPhysicsJointInfo_box2d.cpp \
|
||||
../physics/box2d/CCPhysicsShapeInfo_box2d.cpp \
|
||||
../physics/box2d/CCPhysicsWorldInfo_box2d.cpp \
|
||||
../physics/chipmunk/CCPhysicsBodyInfo_chipmunk.cpp \
|
||||
../physics/chipmunk/CCPhysicsContactInfo_chipmunk.cpp \
|
||||
../physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp \
|
||||
|
|
|
@ -1044,9 +1044,6 @@ void DisplayLinkDirector::startAnimation()
|
|||
}
|
||||
|
||||
_invalid = false;
|
||||
#ifndef EMSCRIPTEN
|
||||
Application::getInstance()->setAnimationInterval(_animationInterval);
|
||||
#endif // EMSCRIPTEN
|
||||
}
|
||||
|
||||
void DisplayLinkDirector::mainLoop()
|
||||
|
@ -1058,6 +1055,9 @@ void DisplayLinkDirector::mainLoop()
|
|||
}
|
||||
else if (! _invalid)
|
||||
{
|
||||
// invoke call back from other thread
|
||||
ThreadHelper::doCallback();
|
||||
|
||||
drawScene();
|
||||
|
||||
// release the objects
|
||||
|
|
|
@ -33,7 +33,7 @@ Use any of these editors to generate BMFonts:
|
|||
#ifndef __CCBITMAP_FONT_ATLAS_H__
|
||||
#define __CCBITMAP_FONT_ATLAS_H__
|
||||
|
||||
#include "CCNewSpriteBatchNode.h"
|
||||
#include "renderer/CCNewSpriteBatchNode.h"
|
||||
#include "uthash.h"
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
|
|
|
@ -25,7 +25,7 @@ THE SOFTWARE.
|
|||
#ifndef __CCLABELTTF_H__
|
||||
#define __CCLABELTTF_H__
|
||||
|
||||
#include "CCNewSprite.h"
|
||||
#include "renderer/CCNewSprite.h"
|
||||
#include "CCTexture2D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
|
|
@ -33,7 +33,6 @@ THE SOFTWARE.
|
|||
#ifdef EMSCRIPTEN
|
||||
#include "CCGLBufferedNode.h"
|
||||
#endif // EMSCRIPTEN
|
||||
#include "CCPhysicsSetting.h"
|
||||
|
||||
#include "CCEventKeyboard.h"
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
#include "CCScriptSupport.h"
|
||||
#include "CCProtocols.h"
|
||||
#include "CCEventDispatcher.h"
|
||||
#include "CCPhysicsSetting.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
|
|
@ -162,10 +162,6 @@ void TextureCache::loadImage()
|
|||
|
||||
while (true)
|
||||
{
|
||||
// create autorelease pool for iOS
|
||||
Thread thread;
|
||||
thread.createAutoreleasePool();
|
||||
|
||||
std::queue<AsyncStruct*> *pQueue = _asyncStructQueue;
|
||||
_asyncStructQueueMutex.lock();
|
||||
if (pQueue->empty())
|
||||
|
|
|
@ -1,3 +1,34 @@
|
|||
if(WIN32)
|
||||
|
||||
ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
|
||||
|
||||
set(PLATFORM_SRC
|
||||
platform/win32/CCStdC.cpp
|
||||
platform/win32/CCFileUtilsWin32.cpp
|
||||
platform/win32/CCCommon.cpp
|
||||
platform/win32/CCApplication.cpp
|
||||
platform/win32/CCEGLView.cpp
|
||||
platform/win32/CCImage.cpp
|
||||
platform/win32/CCDevice.cpp
|
||||
)
|
||||
|
||||
elseif(APPLE)
|
||||
|
||||
else()
|
||||
|
||||
set(PLATFORM_SRC
|
||||
platform/linux/CCStdC.cpp
|
||||
platform/linux/CCFileUtilsLinux.cpp
|
||||
platform/linux/CCCommon.cpp
|
||||
platform/linux/CCApplication.cpp
|
||||
platform/linux/CCEGLView.cpp
|
||||
platform/linux/CCImage.cpp
|
||||
platform/linux/CCDevice.cpp
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
set(COCOS2D_SRC
|
||||
CCAction.cpp
|
||||
CCActionCamera.cpp
|
||||
|
@ -107,27 +138,56 @@ set(COCOS2D_SRC
|
|||
platform/CCThread.cpp
|
||||
platform/CCEGLViewProtocol.cpp
|
||||
platform/CCFileUtils.cpp
|
||||
platform/linux/CCStdC.cpp
|
||||
platform/linux/CCFileUtilsLinux.cpp
|
||||
platform/linux/CCCommon.cpp
|
||||
platform/linux/CCApplication.cpp
|
||||
platform/linux/CCEGLView.cpp
|
||||
platform/linux/CCImage.cpp
|
||||
platform/linux/CCDevice.cpp
|
||||
)
|
||||
|
||||
include(../physics/CMakeLists.txt)
|
||||
|
||||
add_library(cocos2d STATIC
|
||||
${COCOS2D_SRC}
|
||||
${PLATFORM_SRC}
|
||||
${COCOS_PHYSICS_SRC}
|
||||
)
|
||||
target_link_libraries(cocos2d
|
||||
cocosbase
|
||||
chipmunk_static
|
||||
tinyxml2
|
||||
kazmath
|
||||
unzip
|
||||
|
||||
if(WIN32)
|
||||
|
||||
if(MINGW)
|
||||
|
||||
set(COCOS_LINK
|
||||
z
|
||||
jpeg
|
||||
png
|
||||
webp
|
||||
tiff
|
||||
glfw3
|
||||
glew32
|
||||
opengl32
|
||||
iconv
|
||||
freetype
|
||||
bz2
|
||||
)
|
||||
|
||||
else()
|
||||
|
||||
|
||||
set(COCOS_LINK
|
||||
libjpeg
|
||||
libpng
|
||||
libwebp
|
||||
libtiff
|
||||
freetype250
|
||||
glfw3
|
||||
glew32
|
||||
opengl32
|
||||
libiconv
|
||||
libzlib
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
elseif(APPLE)
|
||||
|
||||
else()
|
||||
set(COCOS_LINK
|
||||
jpeg
|
||||
webp
|
||||
tiff
|
||||
|
@ -142,6 +202,16 @@ target_link_libraries(cocos2d
|
|||
rt
|
||||
z
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(cocos2d
|
||||
cocosbase
|
||||
chipmunk_static
|
||||
tinyxml2
|
||||
kazmath
|
||||
unzip
|
||||
${COCOS_LINK}
|
||||
)
|
||||
|
||||
set_target_properties(cocos2d
|
||||
PROPERTIES
|
||||
|
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
|||
#include "TGAlib.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
|
||||
namespace cocos2d {
|
||||
NS_CC_BEGIN
|
||||
|
||||
static bool tgaLoadRLEImageData(unsigned char* Buffer, unsigned long bufSize, tImageTGA *psInfo);
|
||||
void tgaFlipImage( tImageTGA *info );
|
||||
|
@ -191,23 +191,19 @@ void tgaFlipImage( tImageTGA *psInfo )
|
|||
free(row);
|
||||
psInfo->flipped = 0;
|
||||
}
|
||||
|
||||
// this is the function to call when we want to load an image
|
||||
tImageTGA * tgaLoad(const char *filename)
|
||||
|
||||
tImageTGA* tgaLoadBuffer(unsigned char* buffer, long size)
|
||||
{
|
||||
int mode,total;
|
||||
tImageTGA *info = NULL;
|
||||
tImageTGA *info = nullptr;
|
||||
|
||||
long size = 0;
|
||||
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(filename, "rb", &size);
|
||||
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(! pBuffer);
|
||||
CC_BREAK_IF(! buffer);
|
||||
info = (tImageTGA *)malloc(sizeof(tImageTGA));
|
||||
|
||||
// get the file header info
|
||||
if (! tgaLoadHeader(pBuffer, size, info))
|
||||
if (! tgaLoadHeader(buffer, size, info))
|
||||
{
|
||||
info->status = TGA_ERROR_MEMORY;
|
||||
break;
|
||||
|
@ -245,11 +241,11 @@ tImageTGA * tgaLoad(const char *filename)
|
|||
// finally load the image pixels
|
||||
if ( info->type == 10 )
|
||||
{
|
||||
bLoadImage = tgaLoadRLEImageData(pBuffer, size, info);
|
||||
bLoadImage = tgaLoadRLEImageData(buffer, size, info);
|
||||
}
|
||||
else
|
||||
{
|
||||
bLoadImage = tgaLoadImageData(pBuffer, size, info);
|
||||
bLoadImage = tgaLoadImageData(buffer, size, info);
|
||||
}
|
||||
|
||||
// check for errors when reading the pixels
|
||||
|
@ -270,11 +266,26 @@ tImageTGA * tgaLoad(const char *filename)
|
|||
}
|
||||
} while(0);
|
||||
|
||||
free(pBuffer);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
// this is the function to call when we want to load an image
|
||||
tImageTGA * tgaLoad(const char *filename)
|
||||
{
|
||||
long size = 0;
|
||||
unsigned char* buffer = FileUtils::getInstance()->getFileData(filename, "rb", &size);
|
||||
|
||||
if (buffer != nullptr)
|
||||
{
|
||||
tImageTGA* data = tgaLoadBuffer(buffer, size);
|
||||
free(buffer);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// converts RGB to grayscale
|
||||
void tgaRGBtogreyscale(tImageTGA *psInfo) {
|
||||
|
||||
|
@ -326,4 +337,4 @@ void tgaDestroy(tImageTGA *psInfo) {
|
|||
free(psInfo);
|
||||
}
|
||||
}
|
||||
}//namespace cocos2d
|
||||
NS_CC_END
|
||||
|
|
|
@ -58,6 +58,9 @@ bool tgaLoadHeader(unsigned char *Buffer, unsigned long bufSize, tImageTGA *psIn
|
|||
/// loads the image pixels. You shouldn't call this function directly
|
||||
bool tgaLoadImageData(unsigned char *Buffer, unsigned long bufSize, tImageTGA *psInfo);
|
||||
|
||||
/// this is the function to call when we want to load an image buffer.
|
||||
tImageTGA* tgaLoadBuffer(unsigned char* buffer, long size);
|
||||
|
||||
/// this is the function to call when we want to load an image
|
||||
tImageTGA * tgaLoad(const char *filename);
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;CC_USE_PHYSICS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
|
@ -121,7 +121,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
</PreBuildEvent>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;CC_USE_PHYSICS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
|
@ -192,11 +192,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClCompile Include="..\math\kazmath\src\vec2.c" />
|
||||
<ClCompile Include="..\math\kazmath\src\vec3.c" />
|
||||
<ClCompile Include="..\math\kazmath\src\vec4.c" />
|
||||
<ClCompile Include="..\physics\box2d\CCPhysicsBodyInfo_box2d.cpp" />
|
||||
<ClCompile Include="..\physics\box2d\CCPhysicsContactInfo_box2d.cpp" />
|
||||
<ClCompile Include="..\physics\box2d\CCPhysicsJointInfo_box2d.cpp" />
|
||||
<ClCompile Include="..\physics\box2d\CCPhysicsShapeInfo_box2d.cpp" />
|
||||
<ClCompile Include="..\physics\box2d\CCPhysicsWorldInfo_box2d.cpp" />
|
||||
<ClCompile Include="..\physics\CCPhysicsBody.cpp" />
|
||||
<ClCompile Include="..\physics\CCPhysicsContact.cpp" />
|
||||
<ClCompile Include="..\physics\CCPhysicsJoint.cpp" />
|
||||
|
@ -361,16 +356,9 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClInclude Include="..\math\kazmath\include\kazmath\vec2.h" />
|
||||
<ClInclude Include="..\math\kazmath\include\kazmath\vec3.h" />
|
||||
<ClInclude Include="..\math\kazmath\include\kazmath\vec4.h" />
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsBodyInfo_box2d.h" />
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsContactInfo_box2d.h" />
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsHelper_box2d.h" />
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsJointInfo_box2d.h" />
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsShapeInfo_box2d.h" />
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsWorldInfo_box2d.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsBody.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsContact.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsJoint.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsSetting.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsShape.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsWorld.h" />
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.h" />
|
||||
|
|
|
@ -91,9 +91,6 @@
|
|||
<Filter Include="physics\chipmunk">
|
||||
<UniqueIdentifier>{aeadfa95-9c89-4212-98ae-89ad57db596a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="physics\Box2D">
|
||||
<UniqueIdentifier>{b9880458-36e5-4f28-a34b-d01d9512a395}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="kazmath\include">
|
||||
<UniqueIdentifier>{05e27e68-7574-4a8b-af68-553dd3bafdfa}</UniqueIdentifier>
|
||||
</Filter>
|
||||
|
@ -548,21 +545,6 @@
|
|||
<ClCompile Include="CCEventMouse.cpp">
|
||||
<Filter>event_dispatcher</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\box2d\CCPhysicsBodyInfo_box2d.cpp">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\box2d\CCPhysicsContactInfo_box2d.cpp">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\box2d\CCPhysicsJointInfo_box2d.cpp">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\box2d\CCPhysicsShapeInfo_box2d.cpp">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\box2d\CCPhysicsWorldInfo_box2d.cpp">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.cpp">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClCompile>
|
||||
|
@ -589,9 +571,6 @@
|
|||
<ClInclude Include="..\physics\CCPhysicsJoint.h">
|
||||
<Filter>physics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\CCPhysicsSetting.h">
|
||||
<Filter>physics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\CCPhysicsShape.h">
|
||||
<Filter>physics</Filter>
|
||||
</ClInclude>
|
||||
|
@ -1128,24 +1107,6 @@
|
|||
<ClInclude Include="CCEventMouse.h">
|
||||
<Filter>event_dispatcher</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsBodyInfo_box2d.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsContactInfo_box2d.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsHelper_box2d.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsJointInfo_box2d.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsShapeInfo_box2d.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\box2d\CCPhysicsWorldInfo_box2d.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.h">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClInclude>
|
||||
|
@ -1165,4 +1126,4 @@
|
|||
<Filter>physics\chipmunk</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
|
@ -85,6 +85,8 @@ public:
|
|||
S3TC,
|
||||
//! ATITC
|
||||
ATITC,
|
||||
//! TGA
|
||||
TGA,
|
||||
//! Raw Data
|
||||
RAW_DATA,
|
||||
//! Unknown format
|
||||
|
@ -206,6 +208,8 @@ protected:
|
|||
bool initWithETCData(const unsigned char * data, int dataLen);
|
||||
bool initWithS3TCData(const unsigned char * data, int dataLen);
|
||||
bool initWithATITCData(const unsigned char *data, int dataLen);
|
||||
typedef struct sImageTGA tImageTGA;
|
||||
bool initWithTGAData(tImageTGA* tgaData);
|
||||
|
||||
bool saveImageToPNG(const std::string& filePath, bool isToRGB = true);
|
||||
bool saveImageToJPG(const std::string& filePath);
|
||||
|
@ -227,6 +231,7 @@ private:
|
|||
int _numberOfMipmaps;
|
||||
// false if we cann't auto detect the image is premultiplied or not.
|
||||
bool _hasPremultipliedAlpha;
|
||||
std::string _filePath;
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
@ -42,6 +42,7 @@ extern "C"
|
|||
}
|
||||
#include "s3tc.h"
|
||||
#include "atitc.h"
|
||||
#include "TGAlib.h"
|
||||
|
||||
#include "decode.h"
|
||||
|
||||
|
@ -388,13 +389,16 @@ Image::Image()
|
|||
|
||||
Image::~Image()
|
||||
{
|
||||
CC_SAFE_DELETE_ARRAY(_data);
|
||||
if (_data != nullptr)
|
||||
{
|
||||
free(_data);
|
||||
}
|
||||
}
|
||||
|
||||
bool Image::initWithImageFile(const char * strPath)
|
||||
{
|
||||
bool bRet = false;
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(strPath);
|
||||
_filePath = FileUtils::getInstance()->fullPathForFilename(strPath);
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
// Emscripten includes a re-implementation of SDL that uses HTML5 canvas
|
||||
|
@ -417,7 +421,7 @@ bool Image::initWithImageFile(const char * strPath)
|
|||
SDL_FreeSurface(iSurf);
|
||||
#else
|
||||
long bufferLen = 0;
|
||||
unsigned char* buffer = FileUtils::getInstance()->getFileData(fullPath.c_str(), "rb", &bufferLen);
|
||||
unsigned char* buffer = FileUtils::getInstance()->getFileData(_filePath.c_str(), "rb", &bufferLen);
|
||||
|
||||
if (buffer != nullptr && bufferLen > 0)
|
||||
{
|
||||
|
@ -434,6 +438,7 @@ bool Image::initWithImageFileThreadSafe(const char *fullpath)
|
|||
{
|
||||
bool ret = false;
|
||||
long dataLen = 0;
|
||||
_filePath = fullpath;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
FileUtilsAndroid *fileUitls = (FileUtilsAndroid*)FileUtils::getInstance();
|
||||
unsigned char *buffer = fileUitls->getFileDataForAsync(fullpath, "rb", &dataLen);
|
||||
|
@ -503,8 +508,22 @@ bool Image::initWithImageData(const unsigned char * data, long dataLen)
|
|||
ret = initWithATITCData(unpackedData, unpackedLen);
|
||||
break;
|
||||
default:
|
||||
CCAssert(false, "unsupport image format!");
|
||||
break;
|
||||
{
|
||||
// load and detect image format
|
||||
tImageTGA* tgaData = tgaLoadBuffer(unpackedData, unpackedLen);
|
||||
|
||||
if (tgaData != nullptr && tgaData->status == TGA_OK)
|
||||
{
|
||||
ret = initWithTGAData(tgaData);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCAssert(false, "unsupport image format!");
|
||||
}
|
||||
|
||||
free(tgaData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(unpackedData != data)
|
||||
|
@ -613,7 +632,6 @@ bool Image::isPvr(const unsigned char * data, int dataLen)
|
|||
return memcmp(&headerv2->pvrTag, gPVRTexIdentifier, strlen(gPVRTexIdentifier)) == 0 || CC_SWAP_INT32_BIG_TO_HOST(headerv3->version) == 0x50565203;
|
||||
}
|
||||
|
||||
|
||||
Image::Format Image::detectFormat(const unsigned char * data, int dataLen)
|
||||
{
|
||||
if (isPng(data, dataLen))
|
||||
|
@ -787,11 +805,11 @@ bool Image::initWithJpgData(const unsigned char * data, int dataLen)
|
|||
_width = cinfo.output_width;
|
||||
_height = cinfo.output_height;
|
||||
_preMulti = false;
|
||||
row_pointer[0] = new unsigned char[cinfo.output_width*cinfo.output_components];
|
||||
row_pointer[0] = static_cast<unsigned char*>(malloc(cinfo.output_width*cinfo.output_components * sizeof(unsigned char)));
|
||||
CC_BREAK_IF(! row_pointer[0]);
|
||||
|
||||
_dataLen = cinfo.output_width*cinfo.output_height*cinfo.output_components;
|
||||
_data = new unsigned char[_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
CC_BREAK_IF(! _data);
|
||||
|
||||
/* now actually read the jpeg into the raw buffer */
|
||||
|
@ -816,7 +834,10 @@ bool Image::initWithJpgData(const unsigned char * data, int dataLen)
|
|||
bRet = true;
|
||||
} while (0);
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(row_pointer[0]);
|
||||
if (row_pointer[0] != nullptr)
|
||||
{
|
||||
free(row_pointer[0]);
|
||||
};
|
||||
return bRet;
|
||||
}
|
||||
|
||||
|
@ -926,7 +947,7 @@ bool Image::initWithPngData(const unsigned char * data, int dataLen)
|
|||
rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
|
||||
_dataLen = rowbytes * _height;
|
||||
_data = new unsigned char[_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
CC_BREAK_IF(!_data);
|
||||
|
||||
for (unsigned short i = 0; i < _height; ++i)
|
||||
|
@ -939,7 +960,10 @@ bool Image::initWithPngData(const unsigned char * data, int dataLen)
|
|||
|
||||
_preMulti = false;
|
||||
|
||||
CC_SAFE_FREE(row_pointers);
|
||||
if (row_pointers != nullptr)
|
||||
{
|
||||
free(row_pointers);
|
||||
};
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
|
@ -1097,7 +1121,7 @@ bool Image::initWithTiffData(const unsigned char * data, int dataLen)
|
|||
_height = h;
|
||||
|
||||
_dataLen = npixels * sizeof (uint32);
|
||||
_data = new unsigned char[_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
|
||||
uint32* raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32));
|
||||
if (raster != NULL)
|
||||
|
@ -1222,7 +1246,7 @@ bool Image::initWithPVRv2Data(const unsigned char * data, int dataLen)
|
|||
|
||||
//Move by size of header
|
||||
_dataLen = dataLen - sizeof(PVRv2TexHeader);
|
||||
_data = new unsigned char[_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
memcpy(_data, (unsigned char*)data + sizeof(PVRv2TexHeader), _dataLen);
|
||||
|
||||
// Calculate the data size for each texture level and respect the minimum number of blocks
|
||||
|
@ -1344,7 +1368,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, int dataLen)
|
|||
int blockSize = 0, widthBlocks = 0, heightBlocks = 0;
|
||||
|
||||
_dataLen = dataLen - (sizeof(PVRv3TexHeader) + header->metadataLength);
|
||||
_data = new unsigned char[_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
memcpy(_data, static_cast<const unsigned char*>(data) + sizeof(PVRv3TexHeader) + header->metadataLength, _dataLen);
|
||||
|
||||
_numberOfMipmaps = header->numberOfMipmaps;
|
||||
|
@ -1431,7 +1455,7 @@ bool Image::initWithETCData(const unsigned char * data, int dataLen)
|
|||
#ifdef GL_ETC1_RGB8_OES
|
||||
_renderFormat = Texture2D::PixelFormat::ETC;
|
||||
_dataLen = dataLen - ETC_PKM_HEADER_SIZE;
|
||||
_data = new unsigned char[_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
memcpy(_data, static_cast<const unsigned char*>(data) + ETC_PKM_HEADER_SIZE, _dataLen);
|
||||
return true;
|
||||
#endif
|
||||
|
@ -1446,12 +1470,15 @@ bool Image::initWithETCData(const unsigned char * data, int dataLen)
|
|||
_renderFormat = Texture2D::PixelFormat::RGB888;
|
||||
|
||||
_dataLen = _width * _height * bytePerPixel;
|
||||
_data = new unsigned char[_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
|
||||
if (etc1_decode_image(static_cast<const unsigned char*>(data) + ETC_PKM_HEADER_SIZE, static_cast<etc1_byte*>(_data), _width, _height, bytePerPixel, stride) != 0)
|
||||
{
|
||||
_dataLen = 0;
|
||||
CC_SAFE_DELETE_ARRAY(_data);
|
||||
if (_data != nullptr)
|
||||
{
|
||||
free(_data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1460,6 +1487,85 @@ bool Image::initWithETCData(const unsigned char * data, int dataLen)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Image::initWithTGAData(tImageTGA* tgaData)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(tgaData == nullptr);
|
||||
|
||||
// tgaLoadBuffer only support type 2, 3, 10
|
||||
if (2 == tgaData->type || 10 == tgaData->type)
|
||||
{
|
||||
// true color
|
||||
// unsupport RGB555
|
||||
if (tgaData->pixelDepth == 16)
|
||||
{
|
||||
_renderFormat = Texture2D::PixelFormat::RGB5A1;
|
||||
}
|
||||
else if(tgaData->pixelDepth == 24)
|
||||
{
|
||||
_renderFormat = Texture2D::PixelFormat::RGB888;
|
||||
}
|
||||
else if(tgaData->pixelDepth == 32)
|
||||
{
|
||||
_renderFormat = Texture2D::PixelFormat::RGBA8888;
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOG("Image WARNING: unsupport true color tga data pixel format. FILE: %s", _filePath.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(3 == tgaData->type)
|
||||
{
|
||||
// gray
|
||||
if (8 == tgaData->pixelDepth)
|
||||
{
|
||||
_renderFormat = Texture2D::PixelFormat::I8;
|
||||
}
|
||||
else
|
||||
{
|
||||
// actually this won't happen, if it happens, maybe the image file is not a tga
|
||||
CCLOG("Image WARNING: unsupport gray tga data pixel format. FILE: %s", _filePath.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_width = tgaData->width;
|
||||
_height = tgaData->height;
|
||||
_data = tgaData->imageData;
|
||||
_dataLen = _width * _height * tgaData->pixelDepth / 8;
|
||||
_fileType = Format::TGA;
|
||||
_preMulti = false;
|
||||
ret = true;
|
||||
|
||||
}while(false);
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
const unsigned char tgaSuffix[] = ".tga";
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
if (std::tolower(_filePath[_filePath.length() - i - 1]) != tgaSuffix[3 - i])
|
||||
{
|
||||
CCLOG("Image WARNING: the image file suffix is not tga, but parsed as a tga image file. FILE: %s", _filePath.c_str());
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tgaData->imageData != nullptr)
|
||||
{
|
||||
free(tgaData->imageData);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
static const uint32_t makeFourCC(char ch0, char ch1, char ch2, char ch3)
|
||||
|
@ -1479,7 +1585,7 @@ bool Image::initWithS3TCData(const unsigned char * data, int dataLen)
|
|||
/* load the .dds file */
|
||||
|
||||
S3TCTexHeader *header = (S3TCTexHeader *)data;
|
||||
unsigned char *pixelData = new unsigned char [dataLen - sizeof(S3TCTexHeader)];
|
||||
unsigned char *pixelData = static_cast<unsigned char*>(malloc((dataLen - sizeof(S3TCTexHeader)) * sizeof(unsigned char)));
|
||||
memcpy((void *)pixelData, data + sizeof(S3TCTexHeader), dataLen - sizeof(S3TCTexHeader));
|
||||
|
||||
_width = header->ddsd.width;
|
||||
|
@ -1496,7 +1602,7 @@ bool Image::initWithS3TCData(const unsigned char * data, int dataLen)
|
|||
if (Configuration::getInstance()->supportsS3TC()) //compressed data length
|
||||
{
|
||||
_dataLen = dataLen - sizeof(S3TCTexHeader);
|
||||
_data = new unsigned char [_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
memcpy((void *)_data,(void *)pixelData , _dataLen);
|
||||
}
|
||||
else //decompressed data length
|
||||
|
@ -1511,7 +1617,7 @@ bool Image::initWithS3TCData(const unsigned char * data, int dataLen)
|
|||
width >>= 1;
|
||||
height >>= 1;
|
||||
}
|
||||
_data = new unsigned char [_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
}
|
||||
|
||||
/* load the mipmaps */
|
||||
|
@ -1582,7 +1688,10 @@ bool Image::initWithS3TCData(const unsigned char * data, int dataLen)
|
|||
|
||||
/* end load the mipmaps */
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(pixelData);
|
||||
if (pixelData != nullptr)
|
||||
{
|
||||
free(pixelData);
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1622,7 +1731,7 @@ bool Image::initWithATITCData(const unsigned char *data, int dataLen)
|
|||
if (Configuration::getInstance()->supportsATITC()) //compressed data length
|
||||
{
|
||||
_dataLen = dataLen - sizeof(ATITCTexHeader) - header->bytesOfKeyValueData - 4;
|
||||
_data = new unsigned char [_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
memcpy((void *)_data,(void *)pixelData , _dataLen);
|
||||
}
|
||||
else //decompressed data length
|
||||
|
@ -1637,7 +1746,7 @@ bool Image::initWithATITCData(const unsigned char *data, int dataLen)
|
|||
width >>= 1;
|
||||
height >>= 1;
|
||||
}
|
||||
_data = new unsigned char [_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
}
|
||||
|
||||
/* load the mipmaps */
|
||||
|
@ -1738,7 +1847,7 @@ bool Image::initWithWebpData(const unsigned char * data, int dataLen)
|
|||
_height = config.input.height;
|
||||
|
||||
_dataLen = _width * _height * 4;
|
||||
_data = new unsigned char[_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
|
||||
config.output.u.RGBA.rgba = static_cast<uint8_t*>(_data);
|
||||
config.output.u.RGBA.stride = _width * 4;
|
||||
|
@ -1747,7 +1856,7 @@ bool Image::initWithWebpData(const unsigned char * data, int dataLen)
|
|||
|
||||
if (WebPDecode(static_cast<const uint8_t*>(data), dataLen, &config) != VP8_STATUS_OK)
|
||||
{
|
||||
delete []_data;
|
||||
free(_data);
|
||||
_data = NULL;
|
||||
break;
|
||||
}
|
||||
|
@ -1772,7 +1881,7 @@ bool Image::initWithRawData(const unsigned char * data, long dataLen, long width
|
|||
// only RGBA8888 supported
|
||||
int bytesPerComponent = 4;
|
||||
_dataLen = height * width * bytesPerComponent;
|
||||
_data = new unsigned char[_dataLen];
|
||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
CC_BREAK_IF(! _data);
|
||||
memcpy(_data, data, _dataLen);
|
||||
|
||||
|
@ -1907,7 +2016,7 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
|||
{
|
||||
if (isToRGB)
|
||||
{
|
||||
unsigned char *pTempData = new unsigned char[_width * _height * 3];
|
||||
unsigned char *pTempData = static_cast<unsigned char*>(malloc(_width * _height * 3 * sizeof(unsigned char*)));
|
||||
if (NULL == pTempData)
|
||||
{
|
||||
fclose(fp);
|
||||
|
@ -1935,7 +2044,10 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
|||
free(row_pointers);
|
||||
row_pointers = NULL;
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(pTempData);
|
||||
if (pTempData != nullptr)
|
||||
{
|
||||
free(pTempData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1996,7 +2108,7 @@ bool Image::saveImageToJPG(const std::string& filePath)
|
|||
|
||||
if (hasAlpha())
|
||||
{
|
||||
unsigned char *pTempData = new unsigned char[_width * _height * 3];
|
||||
unsigned char *pTempData = static_cast<unsigned char*>(malloc(_width * _height * 3 * sizeof(unsigned char)));
|
||||
if (NULL == pTempData)
|
||||
{
|
||||
jpeg_finish_compress(&cinfo);
|
||||
|
@ -2021,7 +2133,10 @@ bool Image::saveImageToJPG(const std::string& filePath)
|
|||
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(pTempData);
|
||||
if (pTempData != nullptr)
|
||||
{
|
||||
free(pTempData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -24,23 +24,62 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCThread.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// iOS and Mac already has a Thread.mm
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS && CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
|
||||
|
||||
NS_CC_BEGIN
|
||||
std::list<std::function<void(void)>>* ThreadHelper::_callbackList = new std::list<std::function<void(void)>>();
|
||||
std::mutex* ThreadHelper::_mutex = new std::mutex;
|
||||
long ThreadHelper::_callbackNumberPerFrame = 5;
|
||||
|
||||
Thread::~Thread()
|
||||
|
||||
void* ThreadHelper::createAutoreleasePool()
|
||||
{
|
||||
// To prevent warning: private field '_autoreasePool' is not
|
||||
// used [-Wunused-private-field] by CLANG.
|
||||
_autoReleasePool = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Thread::createAutoreleasePool()
|
||||
void ThreadHelper::releaseAutoreleasePool(void* autoreleasePool)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
void ThreadHelper::runOnGLThread(std::function<void(void)> f)
|
||||
{
|
||||
// Insert call back function
|
||||
_mutex->lock();
|
||||
_callbackList->push_back(f);
|
||||
_mutex->unlock();
|
||||
}
|
||||
|
||||
void ThreadHelper::doCallback()
|
||||
{
|
||||
_mutex->lock();
|
||||
auto iter = _callbackList->begin();
|
||||
long i = 0;
|
||||
while (iter != _callbackList->end())
|
||||
{
|
||||
auto f = *iter;
|
||||
f();
|
||||
|
||||
++i;
|
||||
if (i >= _callbackNumberPerFrame)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
iter = _callbackList->erase(iter);
|
||||
}
|
||||
}
|
||||
_mutex->unlock();
|
||||
}
|
||||
|
||||
void ThreadHelper::setCallbackNumberPerFrame(long callbackNumberPerFrame)
|
||||
{
|
||||
_callbackNumberPerFrame = callbackNumberPerFrame;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -25,8 +25,12 @@ THE SOFTWARE.
|
|||
#ifndef __CC_PLATFORM_THREAD_H__
|
||||
#define __CC_PLATFORM_THREAD_H__
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include "platform/CCCommon.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -39,27 +43,45 @@ NS_CC_BEGIN
|
|||
* and release it when the thread end.
|
||||
*/
|
||||
|
||||
class CC_DLL Thread
|
||||
class CC_DLL ThreadHelper
|
||||
{
|
||||
public:
|
||||
/**
|
||||
friend DisplayLinkDirector;
|
||||
|
||||
/** Create an autorelease pool for objective-c codes.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Thread() : _autoReleasePool(nullptr) {}
|
||||
static void* createAutoreleasePool();
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~Thread();
|
||||
/**
|
||||
*/
|
||||
static void releaseAutoreleasePool(void *autoreleasePool);
|
||||
|
||||
/** To run a function in gl thread.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
@since v3.0
|
||||
*/
|
||||
void createAutoreleasePool();
|
||||
static void runOnGLThread(std::function<void(void)> f);
|
||||
|
||||
/** Set how many callback functions being invoked per frame. Default value is 5.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
@since v3.0
|
||||
*/
|
||||
static void setCallbackNumberPerFrame(long callbackNumberPerFrame);
|
||||
|
||||
private:
|
||||
void *_autoReleasePool;
|
||||
// This function will be call by Director to call some call back function on gl thread
|
||||
static void doCallback();
|
||||
|
||||
static std::list<std::function<void(void)>> *_callbackList;
|
||||
static std::mutex *_mutex;
|
||||
// How many callback functions invoked per frame
|
||||
static long _callbackNumberPerFrame;
|
||||
};
|
||||
|
||||
// end of platform group
|
||||
|
|
|
@ -18,17 +18,17 @@ void Device::setAccelerometerEnabled(bool isEnabled)
|
|||
{
|
||||
if (isEnabled)
|
||||
{
|
||||
enableAccelerometer();
|
||||
enableAccelerometerJni();
|
||||
}
|
||||
else
|
||||
{
|
||||
disableAccelerometer();
|
||||
disableAccelerometerJni();
|
||||
}
|
||||
}
|
||||
|
||||
void Device::setAccelerometerInterval(float interval)
|
||||
{
|
||||
setAccelerometerInterval(interval);
|
||||
setAccelerometerIntervalJni(interval);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -471,8 +471,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void enableAccelerometer(void) {
|
||||
LOGI("enableAccelerometer()");
|
||||
void enableAccelerometerJni(void) {
|
||||
LOGI("enableAccelerometerJni()");
|
||||
|
||||
if (engine.accelerometerSensor != NULL) {
|
||||
ASensorEventQueue_enableSensor(engine.sensorEventQueue,
|
||||
|
@ -485,8 +485,8 @@ void enableAccelerometer(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void disableAccelerometer(void) {
|
||||
LOGI("disableAccelerometer()");
|
||||
void disableAccelerometerJni(void) {
|
||||
LOGI("disableAccelerometerJni()");
|
||||
|
||||
if (engine.accelerometerSensor != NULL) {
|
||||
ASensorEventQueue_disableSensor(engine.sensorEventQueue,
|
||||
|
@ -494,8 +494,8 @@ void disableAccelerometer(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void setAccelerometerInterval(float interval) {
|
||||
LOGI("setAccelerometerInterval(%f)", interval);
|
||||
void setAccelerometerIntervalJni(float interval) {
|
||||
LOGI("setAccelerometerIntervalJni(%f)", interval);
|
||||
// We'd like to get 60 events per second (in us).
|
||||
ASensorEventQueue_setEventRate(engine.sensorEventQueue,
|
||||
engine.accelerometerSensor, interval * 1000000L);
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* This is the interface to the Android native activity
|
||||
*/
|
||||
|
||||
void enableAccelerometer(void);
|
||||
void disableAccelerometer(void);
|
||||
void setAccelerometerInterval(float interval);
|
||||
void enableAccelerometerJni(void);
|
||||
void disableAccelerometerJni(void);
|
||||
void setAccelerometerIntervalJni(float interval);
|
||||
|
||||
#endif // __COCOSNATIVEACTIVITY_H__
|
||||
|
|
|
@ -26,14 +26,55 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Thread::~Thread()
|
||||
std::list<std::function<void(void)>>* ThreadHelper::_callbackList = new std::list<std::function<void(void)>>();
|
||||
std::mutex* ThreadHelper::_mutex = new std::mutex;
|
||||
long ThreadHelper::_callbackNumberPerFrame = 5;
|
||||
|
||||
void* ThreadHelper::createAutoreleasePool()
|
||||
{
|
||||
[(id)_autoReleasePool release];
|
||||
id pool = [[NSAutoreleasePool alloc] init];
|
||||
return pool;
|
||||
}
|
||||
|
||||
void Thread::createAutoreleasePool()
|
||||
void ThreadHelper::releaseAutoreleasePool(void *autoreleasePool)
|
||||
{
|
||||
_autoReleasePool = [[NSAutoreleasePool alloc] init];
|
||||
[(NSAutoreleasePool*)autoreleasePool release];
|
||||
}
|
||||
|
||||
void ThreadHelper::runOnGLThread(std::function<void(void)> f)
|
||||
{
|
||||
// Insert call back function
|
||||
_mutex->lock();
|
||||
_callbackList->push_back(f);
|
||||
_mutex->unlock();
|
||||
}
|
||||
|
||||
void ThreadHelper::doCallback()
|
||||
{
|
||||
_mutex->lock();
|
||||
auto iter = _callbackList->begin();
|
||||
long i = 0;
|
||||
while (iter != _callbackList->end())
|
||||
{
|
||||
auto f = *iter;
|
||||
f();
|
||||
|
||||
++i;
|
||||
if (i >= _callbackNumberPerFrame)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
iter = _callbackList->erase(iter);
|
||||
}
|
||||
}
|
||||
_mutex->unlock();
|
||||
}
|
||||
|
||||
void ThreadHelper::setCallbackNumberPerFrame(long callbackNumberPerFrame)
|
||||
{
|
||||
_callbackNumberPerFrame = callbackNumberPerFrame;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -413,7 +413,7 @@ EGLView::EGLView()
|
|||
{
|
||||
g_keyCodeMap.insert(std::make_pair(item.glfwKeyCode, item.keyCode));
|
||||
}
|
||||
strcpy(_viewName, "Cocos2dxWin32");
|
||||
_viewName = "Cocos2dxWin32";
|
||||
glfwSetErrorCallback(EGLViewEventHandler::OnGLFWError);
|
||||
glfwInit();
|
||||
}
|
||||
|
@ -433,7 +433,7 @@ bool EGLView::init(const char* viewName, float width, float height, float frameZ
|
|||
setFrameZoomFactor(frameZoomFactor);
|
||||
|
||||
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
||||
_mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName, nullptr, nullptr);
|
||||
_mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName.c_str(), nullptr, nullptr);
|
||||
glfwMakeContextCurrent(_mainWindow);
|
||||
|
||||
glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]);
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
set(AUDIO_SRC
|
||||
linux/SimpleAudioEngineFMOD.cpp
|
||||
linux/FmodAudioPlayer.cpp
|
||||
)
|
||||
|
||||
# architecture
|
||||
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
|
||||
set(ARCH_DIR "64-bit")
|
||||
|
@ -10,14 +5,31 @@ else()
|
|||
set(ARCH_DIR "32-bit")
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
../../external/linux-specific/fmod/include/${ARCH_DIR}
|
||||
)
|
||||
if(WIN32)
|
||||
set(AUDIO_SRC
|
||||
win32/SimpleAudioEngine.cpp
|
||||
win32/MciPlayer.cpp
|
||||
)
|
||||
elseif(APPLE)
|
||||
|
||||
else()
|
||||
set(AUDIO_SRC
|
||||
linux/SimpleAudioEngineFMOD.cpp
|
||||
linux/FmodAudioPlayer.cpp
|
||||
)
|
||||
|
||||
include_directories(
|
||||
../../external/linux-specific/fmod/include/${ARCH_DIR}
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
add_library(audio STATIC
|
||||
${AUDIO_SRC}
|
||||
)
|
||||
|
||||
if((NOT APPLE) AND (NOT WIN32))
|
||||
|
||||
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
|
||||
set(FMOD_LIB "fmodex64")
|
||||
else()
|
||||
|
@ -33,4 +45,4 @@ set_target_properties(audio
|
|||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib"
|
||||
)
|
||||
|
||||
endif()
|
||||
|
|
|
@ -237,7 +237,7 @@ public: virtual void set##funName(varType var) \
|
|||
// A macro to disallow the copy constructor and operator= functions
|
||||
// This should be used in the private: declarations for a class
|
||||
#if defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUG__ == 4) && (__GNUC_MINOR__ >= 4))) \
|
||||
|| (defined(__clang__) && (__clang_major__ >= 3))
|
||||
|| (defined(__clang__) && (__clang_major__ >= 3)) || (_MSC_VER >= 1800)
|
||||
#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
||||
TypeName(const TypeName &) = delete; \
|
||||
TypeName &operator =(const TypeName &) = delete;
|
||||
|
|
|
@ -154,10 +154,6 @@ void DataReaderHelper::loadData()
|
|||
|
||||
while (true)
|
||||
{
|
||||
// create autorelease pool for iOS
|
||||
Thread thread;
|
||||
thread.createAutoreleasePool();
|
||||
|
||||
std::queue<AsyncStruct *> *pQueue = _asyncStructQueue;
|
||||
_asyncStructQueueMutex.lock(); // get async struct from queue
|
||||
if (pQueue->empty())
|
||||
|
|
|
@ -27,31 +27,20 @@
|
|||
#include <climits>
|
||||
#include <algorithm>
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include "chipmunk.h"
|
||||
#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D)
|
||||
#include "Box2D.h"
|
||||
#endif
|
||||
|
||||
#include "CCPhysicsShape.h"
|
||||
#include "CCPhysicsJoint.h"
|
||||
#include "CCPhysicsWorld.h"
|
||||
|
||||
#include "chipmunk/CCPhysicsBodyInfo_chipmunk.h"
|
||||
#include "box2d/CCPhysicsBodyInfo_box2d.h"
|
||||
#include "chipmunk/CCPhysicsJointInfo_chipmunk.h"
|
||||
#include "box2d/CCPhysicsJointInfo_box2d.h"
|
||||
#include "chipmunk/CCPhysicsWorldInfo_chipmunk.h"
|
||||
#include "box2d/CCPhysicsWorldInfo_box2d.h"
|
||||
#include "chipmunk/CCPhysicsShapeInfo_chipmunk.h"
|
||||
#include "box2d/CCPhysicsShapeInfo_box2d.h"
|
||||
#include "chipmunk/CCPhysicsHelper_chipmunk.h"
|
||||
#include "box2d/CCPhysicsHelper_box2d.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
extern const float PHYSICS_INFINITY;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -526,18 +515,18 @@ void PhysicsBody::addMoment(float moment)
|
|||
{
|
||||
if (moment == PHYSICS_INFINITY)
|
||||
{
|
||||
// if moment is INFINITY, the moment of the body will become INFINITY
|
||||
// if moment is PHYSICS_INFINITY, the moment of the body will become PHYSICS_INFINITY
|
||||
_moment = PHYSICS_INFINITY;
|
||||
_momentDefault = false;
|
||||
}
|
||||
else if (moment == -PHYSICS_INFINITY)
|
||||
{
|
||||
// if moment is -INFINITY, it won't change
|
||||
// if moment is -PHYSICS_INFINITY, it won't change
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if moment of the body is INFINITY is has no effect
|
||||
// if moment of the body is PHYSICS_INFINITY is has no effect
|
||||
if (_moment != PHYSICS_INFINITY)
|
||||
{
|
||||
if (_momentDefault)
|
||||
|
@ -811,11 +800,6 @@ Point PhysicsBody::local2World(const Point& point)
|
|||
return PhysicsHelper::cpv2point(cpBodyLocal2World(_info->getBody(), PhysicsHelper::point2cpv(point)));
|
||||
}
|
||||
|
||||
#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#ifndef __CCPHYSICS_BODY_H__
|
||||
#define __CCPHYSICS_BODY_H__
|
||||
|
||||
#include "CCPhysicsSetting.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#include "CCObject.h"
|
||||
|
@ -40,9 +39,10 @@ NS_CC_BEGIN
|
|||
class Sprite;
|
||||
class PhysicsWorld;
|
||||
class PhysicsJoint;
|
||||
|
||||
class PhysicsBodyInfo;
|
||||
|
||||
typedef Point Vect;
|
||||
|
||||
|
||||
const PhysicsMaterial PHYSICSBODY_MATERIAL_DEFAULT(0.1f, 0.5f, 0.5f);
|
||||
|
||||
|
@ -50,7 +50,7 @@ const PhysicsMaterial PHYSICSBODY_MATERIAL_DEFAULT(0.1f, 0.5f, 0.5f);
|
|||
* A body affect by physics.
|
||||
* it can attach one or more shapes.
|
||||
* if you create body with createXXX, it will automatically compute mass and moment with density your specified(which is PHYSICSBODY_MATERIAL_DEFAULT by default, and the density value is 0.1f), and it based on the formular: mass = density * area.
|
||||
* if you create body with createEdgeXXX, the mass and moment will be INFINITY by default. and it's a static body.
|
||||
* if you create body with createEdgeXXX, the mass and moment will be PHYSICS_INFINITY by default. and it's a static body.
|
||||
* you can change mass and moment with setMass() and setMoment(). and you can change the body to be dynamic or static by use function setDynamic().
|
||||
*/
|
||||
class PhysicsBody : public Object
|
||||
|
|
|
@ -23,19 +23,12 @@
|
|||
****************************************************************************/
|
||||
#include "CCPhysicsContact.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include "chipmunk.h"
|
||||
#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D)
|
||||
#include "Box2D.h"
|
||||
#endif
|
||||
|
||||
#include "CCPhysicsBody.h"
|
||||
|
||||
#include "chipmunk/CCPhysicsContactInfo_chipmunk.h"
|
||||
#include "box2d/CCPhysicsContactInfo_box2d.h"
|
||||
#include "chipmunk/CCPhysicsHelper_chipmunk.h"
|
||||
#include "box2d/CCPhysicsHelper_box2d.h"
|
||||
|
||||
#include "CCEventCustom.h"
|
||||
|
||||
|
@ -105,7 +98,7 @@ void PhysicsContact::generateContactData()
|
|||
cpArbiter* arb = static_cast<cpArbiter*>(_contactInfo);
|
||||
_contactData = new PhysicsContactData();
|
||||
_contactData->count = cpArbiterGetCount(arb);
|
||||
for (int i=0; i<_contactData->count; ++i)
|
||||
for (int i=0; i<_contactData->count && i<PhysicsContactData::POINT_MAX; ++i)
|
||||
{
|
||||
_contactData->points[i] = PhysicsHelper::cpv2point(cpArbiterGetPoint(arb, i));
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#ifndef __CCPHYSICS_CONTACT_H__
|
||||
#define __CCPHYSICS_CONTACT_H__
|
||||
|
||||
#include "CCPhysicsSetting.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#include "CCObject.h"
|
||||
|
@ -41,10 +40,12 @@ class PhysicsWorld;
|
|||
|
||||
class PhysicsContactInfo;
|
||||
|
||||
typedef Point Vect;
|
||||
|
||||
typedef struct PhysicsContactData
|
||||
{
|
||||
Point points[PHYSICS_CONTACT_POINT_MAX];
|
||||
static const long POINT_MAX = 4;
|
||||
Point points[POINT_MAX];
|
||||
int count;
|
||||
Point normal;
|
||||
|
||||
|
|
|
@ -24,24 +24,15 @@
|
|||
|
||||
#include "CCPhysicsJoint.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include "chipmunk.h"
|
||||
#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D)
|
||||
#include "Box2D.h"
|
||||
#endif
|
||||
|
||||
#include "CCPhysicsBody.h"
|
||||
#include "CCPhysicsWorld.h"
|
||||
|
||||
#include "chipmunk/CCPhysicsJointInfo_chipmunk.h"
|
||||
#include "box2d/CCPhysicsJointInfo_box2d.h"
|
||||
#include "chipmunk/CCPhysicsBodyInfo_chipmunk.h"
|
||||
#include "box2d/CCPhysicsBodyInfo_box2d.h"
|
||||
#include "chipmunk/CCPhysicsShapeInfo_chipmunk.h"
|
||||
#include "box2d/CCPhysicsShapeInfo_box2d.h"
|
||||
#include "chipmunk/CCPhysicsHelper_chipmunk.h"
|
||||
#include "box2d/CCPhysicsHelper_box2d.h"
|
||||
#include "CCNode.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -71,19 +62,15 @@ bool PhysicsJoint::init(cocos2d::PhysicsBody *a, cocos2d::PhysicsBody *b)
|
|||
{
|
||||
do
|
||||
{
|
||||
CCASSERT(a != nullptr && b != nullptr, "the body passed in is nil");
|
||||
CCASSERT(a != b, "the two bodies are equal");
|
||||
|
||||
CC_BREAK_IF(!(_info = new PhysicsJointInfo(this)));
|
||||
|
||||
if (a != nullptr)
|
||||
{
|
||||
_bodyA = a;
|
||||
_bodyA->_joints.push_back(this);
|
||||
}
|
||||
|
||||
if (b != nullptr)
|
||||
{
|
||||
_bodyB = b;
|
||||
_bodyB->_joints.push_back(this);
|
||||
}
|
||||
_bodyA = a;
|
||||
_bodyA->_joints.push_back(this);
|
||||
_bodyB = b;
|
||||
_bodyB->_joints.push_back(this);
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
@ -150,7 +137,6 @@ PhysicsJointDistance::~PhysicsJointDistance()
|
|||
|
||||
}
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
PhysicsBodyInfo* PhysicsJoint::getBodyInfo(PhysicsBody* body) const
|
||||
{
|
||||
return body->_info;
|
||||
|
@ -375,9 +361,5 @@ bool PhysicsJointDistance::init(PhysicsBody* a, PhysicsBody* b, const Point& anc
|
|||
return false;
|
||||
}
|
||||
|
||||
#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#ifndef __CCPHYSICS_JOINT_H__
|
||||
#define __CCPHYSICS_JOINT_H__
|
||||
|
||||
#include "CCPhysicsSetting.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#include "CCObject.h"
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
/****************************************************************************
|
||||
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_USE_CHIPMUNK
|
||||
|
||||
#ifdef CC_USE_BOX2D
|
||||
#define CC_PHYSICS_ENGINE CC_PHYSICS_BOX2D
|
||||
#elif defined(CC_USE_CHIPMUNK)
|
||||
#define CC_PHYSICS_ENGINE CC_PHYSICS_CHIPMUNK
|
||||
#else
|
||||
#define CC_PHYSICS_ENGINE CC_PHYSICS_UNKNOWN
|
||||
#endif
|
||||
|
||||
#if (CC_PHYSICS_ENGINE != CC_PHYSICS_UNKNOWN)
|
||||
#define CC_USE_PHYSICS
|
||||
#endif
|
||||
|
||||
namespace cocos2d
|
||||
{
|
||||
extern const float PHYSICS_INFINITY;
|
||||
|
||||
class Point;
|
||||
typedef Point Vect;
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
static const int PHYSICS_CONTACT_POINT_MAX = 4;
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // __CCPHYSICS_SETTING_H__
|
|
@ -27,22 +27,17 @@
|
|||
|
||||
#include <climits>
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include "chipmunk.h"
|
||||
#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D)
|
||||
#include "Box2D.h"
|
||||
#endif
|
||||
|
||||
#include "CCPhysicsBody.h"
|
||||
#include "CCPhysicsWorld.h"
|
||||
|
||||
#include "chipmunk/CCPhysicsBodyInfo_chipmunk.h"
|
||||
#include "box2d/CCPhysicsBodyInfo_box2d.h"
|
||||
#include "chipmunk/CCPhysicsShapeInfo_chipmunk.h"
|
||||
#include "box2d/CCPhysicsShapeInfo_box2d.h"
|
||||
#include "chipmunk/CCPhysicsHelper_chipmunk.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
extern const float PHYSICS_INFINITY;
|
||||
|
||||
PhysicsShape::PhysicsShape()
|
||||
: _body(nullptr)
|
||||
|
@ -195,7 +190,6 @@ PhysicsShapeEdgeSegment::~PhysicsShapeEdgeSegment()
|
|||
|
||||
}
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
void PhysicsShape::setDensity(float density)
|
||||
{
|
||||
if (density < 0)
|
||||
|
@ -810,10 +804,6 @@ bool PhysicsShape::containsPoint(const Point& point) const
|
|||
return false;
|
||||
}
|
||||
|
||||
#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#ifndef __CCPHYSICS_SHAPE_H__
|
||||
#define __CCPHYSICS_SHAPE_H__
|
||||
|
||||
#include "CCPhysicsSetting.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#include "CCObject.h"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,7 +25,6 @@
|
|||
#ifndef __CCPHYSICS_WORLD_H__
|
||||
#define __CCPHYSICS_WORLD_H__
|
||||
|
||||
#include "CCPhysicsSetting.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#include <list>
|
||||
|
@ -43,6 +42,8 @@ class PhysicsShape;
|
|||
class PhysicsContact;
|
||||
class Array;
|
||||
|
||||
typedef Point Vect;
|
||||
|
||||
class Sprite;
|
||||
class Scene;
|
||||
class DrawNode;
|
||||
|
@ -201,6 +202,7 @@ protected:
|
|||
|
||||
friend class PhysicsWorld;
|
||||
};
|
||||
extern const float PHYSICS_INFINITY;
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
set(COCOS_PHYSICS_SRC
|
||||
${CMAKE_SOURCE_DIR}/cocos/physics/box2d/CCPhysicsContactInfo_box2d.cpp
|
||||
${CMAKE_SOURCE_DIR}/cocos/physics/box2d/CCPhysicsJointInfo_box2d.cpp
|
||||
${CMAKE_SOURCE_DIR}/cocos/physics/box2d/CCPhysicsShapeInfo_box2d.cpp
|
||||
${CMAKE_SOURCE_DIR}/cocos/physics/box2d/CCPhysicsBodyInfo_box2d.cpp
|
||||
${CMAKE_SOURCE_DIR}/cocos/physics/box2d/CCPhysicsWorldInfo_box2d.cpp
|
||||
${CMAKE_SOURCE_DIR}/cocos/physics/chipmunk/CCPhysicsContactInfo_chipmunk.cpp
|
||||
${CMAKE_SOURCE_DIR}/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp
|
||||
${CMAKE_SOURCE_DIR}/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
/****************************************************************************
|
||||
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 "CCPhysicsBodyInfo_box2d.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsBodyInfo::PhysicsBodyInfo()
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsBodyInfo::~PhysicsBodyInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -1,45 +0,0 @@
|
|||
/****************************************************************************
|
||||
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_INFO_BOX2D_H__
|
||||
#define __CCPHYSICS_BODY_INFO_BOX2D_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsBodyInfo
|
||||
{
|
||||
public:
|
||||
PhysicsBodyInfo();
|
||||
~PhysicsBodyInfo();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
||||
#endif // __CCPHYSICS_BODY_INFO_BOX2D_H__
|
|
@ -1,39 +0,0 @@
|
|||
/****************************************************************************
|
||||
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 "CCPhysicsContactInfo_box2d.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsContactInfo::PhysicsContactInfo()
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsContactInfo::~PhysicsContactInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -1,44 +0,0 @@
|
|||
/****************************************************************************
|
||||
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_CONTACT_INFO_BOX2D_H__
|
||||
#define __CCPHYSICS_CONTACT_INFO_BOX2D_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsContactInfo
|
||||
{
|
||||
public:
|
||||
PhysicsContactInfo();
|
||||
~PhysicsContactInfo();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
||||
#endif // __CCPHYSICS_CONTACT_INFO_BOX2D_H__
|
|
@ -1,42 +0,0 @@
|
|||
/****************************************************************************
|
||||
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_HELPER_BOX2D_H__
|
||||
#define __CCPHYSICS_HELPER_BOX2D_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCGeometry.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsHelper
|
||||
{
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
||||
#endif // __CCPHYSICS_HELPER_BOX2D_H__
|
|
@ -1,39 +0,0 @@
|
|||
/****************************************************************************
|
||||
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 "CCPhysicsJointInfo_box2d.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsJointInfo::PhysicsJointInfo()
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsJointInfo::~PhysicsJointInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -1,44 +0,0 @@
|
|||
/****************************************************************************
|
||||
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_INFO_BOX2D_H__
|
||||
#define __CCPHYSICS_JOINT_INFO_BOX2D_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsJointInfo
|
||||
{
|
||||
public:
|
||||
PhysicsJointInfo();
|
||||
~PhysicsJointInfo();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
||||
#endif // __CCPHYSICS_JOINT_INFO_BOX2D_H__
|
|
@ -1,39 +0,0 @@
|
|||
/****************************************************************************
|
||||
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 "CCPhysicsShapeInfo_box2d.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsShapeInfo::PhysicsShapeInfo()
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsShapeInfo::~PhysicsShapeInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -1,44 +0,0 @@
|
|||
/****************************************************************************
|
||||
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_SHAPE_INFO_BOX2D_H__
|
||||
#define __CCPHYSICS_SHAPE_INFO_BOX2D_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsShapeInfo
|
||||
{
|
||||
public:
|
||||
PhysicsShapeInfo();
|
||||
~PhysicsShapeInfo();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
||||
#endif // __CCPHYSICS_SHAPE_INFO_BOX2D_H__
|
|
@ -1,39 +0,0 @@
|
|||
/****************************************************************************
|
||||
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 "CCPhysicsWorldInfo_box2d.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsWorldInfo::PhysicsWorldInfo()
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsWorldInfo::~PhysicsWorldInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -1,44 +0,0 @@
|
|||
/****************************************************************************
|
||||
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_INFO_BOX2D_H__
|
||||
#define __CCPHYSICS_WORLD_INFO_BOX2D_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsWorldInfo
|
||||
{
|
||||
public:
|
||||
PhysicsWorldInfo();
|
||||
~PhysicsWorldInfo();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
||||
#endif // __CCPHYSICS_WORLD_INFO_BOX2D_H__
|
|
@ -22,8 +22,8 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#include "CCPhysicsBodyInfo_chipmunk.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsBodyInfo::PhysicsBodyInfo()
|
||||
|
@ -37,4 +37,4 @@ PhysicsBodyInfo::~PhysicsBodyInfo()
|
|||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
|
|
@ -25,8 +25,7 @@
|
|||
#ifndef __CCPHYSICS_BODY_INFO_CHIPMUNK_H__
|
||||
#define __CCPHYSICS_BODY_INFO_CHIPMUNK_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#include "chipmunk.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
@ -52,5 +51,5 @@ private:
|
|||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
||||
#endif // CC_USE_PHYSICS
|
||||
#endif // __CCPHYSICS_BODY_INFO_CHIPMUNK_H__
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#include "CCPhysicsContactInfo_chipmunk.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsContactInfo::PhysicsContactInfo(PhysicsContact* contact)
|
||||
|
@ -36,4 +36,4 @@ PhysicsContactInfo::~PhysicsContactInfo()
|
|||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
|
|
@ -25,8 +25,7 @@
|
|||
#ifndef __CCPHYSICS_CONTACT_INFO_CHIPMUNK_H__
|
||||
#define __CCPHYSICS_CONTACT_INFO_CHIPMUNK_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#include "chipmunk.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
@ -50,5 +49,5 @@ private:
|
|||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
||||
#endif // CC_USE_PHYSICS
|
||||
#endif // __CCPHYSICS_CONTACT_INFO_CHIPMUNK_H__
|
||||
|
|
|
@ -25,8 +25,7 @@
|
|||
#ifndef __CCPHYSICS_HELPER_CHIPMUNK_H__
|
||||
#define __CCPHYSICS_HELPER_CHIPMUNK_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#include "chipmunk.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
@ -69,5 +68,5 @@ public:
|
|||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
||||
#endif // CC_USE_PHYSICS
|
||||
#endif // __CCPHYSICS_HELPER_CHIPMUNK_H__
|
||||
|
|
|
@ -22,9 +22,8 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#include "CCPhysicsJointInfo_chipmunk.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
|
||||
|
@ -82,4 +81,4 @@ void PhysicsJointInfo::removeAll()
|
|||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
|
|
@ -25,8 +25,7 @@
|
|||
#ifndef __CCPHYSICS_JOINT_INFO_CHIPMUNK_H__
|
||||
#define __CCPHYSICS_JOINT_INFO_CHIPMUNK_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#include "chipmunk.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
@ -60,5 +59,5 @@ protected:
|
|||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
||||
#endif // CC_USE_PHYSICS
|
||||
#endif // __CCPHYSICS_JOINT_INFO_CHIPMUNK_H__
|
||||
|
|
|
@ -22,9 +22,8 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#include "CCPhysicsShapeInfo_chipmunk.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
|
||||
|
@ -116,4 +115,4 @@ void PhysicsShapeInfo::removeAll()
|
|||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
|
|
@ -25,8 +25,7 @@
|
|||
#ifndef __CCPHYSICS_SHAPE_INFO_CHIPMUNK_H__
|
||||
#define __CCPHYSICS_SHAPE_INFO_CHIPMUNK_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#if CC_USE_PHYSICS
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
@ -69,5 +68,5 @@ protected:
|
|||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
||||
#endif // CC_USE_PHYSICS
|
||||
#endif // __CCPHYSICS_SHAPE_INFO_CHIPMUNK_H__
|
||||
|
|
|
@ -22,25 +22,14 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
#include "CCPhysicsWorldInfo_chipmunk.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include "CCPhysicsHelper_chipmunk.h"
|
||||
#include "CCPhysicsBodyInfo_chipmunk.h"
|
||||
#include "CCPhysicsShapeInfo_chipmunk.h"
|
||||
#include "CCPhysicsJointInfo_chipmunk.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
#define PHYSICS_WORLD_INFO_FUNCTION_IMPLEMENTS(name, type) \
|
||||
void PhysicsWorldInfo::add##name(cp##type* data) \
|
||||
{ \
|
||||
if (!cpSpaceContains##type(_space, data)) cpSpaceAdd##type(_space, data); \
|
||||
} \
|
||||
\
|
||||
void PhysicsWorldInfo::remove##name(cp##type* data) \
|
||||
{ \
|
||||
if (cpSpaceContains##type(_space, data)) cpSpaceRemove##type(_space, data); \
|
||||
} \
|
||||
|
||||
PHYSICS_WORLD_INFO_FUNCTION_IMPLEMENTS(Shape, Shape)
|
||||
PHYSICS_WORLD_INFO_FUNCTION_IMPLEMENTS(Body, Body)
|
||||
PHYSICS_WORLD_INFO_FUNCTION_IMPLEMENTS(Joint, Constraint)
|
||||
|
||||
PhysicsWorldInfo::PhysicsWorldInfo()
|
||||
{
|
||||
_space = cpSpaceNew();
|
||||
|
@ -51,5 +40,61 @@ PhysicsWorldInfo::~PhysicsWorldInfo()
|
|||
cpSpaceFree(_space);
|
||||
}
|
||||
|
||||
void PhysicsWorldInfo::setGravity(const Vect& gravity)
|
||||
{
|
||||
cpSpaceSetGravity(_space, PhysicsHelper::point2cpv(gravity));
|
||||
}
|
||||
|
||||
void PhysicsWorldInfo::addBody(PhysicsBodyInfo& body)
|
||||
{
|
||||
if (!cpSpaceContainsBody(_space, body.getBody()))
|
||||
{
|
||||
cpSpaceAddBody(_space, body.getBody());
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorldInfo::removeBody(PhysicsBodyInfo& body)
|
||||
{
|
||||
if (cpSpaceContainsBody(_space, body.getBody()))
|
||||
{
|
||||
cpSpaceRemoveBody(_space, body.getBody());
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorldInfo::addShape(PhysicsShapeInfo& shape)
|
||||
{
|
||||
for (auto cps : shape.getShapes())
|
||||
{
|
||||
cpSpaceAddShape(_space, cps);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorldInfo::removeShape(PhysicsShapeInfo& shape)
|
||||
{
|
||||
for (auto cps : shape.getShapes())
|
||||
{
|
||||
if (cpSpaceContainsShape(_space, cps))
|
||||
{
|
||||
cpSpaceRemoveShape(_space, cps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorldInfo::addJoint(PhysicsJointInfo& joint)
|
||||
{
|
||||
for (auto subjoint : joint.getJoints())
|
||||
{
|
||||
cpSpaceAddConstraint(_space, subjoint);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorldInfo::removeJoint(PhysicsJointInfo& joint)
|
||||
{
|
||||
for (auto subjoint : joint.getJoints())
|
||||
{
|
||||
cpSpaceRemoveConstraint(_space, subjoint);
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
|
|
@ -25,24 +25,31 @@
|
|||
#ifndef __CCPHYSICS_WORLD_INFO_CHIPMUNK_H__
|
||||
#define __CCPHYSICS_WORLD_INFO_CHIPMUNK_H__
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#include <vector>
|
||||
#include "chipmunk.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
#include <vector>
|
||||
#include "CCGeometry.h"
|
||||
NS_CC_BEGIN
|
||||
typedef Point Vect;
|
||||
class PhysicsBodyInfo;
|
||||
class PhysicsJointInfo;
|
||||
class PhysicsShapeInfo;
|
||||
|
||||
class PhysicsWorldInfo
|
||||
{
|
||||
public:
|
||||
cpSpace* getSpace() const { return _space; }
|
||||
void addShape(cpShape* shape);
|
||||
void removeShape(cpShape* shape);
|
||||
void addBody(cpBody* body);
|
||||
void removeBody(cpBody* body);
|
||||
void addJoint(cpConstraint* joint);
|
||||
void removeJoint(cpConstraint* joint);
|
||||
void addShape(PhysicsShapeInfo& shape);
|
||||
void removeShape(PhysicsShapeInfo& shape);
|
||||
void addBody(PhysicsBodyInfo& body);
|
||||
void removeBody(PhysicsBodyInfo& body);
|
||||
void addJoint(PhysicsJointInfo& joint);
|
||||
void removeJoint(PhysicsJointInfo& joint);
|
||||
void setGravity(const Vect& gravity);
|
||||
inline bool isLocked() { return static_cast<bool>(_space->locked_private); }
|
||||
inline void step(float delta) { cpSpaceStep(_space, delta); }
|
||||
|
||||
private:
|
||||
PhysicsWorldInfo();
|
||||
|
@ -56,5 +63,5 @@ private:
|
|||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
||||
#endif // CC_USE_PHYSICS
|
||||
#endif // __CCPHYSICS_WORLD_INFO_CHIPMUNK_H__
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 3f5c6fd9082864d9dc214ce225e1515df279406d
|
||||
Subproject commit 8b8a8815474b2dcef3de12161bf7c0621f3c3e05
|
|
@ -86,15 +86,10 @@ AssetsManager::AssetsManager(const char* packageUrl/* =NULL */, const char* vers
|
|||
, _shouldDeleteDelegateWhenExit(false)
|
||||
{
|
||||
checkStoragePath();
|
||||
_schedule = new Helper();
|
||||
}
|
||||
|
||||
AssetsManager::~AssetsManager()
|
||||
{
|
||||
if (_schedule)
|
||||
{
|
||||
_schedule->release();
|
||||
}
|
||||
if (_shouldDeleteDelegateWhenExit)
|
||||
{
|
||||
delete _delegate;
|
||||
|
@ -161,7 +156,10 @@ bool AssetsManager::checkUpdate()
|
|||
|
||||
if (res != 0)
|
||||
{
|
||||
sendErrorMessage(ErrorCode::NETWORK);
|
||||
ThreadHelper::runOnGLThread([&, this]{
|
||||
if (this->_delegate)
|
||||
this->_delegate->onError(ErrorCode::NETWORK);
|
||||
});
|
||||
CCLOG("can not get version file content, error code is %d", res);
|
||||
curl_easy_cleanup(_curl);
|
||||
return false;
|
||||
|
@ -170,7 +168,10 @@ bool AssetsManager::checkUpdate()
|
|||
string recordedVersion = UserDefault::getInstance()->getStringForKey(keyOfVersion().c_str());
|
||||
if (recordedVersion == _version)
|
||||
{
|
||||
sendErrorMessage(ErrorCode::NO_NEW_VERSION);
|
||||
ThreadHelper::runOnGLThread([&, this]{
|
||||
if (this->_delegate)
|
||||
this->_delegate->onError(ErrorCode::NO_NEW_VERSION);
|
||||
});
|
||||
CCLOG("there is not new version");
|
||||
// Set resource search path.
|
||||
setSearchPath();
|
||||
|
@ -190,25 +191,45 @@ void AssetsManager::downloadAndUncompress()
|
|||
{
|
||||
if (! downLoad()) break;
|
||||
|
||||
// Record downloaded version.
|
||||
AssetsManager::Message *msg1 = new AssetsManager::Message();
|
||||
msg1->what = ASSETSMANAGER_MESSAGE_RECORD_DOWNLOADED_VERSION;
|
||||
msg1->obj = this;
|
||||
_schedule->sendMessage(msg1);
|
||||
ThreadHelper::runOnGLThread([&, this]{
|
||||
UserDefault::getInstance()->setStringForKey(this->keyOfDownloadedVersion().c_str(),
|
||||
this->_version.c_str());
|
||||
UserDefault::getInstance()->flush();
|
||||
});
|
||||
}
|
||||
|
||||
// Uncompress zip file.
|
||||
if (! uncompress())
|
||||
{
|
||||
sendErrorMessage(ErrorCode::UNCOMPRESS);
|
||||
ThreadHelper::runOnGLThread([&, this]{
|
||||
if (this->_delegate)
|
||||
this->_delegate->onError(ErrorCode::UNCOMPRESS);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
// Record updated version and remove downloaded zip file
|
||||
AssetsManager::Message *msg2 = new AssetsManager::Message();
|
||||
msg2->what = ASSETSMANAGER_MESSAGE_UPDATE_SUCCEED;
|
||||
msg2->obj = this;
|
||||
_schedule->sendMessage(msg2);
|
||||
ThreadHelper::runOnGLThread([&, this] {
|
||||
|
||||
// Record new version code.
|
||||
UserDefault::getInstance()->setStringForKey(this->keyOfVersion().c_str(), this->_version.c_str());
|
||||
|
||||
// Unrecord downloaded version code.
|
||||
UserDefault::getInstance()->setStringForKey(this->keyOfDownloadedVersion().c_str(), "");
|
||||
UserDefault::getInstance()->flush();
|
||||
|
||||
// Set resource search path.
|
||||
this->setSearchPath();
|
||||
|
||||
// Delete unloaded zip file.
|
||||
string zipfileName = this->_storagePath + TEMP_PACKAGE_FILE_NAME;
|
||||
if (remove(zipfileName.c_str()) != 0)
|
||||
{
|
||||
CCLOG("can not remove downloaded zip file %s", zipfileName.c_str());
|
||||
}
|
||||
|
||||
if (this->_delegate) this->_delegate->onSuccess();
|
||||
});
|
||||
|
||||
} while (0);
|
||||
|
||||
_isDownloading = false;
|
||||
|
@ -452,18 +473,20 @@ static size_t downLoadPackage(void *ptr, size_t size, size_t nmemb, void *userda
|
|||
|
||||
int assetsManagerProgressFunc(void *ptr, double totalToDownload, double nowDownloaded, double totalToUpLoad, double nowUpLoaded)
|
||||
{
|
||||
AssetsManager* manager = (AssetsManager*)ptr;
|
||||
AssetsManager::Message *msg = new AssetsManager::Message();
|
||||
msg->what = ASSETSMANAGER_MESSAGE_PROGRESS;
|
||||
static int percent = 0;
|
||||
int tmp = (int)(nowDownloaded / totalToDownload * 100);
|
||||
|
||||
ProgressMessage *progressData = new ProgressMessage();
|
||||
progressData->percent = (int)(nowDownloaded/totalToDownload*100);
|
||||
progressData->manager = manager;
|
||||
msg->obj = progressData;
|
||||
|
||||
manager->_schedule->sendMessage(msg);
|
||||
|
||||
CCLOG("downloading... %d%%", (int)(nowDownloaded/totalToDownload*100));
|
||||
if (percent != tmp)
|
||||
{
|
||||
percent = tmp;
|
||||
ThreadHelper::runOnGLThread([=]{
|
||||
auto manager = static_cast<AssetsManager*>(ptr);
|
||||
if (manager->_delegate)
|
||||
manager->_delegate->onProgress(percent);
|
||||
});
|
||||
|
||||
CCLOG("downloading... %d%%", percent);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -475,7 +498,10 @@ bool AssetsManager::downLoad()
|
|||
FILE *fp = fopen(outFileName.c_str(), "wb");
|
||||
if (! fp)
|
||||
{
|
||||
sendErrorMessage(ErrorCode::CREATE_FILE);
|
||||
ThreadHelper::runOnGLThread([&, this]{
|
||||
if (this->_delegate)
|
||||
this->_delegate->onError(ErrorCode::CREATE_FILE);
|
||||
});
|
||||
CCLOG("can not create file %s", outFileName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
@ -492,7 +518,10 @@ bool AssetsManager::downLoad()
|
|||
curl_easy_cleanup(_curl);
|
||||
if (res != 0)
|
||||
{
|
||||
sendErrorMessage(ErrorCode::NETWORK);
|
||||
ThreadHelper::runOnGLThread([&, this]{
|
||||
if (this->_delegate)
|
||||
this->_delegate->onError(ErrorCode::NETWORK);
|
||||
});
|
||||
CCLOG("error when download package");
|
||||
fclose(fp);
|
||||
return false;
|
||||
|
@ -560,133 +589,6 @@ unsigned int AssetsManager::getConnectionTimeout()
|
|||
return _connectionTimeout;
|
||||
}
|
||||
|
||||
void AssetsManager::sendErrorMessage(AssetsManager::ErrorCode code)
|
||||
{
|
||||
Message *msg = new Message();
|
||||
msg->what = ASSETSMANAGER_MESSAGE_ERROR;
|
||||
|
||||
ErrorMessage *errorMessage = new ErrorMessage();
|
||||
errorMessage->code = code;
|
||||
errorMessage->manager = this;
|
||||
msg->obj = errorMessage;
|
||||
|
||||
_schedule->sendMessage(msg);
|
||||
}
|
||||
|
||||
// Implementation of AssetsManagerHelper
|
||||
|
||||
AssetsManager::Helper::Helper()
|
||||
{
|
||||
_messageQueue = new list<Message*>();
|
||||
Director::getInstance()->getScheduler()->scheduleUpdateForTarget(this, 0, false);
|
||||
}
|
||||
|
||||
AssetsManager::Helper::~Helper()
|
||||
{
|
||||
Director::getInstance()->getScheduler()->unscheduleAllForTarget(this);
|
||||
delete _messageQueue;
|
||||
}
|
||||
|
||||
void AssetsManager::Helper::sendMessage(Message *msg)
|
||||
{
|
||||
_messageQueueMutex.lock();
|
||||
_messageQueue->push_back(msg);
|
||||
_messageQueueMutex.unlock();
|
||||
}
|
||||
|
||||
void AssetsManager::Helper::update(float dt)
|
||||
{
|
||||
Message *msg = NULL;
|
||||
|
||||
// Returns quickly if no message
|
||||
_messageQueueMutex.lock();
|
||||
if (0 == _messageQueue->size())
|
||||
{
|
||||
_messageQueueMutex.unlock();
|
||||
return;
|
||||
}
|
||||
//remove unnecessary message
|
||||
std::list<Message*>::iterator it;
|
||||
Message *proMsg = nullptr;
|
||||
for (it = _messageQueue->begin(); it != _messageQueue->end(); ++it)
|
||||
{
|
||||
if((*it)->what == ASSETSMANAGER_MESSAGE_PROGRESS)
|
||||
{
|
||||
if (proMsg)
|
||||
{
|
||||
_messageQueue->remove(proMsg);
|
||||
delete (ProgressMessage*)proMsg->obj;
|
||||
delete proMsg;
|
||||
}
|
||||
proMsg = *it;
|
||||
}
|
||||
}
|
||||
// Gets message
|
||||
msg = *(_messageQueue->begin());
|
||||
_messageQueue->pop_front();
|
||||
_messageQueueMutex.unlock();
|
||||
|
||||
switch (msg->what) {
|
||||
case ASSETSMANAGER_MESSAGE_UPDATE_SUCCEED:
|
||||
handleUpdateSucceed(msg);
|
||||
|
||||
break;
|
||||
case ASSETSMANAGER_MESSAGE_RECORD_DOWNLOADED_VERSION:
|
||||
UserDefault::getInstance()->setStringForKey(((AssetsManager*)msg->obj)->keyOfDownloadedVersion().c_str(),
|
||||
((AssetsManager*)msg->obj)->_version.c_str());
|
||||
UserDefault::getInstance()->flush();
|
||||
|
||||
break;
|
||||
case ASSETSMANAGER_MESSAGE_PROGRESS:
|
||||
if (((ProgressMessage*)msg->obj)->manager->_delegate)
|
||||
{
|
||||
((ProgressMessage*)msg->obj)->manager->_delegate->onProgress(((ProgressMessage*)msg->obj)->percent);
|
||||
}
|
||||
|
||||
delete (ProgressMessage*)msg->obj;
|
||||
|
||||
break;
|
||||
case ASSETSMANAGER_MESSAGE_ERROR:
|
||||
// error call back
|
||||
if (((ErrorMessage*)msg->obj)->manager->_delegate)
|
||||
{
|
||||
((ErrorMessage*)msg->obj)->manager->_delegate->onError(((ErrorMessage*)msg->obj)->code);
|
||||
}
|
||||
|
||||
delete ((ErrorMessage*)msg->obj);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
delete msg;
|
||||
}
|
||||
|
||||
void AssetsManager::Helper::handleUpdateSucceed(Message *msg)
|
||||
{
|
||||
AssetsManager* manager = (AssetsManager*)msg->obj;
|
||||
|
||||
// Record new version code.
|
||||
UserDefault::getInstance()->setStringForKey(manager->keyOfVersion().c_str(), manager->_version.c_str());
|
||||
|
||||
// Unrecord downloaded version code.
|
||||
UserDefault::getInstance()->setStringForKey(manager->keyOfDownloadedVersion().c_str(), "");
|
||||
UserDefault::getInstance()->flush();
|
||||
|
||||
// Set resource search path.
|
||||
manager->setSearchPath();
|
||||
|
||||
// Delete unloaded zip file.
|
||||
string zipfileName = manager->_storagePath + TEMP_PACKAGE_FILE_NAME;
|
||||
if (remove(zipfileName.c_str()) != 0)
|
||||
{
|
||||
CCLOG("can not remove downloaded zip file %s", zipfileName.c_str());
|
||||
}
|
||||
|
||||
if (manager->_delegate) manager->_delegate->onSuccess();
|
||||
}
|
||||
|
||||
AssetsManager* AssetsManager::create(const char* packageUrl, const char* versionFileUrl, const char* storagePath, ErrorCallback errorCallback, ProgressCallback progressCallback, SuccessCallback successCallback )
|
||||
{
|
||||
class DelegateProtocolImpl : public AssetsManagerDelegateProtocol
|
||||
|
|
|
@ -166,40 +166,7 @@ protected:
|
|||
bool uncompress();
|
||||
bool createDirectory(const char *path);
|
||||
void setSearchPath();
|
||||
void sendErrorMessage(ErrorCode code);
|
||||
void downloadAndUncompress();
|
||||
|
||||
private:
|
||||
typedef struct _Message
|
||||
{
|
||||
public:
|
||||
_Message() : what(0), obj(NULL){}
|
||||
unsigned int what; // message type
|
||||
void* obj;
|
||||
} Message;
|
||||
|
||||
class Helper : public cocos2d::Object
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
Helper();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~Helper();
|
||||
|
||||
virtual void update(float dt);
|
||||
void sendMessage(Message *msg);
|
||||
|
||||
private:
|
||||
void handleUpdateSucceed(Message *msg);
|
||||
|
||||
std::list<Message*> *_messageQueue;
|
||||
std::mutex _messageQueueMutex;
|
||||
};
|
||||
|
||||
private:
|
||||
/** @brief Initializes storage path.
|
||||
|
@ -224,7 +191,6 @@ private:
|
|||
|
||||
void *_curl;
|
||||
|
||||
Helper *_schedule;
|
||||
unsigned int _connectionTimeout;
|
||||
|
||||
AssetsManagerDelegateProtocol *_delegate;
|
||||
|
|
|
@ -44,6 +44,7 @@ Dynamics/Joints/b2DistanceJoint.cpp \
|
|||
Dynamics/Joints/b2FrictionJoint.cpp \
|
||||
Dynamics/Joints/b2GearJoint.cpp \
|
||||
Dynamics/Joints/b2Joint.cpp \
|
||||
Dynamics/Joints/b2MotorJoint.cpp \
|
||||
Dynamics/Joints/b2MouseJoint.cpp \
|
||||
Dynamics/Joints/b2PrismaticJoint.cpp \
|
||||
Dynamics/Joints/b2PulleyJoint.cpp \
|
||||
|
|
|
@ -56,12 +56,13 @@ For discussion please visit http://box2d.org/forum
|
|||
#include <Box2D/Dynamics/Joints/b2DistanceJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2FrictionJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2GearJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2WheelJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2MotorJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2MouseJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2PrismaticJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2PulleyJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2RevoluteJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2RopeJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2WeldJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2WheelJoint.h>
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,6 +31,7 @@ set(BOX2D_SRC
|
|||
Dynamics/Joints/b2GearJoint.cpp
|
||||
Dynamics/Joints/b2Joint.cpp
|
||||
Dynamics/Joints/b2MouseJoint.cpp
|
||||
Dynamics/Joints/b2MotorJoint.cpp
|
||||
Dynamics/Joints/b2PrismaticJoint.cpp
|
||||
Dynamics/Joints/b2PulleyJoint.cpp
|
||||
Dynamics/Joints/b2RevoluteJoint.cpp
|
||||
|
|
|
@ -19,153 +19,173 @@
|
|||
#include <Box2D/Collision/Shapes/b2ChainShape.h>
|
||||
#include <Box2D/Collision/Shapes/b2EdgeShape.h>
|
||||
#include <new>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
b2ChainShape::~b2ChainShape()
|
||||
{
|
||||
b2Free(m_vertices);
|
||||
m_vertices = NULL;
|
||||
m_count = 0;
|
||||
b2Free(m_vertices);
|
||||
m_vertices = NULL;
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
void b2ChainShape::CreateLoop(const b2Vec2* vertices, int32 count)
|
||||
{
|
||||
b2Assert(m_vertices == NULL && m_count == 0);
|
||||
b2Assert(count >= 3);
|
||||
m_count = count + 1;
|
||||
m_vertices = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));
|
||||
memcpy(m_vertices, vertices, count * sizeof(b2Vec2));
|
||||
m_vertices[count] = m_vertices[0];
|
||||
m_prevVertex = m_vertices[m_count - 2];
|
||||
m_nextVertex = m_vertices[1];
|
||||
m_hasPrevVertex = true;
|
||||
m_hasNextVertex = true;
|
||||
b2Assert(m_vertices == NULL && m_count == 0);
|
||||
b2Assert(count >= 3);
|
||||
for (int32 i = 1; i < count; ++i)
|
||||
{
|
||||
b2Vec2 v1 = vertices[i-1];
|
||||
b2Vec2 v2 = vertices[i];
|
||||
// If the code crashes here, it means your vertices are too close together.
|
||||
b2Assert(b2DistanceSquared(v1, v2) > b2_linearSlop * b2_linearSlop);
|
||||
}
|
||||
|
||||
m_count = count + 1;
|
||||
m_vertices = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));
|
||||
memcpy(m_vertices, vertices, count * sizeof(b2Vec2));
|
||||
m_vertices[count] = m_vertices[0];
|
||||
m_prevVertex = m_vertices[m_count - 2];
|
||||
m_nextVertex = m_vertices[1];
|
||||
m_hasPrevVertex = true;
|
||||
m_hasNextVertex = true;
|
||||
}
|
||||
|
||||
void b2ChainShape::CreateChain(const b2Vec2* vertices, int32 count)
|
||||
{
|
||||
b2Assert(m_vertices == NULL && m_count == 0);
|
||||
b2Assert(count >= 2);
|
||||
m_count = count;
|
||||
m_vertices = (b2Vec2*)b2Alloc(count * sizeof(b2Vec2));
|
||||
memcpy(m_vertices, vertices, m_count * sizeof(b2Vec2));
|
||||
m_hasPrevVertex = false;
|
||||
m_hasNextVertex = false;
|
||||
b2Assert(m_vertices == NULL && m_count == 0);
|
||||
b2Assert(count >= 2);
|
||||
for (int32 i = 1; i < count; ++i)
|
||||
{
|
||||
b2Vec2 v1 = vertices[i-1];
|
||||
b2Vec2 v2 = vertices[i];
|
||||
// If the code crashes here, it means your vertices are too close together.
|
||||
b2Assert(b2DistanceSquared(v1, v2) > b2_linearSlop * b2_linearSlop);
|
||||
}
|
||||
|
||||
m_count = count;
|
||||
m_vertices = (b2Vec2*)b2Alloc(count * sizeof(b2Vec2));
|
||||
memcpy(m_vertices, vertices, m_count * sizeof(b2Vec2));
|
||||
|
||||
m_hasPrevVertex = false;
|
||||
m_hasNextVertex = false;
|
||||
|
||||
m_prevVertex.SetZero();
|
||||
m_nextVertex.SetZero();
|
||||
}
|
||||
|
||||
void b2ChainShape::SetPrevVertex(const b2Vec2& prevVertex)
|
||||
{
|
||||
m_prevVertex = prevVertex;
|
||||
m_hasPrevVertex = true;
|
||||
m_prevVertex = prevVertex;
|
||||
m_hasPrevVertex = true;
|
||||
}
|
||||
|
||||
void b2ChainShape::SetNextVertex(const b2Vec2& nextVertex)
|
||||
{
|
||||
m_nextVertex = nextVertex;
|
||||
m_hasNextVertex = true;
|
||||
m_nextVertex = nextVertex;
|
||||
m_hasNextVertex = true;
|
||||
}
|
||||
|
||||
b2Shape* b2ChainShape::Clone(b2BlockAllocator* allocator) const
|
||||
{
|
||||
void* mem = allocator->Allocate(sizeof(b2ChainShape));
|
||||
b2ChainShape* clone = new (mem) b2ChainShape;
|
||||
clone->CreateChain(m_vertices, m_count);
|
||||
clone->m_prevVertex = m_prevVertex;
|
||||
clone->m_nextVertex = m_nextVertex;
|
||||
clone->m_hasPrevVertex = m_hasPrevVertex;
|
||||
clone->m_hasNextVertex = m_hasNextVertex;
|
||||
return clone;
|
||||
void* mem = allocator->Allocate(sizeof(b2ChainShape));
|
||||
b2ChainShape* clone = new (mem) b2ChainShape;
|
||||
clone->CreateChain(m_vertices, m_count);
|
||||
clone->m_prevVertex = m_prevVertex;
|
||||
clone->m_nextVertex = m_nextVertex;
|
||||
clone->m_hasPrevVertex = m_hasPrevVertex;
|
||||
clone->m_hasNextVertex = m_hasNextVertex;
|
||||
return clone;
|
||||
}
|
||||
|
||||
int32 b2ChainShape::GetChildCount() const
|
||||
{
|
||||
// edge count = vertex count - 1
|
||||
return m_count - 1;
|
||||
// edge count = vertex count - 1
|
||||
return m_count - 1;
|
||||
}
|
||||
|
||||
void b2ChainShape::GetChildEdge(b2EdgeShape* edge, int32 index) const
|
||||
{
|
||||
b2Assert(0 <= index && index < m_count - 1);
|
||||
edge->m_type = b2Shape::e_edge;
|
||||
edge->m_radius = m_radius;
|
||||
b2Assert(0 <= index && index < m_count - 1);
|
||||
edge->m_type = b2Shape::e_edge;
|
||||
edge->m_radius = m_radius;
|
||||
|
||||
edge->m_vertex1 = m_vertices[index + 0];
|
||||
edge->m_vertex2 = m_vertices[index + 1];
|
||||
edge->m_vertex1 = m_vertices[index + 0];
|
||||
edge->m_vertex2 = m_vertices[index + 1];
|
||||
|
||||
if (index > 0)
|
||||
{
|
||||
edge->m_vertex0 = m_vertices[index - 1];
|
||||
edge->m_hasVertex0 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
edge->m_vertex0 = m_prevVertex;
|
||||
edge->m_hasVertex0 = m_hasPrevVertex;
|
||||
}
|
||||
if (index > 0)
|
||||
{
|
||||
edge->m_vertex0 = m_vertices[index - 1];
|
||||
edge->m_hasVertex0 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
edge->m_vertex0 = m_prevVertex;
|
||||
edge->m_hasVertex0 = m_hasPrevVertex;
|
||||
}
|
||||
|
||||
if (index < m_count - 2)
|
||||
{
|
||||
edge->m_vertex3 = m_vertices[index + 2];
|
||||
edge->m_hasVertex3 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
edge->m_vertex3 = m_nextVertex;
|
||||
edge->m_hasVertex3 = m_hasNextVertex;
|
||||
}
|
||||
if (index < m_count - 2)
|
||||
{
|
||||
edge->m_vertex3 = m_vertices[index + 2];
|
||||
edge->m_hasVertex3 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
edge->m_vertex3 = m_nextVertex;
|
||||
edge->m_hasVertex3 = m_hasNextVertex;
|
||||
}
|
||||
}
|
||||
|
||||
bool b2ChainShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
|
||||
{
|
||||
B2_NOT_USED(xf);
|
||||
B2_NOT_USED(p);
|
||||
return false;
|
||||
B2_NOT_USED(xf);
|
||||
B2_NOT_USED(p);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool b2ChainShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& xf, int32 childIndex) const
|
||||
const b2Transform& xf, int32 childIndex) const
|
||||
{
|
||||
b2Assert(childIndex < m_count);
|
||||
b2Assert(childIndex < m_count);
|
||||
|
||||
b2EdgeShape edgeShape;
|
||||
b2EdgeShape edgeShape;
|
||||
|
||||
int32 i1 = childIndex;
|
||||
int32 i2 = childIndex + 1;
|
||||
if (i2 == m_count)
|
||||
{
|
||||
i2 = 0;
|
||||
}
|
||||
int32 i1 = childIndex;
|
||||
int32 i2 = childIndex + 1;
|
||||
if (i2 == m_count)
|
||||
{
|
||||
i2 = 0;
|
||||
}
|
||||
|
||||
edgeShape.m_vertex1 = m_vertices[i1];
|
||||
edgeShape.m_vertex2 = m_vertices[i2];
|
||||
edgeShape.m_vertex1 = m_vertices[i1];
|
||||
edgeShape.m_vertex2 = m_vertices[i2];
|
||||
|
||||
return edgeShape.RayCast(output, input, xf, 0);
|
||||
return edgeShape.RayCast(output, input, xf, 0);
|
||||
}
|
||||
|
||||
void b2ChainShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
|
||||
{
|
||||
b2Assert(childIndex < m_count);
|
||||
b2Assert(childIndex < m_count);
|
||||
|
||||
int32 i1 = childIndex;
|
||||
int32 i2 = childIndex + 1;
|
||||
if (i2 == m_count)
|
||||
{
|
||||
i2 = 0;
|
||||
}
|
||||
int32 i1 = childIndex;
|
||||
int32 i2 = childIndex + 1;
|
||||
if (i2 == m_count)
|
||||
{
|
||||
i2 = 0;
|
||||
}
|
||||
|
||||
b2Vec2 v1 = b2Mul(xf, m_vertices[i1]);
|
||||
b2Vec2 v2 = b2Mul(xf, m_vertices[i2]);
|
||||
b2Vec2 v1 = b2Mul(xf, m_vertices[i1]);
|
||||
b2Vec2 v2 = b2Mul(xf, m_vertices[i2]);
|
||||
|
||||
aabb->lowerBound = b2Min(v1, v2);
|
||||
aabb->upperBound = b2Max(v1, v2);
|
||||
aabb->lowerBound = b2Min(v1, v2);
|
||||
aabb->upperBound = b2Max(v1, v2);
|
||||
}
|
||||
|
||||
void b2ChainShape::ComputeMass(b2MassData* massData, float32 density) const
|
||||
{
|
||||
B2_NOT_USED(density);
|
||||
B2_NOT_USED(density);
|
||||
|
||||
massData->mass = 0.0f;
|
||||
massData->center.SetZero();
|
||||
massData->I = 0.0f;
|
||||
massData->mass = 0.0f;
|
||||
massData->center.SetZero();
|
||||
massData->I = 0.0f;
|
||||
}
|
||||
|
|
|
@ -32,71 +32,71 @@ class b2EdgeShape;
|
|||
class b2ChainShape : public b2Shape
|
||||
{
|
||||
public:
|
||||
b2ChainShape();
|
||||
b2ChainShape();
|
||||
|
||||
/// The destructor frees the vertices using b2Free.
|
||||
~b2ChainShape();
|
||||
/// The destructor frees the vertices using b2Free.
|
||||
~b2ChainShape();
|
||||
|
||||
/// Create a loop. This automatically adjusts connectivity.
|
||||
/// @param vertices an array of vertices, these are copied
|
||||
/// @param count the vertex count
|
||||
void CreateLoop(const b2Vec2* vertices, int32 count);
|
||||
/// Create a loop. This automatically adjusts connectivity.
|
||||
/// @param vertices an array of vertices, these are copied
|
||||
/// @param count the vertex count
|
||||
void CreateLoop(const b2Vec2* vertices, int32 count);
|
||||
|
||||
/// Create a chain with isolated end vertices.
|
||||
/// @param vertices an array of vertices, these are copied
|
||||
/// @param count the vertex count
|
||||
void CreateChain(const b2Vec2* vertices, int32 count);
|
||||
/// Create a chain with isolated end vertices.
|
||||
/// @param vertices an array of vertices, these are copied
|
||||
/// @param count the vertex count
|
||||
void CreateChain(const b2Vec2* vertices, int32 count);
|
||||
|
||||
/// Establish connectivity to a vertex that precedes the first vertex.
|
||||
/// Don't call this for loops.
|
||||
void SetPrevVertex(const b2Vec2& prevVertex);
|
||||
/// Establish connectivity to a vertex that precedes the first vertex.
|
||||
/// Don't call this for loops.
|
||||
void SetPrevVertex(const b2Vec2& prevVertex);
|
||||
|
||||
/// Establish connectivity to a vertex that follows the last vertex.
|
||||
/// Don't call this for loops.
|
||||
void SetNextVertex(const b2Vec2& nextVertex);
|
||||
/// Establish connectivity to a vertex that follows the last vertex.
|
||||
/// Don't call this for loops.
|
||||
void SetNextVertex(const b2Vec2& nextVertex);
|
||||
|
||||
/// Implement b2Shape. Vertices are cloned using b2Alloc.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
/// Implement b2Shape. Vertices are cloned using b2Alloc.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
|
||||
/// Get a child edge.
|
||||
void GetChildEdge(b2EdgeShape* edge, int32 index) const;
|
||||
/// Get a child edge.
|
||||
void GetChildEdge(b2EdgeShape* edge, int32 index) const;
|
||||
|
||||
/// This always return false.
|
||||
/// @see b2Shape::TestPoint
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
/// This always return false.
|
||||
/// @see b2Shape::TestPoint
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// Chains have zero mass.
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
/// Chains have zero mass.
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
|
||||
/// The vertices. Owned by this class.
|
||||
b2Vec2* m_vertices;
|
||||
/// The vertices. Owned by this class.
|
||||
b2Vec2* m_vertices;
|
||||
|
||||
/// The vertex count.
|
||||
int32 m_count;
|
||||
/// The vertex count.
|
||||
int32 m_count;
|
||||
|
||||
b2Vec2 m_prevVertex, m_nextVertex;
|
||||
bool m_hasPrevVertex, m_hasNextVertex;
|
||||
b2Vec2 m_prevVertex, m_nextVertex;
|
||||
bool m_hasPrevVertex, m_hasNextVertex;
|
||||
};
|
||||
|
||||
inline b2ChainShape::b2ChainShape()
|
||||
{
|
||||
m_type = e_chain;
|
||||
m_radius = b2_polygonRadius;
|
||||
m_vertices = NULL;
|
||||
m_count = 0;
|
||||
m_hasPrevVertex = false;
|
||||
m_hasNextVertex = false;
|
||||
m_type = e_chain;
|
||||
m_radius = b2_polygonRadius;
|
||||
m_vertices = NULL;
|
||||
m_count = 0;
|
||||
m_hasPrevVertex = false;
|
||||
m_hasNextVertex = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,26 +18,25 @@
|
|||
|
||||
#include <Box2D/Collision/Shapes/b2CircleShape.h>
|
||||
#include <new>
|
||||
using namespace std;
|
||||
|
||||
b2Shape* b2CircleShape::Clone(b2BlockAllocator* allocator) const
|
||||
{
|
||||
void* mem = allocator->Allocate(sizeof(b2CircleShape));
|
||||
b2CircleShape* clone = new (mem) b2CircleShape;
|
||||
*clone = *this;
|
||||
return clone;
|
||||
void* mem = allocator->Allocate(sizeof(b2CircleShape));
|
||||
b2CircleShape* clone = new (mem) b2CircleShape;
|
||||
*clone = *this;
|
||||
return clone;
|
||||
}
|
||||
|
||||
int32 b2CircleShape::GetChildCount() const
|
||||
{
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool b2CircleShape::TestPoint(const b2Transform& transform, const b2Vec2& p) const
|
||||
{
|
||||
b2Vec2 center = transform.p + b2Mul(transform.q, m_p);
|
||||
b2Vec2 d = p - center;
|
||||
return b2Dot(d, d) <= m_radius * m_radius;
|
||||
b2Vec2 center = transform.p + b2Mul(transform.q, m_p);
|
||||
b2Vec2 d = p - center;
|
||||
return b2Dot(d, d) <= m_radius * m_radius;
|
||||
}
|
||||
|
||||
// Collision Detection in Interactive 3D Environments by Gino van den Bergen
|
||||
|
@ -45,56 +44,56 @@ bool b2CircleShape::TestPoint(const b2Transform& transform, const b2Vec2& p) con
|
|||
// x = s + a * r
|
||||
// norm(x) = radius
|
||||
bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const
|
||||
const b2Transform& transform, int32 childIndex) const
|
||||
{
|
||||
B2_NOT_USED(childIndex);
|
||||
B2_NOT_USED(childIndex);
|
||||
|
||||
b2Vec2 position = transform.p + b2Mul(transform.q, m_p);
|
||||
b2Vec2 s = input.p1 - position;
|
||||
float32 b = b2Dot(s, s) - m_radius * m_radius;
|
||||
b2Vec2 position = transform.p + b2Mul(transform.q, m_p);
|
||||
b2Vec2 s = input.p1 - position;
|
||||
float32 b = b2Dot(s, s) - m_radius * m_radius;
|
||||
|
||||
// Solve quadratic equation.
|
||||
b2Vec2 r = input.p2 - input.p1;
|
||||
float32 c = b2Dot(s, r);
|
||||
float32 rr = b2Dot(r, r);
|
||||
float32 sigma = c * c - rr * b;
|
||||
// Solve quadratic equation.
|
||||
b2Vec2 r = input.p2 - input.p1;
|
||||
float32 c = b2Dot(s, r);
|
||||
float32 rr = b2Dot(r, r);
|
||||
float32 sigma = c * c - rr * b;
|
||||
|
||||
// Check for negative discriminant and short segment.
|
||||
if (sigma < 0.0f || rr < b2_epsilon)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Check for negative discriminant and short segment.
|
||||
if (sigma < 0.0f || rr < b2_epsilon)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find the point of intersection of the line with the circle.
|
||||
float32 a = -(c + b2Sqrt(sigma));
|
||||
// Find the point of intersection of the line with the circle.
|
||||
float32 a = -(c + b2Sqrt(sigma));
|
||||
|
||||
// Is the intersection point on the segment?
|
||||
if (0.0f <= a && a <= input.maxFraction * rr)
|
||||
{
|
||||
a /= rr;
|
||||
output->fraction = a;
|
||||
output->normal = s + a * r;
|
||||
output->normal.Normalize();
|
||||
return true;
|
||||
}
|
||||
// Is the intersection point on the segment?
|
||||
if (0.0f <= a && a <= input.maxFraction * rr)
|
||||
{
|
||||
a /= rr;
|
||||
output->fraction = a;
|
||||
output->normal = s + a * r;
|
||||
output->normal.Normalize();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void b2CircleShape::ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const
|
||||
{
|
||||
B2_NOT_USED(childIndex);
|
||||
B2_NOT_USED(childIndex);
|
||||
|
||||
b2Vec2 p = transform.p + b2Mul(transform.q, m_p);
|
||||
aabb->lowerBound.Set(p.x - m_radius, p.y - m_radius);
|
||||
aabb->upperBound.Set(p.x + m_radius, p.y + m_radius);
|
||||
b2Vec2 p = transform.p + b2Mul(transform.q, m_p);
|
||||
aabb->lowerBound.Set(p.x - m_radius, p.y - m_radius);
|
||||
aabb->upperBound.Set(p.x + m_radius, p.y + m_radius);
|
||||
}
|
||||
|
||||
void b2CircleShape::ComputeMass(b2MassData* massData, float32 density) const
|
||||
{
|
||||
massData->mass = density * b2_pi * m_radius * m_radius;
|
||||
massData->center = m_p;
|
||||
massData->mass = density * b2_pi * m_radius * m_radius;
|
||||
massData->center = m_p;
|
||||
|
||||
// inertia about the local origin
|
||||
massData->I = massData->mass * (0.5f * m_radius * m_radius + b2Dot(m_p, m_p));
|
||||
// inertia about the local origin
|
||||
massData->I = massData->mass * (0.5f * m_radius * m_radius + b2Dot(m_p, m_p));
|
||||
}
|
||||
|
|
|
@ -25,67 +25,67 @@
|
|||
class b2CircleShape : public b2Shape
|
||||
{
|
||||
public:
|
||||
b2CircleShape();
|
||||
b2CircleShape();
|
||||
|
||||
/// Implement b2Shape.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
/// Implement b2Shape.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
|
||||
/// Implement b2Shape.
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
/// Implement b2Shape.
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
|
||||
/// Get the supporting vertex index in the given direction.
|
||||
int32 GetSupport(const b2Vec2& d) const;
|
||||
/// Get the supporting vertex index in the given direction.
|
||||
int32 GetSupport(const b2Vec2& d) const;
|
||||
|
||||
/// Get the supporting vertex in the given direction.
|
||||
const b2Vec2& GetSupportVertex(const b2Vec2& d) const;
|
||||
/// Get the supporting vertex in the given direction.
|
||||
const b2Vec2& GetSupportVertex(const b2Vec2& d) const;
|
||||
|
||||
/// Get the vertex count.
|
||||
int32 GetVertexCount() const { return 1; }
|
||||
/// Get the vertex count.
|
||||
int32 GetVertexCount() const { return 1; }
|
||||
|
||||
/// Get a vertex by index. Used by b2Distance.
|
||||
const b2Vec2& GetVertex(int32 index) const;
|
||||
/// Get a vertex by index. Used by b2Distance.
|
||||
const b2Vec2& GetVertex(int32 index) const;
|
||||
|
||||
/// Position
|
||||
b2Vec2 m_p;
|
||||
/// Position
|
||||
b2Vec2 m_p;
|
||||
};
|
||||
|
||||
inline b2CircleShape::b2CircleShape()
|
||||
{
|
||||
m_type = e_circle;
|
||||
m_radius = 0.0f;
|
||||
m_p.SetZero();
|
||||
m_type = e_circle;
|
||||
m_radius = 0.0f;
|
||||
m_p.SetZero();
|
||||
}
|
||||
|
||||
inline int32 b2CircleShape::GetSupport(const b2Vec2 &d) const
|
||||
{
|
||||
B2_NOT_USED(d);
|
||||
return 0;
|
||||
B2_NOT_USED(d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2CircleShape::GetSupportVertex(const b2Vec2 &d) const
|
||||
{
|
||||
B2_NOT_USED(d);
|
||||
return m_p;
|
||||
B2_NOT_USED(d);
|
||||
return m_p;
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2CircleShape::GetVertex(int32 index) const
|
||||
{
|
||||
B2_NOT_USED(index);
|
||||
b2Assert(index == 0);
|
||||
return m_p;
|
||||
B2_NOT_USED(index);
|
||||
b2Assert(index == 0);
|
||||
return m_p;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,34 +18,33 @@
|
|||
|
||||
#include <Box2D/Collision/Shapes/b2EdgeShape.h>
|
||||
#include <new>
|
||||
using namespace std;
|
||||
|
||||
void b2EdgeShape::Set(const b2Vec2& v1, const b2Vec2& v2)
|
||||
{
|
||||
m_vertex1 = v1;
|
||||
m_vertex2 = v2;
|
||||
m_hasVertex0 = false;
|
||||
m_hasVertex3 = false;
|
||||
m_vertex1 = v1;
|
||||
m_vertex2 = v2;
|
||||
m_hasVertex0 = false;
|
||||
m_hasVertex3 = false;
|
||||
}
|
||||
|
||||
b2Shape* b2EdgeShape::Clone(b2BlockAllocator* allocator) const
|
||||
{
|
||||
void* mem = allocator->Allocate(sizeof(b2EdgeShape));
|
||||
b2EdgeShape* clone = new (mem) b2EdgeShape;
|
||||
*clone = *this;
|
||||
return clone;
|
||||
void* mem = allocator->Allocate(sizeof(b2EdgeShape));
|
||||
b2EdgeShape* clone = new (mem) b2EdgeShape;
|
||||
*clone = *this;
|
||||
return clone;
|
||||
}
|
||||
|
||||
int32 b2EdgeShape::GetChildCount() const
|
||||
{
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool b2EdgeShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
|
||||
{
|
||||
B2_NOT_USED(xf);
|
||||
B2_NOT_USED(p);
|
||||
return false;
|
||||
B2_NOT_USED(xf);
|
||||
B2_NOT_USED(p);
|
||||
return false;
|
||||
}
|
||||
|
||||
// p = p1 + t * d
|
||||
|
@ -53,87 +52,87 @@ bool b2EdgeShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
|
|||
// p1 + t * d = v1 + s * e
|
||||
// s * e - t * d = p1 - v1
|
||||
bool b2EdgeShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& xf, int32 childIndex) const
|
||||
const b2Transform& xf, int32 childIndex) const
|
||||
{
|
||||
B2_NOT_USED(childIndex);
|
||||
B2_NOT_USED(childIndex);
|
||||
|
||||
// Put the ray into the edge's frame of reference.
|
||||
b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
|
||||
b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
|
||||
b2Vec2 d = p2 - p1;
|
||||
// Put the ray into the edge's frame of reference.
|
||||
b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
|
||||
b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
|
||||
b2Vec2 d = p2 - p1;
|
||||
|
||||
b2Vec2 v1 = m_vertex1;
|
||||
b2Vec2 v2 = m_vertex2;
|
||||
b2Vec2 e = v2 - v1;
|
||||
b2Vec2 normal(e.y, -e.x);
|
||||
normal.Normalize();
|
||||
b2Vec2 v1 = m_vertex1;
|
||||
b2Vec2 v2 = m_vertex2;
|
||||
b2Vec2 e = v2 - v1;
|
||||
b2Vec2 normal(e.y, -e.x);
|
||||
normal.Normalize();
|
||||
|
||||
// q = p1 + t * d
|
||||
// dot(normal, q - v1) = 0
|
||||
// dot(normal, p1 - v1) + t * dot(normal, d) = 0
|
||||
float32 numerator = b2Dot(normal, v1 - p1);
|
||||
float32 denominator = b2Dot(normal, d);
|
||||
// q = p1 + t * d
|
||||
// dot(normal, q - v1) = 0
|
||||
// dot(normal, p1 - v1) + t * dot(normal, d) = 0
|
||||
float32 numerator = b2Dot(normal, v1 - p1);
|
||||
float32 denominator = b2Dot(normal, d);
|
||||
|
||||
if (denominator == 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (denominator == 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float32 t = numerator / denominator;
|
||||
if (t < 0.0f || input.maxFraction < t)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
float32 t = numerator / denominator;
|
||||
if (t < 0.0f || input.maxFraction < t)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
b2Vec2 q = p1 + t * d;
|
||||
b2Vec2 q = p1 + t * d;
|
||||
|
||||
// q = v1 + s * r
|
||||
// s = dot(q - v1, r) / dot(r, r)
|
||||
b2Vec2 r = v2 - v1;
|
||||
float32 rr = b2Dot(r, r);
|
||||
if (rr == 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// q = v1 + s * r
|
||||
// s = dot(q - v1, r) / dot(r, r)
|
||||
b2Vec2 r = v2 - v1;
|
||||
float32 rr = b2Dot(r, r);
|
||||
if (rr == 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float32 s = b2Dot(q - v1, r) / rr;
|
||||
if (s < 0.0f || 1.0f < s)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
float32 s = b2Dot(q - v1, r) / rr;
|
||||
if (s < 0.0f || 1.0f < s)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
output->fraction = t;
|
||||
if (numerator > 0.0f)
|
||||
{
|
||||
output->normal = -normal;
|
||||
}
|
||||
else
|
||||
{
|
||||
output->normal = normal;
|
||||
}
|
||||
return true;
|
||||
output->fraction = t;
|
||||
if (numerator > 0.0f)
|
||||
{
|
||||
output->normal = -b2Mul(xf.q, normal);
|
||||
}
|
||||
else
|
||||
{
|
||||
output->normal = b2Mul(xf.q, normal);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void b2EdgeShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
|
||||
{
|
||||
B2_NOT_USED(childIndex);
|
||||
B2_NOT_USED(childIndex);
|
||||
|
||||
b2Vec2 v1 = b2Mul(xf, m_vertex1);
|
||||
b2Vec2 v2 = b2Mul(xf, m_vertex2);
|
||||
b2Vec2 v1 = b2Mul(xf, m_vertex1);
|
||||
b2Vec2 v2 = b2Mul(xf, m_vertex2);
|
||||
|
||||
b2Vec2 lower = b2Min(v1, v2);
|
||||
b2Vec2 upper = b2Max(v1, v2);
|
||||
b2Vec2 lower = b2Min(v1, v2);
|
||||
b2Vec2 upper = b2Max(v1, v2);
|
||||
|
||||
b2Vec2 r(m_radius, m_radius);
|
||||
aabb->lowerBound = lower - r;
|
||||
aabb->upperBound = upper + r;
|
||||
b2Vec2 r(m_radius, m_radius);
|
||||
aabb->lowerBound = lower - r;
|
||||
aabb->upperBound = upper + r;
|
||||
}
|
||||
|
||||
void b2EdgeShape::ComputeMass(b2MassData* massData, float32 density) const
|
||||
{
|
||||
B2_NOT_USED(density);
|
||||
B2_NOT_USED(density);
|
||||
|
||||
massData->mass = 0.0f;
|
||||
massData->center = 0.5f * (m_vertex1 + m_vertex2);
|
||||
massData->I = 0.0f;
|
||||
massData->mass = 0.0f;
|
||||
massData->center = 0.5f * (m_vertex1 + m_vertex2);
|
||||
massData->I = 0.0f;
|
||||
}
|
||||
|
|
|
@ -27,48 +27,48 @@
|
|||
class b2EdgeShape : public b2Shape
|
||||
{
|
||||
public:
|
||||
b2EdgeShape();
|
||||
b2EdgeShape();
|
||||
|
||||
/// Set this as an isolated edge.
|
||||
void Set(const b2Vec2& v1, const b2Vec2& v2);
|
||||
/// Set this as an isolated edge.
|
||||
void Set(const b2Vec2& v1, const b2Vec2& v2);
|
||||
|
||||
/// Implement b2Shape.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
/// Implement b2Shape.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
|
||||
/// @see b2Shape::TestPoint
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
/// @see b2Shape::TestPoint
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
|
||||
/// These are the edge vertices
|
||||
b2Vec2 m_vertex1, m_vertex2;
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
|
||||
/// These are the edge vertices
|
||||
b2Vec2 m_vertex1, m_vertex2;
|
||||
|
||||
/// Optional adjacent vertices. These are used for smooth collision.
|
||||
b2Vec2 m_vertex0, m_vertex3;
|
||||
bool m_hasVertex0, m_hasVertex3;
|
||||
/// Optional adjacent vertices. These are used for smooth collision.
|
||||
b2Vec2 m_vertex0, m_vertex3;
|
||||
bool m_hasVertex0, m_hasVertex3;
|
||||
};
|
||||
|
||||
inline b2EdgeShape::b2EdgeShape()
|
||||
{
|
||||
m_type = e_edge;
|
||||
m_radius = b2_polygonRadius;
|
||||
m_vertex0.x = 0.0f;
|
||||
m_vertex0.y = 0.0f;
|
||||
m_vertex3.x = 0.0f;
|
||||
m_vertex3.y = 0.0f;
|
||||
m_hasVertex0 = false;
|
||||
m_hasVertex3 = false;
|
||||
m_type = e_edge;
|
||||
m_radius = b2_polygonRadius;
|
||||
m_vertex0.x = 0.0f;
|
||||
m_vertex0.y = 0.0f;
|
||||
m_vertex3.x = 0.0f;
|
||||
m_vertex3.y = 0.0f;
|
||||
m_hasVertex0 = false;
|
||||
m_hasVertex3 = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,341 +21,439 @@
|
|||
|
||||
b2Shape* b2PolygonShape::Clone(b2BlockAllocator* allocator) const
|
||||
{
|
||||
void* mem = allocator->Allocate(sizeof(b2PolygonShape));
|
||||
b2PolygonShape* clone = new (mem) b2PolygonShape;
|
||||
*clone = *this;
|
||||
return clone;
|
||||
void* mem = allocator->Allocate(sizeof(b2PolygonShape));
|
||||
b2PolygonShape* clone = new (mem) b2PolygonShape;
|
||||
*clone = *this;
|
||||
return clone;
|
||||
}
|
||||
|
||||
void b2PolygonShape::SetAsBox(float32 hx, float32 hy)
|
||||
{
|
||||
m_vertexCount = 4;
|
||||
m_vertices[0].Set(-hx, -hy);
|
||||
m_vertices[1].Set( hx, -hy);
|
||||
m_vertices[2].Set( hx, hy);
|
||||
m_vertices[3].Set(-hx, hy);
|
||||
m_normals[0].Set(0.0f, -1.0f);
|
||||
m_normals[1].Set(1.0f, 0.0f);
|
||||
m_normals[2].Set(0.0f, 1.0f);
|
||||
m_normals[3].Set(-1.0f, 0.0f);
|
||||
m_centroid.SetZero();
|
||||
m_count = 4;
|
||||
m_vertices[0].Set(-hx, -hy);
|
||||
m_vertices[1].Set( hx, -hy);
|
||||
m_vertices[2].Set( hx, hy);
|
||||
m_vertices[3].Set(-hx, hy);
|
||||
m_normals[0].Set(0.0f, -1.0f);
|
||||
m_normals[1].Set(1.0f, 0.0f);
|
||||
m_normals[2].Set(0.0f, 1.0f);
|
||||
m_normals[3].Set(-1.0f, 0.0f);
|
||||
m_centroid.SetZero();
|
||||
}
|
||||
|
||||
void b2PolygonShape::SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle)
|
||||
{
|
||||
m_vertexCount = 4;
|
||||
m_vertices[0].Set(-hx, -hy);
|
||||
m_vertices[1].Set( hx, -hy);
|
||||
m_vertices[2].Set( hx, hy);
|
||||
m_vertices[3].Set(-hx, hy);
|
||||
m_normals[0].Set(0.0f, -1.0f);
|
||||
m_normals[1].Set(1.0f, 0.0f);
|
||||
m_normals[2].Set(0.0f, 1.0f);
|
||||
m_normals[3].Set(-1.0f, 0.0f);
|
||||
m_centroid = center;
|
||||
m_count = 4;
|
||||
m_vertices[0].Set(-hx, -hy);
|
||||
m_vertices[1].Set( hx, -hy);
|
||||
m_vertices[2].Set( hx, hy);
|
||||
m_vertices[3].Set(-hx, hy);
|
||||
m_normals[0].Set(0.0f, -1.0f);
|
||||
m_normals[1].Set(1.0f, 0.0f);
|
||||
m_normals[2].Set(0.0f, 1.0f);
|
||||
m_normals[3].Set(-1.0f, 0.0f);
|
||||
m_centroid = center;
|
||||
|
||||
b2Transform xf;
|
||||
xf.p = center;
|
||||
xf.q.Set(angle);
|
||||
b2Transform xf;
|
||||
xf.p = center;
|
||||
xf.q.Set(angle);
|
||||
|
||||
// Transform vertices and normals.
|
||||
for (int32 i = 0; i < m_vertexCount; ++i)
|
||||
{
|
||||
m_vertices[i] = b2Mul(xf, m_vertices[i]);
|
||||
m_normals[i] = b2Mul(xf.q, m_normals[i]);
|
||||
}
|
||||
// Transform vertices and normals.
|
||||
for (int32 i = 0; i < m_count; ++i)
|
||||
{
|
||||
m_vertices[i] = b2Mul(xf, m_vertices[i]);
|
||||
m_normals[i] = b2Mul(xf.q, m_normals[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int32 b2PolygonShape::GetChildCount() const
|
||||
{
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static b2Vec2 ComputeCentroid(const b2Vec2* vs, int32 count)
|
||||
{
|
||||
b2Assert(count >= 3);
|
||||
b2Assert(count >= 3);
|
||||
|
||||
b2Vec2 c; c.Set(0.0f, 0.0f);
|
||||
float32 area = 0.0f;
|
||||
b2Vec2 c; c.Set(0.0f, 0.0f);
|
||||
float32 area = 0.0f;
|
||||
|
||||
// pRef is the reference point for forming triangles.
|
||||
// It's location doesn't change the result (except for rounding error).
|
||||
b2Vec2 pRef(0.0f, 0.0f);
|
||||
// pRef is the reference point for forming triangles.
|
||||
// It's location doesn't change the result (except for rounding error).
|
||||
b2Vec2 pRef(0.0f, 0.0f);
|
||||
#if 0
|
||||
// This code would put the reference point inside the polygon.
|
||||
for (int32 i = 0; i < count; ++i)
|
||||
{
|
||||
pRef += vs[i];
|
||||
}
|
||||
pRef *= 1.0f / count;
|
||||
// This code would put the reference point inside the polygon.
|
||||
for (int32 i = 0; i < count; ++i)
|
||||
{
|
||||
pRef += vs[i];
|
||||
}
|
||||
pRef *= 1.0f / count;
|
||||
#endif
|
||||
|
||||
const float32 inv3 = 1.0f / 3.0f;
|
||||
const float32 inv3 = 1.0f / 3.0f;
|
||||
|
||||
for (int32 i = 0; i < count; ++i)
|
||||
{
|
||||
// Triangle vertices.
|
||||
b2Vec2 p1 = pRef;
|
||||
b2Vec2 p2 = vs[i];
|
||||
b2Vec2 p3 = i + 1 < count ? vs[i+1] : vs[0];
|
||||
for (int32 i = 0; i < count; ++i)
|
||||
{
|
||||
// Triangle vertices.
|
||||
b2Vec2 p1 = pRef;
|
||||
b2Vec2 p2 = vs[i];
|
||||
b2Vec2 p3 = i + 1 < count ? vs[i+1] : vs[0];
|
||||
|
||||
b2Vec2 e1 = p2 - p1;
|
||||
b2Vec2 e2 = p3 - p1;
|
||||
b2Vec2 e1 = p2 - p1;
|
||||
b2Vec2 e2 = p3 - p1;
|
||||
|
||||
float32 D = b2Cross(e1, e2);
|
||||
float32 D = b2Cross(e1, e2);
|
||||
|
||||
float32 triangleArea = 0.5f * D;
|
||||
area += triangleArea;
|
||||
float32 triangleArea = 0.5f * D;
|
||||
area += triangleArea;
|
||||
|
||||
// Area weighted centroid
|
||||
c += triangleArea * inv3 * (p1 + p2 + p3);
|
||||
}
|
||||
// Area weighted centroid
|
||||
c += triangleArea * inv3 * (p1 + p2 + p3);
|
||||
}
|
||||
|
||||
// Centroid
|
||||
b2Assert(area > b2_epsilon);
|
||||
c *= 1.0f / area;
|
||||
return c;
|
||||
// Centroid
|
||||
b2Assert(area > b2_epsilon);
|
||||
c *= 1.0f / area;
|
||||
return c;
|
||||
}
|
||||
|
||||
void b2PolygonShape::Set(const b2Vec2* vertices, int32 count)
|
||||
{
|
||||
b2Assert(3 <= count && count <= b2_maxPolygonVertices);
|
||||
m_vertexCount = count;
|
||||
b2Assert(3 <= count && count <= b2_maxPolygonVertices);
|
||||
if (count < 3)
|
||||
{
|
||||
SetAsBox(1.0f, 1.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
int32 n = b2Min(count, b2_maxPolygonVertices);
|
||||
|
||||
// Copy vertices.
|
||||
for (int32 i = 0; i < m_vertexCount; ++i)
|
||||
{
|
||||
m_vertices[i] = vertices[i];
|
||||
}
|
||||
// Perform welding and copy vertices into local buffer.
|
||||
b2Vec2 ps[b2_maxPolygonVertices];
|
||||
int32 tempCount = 0;
|
||||
for (int32 i = 0; i < n; ++i)
|
||||
{
|
||||
b2Vec2 v = vertices[i];
|
||||
|
||||
// Compute normals. Ensure the edges have non-zero length.
|
||||
for (int32 i = 0; i < m_vertexCount; ++i)
|
||||
{
|
||||
int32 i1 = i;
|
||||
int32 i2 = i + 1 < m_vertexCount ? i + 1 : 0;
|
||||
b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
|
||||
b2Assert(edge.LengthSquared() > b2_epsilon * b2_epsilon);
|
||||
m_normals[i] = b2Cross(edge, 1.0f);
|
||||
m_normals[i].Normalize();
|
||||
}
|
||||
bool unique = true;
|
||||
for (int32 j = 0; j < tempCount; ++j)
|
||||
{
|
||||
if (b2DistanceSquared(v, ps[j]) < 0.5f * b2_linearSlop)
|
||||
{
|
||||
unique = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Ensure the polygon is convex and the interior
|
||||
// is to the left of each edge.
|
||||
for (int32 i = 0; i < m_vertexCount; ++i)
|
||||
{
|
||||
int32 i1 = i;
|
||||
int32 i2 = i + 1 < m_vertexCount ? i + 1 : 0;
|
||||
b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
|
||||
if (unique)
|
||||
{
|
||||
ps[tempCount++] = v;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32 j = 0; j < m_vertexCount; ++j)
|
||||
{
|
||||
// Don't check vertices on the current edge.
|
||||
if (j == i1 || j == i2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
b2Vec2 r = m_vertices[j] - m_vertices[i1];
|
||||
n = tempCount;
|
||||
if (n < 3)
|
||||
{
|
||||
// Polygon is degenerate.
|
||||
b2Assert(false);
|
||||
SetAsBox(1.0f, 1.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
// If this crashes, your polygon is non-convex, has colinear edges,
|
||||
// or the winding order is wrong.
|
||||
float32 s = b2Cross(edge, r);
|
||||
b2Assert(s > 0.0f && "ERROR: Please ensure your polygon is convex and has a CCW winding order");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Create the convex hull using the Gift wrapping algorithm
|
||||
// http://en.wikipedia.org/wiki/Gift_wrapping_algorithm
|
||||
|
||||
// Compute the polygon centroid.
|
||||
m_centroid = ComputeCentroid(m_vertices, m_vertexCount);
|
||||
// Find the right most point on the hull
|
||||
int32 i0 = 0;
|
||||
float32 x0 = ps[0].x;
|
||||
for (int32 i = 1; i < n; ++i)
|
||||
{
|
||||
float32 x = ps[i].x;
|
||||
if (x > x0 || (x == x0 && ps[i].y < ps[i0].y))
|
||||
{
|
||||
i0 = i;
|
||||
x0 = x;
|
||||
}
|
||||
}
|
||||
|
||||
int32 hull[b2_maxPolygonVertices];
|
||||
int32 m = 0;
|
||||
int32 ih = i0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
hull[m] = ih;
|
||||
|
||||
int32 ie = 0;
|
||||
for (int32 j = 1; j < n; ++j)
|
||||
{
|
||||
if (ie == ih)
|
||||
{
|
||||
ie = j;
|
||||
continue;
|
||||
}
|
||||
|
||||
b2Vec2 r = ps[ie] - ps[hull[m]];
|
||||
b2Vec2 v = ps[j] - ps[hull[m]];
|
||||
float32 c = b2Cross(r, v);
|
||||
if (c < 0.0f)
|
||||
{
|
||||
ie = j;
|
||||
}
|
||||
|
||||
// Collinearity check
|
||||
if (c == 0.0f && v.LengthSquared() > r.LengthSquared())
|
||||
{
|
||||
ie = j;
|
||||
}
|
||||
}
|
||||
|
||||
++m;
|
||||
ih = ie;
|
||||
|
||||
if (ie == i0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_count = m;
|
||||
|
||||
// Copy vertices.
|
||||
for (int32 i = 0; i < m; ++i)
|
||||
{
|
||||
m_vertices[i] = ps[hull[i]];
|
||||
}
|
||||
|
||||
// Compute normals. Ensure the edges have non-zero length.
|
||||
for (int32 i = 0; i < m; ++i)
|
||||
{
|
||||
int32 i1 = i;
|
||||
int32 i2 = i + 1 < m ? i + 1 : 0;
|
||||
b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
|
||||
b2Assert(edge.LengthSquared() > b2_epsilon * b2_epsilon);
|
||||
m_normals[i] = b2Cross(edge, 1.0f);
|
||||
m_normals[i].Normalize();
|
||||
}
|
||||
|
||||
// Compute the polygon centroid.
|
||||
m_centroid = ComputeCentroid(m_vertices, m);
|
||||
}
|
||||
|
||||
bool b2PolygonShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
|
||||
{
|
||||
b2Vec2 pLocal = b2MulT(xf.q, p - xf.p);
|
||||
b2Vec2 pLocal = b2MulT(xf.q, p - xf.p);
|
||||
|
||||
for (int32 i = 0; i < m_vertexCount; ++i)
|
||||
{
|
||||
float32 dot = b2Dot(m_normals[i], pLocal - m_vertices[i]);
|
||||
if (dot > 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (int32 i = 0; i < m_count; ++i)
|
||||
{
|
||||
float32 dot = b2Dot(m_normals[i], pLocal - m_vertices[i]);
|
||||
if (dot > 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool b2PolygonShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& xf, int32 childIndex) const
|
||||
const b2Transform& xf, int32 childIndex) const
|
||||
{
|
||||
B2_NOT_USED(childIndex);
|
||||
B2_NOT_USED(childIndex);
|
||||
|
||||
// Put the ray into the polygon's frame of reference.
|
||||
b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
|
||||
b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
|
||||
b2Vec2 d = p2 - p1;
|
||||
// Put the ray into the polygon's frame of reference.
|
||||
b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
|
||||
b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
|
||||
b2Vec2 d = p2 - p1;
|
||||
|
||||
float32 lower = 0.0f, upper = input.maxFraction;
|
||||
float32 lower = 0.0f, upper = input.maxFraction;
|
||||
|
||||
int32 index = -1;
|
||||
int32 index = -1;
|
||||
|
||||
for (int32 i = 0; i < m_vertexCount; ++i)
|
||||
{
|
||||
// p = p1 + a * d
|
||||
// dot(normal, p - v) = 0
|
||||
// dot(normal, p1 - v) + a * dot(normal, d) = 0
|
||||
float32 numerator = b2Dot(m_normals[i], m_vertices[i] - p1);
|
||||
float32 denominator = b2Dot(m_normals[i], d);
|
||||
for (int32 i = 0; i < m_count; ++i)
|
||||
{
|
||||
// p = p1 + a * d
|
||||
// dot(normal, p - v) = 0
|
||||
// dot(normal, p1 - v) + a * dot(normal, d) = 0
|
||||
float32 numerator = b2Dot(m_normals[i], m_vertices[i] - p1);
|
||||
float32 denominator = b2Dot(m_normals[i], d);
|
||||
|
||||
if (denominator == 0.0f)
|
||||
{
|
||||
if (numerator < 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Note: we want this predicate without division:
|
||||
// lower < numerator / denominator, where denominator < 0
|
||||
// Since denominator < 0, we have to flip the inequality:
|
||||
// lower < numerator / denominator <==> denominator * lower > numerator.
|
||||
if (denominator < 0.0f && numerator < lower * denominator)
|
||||
{
|
||||
// Increase lower.
|
||||
// The segment enters this half-space.
|
||||
lower = numerator / denominator;
|
||||
index = i;
|
||||
}
|
||||
else if (denominator > 0.0f && numerator < upper * denominator)
|
||||
{
|
||||
// Decrease upper.
|
||||
// The segment exits this half-space.
|
||||
upper = numerator / denominator;
|
||||
}
|
||||
}
|
||||
if (denominator == 0.0f)
|
||||
{
|
||||
if (numerator < 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Note: we want this predicate without division:
|
||||
// lower < numerator / denominator, where denominator < 0
|
||||
// Since denominator < 0, we have to flip the inequality:
|
||||
// lower < numerator / denominator <==> denominator * lower > numerator.
|
||||
if (denominator < 0.0f && numerator < lower * denominator)
|
||||
{
|
||||
// Increase lower.
|
||||
// The segment enters this half-space.
|
||||
lower = numerator / denominator;
|
||||
index = i;
|
||||
}
|
||||
else if (denominator > 0.0f && numerator < upper * denominator)
|
||||
{
|
||||
// Decrease upper.
|
||||
// The segment exits this half-space.
|
||||
upper = numerator / denominator;
|
||||
}
|
||||
}
|
||||
|
||||
// The use of epsilon here causes the assert on lower to trip
|
||||
// in some cases. Apparently the use of epsilon was to make edge
|
||||
// shapes work, but now those are handled separately.
|
||||
//if (upper < lower - b2_epsilon)
|
||||
if (upper < lower)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// The use of epsilon here causes the assert on lower to trip
|
||||
// in some cases. Apparently the use of epsilon was to make edge
|
||||
// shapes work, but now those are handled separately.
|
||||
//if (upper < lower - b2_epsilon)
|
||||
if (upper < lower)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
b2Assert(0.0f <= lower && lower <= input.maxFraction);
|
||||
b2Assert(0.0f <= lower && lower <= input.maxFraction);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
output->fraction = lower;
|
||||
output->normal = b2Mul(xf.q, m_normals[index]);
|
||||
return true;
|
||||
}
|
||||
if (index >= 0)
|
||||
{
|
||||
output->fraction = lower;
|
||||
output->normal = b2Mul(xf.q, m_normals[index]);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void b2PolygonShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
|
||||
{
|
||||
B2_NOT_USED(childIndex);
|
||||
B2_NOT_USED(childIndex);
|
||||
|
||||
b2Vec2 lower = b2Mul(xf, m_vertices[0]);
|
||||
b2Vec2 upper = lower;
|
||||
b2Vec2 lower = b2Mul(xf, m_vertices[0]);
|
||||
b2Vec2 upper = lower;
|
||||
|
||||
for (int32 i = 1; i < m_vertexCount; ++i)
|
||||
{
|
||||
b2Vec2 v = b2Mul(xf, m_vertices[i]);
|
||||
lower = b2Min(lower, v);
|
||||
upper = b2Max(upper, v);
|
||||
}
|
||||
for (int32 i = 1; i < m_count; ++i)
|
||||
{
|
||||
b2Vec2 v = b2Mul(xf, m_vertices[i]);
|
||||
lower = b2Min(lower, v);
|
||||
upper = b2Max(upper, v);
|
||||
}
|
||||
|
||||
b2Vec2 r(m_radius, m_radius);
|
||||
aabb->lowerBound = lower - r;
|
||||
aabb->upperBound = upper + r;
|
||||
b2Vec2 r(m_radius, m_radius);
|
||||
aabb->lowerBound = lower - r;
|
||||
aabb->upperBound = upper + r;
|
||||
}
|
||||
|
||||
void b2PolygonShape::ComputeMass(b2MassData* massData, float32 density) const
|
||||
{
|
||||
// Polygon mass, centroid, and inertia.
|
||||
// Let rho be the polygon density in mass per unit area.
|
||||
// Then:
|
||||
// mass = rho * int(dA)
|
||||
// centroid.x = (1/mass) * rho * int(x * dA)
|
||||
// centroid.y = (1/mass) * rho * int(y * dA)
|
||||
// I = rho * int((x*x + y*y) * dA)
|
||||
//
|
||||
// We can compute these integrals by summing all the integrals
|
||||
// for each triangle of the polygon. To evaluate the integral
|
||||
// for a single triangle, we make a change of variables to
|
||||
// the (u,v) coordinates of the triangle:
|
||||
// x = x0 + e1x * u + e2x * v
|
||||
// y = y0 + e1y * u + e2y * v
|
||||
// where 0 <= u && 0 <= v && u + v <= 1.
|
||||
//
|
||||
// We integrate u from [0,1-v] and then v from [0,1].
|
||||
// We also need to use the Jacobian of the transformation:
|
||||
// D = cross(e1, e2)
|
||||
//
|
||||
// Simplification: triangle centroid = (1/3) * (p1 + p2 + p3)
|
||||
//
|
||||
// The rest of the derivation is handled by computer algebra.
|
||||
// Polygon mass, centroid, and inertia.
|
||||
// Let rho be the polygon density in mass per unit area.
|
||||
// Then:
|
||||
// mass = rho * int(dA)
|
||||
// centroid.x = (1/mass) * rho * int(x * dA)
|
||||
// centroid.y = (1/mass) * rho * int(y * dA)
|
||||
// I = rho * int((x*x + y*y) * dA)
|
||||
//
|
||||
// We can compute these integrals by summing all the integrals
|
||||
// for each triangle of the polygon. To evaluate the integral
|
||||
// for a single triangle, we make a change of variables to
|
||||
// the (u,v) coordinates of the triangle:
|
||||
// x = x0 + e1x * u + e2x * v
|
||||
// y = y0 + e1y * u + e2y * v
|
||||
// where 0 <= u && 0 <= v && u + v <= 1.
|
||||
//
|
||||
// We integrate u from [0,1-v] and then v from [0,1].
|
||||
// We also need to use the Jacobian of the transformation:
|
||||
// D = cross(e1, e2)
|
||||
//
|
||||
// Simplification: triangle centroid = (1/3) * (p1 + p2 + p3)
|
||||
//
|
||||
// The rest of the derivation is handled by computer algebra.
|
||||
|
||||
b2Assert(m_vertexCount >= 3);
|
||||
b2Assert(m_count >= 3);
|
||||
|
||||
b2Vec2 center; center.Set(0.0f, 0.0f);
|
||||
float32 area = 0.0f;
|
||||
float32 I = 0.0f;
|
||||
b2Vec2 center; center.Set(0.0f, 0.0f);
|
||||
float32 area = 0.0f;
|
||||
float32 I = 0.0f;
|
||||
|
||||
// s is the reference point for forming triangles.
|
||||
// It's location doesn't change the result (except for rounding error).
|
||||
b2Vec2 s(0.0f, 0.0f);
|
||||
// s is the reference point for forming triangles.
|
||||
// It's location doesn't change the result (except for rounding error).
|
||||
b2Vec2 s(0.0f, 0.0f);
|
||||
|
||||
// This code would put the reference point inside the polygon.
|
||||
for (int32 i = 0; i < m_vertexCount; ++i)
|
||||
{
|
||||
s += m_vertices[i];
|
||||
}
|
||||
s *= 1.0f / m_vertexCount;
|
||||
// This code would put the reference point inside the polygon.
|
||||
for (int32 i = 0; i < m_count; ++i)
|
||||
{
|
||||
s += m_vertices[i];
|
||||
}
|
||||
s *= 1.0f / m_count;
|
||||
|
||||
const float32 k_inv3 = 1.0f / 3.0f;
|
||||
const float32 k_inv3 = 1.0f / 3.0f;
|
||||
|
||||
for (int32 i = 0; i < m_vertexCount; ++i)
|
||||
{
|
||||
// Triangle vertices.
|
||||
b2Vec2 e1 = m_vertices[i] - s;
|
||||
b2Vec2 e2 = i + 1 < m_vertexCount ? m_vertices[i+1] - s : m_vertices[0] - s;
|
||||
for (int32 i = 0; i < m_count; ++i)
|
||||
{
|
||||
// Triangle vertices.
|
||||
b2Vec2 e1 = m_vertices[i] - s;
|
||||
b2Vec2 e2 = i + 1 < m_count ? m_vertices[i+1] - s : m_vertices[0] - s;
|
||||
|
||||
float32 D = b2Cross(e1, e2);
|
||||
float32 D = b2Cross(e1, e2);
|
||||
|
||||
float32 triangleArea = 0.5f * D;
|
||||
area += triangleArea;
|
||||
float32 triangleArea = 0.5f * D;
|
||||
area += triangleArea;
|
||||
|
||||
// Area weighted centroid
|
||||
center += triangleArea * k_inv3 * (e1 + e2);
|
||||
// Area weighted centroid
|
||||
center += triangleArea * k_inv3 * (e1 + e2);
|
||||
|
||||
float32 ex1 = e1.x, ey1 = e1.y;
|
||||
float32 ex2 = e2.x, ey2 = e2.y;
|
||||
float32 ex1 = e1.x, ey1 = e1.y;
|
||||
float32 ex2 = e2.x, ey2 = e2.y;
|
||||
|
||||
float32 intx2 = ex1*ex1 + ex2*ex1 + ex2*ex2;
|
||||
float32 inty2 = ey1*ey1 + ey2*ey1 + ey2*ey2;
|
||||
float32 intx2 = ex1*ex1 + ex2*ex1 + ex2*ex2;
|
||||
float32 inty2 = ey1*ey1 + ey2*ey1 + ey2*ey2;
|
||||
|
||||
I += (0.25f * k_inv3 * D) * (intx2 + inty2);
|
||||
}
|
||||
I += (0.25f * k_inv3 * D) * (intx2 + inty2);
|
||||
}
|
||||
|
||||
// Total mass
|
||||
massData->mass = density * area;
|
||||
// Total mass
|
||||
massData->mass = density * area;
|
||||
|
||||
// Center of mass
|
||||
b2Assert(area > b2_epsilon);
|
||||
center *= 1.0f / area;
|
||||
massData->center = center + s;
|
||||
// Center of mass
|
||||
b2Assert(area > b2_epsilon);
|
||||
center *= 1.0f / area;
|
||||
massData->center = center + s;
|
||||
|
||||
// Inertia tensor relative to the local origin (point s).
|
||||
massData->I = density * I;
|
||||
|
||||
// Shift to center of mass then to original body origin.
|
||||
massData->I += massData->mass * (b2Dot(massData->center, massData->center) - b2Dot(center, center));
|
||||
// Inertia tensor relative to the local origin (point s).
|
||||
massData->I = density * I;
|
||||
|
||||
// Shift to center of mass then to original body origin.
|
||||
massData->I += massData->mass * (b2Dot(massData->center, massData->center) - b2Dot(center, center));
|
||||
}
|
||||
|
||||
bool b2PolygonShape::Validate() const
|
||||
{
|
||||
for (int32 i = 0; i < m_count; ++i)
|
||||
{
|
||||
int32 i1 = i;
|
||||
int32 i2 = i < m_count - 1 ? i1 + 1 : 0;
|
||||
b2Vec2 p = m_vertices[i1];
|
||||
b2Vec2 e = m_vertices[i2] - p;
|
||||
|
||||
for (int32 j = 0; j < m_count; ++j)
|
||||
{
|
||||
if (j == i1 || j == i2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
b2Vec2 v = m_vertices[j] - p;
|
||||
float32 c = b2Cross(e, v);
|
||||
if (c < 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -28,68 +28,74 @@
|
|||
class b2PolygonShape : public b2Shape
|
||||
{
|
||||
public:
|
||||
b2PolygonShape();
|
||||
b2PolygonShape();
|
||||
|
||||
/// Implement b2Shape.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
/// Implement b2Shape.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
|
||||
/// Copy vertices. This assumes the vertices define a convex polygon.
|
||||
/// It is assumed that the exterior is the the right of each edge.
|
||||
/// The count must be in the range [3, b2_maxPolygonVertices].
|
||||
void Set(const b2Vec2* vertices, int32 vertexCount);
|
||||
/// Create a convex hull from the given array of local points.
|
||||
/// The count must be in the range [3, b2_maxPolygonVertices].
|
||||
/// @warning the points may be re-ordered, even if they form a convex polygon
|
||||
/// @warning collinear points are handled but not removed. Collinear points
|
||||
/// may lead to poor stacking behavior.
|
||||
void Set(const b2Vec2* points, int32 count);
|
||||
|
||||
/// Build vertices to represent an axis-aligned box.
|
||||
/// @param hx the half-width.
|
||||
/// @param hy the half-height.
|
||||
void SetAsBox(float32 hx, float32 hy);
|
||||
/// Build vertices to represent an axis-aligned box centered on the local origin.
|
||||
/// @param hx the half-width.
|
||||
/// @param hy the half-height.
|
||||
void SetAsBox(float32 hx, float32 hy);
|
||||
|
||||
/// Build vertices to represent an oriented box.
|
||||
/// @param hx the half-width.
|
||||
/// @param hy the half-height.
|
||||
/// @param center the center of the box in local coordinates.
|
||||
/// @param angle the rotation of the box in local coordinates.
|
||||
void SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle);
|
||||
/// Build vertices to represent an oriented box.
|
||||
/// @param hx the half-width.
|
||||
/// @param hy the half-height.
|
||||
/// @param center the center of the box in local coordinates.
|
||||
/// @param angle the rotation of the box in local coordinates.
|
||||
void SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle);
|
||||
|
||||
/// @see b2Shape::TestPoint
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
/// @see b2Shape::TestPoint
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
|
||||
/// Get the vertex count.
|
||||
int32 GetVertexCount() const { return m_vertexCount; }
|
||||
/// Get the vertex count.
|
||||
int32 GetVertexCount() const { return m_count; }
|
||||
|
||||
/// Get a vertex by index.
|
||||
const b2Vec2& GetVertex(int32 index) const;
|
||||
/// Get a vertex by index.
|
||||
const b2Vec2& GetVertex(int32 index) const;
|
||||
|
||||
b2Vec2 m_centroid;
|
||||
b2Vec2 m_vertices[b2_maxPolygonVertices];
|
||||
b2Vec2 m_normals[b2_maxPolygonVertices];
|
||||
int32 m_vertexCount;
|
||||
/// Validate convexity. This is a very time consuming operation.
|
||||
/// @returns true if valid
|
||||
bool Validate() const;
|
||||
|
||||
b2Vec2 m_centroid;
|
||||
b2Vec2 m_vertices[b2_maxPolygonVertices];
|
||||
b2Vec2 m_normals[b2_maxPolygonVertices];
|
||||
int32 m_count;
|
||||
};
|
||||
|
||||
inline b2PolygonShape::b2PolygonShape()
|
||||
{
|
||||
m_type = e_polygon;
|
||||
m_radius = b2_polygonRadius;
|
||||
m_vertexCount = 0;
|
||||
m_centroid.SetZero();
|
||||
m_type = e_polygon;
|
||||
m_radius = b2_polygonRadius;
|
||||
m_count = 0;
|
||||
m_centroid.SetZero();
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2PolygonShape::GetVertex(int32 index) const
|
||||
{
|
||||
b2Assert(0 <= index && index < m_vertexCount);
|
||||
return m_vertices[index];
|
||||
b2Assert(0 <= index && index < m_count);
|
||||
return m_vertices[index];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,14 +26,14 @@
|
|||
/// This holds the mass data computed for a shape.
|
||||
struct b2MassData
|
||||
{
|
||||
/// The mass of the shape, usually in kilograms.
|
||||
float32 mass;
|
||||
/// The mass of the shape, usually in kilograms.
|
||||
float32 mass;
|
||||
|
||||
/// The position of the shape's centroid relative to the shape's origin.
|
||||
b2Vec2 center;
|
||||
/// The position of the shape's centroid relative to the shape's origin.
|
||||
b2Vec2 center;
|
||||
|
||||
/// The rotational inertia of the shape about the local origin.
|
||||
float32 I;
|
||||
/// The rotational inertia of the shape about the local origin.
|
||||
float32 I;
|
||||
};
|
||||
|
||||
/// A shape is used for collision detection. You can create a shape however you like.
|
||||
|
@ -42,60 +42,60 @@ struct b2MassData
|
|||
class b2Shape
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
e_circle = 0,
|
||||
e_edge = 1,
|
||||
e_polygon = 2,
|
||||
e_chain = 3,
|
||||
e_typeCount = 4
|
||||
};
|
||||
|
||||
enum Type
|
||||
{
|
||||
e_circle = 0,
|
||||
e_edge = 1,
|
||||
e_polygon = 2,
|
||||
e_chain = 3,
|
||||
e_typeCount = 4
|
||||
};
|
||||
|
||||
virtual ~b2Shape() {}
|
||||
virtual ~b2Shape() {}
|
||||
|
||||
/// Clone the concrete shape using the provided allocator.
|
||||
virtual b2Shape* Clone(b2BlockAllocator* allocator) const = 0;
|
||||
/// Clone the concrete shape using the provided allocator.
|
||||
virtual b2Shape* Clone(b2BlockAllocator* allocator) const = 0;
|
||||
|
||||
/// Get the type of this shape. You can use this to down cast to the concrete shape.
|
||||
/// @return the shape type.
|
||||
Type GetType() const;
|
||||
/// Get the type of this shape. You can use this to down cast to the concrete shape.
|
||||
/// @return the shape type.
|
||||
Type GetType() const;
|
||||
|
||||
/// Get the number of child primitives.
|
||||
virtual int32 GetChildCount() const = 0;
|
||||
/// Get the number of child primitives.
|
||||
virtual int32 GetChildCount() const = 0;
|
||||
|
||||
/// Test a point for containment in this shape. This only works for convex shapes.
|
||||
/// @param xf the shape world transform.
|
||||
/// @param p a point in world coordinates.
|
||||
virtual bool TestPoint(const b2Transform& xf, const b2Vec2& p) const = 0;
|
||||
/// Test a point for containment in this shape. This only works for convex shapes.
|
||||
/// @param xf the shape world transform.
|
||||
/// @param p a point in world coordinates.
|
||||
virtual bool TestPoint(const b2Transform& xf, const b2Vec2& p) const = 0;
|
||||
|
||||
/// Cast a ray against a child shape.
|
||||
/// @param output the ray-cast results.
|
||||
/// @param input the ray-cast input parameters.
|
||||
/// @param transform the transform to be applied to the shape.
|
||||
/// @param childIndex the child shape index
|
||||
virtual bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const = 0;
|
||||
/// Cast a ray against a child shape.
|
||||
/// @param output the ray-cast results.
|
||||
/// @param input the ray-cast input parameters.
|
||||
/// @param transform the transform to be applied to the shape.
|
||||
/// @param childIndex the child shape index
|
||||
virtual bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const = 0;
|
||||
|
||||
/// Given a transform, compute the associated axis aligned bounding box for a child shape.
|
||||
/// @param aabb returns the axis aligned box.
|
||||
/// @param xf the world transform of the shape.
|
||||
/// @param childIndex the child shape
|
||||
virtual void ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const = 0;
|
||||
/// Given a transform, compute the associated axis aligned bounding box for a child shape.
|
||||
/// @param aabb returns the axis aligned box.
|
||||
/// @param xf the world transform of the shape.
|
||||
/// @param childIndex the child shape
|
||||
virtual void ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const = 0;
|
||||
|
||||
/// Compute the mass properties of this shape using its dimensions and density.
|
||||
/// The inertia tensor is computed about the local origin.
|
||||
/// @param massData returns the mass data for this shape.
|
||||
/// @param density the density in kilograms per meter squared.
|
||||
virtual void ComputeMass(b2MassData* massData, float32 density) const = 0;
|
||||
/// Compute the mass properties of this shape using its dimensions and density.
|
||||
/// The inertia tensor is computed about the local origin.
|
||||
/// @param massData returns the mass data for this shape.
|
||||
/// @param density the density in kilograms per meter squared.
|
||||
virtual void ComputeMass(b2MassData* massData, float32 density) const = 0;
|
||||
|
||||
Type m_type;
|
||||
float32 m_radius;
|
||||
Type m_type;
|
||||
float32 m_radius;
|
||||
};
|
||||
|
||||
inline b2Shape::Type b2Shape::GetType() const
|
||||
{
|
||||
return m_type;
|
||||
return m_type;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,106 +17,103 @@
|
|||
*/
|
||||
|
||||
#include <Box2D/Collision/b2BroadPhase.h>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
b2BroadPhase::b2BroadPhase()
|
||||
{
|
||||
m_proxyCount = 0;
|
||||
m_proxyCount = 0;
|
||||
|
||||
m_pairCapacity = 16;
|
||||
m_pairCount = 0;
|
||||
m_pairBuffer = (b2Pair*)b2Alloc(m_pairCapacity * sizeof(b2Pair));
|
||||
m_pairCapacity = 16;
|
||||
m_pairCount = 0;
|
||||
m_pairBuffer = (b2Pair*)b2Alloc(m_pairCapacity * sizeof(b2Pair));
|
||||
|
||||
m_moveCapacity = 16;
|
||||
m_moveCount = 0;
|
||||
m_moveBuffer = (int32*)b2Alloc(m_moveCapacity * sizeof(int32));
|
||||
m_moveCapacity = 16;
|
||||
m_moveCount = 0;
|
||||
m_moveBuffer = (int32*)b2Alloc(m_moveCapacity * sizeof(int32));
|
||||
}
|
||||
|
||||
b2BroadPhase::~b2BroadPhase()
|
||||
{
|
||||
b2Free(m_moveBuffer);
|
||||
b2Free(m_pairBuffer);
|
||||
b2Free(m_moveBuffer);
|
||||
b2Free(m_pairBuffer);
|
||||
}
|
||||
|
||||
int32 b2BroadPhase::CreateProxy(const b2AABB& aabb, void* userData)
|
||||
{
|
||||
int32 proxyId = m_tree.CreateProxy(aabb, userData);
|
||||
++m_proxyCount;
|
||||
BufferMove(proxyId);
|
||||
return proxyId;
|
||||
int32 proxyId = m_tree.CreateProxy(aabb, userData);
|
||||
++m_proxyCount;
|
||||
BufferMove(proxyId);
|
||||
return proxyId;
|
||||
}
|
||||
|
||||
void b2BroadPhase::DestroyProxy(int32 proxyId)
|
||||
{
|
||||
UnBufferMove(proxyId);
|
||||
--m_proxyCount;
|
||||
m_tree.DestroyProxy(proxyId);
|
||||
UnBufferMove(proxyId);
|
||||
--m_proxyCount;
|
||||
m_tree.DestroyProxy(proxyId);
|
||||
}
|
||||
|
||||
void b2BroadPhase::MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement)
|
||||
{
|
||||
bool buffer = m_tree.MoveProxy(proxyId, aabb, displacement);
|
||||
if (buffer)
|
||||
{
|
||||
BufferMove(proxyId);
|
||||
}
|
||||
bool buffer = m_tree.MoveProxy(proxyId, aabb, displacement);
|
||||
if (buffer)
|
||||
{
|
||||
BufferMove(proxyId);
|
||||
}
|
||||
}
|
||||
|
||||
void b2BroadPhase::TouchProxy(int32 proxyId)
|
||||
{
|
||||
BufferMove(proxyId);
|
||||
BufferMove(proxyId);
|
||||
}
|
||||
|
||||
void b2BroadPhase::BufferMove(int32 proxyId)
|
||||
{
|
||||
if (m_moveCount == m_moveCapacity)
|
||||
{
|
||||
int32* oldBuffer = m_moveBuffer;
|
||||
m_moveCapacity *= 2;
|
||||
m_moveBuffer = (int32*)b2Alloc(m_moveCapacity * sizeof(int32));
|
||||
memcpy(m_moveBuffer, oldBuffer, m_moveCount * sizeof(int32));
|
||||
b2Free(oldBuffer);
|
||||
}
|
||||
if (m_moveCount == m_moveCapacity)
|
||||
{
|
||||
int32* oldBuffer = m_moveBuffer;
|
||||
m_moveCapacity *= 2;
|
||||
m_moveBuffer = (int32*)b2Alloc(m_moveCapacity * sizeof(int32));
|
||||
memcpy(m_moveBuffer, oldBuffer, m_moveCount * sizeof(int32));
|
||||
b2Free(oldBuffer);
|
||||
}
|
||||
|
||||
m_moveBuffer[m_moveCount] = proxyId;
|
||||
++m_moveCount;
|
||||
m_moveBuffer[m_moveCount] = proxyId;
|
||||
++m_moveCount;
|
||||
}
|
||||
|
||||
void b2BroadPhase::UnBufferMove(int32 proxyId)
|
||||
{
|
||||
for (int32 i = 0; i < m_moveCount; ++i)
|
||||
{
|
||||
if (m_moveBuffer[i] == proxyId)
|
||||
{
|
||||
m_moveBuffer[i] = e_nullProxy;
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (int32 i = 0; i < m_moveCount; ++i)
|
||||
{
|
||||
if (m_moveBuffer[i] == proxyId)
|
||||
{
|
||||
m_moveBuffer[i] = e_nullProxy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is called from b2DynamicTree::Query when we are gathering pairs.
|
||||
bool b2BroadPhase::QueryCallback(int32 proxyId)
|
||||
{
|
||||
// A proxy cannot form a pair with itself.
|
||||
if (proxyId == m_queryProxyId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// A proxy cannot form a pair with itself.
|
||||
if (proxyId == m_queryProxyId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Grow the pair buffer as needed.
|
||||
if (m_pairCount == m_pairCapacity)
|
||||
{
|
||||
b2Pair* oldBuffer = m_pairBuffer;
|
||||
m_pairCapacity *= 2;
|
||||
m_pairBuffer = (b2Pair*)b2Alloc(m_pairCapacity * sizeof(b2Pair));
|
||||
memcpy(m_pairBuffer, oldBuffer, m_pairCount * sizeof(b2Pair));
|
||||
b2Free(oldBuffer);
|
||||
}
|
||||
// Grow the pair buffer as needed.
|
||||
if (m_pairCount == m_pairCapacity)
|
||||
{
|
||||
b2Pair* oldBuffer = m_pairBuffer;
|
||||
m_pairCapacity *= 2;
|
||||
m_pairBuffer = (b2Pair*)b2Alloc(m_pairCapacity * sizeof(b2Pair));
|
||||
memcpy(m_pairBuffer, oldBuffer, m_pairCount * sizeof(b2Pair));
|
||||
b2Free(oldBuffer);
|
||||
}
|
||||
|
||||
m_pairBuffer[m_pairCount].proxyIdA = b2Min(proxyId, m_queryProxyId);
|
||||
m_pairBuffer[m_pairCount].proxyIdB = b2Max(proxyId, m_queryProxyId);
|
||||
++m_pairCount;
|
||||
m_pairBuffer[m_pairCount].proxyIdA = b2Min(proxyId, m_queryProxyId);
|
||||
m_pairBuffer[m_pairCount].proxyIdB = b2Max(proxyId, m_queryProxyId);
|
||||
++m_pairCount;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -26,9 +26,8 @@
|
|||
|
||||
struct b2Pair
|
||||
{
|
||||
int32 proxyIdA;
|
||||
int32 proxyIdB;
|
||||
int32 next;
|
||||
int32 proxyIdA;
|
||||
int32 proxyIdB;
|
||||
};
|
||||
|
||||
/// The broad-phase is used for computing pairs and performing volume queries and ray casts.
|
||||
|
@ -38,211 +37,221 @@ class b2BroadPhase
|
|||
{
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
e_nullProxy = -1
|
||||
};
|
||||
enum
|
||||
{
|
||||
e_nullProxy = -1
|
||||
};
|
||||
|
||||
b2BroadPhase();
|
||||
~b2BroadPhase();
|
||||
b2BroadPhase();
|
||||
~b2BroadPhase();
|
||||
|
||||
/// Create a proxy with an initial AABB. Pairs are not reported until
|
||||
/// UpdatePairs is called.
|
||||
int32 CreateProxy(const b2AABB& aabb, void* userData);
|
||||
/// Create a proxy with an initial AABB. Pairs are not reported until
|
||||
/// UpdatePairs is called.
|
||||
int32 CreateProxy(const b2AABB& aabb, void* userData);
|
||||
|
||||
/// Destroy a proxy. It is up to the client to remove any pairs.
|
||||
void DestroyProxy(int32 proxyId);
|
||||
/// Destroy a proxy. It is up to the client to remove any pairs.
|
||||
void DestroyProxy(int32 proxyId);
|
||||
|
||||
/// Call MoveProxy as many times as you like, then when you are done
|
||||
/// call UpdatePairs to finalized the proxy pairs (for your time step).
|
||||
void MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement);
|
||||
/// Call MoveProxy as many times as you like, then when you are done
|
||||
/// call UpdatePairs to finalized the proxy pairs (for your time step).
|
||||
void MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement);
|
||||
|
||||
/// Call to trigger a re-processing of it's pairs on the next call to UpdatePairs.
|
||||
void TouchProxy(int32 proxyId);
|
||||
/// Call to trigger a re-processing of it's pairs on the next call to UpdatePairs.
|
||||
void TouchProxy(int32 proxyId);
|
||||
|
||||
/// Get the fat AABB for a proxy.
|
||||
const b2AABB& GetFatAABB(int32 proxyId) const;
|
||||
/// Get the fat AABB for a proxy.
|
||||
const b2AABB& GetFatAABB(int32 proxyId) const;
|
||||
|
||||
/// Get user data from a proxy. Returns NULL if the id is invalid.
|
||||
void* GetUserData(int32 proxyId) const;
|
||||
/// Get user data from a proxy. Returns NULL if the id is invalid.
|
||||
void* GetUserData(int32 proxyId) const;
|
||||
|
||||
/// Test overlap of fat AABBs.
|
||||
bool TestOverlap(int32 proxyIdA, int32 proxyIdB) const;
|
||||
/// Test overlap of fat AABBs.
|
||||
bool TestOverlap(int32 proxyIdA, int32 proxyIdB) const;
|
||||
|
||||
/// Get the number of proxies.
|
||||
int32 GetProxyCount() const;
|
||||
/// Get the number of proxies.
|
||||
int32 GetProxyCount() const;
|
||||
|
||||
/// Update the pairs. This results in pair callbacks. This can only add pairs.
|
||||
template <typename T>
|
||||
void UpdatePairs(T* callback);
|
||||
/// Update the pairs. This results in pair callbacks. This can only add pairs.
|
||||
template <typename T>
|
||||
void UpdatePairs(T* callback);
|
||||
|
||||
/// Query an AABB for overlapping proxies. The callback class
|
||||
/// is called for each proxy that overlaps the supplied AABB.
|
||||
template <typename T>
|
||||
void Query(T* callback, const b2AABB& aabb) const;
|
||||
/// Query an AABB for overlapping proxies. The callback class
|
||||
/// is called for each proxy that overlaps the supplied AABB.
|
||||
template <typename T>
|
||||
void Query(T* callback, const b2AABB& aabb) const;
|
||||
|
||||
/// Ray-cast against the proxies in the tree. This relies on the callback
|
||||
/// to perform a exact ray-cast in the case were the proxy contains a shape.
|
||||
/// The callback also performs the any collision filtering. This has performance
|
||||
/// roughly equal to k * log(n), where k is the number of collisions and n is the
|
||||
/// number of proxies in the tree.
|
||||
/// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
|
||||
/// @param callback a callback class that is called for each proxy that is hit by the ray.
|
||||
template <typename T>
|
||||
void RayCast(T* callback, const b2RayCastInput& input) const;
|
||||
/// Ray-cast against the proxies in the tree. This relies on the callback
|
||||
/// to perform a exact ray-cast in the case were the proxy contains a shape.
|
||||
/// The callback also performs the any collision filtering. This has performance
|
||||
/// roughly equal to k * log(n), where k is the number of collisions and n is the
|
||||
/// number of proxies in the tree.
|
||||
/// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
|
||||
/// @param callback a callback class that is called for each proxy that is hit by the ray.
|
||||
template <typename T>
|
||||
void RayCast(T* callback, const b2RayCastInput& input) const;
|
||||
|
||||
/// Get the height of the embedded tree.
|
||||
int32 GetTreeHeight() const;
|
||||
/// Get the height of the embedded tree.
|
||||
int32 GetTreeHeight() const;
|
||||
|
||||
/// Get the balance of the embedded tree.
|
||||
int32 GetTreeBalance() const;
|
||||
/// Get the balance of the embedded tree.
|
||||
int32 GetTreeBalance() const;
|
||||
|
||||
/// Get the quality metric of the embedded tree.
|
||||
float32 GetTreeQuality() const;
|
||||
/// Get the quality metric of the embedded tree.
|
||||
float32 GetTreeQuality() const;
|
||||
|
||||
/// Shift the world origin. Useful for large worlds.
|
||||
/// The shift formula is: position -= newOrigin
|
||||
/// @param newOrigin the new origin with respect to the old origin
|
||||
void ShiftOrigin(const b2Vec2& newOrigin);
|
||||
|
||||
private:
|
||||
|
||||
friend class b2DynamicTree;
|
||||
friend class b2DynamicTree;
|
||||
|
||||
void BufferMove(int32 proxyId);
|
||||
void UnBufferMove(int32 proxyId);
|
||||
void BufferMove(int32 proxyId);
|
||||
void UnBufferMove(int32 proxyId);
|
||||
|
||||
bool QueryCallback(int32 proxyId);
|
||||
bool QueryCallback(int32 proxyId);
|
||||
|
||||
b2DynamicTree m_tree;
|
||||
b2DynamicTree m_tree;
|
||||
|
||||
int32 m_proxyCount;
|
||||
int32 m_proxyCount;
|
||||
|
||||
int32* m_moveBuffer;
|
||||
int32 m_moveCapacity;
|
||||
int32 m_moveCount;
|
||||
int32* m_moveBuffer;
|
||||
int32 m_moveCapacity;
|
||||
int32 m_moveCount;
|
||||
|
||||
b2Pair* m_pairBuffer;
|
||||
int32 m_pairCapacity;
|
||||
int32 m_pairCount;
|
||||
b2Pair* m_pairBuffer;
|
||||
int32 m_pairCapacity;
|
||||
int32 m_pairCount;
|
||||
|
||||
int32 m_queryProxyId;
|
||||
int32 m_queryProxyId;
|
||||
};
|
||||
|
||||
/// This is used to sort pairs.
|
||||
inline bool b2PairLessThan(const b2Pair& pair1, const b2Pair& pair2)
|
||||
{
|
||||
if (pair1.proxyIdA < pair2.proxyIdA)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (pair1.proxyIdA < pair2.proxyIdA)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pair1.proxyIdA == pair2.proxyIdA)
|
||||
{
|
||||
return pair1.proxyIdB < pair2.proxyIdB;
|
||||
}
|
||||
if (pair1.proxyIdA == pair2.proxyIdA)
|
||||
{
|
||||
return pair1.proxyIdB < pair2.proxyIdB;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void* b2BroadPhase::GetUserData(int32 proxyId) const
|
||||
{
|
||||
return m_tree.GetUserData(proxyId);
|
||||
return m_tree.GetUserData(proxyId);
|
||||
}
|
||||
|
||||
inline bool b2BroadPhase::TestOverlap(int32 proxyIdA, int32 proxyIdB) const
|
||||
{
|
||||
const b2AABB& aabbA = m_tree.GetFatAABB(proxyIdA);
|
||||
const b2AABB& aabbB = m_tree.GetFatAABB(proxyIdB);
|
||||
return b2TestOverlap(aabbA, aabbB);
|
||||
const b2AABB& aabbA = m_tree.GetFatAABB(proxyIdA);
|
||||
const b2AABB& aabbB = m_tree.GetFatAABB(proxyIdB);
|
||||
return b2TestOverlap(aabbA, aabbB);
|
||||
}
|
||||
|
||||
inline const b2AABB& b2BroadPhase::GetFatAABB(int32 proxyId) const
|
||||
{
|
||||
return m_tree.GetFatAABB(proxyId);
|
||||
return m_tree.GetFatAABB(proxyId);
|
||||
}
|
||||
|
||||
inline int32 b2BroadPhase::GetProxyCount() const
|
||||
{
|
||||
return m_proxyCount;
|
||||
return m_proxyCount;
|
||||
}
|
||||
|
||||
inline int32 b2BroadPhase::GetTreeHeight() const
|
||||
{
|
||||
return m_tree.GetHeight();
|
||||
return m_tree.GetHeight();
|
||||
}
|
||||
|
||||
inline int32 b2BroadPhase::GetTreeBalance() const
|
||||
{
|
||||
return m_tree.GetMaxBalance();
|
||||
return m_tree.GetMaxBalance();
|
||||
}
|
||||
|
||||
inline float32 b2BroadPhase::GetTreeQuality() const
|
||||
{
|
||||
return m_tree.GetAreaRatio();
|
||||
return m_tree.GetAreaRatio();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void b2BroadPhase::UpdatePairs(T* callback)
|
||||
{
|
||||
// Reset pair buffer
|
||||
m_pairCount = 0;
|
||||
// Reset pair buffer
|
||||
m_pairCount = 0;
|
||||
|
||||
// Perform tree queries for all moving proxies.
|
||||
for (int32 i = 0; i < m_moveCount; ++i)
|
||||
{
|
||||
m_queryProxyId = m_moveBuffer[i];
|
||||
if (m_queryProxyId == e_nullProxy)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// Perform tree queries for all moving proxies.
|
||||
for (int32 i = 0; i < m_moveCount; ++i)
|
||||
{
|
||||
m_queryProxyId = m_moveBuffer[i];
|
||||
if (m_queryProxyId == e_nullProxy)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// We have to query the tree with the fat AABB so that
|
||||
// we don't fail to create a pair that may touch later.
|
||||
const b2AABB& fatAABB = m_tree.GetFatAABB(m_queryProxyId);
|
||||
// We have to query the tree with the fat AABB so that
|
||||
// we don't fail to create a pair that may touch later.
|
||||
const b2AABB& fatAABB = m_tree.GetFatAABB(m_queryProxyId);
|
||||
|
||||
// Query tree, create pairs and add them pair buffer.
|
||||
m_tree.Query(this, fatAABB);
|
||||
}
|
||||
// Query tree, create pairs and add them pair buffer.
|
||||
m_tree.Query(this, fatAABB);
|
||||
}
|
||||
|
||||
// Reset move buffer
|
||||
m_moveCount = 0;
|
||||
// Reset move buffer
|
||||
m_moveCount = 0;
|
||||
|
||||
// Sort the pair buffer to expose duplicates.
|
||||
std::sort(m_pairBuffer, m_pairBuffer + m_pairCount, b2PairLessThan);
|
||||
// Sort the pair buffer to expose duplicates.
|
||||
std::sort(m_pairBuffer, m_pairBuffer + m_pairCount, b2PairLessThan);
|
||||
|
||||
// Send the pairs back to the client.
|
||||
int32 i = 0;
|
||||
while (i < m_pairCount)
|
||||
{
|
||||
b2Pair* primaryPair = m_pairBuffer + i;
|
||||
void* userDataA = m_tree.GetUserData(primaryPair->proxyIdA);
|
||||
void* userDataB = m_tree.GetUserData(primaryPair->proxyIdB);
|
||||
// Send the pairs back to the client.
|
||||
int32 i = 0;
|
||||
while (i < m_pairCount)
|
||||
{
|
||||
b2Pair* primaryPair = m_pairBuffer + i;
|
||||
void* userDataA = m_tree.GetUserData(primaryPair->proxyIdA);
|
||||
void* userDataB = m_tree.GetUserData(primaryPair->proxyIdB);
|
||||
|
||||
callback->AddPair(userDataA, userDataB);
|
||||
++i;
|
||||
callback->AddPair(userDataA, userDataB);
|
||||
++i;
|
||||
|
||||
// Skip any duplicate pairs.
|
||||
while (i < m_pairCount)
|
||||
{
|
||||
b2Pair* pair = m_pairBuffer + i;
|
||||
if (pair->proxyIdA != primaryPair->proxyIdA || pair->proxyIdB != primaryPair->proxyIdB)
|
||||
{
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
// Skip any duplicate pairs.
|
||||
while (i < m_pairCount)
|
||||
{
|
||||
b2Pair* pair = m_pairBuffer + i;
|
||||
if (pair->proxyIdA != primaryPair->proxyIdA || pair->proxyIdB != primaryPair->proxyIdB)
|
||||
{
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to keep the tree balanced.
|
||||
//m_tree.Rebalance(4);
|
||||
// Try to keep the tree balanced.
|
||||
//m_tree.Rebalance(4);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void b2BroadPhase::Query(T* callback, const b2AABB& aabb) const
|
||||
{
|
||||
m_tree.Query(callback, aabb);
|
||||
m_tree.Query(callback, aabb);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void b2BroadPhase::RayCast(T* callback, const b2RayCastInput& input) const
|
||||
{
|
||||
m_tree.RayCast(callback, input);
|
||||
m_tree.RayCast(callback, input);
|
||||
}
|
||||
|
||||
inline void b2BroadPhase::ShiftOrigin(const b2Vec2& newOrigin)
|
||||
{
|
||||
m_tree.ShiftOrigin(newOrigin);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,134 +21,134 @@
|
|||
#include <Box2D/Collision/Shapes/b2PolygonShape.h>
|
||||
|
||||
void b2CollideCircles(
|
||||
b2Manifold* manifold,
|
||||
const b2CircleShape* circleA, const b2Transform& xfA,
|
||||
const b2CircleShape* circleB, const b2Transform& xfB)
|
||||
b2Manifold* manifold,
|
||||
const b2CircleShape* circleA, const b2Transform& xfA,
|
||||
const b2CircleShape* circleB, const b2Transform& xfB)
|
||||
{
|
||||
manifold->pointCount = 0;
|
||||
manifold->pointCount = 0;
|
||||
|
||||
b2Vec2 pA = b2Mul(xfA, circleA->m_p);
|
||||
b2Vec2 pB = b2Mul(xfB, circleB->m_p);
|
||||
b2Vec2 pA = b2Mul(xfA, circleA->m_p);
|
||||
b2Vec2 pB = b2Mul(xfB, circleB->m_p);
|
||||
|
||||
b2Vec2 d = pB - pA;
|
||||
float32 distSqr = b2Dot(d, d);
|
||||
float32 rA = circleA->m_radius, rB = circleB->m_radius;
|
||||
float32 radius = rA + rB;
|
||||
if (distSqr > radius * radius)
|
||||
{
|
||||
return;
|
||||
}
|
||||
b2Vec2 d = pB - pA;
|
||||
float32 distSqr = b2Dot(d, d);
|
||||
float32 rA = circleA->m_radius, rB = circleB->m_radius;
|
||||
float32 radius = rA + rB;
|
||||
if (distSqr > radius * radius)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
manifold->type = b2Manifold::e_circles;
|
||||
manifold->localPoint = circleA->m_p;
|
||||
manifold->localNormal.SetZero();
|
||||
manifold->pointCount = 1;
|
||||
manifold->type = b2Manifold::e_circles;
|
||||
manifold->localPoint = circleA->m_p;
|
||||
manifold->localNormal.SetZero();
|
||||
manifold->pointCount = 1;
|
||||
|
||||
manifold->points[0].localPoint = circleB->m_p;
|
||||
manifold->points[0].id.key = 0;
|
||||
manifold->points[0].localPoint = circleB->m_p;
|
||||
manifold->points[0].id.key = 0;
|
||||
}
|
||||
|
||||
void b2CollidePolygonAndCircle(
|
||||
b2Manifold* manifold,
|
||||
const b2PolygonShape* polygonA, const b2Transform& xfA,
|
||||
const b2CircleShape* circleB, const b2Transform& xfB)
|
||||
b2Manifold* manifold,
|
||||
const b2PolygonShape* polygonA, const b2Transform& xfA,
|
||||
const b2CircleShape* circleB, const b2Transform& xfB)
|
||||
{
|
||||
manifold->pointCount = 0;
|
||||
manifold->pointCount = 0;
|
||||
|
||||
// Compute circle position in the frame of the polygon.
|
||||
b2Vec2 c = b2Mul(xfB, circleB->m_p);
|
||||
b2Vec2 cLocal = b2MulT(xfA, c);
|
||||
// Compute circle position in the frame of the polygon.
|
||||
b2Vec2 c = b2Mul(xfB, circleB->m_p);
|
||||
b2Vec2 cLocal = b2MulT(xfA, c);
|
||||
|
||||
// Find the min separating edge.
|
||||
int32 normalIndex = 0;
|
||||
float32 separation = -b2_maxFloat;
|
||||
float32 radius = polygonA->m_radius + circleB->m_radius;
|
||||
int32 vertexCount = polygonA->m_vertexCount;
|
||||
const b2Vec2* vertices = polygonA->m_vertices;
|
||||
const b2Vec2* normals = polygonA->m_normals;
|
||||
// Find the min separating edge.
|
||||
int32 normalIndex = 0;
|
||||
float32 separation = -b2_maxFloat;
|
||||
float32 radius = polygonA->m_radius + circleB->m_radius;
|
||||
int32 vertexCount = polygonA->m_count;
|
||||
const b2Vec2* vertices = polygonA->m_vertices;
|
||||
const b2Vec2* normals = polygonA->m_normals;
|
||||
|
||||
for (int32 i = 0; i < vertexCount; ++i)
|
||||
{
|
||||
float32 s = b2Dot(normals[i], cLocal - vertices[i]);
|
||||
for (int32 i = 0; i < vertexCount; ++i)
|
||||
{
|
||||
float32 s = b2Dot(normals[i], cLocal - vertices[i]);
|
||||
|
||||
if (s > radius)
|
||||
{
|
||||
// Early out.
|
||||
return;
|
||||
}
|
||||
if (s > radius)
|
||||
{
|
||||
// Early out.
|
||||
return;
|
||||
}
|
||||
|
||||
if (s > separation)
|
||||
{
|
||||
separation = s;
|
||||
normalIndex = i;
|
||||
}
|
||||
}
|
||||
if (s > separation)
|
||||
{
|
||||
separation = s;
|
||||
normalIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Vertices that subtend the incident face.
|
||||
int32 vertIndex1 = normalIndex;
|
||||
int32 vertIndex2 = vertIndex1 + 1 < vertexCount ? vertIndex1 + 1 : 0;
|
||||
b2Vec2 v1 = vertices[vertIndex1];
|
||||
b2Vec2 v2 = vertices[vertIndex2];
|
||||
// Vertices that subtend the incident face.
|
||||
int32 vertIndex1 = normalIndex;
|
||||
int32 vertIndex2 = vertIndex1 + 1 < vertexCount ? vertIndex1 + 1 : 0;
|
||||
b2Vec2 v1 = vertices[vertIndex1];
|
||||
b2Vec2 v2 = vertices[vertIndex2];
|
||||
|
||||
// If the center is inside the polygon ...
|
||||
if (separation < b2_epsilon)
|
||||
{
|
||||
manifold->pointCount = 1;
|
||||
manifold->type = b2Manifold::e_faceA;
|
||||
manifold->localNormal = normals[normalIndex];
|
||||
manifold->localPoint = 0.5f * (v1 + v2);
|
||||
manifold->points[0].localPoint = circleB->m_p;
|
||||
manifold->points[0].id.key = 0;
|
||||
return;
|
||||
}
|
||||
// If the center is inside the polygon ...
|
||||
if (separation < b2_epsilon)
|
||||
{
|
||||
manifold->pointCount = 1;
|
||||
manifold->type = b2Manifold::e_faceA;
|
||||
manifold->localNormal = normals[normalIndex];
|
||||
manifold->localPoint = 0.5f * (v1 + v2);
|
||||
manifold->points[0].localPoint = circleB->m_p;
|
||||
manifold->points[0].id.key = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute barycentric coordinates
|
||||
float32 u1 = b2Dot(cLocal - v1, v2 - v1);
|
||||
float32 u2 = b2Dot(cLocal - v2, v1 - v2);
|
||||
if (u1 <= 0.0f)
|
||||
{
|
||||
if (b2DistanceSquared(cLocal, v1) > radius * radius)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Compute barycentric coordinates
|
||||
float32 u1 = b2Dot(cLocal - v1, v2 - v1);
|
||||
float32 u2 = b2Dot(cLocal - v2, v1 - v2);
|
||||
if (u1 <= 0.0f)
|
||||
{
|
||||
if (b2DistanceSquared(cLocal, v1) > radius * radius)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
manifold->pointCount = 1;
|
||||
manifold->type = b2Manifold::e_faceA;
|
||||
manifold->localNormal = cLocal - v1;
|
||||
manifold->localNormal.Normalize();
|
||||
manifold->localPoint = v1;
|
||||
manifold->points[0].localPoint = circleB->m_p;
|
||||
manifold->points[0].id.key = 0;
|
||||
}
|
||||
else if (u2 <= 0.0f)
|
||||
{
|
||||
if (b2DistanceSquared(cLocal, v2) > radius * radius)
|
||||
{
|
||||
return;
|
||||
}
|
||||
manifold->pointCount = 1;
|
||||
manifold->type = b2Manifold::e_faceA;
|
||||
manifold->localNormal = cLocal - v1;
|
||||
manifold->localNormal.Normalize();
|
||||
manifold->localPoint = v1;
|
||||
manifold->points[0].localPoint = circleB->m_p;
|
||||
manifold->points[0].id.key = 0;
|
||||
}
|
||||
else if (u2 <= 0.0f)
|
||||
{
|
||||
if (b2DistanceSquared(cLocal, v2) > radius * radius)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
manifold->pointCount = 1;
|
||||
manifold->type = b2Manifold::e_faceA;
|
||||
manifold->localNormal = cLocal - v2;
|
||||
manifold->localNormal.Normalize();
|
||||
manifold->localPoint = v2;
|
||||
manifold->points[0].localPoint = circleB->m_p;
|
||||
manifold->points[0].id.key = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
b2Vec2 faceCenter = 0.5f * (v1 + v2);
|
||||
float32 separation = b2Dot(cLocal - faceCenter, normals[vertIndex1]);
|
||||
if (separation > radius)
|
||||
{
|
||||
return;
|
||||
}
|
||||
manifold->pointCount = 1;
|
||||
manifold->type = b2Manifold::e_faceA;
|
||||
manifold->localNormal = cLocal - v2;
|
||||
manifold->localNormal.Normalize();
|
||||
manifold->localPoint = v2;
|
||||
manifold->points[0].localPoint = circleB->m_p;
|
||||
manifold->points[0].id.key = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
b2Vec2 faceCenter = 0.5f * (v1 + v2);
|
||||
float32 separation = b2Dot(cLocal - faceCenter, normals[vertIndex1]);
|
||||
if (separation > radius)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
manifold->pointCount = 1;
|
||||
manifold->type = b2Manifold::e_faceA;
|
||||
manifold->localNormal = normals[vertIndex1];
|
||||
manifold->localPoint = faceCenter;
|
||||
manifold->points[0].localPoint = circleB->m_p;
|
||||
manifold->points[0].id.key = 0;
|
||||
}
|
||||
manifold->pointCount = 1;
|
||||
manifold->type = b2Manifold::e_faceA;
|
||||
manifold->localNormal = normals[vertIndex1];
|
||||
manifold->localPoint = faceCenter;
|
||||
manifold->points[0].localPoint = circleB->m_p;
|
||||
manifold->points[0].id.key = 0;
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue