Merge pull request #5 from cocos2d/v3

update v3
This commit is contained in:
jianglong0156 2015-05-15 11:06:02 +08:00
commit 729416fa15
441 changed files with 83861 additions and 55228 deletions

View File

@ -1107,6 +1107,7 @@ Developers:
milos1290
Added Lerp for Vec3
Added ActionFloat
perminovVS
Optimize Vec3 and Vec2
@ -1117,6 +1118,11 @@ Developers:
HueyPark
Fixed memory leak in HttpClient on iOS
Dimon4eg
Fixed crash on AssetsManager
Fixed memory leak of WebView on iOS
Fixed crahed that if url contains illegal characters on Android
Retired Core Developers:
WenSheng Yang

View File

@ -1,13 +1,22 @@
cocos2d-x-3.7 ??
[NEW] 3d: added physics3d support
[NEW] C++: added ActionFloat
[NEW] C++: support physical keyboard on WinRT
[NEW] FileUtils: checked filename case characters on windows
[NEW] FileUitls: added supporting loading files that which file path include utf-8 characters
[NEW] PhysicsShape: added sensor property
[FIX] 3rd: fix PIE link error on iOS caused by libpng and libtiff
[FIX] AssetsManager: crashed issue
[FIX] EaseRateAction: no way to create an `EaseRateAction` instance
[FIX] Label: crashed if invoking `setString(text` after `getLetter(letterIndex)` and `letterIndex` is greater than the length of text
[FIX] Label: position is wrong if label content is changed after invoking `getLetter(letterIndex)`
[FIX] Label: shadow effect cause OpenGL error on iOS
[FIX] Label: outline effect doesn't match characters well
[FIX] Sprite3D: setGLProgram() does not work
[FIX] Terrain: terrain is on top of particles, particles can not be seen
[FIX] WebView: memory leak on iOS
[FIX] WebView: crashed if url contains illegal characters on Android
cocos2d-x-3.6 Apr.30 2015
[NEW] 3rd: update chipmunk to v 6.2.2 on Windows 8.1 Universal App

View File

@ -71,6 +71,7 @@ endif()
option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
option(USE_BOX2D "Use box2d for physics library" OFF)
option(USE_BULLET "Use bullet for physics3d library" ON)
option(USE_WEBP "Use WebP codec" ${USE_WEBP_DEFAULT})
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(DEBUG_MODE "Debug or release?" ON)
@ -248,6 +249,24 @@ else()
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
endif(USE_BOX2D)
# Bullet (not prebuilded, exists as source)
if(USE_BULLET)
if(USE_PREBUILT_LIBS)
add_subdirectory(external/bullet)
set(BULLET_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/bullet)
set(BULLET_LIBRARIES bullet)
else()
cocos_find_package(bullet BULLET REQUIRED)
set(BULLET_LIBRARIES bullet)
endif()
message(STATUS "Bullet include dirs: ${BULLET_INCLUDE_DIRS}")
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
add_definitions(-DCC_USE_PHYSICS=1)
else()
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=0)
add_definitions(-DCC_USE_3D_PHYSICS=0)
endif(USE_BULLET)
# Tinyxml2 (not prebuilded, exists as source)
if(USE_PREBUILT_LIBS)
add_subdirectory(external/tinyxml2)

View File

@ -135,10 +135,10 @@ Build Requirements
* Mac OS X 10.7+, Xcode 5.1+
* or Ubuntu 12.10+, CMake 2.6+
* or Windows 7+, VS 2012+
* or Windows 7+, VS 2013+
* Python 2.7.5
* NDK r10c+ is required to build Android games
* Windows Phone/Store 8.0 VS 2012+
* Windows Phone/Store 8.0 VS 2013+
* Windows Phone/Store 8.1 VS 2013 Update 3+
@ -186,7 +186,7 @@ $ bin/lua-empty-test/lua-empty-test
* For Windows
Open the `cocos2d-x/build/cocos2d-win32.vc2012.sln`
Open the `cocos2d-x/build/cocos2d-win32.vc2013.sln`
* For Windows 8.1 Universal Apps (Phone and Store)

View File

@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
MinimumVisualStudioVersion = 12.0.21005.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d", "..\cocos\2d\libcocos2d.vcxproj", "{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "External", "{92D54E36-7916-48EF-A951-224DD3B25442}"
@ -14,6 +14,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libjscocos2d", "..\cocos\sc
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-tests", "..\tests\js-tests\project\proj.win32\js-tests.vcxproj", "{D0F06A44-A245-4D13-A498-0120C203B539}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbullet", "..\external\bullet\proj.win32\libbullet.vcxproj", "{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
@ -52,6 +54,12 @@ Global
{D0F06A44-A245-4D13-A498-0120C203B539}.Release|ARM.ActiveCfg = Release|Win32
{D0F06A44-A245-4D13-A498-0120C203B539}.Release|Win32.ActiveCfg = Release|Win32
{D0F06A44-A245-4D13-A498-0120C203B539}.Release|Win32.Build.0 = Release|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Debug|ARM.ActiveCfg = Debug|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Debug|Win32.ActiveCfg = Debug|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Debug|Win32.Build.0 = Debug|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Release|ARM.ActiveCfg = Release|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Release|Win32.ActiveCfg = Release|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -59,6 +67,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{B7C2A162-DEC9-4418-972E-240AB3CBFCAE} = {92D54E36-7916-48EF-A951-224DD3B25442}
{929480E7-23C0-4DF6-8456-096D71547116} = {92D54E36-7916-48EF-A951-224DD3B25442}
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B} = {92D54E36-7916-48EF-A951-224DD3B25442}
EndGlobalSection
GlobalSection(DPCodeReviewSolutionGUID) = preSolution
DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000}

View File

@ -1,8 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 12.0.21005.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libcocos2d", "libcocos2d", "{B3F299D4-B4CA-4F0B-8BE2-FB328483BC13}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_8_1.Shared", "..\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems", "{5D6F020F-7E72-4494-90A0-2DF11D235DF9}"
@ -11,14 +11,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_8_1.Windows", ".
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_8_1.WindowsPhone", "..\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.WindowsPhone\libcocos2d_8_1.WindowsPhone.vcxproj", "{22F3B9DF-1209-4574-8331-003966F562BF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cpp-tests", "cpp-tests", "{572742C5-9322-4548-AB8B-96C3750A1B5D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpp-tests.Shared", "..\tests\cpp-tests\proj.win8.1-universal\cpp-tests.Shared\cpp-tests.Shared.vcxitems", "{BE3A1791-5BCE-4CEA-92CD-0E2D86DDE27A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpp-tests.Windows", "..\tests\cpp-tests\proj.win8.1-universal\cpp-tests.Windows\cpp-tests.Windows.vcxproj", "{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpp-tests.WindowsPhone", "..\tests\cpp-tests\proj.win8.1-universal\cpp-tests.WindowsPhone\cpp-tests.WindowsPhone.vcxproj", "{15247C71-5289-4913-B88F-E253CC353720}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "External", "{85630454-74EA-4B5B-9B62-0E459B4476CB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libbox2d", "libbox2d", "{B3D1A3D5-9F54-43AF-9322-230B53242B78}"
@ -37,14 +29,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine.Windows", "..\coco
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine.WindowsPhone", "..\cocos\editor-support\spine\proj.win8.1-universal\libSpine.WindowsPhone\libSpine.WindowsPhone.vcxproj", "{CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cpp-empty-test", "cpp-empty-test", "{B70EF25E-E352-4020-BCDF-388973E44637}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloCpp.Shared", "..\tests\cpp-empty-test\proj.win8.1-universal\HelloCpp.Shared\HelloCpp.Shared.vcxitems", "{A3AD93E4-0B2F-4C58-9181-69BED2E42E3E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloCpp.Windows", "..\tests\cpp-empty-test\proj.win8.1-universal\HelloCpp.Windows\HelloCpp.Windows.vcxproj", "{79A8FCDA-4B12-4DD1-B676-FF148D651638}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloCpp.WindowsPhone", "..\tests\cpp-empty-test\proj.win8.1-universal\HelloCpp.WindowsPhone\HelloCpp.WindowsPhone.vcxproj", "{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "js-tests", "js-tests", "{8E24A044-D83D-476D-886D-F40E3CC621DF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "js-tests.Shared", "..\tests\js-tests\project\proj.win8.1-universal\App.Shared\js-tests.Shared.vcxitems", "{AE6763F6-1549-441E-AFB5-377BE1C776DC}"
@ -66,14 +50,10 @@ Global
..\tests\js-tests\project\proj.win8.1-universal\App.Shared\js-tests.Shared.vcxitems*{ae6763f6-1549-441e-afb5-377be1c776dc}*SharedItemsImports = 9
..\tests\js-tests\project\proj.win8.1-universal\App.Shared\js-tests.Shared.vcxitems*{94874b5b-398f-448a-a366-35a35dc1db9c}*SharedItemsImports = 4
..\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems*{9335005f-678e-4e8e-9b84-50037216aec8}*SharedItemsImports = 4
..\tests\cpp-tests\proj.win8.1-universal\cpp-tests.Shared\cpp-tests.Shared.vcxitems*{15247c71-5289-4913-b88f-e253cc353720}*SharedItemsImports = 4
..\tests\cpp-empty-test\proj.win8.1-universal\HelloCpp.Shared\HelloCpp.Shared.vcxitems*{a3ad93e4-0b2f-4c58-9181-69bed2e42e3e}*SharedItemsImports = 9
..\tests\js-tests\project\proj.win8.1-universal\App.Shared\js-tests.Shared.vcxitems*{70914fc8-7709-4cd6-b86b-c63fde5478db}*SharedItemsImports = 4
..\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Shared\libSpine.Shared.vcxitems*{cc1da216-a80d-4be4-b309-acb6af313aff}*SharedItemsImports = 4
..\external\Box2D\proj.win8.1-universal\libbox2d.Shared\libbox2d.Shared.vcxitems*{4a3c6ba8-c227-498b-aa21-40bda27b461f}*SharedItemsImports = 9
..\tests\cpp-empty-test\proj.win8.1-universal\HelloCpp.Shared\HelloCpp.Shared.vcxitems*{79a8fcda-4b12-4dd1-b676-ff148d651638}*SharedItemsImports = 4
..\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Shared\libSpine.Shared.vcxitems*{adafd00d-a0d6-46ef-9f0b-ea2880bfe1de}*SharedItemsImports = 9
..\tests\cpp-tests\proj.win8.1-universal\cpp-tests.Shared\cpp-tests.Shared.vcxitems*{be3a1791-5bce-4cea-92cd-0e2d86dde27a}*SharedItemsImports = 9
..\cocos\scripting\js-bindings\proj.win8.1-universal\libjscocos2d\libjscocos2d.Shared\libjscocos2d.Shared.vcxitems*{ca082ec4-17ce-430b-8207-d1e947a5d1e9}*SharedItemsImports = 4
..\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems*{5d6f020f-7e72-4494-90a0-2df11d235df9}*SharedItemsImports = 9
..\cocos\scripting\js-bindings\proj.win8.1-universal\libjscocos2d\libjscocos2d.Shared\libjscocos2d.Shared.vcxitems*{bea66276-51dd-4c53-92a8-f3d1fea50892}*SharedItemsImports = 9
@ -82,8 +62,6 @@ Global
..\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems*{22f3b9df-1209-4574-8331-003966f562bf}*SharedItemsImports = 4
..\external\Box2D\proj.win8.1-universal\libbox2d.Shared\libbox2d.Shared.vcxitems*{22f798d8-bfff-4754-996f-a5395343d5ec}*SharedItemsImports = 4
..\cocos\editor-support\spine\proj.win8.1-universal\libSpine.Shared\libSpine.Shared.vcxitems*{f3550fe0-c795-44f6-8feb-093eb68143ae}*SharedItemsImports = 4
..\tests\cpp-tests\proj.win8.1-universal\cpp-tests.Shared\cpp-tests.Shared.vcxitems*{f2bae06b-caae-43ee-b21b-57fa48db04fa}*SharedItemsImports = 4
..\tests\cpp-empty-test\proj.win8.1-universal\HelloCpp.Shared\HelloCpp.Shared.vcxitems*{396fe85e-bb05-4b92-bccb-f89aed4ea41a}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
@ -116,38 +94,6 @@ Global
{22F3B9DF-1209-4574-8331-003966F562BF}.Release|Win32.ActiveCfg = Release|Win32
{22F3B9DF-1209-4574-8331-003966F562BF}.Release|Win32.Build.0 = Release|Win32
{22F3B9DF-1209-4574-8331-003966F562BF}.Release|x64.ActiveCfg = Release|Win32
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Debug|ARM.ActiveCfg = Debug|ARM
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Debug|ARM.Build.0 = Debug|ARM
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Debug|ARM.Deploy.0 = Debug|ARM
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Debug|Win32.ActiveCfg = Debug|Win32
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Debug|Win32.Build.0 = Debug|Win32
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Debug|Win32.Deploy.0 = Debug|Win32
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Debug|x64.ActiveCfg = Debug|x64
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Debug|x64.Build.0 = Debug|x64
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Debug|x64.Deploy.0 = Debug|x64
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Release|ARM.ActiveCfg = Release|ARM
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Release|ARM.Build.0 = Release|ARM
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Release|ARM.Deploy.0 = Release|ARM
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Release|Win32.ActiveCfg = Release|Win32
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Release|Win32.Build.0 = Release|Win32
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Release|Win32.Deploy.0 = Release|Win32
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Release|x64.ActiveCfg = Release|x64
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Release|x64.Build.0 = Release|x64
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA}.Release|x64.Deploy.0 = Release|x64
{15247C71-5289-4913-B88F-E253CC353720}.Debug|ARM.ActiveCfg = Debug|ARM
{15247C71-5289-4913-B88F-E253CC353720}.Debug|ARM.Build.0 = Debug|ARM
{15247C71-5289-4913-B88F-E253CC353720}.Debug|ARM.Deploy.0 = Debug|ARM
{15247C71-5289-4913-B88F-E253CC353720}.Debug|Win32.ActiveCfg = Debug|Win32
{15247C71-5289-4913-B88F-E253CC353720}.Debug|Win32.Build.0 = Debug|Win32
{15247C71-5289-4913-B88F-E253CC353720}.Debug|Win32.Deploy.0 = Debug|Win32
{15247C71-5289-4913-B88F-E253CC353720}.Debug|x64.ActiveCfg = Debug|Win32
{15247C71-5289-4913-B88F-E253CC353720}.Release|ARM.ActiveCfg = Release|ARM
{15247C71-5289-4913-B88F-E253CC353720}.Release|ARM.Build.0 = Release|ARM
{15247C71-5289-4913-B88F-E253CC353720}.Release|ARM.Deploy.0 = Release|ARM
{15247C71-5289-4913-B88F-E253CC353720}.Release|Win32.ActiveCfg = Release|Win32
{15247C71-5289-4913-B88F-E253CC353720}.Release|Win32.Build.0 = Release|Win32
{15247C71-5289-4913-B88F-E253CC353720}.Release|Win32.Deploy.0 = Release|Win32
{15247C71-5289-4913-B88F-E253CC353720}.Release|x64.ActiveCfg = Release|Win32
{3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|ARM.ActiveCfg = Debug|ARM
{3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|ARM.Build.0 = Debug|ARM
{3B26A12D-3A44-47EA-82D2-282660FC844D}.Debug|Win32.ActiveCfg = Debug|Win32
@ -192,38 +138,6 @@ Global
{CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|Win32.ActiveCfg = Release|Win32
{CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|Win32.Build.0 = Release|Win32
{CC1DA216-A80D-4BE4-B309-ACB6AF313AFF}.Release|x64.ActiveCfg = Release|Win32
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|ARM.ActiveCfg = Debug|ARM
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|ARM.Build.0 = Debug|ARM
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|ARM.Deploy.0 = Debug|ARM
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|Win32.ActiveCfg = Debug|Win32
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|Win32.Build.0 = Debug|Win32
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|Win32.Deploy.0 = Debug|Win32
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|x64.ActiveCfg = Debug|x64
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|x64.Build.0 = Debug|x64
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Debug|x64.Deploy.0 = Debug|x64
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|ARM.ActiveCfg = Release|ARM
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|ARM.Build.0 = Release|ARM
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|ARM.Deploy.0 = Release|ARM
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|Win32.ActiveCfg = Release|Win32
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|Win32.Build.0 = Release|Win32
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|Win32.Deploy.0 = Release|Win32
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|x64.ActiveCfg = Release|x64
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|x64.Build.0 = Release|x64
{79A8FCDA-4B12-4DD1-B676-FF148D651638}.Release|x64.Deploy.0 = Release|x64
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|ARM.ActiveCfg = Debug|ARM
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|ARM.Build.0 = Debug|ARM
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|ARM.Deploy.0 = Debug|ARM
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|Win32.ActiveCfg = Debug|Win32
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|Win32.Build.0 = Debug|Win32
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|Win32.Deploy.0 = Debug|Win32
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Debug|x64.ActiveCfg = Debug|Win32
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|ARM.ActiveCfg = Release|ARM
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|ARM.Build.0 = Release|ARM
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|ARM.Deploy.0 = Release|ARM
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|Win32.ActiveCfg = Release|Win32
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|Win32.Build.0 = Release|Win32
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|Win32.Deploy.0 = Release|Win32
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A}.Release|x64.ActiveCfg = Release|Win32
{70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|ARM.ActiveCfg = Debug|ARM
{70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|ARM.Build.0 = Debug|ARM
{70914FC8-7709-4CD6-B86B-C63FDE5478DB}.Debug|ARM.Deploy.0 = Debug|ARM
@ -286,9 +200,6 @@ Global
{5D6F020F-7E72-4494-90A0-2DF11D235DF9} = {B3F299D4-B4CA-4F0B-8BE2-FB328483BC13}
{9335005F-678E-4E8E-9B84-50037216AEC8} = {B3F299D4-B4CA-4F0B-8BE2-FB328483BC13}
{22F3B9DF-1209-4574-8331-003966F562BF} = {B3F299D4-B4CA-4F0B-8BE2-FB328483BC13}
{BE3A1791-5BCE-4CEA-92CD-0E2D86DDE27A} = {572742C5-9322-4548-AB8B-96C3750A1B5D}
{F2BAE06B-CAAE-43EE-B21B-57FA48DB04FA} = {572742C5-9322-4548-AB8B-96C3750A1B5D}
{15247C71-5289-4913-B88F-E253CC353720} = {572742C5-9322-4548-AB8B-96C3750A1B5D}
{B3D1A3D5-9F54-43AF-9322-230B53242B78} = {85630454-74EA-4B5B-9B62-0E459B4476CB}
{4A3C6BA8-C227-498B-AA21-40BDA27B461F} = {B3D1A3D5-9F54-43AF-9322-230B53242B78}
{3B26A12D-3A44-47EA-82D2-282660FC844D} = {B3D1A3D5-9F54-43AF-9322-230B53242B78}
@ -297,9 +208,6 @@ Global
{ADAFD00D-A0D6-46EF-9F0B-EA2880BFE1DE} = {6FEB795C-C98C-4C8C-A88B-A35DEE205348}
{F3550FE0-C795-44F6-8FEB-093EB68143AE} = {6FEB795C-C98C-4C8C-A88B-A35DEE205348}
{CC1DA216-A80D-4BE4-B309-ACB6AF313AFF} = {6FEB795C-C98C-4C8C-A88B-A35DEE205348}
{A3AD93E4-0B2F-4C58-9181-69BED2E42E3E} = {B70EF25E-E352-4020-BCDF-388973E44637}
{79A8FCDA-4B12-4DD1-B676-FF148D651638} = {B70EF25E-E352-4020-BCDF-388973E44637}
{396FE85E-BB05-4B92-BCCB-F89AED4EA41A} = {B70EF25E-E352-4020-BCDF-388973E44637}
{AE6763F6-1549-441E-AFB5-377BE1C776DC} = {8E24A044-D83D-476D-886D-F40E3CC621DF}
{70914FC8-7709-4CD6-B86B-C63FDE5478DB} = {8E24A044-D83D-476D-886D-F40E3CC621DF}
{94874B5B-398F-448A-A366-35A35DC1DB9C} = {8E24A044-D83D-476D-886D-F40E3CC621DF}

View File

@ -1,8 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
MinimumVisualStudioVersion = 12.0.21005.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpp-tests", "..\tests\cpp-tests\proj.win32\cpp-tests.vcxproj", "{76A39BB2-9B84-4C65-98A5-654D86B86F2A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua-tests", "..\tests\lua-tests\project\proj.win32\lua-tests.win32.vcxproj", "{4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}"
@ -12,6 +12,9 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua-empty-test", "..\tests\lua-empty-test\project\proj.win32\lua-empty-test.vcxproj", "{13E55395-94A2-4CD9-BFC2-1A051F80C17D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d", "..\cocos\2d\libcocos2d.vcxproj", "{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}"
ProjectSection(ProjectDependencies) = postProject
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B} = {012DFF48-A13F-4F52-B07B-F8B9D21CE95B}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libluacocos2d", "..\cocos\scripting\lua-bindings\proj.win32\libluacocos2d.vcxproj", "{9F2D6CE6-C893-4400-B50C-6DB70CC2562F}"
EndProject
@ -21,6 +24,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine", "..\cocos\editor
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbox2d", "..\external\Box2D\proj.win32\libbox2d.vcxproj", "{929480E7-23C0-4DF6-8456-096D71547116}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbullet", "..\external\bullet\proj.win32\libbullet.vcxproj", "{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
@ -77,6 +82,12 @@ Global
{929480E7-23C0-4DF6-8456-096D71547116}.Release|ARM.ActiveCfg = Release|Win32
{929480E7-23C0-4DF6-8456-096D71547116}.Release|Win32.ActiveCfg = Release|Win32
{929480E7-23C0-4DF6-8456-096D71547116}.Release|Win32.Build.0 = Release|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Debug|ARM.ActiveCfg = Debug|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Debug|Win32.ActiveCfg = Debug|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Debug|Win32.Build.0 = Debug|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Release|ARM.ActiveCfg = Release|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Release|Win32.ActiveCfg = Release|Win32
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -84,6 +95,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{B7C2A162-DEC9-4418-972E-240AB3CBFCAE} = {92D54E36-7916-48EF-A951-224DD3B25442}
{929480E7-23C0-4DF6-8456-096D71547116} = {92D54E36-7916-48EF-A951-224DD3B25442}
{012DFF48-A13F-4F52-B07B-F8B9D21CE95B} = {92D54E36-7916-48EF-A951-224DD3B25442}
EndGlobalSection
GlobalSection(DPCodeReviewSolutionGUID) = preSolution
DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000}

View File

@ -2,7 +2,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
MinimumVisualStudioVersion = 12.0.21005.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libcocos2d", "libcocos2d", "{B3F299D4-B4CA-4F0B-8BE2-FB328483BC13}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_8_1.Shared", "..\cocos\2d\libcocos2d_8_1\libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems", "{5D6F020F-7E72-4494-90A0-2DF11D235DF9}"

File diff suppressed because it is too large Load Diff

View File

@ -836,6 +836,8 @@
B63993321A49359F00B07923 /* Particle3D in Resources */ = {isa = PBXBuildFile; fileRef = B63993301A49359F00B07923 /* Particle3D */; };
B6C039D919C95D83007207DC /* LightTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6C039D719C95D83007207DC /* LightTest.cpp */; };
B6C039DA19C95D83007207DC /* LightTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6C039D719C95D83007207DC /* LightTest.cpp */; };
B6CAB54E1AF9AA6C00B9B856 /* Physics3DTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6CAB54C1AF9AA6C00B9B856 /* Physics3DTest.cpp */; };
B6CAB54F1AF9AA6C00B9B856 /* Physics3DTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6CAB54C1AF9AA6C00B9B856 /* Physics3DTest.cpp */; };
C04F935A1941B05400E9FEAB /* TileMapTest2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C04F93581941B05400E9FEAB /* TileMapTest2.cpp */; };
C04F935B1941B05400E9FEAB /* TileMapTest2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C04F93581941B05400E9FEAB /* TileMapTest2.cpp */; };
C08689C118D370C90093E810 /* background.caf in Resources */ = {isa = PBXBuildFile; fileRef = C08689C018D370C90093E810 /* background.caf */; };
@ -1781,6 +1783,8 @@
B63993301A49359F00B07923 /* Particle3D */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Particle3D; path = "../tests/cpp-tests/Resources/Particle3D"; sourceTree = "<group>"; };
B6C039D719C95D83007207DC /* LightTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LightTest.cpp; path = LightTest/LightTest.cpp; sourceTree = "<group>"; };
B6C039D819C95D83007207DC /* LightTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LightTest.h; path = LightTest/LightTest.h; sourceTree = "<group>"; };
B6CAB54C1AF9AA6C00B9B856 /* Physics3DTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Physics3DTest.cpp; path = Physics3DTest/Physics3DTest.cpp; sourceTree = "<group>"; };
B6CAB54D1AF9AA6C00B9B856 /* Physics3DTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Physics3DTest.h; path = Physics3DTest/Physics3DTest.h; sourceTree = "<group>"; };
C04F93581941B05400E9FEAB /* TileMapTest2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TileMapTest2.cpp; sourceTree = "<group>"; };
C04F93591941B05400E9FEAB /* TileMapTest2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TileMapTest2.h; sourceTree = "<group>"; };
C08689C018D370C90093E810 /* background.caf */ = {isa = PBXFileReference; lastKnownFileType = file; name = background.caf; path = "../tests/cpp-tests/Resources/background.caf"; sourceTree = "<group>"; };
@ -2199,6 +2203,7 @@
1AC3592418CECF0A00F37B72 /* Classes */ = {
isa = PBXGroup;
children = (
B6CAB54B1AF9AA4B00B9B856 /* Physics3DTest */,
5046AB471AF2A8D80060550B /* MaterialSystemTest */,
6886696E1AE8E8A000C2CFD9 /* SpritePolygonTest */,
B603F1AC1AC8EA2E00A9579C /* TerrainTest */,
@ -4030,6 +4035,15 @@
name = LightTest;
sourceTree = "<group>";
};
B6CAB54B1AF9AA4B00B9B856 /* Physics3DTest */ = {
isa = PBXGroup;
children = (
B6CAB54C1AF9AA6C00B9B856 /* Physics3DTest.cpp */,
B6CAB54D1AF9AA6C00B9B856 /* Physics3DTest.h */,
);
name = Physics3DTest;
sourceTree = "<group>";
};
D0FD03611A3B543700825BB5 /* AllocatorTest */ = {
isa = PBXGroup;
children = (
@ -4881,6 +4895,7 @@
1AC35C2F18CECF0C00F37B72 /* PerformanceParticleTest.cpp in Sources */,
1AC35B4918CECF0C00F37B72 /* Bug-914.cpp in Sources */,
1AC35B6318CECF0C00F37B72 /* EffectsAdvancedTest.cpp in Sources */,
B6CAB54E1AF9AA6C00B9B856 /* Physics3DTest.cpp in Sources */,
B639932E1A490EC700B07923 /* Particle3DTest.cpp in Sources */,
1AC35C5F18CECF0C00F37B72 /* Paddle.cpp in Sources */,
1AC35BDB18CECF0C00F37B72 /* SceneEditorTest.cpp in Sources */,
@ -5049,6 +5064,7 @@
1AC35BEC18CECF0C00F37B72 /* CCControlSliderTest.cpp in Sources */,
29080DB4191B595E0066F8DF /* UILayoutTest_Editor.cpp in Sources */,
1AC35C4E18CECF0C00F37B72 /* SpineTest.cpp in Sources */,
B6CAB54F1AF9AA6C00B9B856 /* Physics3DTest.cpp in Sources */,
1AC35C1E18CECF0C00F37B72 /* NewRendererTest.cpp in Sources */,
5EBEECB11995247000429821 /* DrawNode3D.cpp in Sources */,
1AC35B6818CECF0C00F37B72 /* AnimationsTestLayer.cpp in Sources */,
@ -5910,6 +5926,7 @@
"COCOS2D_DEBUG=1",
USE_FILE32API,
"CC_ENABLE_CHIPMUNK_INTEGRATION=1",
"CC_ENABLE_BULLET_INTEGRATION=1",
);
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
@ -5938,6 +5955,7 @@
NDEBUG,
USE_FILE32API,
"CC_ENABLE_CHIPMUNK_INTEGRATION=1",
"CC_ENABLE_BULLET_INTEGRATION=1",
);
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;

View File

@ -1,8 +0,0 @@
@echo off
SETLOCAL
:start
mkdir win32-msvc-vs2012-x86
cd win32-msvc-vs2012-x86
cmake -G "Visual Studio 11" ../..
pause

View File

@ -165,7 +165,7 @@ Sequence* Sequence::createWithTwoActions(FiniteTimeAction *actionOne, FiniteTime
return sequence;
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
Sequence* Sequence::variadicCreate(FiniteTimeAction *action1, ...)
{
va_list params;
@ -554,7 +554,7 @@ RepeatForever *RepeatForever::reverse() const
// Spawn
//
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
Spawn* Spawn::variadicCreate(FiniteTimeAction *action1, ...)
{
va_list params;
@ -2511,4 +2511,60 @@ void TargetedAction::setForcedTarget(Node* forcedTarget)
}
}
// ActionFloat
ActionFloat* ActionFloat::create(float duration, float from, float to, ActionFloatCallback callback)
{
auto ref = new (std::nothrow) ActionFloat();
if (ref && ref->initWithDuration(duration, from, to, callback))
{
ref->autorelease();
return ref;
}
CC_SAFE_DELETE(ref);
return ref;
}
bool ActionFloat::initWithDuration(float duration, float from, float to, ActionFloatCallback callback)
{
if (ActionInterval::initWithDuration(duration))
{
_from = from;
_to = to;
_callback = callback;
return true;
}
return false;
}
ActionFloat* ActionFloat::clone() const
{
auto a = new (std::nothrow) ActionFloat();
a->initWithDuration(_duration, _from, _to, _callback);
a->autorelease();
return a;
}
void ActionFloat::startWithTarget(Node *target)
{
ActionInterval::startWithTarget(target);
_delta = _to - _from;
}
void ActionFloat::update(float delta)
{
float value = _to - _delta * (1 - delta);
if (_callback)
{
// report back value to caller
_callback(value);
}
}
ActionFloat* ActionFloat::reverse() const
{
return ActionFloat::create(_duration, _to, _from, _callback);
}
NS_CC_END

View File

@ -124,8 +124,8 @@ public:
*
* @return An autoreleased Sequence object.
*/
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// WP8 in VS2012 does not support nullptr in variable args lists and variadic templates are also not supported
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// VS2013 does not support nullptr in variable args lists and variadic templates are also not supported
typedef FiniteTimeAction* M;
static Sequence* create(M m1, std::nullptr_t listEnd) { return variadicCreate(m1, NULL); }
static Sequence* create(M m1, M m2, std::nullptr_t listEnd) { return variadicCreate(m1, m2, NULL); }
@ -351,8 +351,8 @@ public:
*
* @return An autoreleased Spawn object.
*/
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// WP8 in VS2012 does not support nullptr in variable args lists and variadic templates are also not supported.
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// VS2013 does not support nullptr in variable args lists and variadic templates are also not supported.
typedef FiniteTimeAction* M;
static Spawn* create(M m1, std::nullptr_t listEnd) { return variadicCreate(m1, NULL); }
static Spawn* create(M m1, M m2, std::nullptr_t listEnd) { return variadicCreate(m1, m2, NULL); }
@ -1525,6 +1525,58 @@ private:
CC_DISALLOW_COPY_AND_ASSIGN(TargetedAction);
};
/**
* @class ActionFloat
* @brief Action used to animate any value in range [from,to] over specified time interval
*/
class CC_DLL ActionFloat : public ActionInterval
{
public:
/**
* Callback function used to report back result
*/
typedef std::function<void(float value)> ActionFloatCallback;
/**
* Creates FloatAction with specified duration, from value, to value and callback to report back
* results
* @param duration of the action
* @param from value to start from
* @param to value to be at the end of the action
* @param callback to report back result
*
* @return An autoreleased ActionFloat object
*/
static ActionFloat* create(float duration, float from, float to, ActionFloatCallback callback);
/**
* Overrided ActionInterval methods
*/
void startWithTarget(Node* target) override;
void update(float delta) override;
ActionFloat* reverse() const override;
ActionFloat* clone() const override;
CC_CONSTRUCTOR_ACCESS:
ActionFloat() {};
virtual ~ActionFloat() {};
bool initWithDuration(float duration, float from, float to, ActionFloatCallback callback);
protected:
/* From value */
float _from;
/* To value */
float _to;
/* delta time */
float _delta;
/* Callback to report back results */
ActionFloatCallback _callback;
private:
CC_DISALLOW_COPY_AND_ASSIGN(ActionFloat);
};
// end of actions group
/// @}

View File

@ -205,14 +205,6 @@ bool Camera::initPerspective(float fieldOfView, float aspectRatio, float nearPla
_nearPlane = nearPlane;
_farPlane = farPlane;
Mat4::createPerspective(_fieldOfView, _aspectRatio, _nearPlane, _farPlane, &_projection);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
//if needed, we need to add a rotation for Landscape orientations on Windows Phone 8 since it is always in Portrait Mode
GLView* view = Director::getInstance()->getOpenGLView();
if(view != nullptr)
{
setAdditionalProjection(view->getOrientationMatrix());
}
#endif
_viewProjectionDirty = true;
_frustumDirty = true;
@ -226,14 +218,6 @@ bool Camera::initOrthographic(float zoomX, float zoomY, float nearPlane, float f
_nearPlane = nearPlane;
_farPlane = farPlane;
Mat4::createOrthographicOffCenter(0, _zoom[0], 0, _zoom[1], _nearPlane, _farPlane, &_projection);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
//if needed, we need to add a rotation for Landscape orientations on Windows Phone 8 since it is always in Portrait Mode
GLView* view = Director::getInstance()->getOpenGLView();
if(view != nullptr)
{
setAdditionalProjection(view->getOrientationMatrix());
}
#endif
_viewProjectionDirty = true;
_frustumDirty = true;

View File

@ -156,4 +156,19 @@ bool ComponentContainer::isEmpty() const
return (_components == nullptr || _components->empty());
}
void ComponentContainer::onEnter()
{
for (auto iter = _components->begin(); iter != _components->end(); ++iter)
{
iter->second->onEnter();
}
}
void ComponentContainer::onExit()
{
for (auto iter = _components->begin(); iter != _components->end(); ++iter)
{
iter->second->onExit();
}
}
NS_CC_END

View File

@ -58,6 +58,10 @@ public:
virtual bool remove(Component *com);
virtual void removeAll();
virtual void visit(float delta);
virtual void onEnter();
virtual void onExit();
public:
bool isEmpty() const;

View File

@ -298,7 +298,7 @@ std::set<unsigned int>* BMFontConfiguration::parseConfigFile(const std::string&
int parseCount = 0;
while (next)
{
lineLength = next - base;
lineLength = ((int)(next - base));
memcpy(line, contents + parseCount, lineLength);
line[lineLength] = 0;

View File

@ -269,10 +269,11 @@ unsigned char* FontFreeType::getGlyphBitmap(unsigned short theChar, long &outWid
break;
}
outRect.origin.x = _fontRef->glyph->metrics.horiBearingX >> 6;
outRect.origin.y = - (_fontRef->glyph->metrics.horiBearingY >> 6);
outRect.size.width = (_fontRef->glyph->metrics.width >> 6);
outRect.size.height = (_fontRef->glyph->metrics.height >> 6);
auto& metrics = _fontRef->glyph->metrics;
outRect.origin.x = metrics.horiBearingX >> 6;
outRect.origin.y = -(metrics.horiBearingY >> 6);
outRect.size.width = (metrics.width >> 6);
outRect.size.height = (metrics.height >> 6);
xAdvance = (static_cast<int>(_fontRef->glyph->metrics.horiAdvance >> 6));
@ -294,35 +295,49 @@ unsigned char* FontFreeType::getGlyphBitmap(unsigned short theChar, long &outWid
break;
}
auto outlineWidth = (bbox.xMax - bbox.xMin)>>6;
auto outlineHeight = (bbox.yMax - bbox.yMin)>>6;
long glyphMinX = outRect.origin.x;
long glyphMaxX = outRect.origin.x + outWidth;
long glyphMinY = -outHeight - outRect.origin.y;
long glyphMaxY = -outRect.origin.y;
auto blendWidth = outlineWidth > outWidth ? outlineWidth : outWidth;
auto blendHeight = outlineHeight > outHeight ? outlineHeight : outHeight;
auto outlineMinX = bbox.xMin >> 6;
auto outlineMaxX = bbox.xMax >> 6;
auto outlineMinY = bbox.yMin >> 6;
auto outlineMaxY = bbox.yMax >> 6;
auto outlineWidth = outlineMaxX - outlineMinX;
auto outlineHeight = outlineMaxY - outlineMinY;
long index,index2;
auto blendImageMinX = MIN(outlineMinX, glyphMinX);
auto blendImageMaxY = MAX(outlineMaxY, glyphMaxY);
auto blendWidth = MAX(outlineMaxX, glyphMaxX) - blendImageMinX;
auto blendHeight = blendImageMaxY - MIN(outlineMinY, glyphMinY);
outRect.origin.x = blendImageMinX;
outRect.origin.y = -blendImageMaxY;
long index, index2;
auto blendImage = new unsigned char[blendWidth * blendHeight * 2];
memset(blendImage, 0, blendWidth * blendHeight * 2);
auto px = (blendWidth - outlineWidth) / 2;
auto py = (blendHeight - outlineHeight) / 2;
auto px = outlineMinX - blendImageMinX;
auto py = blendImageMaxY - outlineMaxY;
for (int x = 0; x < outlineWidth; ++x)
{
for (int y = 0; y < outlineHeight; ++y)
{
index = px + x + ( (py + y) * blendWidth );
index = px + x + ((py + y) * blendWidth);
index2 = x + (y * outlineWidth);
blendImage[2 * index] = outlineBitmap[index2];
}
}
px = (blendWidth - outWidth) / 2;
py = (blendHeight - outHeight) / 2;
px = glyphMinX - blendImageMinX;
py = blendImageMaxY - glyphMaxY;
for (int x = 0; x < outWidth; ++x)
{
for (int y = 0; y < outHeight; ++y)
{
index = px + x + ( (y + py) * blendWidth );
index = px + x + ((y + py) * blendWidth);
index2 = x + (y * outWidth);
blendImage[2 * index + 1] = copyBitmap[index2];
}

View File

@ -33,7 +33,7 @@
#include <string>
#include <ft2build.h>
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#define generic GenericFromFreeTypeLibrary
#define internal InternalFromFreeTypeLibrary
#endif
@ -41,7 +41,7 @@
#include FT_FREETYPE_H
#include FT_STROKER_H
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#undef generic
#undef internal
#endif

View File

@ -406,13 +406,7 @@ void Label::setFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false *
_commonLineHeight = _fontAtlas->getCommonLineHeight();
_contentDirty = true;
}
#if CC_TARGET_PLATFORM != CC_PLATFORM_WP8
_useDistanceField = distanceFieldEnabled;
#else
// some older Windows Phones cannot run the ccShader_Label_df.frag program
// so we must disable distance field
_useDistanceField = false;
#endif
_useA8Shader = useA8Shader;
if (_currentLabelType != LabelType::TTF)
@ -621,7 +615,7 @@ void Label::alignText()
int tag = child->getTag();
if (tag >= strLen)
{
SpriteBatchNode::removeChild(child, true);
child->removeFromParentAndCleanup(true);
}
else if (tag >= 0)
{
@ -633,10 +627,11 @@ void Label::alignText()
uvRect.size.width = letterDef.width;
uvRect.origin.x = letterDef.U;
uvRect.origin.y = letterDef.V;
letterSprite->setTexture(textures.at(letterDef.textureID));
letterSprite->setTextureRect(uvRect);
letterSprite->setPosition(_lettersInfo[tag].position);
letterSprite->setBatchNode(_batchNodes[letterDef.textureID]);
letterSprite->setTextureRect(uvRect, false, uvRect.size);
letterSprite->setPosition(_lettersInfo[tag].position.x + letterDef.width/2,
_lettersInfo[tag].position.y - letterDef.height/2);
}
++index;
}
@ -966,8 +961,7 @@ void Label::onDraw(const Mat4& transform, bool transformUpdated)
for(const auto &child: _children)
{
if(child->getTag() >= 0)
child->updateTransform();
child->updateTransform();
}
for (const auto& batchNode:_batchNodes)

View File

@ -845,7 +845,7 @@ LayerMultiplex::~LayerMultiplex()
}
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
LayerMultiplex * LayerMultiplex::createVariadic(Layer * layer, ...)
{
va_list args;

View File

@ -596,8 +596,8 @@ public:
* In lua:local create(...)
* @endcode
*/
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// WP8 in VS2012 does not support nullptr in variable args lists and variadic templates are also not supported
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// VS2013 does not support nullptr in variable args lists and variadic templates are also not supported
typedef Layer* M;
static LayerMultiplex* create(M m1, std::nullptr_t listEnd) { return createVariadic(m1, NULL); }
static LayerMultiplex* create(M m1, M m2, std::nullptr_t listEnd) { return createVariadic(m1, m2, NULL); }

View File

@ -57,7 +57,7 @@ Menu* Menu::create()
return Menu::create(nullptr, nullptr);
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
Menu * Menu::variadicCreate(MenuItem* item, ...)
{
va_list args;

View File

@ -63,8 +63,8 @@ public:
*/
static Menu* create();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// WP8 in VS2012 does not support nullptr in variable args lists and variadic templates are also not supported.
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// VS2013 does not support nullptr in variable args lists and variadic templates are also not supported.
typedef MenuItem* M;
static Menu* create(M m1, std::nullptr_t listEnd) { return variadicCreate(m1, NULL); }
static Menu* create(M m1, M m2, std::nullptr_t listEnd) { return variadicCreate(m1, m2, NULL); }

View File

@ -820,7 +820,7 @@ MenuItemToggle * MenuItemToggle::createWithTarget(Ref* target, SEL_MenuHandler s
return ret;
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
MenuItemToggle * MenuItemToggle::createWithCallbackVA(const ccMenuCallback &callback, MenuItem* item, ...)
{
va_list args;

View File

@ -493,8 +493,8 @@ public:
*/
static MenuItemToggle * createWithCallback(const ccMenuCallback& callback, const Vector<MenuItem*>& menuItems);
/** Creates a menu item from a list of items with a callable object. */
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// WP8 in VS2012 does not support nullptr in variable args lists and variadic templates are also not supported.
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// VS2013 does not support nullptr in variable args lists and variadic templates are also not supported.
typedef MenuItem* M;
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, NULL); }
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, M m2, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, m2, NULL); }

View File

@ -1047,11 +1047,6 @@ public:
* @param glProgramState The GLProgramState for this node.
*/
virtual void setGLProgramState(GLProgramState *glProgramState);
/** Returns the Material used for this Node */
Material* getMaterial() const;
/** Sets the Material used for this Node */
void setMaterial(Material* material);
/// @} end of Shader Program

View File

@ -164,7 +164,7 @@ bool ParticleSystem::initWithFile(const std::string& plistFile)
{
bool ret = false;
_plistFile = FileUtils::getInstance()->fullPathForFilename(plistFile);
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(_plistFile.c_str());
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(_plistFile);
CCASSERT( !dict.empty(), "Particles: file not found");

View File

@ -130,7 +130,7 @@ emitter.startSpin = 0;
*/
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#ifdef RELATIVE
#undef RELATIVE
#endif

View File

@ -551,13 +551,6 @@ void RenderTexture::onBegin()
if(!_keepMatrix)
{
director->setProjection(director->getProjection());
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
auto modifiedProjection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
modifiedProjection = GLViewImpl::sharedOpenGLView()->getReverseOrientationMatrix() * modifiedProjection;
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION,modifiedProjection);
#endif
const Size& texSize = _texture->getContentSizeInPixels();
// Calculate the adjustment ratios based on the old and new projections
@ -569,14 +562,6 @@ void RenderTexture::onBegin()
Mat4::createOrthographicOffCenter((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1, 1, &orthoMatrix);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix);
}
else
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
auto modifiedProjection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
modifiedProjection = GLViewImpl::sharedOpenGLView()->getReverseOrientationMatrix() * modifiedProjection;
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, modifiedProjection);
#endif
}
//calculate viewport
{

View File

@ -37,6 +37,11 @@ THE SOFTWARE.
#include "physics/CCPhysicsWorld.h"
#endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
#include "physics3d/CCPhysics3DWorld.h"
#include "physics3d/CCPhysics3DComponent.h"
#endif
NS_CC_BEGIN
Scene::Scene()
@ -44,6 +49,10 @@ Scene::Scene()
: _physicsWorld(nullptr)
#endif
{
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
_physics3DWorld = nullptr;
_physics3dDebugCamera = nullptr;
#endif
_ignoreAnchorPointForPosition = true;
setAnchorPoint(Vec2(0.5f, 0.5f));
@ -61,6 +70,10 @@ Scene::~Scene()
{
#if CC_USE_PHYSICS
CC_SAFE_DELETE(_physicsWorld);
#endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
CC_SAFE_RELEASE(_physics3DWorld);
CC_SAFE_RELEASE(_physics3dDebugCamera);
#endif
Director::getInstance()->getEventDispatcher()->removeEventListener(_event);
CC_SAFE_RELEASE(_event);
@ -153,10 +166,22 @@ void Scene::render(Renderer* renderer)
//visit the scene
visit(renderer, transform, 0);
renderer->render();
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
}
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
if (_physics3DWorld && _physics3DWorld->isDebugDrawEnabled())
{
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _physics3dDebugCamera != nullptr ? _physics3dDebugCamera->getViewProjectionMatrix() : defaultCamera->getViewProjectionMatrix());
_physics3DWorld->debugDraw(renderer);
renderer->render();
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
}
#endif
Camera::_visitingCamera = nullptr;
}
@ -175,7 +200,16 @@ void Scene::removeAllChildren()
}
}
#if CC_USE_PHYSICS
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
void Scene::setPhysics3DDebugCamera(Camera* camera)
{
CC_SAFE_RETAIN(camera);
CC_SAFE_RELEASE(_physics3dDebugCamera);
_physics3dDebugCamera = camera;
}
#endif
#if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION))
void Scene::addChild(Node* child, int zOrder, int tag)
{
Node::addChild(child, zOrder, tag);
@ -212,7 +246,17 @@ bool Scene::initWithPhysics()
CC_BREAK_IF( ! (director = Director::getInstance()) );
this->setContentSize(director->getWinSize());
#if CC_USE_PHYSICS
CC_BREAK_IF(! (_physicsWorld = PhysicsWorld::construct(*this)));
#endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
Physics3DWorldDes info;
//TODO: FIX ME
//info.isDebugDrawEnabled = true;
CC_BREAK_IF(! (_physics3DWorld = Physics3DWorld::create(&info)));
_physics3DWorld->retain();
#endif
// success
ret = true;
@ -222,6 +266,7 @@ bool Scene::initWithPhysics()
void Scene::addChildToPhysicsWorld(Node* child)
{
#if CC_USE_PHYSICS
if (_physicsWorld)
{
std::function<void(Node*)> addToPhysicsWorldFunc = nullptr;
@ -242,6 +287,30 @@ void Scene::addChildToPhysicsWorld(Node* child)
addToPhysicsWorldFunc(child);
}
#endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
if (_physics3DWorld)
{
std::function<void(Node*)> addToPhysicsWorldFunc = nullptr;
addToPhysicsWorldFunc = [this, &addToPhysicsWorldFunc](Node* node) -> void
{
static std::string comName = Physics3DComponent::getPhysics3DComponentName();
auto com = static_cast<Physics3DComponent*>(node->getComponent(comName));
if (com)
{
com->addToPhysicsWorld(_physics3DWorld);
}
auto& children = node->getChildren();
for( const auto &n : children) {
addToPhysicsWorldFunc(n);
}
};
addToPhysicsWorldFunc(child);
}
#endif
}
#endif

View File

@ -41,6 +41,9 @@ class EventCustom;
#if CC_USE_PHYSICS
class PhysicsWorld;
#endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
class Physics3DWorld;
#endif
/**
* @addtogroup _2d
* @{
@ -136,15 +139,31 @@ protected:
private:
CC_DISALLOW_COPY_AND_ASSIGN(Scene);
#if CC_USE_PHYSICS
#if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION))
public:
virtual void addChild(Node* child, int zOrder, int tag) override;
virtual void addChild(Node* child, int zOrder, const std::string &name) override;
#if CC_USE_PHYSICS
/** Get the physics world of the scene.
* @return The physics world of the scene.
* @js NA
*/
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; }
#endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
/** Get the 3d physics world of the scene.
* @return The 3d physics world of the scene.
* @js NA
*/
inline Physics3DWorld* getPhysics3DWorld() { return _physics3DWorld; }
/**
* Set Physics3D debug draw camera.
*/
void setPhysics3DDebugCamera(Camera* camera);
#endif
/** Create a scene with physics.
* @return An autoreleased Scene object with physics.
@ -158,8 +177,15 @@ CC_CONSTRUCTOR_ACCESS:
protected:
void addChildToPhysicsWorld(Node* child);
#if CC_USE_PHYSICS
PhysicsWorld* _physicsWorld;
#endif // CC_USE_PHYSICS
#endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
Physics3DWorld* _physics3DWorld;
Camera* _physics3dDebugCamera; //
#endif
#endif // (CC_USE_PHYSICS || CC_USE_3D_PHYSICS)
};
// end of _2d group

View File

@ -142,11 +142,7 @@ bool TextFieldTTF::attachWithIME()
auto pGlView = Director::getInstance()->getOpenGLView();
if (pGlView)
{
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8 && CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
pGlView->setIMEKeyboardState(true);
#else
pGlView->setIMEKeyboardState(true, _inputText);
#endif
}
}
return ret;
@ -161,11 +157,7 @@ bool TextFieldTTF::detachWithIME()
auto glView = Director::getInstance()->getOpenGLView();
if (glView)
{
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8 && CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
glView->setIMEKeyboardState(false);
#else
glView->setIMEKeyboardState(false, "");
#endif
}
}
return ret;

View File

@ -7,7 +7,7 @@
<PropertyGroup />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos;$(EngineRoot)cocos\platform;$(EngineRoot)cocos\platform\desktop;$(EngineRoot)external\glfw3\include\win32;$(EngineRoot)external\win32-specific\gles\include\OGLES;$(EngineRoot)external\freetype2\include\win32\freetype2;$(EngineRoot)external\freetype2\include\win32\</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos;$(EngineRoot)cocos\platform;$(EngineRoot)cocos\platform\desktop;$(EngineRoot)external\glfw3\include\win32;$(EngineRoot)external\win32-specific\gles\include\OGLES;$(EngineRoot)external\freetype2\include\win32\freetype2;$(EngineRoot)external\freetype2\include\win32\;$(EngineRoot)external</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_VARIADIC_MAX=10;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ProjectReference>

View File

@ -20,20 +20,18 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '10.0'">v100</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '11.0'">v110</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '11.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v110_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0'">v120</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v120_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '10.0'">v100</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '11.0'">v110</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '11.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v110_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0'">v120</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v120_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v140_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@ -50,7 +48,7 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<_ProjectFileVersion>12.0.21005.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration).win32\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration).win32\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
@ -78,7 +76,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\box2d;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\edtaa3func;$(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\OpenalSoft\include;$(EngineRoot)external\win32-specific\MP3Decoder\include;$(EngineRoot)external\win32-specific\OggDecoder\include;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\xxhash;$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\curl\include\win32;$(EngineRoot)external\websockets\include\win32;$(EngineRoot)external\poly2tri\common;$(EngineRoot)external\poly2tri\sweep;$(EngineRoot)external\poly2tri;$(EngineRoot)external;$(EngineRoot)cocos;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_USRDLL;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE3DDLL;_EXPORT_DLL_;_USRSTUDIODLL;_USREXDLL;_USEGUIDLL;CC_ENABLE_CHIPMUNK_INTEGRATION=1;PROTOBUF_USE_DLLS;LIBPROTOBUF_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_USRDLL;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE3DDLL;_EXPORT_DLL_;_USRSTUDIODLL;_USREXDLL;_USEGUIDLL;CC_ENABLE_CHIPMUNK_INTEGRATION=1;CC_ENABLE_BULLET_INTEGRATION=1;PROTOBUF_USE_DLLS;LIBPROTOBUF_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
@ -119,7 +117,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\debug-lib\*.*"
<ImportLibrary>$(TargetDir)$(TargetName).lib</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
<ModuleDefinitionFile>cocos2d.def</ModuleDefinitionFile>
<AdditionalDependencies>sqlite3.lib;libcurl_imp.lib;websockets.lib;libmpg123.lib;libogg.lib;libvorbis.lib;libvorbisfile.lib;OpenAL32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>sqlite3.lib;libcurl_imp.lib;websockets.lib;libmpg123.lib;libogg.lib;libvorbis.lib;libvorbisfile.lib;OpenAL32.lib;libbullet.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>
@ -133,7 +131,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\debug-lib\*.*"
</PreBuildEvent>
<ClCompile>
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\edtaa3func;$(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\MP3Decoder\include;$(EngineRoot)external\win32-specific\OggDecoder\include;$(EngineRoot)external\win32-specific\OpenalSoft\include;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\xxhash;$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\Box2d;$(EngineRoot)external\curl\include\win32;$(EngineRoot)external\websockets\include\win32\;$(EngineRoot)external\poly2tri\common;$(EngineRoot)external\poly2tri\sweep;$(EngineRoot)external\poly2tri;$(EngineRoot)external;$(EngineRoot)cocos;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_USRDLL;NDEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE3DDLL;_EXPORT_DLL_;_USRSTUDIODLL;_USREXDLL;_USEGUIDLL;CC_ENABLE_CHIPMUNK_INTEGRATION=1;PROTOBUF_USE_DLLS;LIBPROTOBUF_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_USRDLL;NDEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE3DDLL;_EXPORT_DLL_;_USRSTUDIODLL;_USREXDLL;_USEGUIDLL;CC_ENABLE_CHIPMUNK_INTEGRATION=1;CC_ENABLE_BULLET_INTEGRATION=1;PROTOBUF_USE_DLLS;LIBPROTOBUF_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
@ -166,7 +164,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
</Command>
</PreLinkEvent>
<Link>
<AdditionalDependencies>sqlite3.lib;libcurl_imp.lib;websockets.lib;libmpg123.lib;libogg.lib;libvorbis.lib;libvorbisfile.lib;OpenAL32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>sqlite3.lib;libcurl_imp.lib;websockets.lib;libmpg123.lib;libogg.lib;libvorbis.lib;libvorbisfile.lib;OpenAL32.lib;libbullet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>LIBCMTD.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
@ -436,6 +434,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClCompile Include="..\base\CCIMEDispatcher.cpp" />
<ClCompile Include="..\base\CCNS.cpp" />
<ClCompile Include="..\base\CCProfiling.cpp" />
<ClCompile Include="..\base\CCProperties.cpp" />
<ClCompile Include="..\base\ccRandom.cpp" />
<ClCompile Include="..\base\CCRef.cpp" />
<ClCompile Include="..\base\CCScheduler.cpp" />
@ -567,6 +566,14 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClCompile Include="..\network\HttpClient.cpp" />
<ClCompile Include="..\network\SocketIO.cpp" />
<ClCompile Include="..\network\WebSocket.cpp" />
<ClCompile Include="..\physics3d\CCPhysics3D.cpp" />
<ClCompile Include="..\physics3d\CCPhysics3DComponent.cpp" />
<ClCompile Include="..\physics3d\CCPhysics3DConstraint.cpp" />
<ClCompile Include="..\physics3d\CCPhysics3DDebugDrawer.cpp" />
<ClCompile Include="..\physics3d\CCPhysics3DObject.cpp" />
<ClCompile Include="..\physics3d\CCPhysics3DShape.cpp" />
<ClCompile Include="..\physics3d\CCPhysics3DWorld.cpp" />
<ClCompile Include="..\physics3d\CCPhysicsSprite3D.cpp" />
<ClCompile Include="..\physics\CCPhysicsBody.cpp" />
<ClCompile Include="..\physics\CCPhysicsContact.cpp" />
<ClCompile Include="..\physics\CCPhysicsJoint.cpp" />
@ -606,6 +613,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClCompile Include="..\renderer\CCTextureAtlas.cpp" />
<ClCompile Include="..\renderer\CCTextureCache.cpp" />
<ClCompile Include="..\renderer\CCTrianglesCommand.cpp" />
<ClCompile Include="..\renderer\CCVertexAttribBinding.cpp" />
<ClCompile Include="..\renderer\CCVertexIndexBuffer.cpp" />
<ClCompile Include="..\renderer\CCVertexIndexData.cpp" />
<ClCompile Include="..\storage\local-storage\LocalStorage.cpp" />
@ -989,6 +997,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClInclude Include="..\base\CCMap.h" />
<ClInclude Include="..\base\CCNS.h" />
<ClInclude Include="..\base\CCProfiling.h" />
<ClInclude Include="..\base\CCProperties.h" />
<ClInclude Include="..\base\CCProtocols.h" />
<ClInclude Include="..\base\ccRandom.h" />
<ClInclude Include="..\base\CCRef.h" />
@ -1146,6 +1155,14 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClInclude Include="..\network\HttpResponse.h" />
<ClInclude Include="..\network\SocketIO.h" />
<ClInclude Include="..\network\WebSocket.h" />
<ClInclude Include="..\physics3d\CCPhysics3D.h" />
<ClInclude Include="..\physics3d\CCPhysics3DComponent.h" />
<ClInclude Include="..\physics3d\CCPhysics3DConstraint.h" />
<ClInclude Include="..\physics3d\CCPhysics3DDebugDrawer.h" />
<ClInclude Include="..\physics3d\CCPhysics3DObject.h" />
<ClInclude Include="..\physics3d\CCPhysics3DShape.h" />
<ClInclude Include="..\physics3d\CCPhysics3DWorld.h" />
<ClInclude Include="..\physics3d\CCPhysicsSprite3D.h" />
<ClInclude Include="..\physics\CCPhysicsBody.h" />
<ClInclude Include="..\physics\CCPhysicsContact.h" />
<ClInclude Include="..\physics\CCPhysicsHelper.h" />
@ -1193,6 +1210,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClInclude Include="..\renderer\CCTextureAtlas.h" />
<ClInclude Include="..\renderer\CCTextureCache.h" />
<ClInclude Include="..\renderer\CCTrianglesCommand.h" />
<ClInclude Include="..\renderer\CCVertexAttribBinding.h" />
<ClInclude Include="..\renderer\CCVertexIndexBuffer.h" />
<ClInclude Include="..\renderer\CCVertexIndexData.h" />
<ClInclude Include="..\storage\local-storage\LocalStorage.h" />
@ -1315,6 +1333,9 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ProjectReference Include="..\..\external\Box2D\proj.win32\libbox2d.vcxproj">
<Project>{929480e7-23c0-4df6-8456-096d71547116}</Project>
</ProjectReference>
<ProjectReference Include="..\..\external\bullet\proj.win32\libbullet.vcxproj">
<Project>{012dff48-a13f-4f52-b07b-f8b9d21ce95b}</Project>
</ProjectReference>
<ProjectReference Include="..\editor-support\spine\proj.win32\libSpine.vcxproj">
<Project>{b7c2a162-dec9-4418-972e-240ab3cbfcae}</Project>
</ProjectReference>

View File

@ -268,6 +268,9 @@
<Filter Include="external\poly2tri\sweep">
<UniqueIdentifier>{c37eceeb-5702-4ff7-88de-94680a22266f}</UniqueIdentifier>
</Filter>
<Filter Include="physics3d">
<UniqueIdentifier>{e492faef-2169-4117-8d73-e0c66271fe25}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\physics\CCPhysicsBody.cpp">
@ -1827,6 +1830,30 @@
<ClCompile Include="SpritePolygonCache.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\physics3d\CCPhysics3D.cpp">
<Filter>physics3d</Filter>
</ClCompile>
<ClCompile Include="..\physics3d\CCPhysics3DComponent.cpp">
<Filter>physics3d</Filter>
</ClCompile>
<ClCompile Include="..\physics3d\CCPhysics3DConstraint.cpp">
<Filter>physics3d</Filter>
</ClCompile>
<ClCompile Include="..\physics3d\CCPhysics3DDebugDrawer.cpp">
<Filter>physics3d</Filter>
</ClCompile>
<ClCompile Include="..\physics3d\CCPhysics3DObject.cpp">
<Filter>physics3d</Filter>
</ClCompile>
<ClCompile Include="..\physics3d\CCPhysics3DShape.cpp">
<Filter>physics3d</Filter>
</ClCompile>
<ClCompile Include="..\physics3d\CCPhysics3DWorld.cpp">
<Filter>physics3d</Filter>
</ClCompile>
<ClCompile Include="..\physics3d\CCPhysicsSprite3D.cpp">
<Filter>physics3d</Filter>
</ClCompile>
<ClCompile Include="..\renderer\CCPass.cpp">
<Filter>renderer</Filter>
</ClCompile>
@ -1839,6 +1866,12 @@
<ClCompile Include="..\renderer\CCMaterial.cpp">
<Filter>renderer</Filter>
</ClCompile>
<ClCompile Include="..\base\CCProperties.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\renderer\CCVertexAttribBinding.cpp">
<Filter>renderer</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\physics\CCPhysicsBody.h">
@ -3587,6 +3620,30 @@
<ClInclude Include="SpritePolygonCache.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\physics3d\CCPhysics3D.h">
<Filter>physics3d</Filter>
</ClInclude>
<ClInclude Include="..\physics3d\CCPhysics3DComponent.h">
<Filter>physics3d</Filter>
</ClInclude>
<ClInclude Include="..\physics3d\CCPhysics3DConstraint.h">
<Filter>physics3d</Filter>
</ClInclude>
<ClInclude Include="..\physics3d\CCPhysics3DDebugDrawer.h">
<Filter>physics3d</Filter>
</ClInclude>
<ClInclude Include="..\physics3d\CCPhysics3DObject.h">
<Filter>physics3d</Filter>
</ClInclude>
<ClInclude Include="..\physics3d\CCPhysics3DShape.h">
<Filter>physics3d</Filter>
</ClInclude>
<ClInclude Include="..\physics3d\CCPhysics3DWorld.h">
<Filter>physics3d</Filter>
</ClInclude>
<ClInclude Include="..\physics3d\CCPhysicsSprite3D.h">
<Filter>physics3d</Filter>
</ClInclude>
<ClInclude Include="..\renderer\CCPass.h">
<Filter>renderer</Filter>
</ClInclude>
@ -3599,6 +3656,12 @@
<ClInclude Include="..\renderer\CCMaterial.h">
<Filter>renderer</Filter>
</ClInclude>
<ClInclude Include="..\base\CCProperties.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\renderer\CCVertexAttribBinding.h">
<Filter>renderer</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\math\Mat4.inl">

View File

@ -2,7 +2,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
MinimumVisualStudioVersion = 12.0.21005.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libcocos2d_8_1", "libcocos2d_8_1", "{CA9DBD4B-603D-494E-802A-1C36E3EA3F07}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d_8_1.Shared", "libcocos2d_8_1\libcocos2d_8_1.Shared\libcocos2d_8_1.Shared.vcxitems", "{5D6F020F-7E72-4494-90A0-2DF11D235DF9}"

View File

@ -284,6 +284,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCMap.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCNS.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCProfiling.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCProperties.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCProtocols.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\base\ccRandom.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCRef.h" />
@ -504,6 +505,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCTextureAtlas.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCTextureCache.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCTrianglesCommand.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCVertexAttribBinding.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCVertexIndexBuffer.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCVertexIndexData.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\storage\local-storage\LocalStorage.h" />
@ -883,6 +885,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCIMEDispatcher.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCNS.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCProfiling.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCProperties.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\ccRandom.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCRef.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCScheduler.cpp" />
@ -1070,6 +1073,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCTextureAtlas.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCTextureCache.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCTrianglesCommand.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCVertexAttribBinding.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCVertexIndexBuffer.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCVertexIndexData.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\storage\local-storage\LocalStorage.cpp" />

View File

@ -1785,6 +1785,12 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCPass.h">
<Filter>renderer</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCProperties.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCVertexAttribBinding.h">
<Filter>renderer</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\cocos2d.cpp" />
@ -3393,6 +3399,12 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCPass.cpp">
<Filter>renderer</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCProperties.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCVertexAttribBinding.cpp">
<Filter>renderer</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="2d">

View File

@ -30,7 +30,7 @@
#include "base/CCRef.h"
#include "math/CCMath.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#undef NEAR
#endif

View File

@ -2111,6 +2111,29 @@ Reference* Bundle3D::seekToFirstType(unsigned int type, const std::string& id)
return nullptr;
}
std::vector<Vec3> Bundle3D::getTrianglesList(const std::string& path)
{
std::vector<Vec3> trianglesList;
auto bundle = Bundle3D::createBundle();
if (!bundle->load(path))
{
Bundle3D::destroyBundle(bundle);
return trianglesList;
}
MeshDatas meshs;
bundle->loadMeshDatas(meshs);
Bundle3D::destroyBundle(bundle);
for (auto iter : meshs.meshDatas){
int preVertexSize = iter->getPerVertexSize() / sizeof(float);
for (auto indexArray : iter->subMeshIndices){
for (auto i : indexArray){
trianglesList.push_back(Vec3(iter->vertex[i * preVertexSize], iter->vertex[i * preVertexSize + 1], iter->vertex[i * preVertexSize + 2]));
}
}
}
return trianglesList;
}
Bundle3D::Bundle3D()
: _modelPath(""),
_path(""),

View File

@ -85,6 +85,12 @@ public:
//since 3.3, to support reskin
virtual bool loadMaterials(MaterialDatas& materialdatas);
/**
* load triangle list
* @param path the file path to load
*/
static std::vector<Vec3> getTrianglesList(const std::string& path);
//load .obj file
static bool loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeDatas& nodedatas, const std::string& fullPath, const char* mtl_basepath = nullptr);

View File

@ -37,6 +37,7 @@
#include "renderer/CCTechnique.h"
#include "renderer/CCPass.h"
#include "renderer/CCRenderer.h"
#include "renderer/CCVertexAttribBinding.h"
#include "math/Mat4.h"
using namespace std;
@ -301,6 +302,18 @@ void Mesh::setMaterial(Material* material)
_material = material;
CC_SAFE_RETAIN(_material);
}
if (_material)
{
for (auto technique: _material->getTechniques())
{
for (auto pass: technique->getPasses())
{
auto vertexAttribBinding = VertexAttribBinding::create(_meshIndexData, pass->getGLProgramState());
pass->setVertexAttribBinding(vertexAttribBinding);
}
}
}
}
Material* Mesh::getMaterial() const
@ -340,18 +353,18 @@ void Mesh::draw(Renderer* renderer, float globalZOrder, const Mat4& transform, u
// set default uniforms for Mesh
// 'u_color' and others
const auto& scene = Director::getInstance()->getRunningScene();
const auto scene = Director::getInstance()->getRunningScene();
auto technique = _material->_currentTechnique;
for(auto& pass : technique->_passes)
for(const auto pass : technique->_passes)
{
auto programState = pass->getGLProgramState();
programState->setUniformVec4("u_color", color);
if (_skin)
programState->setUniformVec4v("u_matrixPalette", _skin->getMatrixPalette(), (GLsizei)_skin->getMatrixPaletteSize());
programState->setUniformVec4v("u_matrixPalette", (GLsizei)_skin->getMatrixPaletteSize(), _skin->getMatrixPalette());
if (scene && scene->getLights().size() > 0)
setLightUniforms(programState, scene, color, lightMask);
setLightUniforms(pass, scene, color, lightMask);
}
renderer->addCommand(&_meshCommand);
@ -458,9 +471,9 @@ void Mesh::bindMeshCommand()
}
}
void Mesh::setLightUniforms(GLProgramState* glProgramState, Scene* scene, const Vec4& color, unsigned int lightmask)
void Mesh::setLightUniforms(Pass* pass, Scene* scene, const Vec4& color, unsigned int lightmask)
{
CCASSERT(glProgramState, "Invalid glProgramstate");
CCASSERT(pass, "Invalid Pass");
CCASSERT(scene, "Invalid scene");
const auto& conf = Configuration::getInstance();
@ -469,8 +482,10 @@ void Mesh::setLightUniforms(GLProgramState* glProgramState, Scene* scene, const
int maxSpotLight = conf->getMaxSupportSpotLightInShader();
auto &lights = scene->getLights();
auto glProgramState = pass->getGLProgramState();
auto attributes = pass->getVertexAttributeBinding()->getVertexAttribsFlags();
if (glProgramState->getVertexAttribsFlags() & (1 << GLProgram::VERTEX_ATTRIB_NORMAL))
if (attributes & (1 << GLProgram::VERTEX_ATTRIB_NORMAL))
{
resetLightUniformValues();
@ -549,28 +564,28 @@ void Mesh::setLightUniforms(GLProgramState* glProgramState, Scene* scene, const
if (0 < maxDirLight)
{
glProgramState->setUniformVec3v(s_dirLightUniformColorName, &s_dirLightUniformColorValues[0], s_dirLightUniformColorValues.size());
glProgramState->setUniformVec3v(s_dirLightUniformDirName, &s_dirLightUniformDirValues[0], s_dirLightUniformDirValues.size());
glProgramState->setUniformVec3v(s_dirLightUniformColorName, s_dirLightUniformColorValues.size(), &s_dirLightUniformColorValues[0]);
glProgramState->setUniformVec3v(s_dirLightUniformDirName, s_dirLightUniformDirValues.size(), &s_dirLightUniformDirValues[0]);
}
if (0 < maxPointLight)
{
glProgramState->setUniformVec3v(s_pointLightUniformColorName, &s_pointLightUniformColorValues[0], s_pointLightUniformColorValues.size());
glProgramState->setUniformVec3v(s_pointLightUniformPositionName, &s_pointLightUniformPositionValues[0], s_pointLightUniformPositionValues.size());
glProgramState->setUniformFloatv(s_pointLightUniformRangeInverseName, &s_pointLightUniformRangeInverseValues[0], s_pointLightUniformRangeInverseValues.size());
glProgramState->setUniformVec3v(s_pointLightUniformColorName, s_pointLightUniformColorValues.size(), &s_pointLightUniformColorValues[0]);
glProgramState->setUniformVec3v(s_pointLightUniformPositionName, s_pointLightUniformPositionValues.size(), &s_pointLightUniformPositionValues[0]);
glProgramState->setUniformFloatv(s_pointLightUniformRangeInverseName, s_pointLightUniformRangeInverseValues.size(), &s_pointLightUniformRangeInverseValues[0]);
}
if (0 < maxSpotLight)
{
glProgramState->setUniformVec3v(s_spotLightUniformColorName, &s_spotLightUniformColorValues[0], s_spotLightUniformColorValues.size());
glProgramState->setUniformVec3v(s_spotLightUniformPositionName, &s_spotLightUniformPositionValues[0], s_spotLightUniformPositionValues.size());
glProgramState->setUniformVec3v(s_spotLightUniformDirName, &s_spotLightUniformDirValues[0], s_spotLightUniformDirValues.size());
glProgramState->setUniformFloatv(s_spotLightUniformInnerAngleCosName, &s_spotLightUniformInnerAngleCosValues[0], s_spotLightUniformInnerAngleCosValues.size());
glProgramState->setUniformFloatv(s_spotLightUniformOuterAngleCosName, &s_spotLightUniformOuterAngleCosValues[0], s_spotLightUniformOuterAngleCosValues.size());
glProgramState->setUniformFloatv(s_spotLightUniformRangeInverseName, &s_spotLightUniformRangeInverseValues[0], s_spotLightUniformRangeInverseValues.size());
glProgramState->setUniformVec3v(s_spotLightUniformColorName, s_spotLightUniformColorValues.size(), &s_spotLightUniformColorValues[0]);
glProgramState->setUniformVec3v(s_spotLightUniformPositionName, s_spotLightUniformPositionValues.size(), &s_spotLightUniformPositionValues[0]);
glProgramState->setUniformVec3v(s_spotLightUniformDirName, s_spotLightUniformDirValues.size(), &s_spotLightUniformDirValues[0]);
glProgramState->setUniformFloatv(s_spotLightUniformInnerAngleCosName, s_spotLightUniformInnerAngleCosValues.size(), &s_spotLightUniformInnerAngleCosValues[0]);
glProgramState->setUniformFloatv(s_spotLightUniformOuterAngleCosName, s_spotLightUniformOuterAngleCosValues.size(), &s_spotLightUniformOuterAngleCosValues[0]);
glProgramState->setUniformFloatv(s_spotLightUniformRangeInverseName, s_spotLightUniformRangeInverseValues.size(), &s_spotLightUniformRangeInverseValues[0]);
}
glProgramState->setUniformVec3(s_ambientLightUniformColorName, Vec3(ambientColor.x, ambientColor.y, ambientColor.z));
glProgramState->setUniformVec3(s_ambientLightUniformColorName, Vec3(ambientColor.x, ambientColor.y, ambientColor.z));
}
else // normal does not exist
{

View File

@ -49,6 +49,7 @@ class GLProgram;
class Material;
class Renderer;
class Scene;
class Pass;
/**
* @brief Mesh: contains ref to index buffer, GLProgramState, texture, skin, blend function, aabb and so on
@ -195,7 +196,7 @@ CC_CONSTRUCTOR_ACCESS:
virtual ~Mesh();
protected:
void setLightUniforms(GLProgramState* glProgramState, Scene* scene, const Vec4& color, unsigned int lightmask);
void setLightUniforms(Pass* pass, Scene* scene, const Vec4& color, unsigned int lightmask);
void bindMeshCommand();
Texture2D* _texture; //texture that submesh is using

View File

@ -49,7 +49,7 @@
NS_CC_BEGIN
std::string s_attributeNames[] = {GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::ATTRIBUTE_NAME_TEX_COORD1, GLProgram::ATTRIBUTE_NAME_TEX_COORD2,GLProgram::ATTRIBUTE_NAME_TEX_COORD3,GLProgram::ATTRIBUTE_NAME_NORMAL, GLProgram::ATTRIBUTE_NAME_BLEND_WEIGHT, GLProgram::ATTRIBUTE_NAME_BLEND_INDEX};
static GLProgramState* getGLProgramStateForAttribs(MeshVertexData* meshVertexData, bool usesLight);
Sprite3D* Sprite3D::create()
{
@ -64,7 +64,7 @@ Sprite3D* Sprite3D::create()
return nullptr;
}
Sprite3D* Sprite3D::create(const std::string &modelPath)
Sprite3D* Sprite3D::create(const std::string& modelPath)
{
CCASSERT(modelPath.length() >= 4, "invalid filename for Sprite3D");
@ -78,7 +78,7 @@ Sprite3D* Sprite3D::create(const std::string &modelPath)
CC_SAFE_DELETE(sprite);
return nullptr;
}
Sprite3D* Sprite3D::create(const std::string &modelPath, const std::string &texturePath)
Sprite3D* Sprite3D::create(const std::string& modelPath, const std::string& texturePath)
{
auto sprite = create(modelPath);
if (sprite)
@ -89,12 +89,12 @@ Sprite3D* Sprite3D::create(const std::string &modelPath, const std::string &text
return sprite;
}
void Sprite3D::createAsync(const std::string &modelPath, const std::function<void(Sprite3D*, void*)>& callback, void* callbackparam)
void Sprite3D::createAsync(const std::string& modelPath, const std::function<void(Sprite3D*, void*)>& callback, void* callbackparam)
{
createAsync(modelPath, "", callback, callbackparam);
}
void Sprite3D::createAsync(const std::string &modelPath, const std::string &texturePath, const std::function<void(Sprite3D*, void*)>& callback, void* callbackparam)
void Sprite3D::createAsync(const std::string& modelPath, const std::string& texturePath, const std::function<void(Sprite3D*, void*)>& callback, void* callbackparam)
{
Sprite3D *sprite = new (std::nothrow) Sprite3D();
if (sprite->loadFromCache(modelPath))
@ -249,6 +249,7 @@ Sprite3D::Sprite3D()
, _lightMask(-1)
, _shaderUsingLight(false)
, _forceDepthWrite(false)
, _usingAutogeneratedGLProgram(true)
{
}
@ -269,7 +270,7 @@ bool Sprite3D::init()
return false;
}
bool Sprite3D::initWithFile(const std::string &path)
bool Sprite3D::initWithFile(const std::string& path)
{
_meshes.clear();
_meshVertexDatas.clear();
@ -297,6 +298,7 @@ bool Sprite3D::initWithFile(const std::string &path)
Sprite3DCache::getInstance()->addSprite3DData(path, data);
CC_SAFE_DELETE(meshdatas);
_contentSize = getBoundingBox().size;
return true;
}
}
@ -364,7 +366,7 @@ Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,c
auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
if(tex)
{
Texture2D::TexParams texParams;
Texture2D::TexParams texParams;
texParams.minFilter = GL_LINEAR;
texParams.magFilter = GL_LINEAR;
texParams.wrapS = textureData->wrapS;
@ -395,7 +397,7 @@ Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,c
}
return sprite;
}
void Sprite3D::createAttachSprite3DNode(NodeData* nodedata,const MaterialDatas& materialdatas)
void Sprite3D::createAttachSprite3DNode(NodeData* nodedata, const MaterialDatas& materialdatas)
{
for(const auto& it : nodedata->modelNodeDatas)
{
@ -424,76 +426,43 @@ void Sprite3D::setMaterial(Material *material, int meshIndex)
CCASSERT(material, "Invalid Material");
CCASSERT(meshIndex == -1 || (meshIndex >=0 && meshIndex < _meshes.size()), "Invalid meshIndex");
if (meshIndex == -1)
{
for(auto& mesh: _meshes)
for (auto mesh: _meshes)
{
mesh->setMaterial(material);
}
}
else
{
_meshes.at(meshIndex)->setMaterial(material);
auto mesh = _meshes.at(meshIndex);
mesh->setMaterial(material);
}
_usingAutogeneratedGLProgram = false;
}
Material* Sprite3D::getMaterial(int meshIndex) const
{
CCASSERT(meshIndex >=0 && meshIndex < _meshes.size(), "Invalid meshIndex");
return _meshes.at(meshIndex)->getMaterial();
}
void Sprite3D::genGLProgramState(bool useLight)
{
_shaderUsingLight = useLight;
std::unordered_map<const MeshVertexData*, GLProgramState*> glProgramestates;
for(auto& meshVertexData : _meshVertexDatas)
for(auto meshVertexData : _meshVertexDatas)
{
bool textured = meshVertexData->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_TEX_COORD);
bool hasSkin = meshVertexData->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_BLEND_INDEX)
&& meshVertexData->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_BLEND_WEIGHT);
bool hasNormal = meshVertexData->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_NORMAL);
const char* shader = nullptr;
if(textured)
{
if (hasSkin)
{
if (hasNormal && _shaderUsingLight)
shader = GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE;
else
shader = GLProgram::SHADER_3D_SKINPOSITION_TEXTURE;
}
else
{
if (hasNormal && _shaderUsingLight)
shader = GLProgram::SHADER_3D_POSITION_NORMAL_TEXTURE;
else
shader = GLProgram::SHADER_3D_POSITION_TEXTURE;
}
}
else
{
shader = GLProgram::SHADER_3D_POSITION;
}
CCASSERT(shader, "Couldn't find shader for sprite");
auto glProgram = GLProgramCache::getInstance()->getGLProgram(shader);
auto glprogramstate = GLProgramState::create(glProgram);
long offset = 0;
auto attributeCount = meshVertexData->getMeshVertexAttribCount();
for (auto k = 0; k < attributeCount; k++) {
auto meshattribute = meshVertexData->getMeshVertexAttrib(k);
glprogramstate->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
meshattribute.size,
meshattribute.type,
GL_FALSE,
meshVertexData->getVertexBuffer()->getSizePerVertex(),
(GLvoid*)offset);
offset += meshattribute.attribSizeBytes;
}
auto glprogramstate = getGLProgramStateForAttribs(meshVertexData, useLight);
glProgramestates[meshVertexData] = glprogramstate;
}
for (auto& mesh : _meshes) {
for (auto& mesh: _meshes)
{
auto glProgramState = glProgramestates[mesh->getMeshIndexData()->getMeshVertexData()];
// hack to prevent cloning the very first time
@ -513,7 +482,7 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
{
if(it->bones.size() > 0 || singleSprite)
{
if(singleSprite)
if(singleSprite && root!=nullptr)
root->setName(nodedata->id);
auto mesh = Mesh::create(nodedata->id, getMeshIndexData(it->subMeshId));
if(mesh)
@ -744,9 +713,11 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
//check light and determine the shader used
const auto& scene = Director::getInstance()->getRunningScene();
if (scene)
// Don't override GLProgramState if using manually set Material
if (_usingAutogeneratedGLProgram && scene)
{
const auto& lights = scene->getLights();
const auto lights = scene->getLights();
bool usingLight = false;
for (const auto light : lights) {
usingLight = ((unsigned int)light->getLightFlag() & _lightMask) > 0;
@ -754,10 +725,12 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
break;
}
if (usingLight != _shaderUsingLight)
{
genGLProgramState(usingLight);
}
}
for (auto& mesh : _meshes)
for (auto mesh : _meshes)
{
mesh->draw(renderer,
_globalZOrder,
@ -779,8 +752,8 @@ void Sprite3D::setGLProgramState(GLProgramState *glProgramState)
}
void Sprite3D::setGLProgram(GLProgram *glprogram)
{
Node::setGLProgram(glprogram);
setGLProgramState(getGLProgramState());
auto glProgramState = GLProgramState::create(glprogram);
setGLProgramState(glProgramState);
}
void Sprite3D::setBlendFunc(const BlendFunc &blendFunc)
@ -972,4 +945,45 @@ Sprite3DCache::~Sprite3DCache()
removeAllSprite3DData();
}
//
// MARK: Helpers
//
static GLProgramState* getGLProgramStateForAttribs(MeshVertexData* meshVertexData, bool usesLight)
{
bool textured = meshVertexData->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_TEX_COORD);
bool hasSkin = meshVertexData->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_BLEND_INDEX)
&& meshVertexData->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_BLEND_WEIGHT);
bool hasNormal = meshVertexData->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_NORMAL);
const char* shader = nullptr;
if(textured)
{
if (hasSkin)
{
if (hasNormal && usesLight)
shader = GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE;
else
shader = GLProgram::SHADER_3D_SKINPOSITION_TEXTURE;
}
else
{
if (hasNormal && usesLight)
shader = GLProgram::SHADER_3D_POSITION_NORMAL_TEXTURE;
else
shader = GLProgram::SHADER_3D_POSITION_TEXTURE;
}
}
else
{
shader = GLProgram::SHADER_3D_POSITION;
}
CCASSERT(shader, "Couldn't find shader for sprite");
auto glProgram = GLProgramCache::getInstance()->getGLProgram(shader);
auto glprogramstate = GLProgramState::create(glProgram);
return glprogramstate;
}
NS_CC_END

View File

@ -189,6 +189,12 @@ public:
*/
void setMaterial(Material* material, int meshIndex);
/** Adds a new material to a particular mesh of the sprite.
meshIndex is the mesh that will be applied to.
if meshIndex == -1, then it will be applied to all the meshes that belong to the sprite.
*/
Material* getMaterial(int meshIndex) const;
CC_CONSTRUCTOR_ACCESS:
Sprite3D();
@ -246,6 +252,7 @@ protected:
unsigned int _lightMask;
bool _shaderUsingLight; // is current shader using light ?
bool _forceDepthWrite; // Always write to depth buffer
bool _usingAutogeneratedGLProgram;
struct AsyncLoadParam
{
@ -321,10 +328,6 @@ protected:
std::unordered_map<std::string, Sprite3DData*> _spriteDatas; //cached sprite datas
};
/// @cond
extern std::string CC_DLL s_attributeNames[];//attribute names array
/// @endcond
// end of 3d group
/// @}

View File

@ -262,8 +262,10 @@ bool Terrain::initHeightMap(const char * heightMap)
Terrain::Terrain()
{
_alphaMap = nullptr;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
auto _backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
_customCommand.setTransparent(false);
_customCommand.set3D(true);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
auto _backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
[this](EventCustom*)
{
reload();
@ -482,7 +484,7 @@ Terrain::~Terrain()
glDeleteBuffers(1,&(_chunkLodIndicesSkirtSet[i]._chunkIndices._indices));
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundListener);
#endif
}
@ -604,6 +606,20 @@ Terrain::QuadTree * Terrain::getQuadTree()
return _quadRoot;
}
std::vector<float> Terrain::getHeightData() const
{
std::vector<float> data;
data.resize(_imageWidth * _imageHeight);
for (int i = 0; i < _imageHeight; i++) {
for (int j = 0; j < _imageWidth; j++) {
int idx = i * _imageWidth + j;
data[idx] = (_vertices[idx]._position.y);
}
}
return data;
}
void Terrain::setAlphaMap(cocos2d::Texture2D * newAlphaMapTexture)
{
_alphaMap->release();
@ -1495,4 +1511,5 @@ Terrain::DetailMap::DetailMap()
_detailMapSrc = "";
_detailMapSize = 35;
}
NS_CC_END

View File

@ -384,6 +384,17 @@ public:
QuadTree * getQuadTree();
void reload();
/**
* get the terrain's size
*/
Size getTerrainSize() const { return Size(_imageWidth, _imageHeight); }
/**
* get the terrain's height data
*/
std::vector<float> getHeightData() const;
protected:
Terrain();
@ -458,7 +469,7 @@ protected:
GLint _alphaMapLocation;
GLint _alphaIsHasAlphaMapLocation;
GLint _detailMapSizeLocation[4];
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
EventListenerCustom* _backToForegroundListener;
#endif
};

View File

@ -132,6 +132,7 @@ base/CCEventTouch.cpp \
base/CCIMEDispatcher.cpp \
base/CCNS.cpp \
base/CCProfiling.cpp \
base/CCProperties.cpp \
base/CCRef.cpp \
base/CCScheduler.cpp \
base/CCScriptSupport.cpp \
@ -177,6 +178,7 @@ renderer/CCTexture2D.cpp \
renderer/CCTextureAtlas.cpp \
renderer/CCTextureCache.cpp \
renderer/CCTrianglesCommand.cpp \
renderer/CCVertexAttribBinding.cpp \
renderer/CCVertexIndexBuffer.cpp \
renderer/CCVertexIndexData.cpp \
renderer/ccGLStateCache.cpp \
@ -192,6 +194,14 @@ physics/CCPhysicsContact.cpp \
physics/CCPhysicsJoint.cpp \
physics/CCPhysicsShape.cpp \
physics/CCPhysicsWorld.cpp \
physics3d/CCPhysics3D.cpp \
physics3d/CCPhysics3DWorld.cpp \
physics3d/CCPhysics3DComponent.cpp \
physics3d/CCPhysics3DDebugDrawer.cpp \
physics3d/CCPhysics3DObject.cpp \
physics3d/CCPhysics3DShape.cpp \
physics3d/CCPhysicsSprite3D.cpp \
physics3d/CCPhysics3DConstraint.cpp \
../external/ConvertUTF/ConvertUTFWrapper.cpp \
../external/ConvertUTF/ConvertUTF.c \
../external/tinyxml2/tinyxml2.cpp \
@ -223,7 +233,6 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
$(LOCAL_PATH)/../external/poly2tri/sweep
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
$(LOCAL_PATH)/. \
$(LOCAL_PATH)/platform \
$(LOCAL_PATH)/../external \
$(LOCAL_PATH)/../external/tinyxml2 \
@ -273,6 +282,7 @@ LOCAL_STATIC_LIBRARIES += cocos3d_static
LOCAL_STATIC_LIBRARIES += spine_static
LOCAL_STATIC_LIBRARIES += cocos_network_static
LOCAL_STATIC_LIBRARIES += audioengine_static
LOCAL_STATIC_LIBRARIES += bullet_static
include $(BUILD_STATIC_LIBRARY)
#==============================================================
@ -293,6 +303,7 @@ $(call import-module,network)
$(call import-module,ui)
$(call import-module,extensions)
$(call import-module,Box2D)
$(call import-module,bullet)
$(call import-module,curl/prebuilt/android)
$(call import-module,websockets/prebuilt/android)
$(call import-module,flatbuffers)

View File

@ -35,6 +35,7 @@ include(2d/CMakeLists.txt)
include(3d/CMakeLists.txt)
include(platform/CMakeLists.txt)
include(physics/CMakeLists.txt)
include(physics3d/CMakeLists.txt)
include(math/CMakeLists.txt)
include(renderer/CMakeLists.txt)
include(base/CMakeLists.txt)
@ -67,6 +68,7 @@ set(COCOS_SRC cocos2d.cpp
${COCOS_3D_SRC}
${COCOS_PLATFORM_SRC}
${COCOS_PHYSICS_SRC}
${COCOS_PHYSICS3D_SRC}
${COCOS_MATH_SRC}
${COCOS_RENDERER_SRC}
${COCOS_BASE_SRC}
@ -150,6 +152,10 @@ if(USE_BOX2D)
cocos_use_pkg(cocos2d Box2D)
endif()
if(USE_BULLET)
cocos_use_pkg(cocos2d BULLET)
endif()
set_target_properties(cocos2d
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"

View File

@ -23,11 +23,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "ccdandroidUtils.h"
#include "cocos2d.h"
#include <jni.h>
#include <android/log.h>
#include "jni/JniHelper.h"
#include "platform/CCFileUtils.h"
USING_NS_CC;

View File

@ -43,7 +43,7 @@
#include "platform/win32/inet_pton_mingw.h"
#endif
#define bzero(a, b) memset(a, 0, b);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#include "inet_ntop_winrt.h"
#include "inet_pton_winrt.h"
#include "CCWinRTUtils.h"
@ -243,7 +243,7 @@ static void _log(const char *format, va_list args)
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", "%s", buf);
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_WP8
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
WCHAR wszBuf[MAX_LOG_LENGTH] = {0};
MultiByteToWideChar(CP_UTF8, 0, buf, -1, wszBuf, sizeof(wszBuf));
OutputDebugStringW(wszBuf);
@ -351,7 +351,7 @@ bool Console::listenOnTCP(int port)
hints.ai_family = AF_INET; // AF_UNSPEC: Do we need IPv6 ?
hints.ai_socktype = SOCK_STREAM;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
WSADATA wsaData;
n = WSAStartup(MAKEWORD(2, 2),&wsaData);
@ -393,7 +393,7 @@ bool Console::listenOnTCP(int port)
break; /* success */
/* bind error, close and try next one */
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
closesocket(listenfd);
#else
close(listenfd);
@ -480,7 +480,7 @@ void Console::commandExit(int fd, const std::string &args)
{
FD_CLR(fd, &_read_set);
_fds.erase(std::remove(_fds.begin(), _fds.end(), fd), _fds.end());
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
closesocket(fd);
#else
close(fd);
@ -1124,7 +1124,7 @@ void Console::loop()
//receive a SIGPIPE, which will cause linux system shutdown the sending process.
//Add this ioctl code to check if the socket has been closed by peer.
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
u_long n = 0;
ioctlsocket(fd, FIONREAD, &n);
#else
@ -1169,14 +1169,14 @@ void Console::loop()
// clean up: ignore stdin, stdout and stderr
for(const auto &fd: _fds )
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
closesocket(fd);
#else
close(fd);
#endif
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
closesocket(_listenfd);
WSACleanup();
#else

View File

@ -40,6 +40,8 @@ NS_CC_BEGIN
class CC_DLL Data
{
friend class Properties;
public:
/**
* This parameter is defined for convenient reference if a null Data object is needed.

View File

@ -70,6 +70,10 @@ THE SOFTWARE.
#include "physics/CCPhysicsWorld.h"
#endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
#include "physics3d/CCPhysics3DWorld.h"
#endif
/**
Position of the FPS
@ -293,6 +297,13 @@ void Director::drawScene()
{
physicsWorld->update(_deltaTime, false);
}
#endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
auto physics3DWorld = _runningScene->getPhysics3DWorld();
if (physics3DWorld)
{
physics3DWorld->stepSimulate(_deltaTime);
}
#endif
//clear draw stats
_renderer->clearDrawStats();
@ -606,12 +617,7 @@ void Director::setProjection(Projection projection)
case Projection::_2D:
{
loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
if(getOpenGLView() != nullptr)
{
multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, getOpenGLView()->getOrientationMatrix());
}
#endif
Mat4 orthoMatrix;
Mat4::createOrthographicOffCenter(0, size.width, 0, size.height, -1024, 1024, &orthoMatrix);
multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix);
@ -626,15 +632,7 @@ void Director::setProjection(Projection projection)
Mat4 matrixPerspective, matrixLookup;
loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
//if needed, we need to add a rotation for Landscape orientations on Windows Phone 8 since it is always in Portrait Mode
GLView* view = getOpenGLView();
if(getOpenGLView() != nullptr)
{
multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, getOpenGLView()->getOrientationMatrix());
}
#endif
// issue #1334
Mat4::createPerspective(60, (GLfloat)size.width/size.height, 10, zeye+size.height/2, &matrixPerspective);
@ -718,12 +716,6 @@ static void GLToClipTransform(Mat4 *transformOut)
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
auto projection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
//if needed, we need to undo the rotation for Landscape orientation in order to get the correct positions
projection = Director::getInstance()->getOpenGLView()->getReverseOrientationMatrix() * projection;
#endif
auto modelview = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
*transformOut = projection * modelview;
}

1334
cocos/base/CCProperties.cpp Normal file

File diff suppressed because it is too large Load Diff

616
cocos/base/CCProperties.h Normal file
View File

@ -0,0 +1,616 @@
/**
Copyright 2013 BlackBerry Inc.
Copyright (c) 2015 Chukong Technologies
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Original file from GamePlay3D: http://gameplay3d.org
This file was modified to fit the cocos2d-x project
*/
#ifndef __cocos2d_libs__CCProperties__
#define __cocos2d_libs__CCProperties__
#include <string>
#include <functional>
#include <cstdint>
#include <vector>
#include "renderer/CCTexture2D.h"
#include "platform/CCPlatformMacros.h"
#include "base/CCRef.h"
#include "base/ccTypes.h"
#include "base/CCVector.h"
NS_CC_BEGIN
class Properties;
class Vec2;
class Vec3;
class Vec4;
class Mat4;
class Data;
class Data;
/**
* Defines a properties file for loading text files.
*
* A properties file has very simple syntax and can contain only namespaces and
* name/value pairs (the properties of a namespace).
* The file can have any file extension a user specifies.
*
* Here's an example of a simple
* file that uses all the available features of the markup language:
@verbatim
// This is a comment.
// This property is in the default namespace:
integerProperty = 5
// This line defines a namespace of type "mynamespace" without an ID:
mynamespace
{
// This namespace can be retrieved by searching for its ID, "spriteTexture",
// or by its name "texture":
texture spriteTexture
{
fileName = sprite.png
width = 64
height = 64
}
// This property is in the "space" namespace:
booleanProperty = true
// It's legal to have a name without a value if you leave out the '=' character:
foo
// In fact, the '=' character is optional if you'd rather write:
bar 23
// But don't write this or you'll get an error:
// illegalProperty =
// Or this:
// = 15
// Properties objects let you retrieve values as various types.
floatProperty = 3.333
stringProperty = This is a string.
vector3Property = 1.0, 5.0, 3.55
colorProperty = 1.0, 0.4, 0.0, 1.0
}
@endverbatim
* Retrieving information out of a file like this could be done in two ways. If the
* available namespaces and name/value pairs are known in advance they can be queried by ID or name.
* For example, if the namespace "spriteTexture" and its properties are required then they can
* be retrieved with a call to getNamespace() followed by calls to getString() and getInt().
* A namespace is stored and retrieved as a Properties object.
* Reading the spriteTexture properties out of the file above in this way could be done with the following code:
@verbatim
// Create the top-level Properties object.
Properties* properties = Properties::createWithoutAutorelease("example.properties");
// Retrieve the "spriteTexture" namespace.
Properties* spriteTexture = properties->getNamespace("spriteTexture");
// Get the values of known texture properties out of the namespace.
const char* fileName = spriteTexture->getString("fileName");
int width = spriteTexture->getInt("width");
int height = spriteTexture->getInt("height");
// Deleting the top-level Properties object will clean up all nested namespaces.
SAFE_DELETE(properties);
@endverbatim
* On the other hand, if the structure of the file is not known in advance its
* namespaces and name/value pairs can be retrieved one by one using the getNextNamespace()
* and getNextProperty() methods. The following method prints the contents of any properties file
* to the console:
@verbatim
void printProperties(Properties* properties)
{
// Print the name and ID of the current namespace.
const char* spacename = properties->getNamespace();
const char* id = properties->getId();
GP_WARN("Namespace: %s ID: %s\n{", spacename, id);
// Print all properties in this namespace.
const char* name = properties->getNextProperty();
const char* value = NULL;
while (name != NULL)
{
value = properties->getString(name);
GP_WARN("%s = %s", name, value);
name = properties->getNextProperty();
}
GP_WARN("}\n");
// Print the properties of every namespace within this one.
Properties* space = properties->getNextNamespace();
while (space != NULL)
{
printProperties(space);
space = properties->getNextNamespace();
}
}
@endverbatim
* Note that this method does not keep track of the namespace hierarchy, but could be
* modified to do so. Also note that nothing in a properties file indicates the type
* of a property. If the type is unknown, its string can be retrieved and interpreted
* as necessary.
*/
class CC_DLL Properties
{
friend class Game;
public:
/**
* Data types supported by the properties class.
*/
enum Type
{
NONE,
STRING,
NUMBER,
VECTOR2,
VECTOR3,
VECTOR4,
MATRIX
};
/**
* Creates a Properties runtime settings from the specified URL, where the URL is of
* the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>"
* (and "#<namespace-id>/<namespace-id>/.../<namespace-id>" is optional).
*
* @param url The URL to create the properties from.
*
* @return The created Properties or NULL if there was an error.
* @script{create}
*/
static Properties* createWithoutAutorelease(const std::string& url);
/**
* Destructor.
*/
~Properties();
/**
* Get the name of the next property.
*
* If a valid next property is returned, the value of the property can be
* retrieved using any of the get methods in this class, passing NULL for
// the property name.
*
* @return The name of the next property, or NULL if there are no properties remaining.
*/
const char* getNextProperty();
/**
* Get the next namespace.
*/
Properties* getNextNamespace();
/**
* Rewind the getNextProperty() and getNextNamespace() iterators
* to the beginning of the file.
*/
void rewind();
/**
* Get a specific namespace by ID or name. This method will optionally
* perform a depth-first search on all namespaces and inner namespaces
* within this Property.
*
* @param id The ID or name of the namespace to find.
* @param searchNames If true, namespace names are used in the search,
* instead of namespace IDs. By default this parameter is false
* and namespace IDs are searched.
* @param recurse If true, perform a depth-first search, otherwise search
* only the immediate child namespaces.
*
* @return A properties object with the given ID or name.
*/
Properties* getNamespace(const char* id, bool searchNames = false, bool recurse = true) const;
/**
* Get the name of this Property's namespace.
*
* @return The name of this Property's namespace.
*/
const char* getNamespace() const;
/**
* Get the ID of this Property's namespace. The ID should be a unique identifier,
* but its uniqueness is not enforced.
*
* @return The ID of this Property's namespace.
*/
const char* getId() const;
/**
* Check if a property with the given name is specified in this Properties object.
*
* @param name The name of the property to query.
*
* @return True if the property exists, false otherwise.
*/
bool exists(const char* name) const;
/**
* Returns the type of a property.
*
* @param name The name of the property to interpret, or NULL to return the current property's type.
*
* @return The type of the property.
*/
Type getType(const char* name = NULL) const;
/**
* Get the value of the given property as a string. This can always be retrieved,
* whatever the intended type of the property.
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
* @param defaultValue The default value to return if the specified property does not exist.
*
* @return The value of the given property as a string, or the empty string if no property with that name exists.
*/
const char* getString(const char* name = NULL, const char* defaultValue = NULL) const;
/**
* Sets the value of the property with the specified name.
*
* If there is no property in this namespace with the current name,
* one is added. Otherwise, the value of the first property with the
* specified name is updated.
*
* If name is NULL, the value current property (see getNextProperty) is
* set, unless there is no current property, in which case false
* is returned.
*
* @param name The name of the property to set.
* @param value The property value.
*
* @return True if the property was set, false otherwise.
*/
bool setString(const char* name, const char* value);
/**
* Interpret the value of the given property as a boolean.
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
* @param defaultValue the default value to return if the specified property does not exist within the properties file.
*
* @return true if the property exists and its value is "true", otherwise false.
*/
bool getBool(const char* name = NULL, bool defaultValue = false) const;
/**
* Interpret the value of the given property as an integer.
* If the property does not exist, zero will be returned.
* If the property exists but could not be scanned, an error will be logged and zero will be returned.
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
*
* @return The value of the given property interpreted as an integer.
* Zero if the property does not exist or could not be scanned.
*/
int getInt(const char* name = NULL) const;
/**
* Interpret the value of the given property as a floating-point number.
* If the property does not exist, zero will be returned.
* If the property exists but could not be scanned, an error will be logged and zero will be returned.
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
*
* @return The value of the given property interpreted as a float.
* Zero if the property does not exist or could not be scanned.
*/
float getFloat(const char* name = NULL) const;
/**
* Interpret the value of the given property as a long integer.
* If the property does not exist, zero will be returned.
* If the property exists but could not be scanned, an error will be logged and zero will be returned.
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
*
* @return The value of the given property interpreted as a long.
* Zero if the property does not exist or could not be scanned.
*/
long getLong(const char* name = NULL) const;
/**
* Interpret the value of the given property as a Matrix.
* If the property does not exist, out will be set to the identity matrix.
* If the property exists but could not be scanned, an error will be logged and out will be set
* to the identity matrix.
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
* @param out The matrix to set to this property's interpreted value.
*
* @return True on success, false if the property does not exist or could not be scanned.
*/
bool getMat4(const char* name, Mat4* out) const;
/**
* Interpret the value of the given property as a Vector2.
* If the property does not exist, out will be set to Vector2(0.0f, 0.0f).
* If the property exists but could not be scanned, an error will be logged and out will be set
* to Vector2(0.0f, 0.0f).
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
* @param out The vector to set to this property's interpreted value.
*
* @return True on success, false if the property does not exist or could not be scanned.
*/
bool getVec2(const char* name, Vec2* out) const;
/**
* Interpret the value of the given property as a Vector3.
* If the property does not exist, out will be set to Vector3(0.0f, 0.0f, 0.0f).
* If the property exists but could not be scanned, an error will be logged and out will be set
* to Vector3(0.0f, 0.0f, 0.0f).
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
* @param out The vector to set to this property's interpreted value.
*
* @return True on success, false if the property does not exist or could not be scanned.
*/
bool getVec3(const char* name, Vec3* out) const;
/**
* Interpret the value of the given property as a Vector4.
* If the property does not exist, out will be set to Vector4(0.0f, 0.0f, 0.0f, 0.0f).
* If the property exists but could not be scanned, an error will be logged and out will be set
* to Vector4(0.0f, 0.0f, 0.0f, 0.0f).
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
* @param out The vector to set to this property's interpreted value.
*
* @return True on success, false if the property does not exist or could not be scanned.
*/
bool getVec4(const char* name, Vec4* out) const;
/**
* Interpret the value of the given property as a Quaternion specified as an axis angle.
* If the property does not exist, out will be set to Quaternion().
* If the property exists but could not be scanned, an error will be logged and out will be set
* to Quaternion().
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
* @param out The quaternion to set to this property's interpreted value.
*
* @return True on success, false if the property does not exist or could not be scanned.
*/
bool getQuaternionFromAxisAngle(const char* name, Quaternion* out) const;
/**
* Interpret the value of the given property as an RGB color in hex and write this color to a Vector3.
* E.g. 0xff0000 represents red and sets the vector to (1, 0, 0).
* If the property does not exist, out will be set to Vector3(0.0f, 0.0f, 0.0f).
* If the property exists but could not be scanned, an error will be logged and out will be set
* to Vector3(0.0f, 0.0f, 0.0f).
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
* @param out The vector to set to this property's interpreted value.
*
* @return True on success, false if the property does not exist or could not be scanned.
*/
bool getColor(const char* name, Vec3* out) const;
/**
* Interpret the value of the given property as an RGBA color in hex and write this color to a Vector4.
* E.g. 0xff0000ff represents opaque red and sets the vector to (1, 0, 0, 1).
* If the property does not exist, out will be set to Vector4(0.0f, 0.0f, 0.0f, 0.0f).
* If the property exists but could not be scanned, an error will be logged and out will be set
* to Vector4(0.0f, 0.0f, 0.0f, 0.0f).
*
* @param name The name of the property to interpret, or NULL to return the current property's value.
* @param out The vector to set to this property's interpreted value.
*
* @return True on success, false if the property does not exist or could not be scanned.
*/
bool getColor(const char* name, Vec4* out) const;
/**
* Gets the file path for the given property if the file exists.
*
* This method will first search for the file relative to the working directory.
* If the file is not found then it will search relative to the directory the bundle file is in.
*
* @param name The name of the property.
* @param path The string to copy the path to if the file exists.
*
* @return True if the property exists and the file exists, false otherwise.
*
* @script{ignore}
*/
bool getPath(const char* name, std::string* path) const;
/**
* Returns the value of a variable that is set in this Properties object.
*
* Variables take on the format ${name} and are inherited from parent Property objects.
*
* @param name Name of the variable to get.
* @param defaultValue Value to return if the variable is not found.
*
* @return The value of the specified variable, or defaultValue if not found.
*/
const char* getVariable(const char* name, const char* defaultValue = NULL) const;
/**
* Sets the value of the specified variable.
*
* @param name Name of the variable to set.
* @param value The value to set.
*/
void setVariable(const char* name, const char* value);
/**
* Attempts to parse the specified string as a Vector2 value.
*
* On error, false is returned and the output is set to all zero values.
*
* @param str The string to parse.
* @param out The value to populate if successful.
*
* @return True if a valid Vector2 was parsed, false otherwise.
*/
static bool parseVec2(const char* str, Vec2* out);
/**
* Attempts to parse the specified string as a Vector3 value.
*
* On error, false is returned and the output is set to all zero values.
*
* @param str The string to parse.
* @param out The value to populate if successful.
*
* @return True if a valid Vector3 was parsed, false otherwise.
*/
static bool parseVec3(const char* str, Vec3* out);
/**
* Attempts to parse the specified string as a Vector4 value.
*
* On error, false is returned and the output is set to all zero values.
*
* @param str The string to parse.
* @param out The value to populate if successful.
*
* @return True if a valid Vector4 was parsed, false otherwise.
*/
static bool parseVec4(const char* str, Vec4* out);
/**
* Attempts to parse the specified string as an axis-angle value.
*
* The specified string is expected to contain four comma-separated
* values, where the first three values represents the axis and the
* fourth value represents the angle, in degrees.
*
* On error, false is returned and the output is set to all zero values.
*
* @param str The string to parse.
* @param out A Quaternion populated with the orientation of the axis-angle, if successful.
*
* @return True if a valid axis-angle was parsed, false otherwise.
*/
static bool parseAxisAngle(const char* str, Quaternion* out);
/**
* Atempts to parse the specified string as an RGB color value.
*
* @param str The string to parse.
* @param out The value to populate if successful.
*
* @return True if a valid RGB color was parsed, false otherwise.
*/
static bool parseColor(const char* str, Vec3* out);
/**
* Atempts to parse the specified string as an RGBA color value.
*
* @param str The string to parse.
* @param out The value to populate if successful.
*
* @return True if a valid RGBA color was parsed, false otherwise.
*/
static bool parseColor(const char* str, Vec4* out);
private:
/**
* Internal structure containing a single property.
*/
struct Property
{
std::string name;
std::string value;
Property(const std::string& aname, const std::string& avalue) : name(aname), value(avalue) { }
};
/**
* Constructor.
*/
Properties();
/**
* Constructs the Properties class from a file.
*
* @param stream The stream used for reading the properties from file.
*/
Properties(Data* data, ssize_t* dataIdx);
Properties(const Properties& copy);
/**
* Constructor. Read from the beginning of namespace specified.
*/
Properties(Data* data, ssize_t* dataIdx, const std::string& name, const char* id, const char* parentID, Properties* parent);
// Data manipulation methods
void readProperties();
void skipWhiteSpace();
char* trimWhiteSpace(char* str);
signed char readChar();
char* readLine(char* output, int num);
bool seekFromCurrent(int offset);
bool eof();
// Called after createWithoutAutorelease(); copies info from parents into derived namespaces.
void resolveInheritance(const char* id = NULL);
// Called by resolveInheritance().
void mergeWith(Properties* overrides);
// Clones the Properties object.
Properties* clone();
void setDirectoryPath(const std::string* path);
void setDirectoryPath(const std::string& path);
/**
* Reads the next character from the Data. Returns EOF if the end of the Data is reached.
*/
// XXX: hack in order to simulate GamePlay's Stream with Cocos2d's Data
ssize_t *_dataIdx;
Data *_data;
std::string _namespace;
std::string _id;
std::string _parentID;
std::vector<Property> _properties;
std::vector<Property>::iterator _propertiesItr;
std::vector<Properties*> _namespaces;
std::vector<Properties*>::const_iterator _namespacesItr;
std::vector<Property>* _variables;
std::string* _dirPath;
Properties* _parent;
};
}
#endif // __cocos2d_libs__CCProperties__

View File

@ -8,10 +8,6 @@ endif()
# todo: also base/CCController-android.cpp
set(COCOS_BASE_SRC
base/allocator/CCAllocatorDiagnostics.cpp
base/allocator/CCAllocatorGlobal.cpp
base/allocator/CCAllocatorGlobalNewDelete.cpp
base/ccFPSImages.c
base/CCAsyncTaskPool.cpp
base/CCAutoreleasePool.cpp
base/CCConfiguration.cpp
@ -40,6 +36,7 @@ set(COCOS_BASE_SRC
base/CCIMEDispatcher.cpp
base/CCNS.cpp
base/CCProfiling.cpp
base/CCProperties.cpp
base/CCRef.cpp
base/CCScheduler.cpp
base/CCScriptSupport.cpp
@ -49,9 +46,13 @@ set(COCOS_BASE_SRC
base/ObjectFactory.cpp
base/TGAlib.cpp
base/ZipUtils.cpp
base/allocator/CCAllocatorDiagnostics.cpp
base/allocator/CCAllocatorGlobal.cpp
base/allocator/CCAllocatorGlobalNewDelete.cpp
base/atitc.cpp
base/base64.cpp
base/ccCArray.cpp
base/ccFPSImages.c
base/ccRandom.cpp
base/ccTypes.cpp
base/ccUTF8.cpp

View File

@ -34,7 +34,7 @@ THE SOFTWARE.
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "platform/android/CCFileUtils-android.h"
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// for import ssize_t on win32 platform
#include "platform/CCStdC.h"
#endif

View File

@ -28,7 +28,7 @@
#include <new>
#include <exception>
#include "base/ccMacros.h"
#include <assert.h>
USING_NS_CC_ALLOCATOR;
@ -45,7 +45,7 @@ namespace
void* operator new[] (std::size_t size)
{
void* ptr = global.allocate(size);
CCASSERT(ptr, "No memory");
assert(ptr && "No memory");
// dissabling exceptions since cocos2d-x doesn't use them
//#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID
@ -59,7 +59,7 @@ void* operator new[] (std::size_t size)
void* operator new(std::size_t size)
{
void* ptr = global.allocate(size);
CCASSERT(ptr, "No memory");
assert(ptr && "No memory");
// dissabling exceptions since cocos2d-x doesn't use them
//#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID

View File

@ -41,7 +41,7 @@
pthread_mutex_lock(&m);
#define MUTEX_UNLOCK(m) \
pthread_mutex_unlock(&m);
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#include "windows.h"
#define MUTEX HANDLE
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
@ -49,7 +49,7 @@
m = CreateMutex(0, FALSE, 0)
#define MUTEX_LOCK(m) \
WaitForSingleObject(m, INFINITE)
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#define MUTEX_INIT(m) \
m = CreateMutexEx(NULL,FALSE,0,NULL);
#define MUTEX_LOCK(m) \

View File

@ -252,6 +252,13 @@ THE SOFTWARE.
#define CC_USE_PHYSICS 1
#endif
/** Use 3d physics integration API. */
#ifndef CC_USE_3D_PHYSICS
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
#define CC_USE_3D_PHYSICS 1
#endif
#endif
/** Use culling or not. */
#ifndef CC_USE_CULLING
#define CC_USE_CULLING 1
@ -278,7 +285,7 @@ THE SOFTWARE.
/** Support webp or not. If your application don't use webp format picture, you can undefine this macro to save package size.
*/
#ifndef CC_USE_WEBP
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
#define CC_USE_WEBP 1
#endif
#endif // CC_USE_WEBP

View File

@ -74,16 +74,7 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
}
glPixelStorei(GL_PACK_ALIGNMENT, 1);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
// The frame buffer is always created with portrait orientation on WP8.
// So if the current device orientation is landscape, we need to rotate the frame buffer.
auto renderTargetSize = glView->getRenerTargetSize();
CCASSERT(width * height == static_cast<int>(renderTargetSize.width * renderTargetSize.height), "The frame size is not matched");
glReadPixels(0, 0, (int)renderTargetSize.width, (int)renderTargetSize.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
#else
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
#endif
std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); });
if (!flippedBuffer)
@ -91,32 +82,10 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
break;
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
if (width == static_cast<int>(renderTargetSize.width))
{
// The current device orientation is portrait.
for (int row = 0; row < height; ++row)
{
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
}
}
else
{
// The current device orientation is landscape.
for (int row = 0; row < width; ++row)
{
for (int col = 0; col < height; ++col)
{
*(int*)(flippedBuffer.get() + (height - col - 1) * width * 4 + row * 4) = *(int*)(buffer.get() + row * height * 4 + col * 4);
}
}
}
#else
for (int row = 0; row < height; ++row)
{
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
}
#endif
std::shared_ptr<Image> image(new Image);
if (image)

View File

@ -31,7 +31,7 @@ NS_CC_BEGIN
CC_DLL const char* cocos2dVersion()
{
return "cocos2d-x 3.6";
return "cocos2d-x 3.7-github";
}
NS_CC_END

View File

@ -29,8 +29,8 @@ THE SOFTWARE.
#define __COCOS2D_H__
// 0x00 HI ME LO
// 00 03 03 00
#define COCOS2D_VERSION 0x00030600
// 00 03 07 00
#define COCOS2D_VERSION 0x00030700
//
// all cocos2d include files
@ -38,107 +38,108 @@ THE SOFTWARE.
#include "base/ccConfig.h"
// base
#include "base/CCAsyncTaskPool.h"
#include "base/CCAutoreleasePool.h"
#include "base/CCConfiguration.h"
#include "base/CCConsole.h"
#include "base/CCData.h"
#include "base/CCDirector.h"
#include "base/CCIMEDelegate.h"
#include "base/CCIMEDispatcher.h"
#include "base/CCMap.h"
#include "base/CCNS.h"
#include "base/CCProfiling.h"
#include "base/CCProperties.h"
#include "base/CCRef.h"
#include "base/CCRefPtr.h"
#include "base/CCVector.h"
#include "base/CCMap.h"
#include "base/CCAutoreleasePool.h"
#include "base/CCNS.h"
#include "base/CCData.h"
#include "base/CCScheduler.h"
#include "base/CCUserDefault.h"
#include "base/CCValue.h"
#include "base/CCVector.h"
#include "base/ZipUtils.h"
#include "base/base64.h"
#include "base/ccConfig.h"
#include "base/ccMacros.h"
#include "base/ccTypes.h"
#include "base/CCConfiguration.h"
#include "base/CCDirector.h"
#include "base/CCScheduler.h"
#include "base/base64.h"
#include "base/ZipUtils.h"
#include "base/CCProfiling.h"
#include "base/CCConsole.h"
#include "base/ccUTF8.h"
#include "base/CCUserDefault.h"
#include "base/CCIMEDelegate.h"
#include "base/CCIMEDispatcher.h"
#include "base/ccUtils.h"
// EventDispatcher
#include "base/CCEventType.h"
#include "base/CCEventDispatcher.h"
#include "base/CCEventListenerTouch.h"
#include "base/CCEventTouch.h"
#include "base/CCEventListenerKeyboard.h"
#include "base/CCEventKeyboard.h"
#include "base/CCEventListenerMouse.h"
#include "base/CCEventMouse.h"
#include "base/CCEventAcceleration.h"
#include "base/CCEventListenerAcceleration.h"
#include "base/CCEventCustom.h"
#include "base/CCEventListenerCustom.h"
#include "base/CCEventDispatcher.h"
#include "base/CCEventFocus.h"
#include "base/CCEventKeyboard.h"
#include "base/CCEventListenerAcceleration.h"
#include "base/CCEventListenerCustom.h"
#include "base/CCEventListenerFocus.h"
#include "base/CCEventListenerKeyboard.h"
#include "base/CCEventListenerMouse.h"
#include "base/CCEventListenerTouch.h"
#include "base/CCEventMouse.h"
#include "base/CCEventTouch.h"
#include "base/CCEventType.h"
// math
#include "math/CCAffineTransform.h"
#include "math/CCGeometry.h"
#include "math/CCVertex.h"
#include "math/Mat4.h"
#include "math/MathUtil.h"
#include "math/Quaternion.h"
#include "math/Vec2.h"
#include "math/Vec3.h"
#include "math/Vec4.h"
#include "math/Mat4.h"
#include "math/Quaternion.h"
#include "math/MathUtil.h"
#include "math/CCVertex.h"
// actions
#include "2d/CCAction.h"
#include "2d/CCActionInterval.h"
#include "2d/CCActionCamera.h"
#include "2d/CCActionManager.h"
#include "2d/CCActionEase.h"
#include "2d/CCActionPageTurn3D.h"
#include "2d/CCActionGrid.h"
#include "2d/CCActionProgressTimer.h"
#include "2d/CCActionGrid3D.h"
#include "2d/CCActionTiledGrid.h"
#include "2d/CCActionInstant.h"
#include "2d/CCActionTween.h"
#include "2d/CCActionCatmullRom.h"
#include "2d/CCActionEase.h"
#include "2d/CCActionGrid.h"
#include "2d/CCActionGrid3D.h"
#include "2d/CCActionInstant.h"
#include "2d/CCActionInterval.h"
#include "2d/CCActionManager.h"
#include "2d/CCActionPageTurn3D.h"
#include "2d/CCActionProgressTimer.h"
#include "2d/CCActionTiledGrid.h"
#include "2d/CCActionTween.h"
#include "2d/CCTweenFunction.h"
// 2d nodes
#include "2d/CCNode.h"
#include "2d/CCProtectedNode.h"
#include "2d/CCAtlasNode.h"
#include "2d/CCDrawingPrimitives.h"
#include "2d/CCClippingNode.h"
#include "2d/CCClippingRectangleNode.h"
#include "2d/CCDrawNode.h"
#include "2d/CCLabelAtlas.h"
#include "2d/CCLabelTTF.h"
#include "2d/CCLabelBMFont.h"
#include "2d/CCLabel.h"
#include "2d/CCDrawingPrimitives.h"
#include "2d/CCFontFNT.h"
#include "2d/CCLabel.h"
#include "2d/CCLabelAtlas.h"
#include "2d/CCLabelBMFont.h"
#include "2d/CCLabelTTF.h"
#include "2d/CCLayer.h"
#include "2d/CCMenu.h"
#include "2d/CCMenuItem.h"
#include "2d/CCMotionStreak.h"
#include "2d/CCNode.h"
#include "2d/CCNodeGrid.h"
#include "2d/CCParticleBatchNode.h"
#include "2d/CCParticleExamples.h"
#include "2d/CCParticleSystem.h"
#include "2d/CCParticleSystemQuad.h"
#include "2d/CCProgressTimer.h"
#include "2d/CCProtectedNode.h"
#include "2d/CCRenderTexture.h"
#include "2d/CCScene.h"
#include "2d/CCTransition.h"
#include "2d/CCTransitionPageTurn.h"
#include "2d/CCTransitionProgress.h"
#include "2d/CCMenu.h"
#include "2d/CCMenuItem.h"
#include "2d/CCClippingNode.h"
#include "2d/CCClippingRectangleNode.h"
#include "2d/CCMotionStreak.h"
#include "2d/CCProgressTimer.h"
#include "2d/CCRenderTexture.h"
#include "2d/CCNodeGrid.h"
#include "2d/CCParticleBatchNode.h"
#include "2d/CCParticleSystem.h"
#include "2d/CCParticleExamples.h"
#include "2d/CCParticleSystemQuad.h"
// 2d utils
#include "2d/CCCamera.h"
#include "2d/CCGrabber.h"
#include "2d/CCGrid.h"
#include "2d/CCCamera.h"
#include "2d/CCLight.h"
// include
@ -146,40 +147,45 @@ THE SOFTWARE.
// renderer
#include "renderer/CCCustomCommand.h"
#include "renderer/CCGroupCommand.h"
#include "renderer/CCQuadCommand.h"
#include "renderer/CCRenderCommand.h"
#include "renderer/CCRenderCommandPool.h"
#include "renderer/CCRenderer.h"
#include "renderer/CCGLProgram.h"
#include "renderer/CCGLProgramCache.h"
#include "renderer/CCGLProgramState.h"
#include "renderer/ccGLStateCache.h"
#include "renderer/ccShaders.h"
#include "renderer/CCTexture2D.h"
#include "renderer/CCTextureCache.h"
#include "renderer/CCVertexIndexBuffer.h"
#include "renderer/CCVertexIndexData.h"
#include "renderer/CCGroupCommand.h"
#include "renderer/CCMaterial.h"
#include "renderer/CCPass.h"
#include "renderer/CCPrimitive.h"
#include "renderer/CCPrimitiveCommand.h"
#include "renderer/CCQuadCommand.h"
#include "renderer/CCRenderCommand.h"
#include "renderer/CCRenderCommandPool.h"
#include "renderer/CCRenderState.h"
#include "renderer/CCRenderer.h"
#include "renderer/CCTechnique.h"
#include "renderer/CCTexture2D.h"
#include "renderer/CCTextureCache.h"
#include "renderer/CCTrianglesCommand.h"
#include "renderer/CCVertexAttribBinding.h"
#include "renderer/CCVertexIndexBuffer.h"
#include "renderer/CCVertexIndexData.h"
#include "renderer/ccGLStateCache.h"
#include "renderer/ccShaders.h"
// physics
#include "physics/CCPhysicsBody.h"
#include "physics/CCPhysicsContact.h"
#include "physics/CCPhysicsShape.h"
#include "physics/CCPhysicsJoint.h"
#include "physics/CCPhysicsShape.h"
#include "physics/CCPhysicsWorld.h"
// platform
#include "platform/CCDevice.h"
#include "platform/CCCommon.h"
#include "platform/CCDevice.h"
#include "platform/CCFileUtils.h"
#include "platform/CCImage.h"
#include "platform/CCSAXParser.h"
#include "platform/CCThread.h"
#include "platform/CCPlatformConfig.h"
#include "platform/CCPlatformMacros.h"
#include "platform/CCSAXParser.h"
#include "platform/CCThread.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#include "platform/ios/CCApplication-ios.h"
@ -230,14 +236,6 @@ THE SOFTWARE.
#include "platform/winrt/CCStdC.h"
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
#include "platform/winrt/CCApplication.h"
#include "platform/wp8/CCGLViewImpl-wp8.h"
#include "platform/winrt/CCGL.h"
#include "platform/winrt/CCStdC.h"
#include "platform/winrt/CCPrecompiledShaders.h"
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WP8
// script_support
#include "base/CCScriptSupport.h"
@ -262,8 +260,8 @@ THE SOFTWARE.
#include "2d/CCTMXTiledMap.h"
#include "2d/CCTMXXMLParser.h"
#include "2d/CCTileMapAtlas.h"
#include "2d/CCFastTMXTiledMap.h"
#include "2d/CCFastTMXLayer.h"
#include "2d/CCFastTMXTiledMap.h"
// component
#include "2d/CCComponent.h"
@ -271,34 +269,34 @@ THE SOFTWARE.
//3d
#include "3d/CCAABB.h"
#include "3d/CCOBB.h"
#include "3d/CCRay.h"
#include "3d/CCSprite3D.h"
#include "3d/CCMesh.h"
#include "3d/CCMeshSkin.h"
#include "3d/CCAnimate3D.h"
#include "3d/CCAnimation3D.h"
#include "3d/CCSprite3DMaterial.h"
#include "3d/CCAttachNode.h"
#include "3d/CCMeshVertexIndexData.h"
#include "3d/CCSkeleton3D.h"
#include "3d/CCBillBoard.h"
#include "3d/CCFrustum.h"
#include "3d/CCMesh.h"
#include "3d/CCMeshSkin.h"
#include "3d/CCMeshVertexIndexData.h"
#include "3d/CCOBB.h"
#include "3d/CCPlane.h"
#include "3d/CCTextureCube.h"
#include "3d/CCRay.h"
#include "3d/CCSkeleton3D.h"
#include "3d/CCSkybox.h"
#include "3d/CCSprite3D.h"
#include "3d/CCSprite3DMaterial.h"
#include "3d/CCTerrain.h"
#include "3d/CCTextureCube.h"
// Deprecated include
#include "deprecated/CCDictionary.h"
#include "deprecated/CCArray.h"
#include "deprecated/CCSet.h"
#include "deprecated/CCInteger.h"
#include "deprecated/CCFloat.h"
#include "deprecated/CCDouble.h"
#include "deprecated/CCBool.h"
#include "deprecated/CCString.h"
#include "deprecated/CCDictionary.h"
#include "deprecated/CCDouble.h"
#include "deprecated/CCFloat.h"
#include "deprecated/CCInteger.h"
#include "deprecated/CCNotificationCenter.h"
#include "deprecated/CCSet.h"
#include "deprecated/CCString.h"
// CCDeprecated.h must be included at the end
#include "deprecated/CCDeprecated.h"

View File

@ -131,11 +131,6 @@ public:
MULTIPLY_RESOLUTION,
};
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
#ifdef ABSOLUTE
#undef ABSOLUTE
#endif
#endif
enum class SizeType
{
ABSOLUTE,

View File

@ -282,7 +282,7 @@ void SkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
void SkewFrame::onApply(float percent)
{
if ((nullptr != _node && _betweenSkewX != 0) || _betweenSkewY != 0)
if ((nullptr != _node) && (_betweenSkewX != 0 || _betweenSkewY != 0))
{
float skewx = _skewX + percent * _betweenSkewX;
float skewy = _skewY + percent * _betweenSkewY;
@ -342,7 +342,7 @@ void RotationSkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
void RotationSkewFrame::onApply(float percent)
{
if ((nullptr != _node && _betweenSkewX != 0) || _betweenSkewY != 0)
if ((nullptr != _node) && (_betweenSkewX != 0 || _betweenSkewY != 0))
{
float skewx = _skewX + percent * _betweenSkewX;
float skewy = _skewY + percent * _betweenSkewY;
@ -400,7 +400,7 @@ void PositionFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
void PositionFrame::onApply(float percent)
{
if (nullptr != _node && (_betweenX != 0 || _betweenY != 0))
if ((nullptr != _node) && (_betweenX != 0 || _betweenY != 0))
{
Point p;
p.x = _position.x + _betweenX * percent;
@ -460,7 +460,7 @@ void ScaleFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
void ScaleFrame::onApply(float percent)
{
if ((nullptr != _node && _betweenScaleX != 0) || _betweenScaleY != 0)
if ((nullptr != _node) && (_betweenScaleX != 0 || _betweenScaleY != 0))
{
float scaleX = _scaleX + _betweenScaleX * percent;
float scaleY = _scaleY + _betweenScaleY * percent;
@ -682,7 +682,7 @@ void ColorFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
void ColorFrame::onApply(float percent)
{
if ((nullptr != _node && _betweenRed != 0) || _betweenGreen != 0 || _betweenBlue != 0)
if ((nullptr != _node) && (_betweenRed != 0 || _betweenGreen != 0 || _betweenBlue != 0))
{
Color3B color;
color.r = _color.r+ _betweenRed * percent;

View File

@ -128,7 +128,7 @@ bool ComAudio::serialize(void* r)
}
if (strcmp(className, "CCBackgroundAudio") == 0)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
std::string::size_type pos = filePath.find(".mp3");
if (pos == filePath.npos)
{

10
cocos/editor-support/spine/proj.win32/libSpine.vcxproj Executable file → Normal file
View File

@ -83,21 +83,19 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '10.0'">v100</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '11.0'">v110</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '11.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v110_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0'">v120</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v120_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v140_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '10.0'">v100</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '11.0'">v110</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '11.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v110_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0'">v120</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v120_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>

View File

@ -55,7 +55,7 @@ typedef void (cocos2d::Ref::*SEL_HttpResponse)(HttpClient* client, HttpResponse*
* @lua NA
*/
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#ifdef DELETE
#undef DELETE
#endif

View File

@ -28,12 +28,13 @@
****************************************************************************/
#include "SocketIO.h"
#include <algorithm>
#include <sstream>
#include <iterator>
#include "base/CCDirector.h"
#include "base/CCScheduler.h"
#include "WebSocket.h"
#include "HttpClient.h"
#include <algorithm>
#include <sstream>
NS_CC_BEGIN

View File

@ -0,0 +1,98 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 "CCPhysics3D.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
NS_CC_BEGIN
CC_DLL const char* physics3dVersion()
{
#if CC_ENABLE_BULLET_INTEGRATION
return "bullet2.82";
#endif
}
NS_CC_END
cocos2d::Vec3 convertbtVector3ToVec3( const btVector3 &btVec3 )
{
return cocos2d::Vec3(btVec3.x(), btVec3.y(), btVec3.z());
}
btVector3 convertVec3TobtVector3( const cocos2d::Vec3 &vec3 )
{
return btVector3(vec3.x, vec3.y, vec3.z);
}
cocos2d::Mat4 convertbtTransformToMat4( const btTransform &btTrans )
{
cocos2d::Mat4 mat;
auto rot = btTrans.getBasis();
auto row = rot.getRow(0);
mat.m[0] = row.getX();
mat.m[4] = row.getY();
mat.m[8] = row.getZ();
row = rot.getRow(1);
mat.m[1] = row.getX();
mat.m[5] = row.getY();
mat.m[9] = row.getZ();
row = rot.getRow(2);
mat.m[2] = row.getX();
mat.m[6] = row.getY();
mat.m[10] = row.getZ();
row = btTrans.getOrigin();
mat.m[12] = row.getX();
mat.m[13] = row.getY();
mat.m[14] = row.getZ();
return mat;
}
btTransform convertMat4TobtTransform( const cocos2d::Mat4 &mat4 )
{
btTransform btTrans;
btTrans.setFromOpenGLMatrix(mat4.m);
return btTrans;
}
cocos2d::Quaternion convertbtQuatToQuat( const btQuaternion &btQuat )
{
return cocos2d::Quaternion(btQuat.x(), btQuat.y(), btQuat.z(), btQuat.w());
}
btQuaternion convertQuatTobtQuat( const cocos2d::Quaternion &quat )
{
return btQuaternion(quat.x, quat.y, quat.z, quat.w);
}
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif //CC_USE_3D_PHYSICS

View File

@ -0,0 +1,69 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 __PHYSICS_3D_H__
#define __PHYSICS_3D_H__
#include "base/ccConfig.h"
#include "math/CCMath.h"
#if CC_USE_3D_PHYSICS
#include "CCPhysics3DShape.h"
#include "CCPhysicsSprite3D.h"
#include "CCPhysics3DWorld.h"
#include "CCPhysics3DDebugDrawer.h"
#include "CCPhysics3DObject.h"
#include "CCPhysics3DComponent.h"
#include "CCPhysics3DConstraint.h"
NS_CC_BEGIN
CC_DLL const char* physics3dVersion();
NS_CC_END
#if (CC_ENABLE_BULLET_INTEGRATION)
//include bullet header files
#include "bullet/LinearMath/btTransform.h"
#include "bullet/LinearMath/btVector3.h"
#include "bullet/LinearMath/btQuaternion.h"
#include "bullet/btBulletCollisionCommon.h"
#include "bullet/btBulletDynamicsCommon.h"
//convert between cocos and bullet
cocos2d::Vec3 convertbtVector3ToVec3(const btVector3 &btVec3);
btVector3 convertVec3TobtVector3(const cocos2d::Vec3 &vec3);
cocos2d::Mat4 convertbtTransformToMat4(const btTransform &btTrans);
btTransform convertMat4TobtTransform(const cocos2d::Mat4 &mat4);
cocos2d::Quaternion convertbtQuatToQuat(const btQuaternion &btQuat);
btQuaternion convertQuatTobtQuat(const cocos2d::Quaternion &quat);
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif //CC_USE_3D_PHYSICS
#endif // __PHYSICS_3D_H__

View File

@ -0,0 +1,244 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 "CCPhysics3D.h"
#include "2d/CCNode.h"
#include "2d/CCScene.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
NS_CC_BEGIN
Physics3DComponent::~Physics3DComponent()
{
CC_SAFE_RELEASE(_physics3DObj);
}
std::string& Physics3DComponent::getPhysics3DComponentName()
{
static std::string comName = "___Physics3DComponent___";
return comName;
}
bool Physics3DComponent::init()
{
setName(getPhysics3DComponentName());
return Component::init();
}
Physics3DComponent* Physics3DComponent::create(Physics3DObject* physicsObj, const cocos2d::Vec3& translateInPhysics, const cocos2d::Quaternion& rotInPhsyics)
{
auto ret = new (std::nothrow) Physics3DComponent();
if (ret && ret->init())
{
ret->setPhysics3DObject(physicsObj);
ret->setTransformInPhysics(translateInPhysics, rotInPhsyics);
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
void Physics3DComponent::setPhysics3DObject(Physics3DObject* physicsObj)
{
CC_SAFE_RETAIN(physicsObj);
CC_SAFE_RELEASE(_physics3DObj);
_physics3DObj = physicsObj;
}
Physics3DComponent::Physics3DComponent()
: _physics3DObj(nullptr)
, _syncFlag(Physics3DComponent::PhysicsSyncFlag::NODE_AND_NODE)
{
}
void Physics3DComponent::setEnabled(bool b)
{
bool oldBool = b;
Component::setEnabled(b);
if (_physics3DObj && oldBool != _enabled)
{
_enabled ? _physics3DObj->getPhysicsWorld()->addPhysics3DObject(_physics3DObj) : _physics3DObj->getPhysicsWorld()->removePhysics3DObject(_physics3DObj);
}
}
void Physics3DComponent::addToPhysicsWorld(Physics3DWorld* world)
{
//add component to physics world
if (_physics3DObj)
{
_physics3DObj->setPhysicsWorld(world);
world->addPhysics3DObject(_physics3DObj);
auto& components = world->_physicsComponents;
auto it = std::find(components.begin(), components.end(), this);
if (it == components.end())
{
auto parent = _owner->getParent();
while (parent) {
for (int i = 0; i < components.size(); i++) {
if (parent == components[i]->getOwner())
{
//insert it here
components.insert(components.begin() + i, this);
return;
}
}
parent = parent->getParent();
}
components.insert(components.begin(), this);
}
}
}
void Physics3DComponent::onEnter()
{
Component::onEnter();
if (_physics3DObj->getPhysicsWorld() == nullptr && _owner)
{
auto scene = _owner->getScene();
if (scene)
addToPhysicsWorld(scene->getPhysics3DWorld());
}
}
void Physics3DComponent::onExit()
{
Component::onExit();
setEnabled(false);
//remove component from physics world
if (_physics3DObj)
{
auto& components = _physics3DObj->getPhysicsWorld()->_physicsComponents;
auto it = std::find(components.begin(), components.end(), this);
if (it != components.end())
components.erase(it);
}
}
void Physics3DComponent::preSimulate()
{
if (((int)_syncFlag & (int)Physics3DComponent::PhysicsSyncFlag::NODE_TO_PHYSICS) && _physics3DObj && _owner)
{
syncToNode();
}
}
void Physics3DComponent::postSimulate()
{
if (((int)_syncFlag & (int)Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE) && _physics3DObj && _owner)
{
syncToPhysics();
}
}
void Physics3DComponent::setTransformInPhysics(const cocos2d::Vec3& translateInPhysics, const cocos2d::Quaternion& rotInPhsyics)
{
Mat4::createRotation(rotInPhsyics, &_transformInPhysics);
_transformInPhysics.m[12] = translateInPhysics.x;
_transformInPhysics.m[13] = translateInPhysics.y;
_transformInPhysics.m[14] = translateInPhysics.z;
_invTransformInPhysics = _transformInPhysics.getInversed();
}
void Physics3DComponent::setSyncFlag(PhysicsSyncFlag syncFlag)
{
_syncFlag = syncFlag;
}
void Physics3DComponent::syncToPhysics()
{
if (_physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
{
Mat4 parentMat;
if (_owner->getParent())
parentMat = _owner->getParent()->getNodeToWorldTransform();
auto mat = parentMat.getInversed() * _physics3DObj->getWorldTransform();
//remove scale, no scale support for physics
float oneOverLen = 1.f / sqrtf(mat.m[0] * mat.m[0] + mat.m[1] * mat.m[1] + mat.m[2] * mat.m[2]);
mat.m[0] *= oneOverLen;
mat.m[1] *= oneOverLen;
mat.m[2] *= oneOverLen;
oneOverLen = 1.f / sqrtf(mat.m[4] * mat.m[4] + mat.m[5] * mat.m[5] + mat.m[6] * mat.m[6]);
mat.m[4] *= oneOverLen;
mat.m[5] *= oneOverLen;
mat.m[6] *= oneOverLen;
oneOverLen = 1.f / sqrtf(mat.m[8] * mat.m[8] + mat.m[9] * mat.m[9] + mat.m[10] * mat.m[10]);
mat.m[8] *= oneOverLen;
mat.m[9] *= oneOverLen;
mat.m[10] *= oneOverLen;
mat *= _transformInPhysics;
static Vec3 scale, translation;
static Quaternion quat;
mat.decompose(&scale, &quat, &translation);
_owner->setPosition3D(translation);
quat.normalize();
_owner->setRotationQuat(quat);
}
}
void Physics3DComponent::syncToNode()
{
if (_physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
{
auto mat = _owner->getNodeToWorldTransform();
//remove scale, no scale support for physics
float oneOverLen = 1.f / sqrtf(mat.m[0] * mat.m[0] + mat.m[1] * mat.m[1] + mat.m[2] * mat.m[2]);
mat.m[0] *= oneOverLen;
mat.m[1] *= oneOverLen;
mat.m[2] *= oneOverLen;
oneOverLen = 1.f / sqrtf(mat.m[4] * mat.m[4] + mat.m[5] * mat.m[5] + mat.m[6] * mat.m[6]);
mat.m[4] *= oneOverLen;
mat.m[5] *= oneOverLen;
mat.m[6] *= oneOverLen;
oneOverLen = 1.f / sqrtf(mat.m[8] * mat.m[8] + mat.m[9] * mat.m[9] + mat.m[10] * mat.m[10]);
mat.m[8] *= oneOverLen;
mat.m[9] *= oneOverLen;
mat.m[10] *= oneOverLen;
mat *= _invTransformInPhysics;
if (_physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
{
auto body = static_cast<Physics3DRigidBody*>(_physics3DObj)->getRigidBody();
auto motionState = body->getMotionState();
motionState->setWorldTransform(convertMat4TobtTransform(mat));
body->setMotionState(motionState);
}
}
}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif //CC_USE_3D_PHYSICS

View File

@ -0,0 +1,145 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 __PHYSICS_3D_COMPONENT_H__
#define __PHYSICS_3D_COMPONENT_H__
#include "base/ccConfig.h"
#include "math/CCMath.h"
#include "2d/CCComponent.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
NS_CC_BEGIN
/**
* @addtogroup _3d
* @{
*/
class Physics3DObject;
class Physics3DWorld;
/** @brief Physics3DComponent: A component with 3D physics, you can add a rigid body to it, and then add this component to a node, the node will move and rotate with this rigid body */
class CC_DLL Physics3DComponent : public cocos2d::Component
{
friend class Physics3DWorld;
public:
enum class PhysicsSyncFlag
{
NONE = 0,
NODE_TO_PHYSICS = 1, //align node transform to the physics
PHYSICS_TO_NODE = 2, // align physics transform to the node
NODE_AND_NODE = NODE_TO_PHYSICS | PHYSICS_TO_NODE, //pre simulation, align the physics object to the node and align the node transform according to physics object after simulation
};
CREATE_FUNC(Physics3DComponent);
virtual ~Physics3DComponent();
virtual bool init() override;
/**
* create Physics3DComponent
* @param physicsObj pointer to a Physics object contain in the component
* @param translateInPhysics offset that the owner node in the physics object's space
* @param rotInPhsyics offset rotation that the owner node in the physics object's space
* @return created Physics3DComponent
*/
static Physics3DComponent* create(Physics3DObject* physicsObj, const cocos2d::Vec3& translateInPhysics = cocos2d::Vec3::ZERO, const cocos2d::Quaternion& rotInPhsyics = cocos2d::Quaternion::ZERO);
/**
* set Physics object to the component
*/
void setPhysics3DObject(Physics3DObject* physicsObj);
/**
* get physics object
*/
Physics3DObject* getPhysics3DObject() const { return _physics3DObj; }
/**
* get the component name, it is used to find whether it is Physics3DComponent
*/
static std::string& getPhysics3DComponentName();
/**
* set it enable or not
*/
virtual void setEnabled(bool b) override;
virtual void onEnter() override;
virtual void onExit() override;
/**
* add this component to physics world, called by scene
*/
void addToPhysicsWorld(Physics3DWorld* world);
/**
* The node's transform in physics object space
*/
void setTransformInPhysics(const cocos2d::Vec3& translateInPhysics, const cocos2d::Quaternion& rotInPhsyics);
/**
* synchronization between node and physics is time consuming, you can skip some synchronization using this function
*/
void setSyncFlag(PhysicsSyncFlag syncFlag);
/**
* align node and physics according to physics object
*/
void syncToPhysics();
/**
* align node and physics according to node
*/
void syncToNode();
CC_CONSTRUCTOR_ACCESS:
Physics3DComponent();
protected:
void preSimulate();
void postSimulate();
cocos2d::Mat4 _transformInPhysics; //transform in physics space
cocos2d::Mat4 _invTransformInPhysics;
Physics3DObject* _physics3DObj;
PhysicsSyncFlag _syncFlag;
};
// end of 3d group
/// @}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif //CC_USE_3D_PHYSICS
#endif // __PHYSICS_3D_COMPONENT_H__

View File

@ -0,0 +1,840 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 "CCPhysics3D.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
NS_CC_BEGIN
Physics3DConstraint::Physics3DConstraint()
: _bodyA(nullptr)
, _bodyB(nullptr)
, _constraint(nullptr)
, _type(Physics3DConstraint::ConstraintType::UNKNOWN)
, _userData(nullptr)
{
}
Physics3DConstraint::~Physics3DConstraint()
{
CC_SAFE_RELEASE(_bodyA);
CC_SAFE_RELEASE(_bodyB);
CC_SAFE_DELETE(_constraint);
}
float Physics3DConstraint::getBreakingImpulse() const
{
return _constraint->getBreakingImpulseThreshold();
}
void Physics3DConstraint::setBreakingImpulse(float impulse)
{
_constraint->setBreakingImpulseThreshold(impulse);
}
bool Physics3DConstraint::isEnabled() const
{
return _constraint->isEnabled();
}
void Physics3DConstraint::setEnabled(bool enabled)
{
return _constraint->setEnabled(enabled);
}
int Physics3DConstraint::getOverrideNumSolverIterations() const
{
return _constraint->getOverrideNumSolverIterations();
}
///override the number of constraint solver iterations used to solve this constraint
///-1 will use the default number of iterations, as specified in SolverInfo.m_numIterations
void Physics3DConstraint::setOverrideNumSolverIterations(int overideNumIterations)
{
_constraint->setOverrideNumSolverIterations(overideNumIterations);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Physics3DPointToPointConstraint* Physics3DPointToPointConstraint::create(Physics3DRigidBody* rbA, const cocos2d::Vec3& pivotPointInA)
{
auto ret = new (std::nothrow) Physics3DPointToPointConstraint();
if (ret && ret->init(rbA, pivotPointInA))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return ret;
}
Physics3DPointToPointConstraint* Physics3DPointToPointConstraint::create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Vec3& pivotPointInA, const cocos2d::Vec3& pivotPointInB)
{
auto ret = new (std::nothrow) Physics3DPointToPointConstraint();
if (ret && ret->init(rbA, rbB, pivotPointInA, pivotPointInB))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return ret;
}
bool Physics3DPointToPointConstraint::init(Physics3DRigidBody* rbA, const cocos2d::Vec3& pivotPointInA)
{
_constraint = new btPoint2PointConstraint(*rbA->getRigidBody(), convertVec3TobtVector3(pivotPointInA));
_bodyA = rbA;
_bodyA->retain();
return true;
}
bool Physics3DPointToPointConstraint::init(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Vec3& pivotPointInA, const cocos2d::Vec3& pivotPointInB)
{
_constraint = new btPoint2PointConstraint(*rbA->getRigidBody(), *rbB->getRigidBody(), convertVec3TobtVector3(pivotPointInA), convertVec3TobtVector3(pivotPointInB));
_bodyA = rbA;
_bodyB = rbB;
_bodyA->retain();
_bodyB->retain();
return true;
}
void Physics3DPointToPointConstraint::setPivotPointInA(const cocos2d::Vec3& pivotA)
{
auto point = convertVec3TobtVector3(pivotA);
static_cast<btPoint2PointConstraint*>(_constraint)->setPivotA(point);
}
void Physics3DPointToPointConstraint::setPivotPointInB(const cocos2d::Vec3& pivotB)
{
auto point = convertVec3TobtVector3(pivotB);
static_cast<btPoint2PointConstraint*>(_constraint)->setPivotB(point);
}
cocos2d::Vec3 Physics3DPointToPointConstraint::getPivotPointInA() const
{
const auto& point = static_cast<btPoint2PointConstraint*>(_constraint)->getPivotInA();
return convertbtVector3ToVec3(point);
}
cocos2d::Vec3 Physics3DPointToPointConstraint::getPivotPointInB() const
{
const auto& point = static_cast<btPoint2PointConstraint*>(_constraint)->getPivotInB();
return convertbtVector3ToVec3(point);
}
Physics3DPointToPointConstraint::Physics3DPointToPointConstraint()
{
_type = Physics3DConstraint::ConstraintType::POINT_TO_POINT;
}
Physics3DPointToPointConstraint::~Physics3DPointToPointConstraint()
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Physics3DHingeConstraint* Physics3DHingeConstraint::create(Physics3DRigidBody* rbA, const cocos2d::Mat4& rbAFrame, bool useReferenceFrameA)
{
auto ret = new (std::nothrow) Physics3DHingeConstraint();
ret->_constraint = new btHingeConstraint(*rbA->getRigidBody(), convertMat4TobtTransform(rbAFrame), useReferenceFrameA);
ret->_bodyA = rbA;
rbA->retain();
ret->autorelease();
return ret;
}
Physics3DHingeConstraint* Physics3DHingeConstraint::create(Physics3DRigidBody* rbA, const cocos2d::Vec3& pivotInA, const cocos2d::Vec3& axisInA, bool useReferenceFrameA)
{
auto ret = new (std::nothrow) Physics3DHingeConstraint();
ret->_constraint = new btHingeConstraint(*rbA->getRigidBody(), convertVec3TobtVector3(pivotInA), convertVec3TobtVector3(axisInA), useReferenceFrameA);
ret->_bodyA = rbA;
rbA->retain();
ret->autorelease();
return ret;
}
Physics3DHingeConstraint* Physics3DHingeConstraint::create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Vec3& pivotInA,const cocos2d::Vec3& pivotInB, cocos2d::Vec3& axisInA, cocos2d::Vec3& axisInB, bool useReferenceFrameA)
{
auto ret = new (std::nothrow) Physics3DHingeConstraint();
ret->_constraint = new btHingeConstraint(*rbA->getRigidBody(), *rbB->getRigidBody(), convertVec3TobtVector3(pivotInA), convertVec3TobtVector3(pivotInB), convertVec3TobtVector3(axisInA), convertVec3TobtVector3(axisInB), useReferenceFrameA);
ret->_bodyA = rbA;
rbA->retain();
ret->_bodyB = rbB;
rbB->retain();
ret->autorelease();
return ret;
}
Physics3DHingeConstraint* Physics3DHingeConstraint::create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& rbAFrame, const cocos2d::Mat4& rbBFrame, bool useReferenceFrameA)
{
auto ret = new (std::nothrow) Physics3DHingeConstraint();
ret->_constraint = new btHingeConstraint(*rbA->getRigidBody(), *rbB->getRigidBody(), convertMat4TobtTransform(rbAFrame), convertMat4TobtTransform(rbBFrame), useReferenceFrameA);
ret->_bodyA = rbA;
rbA->retain();
ret->_bodyB = rbB;
rbB->retain();
ret->autorelease();
return ret;
}
cocos2d::Mat4 Physics3DHingeConstraint::getFrameOffsetA() const
{
const auto& transform = static_cast<btHingeConstraint*>(_constraint)->getFrameOffsetA();
return convertbtTransformToMat4(transform);
}
cocos2d::Mat4 Physics3DHingeConstraint::getFrameOffsetB() const
{
const auto& transform = static_cast<btHingeConstraint*>(_constraint)->getFrameOffsetB();
return convertbtTransformToMat4(transform);
}
void Physics3DHingeConstraint::setFrames(const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB)
{
auto transformA = convertMat4TobtTransform(frameA);
auto transformB = convertMat4TobtTransform(frameB);
static_cast<btHingeConstraint*>(_constraint)->setFrames(transformA, transformB);
}
void Physics3DHingeConstraint::setAngularOnly(bool angularOnly)
{
static_cast<btHingeConstraint*>(_constraint)->setAngularOnly(angularOnly);
}
void Physics3DHingeConstraint::enableAngularMotor(bool enableMotor, float targetVelocity, float maxMotorImpulse)
{
static_cast<btHingeConstraint*>(_constraint)->enableAngularMotor(enableMotor, targetVelocity, maxMotorImpulse);
}
void Physics3DHingeConstraint::enableMotor(bool enableMotor)
{
static_cast<btHingeConstraint*>(_constraint)->enableMotor(enableMotor);
}
void Physics3DHingeConstraint::setMaxMotorImpulse(float maxMotorImpulse)
{
static_cast<btHingeConstraint*>(_constraint)->setMaxMotorImpulse(maxMotorImpulse);
}
void Physics3DHingeConstraint::setMotorTarget(const cocos2d::Quaternion& qAinB, float dt)
{
static_cast<btHingeConstraint*>(_constraint)->setMotorTarget(convertQuatTobtQuat(qAinB), dt);
}
void Physics3DHingeConstraint::setMotorTarget(float targetAngle, float dt)
{
static_cast<btHingeConstraint*>(_constraint)->setMotorTarget(targetAngle, dt);
}
void Physics3DHingeConstraint::setLimit(float low, float high, float softness, float biasFactor, float relaxationFactor)
{
static_cast<btHingeConstraint*>(_constraint)->setLimit(low, high, softness, biasFactor, relaxationFactor);
}
void Physics3DHingeConstraint::setAxis(const cocos2d::Vec3& axisInA)
{
auto axis = convertVec3TobtVector3(axisInA);
static_cast<btHingeConstraint*>(_constraint)->setAxis(axis);
}
float Physics3DHingeConstraint::getLowerLimit() const
{
return static_cast<btHingeConstraint*>(_constraint)->getLowerLimit();
}
float Physics3DHingeConstraint::getUpperLimit() const
{
return static_cast<btHingeConstraint*>(_constraint)->getUpperLimit();
}
float Physics3DHingeConstraint::getHingeAngle() const
{
return static_cast<btHingeConstraint*>(_constraint)->getHingeAngle();
}
float Physics3DHingeConstraint::getHingeAngle(const cocos2d::Mat4& transA, const cocos2d::Mat4& transB)
{
auto btTransA = convertMat4TobtTransform(transA);
auto btTransB = convertMat4TobtTransform(transB);
return static_cast<btHingeConstraint*>(_constraint)->getHingeAngle(btTransA, btTransB);
}
cocos2d::Mat4 Physics3DHingeConstraint::getAFrame() const
{
const auto& trans = static_cast<btHingeConstraint*>(_constraint)->getAFrame();
return convertbtTransformToMat4(trans);
}
cocos2d::Mat4 Physics3DHingeConstraint::getBFrame() const
{
const auto& trans = static_cast<btHingeConstraint*>(_constraint)->getBFrame();
return convertbtTransformToMat4(trans);
}
bool Physics3DHingeConstraint::getAngularOnly() const
{
return static_cast<btHingeConstraint*>(_constraint)->getAngularOnly();
}
bool Physics3DHingeConstraint::getEnableAngularMotor() const
{
return static_cast<btHingeConstraint*>(_constraint)->getEnableAngularMotor();
}
float Physics3DHingeConstraint::getMotorTargetVelosity() const
{
return static_cast<btHingeConstraint*>(_constraint)->getMotorTargetVelosity();
}
float Physics3DHingeConstraint::getMaxMotorImpulse() const
{
return static_cast<btHingeConstraint*>(_constraint)->getMaxMotorImpulse();
}
bool Physics3DHingeConstraint::getUseFrameOffset() const
{
return static_cast<btHingeConstraint*>(_constraint)->getUseFrameOffset();
}
void Physics3DHingeConstraint::setUseFrameOffset(bool frameOffsetOnOff)
{
static_cast<btHingeConstraint*>(_constraint)->setUseFrameOffset(frameOffsetOnOff);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Physics3DSliderConstraint* Physics3DSliderConstraint::create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& frameInA, const cocos2d::Mat4& frameInB ,bool useLinearReferenceFrameA)
{
auto ret = new (std::nothrow) Physics3DSliderConstraint();
ret->_bodyA = rbA;
ret->_bodyB = rbB;
rbA->retain();
rbB->retain();
auto transformA = convertMat4TobtTransform(frameInA);
auto transformB = convertMat4TobtTransform(frameInB);
ret->_constraint = new btSliderConstraint(*rbA->getRigidBody(), *rbB->getRigidBody(), transformA, transformB, useLinearReferenceFrameA);
ret->autorelease();
return ret;
}
cocos2d::Mat4 Physics3DSliderConstraint::getFrameOffsetA() const
{
const auto& frameOff = static_cast<btSliderConstraint*>(_constraint)->getFrameOffsetA();
return convertbtTransformToMat4(frameOff);
}
cocos2d::Mat4 Physics3DSliderConstraint::getFrameOffsetB() const
{
const auto& frameOff = static_cast<btSliderConstraint*>(_constraint)->getFrameOffsetB();
return convertbtTransformToMat4(frameOff);
}
float Physics3DSliderConstraint::getLowerLinLimit() const
{
return static_cast<btSliderConstraint*>(_constraint)->getLowerLinLimit();
}
void Physics3DSliderConstraint::setLowerLinLimit(float lowerLimit)
{
static_cast<btSliderConstraint*>(_constraint)->setLowerLinLimit(lowerLimit);
}
float Physics3DSliderConstraint::getUpperLinLimit() const
{
return static_cast<btSliderConstraint*>(_constraint)->getUpperLinLimit();
}
void Physics3DSliderConstraint::setUpperLinLimit(float upperLimit)
{
static_cast<btSliderConstraint*>(_constraint)->setUpperLinLimit(upperLimit);
}
float Physics3DSliderConstraint::getLowerAngLimit() const
{
return static_cast<btSliderConstraint*>(_constraint)->getLowerAngLimit();
}
void Physics3DSliderConstraint::setLowerAngLimit(float lowerLimit)
{
static_cast<btSliderConstraint*>(_constraint)->setLowerAngLimit(lowerLimit);
}
float Physics3DSliderConstraint::getUpperAngLimit() const
{
return static_cast<btSliderConstraint*>(_constraint)->getUpperAngLimit();
}
void Physics3DSliderConstraint::setUpperAngLimit(float upperLimit)
{
static_cast<btSliderConstraint*>(_constraint)->setUpperAngLimit(upperLimit);
}
bool Physics3DSliderConstraint::getUseLinearReferenceFrameA() const
{
return static_cast<btSliderConstraint*>(_constraint)->getUseLinearReferenceFrameA();
}
float Physics3DSliderConstraint::getSoftnessDirLin() const
{
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessDirLin();
}
float Physics3DSliderConstraint::getRestitutionDirLin() const
{
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionDirLin();
}
float Physics3DSliderConstraint::getDampingDirLin() const
{
return static_cast<btSliderConstraint*>(_constraint)->getDampingDirLin();
}
float Physics3DSliderConstraint::getSoftnessDirAng() const
{
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessDirAng();
}
float Physics3DSliderConstraint::getRestitutionDirAng() const
{
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionDirAng();
}
float Physics3DSliderConstraint::getDampingDirAng() const
{
return static_cast<btSliderConstraint*>(_constraint)->getDampingDirAng();
}
float Physics3DSliderConstraint::getSoftnessLimLin() const
{
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessLimLin();
}
float Physics3DSliderConstraint::getRestitutionLimLin() const
{
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionLimLin();
}
float Physics3DSliderConstraint::getDampingLimLin() const
{
return static_cast<btSliderConstraint*>(_constraint)->getDampingLimAng();
}
float Physics3DSliderConstraint::getSoftnessLimAng() const
{
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessLimAng();
}
float Physics3DSliderConstraint::getRestitutionLimAng() const
{
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionLimAng();
}
float Physics3DSliderConstraint::getDampingLimAng() const
{
return static_cast<btSliderConstraint*>(_constraint)->getDampingLimAng();
}
float Physics3DSliderConstraint::getSoftnessOrthoLin() const
{
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessOrthoLin();
}
float Physics3DSliderConstraint::getRestitutionOrthoLin() const
{
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionOrthoAng();
}
float Physics3DSliderConstraint::getDampingOrthoLin() const
{
return static_cast<btSliderConstraint*>(_constraint)->getDampingOrthoLin();
}
float Physics3DSliderConstraint::getSoftnessOrthoAng() const
{
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessOrthoAng();
}
float Physics3DSliderConstraint::getRestitutionOrthoAng() const
{
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionOrthoAng();
}
float Physics3DSliderConstraint::getDampingOrthoAng() const
{
return static_cast<btSliderConstraint*>(_constraint)->getDampingOrthoAng();
}
void Physics3DSliderConstraint::setSoftnessDirLin(float softnessDirLin)
{
static_cast<btSliderConstraint*>(_constraint)->setSoftnessDirLin(softnessDirLin);
}
void Physics3DSliderConstraint::setRestitutionDirLin(float restitutionDirLin)
{
static_cast<btSliderConstraint*>(_constraint)->setRestitutionDirLin(restitutionDirLin);
}
void Physics3DSliderConstraint::setDampingDirLin(float dampingDirLin)
{
static_cast<btSliderConstraint*>(_constraint)->setDampingDirLin(dampingDirLin);
}
void Physics3DSliderConstraint::setSoftnessDirAng(float softnessDirAng)
{
static_cast<btSliderConstraint*>(_constraint)->setSoftnessDirAng(softnessDirAng);
}
void Physics3DSliderConstraint::setRestitutionDirAng(float restitutionDirAng)
{
static_cast<btSliderConstraint*>(_constraint)->setRestitutionDirAng(restitutionDirAng);
}
void Physics3DSliderConstraint::setDampingDirAng(float dampingDirAng)
{
static_cast<btSliderConstraint*>(_constraint)->setDampingDirAng(dampingDirAng);
}
void Physics3DSliderConstraint::setSoftnessLimLin(float softnessLimLin)
{
static_cast<btSliderConstraint*>(_constraint)->setSoftnessLimLin(softnessLimLin);
}
void Physics3DSliderConstraint::setRestitutionLimLin(float restitutionLimLin)
{
static_cast<btSliderConstraint*>(_constraint)->setRestitutionDirLin(restitutionLimLin);
}
void Physics3DSliderConstraint::setDampingLimLin(float dampingLimLin)
{
static_cast<btSliderConstraint*>(_constraint)->setDampingLimLin(dampingLimLin);
}
void Physics3DSliderConstraint::setSoftnessLimAng(float softnessLimAng)
{
static_cast<btSliderConstraint*>(_constraint)->setSoftnessLimAng(softnessLimAng);
}
void Physics3DSliderConstraint::setRestitutionLimAng(float restitutionLimAng)
{
static_cast<btSliderConstraint*>(_constraint)->setRestitutionLimAng(restitutionLimAng);
}
void Physics3DSliderConstraint::setDampingLimAng(float dampingLimAng)
{
static_cast<btSliderConstraint*>(_constraint)->setDampingLimAng(dampingLimAng);
}
void Physics3DSliderConstraint::setSoftnessOrthoLin(float softnessOrthoLin)
{
static_cast<btSliderConstraint*>(_constraint)->setSoftnessOrthoLin(softnessOrthoLin);
}
void Physics3DSliderConstraint::setRestitutionOrthoLin(float restitutionOrthoLin)
{
static_cast<btSliderConstraint*>(_constraint)->setRestitutionOrthoLin(restitutionOrthoLin);
}
void Physics3DSliderConstraint::setDampingOrthoLin(float dampingOrthoLin)
{
static_cast<btSliderConstraint*>(_constraint)->setDampingLimLin(dampingOrthoLin);
}
void Physics3DSliderConstraint::setSoftnessOrthoAng(float softnessOrthoAng)
{
static_cast<btSliderConstraint*>(_constraint)->setSoftnessOrthoAng(softnessOrthoAng);
}
void Physics3DSliderConstraint::setRestitutionOrthoAng(float restitutionOrthoAng)
{
static_cast<btSliderConstraint*>(_constraint)->setRestitutionOrthoAng(restitutionOrthoAng);
}
void Physics3DSliderConstraint::setDampingOrthoAng(float dampingOrthoAng)
{
static_cast<btSliderConstraint*>(_constraint)->setDampingOrthoAng(dampingOrthoAng);
}
void Physics3DSliderConstraint::setPoweredLinMotor(bool onOff)
{
static_cast<btSliderConstraint*>(_constraint)->setPoweredLinMotor(onOff);
}
bool Physics3DSliderConstraint::getPoweredLinMotor() const
{
return static_cast<btSliderConstraint*>(_constraint)->getPoweredLinMotor();
}
void Physics3DSliderConstraint::setTargetLinMotorVelocity(float targetLinMotorVelocity)
{
static_cast<btSliderConstraint*>(_constraint)->setTargetLinMotorVelocity(targetLinMotorVelocity);
}
float Physics3DSliderConstraint::getTargetLinMotorVelocity() const
{
return static_cast<btSliderConstraint*>(_constraint)->getTargetLinMotorVelocity();
}
void Physics3DSliderConstraint::setMaxLinMotorForce(float maxLinMotorForce)
{
static_cast<btSliderConstraint*>(_constraint)->setMaxLinMotorForce(maxLinMotorForce);
}
float Physics3DSliderConstraint::getMaxLinMotorForce() const
{
return static_cast<btSliderConstraint*>(_constraint)->getMaxLinMotorForce();
}
void Physics3DSliderConstraint::setPoweredAngMotor(bool onOff)
{
static_cast<btSliderConstraint*>(_constraint)->setPoweredAngMotor(onOff);
}
bool Physics3DSliderConstraint::getPoweredAngMotor() const
{
return static_cast<btSliderConstraint*>(_constraint)->getPoweredAngMotor();
}
void Physics3DSliderConstraint::setTargetAngMotorVelocity(float targetAngMotorVelocity)
{
return static_cast<btSliderConstraint*>(_constraint)->setTargetAngMotorVelocity(targetAngMotorVelocity);
}
float Physics3DSliderConstraint::getTargetAngMotorVelocity() const
{
return static_cast<btSliderConstraint*>(_constraint)->getTargetAngMotorVelocity();
}
void Physics3DSliderConstraint::setMaxAngMotorForce(float maxAngMotorForce)
{
return static_cast<btSliderConstraint*>(_constraint)->setMaxAngMotorForce(maxAngMotorForce);
}
float Physics3DSliderConstraint::getMaxAngMotorForce() const
{
return static_cast<btSliderConstraint*>(_constraint)->getMaxAngMotorForce();
}
float Physics3DSliderConstraint::getLinearPos() const
{
return static_cast<btSliderConstraint*>(_constraint)->getLinearPos();
}
float Physics3DSliderConstraint::getAngularPos() const
{
return static_cast<btSliderConstraint*>(_constraint)->getAngularPos();
}
// access for UseFrameOffset
bool Physics3DSliderConstraint::getUseFrameOffset() const
{
return static_cast<btSliderConstraint*>(_constraint)->getUseFrameOffset();
}
void Physics3DSliderConstraint::setUseFrameOffset(bool frameOffsetOnOff)
{
static_cast<btSliderConstraint*>(_constraint)->setUseFrameOffset(frameOffsetOnOff);
}
void Physics3DSliderConstraint::setFrames(const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB)
{
auto btFrameA = convertMat4TobtTransform(frameA);
auto btFrameB = convertMat4TobtTransform(frameB);
static_cast<btSliderConstraint*>(_constraint)->setFrames(btFrameA, btFrameB);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Physics3DConeTwistConstraint* Physics3DConeTwistConstraint::create(Physics3DRigidBody* rbA, const cocos2d::Mat4& frameA)
{
auto ret = new (std::nothrow) Physics3DConeTwistConstraint();
ret->_bodyA = rbA;
rbA->retain();
auto btFrame = convertMat4TobtTransform(frameA);
ret->_constraint = new btConeTwistConstraint(*rbA->getRigidBody(), btFrame);
ret->autorelease();
return ret;
}
Physics3DConeTwistConstraint* Physics3DConeTwistConstraint::create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB)
{
auto ret = new (std::nothrow) Physics3DConeTwistConstraint();
ret->_bodyA = rbA;
ret->_bodyB = rbB;
rbA->retain();
rbB->retain();
auto btFrameA = convertMat4TobtTransform(frameA);
auto btFrameB = convertMat4TobtTransform(frameB);
ret->_constraint = new btConeTwistConstraint(*rbA->getRigidBody(), *rbB->getRigidBody(), btFrameA, btFrameB);
ret->autorelease();
return ret;
}
void Physics3DConeTwistConstraint::setLimit(float swingSpan1,float swingSpan2,float twistSpan, float softness, float biasFactor, float relaxationFactor)
{
static_cast<btConeTwistConstraint*>(_constraint)->setLimit(swingSpan1, swingSpan2, twistSpan, softness, biasFactor, relaxationFactor);
}
cocos2d::Mat4 Physics3DConeTwistConstraint::getAFrame() const
{
const auto& frame = static_cast<btConeTwistConstraint*>(_constraint)->getAFrame();
return convertbtTransformToMat4(frame);
}
cocos2d::Mat4 Physics3DConeTwistConstraint::getBFrame() const
{
const auto& frame = static_cast<btConeTwistConstraint*>(_constraint)->getBFrame();
return convertbtTransformToMat4(frame);
}
float Physics3DConeTwistConstraint::getSwingSpan1() const
{
return static_cast<btConeTwistConstraint*>(_constraint)->getSwingSpan1();
}
float Physics3DConeTwistConstraint::getSwingSpan2() const
{
return static_cast<btConeTwistConstraint*>(_constraint)->getSwingSpan2();
}
float Physics3DConeTwistConstraint::getTwistSpan() const
{
return static_cast<btConeTwistConstraint*>(_constraint)->getTwistSpan();
}
float Physics3DConeTwistConstraint::getTwistAngle() const
{
return static_cast<btConeTwistConstraint*>(_constraint)->getTwistAngle();
}
void Physics3DConeTwistConstraint::setDamping(float damping)
{
static_cast<btConeTwistConstraint*>(_constraint)->setDamping(damping);
}
void Physics3DConeTwistConstraint::enableMotor(bool b)
{
static_cast<btConeTwistConstraint*>(_constraint)->enableMotor(b);
}
void Physics3DConeTwistConstraint::setMaxMotorImpulse(float maxMotorImpulse)
{
static_cast<btConeTwistConstraint*>(_constraint)->setMaxMotorImpulse(maxMotorImpulse);
}
void Physics3DConeTwistConstraint::setMaxMotorImpulseNormalized(float maxMotorImpulse)
{
static_cast<btConeTwistConstraint*>(_constraint)->setMaxMotorImpulseNormalized(maxMotorImpulse);
}
float Physics3DConeTwistConstraint::getFixThresh() const
{
return static_cast<btConeTwistConstraint*>(_constraint)->getFixThresh();
}
void Physics3DConeTwistConstraint::setFixThresh(float fixThresh)
{
static_cast<btConeTwistConstraint*>(_constraint)->setFixThresh(fixThresh);
}
void Physics3DConeTwistConstraint::setMotorTarget(const btQuaternion &q)
{
static_cast<btConeTwistConstraint*>(_constraint)->setMotorTarget(q);
}
// same as above, but q is the desired rotation of frameA wrt frameB in constraint space
void Physics3DConeTwistConstraint::setMotorTargetInConstraintSpace(const btQuaternion &q)
{
static_cast<btConeTwistConstraint*>(_constraint)->setMotorTargetInConstraintSpace(q);
}
cocos2d::Vec3 Physics3DConeTwistConstraint::GetPointForAngle(float fAngleInRadians, float fLength) const
{
const auto& point = static_cast<btConeTwistConstraint*>(_constraint)->GetPointForAngle(fAngleInRadians, fLength);
return convertbtVector3ToVec3(point);
}
void Physics3DConeTwistConstraint::setFrames(const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB)
{
const auto& btFrameA = convertMat4TobtTransform(frameA);
const auto& btFrameB = convertMat4TobtTransform(frameB);
static_cast<btConeTwistConstraint*>(_constraint)->setFrames(btFrameA, btFrameB);
}
cocos2d::Mat4 Physics3DConeTwistConstraint::getFrameOffsetA() const
{
const auto& trans = static_cast<btConeTwistConstraint*>(_constraint)->getFrameOffsetA();
return convertbtTransformToMat4(trans);
}
cocos2d::Mat4 Physics3DConeTwistConstraint::getFrameOffsetB() const
{
const auto& trans = static_cast<btConeTwistConstraint*>(_constraint)->getFrameOffsetB();
return convertbtTransformToMat4(trans);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Physics3D6DofConstraint* Physics3D6DofConstraint::create(Physics3DRigidBody* rbB, const cocos2d::Mat4& frameInB, bool useLinearReferenceFrameB)
{
auto ret = new Physics3D6DofConstraint();
ret->_bodyB = rbB;
rbB->retain();
auto frameB = convertMat4TobtTransform(frameInB);
ret->_constraint = new btGeneric6DofConstraint(*rbB->getRigidBody(), frameB, useLinearReferenceFrameB);
ret->autorelease();
return ret;
}
Physics3D6DofConstraint* Physics3D6DofConstraint::create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& frameInA, const cocos2d::Mat4& frameInB, bool useLinearReferenceFrameA)
{
auto ret = new Physics3D6DofConstraint();
ret->_bodyA = rbA;
ret->_bodyB = rbB;
rbA->retain();
rbB->retain();
auto frameA = convertMat4TobtTransform(frameInA);
auto frameB = convertMat4TobtTransform(frameInB);
ret->_constraint = new btGeneric6DofConstraint(*rbA->getRigidBody(), *rbB->getRigidBody(), frameA, frameB, useLinearReferenceFrameA);
ret->autorelease();
return ret;
}
void Physics3D6DofConstraint::setLinearLowerLimit(const cocos2d::Vec3& linearLower)
{
auto lower = convertVec3TobtVector3(linearLower);
static_cast<btGeneric6DofConstraint*>(_constraint)->setLinearLowerLimit(lower);
}
cocos2d::Vec3 Physics3D6DofConstraint::getLinearLowerLimit() const
{
btVector3 lower;
static_cast<btGeneric6DofConstraint*>(_constraint)->getLinearLowerLimit(lower);
return convertbtVector3ToVec3(lower);
}
void Physics3D6DofConstraint::setLinearUpperLimit(const cocos2d::Vec3& linearUpper)
{
auto upper = convertVec3TobtVector3(linearUpper);
static_cast<btGeneric6DofConstraint*>(_constraint)->setLinearUpperLimit(upper);
}
cocos2d::Vec3 Physics3D6DofConstraint::getLinearUpperLimit() const
{
btVector3 upper;
static_cast<btGeneric6DofConstraint*>(_constraint)->getLinearUpperLimit(upper);
return convertbtVector3ToVec3(upper);
}
void Physics3D6DofConstraint::setAngularLowerLimit(const cocos2d::Vec3& angularLower)
{
auto lower = convertVec3TobtVector3(angularLower);
static_cast<btGeneric6DofConstraint*>(_constraint)->setAngularLowerLimit(lower);
}
cocos2d::Vec3 Physics3D6DofConstraint::getAngularLowerLimit() const
{
btVector3 lower;
static_cast<btGeneric6DofConstraint*>(_constraint)->getAngularLowerLimit(lower);
return convertbtVector3ToVec3(lower);
}
void Physics3D6DofConstraint::setAngularUpperLimit(const cocos2d::Vec3& angularUpper)
{
auto upper = convertVec3TobtVector3(angularUpper);
static_cast<btGeneric6DofConstraint*>(_constraint)->setAngularUpperLimit(upper);
}
cocos2d::Vec3 Physics3D6DofConstraint::getAngularUpperLimit() const
{
btVector3 upper;
static_cast<btGeneric6DofConstraint*>(_constraint)->getAngularUpperLimit(upper);
return convertbtVector3ToVec3(upper);
}
bool Physics3D6DofConstraint::isLimited(int limitIndex) const
{
return static_cast<btGeneric6DofConstraint*>(_constraint)->isLimited(limitIndex);
}
bool Physics3D6DofConstraint::getUseFrameOffset() const
{
return static_cast<btGeneric6DofConstraint*>(_constraint)->getUseFrameOffset();
}
void Physics3D6DofConstraint::setUseFrameOffset(bool frameOffsetOnOff) const
{
static_cast<btGeneric6DofConstraint*>(_constraint)->setUseFrameOffset(frameOffsetOnOff);
}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif //CC_USE_3D_PHYSICS

View File

@ -0,0 +1,593 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 __PHYSICS_3D_CONSTRAINT_H__
#define __PHYSICS_3D_CONSTRAINT_H__
#include "math/CCMath.h"
#include "base/CCRef.h"
#include "base/ccConfig.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
class btTypedConstraint;
NS_CC_BEGIN
/**
* @addtogroup _3d
* @{
*/
class Physics3DRigidBody;
/** @brief Physics3DConstraint: Constraint affects the movement of physics object, it usually connet one or two physics object. There are some types of physics constraints. */
class CC_DLL Physics3DConstraint : public Ref
{
public:
enum class ConstraintType
{
UNKNOWN,
POINT_TO_POINT,
HINGE,
SLIDER,
CONE_TWIST,
SIX_DOF,
};
/**
* get the impulse that break the constraint
*/
float getBreakingImpulse() const;
/**
* set the impulse that break the constraint
*/
void setBreakingImpulse(float impulse);
/**
* is it enabled
*/
bool isEnabled() const;
/**
* set enable or not
*/
void setEnabled(bool enabled);
/**
* get rigid body a
*/
Physics3DRigidBody* getBodyA() const { return _bodyA; }
/**
* get rigid body b
*/
Physics3DRigidBody* getBodyB() const { return _bodyB; }
/**
* get constraint type
*/
ConstraintType getConstraintType() const { return _type; }
/**
* get user data
*/
void setUserData(void* userData) { _userData = userData; }
/**
* get user data
*/
void* getUserData() const { return _userData; }
/**
* get override number of solver iterations
*/
int getOverrideNumSolverIterations() const;
/**
* override the number of constraint solver iterations used to solve this constraint, -1 will use the default number of iterations, as specified in SolverInfo.m_numIterations
*/
void setOverrideNumSolverIterations(int overideNumIterations);
#if (CC_ENABLE_BULLET_INTEGRATION)
btTypedConstraint* getbtContraint() { return _constraint; }
#endif
protected:
Physics3DConstraint();
virtual ~Physics3DConstraint();
btTypedConstraint* _constraint;
Physics3DRigidBody* _bodyA;
Physics3DRigidBody* _bodyB;
ConstraintType _type;
void* _userData;
};
/**
* Point to point constraint limits the translation so that the local pivot points of 2 rigidbodies match in worldspace.
*/
class CC_DLL Physics3DPointToPointConstraint : public Physics3DConstraint
{
public:
/**
* create point to point constraint, limits the translation of local pivot point of rigid body A
* @param rbA The rigid body going to be fixed
* @param pivotPointInA local pivot point in A's local space
* @return created constraint
*/
static Physics3DPointToPointConstraint* create(Physics3DRigidBody* rbA, const cocos2d::Vec3& pivotPointInA);
/**
* create point to point constraint, make the local pivot points of 2 rigid bodies match in worldspace.
* @param rbA The rigid body A going to be fixed
* @param rbB The rigid body B going to be fixed
* @param pivotPointInA local pivot point in A's local space
* @param pivotPointInB local pivot point in B's local space
* @return created constraint
*/
static Physics3DPointToPointConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Vec3& pivotPointInA, const cocos2d::Vec3& pivotPointInB);
/**
* set pivot point in A's local space
*/
void setPivotPointInA(const cocos2d::Vec3& pivotA);
/**
* set pivot point in B's local space
*/
void setPivotPointInB(const cocos2d::Vec3& pivotB);
/**
* get pivot point in A's local space
*/
cocos2d::Vec3 getPivotPointInA() const;
/**
* get pivot point in B's local space
*/
cocos2d::Vec3 getPivotPointInB() const;
CC_CONSTRUCTOR_ACCESS:
Physics3DPointToPointConstraint();
virtual ~Physics3DPointToPointConstraint();
protected:
bool init(Physics3DRigidBody* rbA, const cocos2d::Vec3& pivotPointInA);
bool init(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Vec3& pivotPointInA, const cocos2d::Vec3& pivotPointInB);
};
/**
* Hinge constraint restricts two additional angular degrees of freedom, so the body can only rotate around one axis, the hinge axis. This can be useful to represent doors or wheels rotating around one axis.
* hinge constraint between two rigidbodies each with a pivotpoint that descibes the axis location in local space
*/
class CC_DLL Physics3DHingeConstraint : public Physics3DConstraint
{
public:
/**
* create hinge constraint
* @param rbA rigid body A
* @param rbAFrame rigid body A's frame
* @param useReferenceFrameA use frame A as reference
*/
static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA, const cocos2d::Mat4& rbAFrame, bool useReferenceFrameA = false);
/**
* create hinge constraint
* @param rbA rigid body A
* @param pivotInA pivot in rigid body A's local space
* @param axisInA axis in rigid body A's local space
* @param useReferenceFrameA use frame A as reference
*/
static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA, const cocos2d::Vec3& pivotInA, const cocos2d::Vec3& axisInA, bool useReferenceFrameA = false);
/**
* create hinge constraint
* @param rbA rigid body A
* @param rbB rigid body B
* @param pivotInA pivot point in A's local space
* @param pivotInB pivot point in B's local space
* @param axisInA axis in A's local space
* @param axisInB axis in B's local space
* @param useReferenceFrameA use frame A as reference
*/
static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Vec3& pivotInA,const cocos2d::Vec3& pivotInB, cocos2d::Vec3& axisInA, cocos2d::Vec3& axisInB, bool useReferenceFrameA = false);
/**
* create hinge constraint
* @param rbA rigid body A
* @param rbB rigid body B
* @param rbAFrame rigid body A's frame
* @param rbBFrame rigid body B's frame
* @param useReferenceFrameA use frame A as reference
*/
static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& rbAFrame, const cocos2d::Mat4& rbBFrame, bool useReferenceFrameA = false);
/**
* get rigid body A's frame offset
*/
cocos2d::Mat4 getFrameOffsetA() const;
/**
* get rigid body B's frame offset
*/
cocos2d::Mat4 getFrameOffsetB() const;
/**
* set frames for rigid body A and B
*/
void setFrames(const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB);
/**
* set angular only
*/
void setAngularOnly(bool angularOnly);
/** enable angular motor */
void enableAngularMotor(bool enableMotor, float targetVelocity, float maxMotorImpulse);
// extra motor API, including ability to set a target rotation (as opposed to angular velocity)
// note: setMotorTarget sets angular velocity under the hood, so you must call it every tick to
// maintain a given angular target.
void enableMotor(bool enableMotor);
/** set max motor impulse */
void setMaxMotorImpulse(float maxMotorImpulse);
/**
* set motor target
*/
void setMotorTarget(const cocos2d::Quaternion& qAinB, float dt);
/** set motor target */
void setMotorTarget(float targetAngle, float dt);
/** set limit */
void setLimit(float low, float high, float _softness = 0.9f, float _biasFactor = 0.3f, float _relaxationFactor = 1.0f);
/**set axis*/
void setAxis(const cocos2d::Vec3& axisInA);
/**get lower limit*/
float getLowerLimit() const;
/**get upper limit*/
float getUpperLimit() const;
/**get hinge angle*/
float getHingeAngle() const;
/**get hinge angle*/
float getHingeAngle(const cocos2d::Mat4& transA, const cocos2d::Mat4& transB);
/**get A's frame */
cocos2d::Mat4 getAFrame() const;
/**get B's frame*/
cocos2d::Mat4 getBFrame() const;
/**get angular only*/
bool getAngularOnly() const;
/**get enable angular motor*/
bool getEnableAngularMotor() const;
/**get motor target velosity*/
float getMotorTargetVelosity() const;
/**get max motor impulse*/
float getMaxMotorImpulse() const;
/** access for UseFrameOffset*/
bool getUseFrameOffset() const;
/**set use frame offset*/
void setUseFrameOffset(bool frameOffsetOnOff);
CC_CONSTRUCTOR_ACCESS:
Physics3DHingeConstraint()
{
_type = ConstraintType::HINGE;
}
virtual ~Physics3DHingeConstraint(){}
};
/**
* It allows the body to rotate around x axis and translate along this axis.
* softness, restitution and damping for different cases
* DirLin - moving inside linear limits
* LimLin - hitting linear limit
* DirAng - moving inside angular limits
* LimAng - hitting angular limit
* OrthoLin, OrthoAng - against constraint axis
*/
class CC_DLL Physics3DSliderConstraint : public Physics3DConstraint
{
public:
/**
* create slider constraint
* @param rbA rigid body A
* @param rbB rigid body B
* @param frameInA frame in A's local space
* @param frameInB frame in B's local space
* @param useLinearReferenceFrameA use fixed frame A for linear limits
*/
static Physics3DSliderConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& frameInA, const cocos2d::Mat4& frameInB ,bool useLinearReferenceFrameA);
/**get A's frame offset*/
cocos2d::Mat4 getFrameOffsetA() const;
/**get B's frame offset*/
cocos2d::Mat4 getFrameOffsetB() const;
/**get lower linear limit*/
float getLowerLinLimit() const;
/**set lower linear limit*/
void setLowerLinLimit(float lowerLimit);
/**get upper linear limit*/
float getUpperLinLimit() const;
/**set upper linear limit*/
void setUpperLinLimit(float upperLimit);
/**get lower angular limit*/
float getLowerAngLimit() const;
/**set lower angualr limit*/
void setLowerAngLimit(float lowerLimit);
/**get upper anglular limit*/
float getUpperAngLimit() const;
/**set upper anglular limit*/
void setUpperAngLimit(float upperLimit);
/**use A's frame as linear refference*/
bool getUseLinearReferenceFrameA() const;
float getSoftnessDirLin() const;
float getRestitutionDirLin() const;
float getDampingDirLin() const;
float getSoftnessDirAng() const;
float getRestitutionDirAng() const;
float getDampingDirAng() const;
float getSoftnessLimLin() const;
float getRestitutionLimLin() const;
float getDampingLimLin() const;
float getSoftnessLimAng() const;
float getRestitutionLimAng() const;
float getDampingLimAng() const;
float getSoftnessOrthoLin() const;
float getRestitutionOrthoLin() const;
float getDampingOrthoLin() const;
float getSoftnessOrthoAng() const;
float getRestitutionOrthoAng() const;
float getDampingOrthoAng() const;
void setSoftnessDirLin(float softnessDirLin);
void setRestitutionDirLin(float restitutionDirLin);
void setDampingDirLin(float dampingDirLin);
void setSoftnessDirAng(float softnessDirAng);
void setRestitutionDirAng(float restitutionDirAng);
void setDampingDirAng(float dampingDirAng);
void setSoftnessLimLin(float softnessLimLin);
void setRestitutionLimLin(float restitutionLimLin);
void setDampingLimLin(float dampingLimLin);
void setSoftnessLimAng(float softnessLimAng);
void setRestitutionLimAng(float restitutionLimAng);
void setDampingLimAng(float dampingLimAng);
void setSoftnessOrthoLin(float softnessOrthoLin);
void setRestitutionOrthoLin(float restitutionOrthoLin);
void setDampingOrthoLin(float dampingOrthoLin);
void setSoftnessOrthoAng(float softnessOrthoAng);
void setRestitutionOrthoAng(float restitutionOrthoAng);
void setDampingOrthoAng(float dampingOrthoAng);
void setPoweredLinMotor(bool onOff);
bool getPoweredLinMotor() const;
void setTargetLinMotorVelocity(float targetLinMotorVelocity);
float getTargetLinMotorVelocity() const;
void setMaxLinMotorForce(float maxLinMotorForce);
float getMaxLinMotorForce() const;
void setPoweredAngMotor(bool onOff);
bool getPoweredAngMotor() const;
void setTargetAngMotorVelocity(float targetAngMotorVelocity);
float getTargetAngMotorVelocity() const;
void setMaxAngMotorForce(float maxAngMotorForce);
float getMaxAngMotorForce() const;
float getLinearPos() const;
float getAngularPos() const;
/** access for UseFrameOffset*/
bool getUseFrameOffset() const;
/**set use frame offset*/
void setUseFrameOffset(bool frameOffsetOnOff);
/**set frames for rigid body A and B*/
void setFrames(const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB);
CC_CONSTRUCTOR_ACCESS:
Physics3DSliderConstraint()
{
_type = ConstraintType::SLIDER;
}
virtual ~Physics3DSliderConstraint(){}
};
/**
* It is a special point to point constraint that adds cone and twist axis limits. The x-axis serves as twist axis.
*/
class CC_DLL Physics3DConeTwistConstraint : public Physics3DConstraint
{
public:
/**
* create cone twist constraint
* rbA rigid body A
* frameA A's local frame
*/
static Physics3DConeTwistConstraint* create(Physics3DRigidBody* rbA, const cocos2d::Mat4& frameA);
/**
* create cone twist constraint
* rbA rigid body A
* rbB rigid body B
* frameA rigid body A's local frame
* frameB rigid body B's local frame
*/
static Physics3DConeTwistConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB);
/**
* set limits
* @param swingSpan1 swing span1
* @param swingSpan2 swing span2
* @param twistSpan twist span
* @param softness 0->1, recommend ~0.8->1. Describes % of limits where movement is free. Beyond this softness %, the limit is gradually enforced until the "hard" (1.0) limit is reached.
* @param biasFactor 0->1?, recommend 0.3 +/-0.3 or so. Strength with which constraint resists zeroth order (angular, not angular velocity) limit violation.
* @param relaxationFactor 0->1, recommend to stay near 1. the lower the value, the less the constraint will fight velocities which violate the angular limits.
*/
void setLimit(float swingSpan1,float swingSpan2,float twistSpan, float softness = 1.f, float biasFactor = 0.3f, float relaxationFactor = 1.0f);
/**get A's frame*/
cocos2d::Mat4 getAFrame() const;
/**get B's frame*/
cocos2d::Mat4 getBFrame() const;
/**get swing span1*/
float getSwingSpan1() const;
/**get swing span2*/
float getSwingSpan2() const;
/**get twist span*/
float getTwistSpan() const;
/**get twist angle*/
float getTwistAngle() const;
/**set damping*/
void setDamping(float damping);
/**enable motor*/
void enableMotor(bool b);
/**set max motor impulse*/
void setMaxMotorImpulse(float maxMotorImpulse);
/**set max motor impulse normalize*/
void setMaxMotorImpulseNormalized(float maxMotorImpulse);
/**get fix thresh*/
float getFixThresh() const;
/**set fix thresh*/
void setFixThresh(float fixThresh);
/**
* setMotorTarget
* @param q the desired rotation of bodyA wrt bodyB. Note: if q violates the joint limits, the internal target is clamped to avoid conflicting impulses (very bad for stability), also don't forget to enableMotor()
*/
void setMotorTarget(const btQuaternion &q);
/** setMotorTarget, q is the desired rotation of frameA wrt frameB in constraint space*/
void setMotorTargetInConstraintSpace(const btQuaternion &q);
/**get point for angle*/
cocos2d::Vec3 GetPointForAngle(float fAngleInRadians, float fLength) const;
/**set A and B's frame*/
virtual void setFrames(const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB);
/**get A's frame offset*/
cocos2d::Mat4 getFrameOffsetA() const;
/**get B's frame offset*/
cocos2d::Mat4 getFrameOffsetB() const;
CC_CONSTRUCTOR_ACCESS:
Physics3DConeTwistConstraint()
{
_type = ConstraintType::CONE_TWIST;
}
virtual ~Physics3DConeTwistConstraint(){}
};
/**
* This generic constraint can emulate a variety of standard constraints, by configuring each of the 6 degrees of freedom (dof).
* The first 3 dof axis are linear axis, which represent translation of rigidbodies, and the latter 3 dof axis represent the angular motion.
* Each axis can be either locked, free or limited. All axis are locked by default.
* For each axis:
* Lowerlimit == Upperlimit -> axis is locked.
* Lowerlimit > Upperlimit -> axis is free
* Lowerlimit < Upperlimit -> axis it limited in that range
*/
class CC_DLL Physics3D6DofConstraint : public Physics3DConstraint
{
public:
/**
* create 6 dof constraint
* @param rbA rigid body A
* @param rbB rigid body B
* @param frameInA frame in A's local space
* @param frameInB frame in B's local space
* @param useLinearReferenceFrameA use fixed frame A for linear limits
*/
static Physics3D6DofConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& frameInA, const cocos2d::Mat4& frameInB, bool useLinearReferenceFrameA);
/**
* create 6 dof constraint
* @param rbB rigid body B
* @param frameInB frame in B's local space
* @param useLinearReferenceFrameB use fixed frame B for linear limits
*/
static Physics3D6DofConstraint* create(Physics3DRigidBody* rbB, const cocos2d::Mat4& frameInB, bool useLinearReferenceFrameB);
/**set linear lower limit*/
void setLinearLowerLimit(const cocos2d::Vec3& linearLower);
/**get linear lower limit*/
cocos2d::Vec3 getLinearLowerLimit() const;
/**set linear upper limit*/
void setLinearUpperLimit(const cocos2d::Vec3& linearUpper);
/**get linear upper limit*/
cocos2d::Vec3 getLinearUpperLimit() const;
/**set angular lower limit*/
void setAngularLowerLimit(const cocos2d::Vec3& angularLower);
/**get angular lower limit*/
cocos2d::Vec3 getAngularLowerLimit() const;
/**set angular upper limit*/
void setAngularUpperLimit(const cocos2d::Vec3& angularUpper);
/**get angular upper limit*/
cocos2d::Vec3 getAngularUpperLimit() const;
/**
* is limited?
* @param limitIndex first 3 are linear, next 3 are angular
*/
bool isLimited(int limitIndex) const;
/** access for UseFrameOffset*/
bool getUseFrameOffset() const;
/**set use frame offset*/
void setUseFrameOffset(bool frameOffsetOnOff) const;
CC_CONSTRUCTOR_ACCESS:
Physics3D6DofConstraint()
{
_type = ConstraintType::SIX_DOF;
}
virtual ~Physics3D6DofConstraint(){}
};
// end of 3d group
/// @}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif // CC_USE_3D_PHYSICS
#endif // __PHYSICS_3D_CONSTRAINT_H__

View File

@ -0,0 +1,203 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 "CCPhysics3D.h"
#include "base/CCConfiguration.h"
#include "base/ccMacros.h"
#include "base/CCDirector.h"
#include "renderer/CCGLProgram.h"
#include "renderer/CCRenderer.h"
#include "renderer/ccGLStateCache.h"
#include "renderer/CCGLProgramCache.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
NS_CC_BEGIN
void Physics3DDebugDrawer::drawLine( const btVector3& from,const btVector3& to,const btVector3& color )
{
int count = 2;
ensureCapacity(count);
Vec3 col = convertbtVector3ToVec3(color);
V3F_V4F *lines = (V3F_V4F *)(_buffer + _bufferCount);
lines[0].vertex = convertbtVector3ToVec3(from);
lines[0].color = Vec4(col.x, col.y, col.z, 1.0f);
lines[1].vertex = convertbtVector3ToVec3(to);
lines[1].color = Vec4(col.x, col.y, col.z, 1.0f);
_bufferCount += count;
_dirty = true;
}
void Physics3DDebugDrawer::drawContactPoint( const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color )
{
drawLine(PointOnB, PointOnB + normalOnB * distance, color);
}
void Physics3DDebugDrawer::reportErrorWarning( const char* warningString )
{
CCLOG("%s", warningString);
}
void Physics3DDebugDrawer::draw3dText( const btVector3& location,const char* textString )
{
}
void Physics3DDebugDrawer::setDebugMode( int debugMode )
{
_debugMode = debugMode;
}
int Physics3DDebugDrawer::getDebugMode() const
{
return _debugMode;
}
void Physics3DDebugDrawer::draw( Renderer *renderer)
{
_customCommand.init(0, Mat4::IDENTITY, 0);
_customCommand.func = CC_CALLBACK_0(Physics3DDebugDrawer::drawImplementation, this, Mat4::IDENTITY, 0);
renderer->addCommand(&_customCommand);
}
Physics3DDebugDrawer::Physics3DDebugDrawer()
: _vao(0)
, _vbo(0)
, _bufferCapacity(0)
, _bufferCount(0)
, _buffer(nullptr)
, _blendFunc(BlendFunc::DISABLE)
, _dirty(true)
, _debugMode(DBG_DrawWireframe | DBG_DrawConstraints | DBG_DrawConstraintLimits)
{
init();
}
Physics3DDebugDrawer::~Physics3DDebugDrawer()
{
free(_buffer);
if (_vao)
{
glDeleteVertexArrays(1, &_vao);
_vao = 0;
}
if (_vbo)
{
glDeleteBuffers(1, &_vbo);
_vbo = 0;
}
}
void Physics3DDebugDrawer::ensureCapacity( int count )
{
CCASSERT(count>=0, "capacity must be >= 0");
if(_bufferCount + count > _bufferCapacity)
{
_bufferCapacity += MAX(_bufferCapacity, count);
_buffer = (V3F_V4F*)realloc(_buffer, _bufferCapacity*sizeof(V3F_V4F));
}
}
void Physics3DDebugDrawer::drawImplementation( const Mat4 &transform, uint32_t flags )
{
_program->use();
_program->setUniformsForBuiltins(transform);
glEnable(GL_DEPTH_TEST);
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
if (_dirty)
{
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_V4F) * _bufferCapacity, _buffer, GL_STREAM_DRAW);
_dirty = false;
}
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(_vao);
}
else
{
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
// vertex
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_V4F), (GLvoid *)offsetof(V3F_V4F, vertex));
// color
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(V3F_V4F), (GLvoid *)offsetof(V3F_V4F, color));
}
glDrawArrays(GL_LINES, 0, _bufferCount);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCount);
glDisable(GL_DEPTH_TEST);
}
void Physics3DDebugDrawer::init()
{
_program = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR);
ensureCapacity(512);
if (Configuration::getInstance()->supportsShareableVAO())
{
glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao);
}
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_V4F)* _bufferCapacity, _buffer, GL_STREAM_DRAW);
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_V4F), (GLvoid *)offsetof(V3F_V4F, vertex));
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(V3F_V4F), (GLvoid *)offsetof(V3F_V4F, color));
glBindBuffer(GL_ARRAY_BUFFER, 0);
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(0);
}
}
void Physics3DDebugDrawer::clear()
{
_bufferCount = 0;
}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif //CC_USE_3D_PHYSICS

View File

@ -0,0 +1,108 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 __PHYSICS_3D_VIEWER_H__
#define __PHYSICS_3D_VIEWER_H__
#include "math/CCMath.h"
#include "base/CCRef.h"
#include "base/ccTypes.h"
#include "base/ccConfig.h"
#include "renderer/CCCustomCommand.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
#include "renderer/CCCustomCommand.h"
#include "bullet/LinearMath/btIDebugDraw.h"
NS_CC_BEGIN
/**
* @addtogroup _3d
* @{
*/
class GLProgram;
class Renderer;
/** @brief Physics3DDebugDrawer: debug draw the physics object, used by Physics3DWorld */
class Physics3DDebugDrawer : public btIDebugDraw
{
public:
Physics3DDebugDrawer();
virtual ~Physics3DDebugDrawer();
void draw(cocos2d::Renderer *renderer);
// override function
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color) override;
virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color) override;
virtual void reportErrorWarning(const char* warningString) override;
virtual void draw3dText(const btVector3& location,const char* textString) override;
virtual void setDebugMode(int debugMode) override;
virtual int getDebugMode() const override;
void clear();
protected:
void init();
void ensureCapacity(int count);
void drawImplementation(const cocos2d::Mat4 &transform, uint32_t flags);
protected:
struct V3F_V4F
{
cocos2d::Vec3 vertex;
cocos2d::Vec4 color;
};
GLuint _vao;
GLuint _vbo;
int _bufferCapacity;
GLsizei _bufferCount;
V3F_V4F* _buffer;
cocos2d::BlendFunc _blendFunc;
cocos2d::CustomCommand _customCommand;
cocos2d::GLProgram *_program;
bool _dirty;
int _debugMode;
};
// end of 3d group
/// @}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif // CC_USE_3D_PHYSICS
#endif // __PHYSICS_3D_VIEWER_H__

View File

@ -0,0 +1,377 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 "CCPhysics3D.h"
#include "base/ccUTF8.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
#include "bullet/btBulletCollisionCommon.h"
#include "bullet/btBulletDynamicsCommon.h"
NS_CC_BEGIN
Physics3DRigidBody::Physics3DRigidBody()
: _btRigidBody(nullptr)
, _physics3DShape(nullptr)
{
}
Physics3DRigidBody::~Physics3DRigidBody()
{
if (_physicsWorld)
{
for(auto constraint : _constraintList)
{
_physicsWorld->removePhysics3DConstraint(constraint);
}
_constraintList.clear();
}
auto ms = _btRigidBody->getMotionState();
CC_SAFE_DELETE(ms);
CC_SAFE_DELETE(_btRigidBody);
CC_SAFE_RELEASE(_physics3DShape);
}
Physics3DRigidBody* Physics3DRigidBody::create(Physics3DRigidBodyDes* info)
{
auto ret = new (std::nothrow) Physics3DRigidBody();
if (ret->init(info))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return ret;
}
bool Physics3DRigidBody::init(Physics3DRigidBodyDes* info)
{
if (info->shape == nullptr)
return false;
btScalar mass = info->mass;
auto shape = info->shape->getbtShape();
auto localInertia = convertVec3TobtVector3(info->localInertia);
if (mass != 0.f)
{
shape->calculateLocalInertia(mass,localInertia);
}
auto transform = convertMat4TobtTransform(info->originalTransform);
btDefaultMotionState* myMotionState = new btDefaultMotionState(transform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia);
_btRigidBody = new btRigidBody(rbInfo);
_type = Physics3DObject::PhysicsObjType::RIGID_BODY;
_physics3DShape = info->shape;
_physics3DShape->retain();
if (info->disableSleep)
_btRigidBody->setActivationState(DISABLE_DEACTIVATION);
return true;
}
void Physics3DRigidBody::setActive(bool active)
{
if (_btRigidBody)
{
_btRigidBody->setActivationState(active ? ACTIVE_TAG : WANTS_DEACTIVATION);
}
}
void Physics3DRigidBody::applyForce( const cocos2d::Vec3& force, const cocos2d::Vec3& rel_pos )
{
_btRigidBody->applyForce(convertVec3TobtVector3(force), convertVec3TobtVector3(rel_pos));
}
void Physics3DRigidBody::setLinearVelocity( const cocos2d::Vec3& lin_vel )
{
_btRigidBody->setLinearVelocity(convertVec3TobtVector3(lin_vel));
}
void Physics3DRigidBody::applyCentralForce( const cocos2d::Vec3& force )
{
_btRigidBody->applyCentralForce(convertVec3TobtVector3(force));
}
void Physics3DRigidBody::applyCentralImpulse( const cocos2d::Vec3& impulse )
{
_btRigidBody->applyCentralImpulse(convertVec3TobtVector3(impulse));
}
void Physics3DRigidBody::applyTorque( const cocos2d::Vec3& torque )
{
_btRigidBody->applyTorque(convertVec3TobtVector3(torque));
}
void Physics3DRigidBody::applyTorqueImpulse( const cocos2d::Vec3& torque )
{
_btRigidBody->applyTorqueImpulse(convertVec3TobtVector3(torque));
}
void Physics3DRigidBody::applyImpulse( const cocos2d::Vec3& impulse, const cocos2d::Vec3& rel_pos )
{
_btRigidBody->applyImpulse(convertVec3TobtVector3(impulse), convertVec3TobtVector3(rel_pos));
}
void Physics3DRigidBody::applyDamping( float timeStep )
{
_btRigidBody->applyDamping(timeStep);
}
cocos2d::Vec3 Physics3DRigidBody::getLinearVelocity() const
{
return convertbtVector3ToVec3(_btRigidBody->getLinearVelocity());
}
void Physics3DRigidBody::setLinearFactor( const cocos2d::Vec3& linearFactor )
{
_btRigidBody->setLinearFactor(convertVec3TobtVector3(linearFactor));
}
cocos2d::Vec3 Physics3DRigidBody::getLinearFactor() const
{
return convertbtVector3ToVec3(_btRigidBody->getLinearFactor());
}
void Physics3DRigidBody::setAngularFactor( const cocos2d::Vec3& angFac )
{
_btRigidBody->setAngularFactor(convertVec3TobtVector3(angFac));
}
void Physics3DRigidBody::setAngularFactor( float angFac )
{
_btRigidBody->setAngularFactor(angFac);
}
cocos2d::Vec3 Physics3DRigidBody::getAngularFactor() const
{
return convertbtVector3ToVec3(_btRigidBody->getAngularFactor());
}
void Physics3DRigidBody::setAngularVelocity( const cocos2d::Vec3& ang_vel )
{
_btRigidBody->setAngularVelocity(convertVec3TobtVector3(ang_vel));
}
cocos2d::Vec3 Physics3DRigidBody::getAngularVelocity() const
{
return convertbtVector3ToVec3(_btRigidBody->getAngularVelocity());
}
void Physics3DRigidBody::setCenterOfMassTransform( const cocos2d::Mat4& xform )
{
_btRigidBody->setCenterOfMassTransform(convertMat4TobtTransform(xform));
}
cocos2d::Mat4 Physics3DRigidBody::getCenterOfMassTransform() const
{
return convertbtTransformToMat4(_btRigidBody->getCenterOfMassTransform());
}
void Physics3DRigidBody::setDamping( float lin_damping, float ang_damping )
{
_btRigidBody->setDamping(lin_damping, ang_damping);
}
float Physics3DRigidBody::getLinearDamping() const
{
return _btRigidBody->getLinearDamping();
}
float Physics3DRigidBody::getAngularDamping() const
{
return _btRigidBody->getAngularDamping();
}
void Physics3DRigidBody::setGravity( const cocos2d::Vec3& acceleration )
{
_btRigidBody->setGravity(convertVec3TobtVector3(acceleration));
}
cocos2d::Vec3 Physics3DRigidBody::getGravity() const
{
return convertbtVector3ToVec3(_btRigidBody->getGravity());
}
void Physics3DRigidBody::setInvInertiaDiagLocal( const cocos2d::Vec3& diagInvInertia )
{
_btRigidBody->setInvInertiaDiagLocal(convertVec3TobtVector3(diagInvInertia));
}
cocos2d::Vec3 Physics3DRigidBody::getInvInertiaDiagLocal() const
{
return convertbtVector3ToVec3(_btRigidBody->getInvInertiaDiagLocal());
}
void Physics3DRigidBody::setMassProps( float mass, const cocos2d::Vec3& inertia )
{
_btRigidBody->setMassProps(mass, convertVec3TobtVector3(inertia));
}
float Physics3DRigidBody::getInvMass() const
{
return _btRigidBody->getInvMass();
}
cocos2d::Vec3 Physics3DRigidBody::getTotalForce() const
{
return convertbtVector3ToVec3(_btRigidBody->getTotalForce());
}
cocos2d::Vec3 Physics3DRigidBody::getTotalTorque() const
{
return convertbtVector3ToVec3(_btRigidBody->getTotalTorque());
}
void Physics3DRigidBody::setRestitution( float rest )
{
_btRigidBody->setRestitution(rest);
}
float Physics3DRigidBody::getRestitution() const
{
return _btRigidBody->getRestitution();
}
void Physics3DRigidBody::setFriction( float frict )
{
_btRigidBody->setFriction(frict);
}
float Physics3DRigidBody::getFriction() const
{
return _btRigidBody->getFriction();
}
void Physics3DRigidBody::setRollingFriction( float frict )
{
_btRigidBody->setRollingFriction(frict);
}
float Physics3DRigidBody::getRollingFriction() const
{
return _btRigidBody->getRollingFriction();
}
void Physics3DRigidBody::setHitFraction( float hitFraction )
{
_btRigidBody->setHitFraction(hitFraction);
}
float Physics3DRigidBody::getHitFraction() const
{
return _btRigidBody->getHitFraction();
}
void Physics3DRigidBody::setCcdMotionThreshold( float ccdMotionThreshold )
{
_btRigidBody->setCcdMotionThreshold(ccdMotionThreshold);
}
float Physics3DRigidBody::getCcdMotionThreshold() const
{
return _btRigidBody->getCcdMotionThreshold();
}
void Physics3DRigidBody::setCcdSweptSphereRadius( float radius )
{
_btRigidBody->setCcdSweptSphereRadius(radius);
}
float Physics3DRigidBody::getCcdSweptSphereRadius() const
{
return _btRigidBody->getCcdSweptSphereRadius();
}
void Physics3DRigidBody::addConstraint( Physics3DConstraint *constraint )
{
auto iter = std::find(_constraintList.begin(), _constraintList.end(), constraint);
if (iter == _constraintList.end()){
_constraintList.push_back(constraint);
constraint->retain();
}
}
void Physics3DRigidBody::removeConstraint( Physics3DConstraint *constraint )
{
auto iter = std::find(_constraintList.begin(), _constraintList.end(), constraint);
if (iter != _constraintList.end()){
constraint->release();
_constraintList.erase(iter);
}
}
void Physics3DRigidBody::removeConstraint( unsigned int idx )
{
CCASSERT(idx < _constraintList.size(), "idx < _constraintList.size()");
removeConstraint(_constraintList[idx]);
}
Physics3DConstraint* Physics3DRigidBody::getConstraint( unsigned int idx ) const
{
CCASSERT(idx < _constraintList.size(), "idx < _constraintList.size()");
return _constraintList[idx];
}
unsigned int Physics3DRigidBody::getConstraintCount() const
{
return (unsigned int)_constraintList.size();
}
cocos2d::Mat4 Physics3DRigidBody::getWorldTransform() const
{
const auto& transform = _btRigidBody->getWorldTransform();
return convertbtTransformToMat4(transform);
}
void Physics3DRigidBody::setKinematic(bool kinematic)
{
if (kinematic)
{
_btRigidBody->setCollisionFlags(_btRigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
_btRigidBody->setActivationState(DISABLE_DEACTIVATION);
}
else
{
_btRigidBody->setCollisionFlags(_btRigidBody->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
_btRigidBody->setActivationState(ACTIVE_TAG);
}
}
bool Physics3DRigidBody::isKinematic() const
{
if (_btRigidBody)
return _btRigidBody->isKinematicObject();
return false;
}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif // CC_USE_3D_PHYSICS

View File

@ -0,0 +1,370 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 __PHYSICS_3D_OBJECT_H__
#define __PHYSICS_3D_OBJECT_H__
#include "math/CCMath.h"
#include "base/CCRef.h"
#include "base/ccConfig.h"
#include <vector>
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
class btCollisionShape;
class btRigidBody;
class btPersistentManifold;
NS_CC_BEGIN
/**
* @addtogroup _3d
* @{
*/
class Physics3DShape;
class Physics3DWorld;
class Physics3DConstraint;
class Physics3DObject;
/**
* @brief The collision information of Physics3DObject.
*/
struct CC_DLL Physics3DCollisionInfo
{
struct CollisionPoint
{
Vec3 localPositionOnA;
Vec3 worldPositionOnA;
Vec3 localPositionOnB;
Vec3 worldPositionOnB;
Vec3 worldNormalOnB;
};
Physics3DObject *objA;
Physics3DObject *objB;
std::vector<CollisionPoint> collisionPointList;
};
/**
* @brief Inherit from Ref, base class
*/
class CC_DLL Physics3DObject : public Ref
{
public:
typedef std::function<void(const Physics3DCollisionInfo &ci)> CollisionCallbackFunc;
enum class PhysicsObjType
{
UNKNOWN = 0,
RIGID_BODY,
};
/** Get the Physics3DObject Type. */
virtual PhysicsObjType getObjType() const { return _type; }
/** Set the user data. */
void setUserData(void* userData) { _userData = userData; }
/** Get the user data. */
void* getUserData() const { return _userData; }
/** Internal method. Set the pointer of Physics3DWorld. */
void setPhysicsWorld(Physics3DWorld* world) { _physicsWorld = world; };
/** Get the pointer of Physics3DWorld. */
Physics3DWorld* getPhysicsWorld() const { return _physicsWorld; }
/** Get the world matrix of Physics3DObject. */
virtual cocos2d::Mat4 getWorldTransform() const = 0;
/** Set the collision callback function. */
void setCollisionCallback(const CollisionCallbackFunc &func) { _collisionCallbackFunc = func; };
/** Get the collision callback function. */
const CollisionCallbackFunc& getCollisionCallback() const { return _collisionCallbackFunc; }
/** Check has collision callback function. */
bool needCollisionCallback() { return _collisionCallbackFunc != nullptr; };
/** Set the mask of Physics3DObject. */
void setMask(unsigned int mask) { _mask = mask; };
/** Get the mask of Physics3DObject. */
unsigned int getMask() const { return _mask; };
CC_CONSTRUCTOR_ACCESS:
Physics3DObject()
: _type(PhysicsObjType::UNKNOWN)
, _userData(nullptr)
, _isEnabled(true)
, _physicsWorld(nullptr)
, _mask(-1)
{
}
virtual ~Physics3DObject(){}
protected:
bool _isEnabled;
PhysicsObjType _type;
void* _userData;
Physics3DWorld* _physicsWorld;
CollisionCallbackFunc _collisionCallbackFunc;
unsigned int _mask;
};
/**
* @brief The description of Physics3DRigidBody.
*/
struct CC_DLL Physics3DRigidBodyDes
{
float mass; //Note: mass equals zero means static, default 0
cocos2d::Vec3 localInertia; //default (0, 0, 0)
Physics3DShape* shape;
cocos2d::Mat4 originalTransform;
bool disableSleep; //it is always active if disabled
Physics3DRigidBodyDes()
: mass(0.f)
, localInertia(0.f, 0.f, 0.f)
, shape(nullptr)
, disableSleep(false)
{
}
};
/**
* @brief Inherit from Physics3DObject, the main class for rigid body objects
*/
class CC_DLL Physics3DRigidBody : public Physics3DObject
{
friend class Physics3DWorld;
public:
/**
* Creates a Physics3DRigidBody with Physics3DRigidBody.
*
* @return An autoreleased Physics3DRigidBody object.
*/
static Physics3DRigidBody* create(Physics3DRigidBodyDes* info);
/** Get the pointer of btRigidBody. */
btRigidBody* getRigidBody() const { return _btRigidBody; }
/**
* Apply a force.
*
* @param force the value of the force
* @param rel_pos the position of the force
*/
void applyForce(const cocos2d::Vec3& force, const cocos2d::Vec3& rel_pos);
/**
* Apply a central force.
*
* @param force the value of the force
*/
void applyCentralForce(const cocos2d::Vec3& force);
/**
* Apply a central impulse.
*
* @param impulse the value of the impulse
*/
void applyCentralImpulse(const cocos2d::Vec3& impulse);
/**
* Apply a torque.
*
* @param torque the value of the torque
*/
void applyTorque(const cocos2d::Vec3& torque);
/**
* Apply a torque impulse.
*
* @param torque the value of the torque
*/
void applyTorqueImpulse(const cocos2d::Vec3& torque);
/**
* Apply a impulse.
*
* @param impulse the value of the impulse
* @param rel_pos the position of the impulse
*/
void applyImpulse(const cocos2d::Vec3& impulse, const cocos2d::Vec3& rel_pos);
/** Damps the velocity, using the given linearDamping and angularDamping. */
void applyDamping(float timeStep);
/** Set the linear velocity. */
void setLinearVelocity(const cocos2d::Vec3& lin_vel);
/** Get the linear velocity. */
cocos2d::Vec3 getLinearVelocity() const;
/** Set the linear factor. */
void setLinearFactor(const cocos2d::Vec3& linearFactor);
/** Get the linear factor. */
cocos2d::Vec3 getLinearFactor() const;
/** Set the angular factor. */
void setAngularFactor(const cocos2d::Vec3& angFac);
/** Set the angular factor, use unified factor. */
void setAngularFactor(float angFac);
/** Get the angular factor. */
cocos2d::Vec3 getAngularFactor() const;
/** Set the angular velocity. */
void setAngularVelocity(const cocos2d::Vec3& ang_vel);
/** Get the angular velocity. */
cocos2d::Vec3 getAngularVelocity() const;
/** Set the center of mass. */
void setCenterOfMassTransform(const cocos2d::Mat4& xform);
/** Get the center of mass. */
cocos2d::Mat4 getCenterOfMassTransform() const;
/** Set linear damping and angular damping. */
void setDamping(float lin_damping, float ang_damping);
/** Get linear damping. */
float getLinearDamping() const;
/** Get angular damping. */
float getAngularDamping() const;
/** Set the acceleration. */
void setGravity(const cocos2d::Vec3& acceleration);
/** Get the acceleration. */
cocos2d::Vec3 getGravity() const;
/** Set the inverse of local inertia. */
void setInvInertiaDiagLocal(const cocos2d::Vec3& diagInvInertia);
/** Get the inverse of local inertia. */
cocos2d::Vec3 getInvInertiaDiagLocal() const;
/** Set mass and inertia. */
void setMassProps(float mass, const cocos2d::Vec3& inertia);
/** Get inverse of mass. */
float getInvMass() const;
/** Get total force. */
cocos2d::Vec3 getTotalForce() const;
/** Get total torque. */
cocos2d::Vec3 getTotalTorque() const;
/** Set restitution. */
void setRestitution(float rest);
/** Get restitution. */
float getRestitution() const;
/** Set friction. */
void setFriction(float frict);
/** Get friction. */
float getFriction() const;
/** Set rolling friction. */
void setRollingFriction(float frict);
/** Get rolling friction. */
float getRollingFriction() const;
/** Set hit friction. */
void setHitFraction(float hitFraction);
/** Get hit friction. */
float getHitFraction() const;
/** Set motion threshold, don't do continuous collision detection if the motion (in one step) is less then ccdMotionThreshold */
void setCcdMotionThreshold(float ccdMotionThreshold);
/** Get motion threshold. */
float getCcdMotionThreshold() const;
/** Set swept sphere radius. */
void setCcdSweptSphereRadius(float radius);
/** Get swept sphere radius. */
float getCcdSweptSphereRadius() const;
/** Set kinematic object. */
void setKinematic(bool kinematic);
/** Check rigid body is kinematic object. */
bool isKinematic() const;
/** override. */
virtual cocos2d::Mat4 getWorldTransform() const override;
/** Get constraint by index. */
Physics3DConstraint* getConstraint(unsigned int idx) const;
/** Get the total number of constraints. */
unsigned int getConstraintCount() const;
/** Active or inactive. */
void setActive(bool active);
CC_CONSTRUCTOR_ACCESS:
Physics3DRigidBody();
virtual ~Physics3DRigidBody();
bool init(Physics3DRigidBodyDes* info);
void addConstraint(Physics3DConstraint *constraint);
void removeConstraint(Physics3DConstraint *constraint);
void removeConstraint(unsigned int idx);
protected:
btRigidBody* _btRigidBody;
Physics3DShape *_physics3DShape;
std::vector<Physics3DConstraint *> _constraintList;
};
// end of 3d group
/// @}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif //CC_USE_3D_PHYSICS
#endif // __PHYSICS_3D_OBJECT_H__

View File

@ -0,0 +1,208 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 "CCPhysics3D.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
#include "bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"
NS_CC_BEGIN
Physics3DShape::ShapeType Physics3DShape::getShapeType() const
{
return _shapeType;
}
Physics3DShape::Physics3DShape()
: _shapeType(ShapeType::UNKNOWN)
{
#if (CC_ENABLE_BULLET_INTEGRATION)
_btShape = nullptr;
_heightfieldData = nullptr;
#endif
}
Physics3DShape::~Physics3DShape()
{
#if (CC_ENABLE_BULLET_INTEGRATION)
CC_SAFE_DELETE(_btShape);
CC_SAFE_DELETE_ARRAY(_heightfieldData);
for (auto iter : _compoundChildShapes){
CC_SAFE_RELEASE(iter);
}
_compoundChildShapes.clear();
#endif
}
Physics3DShape* Physics3DShape::createBox(const cocos2d::Vec3& extent)
{
auto shape = new (std::nothrow) Physics3DShape();
shape->initBox(extent);
shape->autorelease();
return shape;
}
Physics3DShape* Physics3DShape::createSphere(float radius)
{
auto shape = new (std::nothrow) Physics3DShape();
shape->initSphere(radius);
shape->autorelease();
return shape;
}
Physics3DShape* Physics3DShape::createCylinder(float radius, float height)
{
auto shape = new (std::nothrow) Physics3DShape();
shape->initCylinder(radius, height);
shape->autorelease();
return shape;
}
Physics3DShape* Physics3DShape::createCapsule(float radius, float height)
{
auto shape = new (std::nothrow) Physics3DShape();
shape->initCapsule(radius, height);
shape->autorelease();
return shape;
}
Physics3DShape* Physics3DShape::createConvexHull( const cocos2d::Vec3 *points, int numPoints )
{
auto shape = new (std::nothrow) Physics3DShape();
shape->initConvexHull(points, numPoints);
shape->autorelease();
return shape;
}
Physics3DShape* Physics3DShape::createMesh( const cocos2d::Vec3 *triangles, int numTriangles )
{
auto shape = new (std::nothrow) Physics3DShape();
shape->initMesh(triangles, numTriangles);
shape->autorelease();
return shape;
}
Physics3DShape* Physics3DShape::createHeightfield( int heightStickWidth,int heightStickLength
, const void* heightfieldData, float heightScale
, float minHeight, float maxHeight
, bool useFloatDatam, bool flipQuadEdges
, bool useDiamondSubdivision)
{
auto shape = new (std::nothrow) Physics3DShape();
shape->initHeightfield(heightStickWidth, heightStickLength, heightfieldData, heightScale, minHeight, maxHeight, useFloatDatam, flipQuadEdges, useDiamondSubdivision);
shape->autorelease();
return shape;
}
Physics3DShape* Physics3DShape::createCompoundShape( const std::vector<std::pair<Physics3DShape *, Mat4>> &shapes )
{
auto shape = new (std::nothrow) Physics3DShape();
shape->initCompoundShape(shapes);
shape->autorelease();
return shape;
}
bool Physics3DShape::initBox(const cocos2d::Vec3& ext)
{
_shapeType = ShapeType::BOX;
_btShape = new btBoxShape(convertVec3TobtVector3(ext * 0.5f));
return true;
}
bool Physics3DShape::initSphere(float radius)
{
_shapeType = ShapeType::SPHERE;
_btShape = new btSphereShape(radius);
return true;
}
bool Physics3DShape::initCylinder(float radius, float height)
{
_shapeType = ShapeType::CYLINDER;
_btShape = new btCylinderShape(convertVec3TobtVector3(cocos2d::Vec3(radius, height, radius) * 0.5f));
return true;
}
bool Physics3DShape::initCapsule(float radius, float height)
{
_shapeType = ShapeType::CAPSULE;
_btShape = new btCapsuleShape(radius, height);
return true;
}
bool Physics3DShape::initConvexHull( const cocos2d::Vec3 *points, int numPoints )
{
_shapeType = ShapeType::CONVEX;
_btShape = new btConvexHullShape((btScalar *)points, numPoints, sizeof(cocos2d::Vec3));
return true;
}
bool Physics3DShape::initMesh( const cocos2d::Vec3 *triangles, int numTriangles )
{
_shapeType = ShapeType::MESH;
auto mesh = new btTriangleMesh(false);
for (int i = 0; i < numTriangles * 3; i += 3){
mesh->addTriangle(convertVec3TobtVector3(triangles[i]), convertVec3TobtVector3(triangles[i + 1]), convertVec3TobtVector3(triangles[i + 2]));
}
_btShape = new btBvhTriangleMeshShape(mesh, true);
return true;
}
bool Physics3DShape::initHeightfield( int heightStickWidth,int heightStickLength
, const void* heightfieldData, float heightScale
, float minHeight, float maxHeight
, bool useFloatDatam, bool flipQuadEdges
, bool useDiamondSubdivision)
{
_shapeType = ShapeType::HEIGHT_FIELD;
PHY_ScalarType type = PHY_UCHAR;
unsigned int dataSizeInByte = heightStickWidth * heightStickLength;
if (useFloatDatam){
type = PHY_FLOAT;
dataSizeInByte *= sizeof(float);
}
_heightfieldData = new unsigned char[dataSizeInByte];
memcpy(_heightfieldData, heightfieldData, dataSizeInByte);
auto heightfield = new btHeightfieldTerrainShape(heightStickWidth, heightStickLength, _heightfieldData, heightScale, minHeight, maxHeight, 1, type, flipQuadEdges);
heightfield->setUseDiamondSubdivision(useDiamondSubdivision);
_btShape = heightfield;
return true;
}
bool Physics3DShape::initCompoundShape( const std::vector<std::pair<Physics3DShape *, Mat4>> &shapes )
{
_shapeType = ShapeType::COMPOUND;
auto compound = new btCompoundShape;
for (auto iter : shapes){
compound->addChildShape(convertMat4TobtTransform(iter.second), iter.first->getbtShape());
CC_SAFE_RETAIN(iter.first);
_compoundChildShapes.push_back(iter.first);
}
_btShape = compound;
return true;
}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif // CC_USE_3D_PHYSICS

View File

@ -0,0 +1,169 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 __PHYSICS_3D_SHAPE_H__
#define __PHYSICS_3D_SHAPE_H__
#include "base/CCRef.h"
#include "base/ccConfig.h"
#include "math/CCMath.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
class btCollisionShape;
NS_CC_BEGIN
/**
* @addtogroup _3d
* @{
*/
/**
* @brief Create a physical shape(box, sphere, cylinder, capsule, convexhull, mesh and heightfield)
*/
class CC_DLL Physics3DShape : public Ref
{
public:
enum class ShapeType
{
UNKNOWN = 0,
BOX,
SPHERE,
CYLINDER,
CAPSULE,
CONVEX,
MESH,
HEIGHT_FIELD,
COMPOUND
};
/**
* get shape type
*/
virtual ShapeType getShapeType() const;
/**
* create box shape
* @param extent The extent of sphere.
*/
static Physics3DShape* createBox(const cocos2d::Vec3& extent);
/**
* create sphere shape
* @param radius The radius of sphere.
*/
static Physics3DShape* createSphere(float radius);
/**
* create cylinder shape
* @param radius The radius of cylinder.
* @param height The height.
*/
static Physics3DShape* createCylinder(float radius, float height);
/**
* create capsule shape
* @param radius The radius of casule.
* @param height The height (cylinder part).
*/
static Physics3DShape* createCapsule(float radius, float height);
/**
* create convex hull
* @param points The vertices of convex hull
* @param numPoints The number of vertices.
*/
static Physics3DShape* createConvexHull(const cocos2d::Vec3 *points, int numPoints);
/**
* create mesh
* @param triangles The pointer of triangle list
* @param numTriangles The number of triangles.
*/
static Physics3DShape* createMesh(const cocos2d::Vec3 *triangles, int numTriangles);
/**
* create heightfield
* @param heightStickWidth The Width of heightfield
* @param heightStickLength The Length of heightfield.
* @param heightfieldData The Data of heightfield.
* @param minHeight The minHeight of heightfield.
* @param maxHeight The maxHeight of heightfield.
* @param flipQuadEdges if flip QuadEdges
*/
static Physics3DShape* createHeightfield(int heightStickWidth,int heightStickLength
, const void* heightfieldData, float heightScale
, float minHeight, float maxHeight
, bool useFloatDatam, bool flipQuadEdges, bool useDiamondSubdivision = false);
/**
* create Compound Shape
* @param shapes The list of child shape
*/
static Physics3DShape* createCompoundShape(const std::vector<std::pair<Physics3DShape *, Mat4>> &shapes);
#if CC_ENABLE_BULLET_INTEGRATION
btCollisionShape* getbtShape() const { return _btShape; }
#endif
protected:
Physics3DShape();
~Physics3DShape();
bool initBox(const cocos2d::Vec3& ext);
bool initSphere(float radius);
bool initCylinder(float radius, float height);
bool initCapsule(float radius, float height);
bool initConvexHull(const cocos2d::Vec3 *points, int numPoints);
bool initMesh(const cocos2d::Vec3 *triangles, int numTriangles);
bool initHeightfield(int heightStickWidth,int heightStickLength
, const void* heightfieldData, float heightScale
, float minHeight, float maxHeight
, bool useFloatDatam, bool flipQuadEdges
, bool useDiamondSubdivision);
bool initCompoundShape(const std::vector<std::pair<Physics3DShape *, Mat4>> &shapes);
ShapeType _shapeType; //shape type
#if (CC_ENABLE_BULLET_INTEGRATION)
btCollisionShape* _btShape;
unsigned char *_heightfieldData;
std::vector<Physics3DShape *> _compoundChildShapes;
#endif
};
// end of 3d group
/// @}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif //CC_USE_3D_PHYSICS
#endif // __PHYSICS_3D_SHAPE_H__

View File

@ -0,0 +1,331 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 "CCPhysics3D.h"
#include "renderer/CCRenderer.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
NS_CC_BEGIN
Physics3DWorld::Physics3DWorld()
: _btPhyiscsWorld(nullptr)
, _collisionConfiguration(nullptr)
, _dispatcher(nullptr)
, _broadphase(nullptr)
, _solver(nullptr)
, _debugDrawer(nullptr)
, _needCollisionChecking(false)
, _collisionCheckingFlag(false)
{
}
Physics3DWorld::~Physics3DWorld()
{
removeAllPhysics3DConstraints();
removeAllPhysics3DObjects();
CC_SAFE_DELETE(_collisionConfiguration);
CC_SAFE_DELETE(_dispatcher);
CC_SAFE_DELETE(_broadphase);
CC_SAFE_DELETE(_solver);
CC_SAFE_DELETE(_btPhyiscsWorld);
CC_SAFE_DELETE(_debugDrawer);
for (auto it : _physicsComponents)
it->setPhysics3DObject(nullptr);
_physicsComponents.clear();
}
Physics3DWorld* Physics3DWorld::create(Physics3DWorldDes* info)
{
auto world = new (std::nothrow) Physics3DWorld();
world->init(info);
world->autorelease();
return world;
}
bool Physics3DWorld::init(Physics3DWorldDes* info)
{
///collision configuration contains default setup for memory, collision setup
_collisionConfiguration = new (std::nothrow) btDefaultCollisionConfiguration();
//_collisionConfiguration->setConvexConvexMultipointIterations();
///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
_dispatcher = new (std::nothrow) btCollisionDispatcher(_collisionConfiguration);
_broadphase = new (std::nothrow) btDbvtBroadphase();
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver();
_solver = sol;
_btPhyiscsWorld = new btDiscreteDynamicsWorld(_dispatcher,_broadphase,_solver,_collisionConfiguration);
_btPhyiscsWorld->setGravity(convertVec3TobtVector3(info->gravity));
if (info->isDebugDrawEnabled)
{
_debugDrawer = new (std::nothrow) Physics3DDebugDrawer();
_btPhyiscsWorld->setDebugDrawer(_debugDrawer);
}
return true;
}
void Physics3DWorld::setDebugDrawEnable(bool enableDebugDraw)
{
if (enableDebugDraw && _btPhyiscsWorld->getDebugDrawer() == nullptr)
{
_debugDrawer = new (std::nothrow) Physics3DDebugDrawer();
}
enableDebugDraw ? _btPhyiscsWorld->setDebugDrawer(_debugDrawer) : _btPhyiscsWorld->setDebugDrawer(nullptr);
}
bool Physics3DWorld::isDebugDrawEnabled() const
{
return _btPhyiscsWorld->getDebugDrawer() != nullptr;
}
void Physics3DWorld::addPhysics3DObject(Physics3DObject* physicsObj)
{
auto it = std::find(_objects.begin(), _objects.end(), physicsObj);
if (it == _objects.end())
{
_objects.push_back(physicsObj);
physicsObj->retain();
if (physicsObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
{
_btPhyiscsWorld->addRigidBody(static_cast<Physics3DRigidBody*>(physicsObj)->getRigidBody());
}
_collisionCheckingFlag = true;
}
}
void Physics3DWorld::removePhysics3DObject(Physics3DObject* physicsObj)
{
auto it = std::find(_objects.begin(), _objects.end(), physicsObj);
if (it != _objects.end())
{
if (physicsObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
{
_btPhyiscsWorld->removeRigidBody(static_cast<Physics3DRigidBody*>(physicsObj)->getRigidBody());
}
physicsObj->release();
_objects.erase(it);
_collisionCheckingFlag = true;
}
}
void Physics3DWorld::removeAllPhysics3DObjects()
{
for (auto it : _objects) {
if (it->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
{
_btPhyiscsWorld->removeRigidBody(static_cast<Physics3DRigidBody*>(it)->getRigidBody());
}
it->release();
}
_objects.clear();
_collisionCheckingFlag = true;
}
void Physics3DWorld::addPhysics3DConstraint(Physics3DConstraint* constraint, bool disableCollisionsBetweenLinkedObjs)
{
auto body = constraint->getBodyA();
if (body)
body->addConstraint(constraint);
body = constraint->getBodyB();
if (body)
{
body->addConstraint(constraint);
}
_btPhyiscsWorld->addConstraint(constraint->getbtContraint(), disableCollisionsBetweenLinkedObjs);
}
void Physics3DWorld::removePhysics3DConstraint(Physics3DConstraint* constraint)
{
_btPhyiscsWorld->removeConstraint(constraint->getbtContraint());
auto bodyA = constraint->getBodyA();
auto bodyB = constraint->getBodyB();
if (bodyA)
bodyA->removeConstraint(constraint);
if (bodyB)
bodyB->removeConstraint(constraint);
}
void Physics3DWorld::removeAllPhysics3DConstraints()
{
for(auto it : _objects)
{
auto type = it->getObjType();
if (type == Physics3DObject::PhysicsObjType::RIGID_BODY)
{
auto& constraints = static_cast<Physics3DRigidBody*>(it)->_constraintList;
for (auto constraint : constraints) {
_btPhyiscsWorld->removeConstraint(constraint->getbtContraint());
constraint->release();
}
constraints.clear();
}
}
}
void Physics3DWorld::stepSimulate(float dt)
{
if (_btPhyiscsWorld)
{
//should sync kinematic node before simulation
for (auto it : _physicsComponents)
{
it->preSimulate();
}
_btPhyiscsWorld->stepSimulation(dt, 3);
//sync dynamic node after simulation
for (auto it : _physicsComponents)
{
it->postSimulate();
}
if (needCollisionChecking())
collisionChecking();
}
}
void Physics3DWorld::debugDraw(Renderer* renderer)
{
if (_debugDrawer)
{
_debugDrawer->clear();
_btPhyiscsWorld->debugDrawWorld();
_debugDrawer->draw(renderer);
}
}
bool Physics3DWorld::rayCast(const cocos2d::Vec3& startPos, const cocos2d::Vec3& endPos, Physics3DWorld::HitResult* result)
{
auto btStart = convertVec3TobtVector3(startPos);
auto btEnd = convertVec3TobtVector3(endPos);
btCollisionWorld::ClosestRayResultCallback btResult(btStart, btEnd);
_btPhyiscsWorld->rayTest(btStart, btEnd, btResult);
if (btResult.hasHit())
{
result->hitObj = getPhysicsObject(btResult.m_collisionObject);
result->hitPosition = convertbtVector3ToVec3(btResult.m_hitPointWorld);
result->hitNormal = convertbtVector3ToVec3(btResult.m_hitNormalWorld);
return true;
}
result->hitObj = nullptr;
return false;
}
bool Physics3DWorld::sweepShape(Physics3DShape* shape, const cocos2d::Mat4& startTransform, const cocos2d::Mat4& endTransform, Physics3DWorld::HitResult* result)
{
CC_ASSERT(shape->getShapeType() != Physics3DShape::ShapeType::HEIGHT_FIELD && shape->getShapeType() != Physics3DShape::ShapeType::MESH);
auto btStart = convertMat4TobtTransform(startTransform);
auto btEnd = convertMat4TobtTransform(endTransform);
btCollisionWorld::ClosestConvexResultCallback btResult(btStart.getOrigin(), btEnd.getOrigin());
_btPhyiscsWorld->convexSweepTest((btConvexShape*)shape->getbtShape(), btStart, btEnd, btResult);
if (btResult.hasHit())
{
result->hitObj = getPhysicsObject(btResult.m_hitCollisionObject);
result->hitPosition = convertbtVector3ToVec3(btResult.m_hitPointWorld);
result->hitNormal = convertbtVector3ToVec3(btResult.m_hitNormalWorld);
return true;
}
result->hitObj = nullptr;
return false;
}
Physics3DObject* Physics3DWorld::getPhysicsObject(const btCollisionObject* btObj)
{
for(auto it : _objects)
{
if (it->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
{
if (static_cast<Physics3DRigidBody*>(it)->getRigidBody() == btObj)
return it;
}
}
return nullptr;
}
void Physics3DWorld::collisionChecking()
{
int numManifolds = _dispatcher->getNumManifolds();
for (int i = 0; i < numManifolds; ++i){
btPersistentManifold * contactManifold = _dispatcher->getManifoldByIndexInternal(i);
int numContacts = contactManifold->getNumContacts();
if (0 < numContacts){
const btCollisionObject* obA = static_cast<const btCollisionObject*>(contactManifold->getBody0());
const btCollisionObject* obB = static_cast<const btCollisionObject*>(contactManifold->getBody1());
Physics3DObject *poA = getPhysicsObject(obA);
Physics3DObject *poB = getPhysicsObject(obB);
if (poA->needCollisionCallback() || poB->needCollisionCallback()){
Physics3DCollisionInfo ci;
ci.objA = poA;
ci.objB = poB;
for (int c = 0; c < numContacts; ++c){
btManifoldPoint& pt = contactManifold->getContactPoint(c);
Physics3DCollisionInfo::CollisionPoint cp = {
convertbtVector3ToVec3(pt.m_localPointA), convertbtVector3ToVec3(pt.m_positionWorldOnA)
, convertbtVector3ToVec3(pt.m_localPointB), convertbtVector3ToVec3(pt.m_positionWorldOnB)
, convertbtVector3ToVec3(pt.m_normalWorldOnB)
};
ci.collisionPointList.push_back(cp);
}
if (poA->needCollisionCallback()){
poA->getCollisionCallback()(ci);
}
if (poB->needCollisionCallback()){
poB->getCollisionCallback()(ci);
}
}
}
}
}
bool Physics3DWorld::needCollisionChecking()
{
if (_collisionCheckingFlag){
_needCollisionChecking = false;
for(auto it : _objects)
{
if (it->getCollisionCallback() != nullptr){
_needCollisionChecking = true;
break;
}
}
_collisionCheckingFlag = false;
}
return _needCollisionChecking;
}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif //CC_USE_3D_PHYSICS

View File

@ -0,0 +1,173 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 __PHYSICS_3D_WORLD_H__
#define __PHYSICS_3D_WORLD_H__
#include "math/CCMath.h"
#include "base/CCRef.h"
#include "base/ccConfig.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
class btDynamicsWorld;
class btDefaultCollisionConfiguration;
class btCollisionDispatcher;
class btDbvtBroadphase;
class btSequentialImpulseConstraintSolver;
class btRigidBody;
class btCollisionObject;
NS_CC_BEGIN
/**
* @addtogroup _3d
* @{
*/
class Physics3DObject;
class Physics3DConstraint;
class Physics3DDebugDrawer;
class Physics3DComponent;
class Physics3DShape;
class Renderer;
/**
* @brief The description of Physics3DWorld.
*/
struct CC_DLL Physics3DWorldDes
{
bool isDebugDrawEnabled; //using physics debug draw?, false by default
cocos2d::Vec3 gravity;//gravity, (0, -9.8, 0)
Physics3DWorldDes()
{
isDebugDrawEnabled = false;
gravity = cocos2d::Vec3(0.f, -9.8f, 0.f);
}
};
/**
* @brief The physics information container, include Physics3DObjects, Physics3DConstraints, collision information and so on.
*/
class CC_DLL Physics3DWorld : public Ref
{
friend class Physics3DComponent;
public:
struct HitResult
{
cocos2d::Vec3 hitPosition;
cocos2d::Vec3 hitNormal;
Physics3DObject* hitObj;
};
/**
* Creates a Physics3DWorld with Physics3DWorldDes.
*
* @return An autoreleased Physics3DWorld object.
*/
static Physics3DWorld* create(Physics3DWorldDes* info);
/** Add a Physics3DObject. */
void addPhysics3DObject(Physics3DObject* physicsObj);
/** Remove a Physics3DObject. */
void removePhysics3DObject(Physics3DObject* physicsObj);
/** Remove all Physics3DObjects. */
void removeAllPhysics3DObjects();
/** Add a Physics3DConstraint. */
void addPhysics3DConstraint(Physics3DConstraint* constraint, bool disableCollisionsBetweenLinkedObjs = true);
/** Remove a Physics3DConstraint. */
void removePhysics3DConstraint(Physics3DConstraint* constraint);
/** Remove all Physics3DConstraint. */
void removeAllPhysics3DConstraints();
/** Simulate one frame. */
void stepSimulate(float dt);
/** Enable or disable debug drawing. */
void setDebugDrawEnable(bool enableDebugDraw);
/** Check debug drawing is enabled. */
bool isDebugDrawEnabled() const;
/** Internal method, the updater of debug drawing, need called each frame. */
void debugDraw(cocos2d::Renderer* renderer);
/** Get the list of Physics3DObjects. */
const std::vector<Physics3DObject*>& getPhysicsObjects() const { return _objects; }
/**
* Ray cast method
* @param startPos The start position of ray.
* @param endPos The end position of ray.
* @param result the result of ray cast.
*/
bool rayCast(const cocos2d::Vec3& startPos, const cocos2d::Vec3& endPos, HitResult* result);
/** Performs a swept shape cast on all objects in the Physics3DWorld. */
bool sweepShape(Physics3DShape* shape, const cocos2d::Mat4& startTransform, const cocos2d::Mat4& endTransform, HitResult* result);
CC_CONSTRUCTOR_ACCESS:
Physics3DWorld();
virtual ~Physics3DWorld();
bool init(Physics3DWorldDes* info);
Physics3DObject* getPhysicsObject(const btCollisionObject* btObj);
void collisionChecking();
bool needCollisionChecking();
protected:
std::vector<Physics3DObject*> _objects;
std::vector<Physics3DComponent*> _physicsComponents; //physics3d components
bool _needCollisionChecking;
bool _collisionCheckingFlag;
#if (CC_ENABLE_BULLET_INTEGRATION)
btDynamicsWorld* _btPhyiscsWorld;
btDefaultCollisionConfiguration* _collisionConfiguration;
btCollisionDispatcher* _dispatcher;
btDbvtBroadphase* _broadphase;
btSequentialImpulseConstraintSolver* _solver;
Physics3DDebugDrawer* _debugDrawer;
#endif // CC_ENABLE_BULLET_INTEGRATION
};
// end of 3d group
/// @}
NS_CC_END
#endif
#endif //CC_USE_3D_PHYSICS
#endif // __PHYSICS_3D_WORLD_H__

View File

@ -0,0 +1,86 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 "CCPhysics3D.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
NS_CC_BEGIN
PhysicsSprite3D* PhysicsSprite3D::create(const std::string &modelPath, Physics3DRigidBodyDes* rigidDes, const cocos2d::Vec3& translateInPhysics, const cocos2d::Quaternion& rotInPhsyics)
{
auto ret = new PhysicsSprite3D();
if (ret && ret->initWithFile(modelPath))
{
auto obj = Physics3DRigidBody::create(rigidDes);
ret->_physicsComponent = Physics3DComponent::create(obj);
ret->addComponent(ret->_physicsComponent);
ret->_contentSize = ret->getBoundingBox().size;
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return ret;
}
Physics3DObject* PhysicsSprite3D::getPhysicsObj() const
{
return _physicsComponent->getPhysics3DObject();
}
void PhysicsSprite3D::setSyncFlag(Physics3DComponent::PhysicsSyncFlag syncFlag)
{
if (_physicsComponent)
_physicsComponent->setSyncFlag(syncFlag);
}
void PhysicsSprite3D::syncToPhysics()
{
if (_physicsComponent)
_physicsComponent->syncToPhysics();
}
void PhysicsSprite3D::syncToNode()
{
if (_physicsComponent)
_physicsComponent->syncToNode();
}
PhysicsSprite3D::PhysicsSprite3D()
: _physicsComponent(nullptr)
{
}
PhysicsSprite3D::~PhysicsSprite3D()
{
}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif // CC_USE_3D_PHYSICS

View File

@ -0,0 +1,81 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
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 __PHYSICS_SPRITE_3D_H__
#define __PHYSICS_SPRITE_3D_H__
#include "base/ccConfig.h"
#include "3d/CCSprite3D.h"
#include "CCPhysics3DObject.h"
#include "CCPhysics3DComponent.h"
#if CC_USE_3D_PHYSICS
#if (CC_ENABLE_BULLET_INTEGRATION)
NS_CC_BEGIN
/**
* @addtogroup _3d
* @{
*/
/**
* @brief Convenient class to create a rigid body with Sprite3D
*/
class CC_DLL PhysicsSprite3D : public cocos2d::Sprite3D
{
public:
/** creates a PhysicsSprite3D*/
static PhysicsSprite3D* create(const std::string &modelPath, Physics3DRigidBodyDes* rigidDes, const cocos2d::Vec3& translateInPhysics = cocos2d::Vec3::ZERO, const cocos2d::Quaternion& rotInPhsyics = cocos2d::Quaternion::ZERO);
/** Get the Physics3DObject. */
Physics3DObject* getPhysicsObj() const;
/** Set synchronization flag, see Physics3DComponent. */
void setSyncFlag(Physics3DComponent::PhysicsSyncFlag syncFlag);
/** Physics synchronize rendering. */
void syncToPhysics();
/** Rendering synchronize physics. */
void syncToNode();
CC_CONSTRUCTOR_ACCESS:
PhysicsSprite3D();
virtual ~PhysicsSprite3D();
protected:
Physics3DComponent* _physicsComponent;
};
// end of 3d group
/// @}
NS_CC_END
#endif // CC_ENABLE_BULLET_INTEGRATION
#endif // CC_USE_3D_PHYSICS
#endif // __PHYSICS_SPRITE_3D_H__

View File

@ -0,0 +1,12 @@
set(COCOS_PHYSICS3D_SRC
physics3d/CCPhysics3D.cpp
physics3d/CCPhysics3DComponent.cpp
physics3d/CCPhysics3DConstraint.cpp
physics3d/CCPhysics3DDebugDrawer.cpp
physics3d/CCPhysics3DObject.cpp
physics3d/CCPhysics3DShape.cpp
physics3d/CCPhysics3DWorld.cpp
physics3d/CCPhysicsSprite3D.cpp
)

View File

@ -37,7 +37,7 @@ THE SOFTWARE.
#include "platform/android/CCApplication-android.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
#include "platform/win32/CCApplication-win32.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WP8
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#include "platform/winrt/CCApplication.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
#include "platform/linux/CCApplication-linux.h"

View File

@ -41,7 +41,7 @@ THE SOFTWARE.
#endif
#include <sys/stat.h>
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#include <regex>
#endif
@ -49,7 +49,7 @@ THE SOFTWARE.
#include <ftw.h>
#endif
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) && (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
#include <sys/types.h>
#include <errno.h>
#include <dirent.h>
@ -561,12 +561,13 @@ static Data getData(const std::string& filename, bool forString)
mode = "rt";
else
mode = "rb";
auto fileutils = FileUtils::getInstance();
do
{
// Read the file from hardware
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename);
FILE *fp = fopen(FileUtils::getInstance()->getSuitableFOpen(fullPath).c_str(), mode);
std::string fullPath = fileutils->fullPathForFilename(filename);
FILE *fp = fopen(fileutils->getSuitableFOpen(fullPath).c_str(), mode);
CC_BREAK_IF(!fp);
fseek(fp,0,SEEK_END);
size = ftell(fp);
@ -593,9 +594,7 @@ static Data getData(const std::string& filename, bool forString)
if (nullptr == buffer || 0 == readsize)
{
std::string msg = "Get data from file(";
msg.append(filename).append(") failed!");
CCLOG("%s", msg.c_str());
CCLOG("Get data from file %s failed", filename.c_str());
}
else
{
@ -982,7 +981,7 @@ bool FileUtils::isAbsolutePath(const std::string& path) const
bool FileUtils::isDirectoryExistInternal(const std::string& dirPath) const
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
WIN32_FILE_ATTRIBUTE_DATA wfad;
std::wstring wdirPath(dirPath.begin(), dirPath.end());
if (GetFileAttributesEx(wdirPath.c_str(), GetFileExInfoStandard, &wfad))
@ -1078,7 +1077,7 @@ bool FileUtils::createDirectory(const std::string& path)
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
WIN32_FILE_ATTRIBUTE_DATA wfad;
std::wstring wpath(path.begin(), path.end());
if (!(GetFileAttributesEx(wpath.c_str(), GetFileExInfoStandard, &wfad)))
@ -1172,7 +1171,7 @@ bool FileUtils::removeDirectory(const std::string& path)
// Remove downloaded files
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
std::wstring wpath = std::wstring(path.begin(), path.end());
std::wstring files = wpath + L"*.*";
WIN32_FIND_DATA wfd;
@ -1236,7 +1235,7 @@ bool FileUtils::removeFile(const std::string &path)
{
// Remove downloaded file
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
std::wstring wpath(path.begin(), path.end());
if (DeleteFile(wpath.c_str()))
{
@ -1276,7 +1275,7 @@ bool FileUtils::renameFile(const std::string &path, const std::string &oldname,
std::string newPath = path + name;
// Rename a file
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
std::regex pat("\\/");
std::string _old = std::regex_replace(oldPath, pat, "\\");
std::string _new = std::regex_replace(newPath, pat, "\\");
@ -1364,7 +1363,7 @@ bool FileUtils::isPopupNotify() const
return s_popupNotify;
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
static std::wstring StringUtf8ToWideChar(const std::string& strUtf8)
{
std::wstring ret;

View File

@ -37,7 +37,7 @@ THE SOFTWARE.
#include "platform/android/CCGL-android.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
#include "platform/win32/CCGL-win32.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#include "platform/winrt/CCGL.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
#include "platform/linux/CCGL-linux.h"

View File

@ -120,10 +120,6 @@ public:
* @param open Open or close IME keyboard.
*/
virtual void setIMEKeyboardState(bool open) = 0;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
virtual void setIMEKeyboardState(bool open, std::string str) = 0;
#endif
/** When the window is closed, it will return false if the platforms is Ios or Android.
* If the platforms is windows or Mac,it will return true.
@ -215,11 +211,6 @@ public:
virtual void* getEAGLView() const { return nullptr; }
#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) */
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
virtual Size getRenerTargetSize() const = 0;
virtual const Mat4& getOrientationMatrix() const = 0;
virtual const Mat4& getReverseOrientationMatrix() const = 0;
#endif
/**
* Get the visible area size of opengl viewport.
*

View File

@ -923,9 +923,9 @@ bool Image::encodeWithWIC(const std::string& filePath, bool isToRGB, GUID contai
bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)
{
#if defined(CC_USE_WIC)
#if CC_USE_WIC
return decodeWithWIC(data, dataLen);
#elif defined(CC_USE_JPEG)
#elif CC_USE_JPEG
/* these are standard libjpeg structures for reading(decompression) */
struct jpeg_decompress_struct cinfo;
/* We use our private extension JPEG error handler.
@ -1019,9 +1019,9 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)
bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen)
{
#if defined(CC_USE_WIC)
#if CC_USE_WIC
return decodeWithWIC(data, dataLen);
#elif defined(CC_USE_PNG)
#elif CC_USE_PNG
// length of bytes to check if it is a valid png file
#define PNGSIGSIZE 8
bool ret = false;
@ -1288,9 +1288,9 @@ namespace
bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen)
{
#if defined(CC_USE_WIC)
#if CC_USE_WIC
return decodeWithWIC(data, dataLen);
#elif defined(CC_USE_TIFF)
#elif CC_USE_TIFF
bool ret = false;
do
{
@ -2138,7 +2138,7 @@ bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen)
#if CC_USE_WEBP
bool ret = false;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
CCLOG("WEBP image format not supported on WinRT or WP8");
#else
do
@ -2173,7 +2173,7 @@ bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen)
ret = true;
} while (0);
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
return ret;
#else
CCLOG("webp is not enabled, please enable it in ccConfig.h");
@ -2253,9 +2253,9 @@ bool Image::saveToFile(const std::string& filename, bool isToRGB)
bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
{
#if defined(CC_USE_WIC)
#if CC_USE_WIC
return encodeWithWIC(filePath, isToRGB, GUID_ContainerFormatPng);
#elif defined(CC_USE_PNG)
#elif CC_USE_PNG
bool ret = false;
do
{
@ -2405,9 +2405,9 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
bool Image::saveImageToJPG(const std::string& filePath)
{
#if defined(CC_USE_WIC)
#if CC_USE_WIC
return encodeWithWIC(filePath, false, GUID_ContainerFormatJpeg);
#elif defined(CC_USE_JPEG)
#elif CC_USE_JPEG
bool ret = false;
do
{

View File

@ -51,8 +51,7 @@ THE SOFTWARE.
#define CC_PLATFORM_EMSCRIPTEN 10
#define CC_PLATFORM_TIZEN 11
#define CC_PLATFORM_QT5 12
#define CC_PLATFORM_WP8 13
#define CC_PLATFORM_WINRT 14
#define CC_PLATFORM_WINRT 13
// Determine target platform by compile environment macro.
#define CC_TARGET_PLATFORM CC_PLATFORM_UNKNOWN
@ -129,19 +128,12 @@ THE SOFTWARE.
#define CC_TARGET_PLATFORM CC_PLATFORM_QT5
#endif
// WinRT (Windows Store App)
// WinRT (Windows 8.1 Store/Phone App)
#if defined(WINRT)
#undef CC_TARGET_PLATFORM
#define CC_TARGET_PLATFORM CC_PLATFORM_WINRT
#endif
// WP8 (Windows Phone 8 App)
#if defined(WP8)
#undef CC_TARGET_PLATFORM
#define CC_TARGET_PLATFORM CC_PLATFORM_WP8
#endif
//////////////////////////////////////////////////////////////////////////
// post configure
//////////////////////////////////////////////////////////////////////////

View File

@ -37,7 +37,7 @@ THE SOFTWARE.
#include "platform/android/CCPlatformDefine-android.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
#include "platform/win32/CCPlatformDefine-win32.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#include "platform/winrt/CCPlatformDefine-winrt.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
#include "platform/linux/CCPlatformDefine-linux.h"

View File

@ -85,7 +85,7 @@ CC_DEPRECATED_ATTRIBUTE static __TYPE__* node() \
*
* @since v0.99.5
*/
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#define CC_ENABLE_CACHE_TEXTURE_DATA 1
#else
#define CC_ENABLE_CACHE_TEXTURE_DATA 0

View File

@ -36,7 +36,7 @@ THE SOFTWARE.
#include "platform/android/CCStdC-android.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
#include "platform/win32/CCStdC-win32.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#include "platform/winrt/CCStdC.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
#include "platform/linux/CCStdC-linux.h"

View File

@ -101,6 +101,15 @@ public class Cocos2dxLocalStorage {
}
}
public static void clear() {
try {
String sql = "delete from "+TABLE_NAME;
mDatabase.execSQL(sql);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* This creates/opens the database.

View File

@ -58,11 +58,16 @@ public class Cocos2dxWebView extends WebView {
class Cocos2dxWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String urlString) {
URI uri = URI.create(urlString);
if (uri != null && uri.getScheme().equals(mJSScheme)) {
Cocos2dxWebViewHelper._onJsCallback(mViewTag, urlString);
return true;
try {
URI uri = URI.create(urlString);
if (uri != null && uri.getScheme().equals(mJSScheme)) {
Cocos2dxWebViewHelper._onJsCallback(mViewTag, urlString);
return true;
}
} catch (Exception e) {
Log.d(TAG, "Failed to create URI from url");
}
return Cocos2dxWebViewHelper._shouldStartLoading(mViewTag, urlString);
}

View File

@ -49,14 +49,14 @@ using namespace cocos2d;
extern "C"
{
jint JNI_OnLoad(JavaVM *vm, void *reserved)
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
JniHelper::setJavaVM(vm);
return JNI_VERSION_1_4;
}
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
JNIEXPORT void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{
auto director = cocos2d::Director::getInstance();
auto glview = director->getOpenGLView();
@ -83,7 +83,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
}
}
jintArray Java_org_cocos2dx_lib_Cocos2dxActivity_getGLContextAttrs(JNIEnv* env, jobject thiz)
JNIEXPORT jintArray Java_org_cocos2dx_lib_Cocos2dxActivity_getGLContextAttrs(JNIEnv* env, jobject thiz)
{
cocos_android_app_init(env, thiz);
cocos2d::Application::getInstance()->initGLContextAttrs();
@ -99,7 +99,7 @@ jintArray Java_org_cocos2dx_lib_Cocos2dxActivity_getGLContextAttrs(JNIEnv* env,
return glContextAttrsJava;
}
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnSurfaceChanged(JNIEnv* env, jobject thiz, jint w, jint h)
JNIEXPORT void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnSurfaceChanged(JNIEnv* env, jobject thiz, jint w, jint h)
{
cocos2d::Application::getInstance()->applicationScreenSizeChanged(w, h);
}

View File

@ -22,11 +22,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CocosPlayClient.h"
#include "cocos2d.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include <map>
#include<unordered_map>
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "jni/JniHelper.h"
#include "platform/CCCommon.h"
#include "platform/CCFileUtils.h"
using namespace cocos2d;

Some files were not shown because too many files have changed in this diff Show More