Add PhysicsEffects to Extras. The build is only tested on Windows and Android.

The Android/NEON optimized version of Physics Effects is thanks to Graham Rhodes and Anthony Hamilton, See Issue 587
This commit is contained in:
erwin.coumans
2012-03-05 04:59:58 +00:00
parent 6cf8dfc202
commit a93a661b94
462 changed files with 86626 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 2.4)
#this line has to appear before 'PROJECT' in order to be able to disable incremental linking
SET(MSVC_INCREMENTAL_DEFAULT ON)
PROJECT(App_0_Console)
SET(App_0_Console_SRCS
main.cpp
physics_func.cpp
../common/perf_func.win32.cpp
)
SET(App_0_Console_HDRS
landscape.h
physics_func.h
)
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/include
)
#ADD_DEFINITIONS(-DUNICODE)
#ADD_DEFINITIONS(-D_UNICODE)
ADD_EXECUTABLE(App_0_Console
${App_0_Console_SRCS}
${App_0_Console_HDRS}
)
TARGET_LINK_LIBRARIES(App_0_Console
PfxLowLevel
PfxBaseLevel
PfxUtil
)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(App_0_Console PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_0_Console PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_0_Console PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF()

View File

@@ -0,0 +1,202 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define BarrelVtxCount 57
#define BarrelIdxCount 180
static float BarrelVtx[] = {
0.0f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
-0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
0.0f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
-0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.957307f,-0.289072f,0.0f,
0.404509f,0.0f,-0.293893f, 0.809017f,0.0f,-0.587785f,
0.5f,0.0f,0.0f, 1.0f,0.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.774478f,-0.289072f,-0.562691f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
-0.154509f,0.0f,-0.475528f, -0.309017f,0.0f,-0.951057f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
-0.107853f,-0.5f,-0.331936f, -0.295824f,-0.289072f,-0.910453f,
-0.404509f,0.0f,-0.293893f, -0.809017f,0.0f,-0.587785f,
-0.282362f,-0.5f,-0.205148f, -0.774478f,-0.289072f,-0.562691f,
-0.5f,0.0f,0.0f, -1.0f,0.0f,0.0f,
-0.349018f,-0.5f,0.0f, -0.957307f,-0.289072f,0.0f,
-0.404508f,0.0f,0.293893f, -0.809017f,0.0f,0.587785f,
-0.282362f,-0.5f,0.205148f, -0.774478f,-0.289072f,0.562691f,
-0.154509f,0.0f,0.475528f, -0.309017f,0.0f,0.951056f,
-0.107853f,-0.5f,0.331936f, -0.295824f,-0.289072f,0.910453f,
0.154509f,0.0f,0.475528f, 0.309017f,0.0f,0.951056f,
0.107853f,-0.5f,0.331936f, 0.295824f,-0.289072f,0.910453f,
0.404509f,0.0f,0.293892f, 0.809017f,0.0f,0.587785f,
0.282362f,-0.5f,0.205148f, 0.774478f,-0.289072f,0.562691f,
0.282362f,0.5f,-0.205148f, 0.774478f,0.289072f,-0.562691f,
0.349018f,0.5f,0.0f, 0.957307f,0.289072f,0.0f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.107853f,0.5f,-0.331936f, -0.295824f,0.289072f,-0.910453f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.282362f,0.5f,-0.205148f, -0.774478f,0.289072f,-0.562691f,
-0.349018f,0.5f,0.0f, -0.957307f,0.289072f,0.0f,
-0.282362f,0.5f,0.205148f, -0.774478f,0.289072f,0.562691f,
-0.107853f,0.5f,0.331936f, -0.295824f,0.289072f,0.910453f,
0.107853f,0.5f,0.331936f, 0.295824f,0.289072f,0.910453f,
0.282362f,0.5f,0.205148f, 0.774478f,0.289072f,0.562691f,
};
static float BarrelTex[] = {
0.0f,0.5f,
0.0f,0.85f,
0.0f,0.75f,
0.0f,0.95f,
0.0f,0.05f,
0.0f,-0.05f,
0.0f,0.15f,
0.0f,0.25f,
0.0f,0.35f,
0.0f,0.45f,
0.0f,0.55f,
0.0f,0.65f,
1.0f,0.5f,
1.0f,0.75f,
1.0f,0.85f,
1.0f,0.95f,
1.0f,-0.05f,
1.0f,0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
0.0f,0.75f,
0.5f,0.85f,
0.5f,0.75f,
0.0f,0.85f,
0.5f,0.95f,
0.0f,0.95f,
0.0f,-0.05f,
0.5f,0.05f,
0.5f,-0.05f,
0.0f,0.05f,
0.5f,0.15f,
0.0f,0.15f,
0.5f,0.25f,
0.0f,0.25f,
0.5f,0.35f,
0.0f,0.35f,
0.5f,0.45f,
0.0f,0.45f,
0.5f,0.55f,
0.0f,0.55f,
0.5f,0.65f,
0.0f,0.65f,
1.0f,0.85f,
1.0f,0.75f,
1.0f,0.95f,
1.0f,0.05f,
1.0f,-0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
};
static unsigned short BarrelIdx[] = {
0,1,2,
0,3,1,
0,4,5,
0,6,4,
0,7,6,
0,8,7,
0,9,8,
0,10,9,
0,11,10,
0,2,11,
12,13,14,
12,14,15,
12,16,17,
12,17,18,
12,18,19,
12,19,20,
12,20,21,
12,21,22,
12,22,23,
12,23,13,
24,25,26,
24,27,25,
27,28,25,
27,29,28,
30,31,32,
30,33,31,
33,34,31,
33,35,34,
35,36,34,
35,37,36,
37,38,36,
37,39,38,
39,40,38,
39,41,40,
41,42,40,
41,43,42,
43,44,42,
43,45,44,
45,26,44,
45,24,26,
26,46,47,
26,25,46,
25,48,46,
25,28,48,
32,49,50,
32,31,49,
31,51,49,
31,34,51,
34,52,51,
34,36,52,
36,53,52,
36,38,53,
38,54,53,
38,40,54,
40,55,54,
40,42,55,
42,56,55,
42,44,56,
44,47,56,
44,26,47,
};

View File

@@ -0,0 +1,318 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define LargeMeshVtxCount 81
#define LargeMeshIdxCount 384
static float LargeMeshVtx[] = {
-25.0f,-2.19407f,18.5625f, 0.232976f,0.967754f,0.0957829f,
-25.0f,0.0644502f,24.75f, 0.188094f,0.871343f,-0.45319f,
-18.75f,-4.50287f,18.5625f, -0.0716098f,0.995449f,0.0628767f,
-18.75f,-0.39999f,24.75f, -0.0602794f,0.895848f,-0.440253f,
-12.5f,-1.2166f,18.5625f, -0.269469f,0.961403f,0.0555879f,
-12.5f,-0.942431f,24.75f, -0.0997841f,0.993258f,0.0589987f,
-6.25f,1.93598f,18.5625f, -0.283933f,0.956351f,-0.0691025f,
-6.25f,-0.445954f,24.75f, -0.180725f,0.942766f,0.280233f,
0.0f,2.76983f,18.5625f, 0.171645f,0.984908f,0.0222501f,
0.0f,2.76642f,24.75f, 0.0784993f,0.995428f,-0.0544117f,
6.25f,-2.53736f,18.5625f, 0.248298f,0.965028f,0.0840741f,
6.25f,-0.915645f,24.75f, 0.164311f,0.945856f,-0.279926f,
12.5f,-1.60054f,18.5625f, -0.180435f,0.983586f,0.00115547f,
12.5f,0.831925f,24.75f, -0.0692495f,0.964821f,-0.253623f,
18.75f,-0.800282f,18.5625f, 0.10755f,0.951538f,0.288112f,
18.75f,-1.47284f,24.75f, 0.232178f,0.972664f,0.00429361f,
25.0f,-2.78379f,18.5625f, 0.1833f,0.937477f,0.295867f,
25.0f,-0.967508f,24.75f, -0.0773477f,0.956641f,-0.280812f,
-25.0f,-0.352038f,12.375f, -0.192222f,0.972435f,0.131987f,
-18.75f,0.681228f,12.375f, -0.107779f,0.962569f,0.248686f,
-12.5f,2.72065f,12.375f, 0.0520846f,0.993034f,0.105692f,
-6.25f,-1.78776f,12.375f, -0.0133223f,0.99674f,-0.0795754f,
0.0f,1.57707f,12.375f, -0.129025f,0.969662f,-0.207627f,
6.25f,0.424356f,12.375f, 0.180995f,0.97074f,0.157815f,
12.5f,0.283234f,12.375f, -0.16285f,0.973539f,0.160316f,
18.75f,2.57015f,12.375f, -0.165454f,0.978339f,0.124408f,
25.0f,3.07363f,12.375f, -0.00454559f,0.988151f,0.153417f,
-25.0f,-0.893751f,6.1875f, -0.0836251f,0.990084f,-0.112876f,
-18.75f,0.930932f,6.1875f, 0.00269413f,0.971838f,-0.235633f,
-12.5f,-0.684529f,6.1875f, -0.010319f,0.927048f,-0.3748f,
-6.25f,-0.661383f,6.1875f, 0.012265f,0.999875f,-0.00994222f,
0.0f,0.385718f,6.1875f, -0.15435f,0.984937f,-0.0779465f,
6.25f,0.589796f,6.1875f, 0.0241717f,0.999582f,-0.0158589f,
12.5f,0.47454f,6.1875f, -0.017184f,0.997953f,-0.0616073f,
18.75f,1.59939f,6.1875f, -0.0902706f,0.957309f,-0.274609f,
25.0f,1.13434f,6.1875f, 0.0346006f,0.957441f,-0.286547f,
-25.0f,0.74548f,0.0f, 0.329903f,0.930812f,0.157334f,
-18.75f,-2.47437f,0.0f, 0.247844f,0.968142f,0.0357041f,
-12.5f,-4.16309f,1.81975e-007f, -0.0623898f,0.997626f,-0.0291436f,
-6.25f,-0.700022f,0.0f, -0.217067f,0.974987f,-0.0477624f,
0.0f,-0.0957388f,0.0f, -0.117693f,0.990712f,-0.068098f,
6.25f,0.614077f,0.0f, -0.0713214f,0.997305f,0.01722f,
12.5f,0.299109f,0.0f, 0.218606f,0.968641f,0.118094f,
18.75f,-1.71753f,0.0f, 0.0339493f,0.985612f,-0.165579f,
25.0f,-1.12638f,0.0f, -0.0547573f,0.989177f,-0.136126f,
-25.0f,-0.403319f,-6.1875f, -0.1263f,0.989211f,-0.074223f,
-18.75f,-0.0730335f,-6.1875f, 0.0173428f,0.965382f,0.260261f,
-12.5f,-0.450125f,-6.1875f, 0.0658811f,0.875f,0.479619f,
-6.25f,-0.180204f,-6.1875f, 0.0116584f,0.981445f,0.19139f,
0.0f,-0.632679f,-6.1875f, -0.0557983f,0.993041f,-0.103716f,
6.25f,0.308409f,-6.1875f, -0.191898f,0.96766f,-0.163737f,
12.5f,2.5011f,-6.1875f, 0.0758397f,0.996403f,-0.0378189f,
18.75f,-1.69303f,-6.1875f, 0.16761f,0.974057f,0.15205f,
25.0f,-0.141349f,-6.1875f, -0.204846f,0.978471f,0.0251341f,
-25.0f,-1.10316f,-12.375f, -0.0350644f,0.993748f,-0.106001f,
-18.75f,1.06711f,-12.375f, -0.309806f,0.919244f,-0.242922f,
-12.5f,3.61544f,-12.375f, -0.0506281f,0.998702f,-0.00561657f,
-6.25f,1.6504f,-12.375f, 0.322294f,0.937465f,0.131477f,
0.0f,-1.60595f,-12.375f, 0.086016f,0.995916f,0.0274459f,
6.25f,-0.849859f,-12.375f, -0.0332811f,0.997087f,0.0686255f,
12.5f,-0.942201f,-12.375f, -0.153559f,0.982185f,-0.108312f,
18.75f,0.494873f,-12.375f, 0.0753195f,0.981472f,0.176181f,
25.0f,-0.333828f,-12.375f, 0.035057f,0.987194f,0.155624f,
-25.0f,2.1862f,-18.5625f, 0.612899f,0.782306f,0.111138f,
-18.75f,-3.38259f,-18.5625f, 0.0194078f,0.992789f,-0.118297f,
-12.5f,-0.880916f,-18.5625f, -0.282251f,0.949875f,-0.13443f,
-6.25f,0.818158f,-18.5625f, 0.1476f,0.981788f,-0.119612f,
0.0f,-1.48019f,-18.5625f, -0.044551f,0.996013f,-0.0772824f,
6.25f,1.47123f,-18.5625f, -0.117036f,0.97986f,0.161792f,
12.5f,0.164076f,-18.5625f, -0.0340355f,0.978993f,0.201034f,
18.75f,2.14568f,-18.5625f, -0.0439269f,0.994859f,0.0912435f,
25.0f,0.626506f,-18.5625f, 0.208015f,0.968592f,0.136229f,
-25.0f,0.296889f,-24.75f, 0.46973f,0.844327f,-0.257809f,
-18.75f,-3.18022f,-24.75f, -0.0226758f,0.998794f,-0.0435401f,
-12.5f,1.8927f,-24.75f, -0.202772f,0.919836f,0.335836f,
-6.25f,1.46387f,-24.75f, 0.224904f,0.955746f,0.189652f,
0.0f,-2.52726f,-24.75f, -0.0435882f,0.993572f,-0.10447f,
6.25f,1.30397f,-24.75f, -0.28646f,0.956525f,-0.0547707f,
12.5f,1.85812f,-24.75f, 0.0521949f,0.979796f,0.193067f,
18.75f,1.56331f,-24.75f, -0.0270784f,0.999629f,-0.00293115f,
25.0f,1.05366f,-24.75f, 0.161f,0.986887f,-0.0115473f,
};
static float LargeMeshTex[] = {
0.125f,0.0f,
0.0f,0.0f,
0.125f,0.125f,
0.0f,0.125f,
0.125f,0.25f,
0.0f,0.25f,
0.125f,0.375f,
0.0f,0.375f,
0.125f,0.5f,
0.0f,0.5f,
0.125f,0.625f,
0.0f,0.625f,
0.125f,0.75f,
0.0f,0.75f,
0.125f,0.875f,
0.0f,0.875f,
0.125f,1.0f,
0.0f,1.0f,
0.25f,0.0f,
0.25f,0.125f,
0.25f,0.25f,
0.25f,0.375f,
0.25f,0.5f,
0.25f,0.625f,
0.25f,0.75f,
0.25f,0.875f,
0.25f,1.0f,
0.375f,0.0f,
0.375f,0.125f,
0.375f,0.25f,
0.375f,0.375f,
0.375f,0.5f,
0.375f,0.625f,
0.375f,0.75f,
0.375f,0.875f,
0.375f,1.0f,
0.5f,0.0f,
0.5f,0.125f,
0.5f,0.25f,
0.5f,0.375f,
0.5f,0.5f,
0.5f,0.625f,
0.5f,0.75f,
0.5f,0.875f,
0.5f,1.0f,
0.625f,0.0f,
0.625f,0.125f,
0.625f,0.25f,
0.625f,0.375f,
0.625f,0.5f,
0.625f,0.625f,
0.625f,0.75f,
0.625f,0.875f,
0.625f,1.0f,
0.75f,0.0f,
0.75f,0.125f,
0.75f,0.25f,
0.75f,0.375f,
0.75f,0.5f,
0.75f,0.625f,
0.75f,0.75f,
0.75f,0.875f,
0.75f,1.0f,
0.875f,0.0f,
0.875f,0.125f,
0.875f,0.25f,
0.875f,0.375f,
0.875f,0.5f,
0.875f,0.625f,
0.875f,0.75f,
0.875f,0.875f,
0.875f,1.0f,
1.0f,0.0f,
1.0f,0.125f,
1.0f,0.25f,
1.0f,0.375f,
1.0f,0.5f,
1.0f,0.625f,
1.0f,0.75f,
1.0f,0.875f,
1.0f,1.0f,
};
static unsigned short LargeMeshIdx[] = {
0,1,2,
3,2,1,
2,3,4,
5,4,3,
4,5,6,
7,6,5,
6,7,8,
9,8,7,
8,9,10,
11,10,9,
10,11,12,
13,12,11,
12,13,14,
15,14,13,
14,15,16,
17,16,15,
18,0,19,
2,19,0,
19,2,20,
4,20,2,
20,4,21,
6,21,4,
21,6,22,
8,22,6,
22,8,23,
10,23,8,
23,10,24,
12,24,10,
24,12,25,
14,25,12,
25,14,26,
16,26,14,
27,18,28,
19,28,18,
28,19,29,
20,29,19,
29,20,30,
21,30,20,
30,21,31,
22,31,21,
31,22,32,
23,32,22,
32,23,33,
24,33,23,
33,24,34,
25,34,24,
34,25,35,
26,35,25,
36,27,37,
28,37,27,
37,28,38,
29,38,28,
38,29,39,
30,39,29,
39,30,40,
31,40,30,
40,31,41,
32,41,31,
41,32,42,
33,42,32,
42,33,43,
34,43,33,
43,34,44,
35,44,34,
45,36,46,
37,46,36,
46,37,47,
38,47,37,
47,38,48,
39,48,38,
48,39,49,
40,49,39,
49,40,50,
41,50,40,
50,41,51,
42,51,41,
51,42,52,
43,52,42,
52,43,53,
44,53,43,
54,45,55,
46,55,45,
55,46,56,
47,56,46,
56,47,57,
48,57,47,
57,48,58,
49,58,48,
58,49,59,
50,59,49,
59,50,60,
51,60,50,
60,51,61,
52,61,51,
61,52,62,
53,62,52,
63,54,64,
55,64,54,
64,55,65,
56,65,55,
65,56,66,
57,66,56,
66,57,67,
58,67,57,
67,58,68,
59,68,58,
68,59,69,
60,69,59,
69,60,70,
61,70,60,
70,61,71,
62,71,61,
72,63,73,
64,73,63,
73,64,74,
65,74,64,
74,65,75,
66,75,65,
75,66,76,
67,76,66,
76,67,77,
68,77,67,
77,68,78,
69,78,68,
78,69,79,
70,79,69,
79,70,80,
71,80,70,
};

View File

@@ -0,0 +1,44 @@
/*
Physics Effects Copyright(C) 2011 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "physics_effects.h"
#include "physics_func.h"
#include "../common/perf_func.h"
static int frameCount = 0;
static int sceneId = 2;
int main()
{
perf_init();
physics_init();
physics_create_scene(sceneId);
frameCount = 0;
//createScene();
while(frameCount<600) {
physics_simulate();
perf_sync();
}
SCE_PFX_PRINTF("program complete\n");
return 0;
}

View File

@@ -0,0 +1,861 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "physics_func.h"
#include "../common/perf_func.h"
///////////////////////////////////////////////////////////////////////////////
// Simulation Data
#define NUM_RIGIDBODIES 500
#define NUM_JOINTS 500
#define NUM_CONTACTS 4000
const float timeStep = 0.016f;
const float separateBias = 0.1f;
int iteration = 5;
//J ワールドサイズ
//E World size
PfxVector3 worldCenter(0.0f);
PfxVector3 worldExtent(500.0f);
//J 剛体
//E Rigid body
PfxRigidState states[NUM_RIGIDBODIES];
PfxRigidBody bodies[NUM_RIGIDBODIES];
PfxCollidable collidables[NUM_RIGIDBODIES];
PfxSolverBody solverBodies[NUM_RIGIDBODIES];
int numRigidBodies = 0;
//J 地形を表現するためのラージメッシュ
//E Large mesh for representing a landscape
#include "landscape.h"
PfxLargeTriMesh gLargeMesh;
//J 凸メッシュ
//E Convex Mesh
#include "barrel.h"
PfxConvexMesh gConvex;
//J プロキシ
//E Proxies
PfxBroadphaseProxy proxies[NUM_RIGIDBODIES];
//J ジョイント
//E Joint
PfxConstraintPair jointPairs[NUM_JOINTS];
PfxJoint joints[NUM_JOINTS];
int numJoints = 0;
//J ペア
//E Pairs
unsigned int pairSwap;
unsigned int numPairs[2];
PfxBroadphasePair pairsBuff[2][NUM_CONTACTS];
//J コンタクト
//E Contacts
PfxContactManifold contacts[NUM_CONTACTS];
int numContacts;
PfxUInt32 contactIdPool[NUM_CONTACTS];
int numContactIdPool;
//J 一時バッファ
//E Temporary buffers
#define POOL_BYTES (5*1024*1024)
unsigned char SCE_PFX_ALIGNED(128) poolBuff[POOL_BYTES];
//J 一時バッファ用スタックアロケータ
//E Stack allocator for temporary buffers
PfxHeapManager pool(poolBuff,POOL_BYTES);
///////////////////////////////////////////////////////////////////////////////
// Simulation Function
int frame = 0;
void broadphase()
{
pairSwap = 1-pairSwap;
unsigned int &numPreviousPairs = numPairs[1-pairSwap];
unsigned int &numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *previousPairs = pairsBuff[1-pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
//J 剛体が最も分散している軸を見つける
//E Find the axis along which all rigid bodies are most widely positioned
int axis = 0;
{
PfxVector3 s(0.0f),s2(0.0f);
for(int i=0;i<numRigidBodies;i++) {
PfxVector3 c = states[i].getPosition();
s += c;
s2 += mulPerElem(c,c);
}
PfxVector3 v = s2 - mulPerElem(s,s) / (float)numRigidBodies;
if(v[1] > v[0]) axis = 1;
if(v[2] > v[axis]) axis = 2;
}
//J ブロードフェーズプロキシの更新
//E Create broadpahse proxies
{
for(int i=0;i<numRigidBodies;i++) {
pfxUpdateBroadphaseProxy(proxies[i],states[i],collidables[i],worldCenter,worldExtent,axis);
}
int workBytes = sizeof(PfxBroadphaseProxy) * numRigidBodies;
void *workBuff = pool.allocate(workBytes);
pfxParallelSort(proxies,numRigidBodies,workBuff,workBytes);
pool.deallocate(workBuff);
}
//J 交差ペア探索
//E Find overlapped pairs
{
PfxFindPairsParam findPairsParam;
findPairsParam.pairBytes = pfxGetPairBytesOfFindPairs(NUM_CONTACTS);
findPairsParam.pairBuff = pool.allocate(findPairsParam.pairBytes);
findPairsParam.workBytes = pfxGetWorkBytesOfFindPairs(NUM_CONTACTS);
findPairsParam.workBuff = pool.allocate(findPairsParam.workBytes);
findPairsParam.proxies = proxies;
findPairsParam.numProxies = numRigidBodies;
findPairsParam.maxPairs = NUM_CONTACTS;
findPairsParam.axis = axis;
PfxFindPairsResult findPairsResult;
int ret = pfxFindPairs(findPairsParam,findPairsResult);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxFindPairs failed %d\n",ret);
pool.deallocate(findPairsParam.workBuff);
//J 交差ペア合成
//E Decompose overlapped pairs into 3 arrays
PfxDecomposePairsParam decomposePairsParam;
decomposePairsParam.pairBytes = pfxGetPairBytesOfDecomposePairs(numPreviousPairs,findPairsResult.numPairs);
decomposePairsParam.pairBuff = pool.allocate(decomposePairsParam.pairBytes);
decomposePairsParam.workBytes = pfxGetWorkBytesOfDecomposePairs(numPreviousPairs,findPairsResult.numPairs);
decomposePairsParam.workBuff = pool.allocate(decomposePairsParam.workBytes);
decomposePairsParam.previousPairs = previousPairs;
decomposePairsParam.numPreviousPairs = numPreviousPairs;
decomposePairsParam.currentPairs = findPairsResult.pairs; // Set pairs from pfxFindPairs()
decomposePairsParam.numCurrentPairs = findPairsResult.numPairs; // Set the number of pairs from pfxFindPairs()
PfxDecomposePairsResult decomposePairsResult;
ret = pfxDecomposePairs(decomposePairsParam,decomposePairsResult);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxDecomposePairs failed %d\n",ret);
pool.deallocate(decomposePairsParam.workBuff);
PfxBroadphasePair *outNewPairs = decomposePairsResult.outNewPairs;
PfxBroadphasePair *outKeepPairs = decomposePairsResult.outKeepPairs;
PfxBroadphasePair *outRemovePairs = decomposePairsResult.outRemovePairs;
PfxUInt32 numOutNewPairs = decomposePairsResult.numOutNewPairs;
PfxUInt32 numOutKeepPairs = decomposePairsResult.numOutKeepPairs;
PfxUInt32 numOutRemovePairs = decomposePairsResult.numOutRemovePairs;
//J 廃棄ペアのコンタクトをプールに戻す
//E Put removed contacts into the contact pool
for(PfxUInt32 i=0;i<numOutRemovePairs;i++) {
contactIdPool[numContactIdPool++] = pfxGetContactId(outRemovePairs[i]);
}
//J 新規ペアのコンタクトのリンクと初期化
//E Add new contacts and initialize
for(PfxUInt32 i=0;i<numOutNewPairs;i++) {
int cId = 0;
if(numContactIdPool > 0) {
cId = contactIdPool[--numContactIdPool];
}
else {
cId = numContacts++;
}
if(cId >= NUM_CONTACTS) {
cId = 0;
}
SCE_PFX_ASSERT(cId < NUM_CONTACTS);
pfxSetContactId(outNewPairs[i],cId);
PfxContactManifold &contact = contacts[cId];
contact.reset(pfxGetObjectIdA(outNewPairs[i]),pfxGetObjectIdB(outNewPairs[i]));
}
//J 新規ペアと維持ペアを合成
//E Merge 'new' and 'keep' pairs
numCurrentPairs = 0;
for(PfxUInt32 i=0;i<numOutKeepPairs;i++) {
currentPairs[numCurrentPairs++] = outKeepPairs[i];
}
for(PfxUInt32 i=0;i<numOutNewPairs;i++) {
currentPairs[numCurrentPairs++] = outNewPairs[i];
}
pool.deallocate(decomposePairsParam.pairBuff);
pool.deallocate(findPairsParam.pairBuff);
}
{
int workBytes = sizeof(PfxBroadphasePair) * numCurrentPairs;
void *workBuff = pool.allocate(workBytes);
pfxParallelSort(currentPairs,numCurrentPairs,workBuff,workBytes);
pool.deallocate(workBuff);
}
}
void collision()
{
unsigned int numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
//J 衝突検出
//E Detect collisions
{
PfxDetectCollisionParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetCollidables = collidables;
param.numRigidBodies = numRigidBodies;
int ret = pfxDetectCollision(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxDetectCollision failed %d\n",ret);
}
//J リフレッシュ
//E Refresh contacts
{
PfxRefreshContactsParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.numRigidBodies = numRigidBodies;
int ret = pfxRefreshContacts(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxRefreshContacts failed %d\n",ret);
}
}
void constraintSolver()
{
PfxPerfCounter pc;
unsigned int numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
pc.countBegin("setup solver bodies");
{
PfxSetupSolverBodiesParam param;
param.states = states;
param.bodies = bodies;
param.solverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
int ret = pfxSetupSolverBodies(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupSolverBodies failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup contact constraints");
{
PfxSetupContactConstraintsParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
param.separateBias = separateBias;
int ret = pfxSetupContactConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup joint constraints");
{
PfxSetupJointConstraintsParam param;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
for(int i=0;i<numJoints;i++) {
pfxUpdateJointPairs(jointPairs[i],i,joints[i],states[joints[i].m_rigidBodyIdA],states[joints[i].m_rigidBodyIdB]);
}
int ret = pfxSetupJointConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("solve constraints");
{
PfxSolveConstraintsParam param;
param.workBytes = pfxGetWorkBytesOfSolveConstraints(numRigidBodies,numCurrentPairs,numJoints);
param.workBuff = pool.allocate(param.workBytes);
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.iteration = iteration;
int ret = pfxSolveConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSolveConstraints failed %d\n",ret);
pool.deallocate(param.workBuff);
}
pc.countEnd();
//pc.printCount();
}
void integrate()
{
PfxUpdateRigidStatesParam param;
param.states = states;
param.bodies = bodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
pfxUpdateRigidStates(param);
}
void physics_simulate()
{
PfxPerfCounter pc;
for(int i=1;i<numRigidBodies;i++) {
pfxApplyExternalForce(states[i],bodies[i],bodies[i].getMass()*PfxVector3(0.0f,-9.8f,0.0f),PfxVector3(0.0f),timeStep);
}
perf_push_marker("broadphase");
pc.countBegin("broadphase");
broadphase();
pc.countEnd();
perf_pop_marker();
perf_push_marker("collision");
pc.countBegin("collision");
collision();
pc.countEnd();
perf_pop_marker();
perf_push_marker("solver");
pc.countBegin("solver");
constraintSolver();
pc.countEnd();
perf_pop_marker();
perf_push_marker("integrate");
pc.countBegin("integrate");
integrate();
pc.countEnd();
perf_pop_marker();
frame++;
if(frame%100 == 0) {
float broadphaseTime = pc.getCountTime(0);
float collisionTime = pc.getCountTime(2);
float solverTime = pc.getCountTime(4);
float integrateTime = pc.getCountTime(6);
SCE_PFX_PRINTF("frame %3d broadphase %.2f collision %.2f solver %.2f integrate %.2f | total %.2f\n",frame,
broadphaseTime,collisionTime,solverTime,integrateTime,
broadphaseTime+collisionTime+solverTime+integrateTime);
}
}
///////////////////////////////////////////////////////////////////////////////
// Create Scene
void createBrick(int id,const PfxVector3 &pos,const PfxQuat &rot,const PfxVector3 &boxSize,PfxFloat mass)
{
PfxBox box(boxSize);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setRestitution(0.0f);
bodies[id].setMass(mass);
bodies[id].setInertia(pfxCalcInertiaBox(boxSize,mass));
states[id].reset();
states[id].setPosition(pos);
states[id].setOrientation(rot);
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
void createWall(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
PfxFloat bodyMass = 0.5f;
PfxFloat diffX = boxSize[0] * 1.02f;
PfxFloat diffY = boxSize[1] * 1.02f;
PfxFloat diffZ = boxSize[2] * 1.02f;
PfxFloat offset = -stackSize * (diffZ * 2.0f) * 0.5f;
PfxVector3 pos(0.0f, diffY, 0.0f);
while(stackSize) {
for(int i=0;i<stackSize;i++) {
pos[2] = offset + (PfxFloat)i * (diffZ * 2.0f);
createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,bodyMass);
}
offset += diffZ;
pos[1] += (diffY * 2.0f);
stackSize--;
}
}
void createPyramid(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
PfxFloat space = 0.0001f;
PfxVector3 pos(0.0f, boxSize[1], 0.0f);
PfxFloat diffX = boxSize[0] * 1.02f;
PfxFloat diffY = boxSize[1] * 1.02f;
PfxFloat diffZ = boxSize[2] * 1.02f;
PfxFloat offsetX = -stackSize * (diffX * 2.0f + space) * 0.5f;
PfxFloat offsetZ = -stackSize * (diffZ * 2.0f + space) * 0.5f;
while(stackSize) {
for(int j=0;j<stackSize;j++) {
pos[2] = offsetZ + (PfxFloat)j * (diffZ * 2.0f + space);
for(int i=0;i<stackSize;i++) {
pos[0] = offsetX + (PfxFloat)i * (diffX * 2.0f + space);
createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,1.0f);
}
}
offsetX += diffX;
offsetZ += diffZ;
pos[1] += (diffY * 2.0f + space);
stackSize--;
}
}
void createTowerCircle(const PfxVector3 &offsetPosition,int stackSize,int rotSize,const PfxVector3 &boxSize)
{
PfxFloat radius = 1.3f * rotSize * boxSize[0] / SCE_PFX_PI;
// create active boxes
PfxQuat rotY = PfxQuat::identity();
PfxFloat posY = boxSize[1];
for(int i=0;i<stackSize;i++) {
for(int j=0;j<rotSize;j++) {
createBrick(numRigidBodies++,offsetPosition+rotate(rotY,PfxVector3(0.0f , posY, radius)),rotY,boxSize,0.5f);
rotY *= PfxQuat::rotationY(SCE_PFX_PI/(rotSize*0.5f));
}
posY += boxSize[1] * 2.0f;
rotY *= PfxQuat::rotationY(SCE_PFX_PI/(PfxFloat)rotSize);
}
}
void createScenePrimitives()
{
// sphere
{
int id = numRigidBodies++;
PfxSphere sphere(1.0f);
PfxShape shape;
shape.reset();
shape.setSphere(sphere);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(1.0f);
bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(-5.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// box
{
int id = numRigidBodies++;
PfxBox box(1.0f,1.0f,1.0f);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(1.0f);
bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(1.0f),1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,5.0f,5.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// capsule
{
int id = numRigidBodies++;
PfxCapsule capsule(1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setCapsule(capsule);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(2.0f);
bodies[id].setInertia(pfxCalcInertiaCylinderX(2.0f,0.5f,2.0f));
states[id].reset();
states[id].setPosition(PfxVector3(5.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// cylinder
{
int id = numRigidBodies++;
PfxCylinder cylinder(0.5f,1.5f);
PfxShape shape;
shape.reset();
shape.setCylinder(cylinder);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaCylinderX(0.5f,1.5f,3.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,10.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// convex mesh
{
PfxCreateConvexMeshParam param;
param.verts = BarrelVtx;
param.numVerts = BarrelVtxCount;
param.vertexStrideBytes = sizeof(float)*6;
param.triangles = BarrelIdx;
param.numTriangles = BarrelIdxCount/3;
param.triangleStrideBytes = sizeof(unsigned short)*3;
PfxInt32 ret = pfxCreateConvexMesh(gConvex,param);
if(ret != SCE_PFX_OK) {
SCE_PFX_PRINTF("Can't create gConvex mesh.\n");
}
int id = numRigidBodies++;
PfxShape shape;
shape.reset();
shape.setConvexMesh(&gConvex);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,15.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// combined primitives
{
int id = numRigidBodies++;
//E Both shapes and incides buffer have to be kept when creating a combined shape.
static PfxShape shapes[3];
PfxUInt16 shapeIds[3]={0,1,2};
collidables[id].reset(shapes,shapeIds,3);
{
PfxBox box(0.5f,0.5f,1.5f);
PfxShape shape;
shape.reset();
shape.setBox(box);
shape.setOffsetPosition(PfxVector3(-2.0f,0.0f,0.0f));
collidables[id].addShape(shape);
}
{
PfxBox box(0.5f,1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setBox(box);
shape.setOffsetPosition(PfxVector3(2.0f,0.0f,0.0f));
collidables[id].addShape(shape);
}
{
PfxCapsule cap(1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setCapsule(cap);
collidables[id].addShape(shape);
}
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(2.5f,1.0f,1.0f),3.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
}
void createSceneJoints()
{
const int n = 10;
int startId = numRigidBodies;
PfxVector3 boxSize(1.0f);
PfxFloat boxMass = 1.0f;
for(int i=0;i<n;i++) {
createBrick(numRigidBodies++,PfxVector3(0,3.0f+i*2.5f*boxSize[1],0),PfxQuat::identity(),boxSize,boxMass);
}
for(int i=startId;i<startId+n;i++) {
PfxRigidState &stateA = states[i];
PfxRigidState &stateB = states[(i+1)%numRigidBodies];
PfxVector3 anchor;
if(i == numRigidBodies-1) {
anchor = stateA.getPosition() + PfxVector3(0,boxSize[1],0);
}
else {
anchor = ( stateA.getPosition() + stateB.getPosition() ) * 0.5f;
}
PfxSwingTwistJointInitParam jparam;
jparam.anchorPoint = anchor;
jparam.twistAxis = PfxVector3(0,1,0);
pfxInitializeSwingTwistJoint(joints[numJoints],stateA,stateB,jparam);
joints[numJoints].m_constraints[4].m_damping = 0.1f;
joints[numJoints].m_constraints[5].m_damping = 0.1f;
pfxUpdateJointPairs(jointPairs[numJoints],numJoints,joints[numJoints],stateA,stateB);
SCE_PFX_ASSERT(numJoints<NUM_JOINTS);
numJoints++;
}
states[startId].setLinearVelocity(PfxVector3(0,0,5));
states[startId].setLinearDamping(0.95f);
states[startId].setAngularDamping(0.95f);
}
void createSceneStacking()
{
createTowerCircle(PfxVector3(0.0f,0.0f,0.0f),8,24,PfxVector3(1));
}
void createSceneBoxGround()
{
int id = numRigidBodies++;
PfxBox box(150.0f,2.5f,150.0f);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,-2.5f,0.0f));
states[id].setMotionType(kPfxMotionTypeFixed);
states[id].setRigidBodyId(id);
}
void createSceneLandscape()
{
PfxCreateLargeTriMeshParam param;
param.verts = LargeMeshVtx;
param.numVerts = LargeMeshVtxCount;
param.vertexStrideBytes = sizeof(float)*6;
param.triangles = LargeMeshIdx;
param.numTriangles = LargeMeshIdxCount/3;
param.triangleStrideBytes = sizeof(unsigned short)*3;
if(gLargeMesh.m_numIslands > 0) {
pfxReleaseLargeTriMesh(gLargeMesh);
}
PfxInt32 ret = pfxCreateLargeTriMesh(gLargeMesh,param);
if(ret != SCE_PFX_OK) {
SCE_PFX_PRINTF("Can't create large mesh.\n");
}
int id = numRigidBodies++;
PfxShape shape;
shape.reset();
shape.setLargeTriMesh(&gLargeMesh);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,-5.0f,0.0f));
states[id].setOrientation(PfxQuat::rotationX(0.5f)*PfxQuat::rotationY(0.7f));
states[id].setMotionType(kPfxMotionTypeFixed);
states[id].setRigidBodyId(id);
}
void physics_create_scene(int sceneId)
{
const int numScenes = 4;
int sid = sceneId % numScenes;
numRigidBodies= 0;
pairSwap = 0;
numPairs[0] = 0;
numPairs[1] = 0;
numContacts = 0;
numContactIdPool = 0;
numJoints = 0;
frame = 0;
switch(sid) {
case 0: // simple primitives
createSceneBoxGround();
createScenePrimitives();
break;
case 1: // joints
createSceneBoxGround();
createSceneJoints();
break;
case 2: // stacking
createSceneBoxGround();
createSceneStacking();
break;
case 3: // landscape
createSceneLandscape();
createScenePrimitives();
break;
}
SCE_PFX_PRINTF("----- Size of rigid body buffer ------\n");
SCE_PFX_PRINTF(" size * num = total\n");
SCE_PFX_PRINTF("PfxRigidState %5d * %5d = %5d bytes\n",sizeof(PfxRigidState),numRigidBodies,sizeof(PfxRigidState)*numRigidBodies);
SCE_PFX_PRINTF("PfxRigidBody %5d * %5d = %5d bytes\n",sizeof(PfxRigidBody),numRigidBodies,sizeof(PfxRigidBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxCollidable %5d * %5d = %5d bytes\n",sizeof(PfxCollidable),numRigidBodies,sizeof(PfxCollidable)*numRigidBodies);
SCE_PFX_PRINTF("PfxJoint %5d * %5d = %5d bytes\n",sizeof(PfxJoint),numJoints,sizeof(PfxJoint)*numJoints);
SCE_PFX_PRINTF("PfxSolverBody %5d * %5d = %5d bytes\n",sizeof(PfxSolverBody),numRigidBodies,sizeof(PfxSolverBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxBroadphaseProxy %5d * %5d = %5d bytes\n",sizeof(PfxBroadphaseProxy),numRigidBodies,sizeof(PfxBroadphaseProxy)*numRigidBodies);
SCE_PFX_PRINTF("PfxContactManifold %5d * %5d = %5d bytes\n",sizeof(PfxContactManifold),NUM_CONTACTS,sizeof(PfxContactManifold)*NUM_CONTACTS);
SCE_PFX_PRINTF("PfxBroadphasePair %5d * %5d = %5d bytes\n",sizeof(PfxBroadphasePair),NUM_CONTACTS,sizeof(PfxBroadphasePair)*NUM_CONTACTS);
int totalBytes =
(sizeof(PfxRigidState) + sizeof(PfxRigidBody) + sizeof(PfxCollidable) + sizeof(PfxSolverBody) + sizeof(PfxBroadphaseProxy)) * numRigidBodies +
(sizeof(PfxContactManifold) + sizeof(PfxBroadphasePair)) * NUM_CONTACTS;
SCE_PFX_PRINTF("----------------------------------------------------------\n");
SCE_PFX_PRINTF("Total %5d bytes\n",totalBytes);
}
///////////////////////////////////////////////////////////////////////////////
// Initialize / Finalize Engine
bool physics_init()
{
return true;
}
void physics_release()
{
}
///////////////////////////////////////////////////////////////////////////////
// Pick
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2)
{
return PfxVector3(0.0f);
}
void physics_pick_update(const PfxVector3 &p)
{
}
void physics_pick_end()
{
}
///////////////////////////////////////////////////////////////////////////////
// Get Information
int physics_get_num_rigidbodies()
{
return numRigidBodies;
}
const PfxRigidState& physics_get_state(int id)
{
return states[id];
}
const PfxRigidBody& physics_get_body(int id)
{
return bodies[id];
}
const PfxCollidable& physics_get_collidable(int id)
{
return collidables[id];
}
int physics_get_num_contacts()
{
return numPairs[pairSwap];
}
const PfxContactManifold &physics_get_contact(int id)
{
return contacts[pfxGetConstraintId(pairsBuff[pairSwap][id])];
}

View File

@@ -0,0 +1,49 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __PHYSICS_FUNC_H__
#define __PHYSICS_FUNC_H__
#define SCE_PFX_USE_PERFCOUNTER
#include "physics_effects.h"
using namespace sce::PhysicsEffects;
//E Simulation
//J シミュレーション
bool physics_init();
void physics_release();
void physics_create_scene(int sceneId);
void physics_simulate();
//E Picking
//J ピッキング
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2);
void physics_pick_update(const PfxVector3 &p);
void physics_pick_end();
//E Change parameters
//J パラメータの取得
int physics_get_num_rigidbodies();
const PfxRigidState& physics_get_state(int id);
const PfxRigidBody& physics_get_body(int id);
const PfxCollidable& physics_get_collidable(int id);
int physics_get_num_contacts();
const PfxContactManifold &physics_get_contact(int id);
#endif /* __PHYSICS_FUNC_H__ */

View File

@@ -0,0 +1,18 @@
project "0_console_sample"
kind "ConsoleApp"
targetdir "../../../bin"
includedirs {"../../../include"}
links {
"physicseffects2_lowlevel",
"physicseffects2_baselevel",
"physicseffects2_util"
}
files {
"main.cpp",
"physics_func.cpp",
"physics_func.h",
"../common/perf_func.win32.cpp"
}

View File

@@ -0,0 +1,713 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="1_simple.windows"
ProjectGUID="{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}"
RootNamespace="1_simple.win32"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Win32 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib "
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib "
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
>
<File
RelativePath=".\physics_func.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\physics_func.cpp"
>
</File>
</Filter>
<Filter
Name="Common"
>
<File
RelativePath="..\common\common.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\perf_func.h"
>
</File>
<File
RelativePath="..\common\perf_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\render_func.h"
>
</File>
<File
RelativePath="..\common\render_func.win32.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 2.4)
#this line has to appear before 'PROJECT' in order to be able to disable incremental linking
SET(MSVC_INCREMENTAL_DEFAULT ON)
PROJECT(App_1_Simple)
IF (NOT CMAKE_BUILD_TYPE)
# SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_BUILD_TYPE "Release")
ENDIF (NOT CMAKE_BUILD_TYPE)
OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" ON)
OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
ENDIF(COMMAND cmake_policy)
SET(App_1_Simple_SRCS
main.cpp
physics_func.cpp
../common/ctrl_func.win32.cpp
../common/perf_func.win32.cpp
../common/render_func.win32.cpp
)
SET(App_1_Simple_HDRS
physics_func.h
landscape.h
barrel.h
../common/render_func.h
../common/common.h
../common/ctrl_func.h
../common/perf_func.h
)
INCLUDE_DIRECTORIES(
${PHYSICS_EFFECTS_SOURCE_DIR}/include
# ${VECTOR_MATH_INCLUDE}
)
#LINK_DIRECTORIES(
#
#)
#ADD_DEFINITIONS(-DUNICODE)
#ADD_DEFINITIONS(-D_UNICODE)
ADD_EXECUTABLE(App_1_Simple WIN32
${App_1_Simple_SRCS}
${App_1_Simple_HDRS}
)
TARGET_LINK_LIBRARIES(App_1_Simple
PfxBaseLevel
PfxLowLevel
PfxUtil
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(App_1_Simple PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_1_Simple PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_1_Simple PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF()

View File

@@ -0,0 +1,202 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define BarrelVtxCount 57
#define BarrelIdxCount 180
static float BarrelVtx[] = {
0.0f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
-0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
0.0f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
-0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.957307f,-0.289072f,0.0f,
0.404509f,0.0f,-0.293893f, 0.809017f,0.0f,-0.587785f,
0.5f,0.0f,0.0f, 1.0f,0.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.774478f,-0.289072f,-0.562691f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
-0.154509f,0.0f,-0.475528f, -0.309017f,0.0f,-0.951057f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
-0.107853f,-0.5f,-0.331936f, -0.295824f,-0.289072f,-0.910453f,
-0.404509f,0.0f,-0.293893f, -0.809017f,0.0f,-0.587785f,
-0.282362f,-0.5f,-0.205148f, -0.774478f,-0.289072f,-0.562691f,
-0.5f,0.0f,0.0f, -1.0f,0.0f,0.0f,
-0.349018f,-0.5f,0.0f, -0.957307f,-0.289072f,0.0f,
-0.404508f,0.0f,0.293893f, -0.809017f,0.0f,0.587785f,
-0.282362f,-0.5f,0.205148f, -0.774478f,-0.289072f,0.562691f,
-0.154509f,0.0f,0.475528f, -0.309017f,0.0f,0.951056f,
-0.107853f,-0.5f,0.331936f, -0.295824f,-0.289072f,0.910453f,
0.154509f,0.0f,0.475528f, 0.309017f,0.0f,0.951056f,
0.107853f,-0.5f,0.331936f, 0.295824f,-0.289072f,0.910453f,
0.404509f,0.0f,0.293892f, 0.809017f,0.0f,0.587785f,
0.282362f,-0.5f,0.205148f, 0.774478f,-0.289072f,0.562691f,
0.282362f,0.5f,-0.205148f, 0.774478f,0.289072f,-0.562691f,
0.349018f,0.5f,0.0f, 0.957307f,0.289072f,0.0f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.107853f,0.5f,-0.331936f, -0.295824f,0.289072f,-0.910453f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.282362f,0.5f,-0.205148f, -0.774478f,0.289072f,-0.562691f,
-0.349018f,0.5f,0.0f, -0.957307f,0.289072f,0.0f,
-0.282362f,0.5f,0.205148f, -0.774478f,0.289072f,0.562691f,
-0.107853f,0.5f,0.331936f, -0.295824f,0.289072f,0.910453f,
0.107853f,0.5f,0.331936f, 0.295824f,0.289072f,0.910453f,
0.282362f,0.5f,0.205148f, 0.774478f,0.289072f,0.562691f,
};
static float BarrelTex[] = {
0.0f,0.5f,
0.0f,0.85f,
0.0f,0.75f,
0.0f,0.95f,
0.0f,0.05f,
0.0f,-0.05f,
0.0f,0.15f,
0.0f,0.25f,
0.0f,0.35f,
0.0f,0.45f,
0.0f,0.55f,
0.0f,0.65f,
1.0f,0.5f,
1.0f,0.75f,
1.0f,0.85f,
1.0f,0.95f,
1.0f,-0.05f,
1.0f,0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
0.0f,0.75f,
0.5f,0.85f,
0.5f,0.75f,
0.0f,0.85f,
0.5f,0.95f,
0.0f,0.95f,
0.0f,-0.05f,
0.5f,0.05f,
0.5f,-0.05f,
0.0f,0.05f,
0.5f,0.15f,
0.0f,0.15f,
0.5f,0.25f,
0.0f,0.25f,
0.5f,0.35f,
0.0f,0.35f,
0.5f,0.45f,
0.0f,0.45f,
0.5f,0.55f,
0.0f,0.55f,
0.5f,0.65f,
0.0f,0.65f,
1.0f,0.85f,
1.0f,0.75f,
1.0f,0.95f,
1.0f,0.05f,
1.0f,-0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
};
static unsigned short BarrelIdx[] = {
0,1,2,
0,3,1,
0,4,5,
0,6,4,
0,7,6,
0,8,7,
0,9,8,
0,10,9,
0,11,10,
0,2,11,
12,13,14,
12,14,15,
12,16,17,
12,17,18,
12,18,19,
12,19,20,
12,20,21,
12,21,22,
12,22,23,
12,23,13,
24,25,26,
24,27,25,
27,28,25,
27,29,28,
30,31,32,
30,33,31,
33,34,31,
33,35,34,
35,36,34,
35,37,36,
37,38,36,
37,39,38,
39,40,38,
39,41,40,
41,42,40,
41,43,42,
43,44,42,
43,45,44,
45,26,44,
45,24,26,
26,46,47,
26,25,46,
25,48,46,
25,28,48,
32,49,50,
32,31,49,
31,51,49,
31,34,51,
34,52,51,
34,36,52,
36,53,52,
36,38,53,
38,54,53,
38,40,54,
40,55,54,
40,42,55,
42,56,55,
42,44,56,
44,47,56,
44,26,47,
};

View File

@@ -0,0 +1,318 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define LargeMeshVtxCount 81
#define LargeMeshIdxCount 384
static float LargeMeshVtx[] = {
-25.0f,-2.19407f,18.5625f, 0.232976f,0.967754f,0.0957829f,
-25.0f,0.0644502f,24.75f, 0.188094f,0.871343f,-0.45319f,
-18.75f,-4.50287f,18.5625f, -0.0716098f,0.995449f,0.0628767f,
-18.75f,-0.39999f,24.75f, -0.0602794f,0.895848f,-0.440253f,
-12.5f,-1.2166f,18.5625f, -0.269469f,0.961403f,0.0555879f,
-12.5f,-0.942431f,24.75f, -0.0997841f,0.993258f,0.0589987f,
-6.25f,1.93598f,18.5625f, -0.283933f,0.956351f,-0.0691025f,
-6.25f,-0.445954f,24.75f, -0.180725f,0.942766f,0.280233f,
0.0f,2.76983f,18.5625f, 0.171645f,0.984908f,0.0222501f,
0.0f,2.76642f,24.75f, 0.0784993f,0.995428f,-0.0544117f,
6.25f,-2.53736f,18.5625f, 0.248298f,0.965028f,0.0840741f,
6.25f,-0.915645f,24.75f, 0.164311f,0.945856f,-0.279926f,
12.5f,-1.60054f,18.5625f, -0.180435f,0.983586f,0.00115547f,
12.5f,0.831925f,24.75f, -0.0692495f,0.964821f,-0.253623f,
18.75f,-0.800282f,18.5625f, 0.10755f,0.951538f,0.288112f,
18.75f,-1.47284f,24.75f, 0.232178f,0.972664f,0.00429361f,
25.0f,-2.78379f,18.5625f, 0.1833f,0.937477f,0.295867f,
25.0f,-0.967508f,24.75f, -0.0773477f,0.956641f,-0.280812f,
-25.0f,-0.352038f,12.375f, -0.192222f,0.972435f,0.131987f,
-18.75f,0.681228f,12.375f, -0.107779f,0.962569f,0.248686f,
-12.5f,2.72065f,12.375f, 0.0520846f,0.993034f,0.105692f,
-6.25f,-1.78776f,12.375f, -0.0133223f,0.99674f,-0.0795754f,
0.0f,1.57707f,12.375f, -0.129025f,0.969662f,-0.207627f,
6.25f,0.424356f,12.375f, 0.180995f,0.97074f,0.157815f,
12.5f,0.283234f,12.375f, -0.16285f,0.973539f,0.160316f,
18.75f,2.57015f,12.375f, -0.165454f,0.978339f,0.124408f,
25.0f,3.07363f,12.375f, -0.00454559f,0.988151f,0.153417f,
-25.0f,-0.893751f,6.1875f, -0.0836251f,0.990084f,-0.112876f,
-18.75f,0.930932f,6.1875f, 0.00269413f,0.971838f,-0.235633f,
-12.5f,-0.684529f,6.1875f, -0.010319f,0.927048f,-0.3748f,
-6.25f,-0.661383f,6.1875f, 0.012265f,0.999875f,-0.00994222f,
0.0f,0.385718f,6.1875f, -0.15435f,0.984937f,-0.0779465f,
6.25f,0.589796f,6.1875f, 0.0241717f,0.999582f,-0.0158589f,
12.5f,0.47454f,6.1875f, -0.017184f,0.997953f,-0.0616073f,
18.75f,1.59939f,6.1875f, -0.0902706f,0.957309f,-0.274609f,
25.0f,1.13434f,6.1875f, 0.0346006f,0.957441f,-0.286547f,
-25.0f,0.74548f,0.0f, 0.329903f,0.930812f,0.157334f,
-18.75f,-2.47437f,0.0f, 0.247844f,0.968142f,0.0357041f,
-12.5f,-4.16309f,1.81975e-007f, -0.0623898f,0.997626f,-0.0291436f,
-6.25f,-0.700022f,0.0f, -0.217067f,0.974987f,-0.0477624f,
0.0f,-0.0957388f,0.0f, -0.117693f,0.990712f,-0.068098f,
6.25f,0.614077f,0.0f, -0.0713214f,0.997305f,0.01722f,
12.5f,0.299109f,0.0f, 0.218606f,0.968641f,0.118094f,
18.75f,-1.71753f,0.0f, 0.0339493f,0.985612f,-0.165579f,
25.0f,-1.12638f,0.0f, -0.0547573f,0.989177f,-0.136126f,
-25.0f,-0.403319f,-6.1875f, -0.1263f,0.989211f,-0.074223f,
-18.75f,-0.0730335f,-6.1875f, 0.0173428f,0.965382f,0.260261f,
-12.5f,-0.450125f,-6.1875f, 0.0658811f,0.875f,0.479619f,
-6.25f,-0.180204f,-6.1875f, 0.0116584f,0.981445f,0.19139f,
0.0f,-0.632679f,-6.1875f, -0.0557983f,0.993041f,-0.103716f,
6.25f,0.308409f,-6.1875f, -0.191898f,0.96766f,-0.163737f,
12.5f,2.5011f,-6.1875f, 0.0758397f,0.996403f,-0.0378189f,
18.75f,-1.69303f,-6.1875f, 0.16761f,0.974057f,0.15205f,
25.0f,-0.141349f,-6.1875f, -0.204846f,0.978471f,0.0251341f,
-25.0f,-1.10316f,-12.375f, -0.0350644f,0.993748f,-0.106001f,
-18.75f,1.06711f,-12.375f, -0.309806f,0.919244f,-0.242922f,
-12.5f,3.61544f,-12.375f, -0.0506281f,0.998702f,-0.00561657f,
-6.25f,1.6504f,-12.375f, 0.322294f,0.937465f,0.131477f,
0.0f,-1.60595f,-12.375f, 0.086016f,0.995916f,0.0274459f,
6.25f,-0.849859f,-12.375f, -0.0332811f,0.997087f,0.0686255f,
12.5f,-0.942201f,-12.375f, -0.153559f,0.982185f,-0.108312f,
18.75f,0.494873f,-12.375f, 0.0753195f,0.981472f,0.176181f,
25.0f,-0.333828f,-12.375f, 0.035057f,0.987194f,0.155624f,
-25.0f,2.1862f,-18.5625f, 0.612899f,0.782306f,0.111138f,
-18.75f,-3.38259f,-18.5625f, 0.0194078f,0.992789f,-0.118297f,
-12.5f,-0.880916f,-18.5625f, -0.282251f,0.949875f,-0.13443f,
-6.25f,0.818158f,-18.5625f, 0.1476f,0.981788f,-0.119612f,
0.0f,-1.48019f,-18.5625f, -0.044551f,0.996013f,-0.0772824f,
6.25f,1.47123f,-18.5625f, -0.117036f,0.97986f,0.161792f,
12.5f,0.164076f,-18.5625f, -0.0340355f,0.978993f,0.201034f,
18.75f,2.14568f,-18.5625f, -0.0439269f,0.994859f,0.0912435f,
25.0f,0.626506f,-18.5625f, 0.208015f,0.968592f,0.136229f,
-25.0f,0.296889f,-24.75f, 0.46973f,0.844327f,-0.257809f,
-18.75f,-3.18022f,-24.75f, -0.0226758f,0.998794f,-0.0435401f,
-12.5f,1.8927f,-24.75f, -0.202772f,0.919836f,0.335836f,
-6.25f,1.46387f,-24.75f, 0.224904f,0.955746f,0.189652f,
0.0f,-2.52726f,-24.75f, -0.0435882f,0.993572f,-0.10447f,
6.25f,1.30397f,-24.75f, -0.28646f,0.956525f,-0.0547707f,
12.5f,1.85812f,-24.75f, 0.0521949f,0.979796f,0.193067f,
18.75f,1.56331f,-24.75f, -0.0270784f,0.999629f,-0.00293115f,
25.0f,1.05366f,-24.75f, 0.161f,0.986887f,-0.0115473f,
};
static float LargeMeshTex[] = {
0.125f,0.0f,
0.0f,0.0f,
0.125f,0.125f,
0.0f,0.125f,
0.125f,0.25f,
0.0f,0.25f,
0.125f,0.375f,
0.0f,0.375f,
0.125f,0.5f,
0.0f,0.5f,
0.125f,0.625f,
0.0f,0.625f,
0.125f,0.75f,
0.0f,0.75f,
0.125f,0.875f,
0.0f,0.875f,
0.125f,1.0f,
0.0f,1.0f,
0.25f,0.0f,
0.25f,0.125f,
0.25f,0.25f,
0.25f,0.375f,
0.25f,0.5f,
0.25f,0.625f,
0.25f,0.75f,
0.25f,0.875f,
0.25f,1.0f,
0.375f,0.0f,
0.375f,0.125f,
0.375f,0.25f,
0.375f,0.375f,
0.375f,0.5f,
0.375f,0.625f,
0.375f,0.75f,
0.375f,0.875f,
0.375f,1.0f,
0.5f,0.0f,
0.5f,0.125f,
0.5f,0.25f,
0.5f,0.375f,
0.5f,0.5f,
0.5f,0.625f,
0.5f,0.75f,
0.5f,0.875f,
0.5f,1.0f,
0.625f,0.0f,
0.625f,0.125f,
0.625f,0.25f,
0.625f,0.375f,
0.625f,0.5f,
0.625f,0.625f,
0.625f,0.75f,
0.625f,0.875f,
0.625f,1.0f,
0.75f,0.0f,
0.75f,0.125f,
0.75f,0.25f,
0.75f,0.375f,
0.75f,0.5f,
0.75f,0.625f,
0.75f,0.75f,
0.75f,0.875f,
0.75f,1.0f,
0.875f,0.0f,
0.875f,0.125f,
0.875f,0.25f,
0.875f,0.375f,
0.875f,0.5f,
0.875f,0.625f,
0.875f,0.75f,
0.875f,0.875f,
0.875f,1.0f,
1.0f,0.0f,
1.0f,0.125f,
1.0f,0.25f,
1.0f,0.375f,
1.0f,0.5f,
1.0f,0.625f,
1.0f,0.75f,
1.0f,0.875f,
1.0f,1.0f,
};
static unsigned short LargeMeshIdx[] = {
0,1,2,
3,2,1,
2,3,4,
5,4,3,
4,5,6,
7,6,5,
6,7,8,
9,8,7,
8,9,10,
11,10,9,
10,11,12,
13,12,11,
12,13,14,
15,14,13,
14,15,16,
17,16,15,
18,0,19,
2,19,0,
19,2,20,
4,20,2,
20,4,21,
6,21,4,
21,6,22,
8,22,6,
22,8,23,
10,23,8,
23,10,24,
12,24,10,
24,12,25,
14,25,12,
25,14,26,
16,26,14,
27,18,28,
19,28,18,
28,19,29,
20,29,19,
29,20,30,
21,30,20,
30,21,31,
22,31,21,
31,22,32,
23,32,22,
32,23,33,
24,33,23,
33,24,34,
25,34,24,
34,25,35,
26,35,25,
36,27,37,
28,37,27,
37,28,38,
29,38,28,
38,29,39,
30,39,29,
39,30,40,
31,40,30,
40,31,41,
32,41,31,
41,32,42,
33,42,32,
42,33,43,
34,43,33,
43,34,44,
35,44,34,
45,36,46,
37,46,36,
46,37,47,
38,47,37,
47,38,48,
39,48,38,
48,39,49,
40,49,39,
49,40,50,
41,50,40,
50,41,51,
42,51,41,
51,42,52,
43,52,42,
52,43,53,
44,53,43,
54,45,55,
46,55,45,
55,46,56,
47,56,46,
56,47,57,
48,57,47,
57,48,58,
49,58,48,
58,49,59,
50,59,49,
59,50,60,
51,60,50,
60,51,61,
52,61,51,
61,52,62,
53,62,52,
63,54,64,
55,64,54,
64,55,65,
56,65,55,
65,56,66,
57,66,56,
66,57,67,
58,67,57,
67,58,68,
59,68,58,
68,59,69,
60,69,59,
69,60,70,
61,70,60,
70,61,71,
62,71,61,
72,63,73,
64,73,63,
73,64,74,
65,74,64,
74,65,75,
66,75,65,
75,66,76,
67,76,66,
76,67,77,
68,77,67,
77,68,78,
69,78,68,
78,69,79,
70,79,69,
79,70,80,
71,80,70,
};

View File

@@ -0,0 +1,495 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "../common/common.h"
#include "../common/ctrl_func.h"
#include "../common/render_func.h"
#include "../common/perf_func.h"
#include "physics_func.h"
#include "barrel.h"
#include "landscape.h"
#ifdef _WIN32
#include <gl/gl.h>
#include <gl/glu.h>
#endif
// ARA begin insert new code
#ifdef __ANDROID__
#include <EGL/egl.h>
#include <GLES/gl.h>
#include <cpu-features.h> // used to check for presence of NEON on device
#ifdef __ARM_NEON__
#include <arm_neon.h>
#ifdef TEST_NEON_PERFORMANCE // define this to run NEON performance tests
#include "../../test_ARM_NEON_performance/test_neon.h"
#endif
#endif // __ARM_NEON__
#endif // __ANDROID__
// ARA end
#define SAMPLE_NAME "api_physics_effects/1_simple"
static bool s_isRunning = true;
int sceneId = 0;
bool simulating = false;
int landscapeMeshId;
int convexMeshId;
void render(void)
{
render_begin();
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxTransform3 rbT(state.getOrientation(), state.getPosition());
PfxShapeIterator itrShape(coll);
for(int j=0;j<coll.getNumShapes();j++,++itrShape) {
const PfxShape &shape = *itrShape;
PfxTransform3 offsetT = shape.getOffsetTransform();
PfxTransform3 worldT = rbT * offsetT;
switch(shape.getType()) {
case kPfxShapeSphere:
render_sphere(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getSphere().m_radius));
break;
case kPfxShapeBox:
render_box(
worldT,
PfxVector3(1,1,1),
shape.getBox().m_half);
break;
case kPfxShapeCapsule:
render_capsule(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getCapsule().m_radius),
PfxFloatInVec(shape.getCapsule().m_halfLen));
break;
case kPfxShapeCylinder:
render_cylinder(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getCylinder().m_radius),
PfxFloatInVec(shape.getCylinder().m_halfLen));
break;
case kPfxShapeConvexMesh:
render_mesh(
worldT,
PfxVector3(1,1,1),
convexMeshId);
break;
case kPfxShapeLargeTriMesh:
render_mesh(
worldT,
PfxVector3(1,1,1),
landscapeMeshId);
break;
default:
break;
}
}
}
render_end();
}
// ARA begin insert new code
#ifdef __ANDROID__
static void runNEONTests()
{
uint64_t features = android_getCpuFeatures();
if ((features & ANDROID_CPU_ARM_FEATURE_NEON) == 0)
{
SCE_PFX_PRINTF("CPU has NO support for NEON.");
}
else
{
SCE_PFX_PRINTF("CPU HAS support for NEON.\n");
#ifdef __ARM_NEON__
#ifdef TEST_NEON_PERFORMANCE
SCE_PFX_PRINTF("Running NEON performance tests...\n");
TestNeonDotProduct();
TestNeonCrossProduct();
TestNeonMatrix3OperatorMultiply();
TestNeonMatrix4OperatorMultiply();
TestNeonOrthoInverseTransform3();
TestNeonTransform3OperatorMultiply();
TestNeonTransposeMatrix3();
TestNeonSolveLinearConstraintRow();
SCE_PFX_PRINTF("Finished NEON performance tests.");
#endif // TEST_NEON_PERFORMANCE
#endif // __ARM_NEON__
}
}
#endif // __ANDROID__
// ARA end
int init(void)
{
// ARA begin insert new code
#ifdef __ANDROID__
runNEONTests();
#endif
// ARA end
perf_init();
ctrl_init();
render_init();
physics_init();
landscapeMeshId = render_init_mesh(
LargeMeshVtx,sizeof(float)*6,
LargeMeshVtx+3,sizeof(float)*6,
LargeMeshIdx,sizeof(unsigned short)*3,
LargeMeshVtxCount,LargeMeshIdxCount/3);
convexMeshId = render_init_mesh(
BarrelVtx,sizeof(float)*6,
BarrelVtx+3,sizeof(float)*6,
BarrelIdx,sizeof(unsigned short)*3,
BarrelVtxCount,BarrelIdxCount/3);
return 0;
}
static int shutdown(void)
{
ctrl_release();
render_release();
physics_release();
perf_release();
return 0;
}
void update(void)
{
float angX,angY,r;
render_get_view_angle(angX,angY,r);
ctrl_update();
if(ctrl_button_pressed(BTN_UP)) {
angX -= 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_DOWN)) {
angX += 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_LEFT)) {
angY -= 0.05f;
}
if(ctrl_button_pressed(BTN_RIGHT)) {
angY += 0.05f;
}
if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
r *= 1.1f;
if(r > 500.0f) r = 500.0f;
}
if(ctrl_button_pressed(BTN_ZOOM_IN)) {
r *= 0.9f;
if(r < 1.0f) r = 1.0f;
}
if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
physics_create_scene(sceneId);
}
if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
physics_create_scene(++sceneId);
}
if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
simulating = !simulating;
}
if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
simulating = true;
}
else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
simulating = false;
}
render_set_view_angle(angX,angY,r);
}
#ifndef _WIN32
// ARA begin insert new code
#ifdef __ANDROID__
///////////////////////////////////////////////////////////////////////////////
// sceneChange
//
/// This function is used to change the physics scene on Android devices
///////////////////////////////////////////////////////////////////////////////
void sceneChange()
{
physics_create_scene(sceneId++);
}
#else // __ANDROID__
// ARA end
///////////////////////////////////////////////////////////////////////////////
// Main
int main(void)
{
init();
physics_create_scene(sceneId);
printf("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
while (s_isRunning) {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
shutdown();
printf("## %s: FINISHED ##\n", SAMPLE_NAME);
return 0;
}
// ARA begin insert new code
#endif // __ANDROID__
// ARA end
#else // _WIN32
///////////////////////////////////////////////////////////////////////////////
// WinMain
extern HDC hDC;
extern HGLRC hRC;
HWND hWnd;
HINSTANCE hInstance;
void releaseWindow()
{
if(hRC) {
wglMakeCurrent(0,0);
wglDeleteContext(hRC);
}
if(hDC) ReleaseDC(hWnd,hDC);
if(hWnd) DestroyWindow(hWnd);
UnregisterClass(SAMPLE_NAME,hInstance);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg) {
case WM_SYSCOMMAND:
{
switch (wParam) {
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_SIZE:
render_resize(LOWORD(lParam),HIWORD(lParam));
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
bool createWindow(char* title, int width, int height)
{
WNDCLASS wc;
RECT rect;
rect.left=0;
rect.right=width;
rect.top=0;
rect.bottom=height;
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = SAMPLE_NAME;
if(!RegisterClass(&wc)) {
return false;
}
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
if(!(hWnd=CreateWindowEx(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,SAMPLE_NAME,title,
WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
0,0,rect.right-rect.left,rect.bottom-rect.top,
NULL,NULL,hInstance,NULL))) {
releaseWindow();
return false;
}
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0,
0, 0,
0, 0,
0, 0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if(!(hDC=GetDC(hWnd)))
{
releaseWindow();
OutputDebugString("");
return FALSE;
}
int pixelformat;
if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 ){
OutputDebugString("ChoosePixelFormat Failed....");
return FALSE;
}
if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE){
OutputDebugString("SetPixelFormat Failed....");
return FALSE;
}
if (!(hRC=wglCreateContext(hDC))){
OutputDebugString("Creating HGLRC Failed....");
return FALSE;
}
// Set Vsync
//BOOL (WINAPI *wglSwapIntervalEXT)(int) = NULL;
//if(strstr((char*)glGetString( GL_EXTENSIONS ),"WGL_EXT_swap_control")== 0) {
//}
//else {
//wglSwapIntervalEXT = (BOOL (WINAPI*)(int))wglGetProcAddress("wglSwapIntervalEXT");
//if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
//}
wglMakeCurrent(hDC,hRC);
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
render_resize(width, height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return 0;
}
init();
physics_create_scene(sceneId);
SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
MSG msg;
while(s_isRunning) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if(msg.message==WM_QUIT) {
s_isRunning = false;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
}
shutdown();
SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);
releaseWindow();
return (msg.wParam);
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -0,0 +1,769 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "physics_func.h"
#include "../common/perf_func.h"
///////////////////////////////////////////////////////////////////////////////
// Simulation Data
#define NUM_RIGIDBODIES 500
#define NUM_JOINTS 500
#define NUM_CONTACTS 4000
const float timeStep = 0.016f;
const float separateBias = 0.1f;
int iteration = 5;
//J ワールドサイズ
//E World size
PfxVector3 worldCenter(0.0f);
PfxVector3 worldExtent(500.0f);
//J 剛体
//E Rigid body
PfxRigidState states[NUM_RIGIDBODIES];
PfxRigidBody bodies[NUM_RIGIDBODIES];
PfxCollidable collidables[NUM_RIGIDBODIES];
PfxSolverBody solverBodies[NUM_RIGIDBODIES];
int numRigidBodies = 0;
//J 地形を表現するためのラージメッシュ
//E Large mesh for representing a landscape
#include "landscape.h"
PfxLargeTriMesh gLargeMesh;
//J 凸メッシュ
//E Convex Mesh
#include "barrel.h"
PfxConvexMesh gConvex;
//J プロキシ
//E Proxies
PfxBroadphaseProxy proxies[NUM_RIGIDBODIES];
//J ジョイント
//E Joint
PfxConstraintPair jointPairs[NUM_JOINTS];
PfxJoint joints[NUM_JOINTS];
int numJoints = 0;
//J ペア
//E Pairs
unsigned int numPairs;
PfxBroadphasePair pairs[NUM_CONTACTS];
//J コンタクト
//E Contacts
PfxContactManifold contacts[NUM_CONTACTS];
int numContacts;
//J 一時バッファ
//E Temporary buffers
#define POOL_BYTES (5*1024*1024)
unsigned char SCE_PFX_ALIGNED(128) poolBuff[POOL_BYTES];
//J 一時バッファ用スタックアロケータ
//E Stack allocator for temporary buffers
PfxHeapManager pool(poolBuff,POOL_BYTES);
///////////////////////////////////////////////////////////////////////////////
// Simulation Function
int frame = 0;
void broadphase()
{
//J 剛体が最も分散している軸を見つける
//E Find the axis along which all rigid bodies are most widely positioned
int axis = 0;
{
PfxVector3 s(0.0f),s2(0.0f);
for(int i=0;i<numRigidBodies;i++) {
PfxVector3 c = states[i].getPosition();
s += c;
s2 += mulPerElem(c,c);
}
PfxVector3 v = s2 - mulPerElem(s,s) / (float)numRigidBodies;
if(v[1] > v[0]) axis = 1;
if(v[2] > v[axis]) axis = 2;
}
//J ブロードフェーズプロキシの更新
//E Create broadpahse proxies
{
for(int i=0;i<numRigidBodies;i++) {
pfxUpdateBroadphaseProxy(proxies[i],states[i],collidables[i],worldCenter,worldExtent,axis);
}
int workBytes = sizeof(PfxBroadphaseProxy) * numRigidBodies;
void *workBuff = pool.allocate(workBytes);
pfxParallelSort(proxies,numRigidBodies,workBuff,workBytes);
pool.deallocate(workBuff);
}
//J 交差ペア探索
//E Find overlapped pairs
{
PfxFindPairsParam param;
param.workBytes = pfxGetWorkBytesOfFindPairs(NUM_CONTACTS);
param.workBuff = pool.allocate(param.workBytes);
param.pairBytes = pfxGetPairBytesOfFindPairs(NUM_CONTACTS);
param.pairBuff = pool.allocate(param.pairBytes);
param.proxies = proxies;
param.numProxies = numRigidBodies;
param.maxPairs = NUM_CONTACTS;
param.axis = axis;
PfxFindPairsResult result;
int ret = pfxFindPairs(param,result);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxFindPairs failed %d\n",ret);
memcpy(pairs,result.pairs,sizeof(PfxBroadphasePair)*result.numPairs);
numPairs = result.numPairs;
pool.deallocate(param.pairBuff);
pool.deallocate(param.workBuff);
}
//J 新規ペアのコンタクトを初期化
//E Add new contacts and initialize
for(PfxUInt32 i=0;i<numPairs;i++) {
pfxSetContactId(pairs[i],i);
PfxContactManifold &contact = contacts[i];
contact.reset(pfxGetObjectIdA(pairs[i]),pfxGetObjectIdB(pairs[i]));
}
numContacts = numPairs;
}
void collision()
{
//J 衝突検出
//E Detect collisions
{
PfxDetectCollisionParam param;
param.contactPairs = pairs;
param.numContactPairs = numPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetCollidables = collidables;
param.numRigidBodies = numRigidBodies;
int ret = pfxDetectCollision(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxDetectCollision failed %d\n",ret);
}
}
void constraintSolver()
{
PfxPerfCounter pc;
pc.countBegin("setup solver bodies");
{
PfxSetupSolverBodiesParam param;
param.states = states;
param.bodies = bodies;
param.solverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
int ret = pfxSetupSolverBodies(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupSolverBodies failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup contact constraints");
{
PfxSetupContactConstraintsParam param;
param.contactPairs = pairs;
param.numContactPairs = numPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
param.separateBias = separateBias;
int ret = pfxSetupContactConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup joint constraints");
{
PfxSetupJointConstraintsParam param;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
for(int i=0;i<numJoints;i++) {
pfxUpdateJointPairs(jointPairs[i],i,joints[i],states[joints[i].m_rigidBodyIdA],states[joints[i].m_rigidBodyIdB]);
}
int ret = pfxSetupJointConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("solve constraints");
{
PfxSolveConstraintsParam param;
param.workBytes = pfxGetWorkBytesOfSolveConstraints(numRigidBodies,numPairs,numJoints);
param.workBuff = pool.allocate(param.workBytes);
param.contactPairs = pairs;
param.numContactPairs = numPairs;
param.offsetContactManifolds = contacts;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.iteration = iteration;
int ret = pfxSolveConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSolveConstraints failed %d\n",ret);
pool.deallocate(param.workBuff);
}
pc.countEnd();
//pc.printCount();
}
void integrate()
{
PfxUpdateRigidStatesParam param;
param.states = states;
param.bodies = bodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
pfxUpdateRigidStates(param);
}
void physics_simulate()
{
PfxPerfCounter pc;
for(int i=1;i<numRigidBodies;i++) {
pfxApplyExternalForce(states[i],bodies[i],bodies[i].getMass()*PfxVector3(0.0f,-9.8f,0.0f),PfxVector3(0.0f),timeStep);
}
perf_push_marker("broadphase");
pc.countBegin("broadphase");
broadphase();
pc.countEnd();
perf_pop_marker();
perf_push_marker("collision");
pc.countBegin("collision");
collision();
pc.countEnd();
perf_pop_marker();
perf_push_marker("solver");
pc.countBegin("solver");
constraintSolver();
pc.countEnd();
perf_pop_marker();
perf_push_marker("integrate");
pc.countBegin("integrate");
integrate();
pc.countEnd();
perf_pop_marker();
frame++;
if(frame%100 == 0) {
float broadphaseTime = pc.getCountTime(0);
float collisionTime = pc.getCountTime(2);
float solverTime = pc.getCountTime(4);
float integrateTime = pc.getCountTime(6);
SCE_PFX_PRINTF("frame %3d broadphase %.2f collision %.2f solver %.2f integrate %.2f | total %.2f\n",frame,
broadphaseTime,collisionTime,solverTime,integrateTime,
broadphaseTime+collisionTime+solverTime+integrateTime);
}
}
///////////////////////////////////////////////////////////////////////////////
// Create Scene
void createBrick(int id,const PfxVector3 &pos,const PfxQuat &rot,const PfxVector3 &boxSize,PfxFloat mass)
{
PfxBox box(boxSize);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setRestitution(0.0f);
bodies[id].setMass(mass);
bodies[id].setInertia(pfxCalcInertiaBox(boxSize,mass));
states[id].reset();
states[id].setPosition(pos);
states[id].setOrientation(rot);
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
void createWall(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
PfxFloat bodyMass = 0.5f;
PfxFloat diffX = boxSize[0] * 1.02f;
PfxFloat diffY = boxSize[1] * 1.02f;
PfxFloat diffZ = boxSize[2] * 1.02f;
PfxFloat offset = -stackSize * (diffZ * 2.0f) * 0.5f;
PfxVector3 pos(0.0f, diffY, 0.0f);
while(stackSize) {
for(int i=0;i<stackSize;i++) {
pos[2] = offset + (PfxFloat)i * (diffZ * 2.0f);
createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,bodyMass);
}
offset += diffZ;
pos[1] += (diffY * 2.0f);
stackSize--;
}
}
void createPyramid(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
PfxFloat space = 0.0001f;
PfxVector3 pos(0.0f, boxSize[1], 0.0f);
PfxFloat diffX = boxSize[0] * 1.02f;
PfxFloat diffY = boxSize[1] * 1.02f;
PfxFloat diffZ = boxSize[2] * 1.02f;
PfxFloat offsetX = -stackSize * (diffX * 2.0f + space) * 0.5f;
PfxFloat offsetZ = -stackSize * (diffZ * 2.0f + space) * 0.5f;
while(stackSize) {
for(int j=0;j<stackSize;j++) {
pos[2] = offsetZ + (PfxFloat)j * (diffZ * 2.0f + space);
for(int i=0;i<stackSize;i++) {
pos[0] = offsetX + (PfxFloat)i * (diffX * 2.0f + space);
createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,1.0f);
}
}
offsetX += diffX;
offsetZ += diffZ;
pos[1] += (diffY * 2.0f + space);
stackSize--;
}
}
void createTowerCircle(const PfxVector3 &offsetPosition,int stackSize,int rotSize,const PfxVector3 &boxSize)
{
PfxFloat radius = 1.3f * rotSize * boxSize[0] / SCE_PFX_PI;
// create active boxes
PfxQuat rotY = PfxQuat::identity();
PfxFloat posY = boxSize[1];
for(int i=0;i<stackSize;i++) {
for(int j=0;j<rotSize;j++) {
createBrick(numRigidBodies++,offsetPosition+rotate(rotY,PfxVector3(0.0f , posY, radius)),rotY,boxSize,0.5f);
rotY *= PfxQuat::rotationY(SCE_PFX_PI/(rotSize*0.5f));
}
posY += boxSize[1] * 2.0f;
rotY *= PfxQuat::rotationY(SCE_PFX_PI/(PfxFloat)rotSize);
}
}
void createScenePrimitives()
{
// sphere
{
int id = numRigidBodies++;
PfxSphere sphere(1.0f);
PfxShape shape;
shape.reset();
shape.setSphere(sphere);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(1.0f);
bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(-5.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// box
{
int id = numRigidBodies++;
PfxBox box(1.0f,1.0f,1.0f);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(1.0f);
bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(1.0f),1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,5.0f,5.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// capsule
{
int id = numRigidBodies++;
PfxCapsule capsule(1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setCapsule(capsule);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(2.0f);
bodies[id].setInertia(pfxCalcInertiaCylinderX(2.0f,0.5f,2.0f));
states[id].reset();
states[id].setPosition(PfxVector3(5.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// cylinder
{
int id = numRigidBodies++;
PfxCylinder cylinder(0.5f,1.5f);
PfxShape shape;
shape.reset();
shape.setCylinder(cylinder);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaCylinderX(0.5f,1.5f,3.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,10.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// convex mesh
{
PfxCreateConvexMeshParam param;
param.verts = BarrelVtx;
param.numVerts = BarrelVtxCount;
param.vertexStrideBytes = sizeof(float)*6;
param.triangles = BarrelIdx;
param.numTriangles = BarrelIdxCount/3;
param.triangleStrideBytes = sizeof(unsigned short)*3;
PfxInt32 ret = pfxCreateConvexMesh(gConvex,param);
if(ret != SCE_PFX_OK) {
SCE_PFX_PRINTF("Can't create gConvex mesh.\n");
}
int id = numRigidBodies++;
PfxShape shape;
shape.reset();
shape.setConvexMesh(&gConvex);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,15.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// combined primitives
{
int id = numRigidBodies++;
//E Both shapes and incides buffer have to be kept when creating a combined shape.
static PfxShape shapes[3];
PfxUInt16 shapeIds[3]={0,1,2};
collidables[id].reset(shapes,shapeIds,3);
{
PfxBox box(0.5f,0.5f,1.5f);
PfxShape shape;
shape.reset();
shape.setBox(box);
shape.setOffsetPosition(PfxVector3(-2.0f,0.0f,0.0f));
collidables[id].addShape(shape);
}
{
PfxBox box(0.5f,1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setBox(box);
shape.setOffsetPosition(PfxVector3(2.0f,0.0f,0.0f));
collidables[id].addShape(shape);
}
{
PfxCapsule cap(1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setCapsule(cap);
collidables[id].addShape(shape);
}
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(2.5f,1.0f,1.0f),3.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
}
void createSceneJoints()
{
const int n = 10;
int startId = numRigidBodies;
PfxVector3 boxSize(1.0f);
PfxFloat boxMass = 1.0f;
for(int i=0;i<n;i++) {
createBrick(numRigidBodies++,PfxVector3(0,3.0f+i*2.5f*boxSize[1],0),PfxQuat::identity(),boxSize,boxMass);
}
for(int i=startId;i<startId+n;i++) {
PfxRigidState &stateA = states[i];
PfxRigidState &stateB = states[(i+1)%numRigidBodies];
PfxVector3 anchor;
if(i == numRigidBodies-1) {
anchor = stateA.getPosition() + PfxVector3(0,boxSize[1],0);
}
else {
anchor = ( stateA.getPosition() + stateB.getPosition() ) * 0.5f;
}
PfxSwingTwistJointInitParam jparam;
jparam.anchorPoint = anchor;
jparam.twistAxis = PfxVector3(0,1,0);
pfxInitializeSwingTwistJoint(joints[numJoints],stateA,stateB,jparam);
joints[numJoints].m_constraints[4].m_damping = 0.1f;
joints[numJoints].m_constraints[5].m_damping = 0.1f;
pfxUpdateJointPairs(jointPairs[numJoints],numJoints,joints[numJoints],stateA,stateB);
SCE_PFX_ASSERT(numJoints<NUM_JOINTS);
numJoints++;
}
states[startId].setLinearVelocity(PfxVector3(0,0,5));
states[startId].setLinearDamping(0.95f);
states[startId].setAngularDamping(0.95f);
}
void createSceneStacking()
{
createTowerCircle(PfxVector3(0.0f,0.0f,0.0f),8,24,PfxVector3(1));
}
void createSceneBoxGround()
{
int id = numRigidBodies++;
PfxBox box(150.0f,2.5f,150.0f);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,-2.5f,0.0f));
states[id].setMotionType(kPfxMotionTypeFixed);
states[id].setRigidBodyId(id);
}
void createSceneLandscape()
{
PfxCreateLargeTriMeshParam param;
param.verts = LargeMeshVtx;
param.numVerts = LargeMeshVtxCount;
param.vertexStrideBytes = sizeof(float)*6;
param.triangles = LargeMeshIdx;
param.numTriangles = LargeMeshIdxCount/3;
param.triangleStrideBytes = sizeof(unsigned short)*3;
if(gLargeMesh.m_numIslands > 0) {
pfxReleaseLargeTriMesh(gLargeMesh);
}
PfxInt32 ret = pfxCreateLargeTriMesh(gLargeMesh,param);
if(ret != SCE_PFX_OK) {
SCE_PFX_PRINTF("Can't create large mesh.\n");
}
int id = numRigidBodies++;
PfxShape shape;
shape.reset();
shape.setLargeTriMesh(&gLargeMesh);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,-5.0f,0.0f));
states[id].setOrientation(PfxQuat::rotationX(0.5f)*PfxQuat::rotationY(0.7f));
states[id].setMotionType(kPfxMotionTypeFixed);
states[id].setRigidBodyId(id);
}
void physics_create_scene(int sceneId)
{
const int numScenes = 4;
int sid = sceneId % numScenes;
numRigidBodies= 0;
numPairs = 0;
numContacts = 0;
numJoints = 0;
frame = 0;
switch(sid) {
case 0: // simple primitives
createSceneBoxGround();
createScenePrimitives();
break;
case 1: // joints
createSceneBoxGround();
createSceneJoints();
break;
case 2: // stacking
createSceneBoxGround();
createSceneStacking();
break;
case 3: // landscape
createSceneLandscape();
createScenePrimitives();
break;
}
SCE_PFX_PRINTF("----- Size of rigid body buffer ------\n");
SCE_PFX_PRINTF(" size * num = total\n");
SCE_PFX_PRINTF("PfxRigidState %5d * %5d = %5d bytes\n",sizeof(PfxRigidState),numRigidBodies,sizeof(PfxRigidState)*numRigidBodies);
SCE_PFX_PRINTF("PfxRigidBody %5d * %5d = %5d bytes\n",sizeof(PfxRigidBody),numRigidBodies,sizeof(PfxRigidBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxCollidable %5d * %5d = %5d bytes\n",sizeof(PfxCollidable),numRigidBodies,sizeof(PfxCollidable)*numRigidBodies);
SCE_PFX_PRINTF("PfxJoint %5d * %5d = %5d bytes\n",sizeof(PfxJoint),numJoints,sizeof(PfxJoint)*numJoints);
SCE_PFX_PRINTF("PfxSolverBody %5d * %5d = %5d bytes\n",sizeof(PfxSolverBody),numRigidBodies,sizeof(PfxSolverBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxBroadphaseProxy %5d * %5d = %5d bytes\n",sizeof(PfxBroadphaseProxy),numRigidBodies,sizeof(PfxBroadphaseProxy)*numRigidBodies);
SCE_PFX_PRINTF("PfxContactManifold %5d * %5d = %5d bytes\n",sizeof(PfxContactManifold),NUM_CONTACTS,sizeof(PfxContactManifold)*NUM_CONTACTS);
SCE_PFX_PRINTF("PfxBroadphasePair %5d * %5d = %5d bytes\n",sizeof(PfxBroadphasePair),NUM_CONTACTS,sizeof(PfxBroadphasePair)*NUM_CONTACTS);
int totalBytes =
(sizeof(PfxRigidState) + sizeof(PfxRigidBody) + sizeof(PfxCollidable) + sizeof(PfxSolverBody) + sizeof(PfxBroadphaseProxy)) * numRigidBodies +
(sizeof(PfxContactManifold) + sizeof(PfxBroadphasePair)) * NUM_CONTACTS;
SCE_PFX_PRINTF("----------------------------------------------------------\n");
SCE_PFX_PRINTF("Total %5d bytes\n",totalBytes);
}
///////////////////////////////////////////////////////////////////////////////
// Initialize / Finalize Engine
bool physics_init()
{
return true;
}
void physics_release()
{
}
///////////////////////////////////////////////////////////////////////////////
// Pick
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2)
{
return PfxVector3(0.0f);
}
void physics_pick_update(const PfxVector3 &p)
{
}
void physics_pick_end()
{
}
///////////////////////////////////////////////////////////////////////////////
// Get Information
int physics_get_num_rigidbodies()
{
return numRigidBodies;
}
const PfxRigidState& physics_get_state(int id)
{
return states[id];
}
const PfxRigidBody& physics_get_body(int id)
{
return bodies[id];
}
const PfxCollidable& physics_get_collidable(int id)
{
return collidables[id];
}
int physics_get_num_contacts()
{
return numPairs;
}
const PfxContactManifold &physics_get_contact(int id)
{
return contacts[pfxGetConstraintId(pairs[id])];
}

View File

@@ -0,0 +1,49 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __PHYSICS_FUNC_H__
#define __PHYSICS_FUNC_H__
#define SCE_PFX_USE_PERFCOUNTER
#include "physics_effects.h"
using namespace sce::PhysicsEffects;
//E Simulation
//J シミュレーション
bool physics_init();
void physics_release();
void physics_create_scene(int sceneId);
void physics_simulate();
//E Picking
//J ピッキング
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2);
void physics_pick_update(const PfxVector3 &p);
void physics_pick_end();
//E Change parameters
//J パラメータの取得
int physics_get_num_rigidbodies();
const PfxRigidState& physics_get_state(int id);
const PfxRigidBody& physics_get_body(int id);
const PfxCollidable& physics_get_collidable(int id);
int physics_get_num_contacts();
const PfxContactManifold &physics_get_contact(int id);
#endif /* __PHYSICS_FUNC_H__ */

View File

@@ -0,0 +1,22 @@
project "1_simple"
kind "WindowedApp"
targetdir "../../../bin"
includedirs {"../../../include"}
links {
"physicseffects2_lowlevel",
"physicseffects2_baselevel",
"physicseffects2_util",
"opengl32"
}
flags {"WinMain"}
files {
"main.cpp",
"physics_func.cpp",
"../common/ctrl_func.win32.cpp",
"../common/perf_func.win32.cpp",
"../common/render_func.win32.cpp"
}

View File

@@ -0,0 +1,202 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define BarrelVtxCount 57
#define BarrelIdxCount 180
static float BarrelVtx[] = {
0.0f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
-0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
0.0f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
-0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.957307f,-0.289072f,0.0f,
0.404509f,0.0f,-0.293893f, 0.809017f,0.0f,-0.587785f,
0.5f,0.0f,0.0f, 1.0f,0.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.774478f,-0.289072f,-0.562691f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
-0.154509f,0.0f,-0.475528f, -0.309017f,0.0f,-0.951057f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
-0.107853f,-0.5f,-0.331936f, -0.295824f,-0.289072f,-0.910453f,
-0.404509f,0.0f,-0.293893f, -0.809017f,0.0f,-0.587785f,
-0.282362f,-0.5f,-0.205148f, -0.774478f,-0.289072f,-0.562691f,
-0.5f,0.0f,0.0f, -1.0f,0.0f,0.0f,
-0.349018f,-0.5f,0.0f, -0.957307f,-0.289072f,0.0f,
-0.404508f,0.0f,0.293893f, -0.809017f,0.0f,0.587785f,
-0.282362f,-0.5f,0.205148f, -0.774478f,-0.289072f,0.562691f,
-0.154509f,0.0f,0.475528f, -0.309017f,0.0f,0.951056f,
-0.107853f,-0.5f,0.331936f, -0.295824f,-0.289072f,0.910453f,
0.154509f,0.0f,0.475528f, 0.309017f,0.0f,0.951056f,
0.107853f,-0.5f,0.331936f, 0.295824f,-0.289072f,0.910453f,
0.404509f,0.0f,0.293892f, 0.809017f,0.0f,0.587785f,
0.282362f,-0.5f,0.205148f, 0.774478f,-0.289072f,0.562691f,
0.282362f,0.5f,-0.205148f, 0.774478f,0.289072f,-0.562691f,
0.349018f,0.5f,0.0f, 0.957307f,0.289072f,0.0f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.107853f,0.5f,-0.331936f, -0.295824f,0.289072f,-0.910453f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.282362f,0.5f,-0.205148f, -0.774478f,0.289072f,-0.562691f,
-0.349018f,0.5f,0.0f, -0.957307f,0.289072f,0.0f,
-0.282362f,0.5f,0.205148f, -0.774478f,0.289072f,0.562691f,
-0.107853f,0.5f,0.331936f, -0.295824f,0.289072f,0.910453f,
0.107853f,0.5f,0.331936f, 0.295824f,0.289072f,0.910453f,
0.282362f,0.5f,0.205148f, 0.774478f,0.289072f,0.562691f,
};
static float BarrelTex[] = {
0.0f,0.5f,
0.0f,0.85f,
0.0f,0.75f,
0.0f,0.95f,
0.0f,0.05f,
0.0f,-0.05f,
0.0f,0.15f,
0.0f,0.25f,
0.0f,0.35f,
0.0f,0.45f,
0.0f,0.55f,
0.0f,0.65f,
1.0f,0.5f,
1.0f,0.75f,
1.0f,0.85f,
1.0f,0.95f,
1.0f,-0.05f,
1.0f,0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
0.0f,0.75f,
0.5f,0.85f,
0.5f,0.75f,
0.0f,0.85f,
0.5f,0.95f,
0.0f,0.95f,
0.0f,-0.05f,
0.5f,0.05f,
0.5f,-0.05f,
0.0f,0.05f,
0.5f,0.15f,
0.0f,0.15f,
0.5f,0.25f,
0.0f,0.25f,
0.5f,0.35f,
0.0f,0.35f,
0.5f,0.45f,
0.0f,0.45f,
0.5f,0.55f,
0.0f,0.55f,
0.5f,0.65f,
0.0f,0.65f,
1.0f,0.85f,
1.0f,0.75f,
1.0f,0.95f,
1.0f,0.05f,
1.0f,-0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
};
static unsigned short BarrelIdx[] = {
0,1,2,
0,3,1,
0,4,5,
0,6,4,
0,7,6,
0,8,7,
0,9,8,
0,10,9,
0,11,10,
0,2,11,
12,13,14,
12,14,15,
12,16,17,
12,17,18,
12,18,19,
12,19,20,
12,20,21,
12,21,22,
12,22,23,
12,23,13,
24,25,26,
24,27,25,
27,28,25,
27,29,28,
30,31,32,
30,33,31,
33,34,31,
33,35,34,
35,36,34,
35,37,36,
37,38,36,
37,39,38,
39,40,38,
39,41,40,
41,42,40,
41,43,42,
43,44,42,
43,45,44,
45,26,44,
45,24,26,
26,46,47,
26,25,46,
25,48,46,
25,28,48,
32,49,50,
32,31,49,
31,51,49,
31,34,51,
34,52,51,
34,36,52,
36,53,52,
36,38,53,
38,54,53,
38,40,54,
40,55,54,
40,42,55,
42,56,55,
42,44,56,
44,47,56,
44,26,47,
};

View File

@@ -0,0 +1,318 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define LargeMeshVtxCount 81
#define LargeMeshIdxCount 384
static float LargeMeshVtx[] = {
-25.0f,-2.19407f,18.5625f, 0.232976f,0.967754f,0.0957829f,
-25.0f,0.0644502f,24.75f, 0.188094f,0.871343f,-0.45319f,
-18.75f,-4.50287f,18.5625f, -0.0716098f,0.995449f,0.0628767f,
-18.75f,-0.39999f,24.75f, -0.0602794f,0.895848f,-0.440253f,
-12.5f,-1.2166f,18.5625f, -0.269469f,0.961403f,0.0555879f,
-12.5f,-0.942431f,24.75f, -0.0997841f,0.993258f,0.0589987f,
-6.25f,1.93598f,18.5625f, -0.283933f,0.956351f,-0.0691025f,
-6.25f,-0.445954f,24.75f, -0.180725f,0.942766f,0.280233f,
0.0f,2.76983f,18.5625f, 0.171645f,0.984908f,0.0222501f,
0.0f,2.76642f,24.75f, 0.0784993f,0.995428f,-0.0544117f,
6.25f,-2.53736f,18.5625f, 0.248298f,0.965028f,0.0840741f,
6.25f,-0.915645f,24.75f, 0.164311f,0.945856f,-0.279926f,
12.5f,-1.60054f,18.5625f, -0.180435f,0.983586f,0.00115547f,
12.5f,0.831925f,24.75f, -0.0692495f,0.964821f,-0.253623f,
18.75f,-0.800282f,18.5625f, 0.10755f,0.951538f,0.288112f,
18.75f,-1.47284f,24.75f, 0.232178f,0.972664f,0.00429361f,
25.0f,-2.78379f,18.5625f, 0.1833f,0.937477f,0.295867f,
25.0f,-0.967508f,24.75f, -0.0773477f,0.956641f,-0.280812f,
-25.0f,-0.352038f,12.375f, -0.192222f,0.972435f,0.131987f,
-18.75f,0.681228f,12.375f, -0.107779f,0.962569f,0.248686f,
-12.5f,2.72065f,12.375f, 0.0520846f,0.993034f,0.105692f,
-6.25f,-1.78776f,12.375f, -0.0133223f,0.99674f,-0.0795754f,
0.0f,1.57707f,12.375f, -0.129025f,0.969662f,-0.207627f,
6.25f,0.424356f,12.375f, 0.180995f,0.97074f,0.157815f,
12.5f,0.283234f,12.375f, -0.16285f,0.973539f,0.160316f,
18.75f,2.57015f,12.375f, -0.165454f,0.978339f,0.124408f,
25.0f,3.07363f,12.375f, -0.00454559f,0.988151f,0.153417f,
-25.0f,-0.893751f,6.1875f, -0.0836251f,0.990084f,-0.112876f,
-18.75f,0.930932f,6.1875f, 0.00269413f,0.971838f,-0.235633f,
-12.5f,-0.684529f,6.1875f, -0.010319f,0.927048f,-0.3748f,
-6.25f,-0.661383f,6.1875f, 0.012265f,0.999875f,-0.00994222f,
0.0f,0.385718f,6.1875f, -0.15435f,0.984937f,-0.0779465f,
6.25f,0.589796f,6.1875f, 0.0241717f,0.999582f,-0.0158589f,
12.5f,0.47454f,6.1875f, -0.017184f,0.997953f,-0.0616073f,
18.75f,1.59939f,6.1875f, -0.0902706f,0.957309f,-0.274609f,
25.0f,1.13434f,6.1875f, 0.0346006f,0.957441f,-0.286547f,
-25.0f,0.74548f,0.0f, 0.329903f,0.930812f,0.157334f,
-18.75f,-2.47437f,0.0f, 0.247844f,0.968142f,0.0357041f,
-12.5f,-4.16309f,1.81975e-007f, -0.0623898f,0.997626f,-0.0291436f,
-6.25f,-0.700022f,0.0f, -0.217067f,0.974987f,-0.0477624f,
0.0f,-0.0957388f,0.0f, -0.117693f,0.990712f,-0.068098f,
6.25f,0.614077f,0.0f, -0.0713214f,0.997305f,0.01722f,
12.5f,0.299109f,0.0f, 0.218606f,0.968641f,0.118094f,
18.75f,-1.71753f,0.0f, 0.0339493f,0.985612f,-0.165579f,
25.0f,-1.12638f,0.0f, -0.0547573f,0.989177f,-0.136126f,
-25.0f,-0.403319f,-6.1875f, -0.1263f,0.989211f,-0.074223f,
-18.75f,-0.0730335f,-6.1875f, 0.0173428f,0.965382f,0.260261f,
-12.5f,-0.450125f,-6.1875f, 0.0658811f,0.875f,0.479619f,
-6.25f,-0.180204f,-6.1875f, 0.0116584f,0.981445f,0.19139f,
0.0f,-0.632679f,-6.1875f, -0.0557983f,0.993041f,-0.103716f,
6.25f,0.308409f,-6.1875f, -0.191898f,0.96766f,-0.163737f,
12.5f,2.5011f,-6.1875f, 0.0758397f,0.996403f,-0.0378189f,
18.75f,-1.69303f,-6.1875f, 0.16761f,0.974057f,0.15205f,
25.0f,-0.141349f,-6.1875f, -0.204846f,0.978471f,0.0251341f,
-25.0f,-1.10316f,-12.375f, -0.0350644f,0.993748f,-0.106001f,
-18.75f,1.06711f,-12.375f, -0.309806f,0.919244f,-0.242922f,
-12.5f,3.61544f,-12.375f, -0.0506281f,0.998702f,-0.00561657f,
-6.25f,1.6504f,-12.375f, 0.322294f,0.937465f,0.131477f,
0.0f,-1.60595f,-12.375f, 0.086016f,0.995916f,0.0274459f,
6.25f,-0.849859f,-12.375f, -0.0332811f,0.997087f,0.0686255f,
12.5f,-0.942201f,-12.375f, -0.153559f,0.982185f,-0.108312f,
18.75f,0.494873f,-12.375f, 0.0753195f,0.981472f,0.176181f,
25.0f,-0.333828f,-12.375f, 0.035057f,0.987194f,0.155624f,
-25.0f,2.1862f,-18.5625f, 0.612899f,0.782306f,0.111138f,
-18.75f,-3.38259f,-18.5625f, 0.0194078f,0.992789f,-0.118297f,
-12.5f,-0.880916f,-18.5625f, -0.282251f,0.949875f,-0.13443f,
-6.25f,0.818158f,-18.5625f, 0.1476f,0.981788f,-0.119612f,
0.0f,-1.48019f,-18.5625f, -0.044551f,0.996013f,-0.0772824f,
6.25f,1.47123f,-18.5625f, -0.117036f,0.97986f,0.161792f,
12.5f,0.164076f,-18.5625f, -0.0340355f,0.978993f,0.201034f,
18.75f,2.14568f,-18.5625f, -0.0439269f,0.994859f,0.0912435f,
25.0f,0.626506f,-18.5625f, 0.208015f,0.968592f,0.136229f,
-25.0f,0.296889f,-24.75f, 0.46973f,0.844327f,-0.257809f,
-18.75f,-3.18022f,-24.75f, -0.0226758f,0.998794f,-0.0435401f,
-12.5f,1.8927f,-24.75f, -0.202772f,0.919836f,0.335836f,
-6.25f,1.46387f,-24.75f, 0.224904f,0.955746f,0.189652f,
0.0f,-2.52726f,-24.75f, -0.0435882f,0.993572f,-0.10447f,
6.25f,1.30397f,-24.75f, -0.28646f,0.956525f,-0.0547707f,
12.5f,1.85812f,-24.75f, 0.0521949f,0.979796f,0.193067f,
18.75f,1.56331f,-24.75f, -0.0270784f,0.999629f,-0.00293115f,
25.0f,1.05366f,-24.75f, 0.161f,0.986887f,-0.0115473f,
};
static float LargeMeshTex[] = {
0.125f,0.0f,
0.0f,0.0f,
0.125f,0.125f,
0.0f,0.125f,
0.125f,0.25f,
0.0f,0.25f,
0.125f,0.375f,
0.0f,0.375f,
0.125f,0.5f,
0.0f,0.5f,
0.125f,0.625f,
0.0f,0.625f,
0.125f,0.75f,
0.0f,0.75f,
0.125f,0.875f,
0.0f,0.875f,
0.125f,1.0f,
0.0f,1.0f,
0.25f,0.0f,
0.25f,0.125f,
0.25f,0.25f,
0.25f,0.375f,
0.25f,0.5f,
0.25f,0.625f,
0.25f,0.75f,
0.25f,0.875f,
0.25f,1.0f,
0.375f,0.0f,
0.375f,0.125f,
0.375f,0.25f,
0.375f,0.375f,
0.375f,0.5f,
0.375f,0.625f,
0.375f,0.75f,
0.375f,0.875f,
0.375f,1.0f,
0.5f,0.0f,
0.5f,0.125f,
0.5f,0.25f,
0.5f,0.375f,
0.5f,0.5f,
0.5f,0.625f,
0.5f,0.75f,
0.5f,0.875f,
0.5f,1.0f,
0.625f,0.0f,
0.625f,0.125f,
0.625f,0.25f,
0.625f,0.375f,
0.625f,0.5f,
0.625f,0.625f,
0.625f,0.75f,
0.625f,0.875f,
0.625f,1.0f,
0.75f,0.0f,
0.75f,0.125f,
0.75f,0.25f,
0.75f,0.375f,
0.75f,0.5f,
0.75f,0.625f,
0.75f,0.75f,
0.75f,0.875f,
0.75f,1.0f,
0.875f,0.0f,
0.875f,0.125f,
0.875f,0.25f,
0.875f,0.375f,
0.875f,0.5f,
0.875f,0.625f,
0.875f,0.75f,
0.875f,0.875f,
0.875f,1.0f,
1.0f,0.0f,
1.0f,0.125f,
1.0f,0.25f,
1.0f,0.375f,
1.0f,0.5f,
1.0f,0.625f,
1.0f,0.75f,
1.0f,0.875f,
1.0f,1.0f,
};
static unsigned short LargeMeshIdx[] = {
0,1,2,
3,2,1,
2,3,4,
5,4,3,
4,5,6,
7,6,5,
6,7,8,
9,8,7,
8,9,10,
11,10,9,
10,11,12,
13,12,11,
12,13,14,
15,14,13,
14,15,16,
17,16,15,
18,0,19,
2,19,0,
19,2,20,
4,20,2,
20,4,21,
6,21,4,
21,6,22,
8,22,6,
22,8,23,
10,23,8,
23,10,24,
12,24,10,
24,12,25,
14,25,12,
25,14,26,
16,26,14,
27,18,28,
19,28,18,
28,19,29,
20,29,19,
29,20,30,
21,30,20,
30,21,31,
22,31,21,
31,22,32,
23,32,22,
32,23,33,
24,33,23,
33,24,34,
25,34,24,
34,25,35,
26,35,25,
36,27,37,
28,37,27,
37,28,38,
29,38,28,
38,29,39,
30,39,29,
39,30,40,
31,40,30,
40,31,41,
32,41,31,
41,32,42,
33,42,32,
42,33,43,
34,43,33,
43,34,44,
35,44,34,
45,36,46,
37,46,36,
46,37,47,
38,47,37,
47,38,48,
39,48,38,
48,39,49,
40,49,39,
49,40,50,
41,50,40,
50,41,51,
42,51,41,
51,42,52,
43,52,42,
52,43,53,
44,53,43,
54,45,55,
46,55,45,
55,46,56,
47,56,46,
56,47,57,
48,57,47,
57,48,58,
49,58,48,
58,49,59,
50,59,49,
59,50,60,
51,60,50,
60,51,61,
52,61,51,
61,52,62,
53,62,52,
63,54,64,
55,64,54,
64,55,65,
56,65,55,
65,56,66,
57,66,56,
66,57,67,
58,67,57,
67,58,68,
59,68,58,
68,59,69,
60,69,59,
69,60,70,
61,70,60,
70,61,71,
62,71,61,
72,63,73,
64,73,63,
73,64,74,
65,74,64,
74,65,75,
66,75,65,
75,66,76,
67,76,66,
76,67,77,
68,77,67,
77,68,78,
69,78,68,
78,69,79,
70,79,69,
79,70,80,
71,80,70,
};

View File

@@ -0,0 +1,448 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "../common/common.h"
#include "../common/ctrl_func.h"
#include "../common/render_func.h"
#include "../common/perf_func.h"
#include "physics_func.h"
#include "barrel.h"
#include "landscape.h"
#ifdef _WIN32
#include <gl/gl.h>
#include <gl/glu.h>
#endif
// ARA begin insert new code
#ifdef __ANDROID__
#include <EGL/egl.h>
#include <GLES/gl.h>
#endif // __ANDROID__
// ARA end
#define SAMPLE_NAME "api_physics_effects/1_simple"
static bool s_isRunning = true;
int sceneId = 0;
bool simulating = false;
int landscapeMeshId;
int convexMeshId;
void render(void)
{
render_begin();
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxTransform3 rbT(state.getOrientation(), state.getPosition());
PfxShapeIterator itrShape(coll);
for(int j=0;j<coll.getNumShapes();j++,++itrShape) {
const PfxShape &shape = *itrShape;
PfxTransform3 offsetT = shape.getOffsetTransform();
PfxTransform3 worldT = rbT * offsetT;
switch(shape.getType()) {
case kPfxShapeSphere:
render_sphere(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getSphere().m_radius));
break;
case kPfxShapeBox:
render_box(
worldT,
PfxVector3(1,1,1),
shape.getBox().m_half);
break;
case kPfxShapeCapsule:
render_capsule(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getCapsule().m_radius),
PfxFloatInVec(shape.getCapsule().m_halfLen));
break;
case kPfxShapeCylinder:
render_cylinder(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getCylinder().m_radius),
PfxFloatInVec(shape.getCylinder().m_halfLen));
break;
case kPfxShapeConvexMesh:
render_mesh(
worldT,
PfxVector3(1,1,1),
convexMeshId);
break;
case kPfxShapeLargeTriMesh:
render_mesh(
worldT,
PfxVector3(1,1,1),
landscapeMeshId);
break;
default:
break;
}
}
}
render_end();
}
int init(void)
{
perf_init();
ctrl_init();
render_init();
physics_init();
landscapeMeshId = render_init_mesh(
LargeMeshVtx,sizeof(float)*6,
LargeMeshVtx+3,sizeof(float)*6,
LargeMeshIdx,sizeof(unsigned short)*3,
LargeMeshVtxCount,LargeMeshIdxCount/3);
convexMeshId = render_init_mesh(
BarrelVtx,sizeof(float)*6,
BarrelVtx+3,sizeof(float)*6,
BarrelIdx,sizeof(unsigned short)*3,
BarrelVtxCount,BarrelIdxCount/3);
return 0;
}
static int shutdown(void)
{
ctrl_release();
render_release();
physics_release();
perf_release();
return 0;
}
void update(void)
{
float angX,angY,r;
render_get_view_angle(angX,angY,r);
ctrl_update();
if(ctrl_button_pressed(BTN_UP)) {
angX -= 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_DOWN)) {
angX += 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_LEFT)) {
angY -= 0.05f;
}
if(ctrl_button_pressed(BTN_RIGHT)) {
angY += 0.05f;
}
if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
r *= 1.1f;
if(r > 500.0f) r = 500.0f;
}
if(ctrl_button_pressed(BTN_ZOOM_IN)) {
r *= 0.9f;
if(r < 1.0f) r = 1.0f;
}
if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
physics_create_scene(sceneId);
}
if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
physics_create_scene(++sceneId);
}
if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
simulating = !simulating;
}
if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
simulating = true;
}
else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
simulating = false;
}
render_set_view_angle(angX,angY,r);
}
#ifndef _WIN32
// ARA begin insert new code
#ifdef __ANDROID__
///////////////////////////////////////////////////////////////////////////////
// sceneChange
//
/// This function is used to change the physics scene on Android devices
///////////////////////////////////////////////////////////////////////////////
void sceneChange()
{
physics_create_scene(sceneId++);
}
#else // __ANDROID__
// ARA end
///////////////////////////////////////////////////////////////////////////////
// Main
int main(void)
{
init();
physics_create_scene(sceneId);
printf("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
while (s_isRunning) {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
shutdown();
printf("## %s: FINISHED ##\n", SAMPLE_NAME);
return 0;
}
// ARA begin insert new code
#endif // __ANDROID__
// ARA end
#else // _WIN32
///////////////////////////////////////////////////////////////////////////////
// WinMain
extern HDC hDC;
extern HGLRC hRC;
HWND hWnd;
HINSTANCE hInstance;
void releaseWindow()
{
if(hRC) {
wglMakeCurrent(0,0);
wglDeleteContext(hRC);
}
if(hDC) ReleaseDC(hWnd,hDC);
if(hWnd) DestroyWindow(hWnd);
UnregisterClass(SAMPLE_NAME,hInstance);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg) {
case WM_SYSCOMMAND:
{
switch (wParam) {
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_SIZE:
render_resize(LOWORD(lParam),HIWORD(lParam));
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
bool createWindow(char* title, int width, int height)
{
WNDCLASS wc;
RECT rect;
rect.left=0;
rect.right=width;
rect.top=0;
rect.bottom=height;
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = SAMPLE_NAME;
if(!RegisterClass(&wc)) {
return false;
}
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
if(!(hWnd=CreateWindowEx(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,SAMPLE_NAME,title,
WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
0,0,rect.right-rect.left,rect.bottom-rect.top,
NULL,NULL,hInstance,NULL))) {
releaseWindow();
return false;
}
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0,
0, 0,
0, 0,
0, 0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if(!(hDC=GetDC(hWnd)))
{
releaseWindow();
OutputDebugString("");
return FALSE;
}
int pixelformat;
if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 ){
OutputDebugString("ChoosePixelFormat Failed....");
return FALSE;
}
if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE){
OutputDebugString("SetPixelFormat Failed....");
return FALSE;
}
if (!(hRC=wglCreateContext(hDC))){
OutputDebugString("Creating HGLRC Failed....");
return FALSE;
}
// Set Vsync
//BOOL (WINAPI *wglSwapIntervalEXT)(int) = NULL;
//if(strstr((char*)glGetString( GL_EXTENSIONS ),"WGL_EXT_swap_control")== 0) {
//}
//else {
//wglSwapIntervalEXT = (BOOL (WINAPI*)(int))wglGetProcAddress("wglSwapIntervalEXT");
//if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
//}
wglMakeCurrent(hDC,hRC);
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
render_resize(width, height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return 0;
}
init();
physics_create_scene(sceneId);
SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
MSG msg;
while(s_isRunning) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if(msg.message==WM_QUIT) {
s_isRunning = false;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
}
shutdown();
SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);
releaseWindow();
return (msg.wParam);
}
#endif

View File

@@ -0,0 +1,857 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "physics_func.h"
#include "../common/perf_func.h"
///////////////////////////////////////////////////////////////////////////////
// Simulation Data
#define NUM_RIGIDBODIES 1000
#define NUM_JOINTS 500
#define NUM_CONTACTS 4000
const float timeStep = 0.016f;
const float separateBias = 0.1f;
int iteration = 5;
//J ???????
//E World size
PfxVector3 worldCenter(0.0f);
PfxVector3 worldExtent(500.0f);
//J ??
//E Rigid body
PfxRigidState states[NUM_RIGIDBODIES];
PfxRigidBody bodies[NUM_RIGIDBODIES];
PfxCollidable collidables[NUM_RIGIDBODIES];
PfxSolverBody solverBodies[NUM_RIGIDBODIES];
int numRigidBodies = 0;
//J ?????????????????
//E Large mesh for representing a landscape
#include "landscape.h"
PfxLargeTriMesh gLargeMesh;
//J ?????
//E Convex Mesh
#include "barrel.h"
PfxConvexMesh gConvex;
//J ????
//E Proxies
PfxBroadphaseProxy proxies[NUM_RIGIDBODIES];
//J ?????
//E Joint
PfxConstraintPair jointPairs[NUM_JOINTS];
PfxJoint joints[NUM_JOINTS];
int numJoints = 0;
//J ??
//E Pairs
unsigned int numPairs;
PfxBroadphasePair pairs[NUM_CONTACTS];
//J ?????
//E Contacts
PfxContactManifold contacts[NUM_CONTACTS];
int numContacts;
//J ??????
//E Temporary buffers
#define POOL_BYTES (5*1024*1024)
unsigned char SCE_PFX_ALIGNED(128) poolBuff[POOL_BYTES];
//J ????????????????
//E Stack allocator for temporary buffers
PfxHeapManager pool(poolBuff,POOL_BYTES);
// ARA begin insert new code
//E task manager for parallel demo
#define NUM_THREADS 2
PfxTaskManager *taskManager = NULL;
//E need enough bytes for NUM_THREADS PfxTaskArg objects, with the space rounded up to fill a 16-bit aligned space
#define TASK_MANAGER_POOL_BYTES 1024
unsigned char SCE_PFX_ALIGNED(16) taskPoolBuff[TASK_MANAGER_POOL_BYTES];
// ARA end
///////////////////////////////////////////////////////////////////////////////
// Simulation Function
int frame = 0;
void broadphase()
{
//J ?????????????????
//E Find the axis along which all rigid bodies are most widely positioned
int axis = 0;
{
PfxVector3 s(0.0f),s2(0.0f);
for(int i=0;i<numRigidBodies;i++) {
PfxVector3 c = states[i].getPosition();
s += c;
s2 += mulPerElem(c,c);
}
PfxVector3 v = s2 - mulPerElem(s,s) / (float)numRigidBodies;
if(v[1] > v[0]) axis = 1;
if(v[2] > v[axis]) axis = 2;
}
//J ???????????????
//E Create broadpahse proxies
{
for(int i=0;i<numRigidBodies;i++) {
pfxUpdateBroadphaseProxy(proxies[i],states[i],collidables[i],worldCenter,worldExtent,axis);
}
int workBytes = sizeof(PfxBroadphaseProxy) * numRigidBodies;
void *workBuff = pool.allocate(workBytes);
pfxParallelSort(proxies,numRigidBodies,workBuff,workBytes);
pool.deallocate(workBuff);
}
//J ??????
//E Find overlapped pairs
{
PfxFindPairsParam param;
param.workBytes = pfxGetWorkBytesOfFindPairs(NUM_CONTACTS);
param.workBuff = pool.allocate(param.workBytes);
param.pairBytes = pfxGetPairBytesOfFindPairs(NUM_CONTACTS);
param.pairBuff = pool.allocate(param.pairBytes);
param.proxies = proxies;
param.numProxies = numRigidBodies;
param.maxPairs = NUM_CONTACTS;
param.axis = axis;
PfxFindPairsResult result;
int ret = pfxFindPairs(param,result);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxFindPairs failed %d\n",ret);
memcpy(pairs,result.pairs,sizeof(PfxBroadphasePair)*result.numPairs);
numPairs = result.numPairs;
pool.deallocate(param.pairBuff);
pool.deallocate(param.workBuff);
}
//J ??????????????
//E Add new contacts and initialize
for(PfxUInt32 i=0;i<numPairs;i++) {
pfxSetContactId(pairs[i],i);
PfxContactManifold &contact = contacts[i];
contact.reset(pfxGetObjectIdA(pairs[i]),pfxGetObjectIdB(pairs[i]));
}
numContacts = numPairs;
}
void collision()
{
//J ????
//E Detect collisions
{
PfxDetectCollisionParam param;
param.contactPairs = pairs;
param.numContactPairs = numPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetCollidables = collidables;
param.numRigidBodies = numRigidBodies;
// ARA begin insert new code
#ifdef USE_PTHREADS
int ret = pfxDetectCollision(param, taskManager);
#else
// ARA end
int ret = pfxDetectCollision(param);
// ARA begin insert new code
#endif
// ARA end
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxDetectCollision failed %d\n",ret);
}
}
void constraintSolver()
{
PfxPerfCounter pc;
pc.countBegin("setup solver bodies");
{
PfxSetupSolverBodiesParam param;
param.states = states;
param.bodies = bodies;
param.solverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
// ARA begin insert new code
#ifdef USE_PTHREADS
int ret = pfxSetupSolverBodies(param, taskManager);
#else
// ARA end
int ret = pfxSetupSolverBodies(param);
// ARA begin insert new code
#endif
// ARA end
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupSolverBodies failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup contact constraints");
{
PfxSetupContactConstraintsParam param;
param.contactPairs = pairs;
param.numContactPairs = numPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
param.separateBias = separateBias;
// ARA begin insert new code
#ifdef USE_PTHREADS
int ret = pfxSetupContactConstraints(param, taskManager);
#else
// ARA end
int ret = pfxSetupContactConstraints(param);
// ARA begin insert new code
#endif
// ARA end
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup joint constraints");
{
PfxSetupJointConstraintsParam param;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
for(int i=0;i<numJoints;i++) {
pfxUpdateJointPairs(jointPairs[i],i,joints[i],states[joints[i].m_rigidBodyIdA],states[joints[i].m_rigidBodyIdB]);
}
// ARA begin insert new code
#ifdef USE_PTHREADS
int ret = pfxSetupJointConstraints(param, taskManager);
#else
// ARA end
int ret = pfxSetupJointConstraints(param);
// ARA begin insert new code
#endif
// ARA end
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("solve constraints");
{
PfxSolveConstraintsParam param;
param.workBytes = pfxGetWorkBytesOfSolveConstraints(numRigidBodies,numPairs,numJoints);
param.workBuff = pool.allocate(param.workBytes);
param.contactPairs = pairs;
param.numContactPairs = numPairs;
param.offsetContactManifolds = contacts;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.iteration = iteration;
// ARA begin insert new code
#ifdef USE_PTHREADS
int ret = pfxSolveConstraints(param, taskManager);
#else
// ARA end
int ret = pfxSolveConstraints(param);
// ARA begin insert new code
#endif
// ARA end
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSolveConstraints failed %d\n",ret);
pool.deallocate(param.workBuff);
}
pc.countEnd();
//pc.printCount();
}
void integrate()
{
PfxUpdateRigidStatesParam param;
param.states = states;
param.bodies = bodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
// ARA begin insert new code
#ifdef USE_PTHREADS
pfxUpdateRigidStates(param, taskManager);
#else
// ARA end
pfxUpdateRigidStates(param);
// ARA begin insert new code
#endif
// ARA end
}
void physics_simulate()
{
PfxPerfCounter pc;
for(int i=1;i<numRigidBodies;i++) {
pfxApplyExternalForce(states[i],bodies[i],bodies[i].getMass()*PfxVector3(0.0f,-9.8f,0.0f),PfxVector3(0.0f),timeStep);
}
perf_push_marker("broadphase");
pc.countBegin("broadphase");
broadphase();
pc.countEnd();
perf_pop_marker();
perf_push_marker("collision");
pc.countBegin("collision");
collision();
pc.countEnd();
perf_pop_marker();
perf_push_marker("solver");
pc.countBegin("solver");
constraintSolver();
pc.countEnd();
perf_pop_marker();
perf_push_marker("integrate");
pc.countBegin("integrate");
integrate();
pc.countEnd();
perf_pop_marker();
frame++;
if(frame%100 == 0) {
float broadphaseTime = pc.getCountTime(0);
float collisionTime = pc.getCountTime(2);
float solverTime = pc.getCountTime(4);
float integrateTime = pc.getCountTime(6);
SCE_PFX_PRINTF("frame %3d broadphase %.2f collision %.2f solver %.2f integrate %.2f | total %.2f\n",frame,
broadphaseTime,collisionTime,solverTime,integrateTime,
broadphaseTime+collisionTime+solverTime+integrateTime);
}
}
///////////////////////////////////////////////////////////////////////////////
// Create Scene
void createBrick(int id,const PfxVector3 &pos,const PfxQuat &rot,const PfxVector3 &boxSize,PfxFloat mass)
{
PfxBox box(boxSize);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setRestitution(0.0f);
bodies[id].setMass(mass);
bodies[id].setInertia(pfxCalcInertiaBox(boxSize,mass));
states[id].reset();
states[id].setPosition(pos);
states[id].setOrientation(rot);
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
void createWall(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
PfxFloat bodyMass = 0.5f;
PfxFloat diffX = boxSize[0] * 1.02f;
PfxFloat diffY = boxSize[1] * 1.02f;
PfxFloat diffZ = boxSize[2] * 1.02f;
PfxFloat offset = -stackSize * (diffZ * 2.0f) * 0.5f;
PfxVector3 pos(0.0f, diffY, 0.0f);
while(stackSize) {
for(int i=0;i<stackSize;i++) {
pos[2] = offset + (PfxFloat)i * (diffZ * 2.0f);
createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,bodyMass);
}
offset += diffZ;
pos[1] += (diffY * 2.0f);
stackSize--;
}
}
void createPyramid(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
PfxFloat space = 0.0001f;
PfxVector3 pos(0.0f, boxSize[1], 0.0f);
PfxFloat diffX = boxSize[0] * 1.02f;
PfxFloat diffY = boxSize[1] * 1.02f;
PfxFloat diffZ = boxSize[2] * 1.02f;
PfxFloat offsetX = -stackSize * (diffX * 2.0f + space) * 0.5f;
PfxFloat offsetZ = -stackSize * (diffZ * 2.0f + space) * 0.5f;
while(stackSize) {
for(int j=0;j<stackSize;j++) {
pos[2] = offsetZ + (PfxFloat)j * (diffZ * 2.0f + space);
for(int i=0;i<stackSize;i++) {
pos[0] = offsetX + (PfxFloat)i * (diffX * 2.0f + space);
createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,1.0f);
}
}
offsetX += diffX;
offsetZ += diffZ;
pos[1] += (diffY * 2.0f + space);
stackSize--;
}
}
void createTowerCircle(const PfxVector3 &offsetPosition,int stackSize,int rotSize,const PfxVector3 &boxSize)
{
PfxFloat radius = 1.3f * rotSize * boxSize[0] / SCE_PFX_PI;
// create active boxes
PfxQuat rotY = PfxQuat::identity();
PfxFloat posY = boxSize[1];
for(int i=0;i<stackSize;i++) {
for(int j=0;j<rotSize;j++) {
createBrick(numRigidBodies++,offsetPosition+rotate(rotY,PfxVector3(0.0f , posY, radius)),rotY,boxSize,0.5f);
rotY *= PfxQuat::rotationY(SCE_PFX_PI/(rotSize*0.5f));
}
posY += boxSize[1] * 2.0f;
rotY *= PfxQuat::rotationY(SCE_PFX_PI/(PfxFloat)rotSize);
}
}
void createScenePrimitives()
{
// sphere
{
int id = numRigidBodies++;
PfxSphere sphere(1.0f);
PfxShape shape;
shape.reset();
shape.setSphere(sphere);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(1.0f);
bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(-5.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// box
{
int id = numRigidBodies++;
PfxBox box(1.0f,1.0f,1.0f);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(1.0f);
bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(1.0f),1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,5.0f,5.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// capsule
{
int id = numRigidBodies++;
PfxCapsule capsule(1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setCapsule(capsule);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(2.0f);
bodies[id].setInertia(pfxCalcInertiaCylinderX(2.0f,0.5f,2.0f));
states[id].reset();
states[id].setPosition(PfxVector3(5.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// cylinder
{
int id = numRigidBodies++;
PfxCylinder cylinder(0.5f,1.5f);
PfxShape shape;
shape.reset();
shape.setCylinder(cylinder);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaCylinderX(0.5f,1.5f,3.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,10.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// convex mesh
{
PfxCreateConvexMeshParam param;
param.verts = BarrelVtx;
param.numVerts = BarrelVtxCount;
param.vertexStrideBytes = sizeof(float)*6;
param.triangles = BarrelIdx;
param.numTriangles = BarrelIdxCount/3;
param.triangleStrideBytes = sizeof(unsigned short)*3;
PfxInt32 ret = pfxCreateConvexMesh(gConvex,param);
if(ret != SCE_PFX_OK) {
SCE_PFX_PRINTF("Can't create gConvex mesh.\n");
}
int id = numRigidBodies++;
PfxShape shape;
shape.reset();
shape.setConvexMesh(&gConvex);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,15.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// combined primitives
{
int id = numRigidBodies++;
//E Both shapes and incides buffer have to be kept when creating a combined shape.
static PfxShape shapes[3];
PfxUInt16 shapeIds[3]={0,1,2};
collidables[id].reset(shapes,shapeIds,3);
{
PfxBox box(0.5f,0.5f,1.5f);
PfxShape shape;
shape.reset();
shape.setBox(box);
shape.setOffsetPosition(PfxVector3(-2.0f,0.0f,0.0f));
collidables[id].addShape(shape);
}
{
PfxBox box(0.5f,1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setBox(box);
shape.setOffsetPosition(PfxVector3(2.0f,0.0f,0.0f));
collidables[id].addShape(shape);
}
{
PfxCapsule cap(1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setCapsule(cap);
collidables[id].addShape(shape);
}
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(2.5f,1.0f,1.0f),3.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
}
void createSceneJoints()
{
const int n = 10;
int startId = numRigidBodies;
PfxVector3 boxSize(1.0f);
PfxFloat boxMass = 1.0f;
for(int i=0;i<n;i++) {
createBrick(numRigidBodies++,PfxVector3(0,3.0f+i*2.5f*boxSize[1],0),PfxQuat::identity(),boxSize,boxMass);
}
for(int i=startId;i<startId+n;i++) {
PfxRigidState &stateA = states[i];
PfxRigidState &stateB = states[(i+1)%numRigidBodies];
PfxVector3 anchor;
if(i == numRigidBodies-1) {
anchor = stateA.getPosition() + PfxVector3(0,boxSize[1],0);
}
else {
anchor = ( stateA.getPosition() + stateB.getPosition() ) * 0.5f;
}
PfxSwingTwistJointInitParam jparam;
jparam.anchorPoint = anchor;
jparam.twistAxis = PfxVector3(0,1,0);
pfxInitializeSwingTwistJoint(joints[numJoints],stateA,stateB,jparam);
joints[numJoints].m_constraints[4].m_damping = 0.1f;
joints[numJoints].m_constraints[5].m_damping = 0.1f;
pfxUpdateJointPairs(jointPairs[numJoints],numJoints,joints[numJoints],stateA,stateB);
SCE_PFX_ASSERT(numJoints<NUM_JOINTS);
numJoints++;
}
states[startId].setLinearVelocity(PfxVector3(0,0,5));
states[startId].setLinearDamping(0.95f);
states[startId].setAngularDamping(0.95f);
}
void createSceneStacking()
{
createTowerCircle(PfxVector3(0.0f,0.0f,0.0f),8,24,PfxVector3(1));
}
void createSceneBoxGround()
{
int id = numRigidBodies++;
PfxBox box(150.0f,2.5f,150.0f);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,-2.5f,0.0f));
states[id].setMotionType(kPfxMotionTypeFixed);
states[id].setRigidBodyId(id);
}
void createSceneLandscape()
{
PfxCreateLargeTriMeshParam param;
param.verts = LargeMeshVtx;
param.numVerts = LargeMeshVtxCount;
param.vertexStrideBytes = sizeof(float)*6;
param.triangles = LargeMeshIdx;
param.numTriangles = LargeMeshIdxCount/3;
param.triangleStrideBytes = sizeof(unsigned short)*3;
if(gLargeMesh.m_numIslands > 0) {
pfxReleaseLargeTriMesh(gLargeMesh);
}
PfxInt32 ret = pfxCreateLargeTriMesh(gLargeMesh,param);
if(ret != SCE_PFX_OK) {
SCE_PFX_PRINTF("Can't create large mesh.\n");
}
int id = numRigidBodies++;
PfxShape shape;
shape.reset();
shape.setLargeTriMesh(&gLargeMesh);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,-5.0f,0.0f));
states[id].setOrientation(PfxQuat::rotationX(0.5f)*PfxQuat::rotationY(0.7f));
states[id].setMotionType(kPfxMotionTypeFixed);
states[id].setRigidBodyId(id);
}
void physics_create_scene(int sceneId)
{
const int numScenes = 4;
int sid = sceneId % numScenes;
numRigidBodies= 0;
numPairs = 0;
numContacts = 0;
numJoints = 0;
frame = 0;
switch(sid) {
case 0: // simple primitives
createSceneBoxGround();
createScenePrimitives();
break;
case 1: // joints
createSceneBoxGround();
createSceneJoints();
break;
case 2: // stacking
createSceneBoxGround();
createSceneStacking();
break;
case 3: // landscape
createSceneLandscape();
createScenePrimitives();
break;
}
SCE_PFX_PRINTF("----- Size of rigid body buffer ------\n");
SCE_PFX_PRINTF(" size * num = total\n");
SCE_PFX_PRINTF("PfxRigidState %5d * %5d = %5d bytes\n",sizeof(PfxRigidState),numRigidBodies,sizeof(PfxRigidState)*numRigidBodies);
SCE_PFX_PRINTF("PfxRigidBody %5d * %5d = %5d bytes\n",sizeof(PfxRigidBody),numRigidBodies,sizeof(PfxRigidBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxCollidable %5d * %5d = %5d bytes\n",sizeof(PfxCollidable),numRigidBodies,sizeof(PfxCollidable)*numRigidBodies);
SCE_PFX_PRINTF("PfxJoint %5d * %5d = %5d bytes\n",sizeof(PfxJoint),numJoints,sizeof(PfxJoint)*numJoints);
SCE_PFX_PRINTF("PfxSolverBody %5d * %5d = %5d bytes\n",sizeof(PfxSolverBody),numRigidBodies,sizeof(PfxSolverBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxBroadphaseProxy %5d * %5d = %5d bytes\n",sizeof(PfxBroadphaseProxy),numRigidBodies,sizeof(PfxBroadphaseProxy)*numRigidBodies);
SCE_PFX_PRINTF("PfxContactManifold %5d * %5d = %5d bytes\n",sizeof(PfxContactManifold),NUM_CONTACTS,sizeof(PfxContactManifold)*NUM_CONTACTS);
SCE_PFX_PRINTF("PfxBroadphasePair %5d * %5d = %5d bytes\n",sizeof(PfxBroadphasePair),NUM_CONTACTS,sizeof(PfxBroadphasePair)*NUM_CONTACTS);
int totalBytes =
(sizeof(PfxRigidState) + sizeof(PfxRigidBody) + sizeof(PfxCollidable) + sizeof(PfxSolverBody) + sizeof(PfxBroadphaseProxy)) * numRigidBodies +
(sizeof(PfxContactManifold) + sizeof(PfxBroadphasePair)) * NUM_CONTACTS;
SCE_PFX_PRINTF("----------------------------------------------------------\n");
SCE_PFX_PRINTF("Total %5d bytes\n",totalBytes);
// ARA begin insert new code
#ifdef USE_PTHREADS
if (!taskManager)
{
taskManager = PfxCreateTaskManagerPthreads(NUM_THREADS, NUM_THREADS, taskPoolBuff, TASK_MANAGER_POOL_BYTES);
taskManager->initialize();
}
#endif
// ARA end
}
///////////////////////////////////////////////////////////////////////////////
// Initialize / Finalize Engine
bool physics_init()
{
return true;
}
void physics_release()
{
// ARA begin insert new code
if (taskManager)
taskManager->finalize();
// ARA end
}
///////////////////////////////////////////////////////////////////////////////
// Pick
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2)
{
return PfxVector3(0.0f);
}
void physics_pick_update(const PfxVector3 &p)
{
}
void physics_pick_end()
{
}
///////////////////////////////////////////////////////////////////////////////
// Get Information
int physics_get_num_rigidbodies()
{
return numRigidBodies;
}
const PfxRigidState& physics_get_state(int id)
{
return states[id];
}
const PfxRigidBody& physics_get_body(int id)
{
return bodies[id];
}
const PfxCollidable& physics_get_collidable(int id)
{
return collidables[id];
}
int physics_get_num_contacts()
{
return numPairs;
}
const PfxContactManifold &physics_get_contact(int id)
{
return contacts[pfxGetConstraintId(pairs[id])];
}

View File

@@ -0,0 +1,49 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __PHYSICS_FUNC_H__
#define __PHYSICS_FUNC_H__
#define SCE_PFX_USE_PERFCOUNTER
#include "physics_effects.h"
using namespace sce::PhysicsEffects;
//E Simulation
//J ????????
bool physics_init();
void physics_release();
void physics_create_scene(int sceneId);
void physics_simulate();
//E Picking
//J ?????
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2);
void physics_pick_update(const PfxVector3 &p);
void physics_pick_end();
//E Change parameters
//J ????????
int physics_get_num_rigidbodies();
const PfxRigidState& physics_get_state(int id);
const PfxRigidBody& physics_get_body(int id);
const PfxCollidable& physics_get_collidable(int id);
int physics_get_num_contacts();
const PfxContactManifold &physics_get_contact(int id);
#endif /* __PHYSICS_FUNC_H__ */

View File

@@ -0,0 +1,713 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="2_stable.windows"
ProjectGUID="{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}"
RootNamespace="2_stable.win32"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Win32 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
>
<File
RelativePath=".\physics_func.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\physics_func.cpp"
>
</File>
</Filter>
<Filter
Name="Common"
>
<File
RelativePath="..\common\common.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\perf_func.h"
>
</File>
<File
RelativePath="..\common\perf_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\render_func.h"
>
</File>
<File
RelativePath="..\common\render_func.win32.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 2.4)
#this line has to appear before 'PROJECT' in order to be able to disable incremental linking
SET(MSVC_INCREMENTAL_DEFAULT ON)
PROJECT(App_2_Stable)
IF (NOT CMAKE_BUILD_TYPE)
# SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_BUILD_TYPE "Release")
ENDIF (NOT CMAKE_BUILD_TYPE)
OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" ON)
OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
ENDIF(COMMAND cmake_policy)
SET(App_2_Stable_SRCS
main.cpp
physics_func.cpp
../common/ctrl_func.win32.cpp
../common/perf_func.win32.cpp
../common/render_func.win32.cpp
)
SET(App_2_Stable_HDRS
physics_func.h
landscape.h
barrel.h
../common/render_func.h
../common/common.h
../common/ctrl_func.h
../common/perf_func.h
)
INCLUDE_DIRECTORIES(
${PHYSICS_EFFECTS_SOURCE_DIR}/include
# ${VECTOR_MATH_INCLUDE}
)
#LINK_DIRECTORIES(
#
#)
#ADD_DEFINITIONS(-DUNICODE)
#ADD_DEFINITIONS(-D_UNICODE)
ADD_EXECUTABLE(App_2_Stable WIN32
${App_2_Stable_SRCS}
${App_2_Stable_HDRS}
)
TARGET_LINK_LIBRARIES(App_2_Stable
PfxBaseLevel
PfxLowLevel
PfxUtil
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(App_2_Stable PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_2_Stable PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_2_Stable PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF()

View File

@@ -0,0 +1,202 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define BarrelVtxCount 57
#define BarrelIdxCount 180
static float BarrelVtx[] = {
0.0f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
-0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
0.0f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
-0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.957307f,-0.289072f,0.0f,
0.404509f,0.0f,-0.293893f, 0.809017f,0.0f,-0.587785f,
0.5f,0.0f,0.0f, 1.0f,0.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.774478f,-0.289072f,-0.562691f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
-0.154509f,0.0f,-0.475528f, -0.309017f,0.0f,-0.951057f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
-0.107853f,-0.5f,-0.331936f, -0.295824f,-0.289072f,-0.910453f,
-0.404509f,0.0f,-0.293893f, -0.809017f,0.0f,-0.587785f,
-0.282362f,-0.5f,-0.205148f, -0.774478f,-0.289072f,-0.562691f,
-0.5f,0.0f,0.0f, -1.0f,0.0f,0.0f,
-0.349018f,-0.5f,0.0f, -0.957307f,-0.289072f,0.0f,
-0.404508f,0.0f,0.293893f, -0.809017f,0.0f,0.587785f,
-0.282362f,-0.5f,0.205148f, -0.774478f,-0.289072f,0.562691f,
-0.154509f,0.0f,0.475528f, -0.309017f,0.0f,0.951056f,
-0.107853f,-0.5f,0.331936f, -0.295824f,-0.289072f,0.910453f,
0.154509f,0.0f,0.475528f, 0.309017f,0.0f,0.951056f,
0.107853f,-0.5f,0.331936f, 0.295824f,-0.289072f,0.910453f,
0.404509f,0.0f,0.293892f, 0.809017f,0.0f,0.587785f,
0.282362f,-0.5f,0.205148f, 0.774478f,-0.289072f,0.562691f,
0.282362f,0.5f,-0.205148f, 0.774478f,0.289072f,-0.562691f,
0.349018f,0.5f,0.0f, 0.957307f,0.289072f,0.0f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.107853f,0.5f,-0.331936f, -0.295824f,0.289072f,-0.910453f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.282362f,0.5f,-0.205148f, -0.774478f,0.289072f,-0.562691f,
-0.349018f,0.5f,0.0f, -0.957307f,0.289072f,0.0f,
-0.282362f,0.5f,0.205148f, -0.774478f,0.289072f,0.562691f,
-0.107853f,0.5f,0.331936f, -0.295824f,0.289072f,0.910453f,
0.107853f,0.5f,0.331936f, 0.295824f,0.289072f,0.910453f,
0.282362f,0.5f,0.205148f, 0.774478f,0.289072f,0.562691f,
};
static float BarrelTex[] = {
0.0f,0.5f,
0.0f,0.85f,
0.0f,0.75f,
0.0f,0.95f,
0.0f,0.05f,
0.0f,-0.05f,
0.0f,0.15f,
0.0f,0.25f,
0.0f,0.35f,
0.0f,0.45f,
0.0f,0.55f,
0.0f,0.65f,
1.0f,0.5f,
1.0f,0.75f,
1.0f,0.85f,
1.0f,0.95f,
1.0f,-0.05f,
1.0f,0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
0.0f,0.75f,
0.5f,0.85f,
0.5f,0.75f,
0.0f,0.85f,
0.5f,0.95f,
0.0f,0.95f,
0.0f,-0.05f,
0.5f,0.05f,
0.5f,-0.05f,
0.0f,0.05f,
0.5f,0.15f,
0.0f,0.15f,
0.5f,0.25f,
0.0f,0.25f,
0.5f,0.35f,
0.0f,0.35f,
0.5f,0.45f,
0.0f,0.45f,
0.5f,0.55f,
0.0f,0.55f,
0.5f,0.65f,
0.0f,0.65f,
1.0f,0.85f,
1.0f,0.75f,
1.0f,0.95f,
1.0f,0.05f,
1.0f,-0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
};
static unsigned short BarrelIdx[] = {
0,1,2,
0,3,1,
0,4,5,
0,6,4,
0,7,6,
0,8,7,
0,9,8,
0,10,9,
0,11,10,
0,2,11,
12,13,14,
12,14,15,
12,16,17,
12,17,18,
12,18,19,
12,19,20,
12,20,21,
12,21,22,
12,22,23,
12,23,13,
24,25,26,
24,27,25,
27,28,25,
27,29,28,
30,31,32,
30,33,31,
33,34,31,
33,35,34,
35,36,34,
35,37,36,
37,38,36,
37,39,38,
39,40,38,
39,41,40,
41,42,40,
41,43,42,
43,44,42,
43,45,44,
45,26,44,
45,24,26,
26,46,47,
26,25,46,
25,48,46,
25,28,48,
32,49,50,
32,31,49,
31,51,49,
31,34,51,
34,52,51,
34,36,52,
36,53,52,
36,38,53,
38,54,53,
38,40,54,
40,55,54,
40,42,55,
42,56,55,
42,44,56,
44,47,56,
44,26,47,
};

View File

@@ -0,0 +1,318 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define LargeMeshVtxCount 81
#define LargeMeshIdxCount 384
static float LargeMeshVtx[] = {
-25.0f,-2.19407f,18.5625f, 0.232976f,0.967754f,0.0957829f,
-25.0f,0.0644502f,24.75f, 0.188094f,0.871343f,-0.45319f,
-18.75f,-4.50287f,18.5625f, -0.0716098f,0.995449f,0.0628767f,
-18.75f,-0.39999f,24.75f, -0.0602794f,0.895848f,-0.440253f,
-12.5f,-1.2166f,18.5625f, -0.269469f,0.961403f,0.0555879f,
-12.5f,-0.942431f,24.75f, -0.0997841f,0.993258f,0.0589987f,
-6.25f,1.93598f,18.5625f, -0.283933f,0.956351f,-0.0691025f,
-6.25f,-0.445954f,24.75f, -0.180725f,0.942766f,0.280233f,
0.0f,2.76983f,18.5625f, 0.171645f,0.984908f,0.0222501f,
0.0f,2.76642f,24.75f, 0.0784993f,0.995428f,-0.0544117f,
6.25f,-2.53736f,18.5625f, 0.248298f,0.965028f,0.0840741f,
6.25f,-0.915645f,24.75f, 0.164311f,0.945856f,-0.279926f,
12.5f,-1.60054f,18.5625f, -0.180435f,0.983586f,0.00115547f,
12.5f,0.831925f,24.75f, -0.0692495f,0.964821f,-0.253623f,
18.75f,-0.800282f,18.5625f, 0.10755f,0.951538f,0.288112f,
18.75f,-1.47284f,24.75f, 0.232178f,0.972664f,0.00429361f,
25.0f,-2.78379f,18.5625f, 0.1833f,0.937477f,0.295867f,
25.0f,-0.967508f,24.75f, -0.0773477f,0.956641f,-0.280812f,
-25.0f,-0.352038f,12.375f, -0.192222f,0.972435f,0.131987f,
-18.75f,0.681228f,12.375f, -0.107779f,0.962569f,0.248686f,
-12.5f,2.72065f,12.375f, 0.0520846f,0.993034f,0.105692f,
-6.25f,-1.78776f,12.375f, -0.0133223f,0.99674f,-0.0795754f,
0.0f,1.57707f,12.375f, -0.129025f,0.969662f,-0.207627f,
6.25f,0.424356f,12.375f, 0.180995f,0.97074f,0.157815f,
12.5f,0.283234f,12.375f, -0.16285f,0.973539f,0.160316f,
18.75f,2.57015f,12.375f, -0.165454f,0.978339f,0.124408f,
25.0f,3.07363f,12.375f, -0.00454559f,0.988151f,0.153417f,
-25.0f,-0.893751f,6.1875f, -0.0836251f,0.990084f,-0.112876f,
-18.75f,0.930932f,6.1875f, 0.00269413f,0.971838f,-0.235633f,
-12.5f,-0.684529f,6.1875f, -0.010319f,0.927048f,-0.3748f,
-6.25f,-0.661383f,6.1875f, 0.012265f,0.999875f,-0.00994222f,
0.0f,0.385718f,6.1875f, -0.15435f,0.984937f,-0.0779465f,
6.25f,0.589796f,6.1875f, 0.0241717f,0.999582f,-0.0158589f,
12.5f,0.47454f,6.1875f, -0.017184f,0.997953f,-0.0616073f,
18.75f,1.59939f,6.1875f, -0.0902706f,0.957309f,-0.274609f,
25.0f,1.13434f,6.1875f, 0.0346006f,0.957441f,-0.286547f,
-25.0f,0.74548f,0.0f, 0.329903f,0.930812f,0.157334f,
-18.75f,-2.47437f,0.0f, 0.247844f,0.968142f,0.0357041f,
-12.5f,-4.16309f,1.81975e-007f, -0.0623898f,0.997626f,-0.0291436f,
-6.25f,-0.700022f,0.0f, -0.217067f,0.974987f,-0.0477624f,
0.0f,-0.0957388f,0.0f, -0.117693f,0.990712f,-0.068098f,
6.25f,0.614077f,0.0f, -0.0713214f,0.997305f,0.01722f,
12.5f,0.299109f,0.0f, 0.218606f,0.968641f,0.118094f,
18.75f,-1.71753f,0.0f, 0.0339493f,0.985612f,-0.165579f,
25.0f,-1.12638f,0.0f, -0.0547573f,0.989177f,-0.136126f,
-25.0f,-0.403319f,-6.1875f, -0.1263f,0.989211f,-0.074223f,
-18.75f,-0.0730335f,-6.1875f, 0.0173428f,0.965382f,0.260261f,
-12.5f,-0.450125f,-6.1875f, 0.0658811f,0.875f,0.479619f,
-6.25f,-0.180204f,-6.1875f, 0.0116584f,0.981445f,0.19139f,
0.0f,-0.632679f,-6.1875f, -0.0557983f,0.993041f,-0.103716f,
6.25f,0.308409f,-6.1875f, -0.191898f,0.96766f,-0.163737f,
12.5f,2.5011f,-6.1875f, 0.0758397f,0.996403f,-0.0378189f,
18.75f,-1.69303f,-6.1875f, 0.16761f,0.974057f,0.15205f,
25.0f,-0.141349f,-6.1875f, -0.204846f,0.978471f,0.0251341f,
-25.0f,-1.10316f,-12.375f, -0.0350644f,0.993748f,-0.106001f,
-18.75f,1.06711f,-12.375f, -0.309806f,0.919244f,-0.242922f,
-12.5f,3.61544f,-12.375f, -0.0506281f,0.998702f,-0.00561657f,
-6.25f,1.6504f,-12.375f, 0.322294f,0.937465f,0.131477f,
0.0f,-1.60595f,-12.375f, 0.086016f,0.995916f,0.0274459f,
6.25f,-0.849859f,-12.375f, -0.0332811f,0.997087f,0.0686255f,
12.5f,-0.942201f,-12.375f, -0.153559f,0.982185f,-0.108312f,
18.75f,0.494873f,-12.375f, 0.0753195f,0.981472f,0.176181f,
25.0f,-0.333828f,-12.375f, 0.035057f,0.987194f,0.155624f,
-25.0f,2.1862f,-18.5625f, 0.612899f,0.782306f,0.111138f,
-18.75f,-3.38259f,-18.5625f, 0.0194078f,0.992789f,-0.118297f,
-12.5f,-0.880916f,-18.5625f, -0.282251f,0.949875f,-0.13443f,
-6.25f,0.818158f,-18.5625f, 0.1476f,0.981788f,-0.119612f,
0.0f,-1.48019f,-18.5625f, -0.044551f,0.996013f,-0.0772824f,
6.25f,1.47123f,-18.5625f, -0.117036f,0.97986f,0.161792f,
12.5f,0.164076f,-18.5625f, -0.0340355f,0.978993f,0.201034f,
18.75f,2.14568f,-18.5625f, -0.0439269f,0.994859f,0.0912435f,
25.0f,0.626506f,-18.5625f, 0.208015f,0.968592f,0.136229f,
-25.0f,0.296889f,-24.75f, 0.46973f,0.844327f,-0.257809f,
-18.75f,-3.18022f,-24.75f, -0.0226758f,0.998794f,-0.0435401f,
-12.5f,1.8927f,-24.75f, -0.202772f,0.919836f,0.335836f,
-6.25f,1.46387f,-24.75f, 0.224904f,0.955746f,0.189652f,
0.0f,-2.52726f,-24.75f, -0.0435882f,0.993572f,-0.10447f,
6.25f,1.30397f,-24.75f, -0.28646f,0.956525f,-0.0547707f,
12.5f,1.85812f,-24.75f, 0.0521949f,0.979796f,0.193067f,
18.75f,1.56331f,-24.75f, -0.0270784f,0.999629f,-0.00293115f,
25.0f,1.05366f,-24.75f, 0.161f,0.986887f,-0.0115473f,
};
static float LargeMeshTex[] = {
0.125f,0.0f,
0.0f,0.0f,
0.125f,0.125f,
0.0f,0.125f,
0.125f,0.25f,
0.0f,0.25f,
0.125f,0.375f,
0.0f,0.375f,
0.125f,0.5f,
0.0f,0.5f,
0.125f,0.625f,
0.0f,0.625f,
0.125f,0.75f,
0.0f,0.75f,
0.125f,0.875f,
0.0f,0.875f,
0.125f,1.0f,
0.0f,1.0f,
0.25f,0.0f,
0.25f,0.125f,
0.25f,0.25f,
0.25f,0.375f,
0.25f,0.5f,
0.25f,0.625f,
0.25f,0.75f,
0.25f,0.875f,
0.25f,1.0f,
0.375f,0.0f,
0.375f,0.125f,
0.375f,0.25f,
0.375f,0.375f,
0.375f,0.5f,
0.375f,0.625f,
0.375f,0.75f,
0.375f,0.875f,
0.375f,1.0f,
0.5f,0.0f,
0.5f,0.125f,
0.5f,0.25f,
0.5f,0.375f,
0.5f,0.5f,
0.5f,0.625f,
0.5f,0.75f,
0.5f,0.875f,
0.5f,1.0f,
0.625f,0.0f,
0.625f,0.125f,
0.625f,0.25f,
0.625f,0.375f,
0.625f,0.5f,
0.625f,0.625f,
0.625f,0.75f,
0.625f,0.875f,
0.625f,1.0f,
0.75f,0.0f,
0.75f,0.125f,
0.75f,0.25f,
0.75f,0.375f,
0.75f,0.5f,
0.75f,0.625f,
0.75f,0.75f,
0.75f,0.875f,
0.75f,1.0f,
0.875f,0.0f,
0.875f,0.125f,
0.875f,0.25f,
0.875f,0.375f,
0.875f,0.5f,
0.875f,0.625f,
0.875f,0.75f,
0.875f,0.875f,
0.875f,1.0f,
1.0f,0.0f,
1.0f,0.125f,
1.0f,0.25f,
1.0f,0.375f,
1.0f,0.5f,
1.0f,0.625f,
1.0f,0.75f,
1.0f,0.875f,
1.0f,1.0f,
};
static unsigned short LargeMeshIdx[] = {
0,1,2,
3,2,1,
2,3,4,
5,4,3,
4,5,6,
7,6,5,
6,7,8,
9,8,7,
8,9,10,
11,10,9,
10,11,12,
13,12,11,
12,13,14,
15,14,13,
14,15,16,
17,16,15,
18,0,19,
2,19,0,
19,2,20,
4,20,2,
20,4,21,
6,21,4,
21,6,22,
8,22,6,
22,8,23,
10,23,8,
23,10,24,
12,24,10,
24,12,25,
14,25,12,
25,14,26,
16,26,14,
27,18,28,
19,28,18,
28,19,29,
20,29,19,
29,20,30,
21,30,20,
30,21,31,
22,31,21,
31,22,32,
23,32,22,
32,23,33,
24,33,23,
33,24,34,
25,34,24,
34,25,35,
26,35,25,
36,27,37,
28,37,27,
37,28,38,
29,38,28,
38,29,39,
30,39,29,
39,30,40,
31,40,30,
40,31,41,
32,41,31,
41,32,42,
33,42,32,
42,33,43,
34,43,33,
43,34,44,
35,44,34,
45,36,46,
37,46,36,
46,37,47,
38,47,37,
47,38,48,
39,48,38,
48,39,49,
40,49,39,
49,40,50,
41,50,40,
50,41,51,
42,51,41,
51,42,52,
43,52,42,
52,43,53,
44,53,43,
54,45,55,
46,55,45,
55,46,56,
47,56,46,
56,47,57,
48,57,47,
57,48,58,
49,58,48,
58,49,59,
50,59,49,
59,50,60,
51,60,50,
60,51,61,
52,61,51,
61,52,62,
53,62,52,
63,54,64,
55,64,54,
64,55,65,
56,65,55,
65,56,66,
57,66,56,
66,57,67,
58,67,57,
67,58,68,
59,68,58,
68,59,69,
60,69,59,
69,60,70,
61,70,60,
70,61,71,
62,71,61,
72,63,73,
64,73,63,
73,64,74,
65,74,64,
74,65,75,
66,75,65,
75,66,76,
67,76,66,
76,67,77,
68,77,67,
77,68,78,
69,78,68,
78,69,79,
70,79,69,
79,70,80,
71,80,70,
};

View File

@@ -0,0 +1,448 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "../common/common.h"
#include "../common/ctrl_func.h"
#include "../common/render_func.h"
#include "../common/perf_func.h"
#include "physics_func.h"
#include "barrel.h"
#include "landscape.h"
#ifdef _WIN32
#include <gl/gl.h>
#include <gl/glu.h>
#endif
// ARA begin insert new code
#ifdef __ANDROID__
#include <EGL/egl.h>
#include <GLES/gl.h>
#endif
// ARA end
#define SAMPLE_NAME "api_physics_effects/2_stable"
static bool s_isRunning = true;
int sceneId = 2;
bool simulating = false;
int landscapeMeshId;
int convexMeshId;
void render(void)
{
render_begin();
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxTransform3 rbT(state.getOrientation(), state.getPosition());
PfxShapeIterator itrShape(coll);
for(int j=0;j<coll.getNumShapes();j++,++itrShape) {
const PfxShape &shape = *itrShape;
PfxTransform3 offsetT = shape.getOffsetTransform();
PfxTransform3 worldT = rbT * offsetT;
switch(shape.getType()) {
case kPfxShapeSphere:
render_sphere(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getSphere().m_radius));
break;
case kPfxShapeBox:
render_box(
worldT,
PfxVector3(1,1,1),
shape.getBox().m_half);
break;
case kPfxShapeCapsule:
render_capsule(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getCapsule().m_radius),
PfxFloatInVec(shape.getCapsule().m_halfLen));
break;
case kPfxShapeCylinder:
render_cylinder(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getCylinder().m_radius),
PfxFloatInVec(shape.getCylinder().m_halfLen));
break;
case kPfxShapeConvexMesh:
render_mesh(
worldT,
PfxVector3(1,1,1),
convexMeshId);
break;
case kPfxShapeLargeTriMesh:
render_mesh(
worldT,
PfxVector3(1,1,1),
landscapeMeshId);
break;
default:
break;
}
}
}
render_end();
}
int init(void)
{
perf_init();
ctrl_init();
render_init();
physics_init();
landscapeMeshId = render_init_mesh(
LargeMeshVtx,sizeof(float)*6,
LargeMeshVtx+3,sizeof(float)*6,
LargeMeshIdx,sizeof(unsigned short)*3,
LargeMeshVtxCount,LargeMeshIdxCount/3);
convexMeshId = render_init_mesh(
BarrelVtx,sizeof(float)*6,
BarrelVtx+3,sizeof(float)*6,
BarrelIdx,sizeof(unsigned short)*3,
BarrelVtxCount,BarrelIdxCount/3);
return 0;
}
static int shutdown(void)
{
ctrl_release();
render_release();
physics_release();
perf_release();
return 0;
}
void update(void)
{
float angX,angY,r;
render_get_view_angle(angX,angY,r);
ctrl_update();
if(ctrl_button_pressed(BTN_UP)) {
angX -= 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_DOWN)) {
angX += 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_LEFT)) {
angY -= 0.05f;
}
if(ctrl_button_pressed(BTN_RIGHT)) {
angY += 0.05f;
}
if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
r *= 1.1f;
if(r > 500.0f) r = 500.0f;
}
if(ctrl_button_pressed(BTN_ZOOM_IN)) {
r *= 0.9f;
if(r < 1.0f) r = 1.0f;
}
if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
physics_create_scene(sceneId);
}
if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
physics_create_scene(++sceneId);
}
if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
simulating = !simulating;
}
if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
simulating = true;
}
else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
simulating = false;
}
render_set_view_angle(angX,angY,r);
}
#ifndef _WIN32
// ARA begin insert new code
#ifdef __ANDROID__
///////////////////////////////////////////////////////////////////////////////
// sceneChange
//
/// This function is used to change the physics scene on Android devices
///////////////////////////////////////////////////////////////////////////////
void sceneChange()
{
physics_create_scene(sceneId++);
}
#else // __ANDROID__
// ARA end
///////////////////////////////////////////////////////////////////////////////
// Main
int main(void)
{
init();
physics_create_scene(sceneId);
printf("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
while (s_isRunning) {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
shutdown();
printf("## %s: FINISHED ##\n", SAMPLE_NAME);
return 0;
}
// ARA begin insert new code
#endif // __ANDROID__
// ARA end
#else // _WIN32
///////////////////////////////////////////////////////////////////////////////
// WinMain
extern HDC hDC;
extern HGLRC hRC;
HWND hWnd;
HINSTANCE hInstance;
void releaseWindow()
{
if(hRC) {
wglMakeCurrent(0,0);
wglDeleteContext(hRC);
}
if(hDC) ReleaseDC(hWnd,hDC);
if(hWnd) DestroyWindow(hWnd);
UnregisterClass(SAMPLE_NAME,hInstance);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg) {
case WM_SYSCOMMAND:
{
switch (wParam) {
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_SIZE:
render_resize(LOWORD(lParam),HIWORD(lParam));
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
bool createWindow(char* title, int width, int height)
{
WNDCLASS wc;
RECT rect;
rect.left=0;
rect.right=width;
rect.top=0;
rect.bottom=height;
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = SAMPLE_NAME;
if(!RegisterClass(&wc)) {
return false;
}
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
if(!(hWnd=CreateWindowEx(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,SAMPLE_NAME,title,
WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
0,0,rect.right-rect.left,rect.bottom-rect.top,
NULL,NULL,hInstance,NULL))) {
releaseWindow();
return false;
}
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0,
0, 0,
0, 0,
0, 0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if(!(hDC=GetDC(hWnd)))
{
releaseWindow();
OutputDebugString("");
return FALSE;
}
int pixelformat;
if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 ){
OutputDebugString("ChoosePixelFormat Failed....");
return FALSE;
}
if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE){
OutputDebugString("SetPixelFormat Failed....");
return FALSE;
}
if (!(hRC=wglCreateContext(hDC))){
OutputDebugString("Creating HGLRC Failed....");
return FALSE;
}
// Set Vsync
//BOOL (WINAPI *wglSwapIntervalEXT)(int) = NULL;
//if(strstr((char*)glGetString( GL_EXTENSIONS ),"WGL_EXT_swap_control")== 0) {
//}
//else {
//wglSwapIntervalEXT = (BOOL (WINAPI*)(int))wglGetProcAddress("wglSwapIntervalEXT");
//if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
//}
wglMakeCurrent(hDC,hRC);
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
render_resize(width, height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return 0;
}
init();
physics_create_scene(sceneId);
SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
MSG msg;
while(s_isRunning) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if(msg.message==WM_QUIT) {
s_isRunning = false;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
}
shutdown();
SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);
releaseWindow();
return (msg.wParam);
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View File

@@ -0,0 +1,869 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "physics_func.h"
#include "../common/perf_func.h"
///////////////////////////////////////////////////////////////////////////////
// Simulation Data
#define NUM_RIGIDBODIES 5000
#define NUM_JOINTS 5000
#define NUM_CONTACTS 4000
const float timeStep = 0.016f;
const float separateBias = 0.1f;
int iteration = 5;
//J ワールドサイズ
//E World size
PfxVector3 worldCenter(0.0f);
PfxVector3 worldExtent(500.0f);
//J 剛体
//E Rigid body
PfxRigidState states[NUM_RIGIDBODIES];
PfxRigidBody bodies[NUM_RIGIDBODIES];
PfxCollidable collidables[NUM_RIGIDBODIES];
PfxSolverBody solverBodies[NUM_RIGIDBODIES];
int numRigidBodies = 0;
//J 地形を表現するためのラージメッシュ
//E Large mesh for representing a landscape
#include "landscape.h"
PfxLargeTriMesh gLargeMesh;
//J 凸メッシュ
//E Convex Mesh
#include "barrel.h"
PfxConvexMesh gConvex;
//J プロキシ
//E Proxies
PfxBroadphaseProxy proxies[NUM_RIGIDBODIES];
//J ジョイント
//E Joint
PfxConstraintPair jointPairs[NUM_JOINTS];
PfxJoint joints[NUM_JOINTS];
int numJoints = 0;
//J ペア
//E Pairs
unsigned int pairSwap;
unsigned int numPairs[2];
PfxBroadphasePair pairsBuff[2][NUM_CONTACTS];
//J コンタクト
//E Contacts
PfxContactManifold contacts[NUM_CONTACTS];
int numContacts;
PfxUInt32 contactIdPool[NUM_CONTACTS];
int numContactIdPool;
//J 一時バッファ
//E Temporary buffers
#define POOL_BYTES (5*1024*1024)
unsigned char SCE_PFX_ALIGNED(128) poolBuff[POOL_BYTES];
//J 一時バッファ用スタックアロケータ
//E Stack allocator for temporary buffers
PfxHeapManager pool(poolBuff,POOL_BYTES);
///////////////////////////////////////////////////////////////////////////////
// Simulation Function
int frame = 0;
void broadphase()
{
pairSwap = 1-pairSwap;
unsigned int &numPreviousPairs = numPairs[1-pairSwap];
unsigned int &numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *previousPairs = pairsBuff[1-pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
//J 剛体が最も分散している軸を見つける
//E Find the axis along which all rigid bodies are most widely positioned
int axis = 0;
{
PfxVector3 s(0.0f),s2(0.0f);
for(int i=0;i<numRigidBodies;i++) {
PfxVector3 c = states[i].getPosition();
s += c;
s2 += mulPerElem(c,c);
}
PfxVector3 v = s2 - mulPerElem(s,s) / (float)numRigidBodies;
if(v[1] > v[0]) axis = 1;
if(v[2] > v[axis]) axis = 2;
}
//J ブロードフェーズプロキシの更新
//E Create broadpahse proxies
{
for(int i=0;i<numRigidBodies;i++) {
pfxUpdateBroadphaseProxy(proxies[i],states[i],collidables[i],worldCenter,worldExtent,axis);
}
int workBytes = sizeof(PfxBroadphaseProxy) * numRigidBodies;
void *workBuff = pool.allocate(workBytes);
pfxParallelSort(proxies,numRigidBodies,workBuff,workBytes);
pool.deallocate(workBuff);
}
//J 交差ペア探索
//E Find overlapped pairs
{
PfxFindPairsParam findPairsParam;
findPairsParam.pairBytes = pfxGetPairBytesOfFindPairs(NUM_CONTACTS);
findPairsParam.pairBuff = pool.allocate(findPairsParam.pairBytes);
findPairsParam.workBytes = pfxGetWorkBytesOfFindPairs(NUM_CONTACTS);
findPairsParam.workBuff = pool.allocate(findPairsParam.workBytes);
findPairsParam.proxies = proxies;
findPairsParam.numProxies = numRigidBodies;
findPairsParam.maxPairs = NUM_CONTACTS;
findPairsParam.axis = axis;
PfxFindPairsResult findPairsResult;
int ret = pfxFindPairs(findPairsParam,findPairsResult);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxFindPairs failed %d\n",ret);
pool.deallocate(findPairsParam.workBuff);
//J 交差ペア合成
//E Decompose overlapped pairs into 3 arrays
PfxDecomposePairsParam decomposePairsParam;
decomposePairsParam.pairBytes = pfxGetPairBytesOfDecomposePairs(numPreviousPairs,findPairsResult.numPairs);
decomposePairsParam.pairBuff = pool.allocate(decomposePairsParam.pairBytes);
decomposePairsParam.workBytes = pfxGetWorkBytesOfDecomposePairs(numPreviousPairs,findPairsResult.numPairs);
decomposePairsParam.workBuff = pool.allocate(decomposePairsParam.workBytes);
decomposePairsParam.previousPairs = previousPairs;
decomposePairsParam.numPreviousPairs = numPreviousPairs;
decomposePairsParam.currentPairs = findPairsResult.pairs; // Set pairs from pfxFindPairs()
decomposePairsParam.numCurrentPairs = findPairsResult.numPairs; // Set the number of pairs from pfxFindPairs()
PfxDecomposePairsResult decomposePairsResult;
ret = pfxDecomposePairs(decomposePairsParam,decomposePairsResult);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxDecomposePairs failed %d\n",ret);
pool.deallocate(decomposePairsParam.workBuff);
PfxBroadphasePair *outNewPairs = decomposePairsResult.outNewPairs;
PfxBroadphasePair *outKeepPairs = decomposePairsResult.outKeepPairs;
PfxBroadphasePair *outRemovePairs = decomposePairsResult.outRemovePairs;
PfxUInt32 numOutNewPairs = decomposePairsResult.numOutNewPairs;
PfxUInt32 numOutKeepPairs = decomposePairsResult.numOutKeepPairs;
PfxUInt32 numOutRemovePairs = decomposePairsResult.numOutRemovePairs;
//J 廃棄ペアのコンタクトをプールに戻す
//E Put removed contacts into the contact pool
for(PfxUInt32 i=0;i<numOutRemovePairs;i++) {
contactIdPool[numContactIdPool++] = pfxGetContactId(outRemovePairs[i]);
}
//J 新規ペアのコンタクトのリンクと初期化
//E Add new contacts and initialize
for(PfxUInt32 i=0;i<numOutNewPairs;i++) {
int cId = 0;
if(numContactIdPool > 0) {
cId = contactIdPool[--numContactIdPool];
}
else {
cId = numContacts++;
}
if(cId >= NUM_CONTACTS) {
cId = 0;
}
SCE_PFX_ASSERT(cId < NUM_CONTACTS);
pfxSetContactId(outNewPairs[i],cId);
PfxContactManifold &contact = contacts[cId];
contact.reset(pfxGetObjectIdA(outNewPairs[i]),pfxGetObjectIdB(outNewPairs[i]));
}
//J 新規ペアと維持ペアを合成
//E Merge 'new' and 'keep' pairs
numCurrentPairs = 0;
for(PfxUInt32 i=0;i<numOutKeepPairs;i++) {
currentPairs[numCurrentPairs++] = outKeepPairs[i];
}
for(PfxUInt32 i=0;i<numOutNewPairs;i++) {
currentPairs[numCurrentPairs++] = outNewPairs[i];
}
pool.deallocate(decomposePairsParam.pairBuff);
pool.deallocate(findPairsParam.pairBuff);
}
{
int workBytes = sizeof(PfxBroadphasePair) * numCurrentPairs;
void *workBuff = pool.allocate(workBytes);
pfxParallelSort(currentPairs,numCurrentPairs,workBuff,workBytes);
pool.deallocate(workBuff);
}
}
void collision()
{
unsigned int numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
//J 衝突検出
//E Detect collisions
{
PfxDetectCollisionParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetCollidables = collidables;
param.numRigidBodies = numRigidBodies;
int ret = pfxDetectCollision(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxDetectCollision failed %d\n",ret);
}
//J リフレッシュ
//E Refresh contacts
{
PfxRefreshContactsParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.numRigidBodies = numRigidBodies;
int ret = pfxRefreshContacts(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxRefreshContacts failed %d\n",ret);
}
}
void constraintSolver()
{
PfxPerfCounter pc;
unsigned int numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
pc.countBegin("setup solver bodies");
{
PfxSetupSolverBodiesParam param;
param.states = states;
param.bodies = bodies;
param.solverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
int ret = pfxSetupSolverBodies(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupSolverBodies failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup contact constraints");
{
PfxSetupContactConstraintsParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
param.separateBias = separateBias;
int ret = pfxSetupContactConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup joint constraints");
{
PfxSetupJointConstraintsParam param;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
for(int i=0;i<numJoints;i++) {
pfxUpdateJointPairs(jointPairs[i],i,joints[i],states[joints[i].m_rigidBodyIdA],states[joints[i].m_rigidBodyIdB]);
}
int ret = pfxSetupJointConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("solve constraints");
{
PfxSolveConstraintsParam param;
param.workBytes = pfxGetWorkBytesOfSolveConstraints(numRigidBodies,numCurrentPairs,numJoints);
param.workBuff = pool.allocate(param.workBytes);
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.iteration = iteration;
int ret = pfxSolveConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSolveConstraints failed %d\n",ret);
pool.deallocate(param.workBuff);
}
pc.countEnd();
//pc.printCount();
}
void integrate()
{
PfxUpdateRigidStatesParam param;
param.states = states;
param.bodies = bodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
pfxUpdateRigidStates(param);
}
void physics_simulate()
{
PfxPerfCounter pc;
for(int i=1;i<numRigidBodies;i++) {
pfxApplyExternalForce(states[i],bodies[i],bodies[i].getMass()*PfxVector3(0.0f,-9.8f,0.0f),PfxVector3(0.0f),timeStep);
}
perf_push_marker("broadphase");
pc.countBegin("broadphase");
broadphase();
pc.countEnd();
perf_pop_marker();
perf_push_marker("collision");
pc.countBegin("collision");
collision();
pc.countEnd();
perf_pop_marker();
perf_push_marker("solver");
pc.countBegin("solver");
constraintSolver();
pc.countEnd();
perf_pop_marker();
perf_push_marker("integrate");
pc.countBegin("integrate");
integrate();
pc.countEnd();
perf_pop_marker();
frame++;
if(frame%100 == 0) {
float broadphaseTime = pc.getCountTime(0);
float collisionTime = pc.getCountTime(2);
float solverTime = pc.getCountTime(4);
float integrateTime = pc.getCountTime(6);
SCE_PFX_PRINTF("frame %3d broadphase %.2f collision %.2f solver %.2f integrate %.2f | total %.2f\n",frame,
broadphaseTime,collisionTime,solverTime,integrateTime,
broadphaseTime+collisionTime+solverTime+integrateTime);
}
}
///////////////////////////////////////////////////////////////////////////////
// Create Scene
void createBrick(int id,const PfxVector3 &pos,const PfxQuat &rot,const PfxVector3 &boxSize,PfxFloat mass)
{
PfxBox box(boxSize);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setRestitution(0.0f);
bodies[id].setMass(mass);
bodies[id].setInertia(pfxCalcInertiaBox(boxSize,mass));
states[id].reset();
states[id].setPosition(pos);
states[id].setOrientation(rot);
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
void createWall(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
PfxFloat bodyMass = 0.5f;
PfxFloat diffX = boxSize[0] * 1.02f;
PfxFloat diffY = boxSize[1] * 1.02f;
PfxFloat diffZ = boxSize[2] * 1.02f;
PfxFloat offset = -stackSize * (diffZ * 2.0f) * 0.5f;
PfxVector3 pos(0.0f, diffY, 0.0f);
while(stackSize) {
for(int i=0;i<stackSize;i++) {
pos[2] = offset + (PfxFloat)i * (diffZ * 2.0f);
createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,bodyMass);
}
offset += diffZ;
pos[1] += (diffY * 2.0f);
stackSize--;
}
}
void createPyramid(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
PfxFloat space = 0.0001f;
PfxVector3 pos(0.0f, boxSize[1], 0.0f);
PfxFloat diffX = boxSize[0] * 1.02f;
PfxFloat diffY = boxSize[1] * 1.02f;
PfxFloat diffZ = boxSize[2] * 1.02f;
PfxFloat offsetX = -stackSize * (diffX * 2.0f + space) * 0.5f;
PfxFloat offsetZ = -stackSize * (diffZ * 2.0f + space) * 0.5f;
while(stackSize) {
for(int j=0;j<stackSize;j++) {
pos[2] = offsetZ + (PfxFloat)j * (diffZ * 2.0f + space);
for(int i=0;i<stackSize;i++) {
pos[0] = offsetX + (PfxFloat)i * (diffX * 2.0f + space);
createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,1.0f);
}
}
offsetX += diffX;
offsetZ += diffZ;
pos[1] += (diffY * 2.0f + space);
stackSize--;
}
}
void createTowerCircle(const PfxVector3 &offsetPosition,int stackSize,int rotSize,const PfxVector3 &boxSize)
{
PfxFloat radius = 1.3f * rotSize * boxSize[0] / SCE_PFX_PI;
// create active boxes
PfxQuat rotY = PfxQuat::identity();
PfxFloat posY = boxSize[1];
for(int i=0;i<stackSize;i++) {
for(int j=0;j<rotSize;j++) {
createBrick(numRigidBodies++,offsetPosition+rotate(rotY,PfxVector3(0.0f , posY, radius)),rotY,boxSize,0.5f);
rotY *= PfxQuat::rotationY(SCE_PFX_PI/(rotSize*0.5f));
}
posY += boxSize[1] * 2.0f;
rotY *= PfxQuat::rotationY(SCE_PFX_PI/(PfxFloat)rotSize);
}
}
void createScenePrimitives()
{
// sphere
{
int id = numRigidBodies++;
PfxSphere sphere(1.0f);
PfxShape shape;
shape.reset();
shape.setSphere(sphere);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(1.0f);
bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(-5.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// box
{
int id = numRigidBodies++;
PfxBox box(1.0f,1.0f,1.0f);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(1.0f);
bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(1.0f),1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,5.0f,5.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// capsule
{
int id = numRigidBodies++;
PfxCapsule capsule(1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setCapsule(capsule);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(2.0f);
bodies[id].setInertia(pfxCalcInertiaCylinderX(2.0f,0.5f,2.0f));
states[id].reset();
states[id].setPosition(PfxVector3(5.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// cylinder
{
int id = numRigidBodies++;
PfxCylinder cylinder(0.5f,1.5f);
PfxShape shape;
shape.reset();
shape.setCylinder(cylinder);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaCylinderX(0.5f,1.5f,3.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,10.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// convex mesh
{
PfxCreateConvexMeshParam param;
param.verts = BarrelVtx;
param.numVerts = BarrelVtxCount;
param.vertexStrideBytes = sizeof(float)*6;
param.triangles = BarrelIdx;
param.numTriangles = BarrelIdxCount/3;
param.triangleStrideBytes = sizeof(unsigned short)*3;
PfxInt32 ret = pfxCreateConvexMesh(gConvex,param);
if(ret != SCE_PFX_OK) {
SCE_PFX_PRINTF("Can't create gConvex mesh.\n");
}
int id = numRigidBodies++;
PfxShape shape;
shape.reset();
shape.setConvexMesh(&gConvex);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,15.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// combined primitives
{
int id = numRigidBodies++;
//E Both shapes and incides buffer have to be kept when creating a combined shape.
static PfxShape shapes[3];
PfxUInt16 shapeIds[3]={0,1,2};
collidables[id].reset(shapes,shapeIds,3);
{
PfxBox box(0.5f,0.5f,1.5f);
PfxShape shape;
shape.reset();
shape.setBox(box);
shape.setOffsetPosition(PfxVector3(-2.0f,0.0f,0.0f));
collidables[id].addShape(shape);
}
{
PfxBox box(0.5f,1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setBox(box);
shape.setOffsetPosition(PfxVector3(2.0f,0.0f,0.0f));
collidables[id].addShape(shape);
}
{
PfxCapsule cap(1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setCapsule(cap);
collidables[id].addShape(shape);
}
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(2.5f,1.0f,1.0f),3.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
}
void createSceneJoints()
{
const int n = 10;
int startId = numRigidBodies;
PfxVector3 boxSize(1.0f);
PfxFloat boxMass = 1.0f;
for(int i=0;i<n;i++) {
createBrick(numRigidBodies++,PfxVector3(0,3.0f+i*2.5f*boxSize[1],0),PfxQuat::identity(),boxSize,boxMass);
}
for(int i=startId;i<startId+n;i++) {
PfxRigidState &stateA = states[i];
PfxRigidState &stateB = states[(i+1)%numRigidBodies];
PfxVector3 anchor;
if(i == numRigidBodies-1) {
anchor = stateA.getPosition() + PfxVector3(0,boxSize[1],0);
}
else {
anchor = ( stateA.getPosition() + stateB.getPosition() ) * 0.5f;
}
PfxSwingTwistJointInitParam jparam;
jparam.anchorPoint = anchor;
jparam.twistAxis = PfxVector3(0,1,0);
pfxInitializeSwingTwistJoint(joints[numJoints],stateA,stateB,jparam);
joints[numJoints].m_constraints[4].m_damping = 0.1f;
joints[numJoints].m_constraints[5].m_damping = 0.1f;
pfxUpdateJointPairs(jointPairs[numJoints],numJoints,joints[numJoints],stateA,stateB);
SCE_PFX_ASSERT(numJoints<NUM_JOINTS);
numJoints++;
}
states[startId].setLinearVelocity(PfxVector3(0,0,5));
states[startId].setLinearDamping(0.95f);
states[startId].setAngularDamping(0.95f);
}
void createSceneStacking()
{
const float cubeSize = 1.0f;
createPyramid(PfxVector3(-20.0f,0.0f,0.0f),12,PfxVector3(cubeSize,cubeSize,cubeSize));
createWall(PfxVector3(-2.0f,0.0f,0.0f),12,PfxVector3(cubeSize,cubeSize,cubeSize));
createWall(PfxVector3(4.0f,0.0f,0.0f),12,PfxVector3(cubeSize,cubeSize,cubeSize));
createWall(PfxVector3(10.0f,0.0f,0.0f),12,PfxVector3(cubeSize,cubeSize,cubeSize));
createTowerCircle(PfxVector3(25.0f,0.0f,0.0f),8,24,PfxVector3(cubeSize,cubeSize,cubeSize));
// createTowerCircle(PfxVector3(0.0f,0.0f,0.0f),8,24,PfxVector3(1));
}
void createSceneBoxGround()
{
int id = numRigidBodies++;
PfxBox box(150.0f,2.5f,150.0f);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,-2.5f,0.0f));
states[id].setMotionType(kPfxMotionTypeFixed);
states[id].setRigidBodyId(id);
}
void createSceneLandscape()
{
PfxCreateLargeTriMeshParam param;
param.verts = LargeMeshVtx;
param.numVerts = LargeMeshVtxCount;
param.vertexStrideBytes = sizeof(float)*6;
param.triangles = LargeMeshIdx;
param.numTriangles = LargeMeshIdxCount/3;
param.triangleStrideBytes = sizeof(unsigned short)*3;
if(gLargeMesh.m_numIslands > 0) {
pfxReleaseLargeTriMesh(gLargeMesh);
}
PfxInt32 ret = pfxCreateLargeTriMesh(gLargeMesh,param);
if(ret != SCE_PFX_OK) {
SCE_PFX_PRINTF("Can't create large mesh.\n");
}
int id = numRigidBodies++;
PfxShape shape;
shape.reset();
shape.setLargeTriMesh(&gLargeMesh);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,-5.0f,0.0f));
states[id].setOrientation(PfxQuat::rotationX(0.5f)*PfxQuat::rotationY(0.7f));
states[id].setMotionType(kPfxMotionTypeFixed);
states[id].setRigidBodyId(id);
}
void physics_create_scene(int sceneId)
{
const int numScenes = 4;
int sid = sceneId % numScenes;
numRigidBodies= 0;
pairSwap = 0;
numPairs[0] = 0;
numPairs[1] = 0;
numContacts = 0;
numContactIdPool = 0;
numJoints = 0;
frame = 0;
switch(sid) {
case 0: // simple primitives
createSceneBoxGround();
createScenePrimitives();
break;
case 1: // joints
createSceneBoxGround();
createSceneJoints();
break;
case 2: // stacking
createSceneBoxGround();
createSceneStacking();
break;
case 3: // landscape
createSceneLandscape();
createScenePrimitives();
break;
}
SCE_PFX_PRINTF("----- Size of rigid body buffer ------\n");
SCE_PFX_PRINTF(" size * num = total\n");
SCE_PFX_PRINTF("PfxRigidState %5d * %5d = %5d bytes\n",sizeof(PfxRigidState),numRigidBodies,sizeof(PfxRigidState)*numRigidBodies);
SCE_PFX_PRINTF("PfxRigidBody %5d * %5d = %5d bytes\n",sizeof(PfxRigidBody),numRigidBodies,sizeof(PfxRigidBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxCollidable %5d * %5d = %5d bytes\n",sizeof(PfxCollidable),numRigidBodies,sizeof(PfxCollidable)*numRigidBodies);
SCE_PFX_PRINTF("PfxJoint %5d * %5d = %5d bytes\n",sizeof(PfxJoint),numJoints,sizeof(PfxJoint)*numJoints);
SCE_PFX_PRINTF("PfxSolverBody %5d * %5d = %5d bytes\n",sizeof(PfxSolverBody),numRigidBodies,sizeof(PfxSolverBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxBroadphaseProxy %5d * %5d = %5d bytes\n",sizeof(PfxBroadphaseProxy),numRigidBodies,sizeof(PfxBroadphaseProxy)*numRigidBodies);
SCE_PFX_PRINTF("PfxContactManifold %5d * %5d = %5d bytes\n",sizeof(PfxContactManifold),NUM_CONTACTS,sizeof(PfxContactManifold)*NUM_CONTACTS);
SCE_PFX_PRINTF("PfxBroadphasePair %5d * %5d = %5d bytes\n",sizeof(PfxBroadphasePair),NUM_CONTACTS,sizeof(PfxBroadphasePair)*NUM_CONTACTS);
int totalBytes =
(sizeof(PfxRigidState) + sizeof(PfxRigidBody) + sizeof(PfxCollidable) + sizeof(PfxSolverBody) + sizeof(PfxBroadphaseProxy)) * numRigidBodies +
(sizeof(PfxContactManifold) + sizeof(PfxBroadphasePair)) * NUM_CONTACTS;
SCE_PFX_PRINTF("----------------------------------------------------------\n");
SCE_PFX_PRINTF("Total %5d bytes\n",totalBytes);
}
///////////////////////////////////////////////////////////////////////////////
// Initialize / Finalize Engine
bool physics_init()
{
return true;
}
void physics_release()
{
}
///////////////////////////////////////////////////////////////////////////////
// Pick
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2)
{
return PfxVector3(0.0f);
}
void physics_pick_update(const PfxVector3 &p)
{
}
void physics_pick_end()
{
}
///////////////////////////////////////////////////////////////////////////////
// Get Information
int physics_get_num_rigidbodies()
{
return numRigidBodies;
}
const PfxRigidState& physics_get_state(int id)
{
return states[id];
}
const PfxRigidBody& physics_get_body(int id)
{
return bodies[id];
}
const PfxCollidable& physics_get_collidable(int id)
{
return collidables[id];
}
int physics_get_num_contacts()
{
return numPairs[pairSwap];
}
const PfxContactManifold &physics_get_contact(int id)
{
return contacts[pfxGetConstraintId(pairsBuff[pairSwap][id])];
}

View File

@@ -0,0 +1,49 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __PHYSICS_FUNC_H__
#define __PHYSICS_FUNC_H__
#define SCE_PFX_USE_PERFCOUNTER
#include "physics_effects.h"
using namespace sce::PhysicsEffects;
//E Simulation
//J シミュレーション
bool physics_init();
void physics_release();
void physics_create_scene(int sceneId);
void physics_simulate();
//E Picking
//J ピッキング
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2);
void physics_pick_update(const PfxVector3 &p);
void physics_pick_end();
//E Change parameters
//J パラメータの取得
int physics_get_num_rigidbodies();
const PfxRigidState& physics_get_state(int id);
const PfxRigidBody& physics_get_body(int id);
const PfxCollidable& physics_get_collidable(int id);
int physics_get_num_contacts();
const PfxContactManifold &physics_get_contact(int id);
#endif /* __PHYSICS_FUNC_H__ */

View File

@@ -0,0 +1,22 @@
project "2_stable"
kind "WindowedApp"
targetdir "../../../bin"
includedirs {"../../../include"}
links {
"physicseffects2_lowlevel",
"physicseffects2_baselevel",
"physicseffects2_util",
"opengl32"
}
flags {"WinMain"}
files {
"main.cpp",
"physics_func.cpp",
"../common/ctrl_func.win32.cpp",
"../common/perf_func.win32.cpp",
"../common/render_func.win32.cpp"
}

View File

@@ -0,0 +1,202 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define BarrelVtxCount 57
#define BarrelIdxCount 180
static float BarrelVtx[] = {
0.0f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
-0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
0.0f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
-0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.957307f,-0.289072f,0.0f,
0.404509f,0.0f,-0.293893f, 0.809017f,0.0f,-0.587785f,
0.5f,0.0f,0.0f, 1.0f,0.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.774478f,-0.289072f,-0.562691f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
-0.154509f,0.0f,-0.475528f, -0.309017f,0.0f,-0.951057f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
-0.107853f,-0.5f,-0.331936f, -0.295824f,-0.289072f,-0.910453f,
-0.404509f,0.0f,-0.293893f, -0.809017f,0.0f,-0.587785f,
-0.282362f,-0.5f,-0.205148f, -0.774478f,-0.289072f,-0.562691f,
-0.5f,0.0f,0.0f, -1.0f,0.0f,0.0f,
-0.349018f,-0.5f,0.0f, -0.957307f,-0.289072f,0.0f,
-0.404508f,0.0f,0.293893f, -0.809017f,0.0f,0.587785f,
-0.282362f,-0.5f,0.205148f, -0.774478f,-0.289072f,0.562691f,
-0.154509f,0.0f,0.475528f, -0.309017f,0.0f,0.951056f,
-0.107853f,-0.5f,0.331936f, -0.295824f,-0.289072f,0.910453f,
0.154509f,0.0f,0.475528f, 0.309017f,0.0f,0.951056f,
0.107853f,-0.5f,0.331936f, 0.295824f,-0.289072f,0.910453f,
0.404509f,0.0f,0.293892f, 0.809017f,0.0f,0.587785f,
0.282362f,-0.5f,0.205148f, 0.774478f,-0.289072f,0.562691f,
0.282362f,0.5f,-0.205148f, 0.774478f,0.289072f,-0.562691f,
0.349018f,0.5f,0.0f, 0.957307f,0.289072f,0.0f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.107853f,0.5f,-0.331936f, -0.295824f,0.289072f,-0.910453f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.282362f,0.5f,-0.205148f, -0.774478f,0.289072f,-0.562691f,
-0.349018f,0.5f,0.0f, -0.957307f,0.289072f,0.0f,
-0.282362f,0.5f,0.205148f, -0.774478f,0.289072f,0.562691f,
-0.107853f,0.5f,0.331936f, -0.295824f,0.289072f,0.910453f,
0.107853f,0.5f,0.331936f, 0.295824f,0.289072f,0.910453f,
0.282362f,0.5f,0.205148f, 0.774478f,0.289072f,0.562691f,
};
static float BarrelTex[] = {
0.0f,0.5f,
0.0f,0.85f,
0.0f,0.75f,
0.0f,0.95f,
0.0f,0.05f,
0.0f,-0.05f,
0.0f,0.15f,
0.0f,0.25f,
0.0f,0.35f,
0.0f,0.45f,
0.0f,0.55f,
0.0f,0.65f,
1.0f,0.5f,
1.0f,0.75f,
1.0f,0.85f,
1.0f,0.95f,
1.0f,-0.05f,
1.0f,0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
0.0f,0.75f,
0.5f,0.85f,
0.5f,0.75f,
0.0f,0.85f,
0.5f,0.95f,
0.0f,0.95f,
0.0f,-0.05f,
0.5f,0.05f,
0.5f,-0.05f,
0.0f,0.05f,
0.5f,0.15f,
0.0f,0.15f,
0.5f,0.25f,
0.0f,0.25f,
0.5f,0.35f,
0.0f,0.35f,
0.5f,0.45f,
0.0f,0.45f,
0.5f,0.55f,
0.0f,0.55f,
0.5f,0.65f,
0.0f,0.65f,
1.0f,0.85f,
1.0f,0.75f,
1.0f,0.95f,
1.0f,0.05f,
1.0f,-0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
};
static unsigned short BarrelIdx[] = {
0,1,2,
0,3,1,
0,4,5,
0,6,4,
0,7,6,
0,8,7,
0,9,8,
0,10,9,
0,11,10,
0,2,11,
12,13,14,
12,14,15,
12,16,17,
12,17,18,
12,18,19,
12,19,20,
12,20,21,
12,21,22,
12,22,23,
12,23,13,
24,25,26,
24,27,25,
27,28,25,
27,29,28,
30,31,32,
30,33,31,
33,34,31,
33,35,34,
35,36,34,
35,37,36,
37,38,36,
37,39,38,
39,40,38,
39,41,40,
41,42,40,
41,43,42,
43,44,42,
43,45,44,
45,26,44,
45,24,26,
26,46,47,
26,25,46,
25,48,46,
25,28,48,
32,49,50,
32,31,49,
31,51,49,
31,34,51,
34,52,51,
34,36,52,
36,53,52,
36,38,53,
38,54,53,
38,40,54,
40,55,54,
40,42,55,
42,56,55,
42,44,56,
44,47,56,
44,26,47,
};

View File

@@ -0,0 +1,318 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define LargeMeshVtxCount 81
#define LargeMeshIdxCount 384
static float LargeMeshVtx[] = {
-25.0f,-2.19407f,18.5625f, 0.232976f,0.967754f,0.0957829f,
-25.0f,0.0644502f,24.75f, 0.188094f,0.871343f,-0.45319f,
-18.75f,-4.50287f,18.5625f, -0.0716098f,0.995449f,0.0628767f,
-18.75f,-0.39999f,24.75f, -0.0602794f,0.895848f,-0.440253f,
-12.5f,-1.2166f,18.5625f, -0.269469f,0.961403f,0.0555879f,
-12.5f,-0.942431f,24.75f, -0.0997841f,0.993258f,0.0589987f,
-6.25f,1.93598f,18.5625f, -0.283933f,0.956351f,-0.0691025f,
-6.25f,-0.445954f,24.75f, -0.180725f,0.942766f,0.280233f,
0.0f,2.76983f,18.5625f, 0.171645f,0.984908f,0.0222501f,
0.0f,2.76642f,24.75f, 0.0784993f,0.995428f,-0.0544117f,
6.25f,-2.53736f,18.5625f, 0.248298f,0.965028f,0.0840741f,
6.25f,-0.915645f,24.75f, 0.164311f,0.945856f,-0.279926f,
12.5f,-1.60054f,18.5625f, -0.180435f,0.983586f,0.00115547f,
12.5f,0.831925f,24.75f, -0.0692495f,0.964821f,-0.253623f,
18.75f,-0.800282f,18.5625f, 0.10755f,0.951538f,0.288112f,
18.75f,-1.47284f,24.75f, 0.232178f,0.972664f,0.00429361f,
25.0f,-2.78379f,18.5625f, 0.1833f,0.937477f,0.295867f,
25.0f,-0.967508f,24.75f, -0.0773477f,0.956641f,-0.280812f,
-25.0f,-0.352038f,12.375f, -0.192222f,0.972435f,0.131987f,
-18.75f,0.681228f,12.375f, -0.107779f,0.962569f,0.248686f,
-12.5f,2.72065f,12.375f, 0.0520846f,0.993034f,0.105692f,
-6.25f,-1.78776f,12.375f, -0.0133223f,0.99674f,-0.0795754f,
0.0f,1.57707f,12.375f, -0.129025f,0.969662f,-0.207627f,
6.25f,0.424356f,12.375f, 0.180995f,0.97074f,0.157815f,
12.5f,0.283234f,12.375f, -0.16285f,0.973539f,0.160316f,
18.75f,2.57015f,12.375f, -0.165454f,0.978339f,0.124408f,
25.0f,3.07363f,12.375f, -0.00454559f,0.988151f,0.153417f,
-25.0f,-0.893751f,6.1875f, -0.0836251f,0.990084f,-0.112876f,
-18.75f,0.930932f,6.1875f, 0.00269413f,0.971838f,-0.235633f,
-12.5f,-0.684529f,6.1875f, -0.010319f,0.927048f,-0.3748f,
-6.25f,-0.661383f,6.1875f, 0.012265f,0.999875f,-0.00994222f,
0.0f,0.385718f,6.1875f, -0.15435f,0.984937f,-0.0779465f,
6.25f,0.589796f,6.1875f, 0.0241717f,0.999582f,-0.0158589f,
12.5f,0.47454f,6.1875f, -0.017184f,0.997953f,-0.0616073f,
18.75f,1.59939f,6.1875f, -0.0902706f,0.957309f,-0.274609f,
25.0f,1.13434f,6.1875f, 0.0346006f,0.957441f,-0.286547f,
-25.0f,0.74548f,0.0f, 0.329903f,0.930812f,0.157334f,
-18.75f,-2.47437f,0.0f, 0.247844f,0.968142f,0.0357041f,
-12.5f,-4.16309f,1.81975e-007f, -0.0623898f,0.997626f,-0.0291436f,
-6.25f,-0.700022f,0.0f, -0.217067f,0.974987f,-0.0477624f,
0.0f,-0.0957388f,0.0f, -0.117693f,0.990712f,-0.068098f,
6.25f,0.614077f,0.0f, -0.0713214f,0.997305f,0.01722f,
12.5f,0.299109f,0.0f, 0.218606f,0.968641f,0.118094f,
18.75f,-1.71753f,0.0f, 0.0339493f,0.985612f,-0.165579f,
25.0f,-1.12638f,0.0f, -0.0547573f,0.989177f,-0.136126f,
-25.0f,-0.403319f,-6.1875f, -0.1263f,0.989211f,-0.074223f,
-18.75f,-0.0730335f,-6.1875f, 0.0173428f,0.965382f,0.260261f,
-12.5f,-0.450125f,-6.1875f, 0.0658811f,0.875f,0.479619f,
-6.25f,-0.180204f,-6.1875f, 0.0116584f,0.981445f,0.19139f,
0.0f,-0.632679f,-6.1875f, -0.0557983f,0.993041f,-0.103716f,
6.25f,0.308409f,-6.1875f, -0.191898f,0.96766f,-0.163737f,
12.5f,2.5011f,-6.1875f, 0.0758397f,0.996403f,-0.0378189f,
18.75f,-1.69303f,-6.1875f, 0.16761f,0.974057f,0.15205f,
25.0f,-0.141349f,-6.1875f, -0.204846f,0.978471f,0.0251341f,
-25.0f,-1.10316f,-12.375f, -0.0350644f,0.993748f,-0.106001f,
-18.75f,1.06711f,-12.375f, -0.309806f,0.919244f,-0.242922f,
-12.5f,3.61544f,-12.375f, -0.0506281f,0.998702f,-0.00561657f,
-6.25f,1.6504f,-12.375f, 0.322294f,0.937465f,0.131477f,
0.0f,-1.60595f,-12.375f, 0.086016f,0.995916f,0.0274459f,
6.25f,-0.849859f,-12.375f, -0.0332811f,0.997087f,0.0686255f,
12.5f,-0.942201f,-12.375f, -0.153559f,0.982185f,-0.108312f,
18.75f,0.494873f,-12.375f, 0.0753195f,0.981472f,0.176181f,
25.0f,-0.333828f,-12.375f, 0.035057f,0.987194f,0.155624f,
-25.0f,2.1862f,-18.5625f, 0.612899f,0.782306f,0.111138f,
-18.75f,-3.38259f,-18.5625f, 0.0194078f,0.992789f,-0.118297f,
-12.5f,-0.880916f,-18.5625f, -0.282251f,0.949875f,-0.13443f,
-6.25f,0.818158f,-18.5625f, 0.1476f,0.981788f,-0.119612f,
0.0f,-1.48019f,-18.5625f, -0.044551f,0.996013f,-0.0772824f,
6.25f,1.47123f,-18.5625f, -0.117036f,0.97986f,0.161792f,
12.5f,0.164076f,-18.5625f, -0.0340355f,0.978993f,0.201034f,
18.75f,2.14568f,-18.5625f, -0.0439269f,0.994859f,0.0912435f,
25.0f,0.626506f,-18.5625f, 0.208015f,0.968592f,0.136229f,
-25.0f,0.296889f,-24.75f, 0.46973f,0.844327f,-0.257809f,
-18.75f,-3.18022f,-24.75f, -0.0226758f,0.998794f,-0.0435401f,
-12.5f,1.8927f,-24.75f, -0.202772f,0.919836f,0.335836f,
-6.25f,1.46387f,-24.75f, 0.224904f,0.955746f,0.189652f,
0.0f,-2.52726f,-24.75f, -0.0435882f,0.993572f,-0.10447f,
6.25f,1.30397f,-24.75f, -0.28646f,0.956525f,-0.0547707f,
12.5f,1.85812f,-24.75f, 0.0521949f,0.979796f,0.193067f,
18.75f,1.56331f,-24.75f, -0.0270784f,0.999629f,-0.00293115f,
25.0f,1.05366f,-24.75f, 0.161f,0.986887f,-0.0115473f,
};
static float LargeMeshTex[] = {
0.125f,0.0f,
0.0f,0.0f,
0.125f,0.125f,
0.0f,0.125f,
0.125f,0.25f,
0.0f,0.25f,
0.125f,0.375f,
0.0f,0.375f,
0.125f,0.5f,
0.0f,0.5f,
0.125f,0.625f,
0.0f,0.625f,
0.125f,0.75f,
0.0f,0.75f,
0.125f,0.875f,
0.0f,0.875f,
0.125f,1.0f,
0.0f,1.0f,
0.25f,0.0f,
0.25f,0.125f,
0.25f,0.25f,
0.25f,0.375f,
0.25f,0.5f,
0.25f,0.625f,
0.25f,0.75f,
0.25f,0.875f,
0.25f,1.0f,
0.375f,0.0f,
0.375f,0.125f,
0.375f,0.25f,
0.375f,0.375f,
0.375f,0.5f,
0.375f,0.625f,
0.375f,0.75f,
0.375f,0.875f,
0.375f,1.0f,
0.5f,0.0f,
0.5f,0.125f,
0.5f,0.25f,
0.5f,0.375f,
0.5f,0.5f,
0.5f,0.625f,
0.5f,0.75f,
0.5f,0.875f,
0.5f,1.0f,
0.625f,0.0f,
0.625f,0.125f,
0.625f,0.25f,
0.625f,0.375f,
0.625f,0.5f,
0.625f,0.625f,
0.625f,0.75f,
0.625f,0.875f,
0.625f,1.0f,
0.75f,0.0f,
0.75f,0.125f,
0.75f,0.25f,
0.75f,0.375f,
0.75f,0.5f,
0.75f,0.625f,
0.75f,0.75f,
0.75f,0.875f,
0.75f,1.0f,
0.875f,0.0f,
0.875f,0.125f,
0.875f,0.25f,
0.875f,0.375f,
0.875f,0.5f,
0.875f,0.625f,
0.875f,0.75f,
0.875f,0.875f,
0.875f,1.0f,
1.0f,0.0f,
1.0f,0.125f,
1.0f,0.25f,
1.0f,0.375f,
1.0f,0.5f,
1.0f,0.625f,
1.0f,0.75f,
1.0f,0.875f,
1.0f,1.0f,
};
static unsigned short LargeMeshIdx[] = {
0,1,2,
3,2,1,
2,3,4,
5,4,3,
4,5,6,
7,6,5,
6,7,8,
9,8,7,
8,9,10,
11,10,9,
10,11,12,
13,12,11,
12,13,14,
15,14,13,
14,15,16,
17,16,15,
18,0,19,
2,19,0,
19,2,20,
4,20,2,
20,4,21,
6,21,4,
21,6,22,
8,22,6,
22,8,23,
10,23,8,
23,10,24,
12,24,10,
24,12,25,
14,25,12,
25,14,26,
16,26,14,
27,18,28,
19,28,18,
28,19,29,
20,29,19,
29,20,30,
21,30,20,
30,21,31,
22,31,21,
31,22,32,
23,32,22,
32,23,33,
24,33,23,
33,24,34,
25,34,24,
34,25,35,
26,35,25,
36,27,37,
28,37,27,
37,28,38,
29,38,28,
38,29,39,
30,39,29,
39,30,40,
31,40,30,
40,31,41,
32,41,31,
41,32,42,
33,42,32,
42,33,43,
34,43,33,
43,34,44,
35,44,34,
45,36,46,
37,46,36,
46,37,47,
38,47,37,
47,38,48,
39,48,38,
48,39,49,
40,49,39,
49,40,50,
41,50,40,
50,41,51,
42,51,41,
51,42,52,
43,52,42,
52,43,53,
44,53,43,
54,45,55,
46,55,45,
55,46,56,
47,56,46,
56,47,57,
48,57,47,
57,48,58,
49,58,48,
58,49,59,
50,59,49,
59,50,60,
51,60,50,
60,51,61,
52,61,51,
61,52,62,
53,62,52,
63,54,64,
55,64,54,
64,55,65,
56,65,55,
65,56,66,
57,66,56,
66,57,67,
58,67,57,
67,58,68,
59,68,58,
68,59,69,
60,69,59,
69,60,70,
61,70,60,
70,61,71,
62,71,61,
72,63,73,
64,73,63,
73,64,74,
65,74,64,
74,65,75,
66,75,65,
75,66,76,
67,76,66,
76,67,77,
68,77,67,
77,68,78,
69,78,68,
78,69,79,
70,79,69,
79,70,80,
71,80,70,
};

View File

@@ -0,0 +1,448 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "../common/common.h"
#include "../common/ctrl_func.h"
#include "../common/render_func.h"
#include "../common/perf_func.h"
#include "physics_func.h"
#include "barrel.h"
#include "landscape.h"
#ifdef _WIN32
#include <gl/gl.h>
#include <gl/glu.h>
#endif
// ARA begin insert new code
#ifdef __ANDROID__
#include <EGL/egl.h>
#include <GLES/gl.h>
#endif
// ARA end
#define SAMPLE_NAME "api_physics_effects/2_stable"
static bool s_isRunning = true;
int sceneId = 2;
bool simulating = false;
int landscapeMeshId;
int convexMeshId;
void render(void)
{
render_begin();
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxTransform3 rbT(state.getOrientation(), state.getPosition());
PfxShapeIterator itrShape(coll);
for(int j=0;j<coll.getNumShapes();j++,++itrShape) {
const PfxShape &shape = *itrShape;
PfxTransform3 offsetT = shape.getOffsetTransform();
PfxTransform3 worldT = rbT * offsetT;
switch(shape.getType()) {
case kPfxShapeSphere:
render_sphere(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getSphere().m_radius));
break;
case kPfxShapeBox:
render_box(
worldT,
PfxVector3(1,1,1),
shape.getBox().m_half);
break;
case kPfxShapeCapsule:
render_capsule(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getCapsule().m_radius),
PfxFloatInVec(shape.getCapsule().m_halfLen));
break;
case kPfxShapeCylinder:
render_cylinder(
worldT,
PfxVector3(1,1,1),
PfxFloatInVec(shape.getCylinder().m_radius),
PfxFloatInVec(shape.getCylinder().m_halfLen));
break;
case kPfxShapeConvexMesh:
render_mesh(
worldT,
PfxVector3(1,1,1),
convexMeshId);
break;
case kPfxShapeLargeTriMesh:
render_mesh(
worldT,
PfxVector3(1,1,1),
landscapeMeshId);
break;
default:
break;
}
}
}
render_end();
}
int init(void)
{
perf_init();
ctrl_init();
render_init();
physics_init();
landscapeMeshId = render_init_mesh(
LargeMeshVtx,sizeof(float)*6,
LargeMeshVtx+3,sizeof(float)*6,
LargeMeshIdx,sizeof(unsigned short)*3,
LargeMeshVtxCount,LargeMeshIdxCount/3);
convexMeshId = render_init_mesh(
BarrelVtx,sizeof(float)*6,
BarrelVtx+3,sizeof(float)*6,
BarrelIdx,sizeof(unsigned short)*3,
BarrelVtxCount,BarrelIdxCount/3);
return 0;
}
static int shutdown(void)
{
ctrl_release();
render_release();
physics_release();
perf_release();
return 0;
}
void update(void)
{
float angX,angY,r;
render_get_view_angle(angX,angY,r);
ctrl_update();
if(ctrl_button_pressed(BTN_UP)) {
angX -= 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_DOWN)) {
angX += 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_LEFT)) {
angY -= 0.05f;
}
if(ctrl_button_pressed(BTN_RIGHT)) {
angY += 0.05f;
}
if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
r *= 1.1f;
if(r > 500.0f) r = 500.0f;
}
if(ctrl_button_pressed(BTN_ZOOM_IN)) {
r *= 0.9f;
if(r < 1.0f) r = 1.0f;
}
if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
physics_create_scene(sceneId);
}
if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
physics_create_scene(++sceneId);
}
if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
simulating = !simulating;
}
if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
simulating = true;
}
else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
simulating = false;
}
render_set_view_angle(angX,angY,r);
}
#ifndef _WIN32
// ARA begin insert new code
#ifdef __ANDROID__
///////////////////////////////////////////////////////////////////////////////
// sceneChange
//
/// This function is used to change the physics scene on Android devices
///////////////////////////////////////////////////////////////////////////////
void sceneChange()
{
physics_create_scene(sceneId++);
}
#else // __ANDROID__
// ARA end
///////////////////////////////////////////////////////////////////////////////
// Main
int main(void)
{
init();
physics_create_scene(sceneId);
printf("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
while (s_isRunning) {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
shutdown();
printf("## %s: FINISHED ##\n", SAMPLE_NAME);
return 0;
}
// ARA begin insert new code
#endif // __ANDROID__
// ARA end
#else // _WIN32
///////////////////////////////////////////////////////////////////////////////
// WinMain
extern HDC hDC;
extern HGLRC hRC;
HWND hWnd;
HINSTANCE hInstance;
void releaseWindow()
{
if(hRC) {
wglMakeCurrent(0,0);
wglDeleteContext(hRC);
}
if(hDC) ReleaseDC(hWnd,hDC);
if(hWnd) DestroyWindow(hWnd);
UnregisterClass(SAMPLE_NAME,hInstance);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg) {
case WM_SYSCOMMAND:
{
switch (wParam) {
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_SIZE:
render_resize(LOWORD(lParam),HIWORD(lParam));
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
bool createWindow(char* title, int width, int height)
{
WNDCLASS wc;
RECT rect;
rect.left=0;
rect.right=width;
rect.top=0;
rect.bottom=height;
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = SAMPLE_NAME;
if(!RegisterClass(&wc)) {
return false;
}
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
if(!(hWnd=CreateWindowEx(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,SAMPLE_NAME,title,
WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
0,0,rect.right-rect.left,rect.bottom-rect.top,
NULL,NULL,hInstance,NULL))) {
releaseWindow();
return false;
}
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0,
0, 0,
0, 0,
0, 0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if(!(hDC=GetDC(hWnd)))
{
releaseWindow();
OutputDebugString("");
return FALSE;
}
int pixelformat;
if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 ){
OutputDebugString("ChoosePixelFormat Failed....");
return FALSE;
}
if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE){
OutputDebugString("SetPixelFormat Failed....");
return FALSE;
}
if (!(hRC=wglCreateContext(hDC))){
OutputDebugString("Creating HGLRC Failed....");
return FALSE;
}
// Set Vsync
//BOOL (WINAPI *wglSwapIntervalEXT)(int) = NULL;
//if(strstr((char*)glGetString( GL_EXTENSIONS ),"WGL_EXT_swap_control")== 0) {
//}
//else {
//wglSwapIntervalEXT = (BOOL (WINAPI*)(int))wglGetProcAddress("wglSwapIntervalEXT");
//if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
//}
wglMakeCurrent(hDC,hRC);
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
render_resize(width, height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return 0;
}
init();
physics_create_scene(sceneId);
SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
MSG msg;
while(s_isRunning) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if(msg.message==WM_QUIT) {
s_isRunning = false;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
}
shutdown();
SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);
releaseWindow();
return (msg.wParam);
}
#endif

View File

@@ -0,0 +1,968 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "physics_func.h"
#include "../common/perf_func.h"
///////////////////////////////////////////////////////////////////////////////
// Simulation Data
#define NUM_RIGIDBODIES 5000
#define NUM_JOINTS 5000
#define NUM_CONTACTS 4000
const float timeStep = 0.016f;
const float separateBias = 0.1f;
int iteration = 5;
//J ???????
//E World size
PfxVector3 worldCenter(0.0f);
PfxVector3 worldExtent(500.0f);
//J ??
//E Rigid body
PfxRigidState states[NUM_RIGIDBODIES];
PfxRigidBody bodies[NUM_RIGIDBODIES];
PfxCollidable collidables[NUM_RIGIDBODIES];
PfxSolverBody solverBodies[NUM_RIGIDBODIES];
int numRigidBodies = 0;
//J ?????????????????
//E Large mesh for representing a landscape
#include "landscape.h"
PfxLargeTriMesh gLargeMesh;
//J ?????
//E Convex Mesh
#include "barrel.h"
PfxConvexMesh gConvex;
//J ????
//E Proxies
PfxBroadphaseProxy proxies[NUM_RIGIDBODIES];
//J ?????
//E Joint
PfxConstraintPair jointPairs[NUM_JOINTS];
PfxJoint joints[NUM_JOINTS];
int numJoints = 0;
//J ??
//E Pairs
unsigned int pairSwap;
unsigned int numPairs[2];
PfxBroadphasePair pairsBuff[2][NUM_CONTACTS];
//J ?????
//E Contacts
PfxContactManifold contacts[NUM_CONTACTS];
int numContacts;
PfxUInt32 contactIdPool[NUM_CONTACTS];
int numContactIdPool;
//J ??????
//E Temporary buffers
#define POOL_BYTES (5*1024*1024)
unsigned char SCE_PFX_ALIGNED(128) poolBuff[POOL_BYTES];
//J ????????????????
//E Stack allocator for temporary buffers
PfxHeapManager pool(poolBuff,POOL_BYTES);
// ARA begin insert new code
//E task manager for parallel demo
#define NUM_THREADS 1
PfxTaskManager *taskManager = NULL;
//E need enough bytes for NUM_THREADS PfxTaskArg objects, with the space rounded up to fill a 16-bit aligned space
#define TASK_MANAGER_POOL_BYTES 1024
unsigned char SCE_PFX_ALIGNED(16) taskPoolBuff[TASK_MANAGER_POOL_BYTES];
// ARA end
///////////////////////////////////////////////////////////////////////////////
// Simulation Function
int frame = 0;
void broadphase()
{
pairSwap = 1-pairSwap;
unsigned int &numPreviousPairs = numPairs[1-pairSwap];
unsigned int &numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *previousPairs = pairsBuff[1-pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
//J ?????????????????
//E Find the axis along which all rigid bodies are most widely positioned
int axis = 0;
{
PfxVector3 s(0.0f),s2(0.0f);
for(int i=0;i<numRigidBodies;i++) {
PfxVector3 c = states[i].getPosition();
s += c;
s2 += mulPerElem(c,c);
}
PfxVector3 v = s2 - mulPerElem(s,s) / (float)numRigidBodies;
if(v[1] > v[0]) axis = 1;
if(v[2] > v[axis]) axis = 2;
}
//J ???????????????
//E Create broadpahse proxies
{
for(int i=0;i<numRigidBodies;i++) {
pfxUpdateBroadphaseProxy(proxies[i],states[i],collidables[i],worldCenter,worldExtent,axis);
}
int workBytes = sizeof(PfxBroadphaseProxy) * numRigidBodies;
void *workBuff = pool.allocate(workBytes);
pfxParallelSort(proxies,numRigidBodies,workBuff,workBytes);
pool.deallocate(workBuff);
}
//J ??????
//E Find overlapped pairs
{
PfxFindPairsParam findPairsParam;
findPairsParam.pairBytes = pfxGetPairBytesOfFindPairs(NUM_CONTACTS);
findPairsParam.pairBuff = pool.allocate(findPairsParam.pairBytes);
findPairsParam.workBytes = pfxGetWorkBytesOfFindPairs(NUM_CONTACTS);
findPairsParam.workBuff = pool.allocate(findPairsParam.workBytes);
findPairsParam.proxies = proxies;
findPairsParam.numProxies = numRigidBodies;
findPairsParam.maxPairs = NUM_CONTACTS;
findPairsParam.axis = axis;
PfxFindPairsResult findPairsResult;
int ret = pfxFindPairs(findPairsParam,findPairsResult);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxFindPairs failed %d\n",ret);
pool.deallocate(findPairsParam.workBuff);
//J ??????
//E Decompose overlapped pairs into 3 arrays
PfxDecomposePairsParam decomposePairsParam;
decomposePairsParam.pairBytes = pfxGetPairBytesOfDecomposePairs(numPreviousPairs,findPairsResult.numPairs);
decomposePairsParam.pairBuff = pool.allocate(decomposePairsParam.pairBytes);
decomposePairsParam.workBytes = pfxGetWorkBytesOfDecomposePairs(numPreviousPairs,findPairsResult.numPairs);
decomposePairsParam.workBuff = pool.allocate(decomposePairsParam.workBytes);
decomposePairsParam.previousPairs = previousPairs;
decomposePairsParam.numPreviousPairs = numPreviousPairs;
decomposePairsParam.currentPairs = findPairsResult.pairs; // Set pairs from pfxFindPairs()
decomposePairsParam.numCurrentPairs = findPairsResult.numPairs; // Set the number of pairs from pfxFindPairs()
PfxDecomposePairsResult decomposePairsResult;
ret = pfxDecomposePairs(decomposePairsParam,decomposePairsResult);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxDecomposePairs failed %d\n",ret);
pool.deallocate(decomposePairsParam.workBuff);
PfxBroadphasePair *outNewPairs = decomposePairsResult.outNewPairs;
PfxBroadphasePair *outKeepPairs = decomposePairsResult.outKeepPairs;
PfxBroadphasePair *outRemovePairs = decomposePairsResult.outRemovePairs;
PfxUInt32 numOutNewPairs = decomposePairsResult.numOutNewPairs;
PfxUInt32 numOutKeepPairs = decomposePairsResult.numOutKeepPairs;
PfxUInt32 numOutRemovePairs = decomposePairsResult.numOutRemovePairs;
//J ?????????????????
//E Put removed contacts into the contact pool
for(PfxUInt32 i=0;i<numOutRemovePairs;i++) {
contactIdPool[numContactIdPool++] = pfxGetContactId(outRemovePairs[i]);
}
//J ??????????????????
//E Add new contacts and initialize
for(PfxUInt32 i=0;i<numOutNewPairs;i++) {
int cId = 0;
if(numContactIdPool > 0) {
cId = contactIdPool[--numContactIdPool];
}
else {
cId = numContacts++;
}
if(cId >= NUM_CONTACTS) {
cId = 0;
}
SCE_PFX_ASSERT(cId < NUM_CONTACTS);
pfxSetContactId(outNewPairs[i],cId);
PfxContactManifold &contact = contacts[cId];
contact.reset(pfxGetObjectIdA(outNewPairs[i]),pfxGetObjectIdB(outNewPairs[i]));
}
//J ????????????
//E Merge 'new' and 'keep' pairs
numCurrentPairs = 0;
for(PfxUInt32 i=0;i<numOutKeepPairs;i++) {
currentPairs[numCurrentPairs++] = outKeepPairs[i];
}
for(PfxUInt32 i=0;i<numOutNewPairs;i++) {
currentPairs[numCurrentPairs++] = outNewPairs[i];
}
pool.deallocate(decomposePairsParam.pairBuff);
pool.deallocate(findPairsParam.pairBuff);
}
{
int workBytes = sizeof(PfxBroadphasePair) * numCurrentPairs;
void *workBuff = pool.allocate(workBytes);
pfxParallelSort(currentPairs,numCurrentPairs,workBuff,workBytes);
pool.deallocate(workBuff);
}
}
void collision()
{
unsigned int numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
//J ????
//E Detect collisions
{
PfxDetectCollisionParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetCollidables = collidables;
param.numRigidBodies = numRigidBodies;
// ARA begin insert new code
#ifdef USE_PTHREADS
int ret = pfxDetectCollision(param, taskManager);
#else
// ARA end
int ret = pfxDetectCollision(param);
// ARA begin insert new code
#endif
// ARA end
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxDetectCollision failed %d\n",ret);
}
//J ??????
//E Refresh contacts
{
PfxRefreshContactsParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.numRigidBodies = numRigidBodies;
// ARA begin insert new code
#ifdef USE_PTHREADS
int ret = pfxRefreshContacts(param, taskManager);
#else
// ARA end
int ret = pfxRefreshContacts(param);
// ARA begin insert new code
#endif
// ARA end
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxRefreshContacts failed %d\n",ret);
}
}
void constraintSolver()
{
PfxPerfCounter pc;
unsigned int numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
pc.countBegin("setup solver bodies");
{
PfxSetupSolverBodiesParam param;
param.states = states;
param.bodies = bodies;
param.solverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
// ARA begin insert new code
#ifdef USE_PTHREADS
int ret = pfxSetupSolverBodies(param, taskManager);
#else
// ARA end
int ret = pfxSetupSolverBodies(param);
// ARA begin insert new code
#endif
// ARA end
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupSolverBodies failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup contact constraints");
{
PfxSetupContactConstraintsParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
param.separateBias = separateBias;
// ARA begin insert new code
#ifdef USE_PTHREADS
int ret = pfxSetupContactConstraints(param, taskManager);
#else
// ARA end
int ret = pfxSetupContactConstraints(param);
// ARA begin insert new code
#endif
// ARA end
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup joint constraints");
{
PfxSetupJointConstraintsParam param;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
for(int i=0;i<numJoints;i++) {
pfxUpdateJointPairs(jointPairs[i],i,joints[i],states[joints[i].m_rigidBodyIdA],states[joints[i].m_rigidBodyIdB]);
}
// ARA begin insert new code
#ifdef USE_PTHREADS
int ret = pfxSetupJointConstraints(param, taskManager);
#else
// ARA end
int ret = pfxSetupJointConstraints(param);
// ARA begin insert new code
#endif
// ARA end
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("solve constraints");
{
PfxSolveConstraintsParam param;
param.workBytes = pfxGetWorkBytesOfSolveConstraints(numRigidBodies,numCurrentPairs,numJoints);
param.workBuff = pool.allocate(param.workBytes);
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.iteration = iteration;
// ARA begin insert new code
#ifdef USE_PTHREADS
int ret = pfxSolveConstraints(param, taskManager);
#else
// ARA end
int ret = pfxSolveConstraints(param);
// ARA begin insert new code
#endif
// ARA end
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSolveConstraints failed %d\n",ret);
pool.deallocate(param.workBuff);
}
pc.countEnd();
//pc.printCount();
}
void integrate()
{
PfxUpdateRigidStatesParam param;
param.states = states;
param.bodies = bodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
// ARA begin insert new code
#ifdef USE_PTHREADS
pfxUpdateRigidStates(param, taskManager);
#else
// ARA end
pfxUpdateRigidStates(param);
// ARA begin insert new code
#endif
// ARA end
}
void physics_simulate()
{
PfxPerfCounter pc;
for(int i=1;i<numRigidBodies;i++) {
pfxApplyExternalForce(states[i],bodies[i],bodies[i].getMass()*PfxVector3(0.0f,-9.8f,0.0f),PfxVector3(0.0f),timeStep);
}
perf_push_marker("broadphase");
pc.countBegin("broadphase");
broadphase();
pc.countEnd();
perf_pop_marker();
perf_push_marker("collision");
pc.countBegin("collision");
collision();
pc.countEnd();
perf_pop_marker();
perf_push_marker("solver");
pc.countBegin("solver");
constraintSolver();
pc.countEnd();
perf_pop_marker();
perf_push_marker("integrate");
pc.countBegin("integrate");
integrate();
pc.countEnd();
perf_pop_marker();
frame++;
if(frame%100 == 0) {
float broadphaseTime = pc.getCountTime(0);
float collisionTime = pc.getCountTime(2);
float solverTime = pc.getCountTime(4);
float integrateTime = pc.getCountTime(6);
SCE_PFX_PRINTF("frame %3d broadphase %.2f collision %.2f solver %.2f integrate %.2f | total %.2f\n",frame,
broadphaseTime,collisionTime,solverTime,integrateTime,
broadphaseTime+collisionTime+solverTime+integrateTime);
}
}
///////////////////////////////////////////////////////////////////////////////
// Create Scene
void createBrick(int id,const PfxVector3 &pos,const PfxQuat &rot,const PfxVector3 &boxSize,PfxFloat mass)
{
PfxBox box(boxSize);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setRestitution(0.0f);
bodies[id].setMass(mass);
bodies[id].setInertia(pfxCalcInertiaBox(boxSize,mass));
states[id].reset();
states[id].setPosition(pos);
states[id].setOrientation(rot);
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
void createWall(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
PfxFloat bodyMass = 0.5f;
PfxFloat diffX = boxSize[0] * 1.02f;
PfxFloat diffY = boxSize[1] * 1.02f;
PfxFloat diffZ = boxSize[2] * 1.02f;
PfxFloat offset = -stackSize * (diffZ * 2.0f) * 0.5f;
PfxVector3 pos(0.0f, diffY, 0.0f);
while(stackSize) {
for(int i=0;i<stackSize;i++) {
pos[2] = offset + (PfxFloat)i * (diffZ * 2.0f);
createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,bodyMass);
}
offset += diffZ;
pos[1] += (diffY * 2.0f);
stackSize--;
}
}
void createPyramid(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
PfxFloat space = 0.0001f;
PfxVector3 pos(0.0f, boxSize[1], 0.0f);
PfxFloat diffX = boxSize[0] * 1.02f;
PfxFloat diffY = boxSize[1] * 1.02f;
PfxFloat diffZ = boxSize[2] * 1.02f;
PfxFloat offsetX = -stackSize * (diffX * 2.0f + space) * 0.5f;
PfxFloat offsetZ = -stackSize * (diffZ * 2.0f + space) * 0.5f;
while(stackSize) {
for(int j=0;j<stackSize;j++) {
pos[2] = offsetZ + (PfxFloat)j * (diffZ * 2.0f + space);
for(int i=0;i<stackSize;i++) {
pos[0] = offsetX + (PfxFloat)i * (diffX * 2.0f + space);
createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,1.0f);
}
}
offsetX += diffX;
offsetZ += diffZ;
pos[1] += (diffY * 2.0f + space);
stackSize--;
}
}
void createTowerCircle(const PfxVector3 &offsetPosition,int stackSize,int rotSize,const PfxVector3 &boxSize)
{
PfxFloat radius = 1.3f * rotSize * boxSize[0] / SCE_PFX_PI;
// create active boxes
PfxQuat rotY = PfxQuat::identity();
PfxFloat posY = boxSize[1];
for(int i=0;i<stackSize;i++) {
for(int j=0;j<rotSize;j++) {
createBrick(numRigidBodies++,offsetPosition+rotate(rotY,PfxVector3(0.0f , posY, radius)),rotY,boxSize,0.5f);
rotY *= PfxQuat::rotationY(SCE_PFX_PI/(rotSize*0.5f));
}
posY += boxSize[1] * 2.0f;
rotY *= PfxQuat::rotationY(SCE_PFX_PI/(PfxFloat)rotSize);
}
}
void createScenePrimitives()
{
// sphere
{
int id = numRigidBodies++;
PfxSphere sphere(1.0f);
PfxShape shape;
shape.reset();
shape.setSphere(sphere);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(1.0f);
bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(-5.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// box
{
int id = numRigidBodies++;
PfxBox box(1.0f,1.0f,1.0f);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(1.0f);
bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(1.0f),1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,5.0f,5.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// capsule
{
int id = numRigidBodies++;
PfxCapsule capsule(1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setCapsule(capsule);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(2.0f);
bodies[id].setInertia(pfxCalcInertiaCylinderX(2.0f,0.5f,2.0f));
states[id].reset();
states[id].setPosition(PfxVector3(5.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// cylinder
{
int id = numRigidBodies++;
PfxCylinder cylinder(0.5f,1.5f);
PfxShape shape;
shape.reset();
shape.setCylinder(cylinder);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaCylinderX(0.5f,1.5f,3.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,10.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// convex mesh
{
PfxCreateConvexMeshParam param;
param.verts = BarrelVtx;
param.numVerts = BarrelVtxCount;
param.vertexStrideBytes = sizeof(float)*6;
param.triangles = BarrelIdx;
param.numTriangles = BarrelIdxCount/3;
param.triangleStrideBytes = sizeof(unsigned short)*3;
PfxInt32 ret = pfxCreateConvexMesh(gConvex,param);
if(ret != SCE_PFX_OK) {
SCE_PFX_PRINTF("Can't create gConvex mesh.\n");
}
int id = numRigidBodies++;
PfxShape shape;
shape.reset();
shape.setConvexMesh(&gConvex);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,15.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
// combined primitives
{
int id = numRigidBodies++;
//E Both shapes and incides buffer have to be kept when creating a combined shape.
static PfxShape shapes[3];
PfxUInt16 shapeIds[3]={0,1,2};
collidables[id].reset(shapes,shapeIds,3);
{
PfxBox box(0.5f,0.5f,1.5f);
PfxShape shape;
shape.reset();
shape.setBox(box);
shape.setOffsetPosition(PfxVector3(-2.0f,0.0f,0.0f));
collidables[id].addShape(shape);
}
{
PfxBox box(0.5f,1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setBox(box);
shape.setOffsetPosition(PfxVector3(2.0f,0.0f,0.0f));
collidables[id].addShape(shape);
}
{
PfxCapsule cap(1.5f,0.5f);
PfxShape shape;
shape.reset();
shape.setCapsule(cap);
collidables[id].addShape(shape);
}
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(3.0f);
bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(2.5f,1.0f,1.0f),3.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,5.0f,0.0f));
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setRigidBodyId(id);
}
}
void createSceneJoints()
{
const int n = 10;
int startId = numRigidBodies;
PfxVector3 boxSize(1.0f);
PfxFloat boxMass = 1.0f;
for(int i=0;i<n;i++) {
createBrick(numRigidBodies++,PfxVector3(0,3.0f+i*2.5f*boxSize[1],0),PfxQuat::identity(),boxSize,boxMass);
}
for(int i=startId;i<startId+n;i++) {
PfxRigidState &stateA = states[i];
PfxRigidState &stateB = states[(i+1)%numRigidBodies];
PfxVector3 anchor;
if(i == numRigidBodies-1) {
anchor = stateA.getPosition() + PfxVector3(0,boxSize[1],0);
}
else {
anchor = ( stateA.getPosition() + stateB.getPosition() ) * 0.5f;
}
PfxSwingTwistJointInitParam jparam;
jparam.anchorPoint = anchor;
jparam.twistAxis = PfxVector3(0,1,0);
pfxInitializeSwingTwistJoint(joints[numJoints],stateA,stateB,jparam);
joints[numJoints].m_constraints[4].m_damping = 0.1f;
joints[numJoints].m_constraints[5].m_damping = 0.1f;
pfxUpdateJointPairs(jointPairs[numJoints],numJoints,joints[numJoints],stateA,stateB);
SCE_PFX_ASSERT(numJoints<NUM_JOINTS);
numJoints++;
}
states[startId].setLinearVelocity(PfxVector3(0,0,5));
states[startId].setLinearDamping(0.95f);
states[startId].setAngularDamping(0.95f);
}
void createSceneStacking()
{
const float cubeSize = 1.0f;
createPyramid(PfxVector3(-20.0f,0.0f,0.0f),12,PfxVector3(cubeSize,cubeSize,cubeSize));
createWall(PfxVector3(-2.0f,0.0f,0.0f),12,PfxVector3(cubeSize,cubeSize,cubeSize));
createWall(PfxVector3(4.0f,0.0f,0.0f),12,PfxVector3(cubeSize,cubeSize,cubeSize));
createWall(PfxVector3(10.0f,0.0f,0.0f),12,PfxVector3(cubeSize,cubeSize,cubeSize));
createTowerCircle(PfxVector3(25.0f,0.0f,0.0f),8,24,PfxVector3(cubeSize,cubeSize,cubeSize));
// createTowerCircle(PfxVector3(0.0f,0.0f,0.0f),8,24,PfxVector3(1));
}
void createSceneBoxGround()
{
int id = numRigidBodies++;
PfxBox box(150.0f,2.5f,150.0f);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,-2.5f,0.0f));
states[id].setMotionType(kPfxMotionTypeFixed);
states[id].setRigidBodyId(id);
}
void createSceneLandscape()
{
PfxCreateLargeTriMeshParam param;
param.verts = LargeMeshVtx;
param.numVerts = LargeMeshVtxCount;
param.vertexStrideBytes = sizeof(float)*6;
param.triangles = LargeMeshIdx;
param.numTriangles = LargeMeshIdxCount/3;
param.triangleStrideBytes = sizeof(unsigned short)*3;
if(gLargeMesh.m_numIslands > 0) {
pfxReleaseLargeTriMesh(gLargeMesh);
}
PfxInt32 ret = pfxCreateLargeTriMesh(gLargeMesh,param);
if(ret != SCE_PFX_OK) {
SCE_PFX_PRINTF("Can't create large mesh.\n");
}
int id = numRigidBodies++;
PfxShape shape;
shape.reset();
shape.setLargeTriMesh(&gLargeMesh);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,-5.0f,0.0f));
states[id].setOrientation(PfxQuat::rotationX(0.5f)*PfxQuat::rotationY(0.7f));
states[id].setMotionType(kPfxMotionTypeFixed);
states[id].setRigidBodyId(id);
}
void physics_create_scene(int sceneId)
{
const int numScenes = 4;
int sid = sceneId % numScenes;
numRigidBodies= 0;
pairSwap = 0;
numPairs[0] = 0;
numPairs[1] = 0;
numContacts = 0;
numContactIdPool = 0;
numJoints = 0;
frame = 0;
switch(sid) {
case 0: // simple primitives
createSceneBoxGround();
createScenePrimitives();
break;
case 1: // joints
createSceneBoxGround();
createSceneJoints();
break;
case 2: // stacking
createSceneBoxGround();
createSceneStacking();
break;
case 3: // landscape
createSceneLandscape();
createScenePrimitives();
break;
}
SCE_PFX_PRINTF("----- Size of rigid body buffer ------\n");
SCE_PFX_PRINTF(" size * num = total\n");
SCE_PFX_PRINTF("PfxRigidState %5d * %5d = %5d bytes\n",sizeof(PfxRigidState),numRigidBodies,sizeof(PfxRigidState)*numRigidBodies);
SCE_PFX_PRINTF("PfxRigidBody %5d * %5d = %5d bytes\n",sizeof(PfxRigidBody),numRigidBodies,sizeof(PfxRigidBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxCollidable %5d * %5d = %5d bytes\n",sizeof(PfxCollidable),numRigidBodies,sizeof(PfxCollidable)*numRigidBodies);
SCE_PFX_PRINTF("PfxJoint %5d * %5d = %5d bytes\n",sizeof(PfxJoint),numJoints,sizeof(PfxJoint)*numJoints);
SCE_PFX_PRINTF("PfxSolverBody %5d * %5d = %5d bytes\n",sizeof(PfxSolverBody),numRigidBodies,sizeof(PfxSolverBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxBroadphaseProxy %5d * %5d = %5d bytes\n",sizeof(PfxBroadphaseProxy),numRigidBodies,sizeof(PfxBroadphaseProxy)*numRigidBodies);
SCE_PFX_PRINTF("PfxContactManifold %5d * %5d = %5d bytes\n",sizeof(PfxContactManifold),NUM_CONTACTS,sizeof(PfxContactManifold)*NUM_CONTACTS);
SCE_PFX_PRINTF("PfxBroadphasePair %5d * %5d = %5d bytes\n",sizeof(PfxBroadphasePair),NUM_CONTACTS,sizeof(PfxBroadphasePair)*NUM_CONTACTS);
int totalBytes =
(sizeof(PfxRigidState) + sizeof(PfxRigidBody) + sizeof(PfxCollidable) + sizeof(PfxSolverBody) + sizeof(PfxBroadphaseProxy)) * numRigidBodies +
(sizeof(PfxContactManifold) + sizeof(PfxBroadphasePair)) * NUM_CONTACTS;
SCE_PFX_PRINTF("----------------------------------------------------------\n");
SCE_PFX_PRINTF("Total %5d bytes\n",totalBytes);
// ARA begin insert new code
#ifdef USE_PTHREADS
if (!taskManager)
{
taskManager = PfxCreateTaskManagerPthreads(NUM_THREADS, NUM_THREADS, taskPoolBuff, TASK_MANAGER_POOL_BYTES);
taskManager->initialize();
}
#endif
// ARA end
}
///////////////////////////////////////////////////////////////////////////////
// Initialize / Finalize Engine
bool physics_init()
{
return true;
}
void physics_release()
{
// ARA begin insert new code
if (taskManager)
taskManager->finalize();
// ARA end
}
///////////////////////////////////////////////////////////////////////////////
// Pick
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2)
{
return PfxVector3(0.0f);
}
void physics_pick_update(const PfxVector3 &p)
{
}
void physics_pick_end()
{
}
///////////////////////////////////////////////////////////////////////////////
// Get Information
int physics_get_num_rigidbodies()
{
return numRigidBodies;
}
const PfxRigidState& physics_get_state(int id)
{
return states[id];
}
const PfxRigidBody& physics_get_body(int id)
{
return bodies[id];
}
const PfxCollidable& physics_get_collidable(int id)
{
return collidables[id];
}
int physics_get_num_contacts()
{
return numPairs[pairSwap];
}
const PfxContactManifold &physics_get_contact(int id)
{
return contacts[pfxGetConstraintId(pairsBuff[pairSwap][id])];
}

View File

@@ -0,0 +1,49 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __PHYSICS_FUNC_H__
#define __PHYSICS_FUNC_H__
#define SCE_PFX_USE_PERFCOUNTER
#include "physics_effects.h"
using namespace sce::PhysicsEffects;
//E Simulation
//J ????????
bool physics_init();
void physics_release();
void physics_create_scene(int sceneId);
void physics_simulate();
//E Picking
//J ?????
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2);
void physics_pick_update(const PfxVector3 &p);
void physics_pick_end();
//E Change parameters
//J ????????
int physics_get_num_rigidbodies();
const PfxRigidState& physics_get_state(int id);
const PfxRigidBody& physics_get_body(int id);
const PfxCollidable& physics_get_collidable(int id);
int physics_get_num_contacts();
const PfxContactManifold &physics_get_contact(int id);
#endif /* __PHYSICS_FUNC_H__ */

View File

@@ -0,0 +1,713 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="3_sleep.windows"
ProjectGUID="{97E051D8-9233-410D-8123-E5ED749D6640}"
RootNamespace="3_sleep.win32"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Win32 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib "
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
>
<File
RelativePath=".\physics_func.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\physics_func.cpp"
>
</File>
</Filter>
<Filter
Name="Common"
>
<File
RelativePath="..\common\common.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\perf_func.h"
>
</File>
<File
RelativePath="..\common\perf_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\render_func.h"
>
</File>
<File
RelativePath="..\common\render_func.win32.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 2.4)
#this line has to appear before 'PROJECT' in order to be able to disable incremental linking
SET(MSVC_INCREMENTAL_DEFAULT ON)
PROJECT(App_3_Sleep)
IF (NOT CMAKE_BUILD_TYPE)
# SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_BUILD_TYPE "Release")
ENDIF (NOT CMAKE_BUILD_TYPE)
OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" ON)
OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
ENDIF(COMMAND cmake_policy)
SET(App_3_Sleep_SRCS
main.cpp
physics_func.cpp
../common/ctrl_func.win32.cpp
../common/perf_func.win32.cpp
../common/render_func.win32.cpp
)
SET(App_3_Sleep_HDRS
physics_func.h
landscape.h
barrel.h
../common/render_func.h
../common/common.h
../common/ctrl_func.h
../common/perf_func.h
)
INCLUDE_DIRECTORIES(
${PHYSICS_EFFECTS_SOURCE_DIR}/include
# ${VECTOR_MATH_INCLUDE}
)
#LINK_DIRECTORIES(
#
#)
#ADD_DEFINITIONS(-DUNICODE)
#ADD_DEFINITIONS(-D_UNICODE)
ADD_EXECUTABLE(App_3_Sleep WIN32
${App_3_Sleep_SRCS}
${App_3_Sleep_HDRS}
)
TARGET_LINK_LIBRARIES(App_3_Sleep
PfxBaseLevel
PfxLowLevel
PfxUtil
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(App_3_Sleep PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_3_Sleep PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_3_Sleep PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF()

View File

@@ -0,0 +1,202 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define BarrelVtxCount 57
#define BarrelIdxCount 180
static float BarrelVtx[] = {
0.0f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
-0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
0.0f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
-0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.957307f,-0.289072f,0.0f,
0.404509f,0.0f,-0.293893f, 0.809017f,0.0f,-0.587785f,
0.5f,0.0f,0.0f, 1.0f,0.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.774478f,-0.289072f,-0.562691f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
-0.154509f,0.0f,-0.475528f, -0.309017f,0.0f,-0.951057f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
-0.107853f,-0.5f,-0.331936f, -0.295824f,-0.289072f,-0.910453f,
-0.404509f,0.0f,-0.293893f, -0.809017f,0.0f,-0.587785f,
-0.282362f,-0.5f,-0.205148f, -0.774478f,-0.289072f,-0.562691f,
-0.5f,0.0f,0.0f, -1.0f,0.0f,0.0f,
-0.349018f,-0.5f,0.0f, -0.957307f,-0.289072f,0.0f,
-0.404508f,0.0f,0.293893f, -0.809017f,0.0f,0.587785f,
-0.282362f,-0.5f,0.205148f, -0.774478f,-0.289072f,0.562691f,
-0.154509f,0.0f,0.475528f, -0.309017f,0.0f,0.951056f,
-0.107853f,-0.5f,0.331936f, -0.295824f,-0.289072f,0.910453f,
0.154509f,0.0f,0.475528f, 0.309017f,0.0f,0.951056f,
0.107853f,-0.5f,0.331936f, 0.295824f,-0.289072f,0.910453f,
0.404509f,0.0f,0.293892f, 0.809017f,0.0f,0.587785f,
0.282362f,-0.5f,0.205148f, 0.774478f,-0.289072f,0.562691f,
0.282362f,0.5f,-0.205148f, 0.774478f,0.289072f,-0.562691f,
0.349018f,0.5f,0.0f, 0.957307f,0.289072f,0.0f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.107853f,0.5f,-0.331936f, -0.295824f,0.289072f,-0.910453f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.282362f,0.5f,-0.205148f, -0.774478f,0.289072f,-0.562691f,
-0.349018f,0.5f,0.0f, -0.957307f,0.289072f,0.0f,
-0.282362f,0.5f,0.205148f, -0.774478f,0.289072f,0.562691f,
-0.107853f,0.5f,0.331936f, -0.295824f,0.289072f,0.910453f,
0.107853f,0.5f,0.331936f, 0.295824f,0.289072f,0.910453f,
0.282362f,0.5f,0.205148f, 0.774478f,0.289072f,0.562691f,
};
static float BarrelTex[] = {
0.0f,0.5f,
0.0f,0.85f,
0.0f,0.75f,
0.0f,0.95f,
0.0f,0.05f,
0.0f,-0.05f,
0.0f,0.15f,
0.0f,0.25f,
0.0f,0.35f,
0.0f,0.45f,
0.0f,0.55f,
0.0f,0.65f,
1.0f,0.5f,
1.0f,0.75f,
1.0f,0.85f,
1.0f,0.95f,
1.0f,-0.05f,
1.0f,0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
0.0f,0.75f,
0.5f,0.85f,
0.5f,0.75f,
0.0f,0.85f,
0.5f,0.95f,
0.0f,0.95f,
0.0f,-0.05f,
0.5f,0.05f,
0.5f,-0.05f,
0.0f,0.05f,
0.5f,0.15f,
0.0f,0.15f,
0.5f,0.25f,
0.0f,0.25f,
0.5f,0.35f,
0.0f,0.35f,
0.5f,0.45f,
0.0f,0.45f,
0.5f,0.55f,
0.0f,0.55f,
0.5f,0.65f,
0.0f,0.65f,
1.0f,0.85f,
1.0f,0.75f,
1.0f,0.95f,
1.0f,0.05f,
1.0f,-0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
};
static unsigned short BarrelIdx[] = {
0,1,2,
0,3,1,
0,4,5,
0,6,4,
0,7,6,
0,8,7,
0,9,8,
0,10,9,
0,11,10,
0,2,11,
12,13,14,
12,14,15,
12,16,17,
12,17,18,
12,18,19,
12,19,20,
12,20,21,
12,21,22,
12,22,23,
12,23,13,
24,25,26,
24,27,25,
27,28,25,
27,29,28,
30,31,32,
30,33,31,
33,34,31,
33,35,34,
35,36,34,
35,37,36,
37,38,36,
37,39,38,
39,40,38,
39,41,40,
41,42,40,
41,43,42,
43,44,42,
43,45,44,
45,26,44,
45,24,26,
26,46,47,
26,25,46,
25,48,46,
25,28,48,
32,49,50,
32,31,49,
31,51,49,
31,34,51,
34,52,51,
34,36,52,
36,53,52,
36,38,53,
38,54,53,
38,40,54,
40,55,54,
40,42,55,
42,56,55,
42,44,56,
44,47,56,
44,26,47,
};

View File

@@ -0,0 +1,318 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define LargeMeshVtxCount 81
#define LargeMeshIdxCount 384
static float LargeMeshVtx[] = {
-25.0f,-2.19407f,18.5625f, 0.232976f,0.967754f,0.0957829f,
-25.0f,0.0644502f,24.75f, 0.188094f,0.871343f,-0.45319f,
-18.75f,-4.50287f,18.5625f, -0.0716098f,0.995449f,0.0628767f,
-18.75f,-0.39999f,24.75f, -0.0602794f,0.895848f,-0.440253f,
-12.5f,-1.2166f,18.5625f, -0.269469f,0.961403f,0.0555879f,
-12.5f,-0.942431f,24.75f, -0.0997841f,0.993258f,0.0589987f,
-6.25f,1.93598f,18.5625f, -0.283933f,0.956351f,-0.0691025f,
-6.25f,-0.445954f,24.75f, -0.180725f,0.942766f,0.280233f,
0.0f,2.76983f,18.5625f, 0.171645f,0.984908f,0.0222501f,
0.0f,2.76642f,24.75f, 0.0784993f,0.995428f,-0.0544117f,
6.25f,-2.53736f,18.5625f, 0.248298f,0.965028f,0.0840741f,
6.25f,-0.915645f,24.75f, 0.164311f,0.945856f,-0.279926f,
12.5f,-1.60054f,18.5625f, -0.180435f,0.983586f,0.00115547f,
12.5f,0.831925f,24.75f, -0.0692495f,0.964821f,-0.253623f,
18.75f,-0.800282f,18.5625f, 0.10755f,0.951538f,0.288112f,
18.75f,-1.47284f,24.75f, 0.232178f,0.972664f,0.00429361f,
25.0f,-2.78379f,18.5625f, 0.1833f,0.937477f,0.295867f,
25.0f,-0.967508f,24.75f, -0.0773477f,0.956641f,-0.280812f,
-25.0f,-0.352038f,12.375f, -0.192222f,0.972435f,0.131987f,
-18.75f,0.681228f,12.375f, -0.107779f,0.962569f,0.248686f,
-12.5f,2.72065f,12.375f, 0.0520846f,0.993034f,0.105692f,
-6.25f,-1.78776f,12.375f, -0.0133223f,0.99674f,-0.0795754f,
0.0f,1.57707f,12.375f, -0.129025f,0.969662f,-0.207627f,
6.25f,0.424356f,12.375f, 0.180995f,0.97074f,0.157815f,
12.5f,0.283234f,12.375f, -0.16285f,0.973539f,0.160316f,
18.75f,2.57015f,12.375f, -0.165454f,0.978339f,0.124408f,
25.0f,3.07363f,12.375f, -0.00454559f,0.988151f,0.153417f,
-25.0f,-0.893751f,6.1875f, -0.0836251f,0.990084f,-0.112876f,
-18.75f,0.930932f,6.1875f, 0.00269413f,0.971838f,-0.235633f,
-12.5f,-0.684529f,6.1875f, -0.010319f,0.927048f,-0.3748f,
-6.25f,-0.661383f,6.1875f, 0.012265f,0.999875f,-0.00994222f,
0.0f,0.385718f,6.1875f, -0.15435f,0.984937f,-0.0779465f,
6.25f,0.589796f,6.1875f, 0.0241717f,0.999582f,-0.0158589f,
12.5f,0.47454f,6.1875f, -0.017184f,0.997953f,-0.0616073f,
18.75f,1.59939f,6.1875f, -0.0902706f,0.957309f,-0.274609f,
25.0f,1.13434f,6.1875f, 0.0346006f,0.957441f,-0.286547f,
-25.0f,0.74548f,0.0f, 0.329903f,0.930812f,0.157334f,
-18.75f,-2.47437f,0.0f, 0.247844f,0.968142f,0.0357041f,
-12.5f,-4.16309f,1.81975e-007f, -0.0623898f,0.997626f,-0.0291436f,
-6.25f,-0.700022f,0.0f, -0.217067f,0.974987f,-0.0477624f,
0.0f,-0.0957388f,0.0f, -0.117693f,0.990712f,-0.068098f,
6.25f,0.614077f,0.0f, -0.0713214f,0.997305f,0.01722f,
12.5f,0.299109f,0.0f, 0.218606f,0.968641f,0.118094f,
18.75f,-1.71753f,0.0f, 0.0339493f,0.985612f,-0.165579f,
25.0f,-1.12638f,0.0f, -0.0547573f,0.989177f,-0.136126f,
-25.0f,-0.403319f,-6.1875f, -0.1263f,0.989211f,-0.074223f,
-18.75f,-0.0730335f,-6.1875f, 0.0173428f,0.965382f,0.260261f,
-12.5f,-0.450125f,-6.1875f, 0.0658811f,0.875f,0.479619f,
-6.25f,-0.180204f,-6.1875f, 0.0116584f,0.981445f,0.19139f,
0.0f,-0.632679f,-6.1875f, -0.0557983f,0.993041f,-0.103716f,
6.25f,0.308409f,-6.1875f, -0.191898f,0.96766f,-0.163737f,
12.5f,2.5011f,-6.1875f, 0.0758397f,0.996403f,-0.0378189f,
18.75f,-1.69303f,-6.1875f, 0.16761f,0.974057f,0.15205f,
25.0f,-0.141349f,-6.1875f, -0.204846f,0.978471f,0.0251341f,
-25.0f,-1.10316f,-12.375f, -0.0350644f,0.993748f,-0.106001f,
-18.75f,1.06711f,-12.375f, -0.309806f,0.919244f,-0.242922f,
-12.5f,3.61544f,-12.375f, -0.0506281f,0.998702f,-0.00561657f,
-6.25f,1.6504f,-12.375f, 0.322294f,0.937465f,0.131477f,
0.0f,-1.60595f,-12.375f, 0.086016f,0.995916f,0.0274459f,
6.25f,-0.849859f,-12.375f, -0.0332811f,0.997087f,0.0686255f,
12.5f,-0.942201f,-12.375f, -0.153559f,0.982185f,-0.108312f,
18.75f,0.494873f,-12.375f, 0.0753195f,0.981472f,0.176181f,
25.0f,-0.333828f,-12.375f, 0.035057f,0.987194f,0.155624f,
-25.0f,2.1862f,-18.5625f, 0.612899f,0.782306f,0.111138f,
-18.75f,-3.38259f,-18.5625f, 0.0194078f,0.992789f,-0.118297f,
-12.5f,-0.880916f,-18.5625f, -0.282251f,0.949875f,-0.13443f,
-6.25f,0.818158f,-18.5625f, 0.1476f,0.981788f,-0.119612f,
0.0f,-1.48019f,-18.5625f, -0.044551f,0.996013f,-0.0772824f,
6.25f,1.47123f,-18.5625f, -0.117036f,0.97986f,0.161792f,
12.5f,0.164076f,-18.5625f, -0.0340355f,0.978993f,0.201034f,
18.75f,2.14568f,-18.5625f, -0.0439269f,0.994859f,0.0912435f,
25.0f,0.626506f,-18.5625f, 0.208015f,0.968592f,0.136229f,
-25.0f,0.296889f,-24.75f, 0.46973f,0.844327f,-0.257809f,
-18.75f,-3.18022f,-24.75f, -0.0226758f,0.998794f,-0.0435401f,
-12.5f,1.8927f,-24.75f, -0.202772f,0.919836f,0.335836f,
-6.25f,1.46387f,-24.75f, 0.224904f,0.955746f,0.189652f,
0.0f,-2.52726f,-24.75f, -0.0435882f,0.993572f,-0.10447f,
6.25f,1.30397f,-24.75f, -0.28646f,0.956525f,-0.0547707f,
12.5f,1.85812f,-24.75f, 0.0521949f,0.979796f,0.193067f,
18.75f,1.56331f,-24.75f, -0.0270784f,0.999629f,-0.00293115f,
25.0f,1.05366f,-24.75f, 0.161f,0.986887f,-0.0115473f,
};
static float LargeMeshTex[] = {
0.125f,0.0f,
0.0f,0.0f,
0.125f,0.125f,
0.0f,0.125f,
0.125f,0.25f,
0.0f,0.25f,
0.125f,0.375f,
0.0f,0.375f,
0.125f,0.5f,
0.0f,0.5f,
0.125f,0.625f,
0.0f,0.625f,
0.125f,0.75f,
0.0f,0.75f,
0.125f,0.875f,
0.0f,0.875f,
0.125f,1.0f,
0.0f,1.0f,
0.25f,0.0f,
0.25f,0.125f,
0.25f,0.25f,
0.25f,0.375f,
0.25f,0.5f,
0.25f,0.625f,
0.25f,0.75f,
0.25f,0.875f,
0.25f,1.0f,
0.375f,0.0f,
0.375f,0.125f,
0.375f,0.25f,
0.375f,0.375f,
0.375f,0.5f,
0.375f,0.625f,
0.375f,0.75f,
0.375f,0.875f,
0.375f,1.0f,
0.5f,0.0f,
0.5f,0.125f,
0.5f,0.25f,
0.5f,0.375f,
0.5f,0.5f,
0.5f,0.625f,
0.5f,0.75f,
0.5f,0.875f,
0.5f,1.0f,
0.625f,0.0f,
0.625f,0.125f,
0.625f,0.25f,
0.625f,0.375f,
0.625f,0.5f,
0.625f,0.625f,
0.625f,0.75f,
0.625f,0.875f,
0.625f,1.0f,
0.75f,0.0f,
0.75f,0.125f,
0.75f,0.25f,
0.75f,0.375f,
0.75f,0.5f,
0.75f,0.625f,
0.75f,0.75f,
0.75f,0.875f,
0.75f,1.0f,
0.875f,0.0f,
0.875f,0.125f,
0.875f,0.25f,
0.875f,0.375f,
0.875f,0.5f,
0.875f,0.625f,
0.875f,0.75f,
0.875f,0.875f,
0.875f,1.0f,
1.0f,0.0f,
1.0f,0.125f,
1.0f,0.25f,
1.0f,0.375f,
1.0f,0.5f,
1.0f,0.625f,
1.0f,0.75f,
1.0f,0.875f,
1.0f,1.0f,
};
static unsigned short LargeMeshIdx[] = {
0,1,2,
3,2,1,
2,3,4,
5,4,3,
4,5,6,
7,6,5,
6,7,8,
9,8,7,
8,9,10,
11,10,9,
10,11,12,
13,12,11,
12,13,14,
15,14,13,
14,15,16,
17,16,15,
18,0,19,
2,19,0,
19,2,20,
4,20,2,
20,4,21,
6,21,4,
21,6,22,
8,22,6,
22,8,23,
10,23,8,
23,10,24,
12,24,10,
24,12,25,
14,25,12,
25,14,26,
16,26,14,
27,18,28,
19,28,18,
28,19,29,
20,29,19,
29,20,30,
21,30,20,
30,21,31,
22,31,21,
31,22,32,
23,32,22,
32,23,33,
24,33,23,
33,24,34,
25,34,24,
34,25,35,
26,35,25,
36,27,37,
28,37,27,
37,28,38,
29,38,28,
38,29,39,
30,39,29,
39,30,40,
31,40,30,
40,31,41,
32,41,31,
41,32,42,
33,42,32,
42,33,43,
34,43,33,
43,34,44,
35,44,34,
45,36,46,
37,46,36,
46,37,47,
38,47,37,
47,38,48,
39,48,38,
48,39,49,
40,49,39,
49,40,50,
41,50,40,
50,41,51,
42,51,41,
51,42,52,
43,52,42,
52,43,53,
44,53,43,
54,45,55,
46,55,45,
55,46,56,
47,56,46,
56,47,57,
48,57,47,
57,48,58,
49,58,48,
58,49,59,
50,59,49,
59,50,60,
51,60,50,
60,51,61,
52,61,51,
61,52,62,
53,62,52,
63,54,64,
55,64,54,
64,55,65,
56,65,55,
65,56,66,
57,66,56,
66,57,67,
58,67,57,
67,58,68,
59,68,58,
68,59,69,
60,69,59,
69,60,70,
61,70,60,
70,61,71,
62,71,61,
72,63,73,
64,73,63,
73,64,74,
65,74,64,
74,65,75,
66,75,65,
75,66,76,
67,76,66,
76,67,77,
68,77,67,
77,68,78,
69,78,68,
78,69,79,
70,79,69,
79,70,80,
71,80,70,
};

View File

@@ -0,0 +1,512 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "../common/common.h"
#include "../common/ctrl_func.h"
#include "../common/render_func.h"
#include "../common/perf_func.h"
#include "physics_func.h"
#include "barrel.h"
#include "landscape.h"
#ifdef _WIN32
#include <gl/gl.h>
#include <gl/glu.h>
#endif
// ARA begin insert new code
#ifdef __ANDROID__
#include <EGL/egl.h>
#include <GLES/gl.h>
#endif
// ARA end
#define SAMPLE_NAME "api_physics_effects/3_sleep"
#define ENABLE_DEBUG_DRAW
#ifdef ENABLE_DEBUG_DRAW
//#define ENABLE_DEBUG_DRAW_CONTACT
//#define ENABLE_DEBUG_DRAW_AABB
#define ENABLE_DEBUG_DRAW_ISLAND
#endif
static bool s_isRunning = true;
int sceneId = 0;
bool simulating = false;
int landscapeMeshId;
int convexMeshId;
void render(void)
{
render_begin();
const PfxVector3 colorWhite(1.0f);
const PfxVector3 colorGray(0.7f);
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxVector3 color = state.isAsleep()?colorGray:colorWhite;
PfxTransform3 rbT(state.getOrientation(), state.getPosition());
PfxShapeIterator itrShape(coll);
for(int j=0;j<coll.getNumShapes();j++,++itrShape) {
const PfxShape &shape = *itrShape;
PfxTransform3 offsetT = shape.getOffsetTransform();
PfxTransform3 worldT = rbT * offsetT;
switch(shape.getType()) {
case kPfxShapeSphere:
render_sphere(
worldT,
color,
PfxFloatInVec(shape.getSphere().m_radius));
break;
case kPfxShapeBox:
render_box(
worldT,
color,
shape.getBox().m_half);
break;
case kPfxShapeCapsule:
render_capsule(
worldT,
color,
PfxFloatInVec(shape.getCapsule().m_radius),
PfxFloatInVec(shape.getCapsule().m_halfLen));
break;
case kPfxShapeCylinder:
render_cylinder(
worldT,
color,
PfxFloatInVec(shape.getCylinder().m_radius),
PfxFloatInVec(shape.getCylinder().m_halfLen));
break;
case kPfxShapeConvexMesh:
render_mesh(
worldT,
color,
convexMeshId);
break;
case kPfxShapeLargeTriMesh:
render_mesh(
worldT,
color,
landscapeMeshId);
break;
default:
break;
}
}
}
render_debug_begin();
#ifdef ENABLE_DEBUG_DRAW_CONTACT
for(int i=0;i<physics_get_num_contacts();i++) {
const PfxContactManifold &contact = physics_get_contact(i);
const PfxRigidState &stateA = physics_get_state(contact.getRigidBodyIdA());
const PfxRigidState &stateB = physics_get_state(contact.getRigidBodyIdB());
for(int j=0;j<contact.getNumContacts();j++) {
const PfxContactPoint &cp = contact.getContactPoint(j);
PfxVector3 pA = stateA.getPosition()+rotate(stateA.getOrientation(),pfxReadVector3(cp.m_localPointA));
render_debug_point(pA,PfxVector3(0,0,1));
}
}
#endif
#ifdef ENABLE_DEBUG_DRAW_AABB
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxVector3 center = state.getPosition() + coll.getCenter();
PfxVector3 half = absPerElem(PfxMatrix3(state.getOrientation())) * coll.getHalf();
render_debug_box(center,half,PfxVector3(1,0,0));
}
#endif
#ifdef ENABLE_DEBUG_DRAW_ISLAND
const PfxIsland *island = physics_get_islands();
if(island) {
for(PfxUInt32 i=0;i<pfxGetNumIslands(island);i++) {
PfxIslandUnit *islandUnit = pfxGetFirstUnitInIsland(island,i);
PfxVector3 aabbMin(SCE_PFX_FLT_MAX);
PfxVector3 aabbMax(-SCE_PFX_FLT_MAX);
for(;islandUnit!=NULL;islandUnit=pfxGetNextUnitInIsland(islandUnit)) {
const PfxRigidState &state = physics_get_state(pfxGetUnitId(islandUnit));
const PfxCollidable &coll = physics_get_collidable(pfxGetUnitId(islandUnit));
PfxVector3 center = state.getPosition() + coll.getCenter();
PfxVector3 half = absPerElem(PfxMatrix3(state.getOrientation())) * coll.getHalf();
aabbMin = minPerElem(aabbMin,center-half);
aabbMax = maxPerElem(aabbMax,center+half);
}
render_debug_box((aabbMax+aabbMin)*0.5f,(aabbMax-aabbMin)*0.5f,PfxVector3(0,1,0));
}
}
#endif
render_debug_end();
render_end();
}
int init(void)
{
perf_init();
ctrl_init();
render_init();
physics_init();
landscapeMeshId = render_init_mesh(
LargeMeshVtx,sizeof(float)*6,
LargeMeshVtx+3,sizeof(float)*6,
LargeMeshIdx,sizeof(unsigned short)*3,
LargeMeshVtxCount,LargeMeshIdxCount/3);
convexMeshId = render_init_mesh(
BarrelVtx,sizeof(float)*6,
BarrelVtx+3,sizeof(float)*6,
BarrelIdx,sizeof(unsigned short)*3,
BarrelVtxCount,BarrelIdxCount/3);
return 0;
}
static int shutdown(void)
{
ctrl_release();
render_release();
physics_release();
perf_release();
return 0;
}
void update(void)
{
float angX,angY,r;
render_get_view_angle(angX,angY,r);
ctrl_update();
if(ctrl_button_pressed(BTN_UP)) {
angX -= 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_DOWN)) {
angX += 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_LEFT)) {
angY -= 0.05f;
}
if(ctrl_button_pressed(BTN_RIGHT)) {
angY += 0.05f;
}
if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
r *= 1.1f;
if(r > 500.0f) r = 500.0f;
}
if(ctrl_button_pressed(BTN_ZOOM_IN)) {
r *= 0.9f;
if(r < 1.0f) r = 1.0f;
}
if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
physics_create_scene(sceneId);
}
if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
physics_create_scene(++sceneId);
}
if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
simulating = !simulating;
}
if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
simulating = true;
}
else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
simulating = false;
}
render_set_view_angle(angX,angY,r);
}
#ifndef _WIN32
// ARA begin insert new code
#ifdef __ANDROID__
///////////////////////////////////////////////////////////////////////////////
// sceneChange
//
/// This function is used to change the physics scene on Android devices
///////////////////////////////////////////////////////////////////////////////
void sceneChange()
{
physics_create_scene(sceneId++);
}
#else // __ANDROID__
// ARA end
///////////////////////////////////////////////////////////////////////////////
// Main
int main(void)
{
init();
physics_create_scene(sceneId);
printf("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
while (s_isRunning) {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
shutdown();
printf("## %s: FINISHED ##\n", SAMPLE_NAME);
return 0;
}
// ARA begin insert new code
#endif // __ANDROID__
// ARA end
#else // _WIN32
///////////////////////////////////////////////////////////////////////////////
// WinMain
extern HDC hDC;
extern HGLRC hRC;
HWND hWnd;
HINSTANCE hInstance;
void releaseWindow()
{
if(hRC) {
wglMakeCurrent(0,0);
wglDeleteContext(hRC);
}
if(hDC) ReleaseDC(hWnd,hDC);
if(hWnd) DestroyWindow(hWnd);
UnregisterClass(SAMPLE_NAME,hInstance);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg) {
case WM_SYSCOMMAND:
{
switch (wParam) {
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_SIZE:
render_resize(LOWORD(lParam),HIWORD(lParam));
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
bool createWindow(char* title, int width, int height)
{
WNDCLASS wc;
RECT rect;
rect.left=0;
rect.right=width;
rect.top=0;
rect.bottom=height;
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = SAMPLE_NAME;
if(!RegisterClass(&wc)) {
return false;
}
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
if(!(hWnd=CreateWindowEx(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,SAMPLE_NAME,title,
WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
0,0,rect.right-rect.left,rect.bottom-rect.top,
NULL,NULL,hInstance,NULL))) {
releaseWindow();
return false;
}
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0,
0, 0,
0, 0,
0, 0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if(!(hDC=GetDC(hWnd)))
{
releaseWindow();
OutputDebugString("");
return FALSE;
}
int pixelformat;
if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 ){
OutputDebugString("ChoosePixelFormat Failed....");
return FALSE;
}
if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE){
OutputDebugString("SetPixelFormat Failed....");
return FALSE;
}
if (!(hRC=wglCreateContext(hDC))){
OutputDebugString("Creating HGLRC Failed....");
return FALSE;
}
// Set Vsync
//BOOL (WINAPI *wglSwapIntervalEXT)(int) = NULL;
//if(strstr((char*)glGetString( GL_EXTENSIONS ),"WGL_EXT_swap_control")== 0) {
//}
//else {
//wglSwapIntervalEXT = (BOOL (WINAPI*)(int))wglGetProcAddress("wglSwapIntervalEXT");
//if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
//}
wglMakeCurrent(hDC,hRC);
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
render_resize(width, height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return 0;
}
init();
physics_create_scene(sceneId);
SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
MSG msg;
while(s_isRunning) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if(msg.message==WM_QUIT) {
s_isRunning = false;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
}
shutdown();
SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);
releaseWindow();
return (msg.wParam);
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,53 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __PHYSICS_FUNC_H__
#define __PHYSICS_FUNC_H__
#define SCE_PFX_USE_PERFCOUNTER
#include "physics_effects.h"
using namespace sce::PhysicsEffects;
//E Simulation
//J シミュレーション
bool physics_init();
void physics_release();
void physics_create_scene(int sceneId);
void physics_simulate();
//E Picking
//J ピッキング
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2);
void physics_pick_update(const PfxVector3 &p);
void physics_pick_end();
//E Change parameters
//J パラメータの取得
int physics_get_num_rigidbodies();
const PfxRigidState& physics_get_state(int id);
const PfxRigidBody& physics_get_body(int id);
const PfxCollidable& physics_get_collidable(int id);
// Get contact information
int physics_get_num_contacts();
const PfxContactManifold &physics_get_contact(int id);
// Get simulation island
const PfxIsland* physics_get_islands();
#endif /* __PHYSICS_FUNC_H__ */

View File

@@ -0,0 +1,721 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="4_motion_type.windows"
ProjectGUID="{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}"
RootNamespace="4_motion_type.win32"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Win32 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
ShowProgress="0"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
ShowProgress="0"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib "
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
AdditionalDependencies="opengl32.lib glu32.lib"
ShowProgress="0"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
ShowProgress="0"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
>
<File
RelativePath=".\physics_func.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\physics_func.cpp"
>
</File>
</Filter>
<Filter
Name="Common"
>
<File
RelativePath="..\common\common.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\perf_func.h"
>
</File>
<File
RelativePath="..\common\perf_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\render_func.h"
>
</File>
<File
RelativePath="..\common\render_func.win32.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,75 @@
cmake_minimum_required(VERSION 2.4)
#this line has to appear before 'PROJECT' in order to be able to disable incremental linking
SET(MSVC_INCREMENTAL_DEFAULT ON)
PROJECT(App_4_MotionType)
IF (NOT CMAKE_BUILD_TYPE)
# SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_BUILD_TYPE "Release")
ENDIF (NOT CMAKE_BUILD_TYPE)
OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" ON)
OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
ENDIF(COMMAND cmake_policy)
SET(App_3_Sleep_SRCS
main.cpp
physics_func.cpp
../common/ctrl_func.win32.cpp
../common/perf_func.win32.cpp
../common/render_func.win32.cpp
)
SET(App_3_Sleep_HDRS
physics_func.h
../common/render_func.h
../common/common.h
../common/ctrl_func.h
../common/perf_func.h
)
INCLUDE_DIRECTORIES(
${PHYSICS_EFFECTS_SOURCE_DIR}/include
# ${VECTOR_MATH_INCLUDE}
)
#LINK_DIRECTORIES(
#
#)
#ADD_DEFINITIONS(-DUNICODE)
#ADD_DEFINITIONS(-D_UNICODE)
ADD_EXECUTABLE(App_4_MotionType WIN32
${App_3_Sleep_SRCS}
${App_3_Sleep_HDRS}
)
TARGET_LINK_LIBRARIES(App_4_MotionType
PfxBaseLevel
PfxLowLevel
PfxUtil
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(App_4_MotionType PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_4_MotionType PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_4_MotionType PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF()

View File

@@ -0,0 +1,481 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "../common/common.h"
#include "../common/ctrl_func.h"
#include "../common/render_func.h"
#include "../common/perf_func.h"
#include "physics_func.h"
#ifdef _WIN32
#include <gl/gl.h>
#include <gl/glu.h>
#endif
// ARA begin insert new code
#ifdef __ANDROID__
#include <EGL/egl.h>
#include <GLES/gl.h>
#endif
// ARA end
#define SAMPLE_NAME "api_physics_effects/4_motion_type"
//#define ENABLE_DEBUG_DRAW
#ifdef ENABLE_DEBUG_DRAW
#define ENABLE_DEBUG_DRAW_CONTACT
#define ENABLE_DEBUG_DRAW_AABB
#define ENABLE_DEBUG_DRAW_ISLAND
#endif
static bool s_isRunning = true;
int sceneId = 0;
bool simulating = false;
void render(void)
{
render_begin();
const PfxVector3 colorWhite(1.0f);
const PfxVector3 colorGray(0.7f);
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxVector3 color = state.isAsleep()?colorGray:colorWhite;
PfxTransform3 rbT(state.getOrientation(), state.getPosition());
PfxShapeIterator itrShape(coll);
for(int j=0;j<coll.getNumShapes();j++,++itrShape) {
const PfxShape &shape = *itrShape;
PfxTransform3 offsetT = shape.getOffsetTransform();
PfxTransform3 worldT = rbT * offsetT;
switch(shape.getType()) {
case kPfxShapeSphere:
render_sphere(
worldT,
color,
PfxFloatInVec(shape.getSphere().m_radius));
break;
case kPfxShapeBox:
render_box(
worldT,
color,
shape.getBox().m_half);
break;
case kPfxShapeCapsule:
render_capsule(
worldT,
color,
PfxFloatInVec(shape.getCapsule().m_radius),
PfxFloatInVec(shape.getCapsule().m_halfLen));
break;
case kPfxShapeCylinder:
render_cylinder(
worldT,
color,
PfxFloatInVec(shape.getCylinder().m_radius),
PfxFloatInVec(shape.getCylinder().m_halfLen));
break;
default:
break;
}
}
}
render_debug_begin();
#ifdef ENABLE_DEBUG_DRAW_CONTACT
for(int i=0;i<physics_get_num_contacts();i++) {
const PfxContactManifold &contact = physics_get_contact(i);
const PfxRigidState &stateA = physics_get_state(contact.getRigidBodyIdA());
const PfxRigidState &stateB = physics_get_state(contact.getRigidBodyIdB());
for(int j=0;j<contact.getNumContacts();j++) {
const PfxContactPoint &cp = contact.getContactPoint(j);
PfxVector3 pA = stateA.getPosition()+rotate(stateA.getOrientation(),pfxReadVector3(cp.m_localPointA));
render_debug_point(pA,PfxVector3(0,0,1));
}
}
#endif
#ifdef ENABLE_DEBUG_DRAW_AABB
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxVector3 center = state.getPosition() + coll.getCenter();
PfxVector3 half = absPerElem(PfxMatrix3(state.getOrientation())) * coll.getHalf();
render_debug_box(center,half,PfxVector3(1,0,0));
}
#endif
#ifdef ENABLE_DEBUG_DRAW_ISLAND
const PfxIsland *island = physics_get_islands();
if(island) {
for(PfxUInt32 i=0;i<pfxGetNumIslands(island);i++) {
PfxIslandUnit *islandUnit = pfxGetFirstUnitInIsland(island,i);
PfxVector3 aabbMin(SCE_PFX_FLT_MAX);
PfxVector3 aabbMax(-SCE_PFX_FLT_MAX);
for(;islandUnit!=NULL;islandUnit=pfxGetNextUnitInIsland(islandUnit)) {
const PfxRigidState &state = physics_get_state(pfxGetUnitId(islandUnit));
const PfxCollidable &coll = physics_get_collidable(pfxGetUnitId(islandUnit));
PfxVector3 center = state.getPosition() + coll.getCenter();
PfxVector3 half = absPerElem(PfxMatrix3(state.getOrientation())) * coll.getHalf();
aabbMin = minPerElem(aabbMin,center-half);
aabbMax = maxPerElem(aabbMax,center+half);
}
render_debug_box((aabbMax+aabbMin)*0.5f,(aabbMax-aabbMin)*0.5f,PfxVector3(0,1,0));
}
}
#endif
render_debug_end();
render_end();
}
int init(void)
{
perf_init();
ctrl_init();
render_init();
physics_init();
return 0;
}
static int shutdown(void)
{
ctrl_release();
render_release();
physics_release();
perf_release();
return 0;
}
void update(void)
{
float angX,angY,r;
render_get_view_angle(angX,angY,r);
ctrl_update();
if(ctrl_button_pressed(BTN_UP)) {
angX -= 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_DOWN)) {
angX += 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_LEFT)) {
angY -= 0.05f;
}
if(ctrl_button_pressed(BTN_RIGHT)) {
angY += 0.05f;
}
if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
r *= 1.1f;
if(r > 500.0f) r = 500.0f;
}
if(ctrl_button_pressed(BTN_ZOOM_IN)) {
r *= 0.9f;
if(r < 1.0f) r = 1.0f;
}
if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
physics_create_scene(sceneId);
}
if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
physics_create_scene(++sceneId);
}
if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
simulating = !simulating;
}
if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
simulating = true;
}
else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
simulating = false;
}
render_set_view_angle(angX,angY,r);
}
#ifndef _WIN32
// ARA begin insert new code
#ifdef __ANDROID__
///////////////////////////////////////////////////////////////////////////////
// sceneChange
//
/// This function is used to change the physics scene on Android devices
///////////////////////////////////////////////////////////////////////////////
void sceneChange()
{
physics_create_scene(sceneId++);
}
#else // __ANDROID__
// ARA end
///////////////////////////////////////////////////////////////////////////////
// Main
int main(void)
{
init();
physics_create_scene(sceneId);
printf("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
while (s_isRunning) {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
shutdown();
printf("## %s: FINISHED ##\n", SAMPLE_NAME);
return 0;
}
// ARA begin insert new code
#endif // __ANDROID__
// ARA end
#else // _WIN32
///////////////////////////////////////////////////////////////////////////////
// WinMain
extern HDC hDC;
extern HGLRC hRC;
HWND hWnd;
HINSTANCE hInstance;
void releaseWindow()
{
if(hRC) {
wglMakeCurrent(0,0);
wglDeleteContext(hRC);
}
if(hDC) ReleaseDC(hWnd,hDC);
if(hWnd) DestroyWindow(hWnd);
UnregisterClass(SAMPLE_NAME,hInstance);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg) {
case WM_SYSCOMMAND:
{
switch (wParam) {
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_SIZE:
render_resize(LOWORD(lParam),HIWORD(lParam));
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
bool createWindow(char* title, int width, int height)
{
WNDCLASS wc;
RECT rect;
rect.left=0;
rect.right=width;
rect.top=0;
rect.bottom=height;
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = SAMPLE_NAME;
if(!RegisterClass(&wc)) {
return false;
}
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
if(!(hWnd=CreateWindowEx(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,SAMPLE_NAME,title,
WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
0,0,rect.right-rect.left,rect.bottom-rect.top,
NULL,NULL,hInstance,NULL))) {
releaseWindow();
return false;
}
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0,
0, 0,
0, 0,
0, 0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if(!(hDC=GetDC(hWnd)))
{
releaseWindow();
OutputDebugString("");
return FALSE;
}
int pixelformat;
if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 ){
OutputDebugString("ChoosePixelFormat Failed....");
return FALSE;
}
if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE){
OutputDebugString("SetPixelFormat Failed....");
return FALSE;
}
if (!(hRC=wglCreateContext(hDC))){
OutputDebugString("Creating HGLRC Failed....");
return FALSE;
}
// Set Vsync
//BOOL (WINAPI *wglSwapIntervalEXT)(int) = NULL;
//if(strstr((char*)glGetString( GL_EXTENSIONS ),"WGL_EXT_swap_control")== 0) {
//}
//else {
//wglSwapIntervalEXT = (BOOL (WINAPI*)(int))wglGetProcAddress("wglSwapIntervalEXT");
//if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
//}
wglMakeCurrent(hDC,hRC);
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
render_resize(width, height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return 0;
}
init();
physics_create_scene(sceneId);
SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
MSG msg;
while(s_isRunning) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if(msg.message==WM_QUIT) {
s_isRunning = false;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
}
shutdown();
SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);
releaseWindow();
return (msg.wParam);
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1,822 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "physics_func.h"
#include "../common/perf_func.h"
///////////////////////////////////////////////////////////////////////////////
// Simulation Data
#define NUM_RIGIDBODIES 500
#define NUM_JOINTS 500
#define NUM_CONTACTS 4000
const float timeStep = 0.016f;
const float separateBias = 0.1f;
int iteration = 5;
//J ワールドサイズ
//E World size
PfxVector3 worldCenter(0.0f);
PfxVector3 worldExtent(500.0f);
//J 剛体
//E Rigid body
PfxRigidState states[NUM_RIGIDBODIES];
PfxRigidBody bodies[NUM_RIGIDBODIES];
PfxCollidable collidables[NUM_RIGIDBODIES];
PfxSolverBody solverBodies[NUM_RIGIDBODIES];
int numRigidBodies = 0;
//J プロキシ
//E Proxies
PfxBroadphaseProxy proxies[NUM_RIGIDBODIES];
//J ジョイント
//E Joint
PfxConstraintPair jointPairs[NUM_JOINTS];
PfxJoint joints[NUM_JOINTS];
int numJoints = 0;
//J ペア
//E Pairs
unsigned int pairSwap;
unsigned int numPairs[2];
PfxBroadphasePair pairsBuff[2][NUM_CONTACTS];
//J コンタクト
//E Contacts
PfxContactManifold contacts[NUM_CONTACTS];
int numContacts;
PfxUInt32 contactIdPool[NUM_CONTACTS];
int numContactIdPool;
//J シミュレーションアイランド
//E Island generation
PfxIsland *island=NULL;
PfxUInt8 SCE_PFX_ALIGNED(16) islandBuff[32*NUM_RIGIDBODIES]; // Island buffer should be 32 * the number of rigid bodies.
//J スリープ制御
//E Sleep control
/*
A sleeping object wakes up, when
* a new pair related to this rigid body is created
* a pair releated to this rigid body is removed
* a rigid body's velocity or position are updated
*/
//J スリープに入るカウント
//E Count to enter sleeping
const PfxUInt32 sleepCount = 180;
//J 速度が閾値以下ならばスリープカウントが増加
//E If velocity is under the following value, sleep count is increased.
const PfxFloat sleepVelocity = 0.1f;
//J 一時バッファ
//E Temporary buffers
#define POOL_BYTES (5*1024*1024)
unsigned char SCE_PFX_ALIGNED(128) poolBuff[POOL_BYTES];
//J 一時バッファ用スタックアロケータ
//E Stack allocator for temporary buffers
PfxHeapManager pool(poolBuff,POOL_BYTES);
// Keyframe
void updateKeyframe();
int keyframeId;
// Trigger
void updateTrigger();
int triggerId;
///////////////////////////////////////////////////////////////////////////////
// Simulation Function
int frame = 0;
void broadphase()
{
pairSwap = 1-pairSwap;
unsigned int &numPreviousPairs = numPairs[1-pairSwap];
unsigned int &numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *previousPairs = pairsBuff[1-pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
//J 剛体が最も分散している軸を見つける
//E Find the axis along which all rigid bodies are most widely positioned
int axis = 0;
{
PfxVector3 s(0.0f),s2(0.0f);
for(int i=0;i<numRigidBodies;i++) {
PfxVector3 c = states[i].getPosition();
s += c;
s2 += mulPerElem(c,c);
}
PfxVector3 v = s2 - mulPerElem(s,s) / (float)numRigidBodies;
if(v[1] > v[0]) axis = 1;
if(v[2] > v[axis]) axis = 2;
}
//J ブロードフェーズプロキシの更新
//E Create broadpahse proxies
{
for(int i=0;i<numRigidBodies;i++) {
pfxUpdateBroadphaseProxy(proxies[i],states[i],collidables[i],worldCenter,worldExtent,axis);
}
int workBytes = sizeof(PfxBroadphaseProxy) * numRigidBodies;
void *workBuff = pool.allocate(workBytes);
pfxParallelSort(proxies,numRigidBodies,workBuff,workBytes);
pool.deallocate(workBuff);
}
//J 交差ペア探索
//E Find overlapped pairs
{
PfxFindPairsParam findPairsParam;
findPairsParam.pairBytes = pfxGetPairBytesOfFindPairs(NUM_CONTACTS);
findPairsParam.pairBuff = pool.allocate(findPairsParam.pairBytes);
findPairsParam.workBytes = pfxGetWorkBytesOfFindPairs(NUM_CONTACTS);
findPairsParam.workBuff = pool.allocate(findPairsParam.workBytes);
findPairsParam.proxies = proxies;
findPairsParam.numProxies = numRigidBodies;
findPairsParam.maxPairs = NUM_CONTACTS;
findPairsParam.axis = axis;
PfxFindPairsResult findPairsResult;
int ret = pfxFindPairs(findPairsParam,findPairsResult);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxFindPairs failed %d\n",ret);
pool.deallocate(findPairsParam.workBuff);
//J 交差ペア合成
//E Decompose overlapped pairs into 3 arrays
PfxDecomposePairsParam decomposePairsParam;
decomposePairsParam.pairBytes = pfxGetPairBytesOfDecomposePairs(numPreviousPairs,findPairsResult.numPairs);
decomposePairsParam.pairBuff = pool.allocate(decomposePairsParam.pairBytes);
decomposePairsParam.workBytes = pfxGetWorkBytesOfDecomposePairs(numPreviousPairs,findPairsResult.numPairs);
decomposePairsParam.workBuff = pool.allocate(decomposePairsParam.workBytes);
decomposePairsParam.previousPairs = previousPairs;
decomposePairsParam.numPreviousPairs = numPreviousPairs;
decomposePairsParam.currentPairs = findPairsResult.pairs; // Set pairs from pfxFindPairs()
decomposePairsParam.numCurrentPairs = findPairsResult.numPairs; // Set the number of pairs from pfxFindPairs()
PfxDecomposePairsResult decomposePairsResult;
ret = pfxDecomposePairs(decomposePairsParam,decomposePairsResult);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxDecomposePairs failed %d\n",ret);
pool.deallocate(decomposePairsParam.workBuff);
PfxBroadphasePair *outNewPairs = decomposePairsResult.outNewPairs;
PfxBroadphasePair *outKeepPairs = decomposePairsResult.outKeepPairs;
PfxBroadphasePair *outRemovePairs = decomposePairsResult.outRemovePairs;
PfxUInt32 numOutNewPairs = decomposePairsResult.numOutNewPairs;
PfxUInt32 numOutKeepPairs = decomposePairsResult.numOutKeepPairs;
PfxUInt32 numOutRemovePairs = decomposePairsResult.numOutRemovePairs;
//J 廃棄ペアのコンタクトをプールに戻す
//E Put removed contacts into the contact pool
for(PfxUInt32 i=0;i<numOutRemovePairs;i++) {
contactIdPool[numContactIdPool++] = pfxGetContactId(outRemovePairs[i]);
//J 寝てる剛体を起こす
//E Wake up sleeping rigid bodies
PfxRigidState &stateA = states[pfxGetObjectIdA(outRemovePairs[i])];
PfxRigidState &stateB = states[pfxGetObjectIdB(outRemovePairs[i])];
if(stateA.isAsleep()) {
stateA.wakeup();
}
if(stateB.isAsleep()) {
stateB.wakeup();
}
}
//J 新規ペアのコンタクトのリンクと初期化
//E Add new contacts and initialize
for(PfxUInt32 i=0;i<numOutNewPairs;i++) {
int cId = 0;
if(numContactIdPool > 0) {
cId = contactIdPool[--numContactIdPool];
}
else {
cId = numContacts++;
}
if(cId >= NUM_CONTACTS) {
cId = 0;
}
SCE_PFX_ASSERT(cId < NUM_CONTACTS);
pfxSetContactId(outNewPairs[i],cId);
PfxContactManifold &contact = contacts[cId];
contact.reset(pfxGetObjectIdA(outNewPairs[i]),pfxGetObjectIdB(outNewPairs[i]));
//J 寝てる剛体を起こす
//E Wake up sleeping rigid bodies
PfxRigidState &stateA = states[pfxGetObjectIdA(outNewPairs[i])];
PfxRigidState &stateB = states[pfxGetObjectIdB(outNewPairs[i])];
if(stateA.isAsleep()) {
stateA.wakeup();
}
if(stateB.isAsleep()) {
stateB.wakeup();
}
}
//J 新規ペアと維持ペアを合成
//E Merge 'new' and 'keep' pairs
numCurrentPairs = 0;
for(PfxUInt32 i=0;i<numOutKeepPairs;i++) {
currentPairs[numCurrentPairs++] = outKeepPairs[i];
}
for(PfxUInt32 i=0;i<numOutNewPairs;i++) {
currentPairs[numCurrentPairs++] = outNewPairs[i];
}
pool.deallocate(decomposePairsParam.pairBuff);
pool.deallocate(findPairsParam.pairBuff);
}
{
int workBytes = sizeof(PfxBroadphasePair) * numCurrentPairs;
void *workBuff = pool.allocate(workBytes);
pfxParallelSort(currentPairs,numCurrentPairs,workBuff,workBytes);
pool.deallocate(workBuff);
}
}
void collision()
{
unsigned int numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
//J 衝突検出
//E Detect collisions
{
PfxDetectCollisionParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetCollidables = collidables;
param.numRigidBodies = numRigidBodies;
int ret = pfxDetectCollision(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxDetectCollision failed %d\n",ret);
}
//J リフレッシュ
//E Refresh contacts
{
PfxRefreshContactsParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.numRigidBodies = numRigidBodies;
int ret = pfxRefreshContacts(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxRefreshContacts failed %d\n",ret);
}
//J アイランド生成
//E Create simulation islands
{
PfxGenerateIslandParam param;
param.islandBuff = islandBuff;
param.islandBytes = 32*NUM_RIGIDBODIES;
param.pairs = currentPairs;
param.numPairs = numCurrentPairs;
param.numObjects = numRigidBodies;
PfxGenerateIslandResult result;
int ret = pfxGenerateIsland(param,result);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxGenerateIsland failed %d\n",ret);
island = result.island;
//J ジョイント分のペアを追加
//E Add joint pairs to islands
ret = pfxAppendPairs(island,jointPairs,numJoints);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxAppendPairs failed %d\n",ret);
}
}
void constraintSolver()
{
PfxPerfCounter pc;
unsigned int numCurrentPairs = numPairs[pairSwap];
PfxBroadphasePair *currentPairs = pairsBuff[pairSwap];
pc.countBegin("setup solver bodies");
{
PfxSetupSolverBodiesParam param;
param.states = states;
param.bodies = bodies;
param.solverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
int ret = pfxSetupSolverBodies(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupSolverBodies failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup contact constraints");
{
PfxSetupContactConstraintsParam param;
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
param.separateBias = separateBias;
int ret = pfxSetupContactConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("setup joint constraints");
{
PfxSetupJointConstraintsParam param;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetRigidBodies = bodies;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
for(int i=0;i<numJoints;i++) {
pfxUpdateJointPairs(jointPairs[i],i,joints[i],states[joints[i].m_rigidBodyIdA],states[joints[i].m_rigidBodyIdB]);
}
int ret = pfxSetupJointConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSetupJointConstraints failed %d\n",ret);
}
pc.countEnd();
pc.countBegin("solve constraints");
{
PfxSolveConstraintsParam param;
param.workBytes = pfxGetWorkBytesOfSolveConstraints(numRigidBodies,numCurrentPairs,numJoints);
param.workBuff = pool.allocate(param.workBytes);
param.contactPairs = currentPairs;
param.numContactPairs = numCurrentPairs;
param.offsetContactManifolds = contacts;
param.jointPairs = jointPairs;
param.numJointPairs = numJoints;
param.offsetJoints = joints;
param.offsetRigidStates = states;
param.offsetSolverBodies = solverBodies;
param.numRigidBodies = numRigidBodies;
param.iteration = iteration;
int ret = pfxSolveConstraints(param);
if(ret != SCE_PFX_OK) SCE_PFX_PRINTF("pfxSolveConstraints failed %d\n",ret);
pool.deallocate(param.workBuff);
}
pc.countEnd();
//pc.printCount();
}
void sleepOrWakeup()
{
PfxFloat sleepVelSqr = sleepVelocity * sleepVelocity;
for(PfxUInt32 i=0;i<(PfxUInt32)numRigidBodies;i++) {
PfxRigidState &state = states[i];
if(SCE_PFX_MOTION_MASK_CAN_SLEEP(state.getMotionType())) {
PfxFloat linVelSqr = lengthSqr(state.getLinearVelocity());
PfxFloat angVelSqr = lengthSqr(state.getAngularVelocity());
if(state.isAwake()) {
if( linVelSqr < sleepVelSqr && angVelSqr < sleepVelSqr ) {
state.incrementSleepCount();
}
else {
state.resetSleepCount();
}
}
}
}
if(island) {
for(PfxUInt32 i=0;i<pfxGetNumIslands(island);i++) {
int numActive = 0;
int numSleep = 0;
int numCanSleep = 0;
{
PfxIslandUnit *islandUnit = pfxGetFirstUnitInIsland(island,(PfxUInt32)i);
for(;islandUnit!=NULL;islandUnit=pfxGetNextUnitInIsland(islandUnit)) {
if(!(SCE_PFX_MOTION_MASK_CAN_SLEEP(states[pfxGetUnitId(islandUnit)].getMotionType()))) continue;
PfxRigidState &state = states[pfxGetUnitId(islandUnit)];
if(state.isAsleep()) {
numSleep++;
}
else {
numActive++;
if(state.getSleepCount() > sleepCount) {
numCanSleep++;
}
}
}
}
// Deactivate Island
if(numCanSleep > 0 && numCanSleep == numActive + numSleep) {
PfxIslandUnit *islandUnit = pfxGetFirstUnitInIsland(island,(PfxUInt32)i);
for(;islandUnit!=NULL;islandUnit=pfxGetNextUnitInIsland(islandUnit)) {
if(!(SCE_PFX_MOTION_MASK_CAN_SLEEP(states[pfxGetUnitId(islandUnit)].getMotionType()))) continue;
states[pfxGetUnitId(islandUnit)].sleep();
}
}
// Activate Island
else if(numSleep > 0 && numActive > 0) {
PfxIslandUnit *islandUnit = pfxGetFirstUnitInIsland(island,(PfxUInt32)i);
for(;islandUnit!=NULL;islandUnit=pfxGetNextUnitInIsland(islandUnit)) {
if(!(SCE_PFX_MOTION_MASK_CAN_SLEEP(states[pfxGetUnitId(islandUnit)].getMotionType()))) continue;
states[pfxGetUnitId(islandUnit)].wakeup();
}
}
}
}
}
void integrate()
{
PfxUpdateRigidStatesParam param;
param.states = states;
param.bodies = bodies;
param.numRigidBodies = numRigidBodies;
param.timeStep = timeStep;
pfxUpdateRigidStates(param);
}
void physics_simulate()
{
PfxPerfCounter pc;
for(int i=1;i<numRigidBodies;i++) {
pfxApplyExternalForce(states[i],bodies[i],bodies[i].getMass()*PfxVector3(0.0f,-9.8f,0.0f),PfxVector3(0.0f),timeStep);
}
perf_push_marker("broadphase");
pc.countBegin("broadphase");
broadphase();
pc.countEnd();
perf_pop_marker();
perf_push_marker("collision");
pc.countBegin("collision");
collision();
pc.countEnd();
perf_pop_marker();
perf_push_marker("solver");
pc.countBegin("solver");
constraintSolver();
pc.countEnd();
perf_pop_marker();
perf_push_marker("sleepOrWakeup");
pc.countBegin("sleepOrWakeup");
sleepOrWakeup();
pc.countEnd();
perf_pop_marker();
perf_push_marker("integrate");
pc.countBegin("integrate");
integrate();
pc.countEnd();
perf_pop_marker();
frame++;
if(frame%100 == 0) {
float broadphaseTime = pc.getCountTime(0);
float collisionTime = pc.getCountTime(2);
float solverTime = pc.getCountTime(4);
float integrateTime = pc.getCountTime(6);
SCE_PFX_PRINTF("frame %3d broadphase %.2f collision %.2f solver %.2f integrate %.2f | total %.2f\n",frame,
broadphaseTime,collisionTime,solverTime,integrateTime,
broadphaseTime+collisionTime+solverTime+integrateTime);
}
if(keyframeId>=0) updateKeyframe();
if(triggerId>=0) updateTrigger();
}
///////////////////////////////////////////////////////////////////////////////
// Create Scene
int createBrick(int id,const PfxVector3 &pos,const PfxQuat &rot,const PfxVector3 &boxSize,PfxFloat mass)
{
PfxBox box(boxSize);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setRestitution(0.0f);
bodies[id].setMass(mass);
bodies[id].setInertia(pfxCalcInertiaBox(boxSize,mass));
states[id].reset();
states[id].setPosition(pos);
states[id].setOrientation(rot);
states[id].setMotionType(kPfxMotionTypeActive);
states[id].setUseSleep(1); // sleep mode ON
states[id].setRigidBodyId(id);
return id;
}
void createWall(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
PfxFloat bodyMass = 0.5f;
PfxFloat diffX = boxSize[0] * 1.02f;
PfxFloat diffY = boxSize[1] * 1.02f;
PfxFloat diffZ = boxSize[2] * 1.02f;
PfxFloat offset = -stackSize * (diffZ * 2.0f) * 0.5f;
PfxVector3 pos(0.0f, diffY, 0.0f);
while(stackSize) {
for(int i=0;i<stackSize;i++) {
pos[0] = offset + (PfxFloat)i * (diffX * 2.0f);
createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,bodyMass);
}
offset += diffX;
pos[1] += (diffY * 2.0f);
stackSize--;
}
}
void createSceneKeyframe()
{
// rotation bar
int id = numRigidBodies++;
PfxVector3 barSize(5.0f,0.25f,0.5f);
PfxBox box(barSize);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
bodies[id].setMass(5.0f);
bodies[id].setInertia(pfxCalcInertiaBox(barSize,5.0f));
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,barSize[1],0.0f));
states[id].setMotionType(kPfxMotionTypeKeyframe);
states[id].setRigidBodyId(id);
keyframeId = id; // keep keyframe rigidbody
}
void updateKeyframe()
{
PfxQuat ori = states[keyframeId].getOrientation();
PfxQuat rot = PfxQuat::rotationY(0.02f);
states[keyframeId].moveOrientation(rot*ori,timeStep);
}
void createSceneOneWay()
{
PfxVector3 barSize(4.5f,0.25f,0.25f);
int oneWayId = createBrick(numRigidBodies++,PfxVector3(-3.0f,7.0f,-5.0f),PfxQuat::identity(),barSize,15.0f);
int activeId = createBrick(numRigidBodies++,PfxVector3( 3.0f,8.0f, 5.0f),PfxQuat::identity(),barSize,15.0f);
states[oneWayId].setMotionType(kPfxMotionTypeOneWay);
PfxBallJointInitParam jparam;
jparam.anchorPoint = PfxVector3(-3.0f,7.0f,0.0f);
int jointId1 = numJoints++;
pfxInitializeBallJoint(joints[jointId1],states[0],states[oneWayId],jparam);
pfxUpdateJointPairs(jointPairs[jointId1],jointId1,joints[jointId1],states[0],states[oneWayId]);
jparam.anchorPoint = PfxVector3( 3.0f,8.0f,0.0f);
int jointId2 = numJoints++;
pfxInitializeBallJoint(joints[jointId2],states[0],states[activeId],jparam);
pfxUpdateJointPairs(jointPairs[jointId2],jointId2,joints[jointId2],states[0],states[activeId]);
createWall(PfxVector3(-3.0f,0.0f,0.0f),5,PfxVector3(0.5f));
createWall(PfxVector3( 3.0f,0.0f,0.0f),5,PfxVector3(0.5f));
}
void createSceneTrigger()
{
PfxVector3 wallSize(5.0f,5.0f,0.5f);
triggerId = createBrick(numRigidBodies++,PfxVector3(0.0f,wallSize[1],0.0f),PfxQuat::identity(),wallSize,10.0f);
states[triggerId].setMotionType(kPfxMotionTypeTrigger);
PfxVector3 boxSize(0.5f);
int oneWayId = createBrick(numRigidBodies++,PfxVector3(-3.0f,7.0f,-5.0f),PfxQuat::identity(),boxSize,15.0f);
int activeId = createBrick(numRigidBodies++,PfxVector3( 3.0f,8.0f, 5.0f),PfxQuat::identity(),boxSize,15.0f);
states[oneWayId].setMotionType(kPfxMotionTypeOneWay);
PfxBallJointInitParam jparam;
jparam.anchorPoint = PfxVector3(-3.0f,7.0f,0.0f);
int jointId1 = numJoints++;
pfxInitializeBallJoint(joints[jointId1],states[0],states[oneWayId],jparam);
pfxUpdateJointPairs(jointPairs[jointId1],jointId1,joints[jointId1],states[0],states[oneWayId]);
jparam.anchorPoint = PfxVector3( 3.0f,8.0f,0.0f);
int jointId2 = numJoints++;
pfxInitializeBallJoint(joints[jointId2],states[0],states[activeId],jparam);
pfxUpdateJointPairs(jointPairs[jointId2],jointId2,joints[jointId2],states[0],states[activeId]);
}
void updateTrigger()
{
for(PfxUInt32 i=0;i<numPairs[pairSwap];i++) {
PfxBroadphasePair pair = pairsBuff[pairSwap][i];
PfxContactManifold &contact = contacts[pfxGetContactId(pair)];
if(pfxGetObjectIdA(pair) == triggerId) {
if(contact.getNumContacts() > 0) {
SCE_PFX_PRINTF("Find Contact %u\n",pfxGetObjectIdB(pair));
}
}
if(pfxGetObjectIdB(pair) == triggerId) {
if(contact.getNumContacts() > 0) {
SCE_PFX_PRINTF("Find Contact %u\n",pfxGetObjectIdA(pair));
}
}
}
}
void createSceneBoxGround()
{
int id = numRigidBodies++;
PfxBox box(150.0f,2.5f,150.0f);
PfxShape shape;
shape.reset();
shape.setBox(box);
collidables[id].reset();
collidables[id].addShape(shape);
collidables[id].finish();
bodies[id].reset();
states[id].reset();
states[id].setPosition(PfxVector3(0.0f,-2.5f,0.0f));
states[id].setMotionType(kPfxMotionTypeFixed);
states[id].setRigidBodyId(id);
}
void physics_create_scene(int sceneId)
{
const int numScenes = 3;
int sid = sceneId % numScenes;
numRigidBodies= 0;
pairSwap = 0;
numPairs[0] = 0;
numPairs[1] = 0;
numContacts = 0;
numContactIdPool = 0;
numJoints = 0;
island = NULL;
frame = 0;
keyframeId = -1;
triggerId = -1;
switch(sid) {
case 0:
createSceneBoxGround();
createSceneKeyframe();
createWall(PfxVector3(0.0f,1.0f,0.0f),5,PfxVector3(0.5f));
break;
case 1:
createSceneBoxGround();
createSceneOneWay();
break;
case 2:
createSceneBoxGround();
createSceneTrigger();
break;
}
SCE_PFX_PRINTF("----- Size of rigid body buffer ------\n");
SCE_PFX_PRINTF(" size * num = total\n");
SCE_PFX_PRINTF("PfxRigidState %5d * %5d = %5d bytes\n",sizeof(PfxRigidState),numRigidBodies,sizeof(PfxRigidState)*numRigidBodies);
SCE_PFX_PRINTF("PfxRigidBody %5d * %5d = %5d bytes\n",sizeof(PfxRigidBody),numRigidBodies,sizeof(PfxRigidBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxCollidable %5d * %5d = %5d bytes\n",sizeof(PfxCollidable),numRigidBodies,sizeof(PfxCollidable)*numRigidBodies);
SCE_PFX_PRINTF("PfxJoint %5d * %5d = %5d bytes\n",sizeof(PfxJoint),numJoints,sizeof(PfxJoint)*numJoints);
SCE_PFX_PRINTF("PfxSolverBody %5d * %5d = %5d bytes\n",sizeof(PfxSolverBody),numRigidBodies,sizeof(PfxSolverBody)*numRigidBodies);
SCE_PFX_PRINTF("PfxBroadphaseProxy %5d * %5d = %5d bytes\n",sizeof(PfxBroadphaseProxy),numRigidBodies,sizeof(PfxBroadphaseProxy)*numRigidBodies);
SCE_PFX_PRINTF("PfxContactManifold %5d * %5d = %5d bytes\n",sizeof(PfxContactManifold),NUM_CONTACTS,sizeof(PfxContactManifold)*NUM_CONTACTS);
SCE_PFX_PRINTF("PfxBroadphasePair %5d * %5d = %5d bytes\n",sizeof(PfxBroadphasePair),NUM_CONTACTS,sizeof(PfxBroadphasePair)*NUM_CONTACTS);
int totalBytes =
(sizeof(PfxRigidState) + sizeof(PfxRigidBody) + sizeof(PfxCollidable) + sizeof(PfxSolverBody) + sizeof(PfxBroadphaseProxy)) * numRigidBodies +
(sizeof(PfxContactManifold) + sizeof(PfxBroadphasePair)) * NUM_CONTACTS;
SCE_PFX_PRINTF("----------------------------------------------------------\n");
SCE_PFX_PRINTF("Total %5d bytes\n",totalBytes);
}
///////////////////////////////////////////////////////////////////////////////
// Initialize / Finalize Engine
bool physics_init()
{
return true;
}
void physics_release()
{
}
///////////////////////////////////////////////////////////////////////////////
// Pick
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2)
{
return PfxVector3(0.0f);
}
void physics_pick_update(const PfxVector3 &p)
{
}
void physics_pick_end()
{
}
///////////////////////////////////////////////////////////////////////////////
// Get Information
int physics_get_num_rigidbodies()
{
return numRigidBodies;
}
const PfxRigidState& physics_get_state(int id)
{
return states[id];
}
const PfxRigidBody& physics_get_body(int id)
{
return bodies[id];
}
const PfxCollidable& physics_get_collidable(int id)
{
return collidables[id];
}
int physics_get_num_contacts()
{
return numPairs[pairSwap];
}
const PfxContactManifold &physics_get_contact(int id)
{
return contacts[pfxGetConstraintId(pairsBuff[pairSwap][id])];
}
const PfxIsland* physics_get_islands()
{
return island;
}

View File

@@ -0,0 +1,53 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __PHYSICS_FUNC_H__
#define __PHYSICS_FUNC_H__
#define SCE_PFX_USE_PERFCOUNTER
#include "physics_effects.h"
using namespace sce::PhysicsEffects;
//E Simulation
//J シミュレーション
bool physics_init();
void physics_release();
void physics_create_scene(int sceneId);
void physics_simulate();
//E Picking
//J ピッキング
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2);
void physics_pick_update(const PfxVector3 &p);
void physics_pick_end();
//E Change parameters
//J パラメータの取得
int physics_get_num_rigidbodies();
const PfxRigidState& physics_get_state(int id);
const PfxRigidBody& physics_get_body(int id);
const PfxCollidable& physics_get_collidable(int id);
// Get contact information
int physics_get_num_contacts();
const PfxContactManifold &physics_get_contact(int id);
// Get simulation island
const PfxIsland* physics_get_islands();
#endif /* __PHYSICS_FUNC_H__ */

View File

@@ -0,0 +1,721 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="5_raycast.windows"
ProjectGUID="{96B87A78-C8E3-43C5-B0E4-9A30999B2712}"
RootNamespace="5_raycast.win32"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Win32 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
ShowProgress="0"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
ShowProgress="0"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
AdditionalDependencies="opengl32.lib glu32.lib"
ShowProgress="0"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
ShowProgress="0"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
>
<File
RelativePath=".\physics_func.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\physics_func.cpp"
>
</File>
</Filter>
<Filter
Name="Common"
>
<File
RelativePath="..\common\common.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\perf_func.h"
>
</File>
<File
RelativePath="..\common\perf_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\render_func.h"
>
</File>
<File
RelativePath="..\common\render_func.win32.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 2.4)
#this line has to appear before 'PROJECT' in order to be able to disable incremental linking
SET(MSVC_INCREMENTAL_DEFAULT ON)
PROJECT(App_5_Raycast)
IF (NOT CMAKE_BUILD_TYPE)
# SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_BUILD_TYPE "Release")
ENDIF (NOT CMAKE_BUILD_TYPE)
OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" ON)
OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
ENDIF(COMMAND cmake_policy)
SET(App_5_Raycast_SRCS
main.cpp
physics_func.cpp
../common/ctrl_func.win32.cpp
../common/perf_func.win32.cpp
../common/render_func.win32.cpp
)
SET(App_5_Raycast_HDRS
physics_func.h
landscape.h
barrel.h
../common/render_func.h
../common/common.h
../common/ctrl_func.h
../common/perf_func.h
)
INCLUDE_DIRECTORIES(
${PHYSICS_EFFECTS_SOURCE_DIR}/include
# ${VECTOR_MATH_INCLUDE}
)
#LINK_DIRECTORIES(
#
#)
#ADD_DEFINITIONS(-DUNICODE)
#ADD_DEFINITIONS(-D_UNICODE)
ADD_EXECUTABLE(App_5_Raycast WIN32
${App_5_Raycast_SRCS}
${App_5_Raycast_HDRS}
)
TARGET_LINK_LIBRARIES(App_5_Raycast
PfxBaseLevel
PfxLowLevel
PfxUtil
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(App_5_Raycast PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_5_Raycast PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_5_Raycast PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF()

View File

@@ -0,0 +1,202 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define BarrelVtxCount 57
#define BarrelIdxCount 180
static float BarrelVtx[] = {
0.0f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
-0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
0.0f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
-0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.957307f,-0.289072f,0.0f,
0.404509f,0.0f,-0.293893f, 0.809017f,0.0f,-0.587785f,
0.5f,0.0f,0.0f, 1.0f,0.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.774478f,-0.289072f,-0.562691f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
-0.154509f,0.0f,-0.475528f, -0.309017f,0.0f,-0.951057f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
-0.107853f,-0.5f,-0.331936f, -0.295824f,-0.289072f,-0.910453f,
-0.404509f,0.0f,-0.293893f, -0.809017f,0.0f,-0.587785f,
-0.282362f,-0.5f,-0.205148f, -0.774478f,-0.289072f,-0.562691f,
-0.5f,0.0f,0.0f, -1.0f,0.0f,0.0f,
-0.349018f,-0.5f,0.0f, -0.957307f,-0.289072f,0.0f,
-0.404508f,0.0f,0.293893f, -0.809017f,0.0f,0.587785f,
-0.282362f,-0.5f,0.205148f, -0.774478f,-0.289072f,0.562691f,
-0.154509f,0.0f,0.475528f, -0.309017f,0.0f,0.951056f,
-0.107853f,-0.5f,0.331936f, -0.295824f,-0.289072f,0.910453f,
0.154509f,0.0f,0.475528f, 0.309017f,0.0f,0.951056f,
0.107853f,-0.5f,0.331936f, 0.295824f,-0.289072f,0.910453f,
0.404509f,0.0f,0.293892f, 0.809017f,0.0f,0.587785f,
0.282362f,-0.5f,0.205148f, 0.774478f,-0.289072f,0.562691f,
0.282362f,0.5f,-0.205148f, 0.774478f,0.289072f,-0.562691f,
0.349018f,0.5f,0.0f, 0.957307f,0.289072f,0.0f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.107853f,0.5f,-0.331936f, -0.295824f,0.289072f,-0.910453f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.282362f,0.5f,-0.205148f, -0.774478f,0.289072f,-0.562691f,
-0.349018f,0.5f,0.0f, -0.957307f,0.289072f,0.0f,
-0.282362f,0.5f,0.205148f, -0.774478f,0.289072f,0.562691f,
-0.107853f,0.5f,0.331936f, -0.295824f,0.289072f,0.910453f,
0.107853f,0.5f,0.331936f, 0.295824f,0.289072f,0.910453f,
0.282362f,0.5f,0.205148f, 0.774478f,0.289072f,0.562691f,
};
static float BarrelTex[] = {
0.0f,0.5f,
0.0f,0.85f,
0.0f,0.75f,
0.0f,0.95f,
0.0f,0.05f,
0.0f,-0.05f,
0.0f,0.15f,
0.0f,0.25f,
0.0f,0.35f,
0.0f,0.45f,
0.0f,0.55f,
0.0f,0.65f,
1.0f,0.5f,
1.0f,0.75f,
1.0f,0.85f,
1.0f,0.95f,
1.0f,-0.05f,
1.0f,0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
0.0f,0.75f,
0.5f,0.85f,
0.5f,0.75f,
0.0f,0.85f,
0.5f,0.95f,
0.0f,0.95f,
0.0f,-0.05f,
0.5f,0.05f,
0.5f,-0.05f,
0.0f,0.05f,
0.5f,0.15f,
0.0f,0.15f,
0.5f,0.25f,
0.0f,0.25f,
0.5f,0.35f,
0.0f,0.35f,
0.5f,0.45f,
0.0f,0.45f,
0.5f,0.55f,
0.0f,0.55f,
0.5f,0.65f,
0.0f,0.65f,
1.0f,0.85f,
1.0f,0.75f,
1.0f,0.95f,
1.0f,0.05f,
1.0f,-0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
};
static unsigned short BarrelIdx[] = {
0,1,2,
0,3,1,
0,4,5,
0,6,4,
0,7,6,
0,8,7,
0,9,8,
0,10,9,
0,11,10,
0,2,11,
12,13,14,
12,14,15,
12,16,17,
12,17,18,
12,18,19,
12,19,20,
12,20,21,
12,21,22,
12,22,23,
12,23,13,
24,25,26,
24,27,25,
27,28,25,
27,29,28,
30,31,32,
30,33,31,
33,34,31,
33,35,34,
35,36,34,
35,37,36,
37,38,36,
37,39,38,
39,40,38,
39,41,40,
41,42,40,
41,43,42,
43,44,42,
43,45,44,
45,26,44,
45,24,26,
26,46,47,
26,25,46,
25,48,46,
25,28,48,
32,49,50,
32,31,49,
31,51,49,
31,34,51,
34,52,51,
34,36,52,
36,53,52,
36,38,53,
38,54,53,
38,40,54,
40,55,54,
40,42,55,
42,56,55,
42,44,56,
44,47,56,
44,26,47,
};

View File

@@ -0,0 +1,318 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define LargeMeshVtxCount 81
#define LargeMeshIdxCount 384
static float LargeMeshVtx[] = {
-25.0f,-2.19407f,18.5625f, 0.232976f,0.967754f,0.0957829f,
-25.0f,0.0644502f,24.75f, 0.188094f,0.871343f,-0.45319f,
-18.75f,-4.50287f,18.5625f, -0.0716098f,0.995449f,0.0628767f,
-18.75f,-0.39999f,24.75f, -0.0602794f,0.895848f,-0.440253f,
-12.5f,-1.2166f,18.5625f, -0.269469f,0.961403f,0.0555879f,
-12.5f,-0.942431f,24.75f, -0.0997841f,0.993258f,0.0589987f,
-6.25f,1.93598f,18.5625f, -0.283933f,0.956351f,-0.0691025f,
-6.25f,-0.445954f,24.75f, -0.180725f,0.942766f,0.280233f,
0.0f,2.76983f,18.5625f, 0.171645f,0.984908f,0.0222501f,
0.0f,2.76642f,24.75f, 0.0784993f,0.995428f,-0.0544117f,
6.25f,-2.53736f,18.5625f, 0.248298f,0.965028f,0.0840741f,
6.25f,-0.915645f,24.75f, 0.164311f,0.945856f,-0.279926f,
12.5f,-1.60054f,18.5625f, -0.180435f,0.983586f,0.00115547f,
12.5f,0.831925f,24.75f, -0.0692495f,0.964821f,-0.253623f,
18.75f,-0.800282f,18.5625f, 0.10755f,0.951538f,0.288112f,
18.75f,-1.47284f,24.75f, 0.232178f,0.972664f,0.00429361f,
25.0f,-2.78379f,18.5625f, 0.1833f,0.937477f,0.295867f,
25.0f,-0.967508f,24.75f, -0.0773477f,0.956641f,-0.280812f,
-25.0f,-0.352038f,12.375f, -0.192222f,0.972435f,0.131987f,
-18.75f,0.681228f,12.375f, -0.107779f,0.962569f,0.248686f,
-12.5f,2.72065f,12.375f, 0.0520846f,0.993034f,0.105692f,
-6.25f,-1.78776f,12.375f, -0.0133223f,0.99674f,-0.0795754f,
0.0f,1.57707f,12.375f, -0.129025f,0.969662f,-0.207627f,
6.25f,0.424356f,12.375f, 0.180995f,0.97074f,0.157815f,
12.5f,0.283234f,12.375f, -0.16285f,0.973539f,0.160316f,
18.75f,2.57015f,12.375f, -0.165454f,0.978339f,0.124408f,
25.0f,3.07363f,12.375f, -0.00454559f,0.988151f,0.153417f,
-25.0f,-0.893751f,6.1875f, -0.0836251f,0.990084f,-0.112876f,
-18.75f,0.930932f,6.1875f, 0.00269413f,0.971838f,-0.235633f,
-12.5f,-0.684529f,6.1875f, -0.010319f,0.927048f,-0.3748f,
-6.25f,-0.661383f,6.1875f, 0.012265f,0.999875f,-0.00994222f,
0.0f,0.385718f,6.1875f, -0.15435f,0.984937f,-0.0779465f,
6.25f,0.589796f,6.1875f, 0.0241717f,0.999582f,-0.0158589f,
12.5f,0.47454f,6.1875f, -0.017184f,0.997953f,-0.0616073f,
18.75f,1.59939f,6.1875f, -0.0902706f,0.957309f,-0.274609f,
25.0f,1.13434f,6.1875f, 0.0346006f,0.957441f,-0.286547f,
-25.0f,0.74548f,0.0f, 0.329903f,0.930812f,0.157334f,
-18.75f,-2.47437f,0.0f, 0.247844f,0.968142f,0.0357041f,
-12.5f,-4.16309f,1.81975e-007f, -0.0623898f,0.997626f,-0.0291436f,
-6.25f,-0.700022f,0.0f, -0.217067f,0.974987f,-0.0477624f,
0.0f,-0.0957388f,0.0f, -0.117693f,0.990712f,-0.068098f,
6.25f,0.614077f,0.0f, -0.0713214f,0.997305f,0.01722f,
12.5f,0.299109f,0.0f, 0.218606f,0.968641f,0.118094f,
18.75f,-1.71753f,0.0f, 0.0339493f,0.985612f,-0.165579f,
25.0f,-1.12638f,0.0f, -0.0547573f,0.989177f,-0.136126f,
-25.0f,-0.403319f,-6.1875f, -0.1263f,0.989211f,-0.074223f,
-18.75f,-0.0730335f,-6.1875f, 0.0173428f,0.965382f,0.260261f,
-12.5f,-0.450125f,-6.1875f, 0.0658811f,0.875f,0.479619f,
-6.25f,-0.180204f,-6.1875f, 0.0116584f,0.981445f,0.19139f,
0.0f,-0.632679f,-6.1875f, -0.0557983f,0.993041f,-0.103716f,
6.25f,0.308409f,-6.1875f, -0.191898f,0.96766f,-0.163737f,
12.5f,2.5011f,-6.1875f, 0.0758397f,0.996403f,-0.0378189f,
18.75f,-1.69303f,-6.1875f, 0.16761f,0.974057f,0.15205f,
25.0f,-0.141349f,-6.1875f, -0.204846f,0.978471f,0.0251341f,
-25.0f,-1.10316f,-12.375f, -0.0350644f,0.993748f,-0.106001f,
-18.75f,1.06711f,-12.375f, -0.309806f,0.919244f,-0.242922f,
-12.5f,3.61544f,-12.375f, -0.0506281f,0.998702f,-0.00561657f,
-6.25f,1.6504f,-12.375f, 0.322294f,0.937465f,0.131477f,
0.0f,-1.60595f,-12.375f, 0.086016f,0.995916f,0.0274459f,
6.25f,-0.849859f,-12.375f, -0.0332811f,0.997087f,0.0686255f,
12.5f,-0.942201f,-12.375f, -0.153559f,0.982185f,-0.108312f,
18.75f,0.494873f,-12.375f, 0.0753195f,0.981472f,0.176181f,
25.0f,-0.333828f,-12.375f, 0.035057f,0.987194f,0.155624f,
-25.0f,2.1862f,-18.5625f, 0.612899f,0.782306f,0.111138f,
-18.75f,-3.38259f,-18.5625f, 0.0194078f,0.992789f,-0.118297f,
-12.5f,-0.880916f,-18.5625f, -0.282251f,0.949875f,-0.13443f,
-6.25f,0.818158f,-18.5625f, 0.1476f,0.981788f,-0.119612f,
0.0f,-1.48019f,-18.5625f, -0.044551f,0.996013f,-0.0772824f,
6.25f,1.47123f,-18.5625f, -0.117036f,0.97986f,0.161792f,
12.5f,0.164076f,-18.5625f, -0.0340355f,0.978993f,0.201034f,
18.75f,2.14568f,-18.5625f, -0.0439269f,0.994859f,0.0912435f,
25.0f,0.626506f,-18.5625f, 0.208015f,0.968592f,0.136229f,
-25.0f,0.296889f,-24.75f, 0.46973f,0.844327f,-0.257809f,
-18.75f,-3.18022f,-24.75f, -0.0226758f,0.998794f,-0.0435401f,
-12.5f,1.8927f,-24.75f, -0.202772f,0.919836f,0.335836f,
-6.25f,1.46387f,-24.75f, 0.224904f,0.955746f,0.189652f,
0.0f,-2.52726f,-24.75f, -0.0435882f,0.993572f,-0.10447f,
6.25f,1.30397f,-24.75f, -0.28646f,0.956525f,-0.0547707f,
12.5f,1.85812f,-24.75f, 0.0521949f,0.979796f,0.193067f,
18.75f,1.56331f,-24.75f, -0.0270784f,0.999629f,-0.00293115f,
25.0f,1.05366f,-24.75f, 0.161f,0.986887f,-0.0115473f,
};
static float LargeMeshTex[] = {
0.125f,0.0f,
0.0f,0.0f,
0.125f,0.125f,
0.0f,0.125f,
0.125f,0.25f,
0.0f,0.25f,
0.125f,0.375f,
0.0f,0.375f,
0.125f,0.5f,
0.0f,0.5f,
0.125f,0.625f,
0.0f,0.625f,
0.125f,0.75f,
0.0f,0.75f,
0.125f,0.875f,
0.0f,0.875f,
0.125f,1.0f,
0.0f,1.0f,
0.25f,0.0f,
0.25f,0.125f,
0.25f,0.25f,
0.25f,0.375f,
0.25f,0.5f,
0.25f,0.625f,
0.25f,0.75f,
0.25f,0.875f,
0.25f,1.0f,
0.375f,0.0f,
0.375f,0.125f,
0.375f,0.25f,
0.375f,0.375f,
0.375f,0.5f,
0.375f,0.625f,
0.375f,0.75f,
0.375f,0.875f,
0.375f,1.0f,
0.5f,0.0f,
0.5f,0.125f,
0.5f,0.25f,
0.5f,0.375f,
0.5f,0.5f,
0.5f,0.625f,
0.5f,0.75f,
0.5f,0.875f,
0.5f,1.0f,
0.625f,0.0f,
0.625f,0.125f,
0.625f,0.25f,
0.625f,0.375f,
0.625f,0.5f,
0.625f,0.625f,
0.625f,0.75f,
0.625f,0.875f,
0.625f,1.0f,
0.75f,0.0f,
0.75f,0.125f,
0.75f,0.25f,
0.75f,0.375f,
0.75f,0.5f,
0.75f,0.625f,
0.75f,0.75f,
0.75f,0.875f,
0.75f,1.0f,
0.875f,0.0f,
0.875f,0.125f,
0.875f,0.25f,
0.875f,0.375f,
0.875f,0.5f,
0.875f,0.625f,
0.875f,0.75f,
0.875f,0.875f,
0.875f,1.0f,
1.0f,0.0f,
1.0f,0.125f,
1.0f,0.25f,
1.0f,0.375f,
1.0f,0.5f,
1.0f,0.625f,
1.0f,0.75f,
1.0f,0.875f,
1.0f,1.0f,
};
static unsigned short LargeMeshIdx[] = {
0,1,2,
3,2,1,
2,3,4,
5,4,3,
4,5,6,
7,6,5,
6,7,8,
9,8,7,
8,9,10,
11,10,9,
10,11,12,
13,12,11,
12,13,14,
15,14,13,
14,15,16,
17,16,15,
18,0,19,
2,19,0,
19,2,20,
4,20,2,
20,4,21,
6,21,4,
21,6,22,
8,22,6,
22,8,23,
10,23,8,
23,10,24,
12,24,10,
24,12,25,
14,25,12,
25,14,26,
16,26,14,
27,18,28,
19,28,18,
28,19,29,
20,29,19,
29,20,30,
21,30,20,
30,21,31,
22,31,21,
31,22,32,
23,32,22,
32,23,33,
24,33,23,
33,24,34,
25,34,24,
34,25,35,
26,35,25,
36,27,37,
28,37,27,
37,28,38,
29,38,28,
38,29,39,
30,39,29,
39,30,40,
31,40,30,
40,31,41,
32,41,31,
41,32,42,
33,42,32,
42,33,43,
34,43,33,
43,34,44,
35,44,34,
45,36,46,
37,46,36,
46,37,47,
38,47,37,
47,38,48,
39,48,38,
48,39,49,
40,49,39,
49,40,50,
41,50,40,
50,41,51,
42,51,41,
51,42,52,
43,52,42,
52,43,53,
44,53,43,
54,45,55,
46,55,45,
55,46,56,
47,56,46,
56,47,57,
48,57,47,
57,48,58,
49,58,48,
58,49,59,
50,59,49,
59,50,60,
51,60,50,
60,51,61,
52,61,51,
61,52,62,
53,62,52,
63,54,64,
55,64,54,
64,55,65,
56,65,55,
65,56,66,
57,66,56,
66,57,67,
58,67,57,
67,58,68,
59,68,58,
68,59,69,
60,69,59,
69,60,70,
61,70,60,
70,61,71,
62,71,61,
72,63,73,
64,73,63,
73,64,74,
65,74,64,
74,65,75,
66,75,65,
75,66,76,
67,76,66,
76,67,77,
68,77,67,
77,68,78,
69,78,68,
78,69,79,
70,79,69,
79,70,80,
71,80,70,
};

View File

@@ -0,0 +1,544 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "../common/common.h"
#include "../common/ctrl_func.h"
#include "../common/render_func.h"
#include "../common/perf_func.h"
#include "physics_func.h"
#include "barrel.h"
#include "landscape.h"
#ifdef _WIN32
#include <gl/gl.h>
#include <gl/glu.h>
#endif
// ARA begin insert new code
#ifdef __ANDROID__
#include <EGL/egl.h>
#include <GLES/gl.h>
#endif
// ARA end
#define SAMPLE_NAME "api_physics_effects/5_raycast"
//#define ENABLE_DEBUG_DRAW
#ifdef ENABLE_DEBUG_DRAW
#define ENABLE_DEBUG_DRAW_CONTACT
#define ENABLE_DEBUG_DRAW_AABB
#define ENABLE_DEBUG_DRAW_ISLAND
#endif
static bool s_isRunning = true;
int sceneId = 0;
bool simulating = false;
int landscapeMeshId;
int convexMeshId;
void render(void)
{
render_begin();
const PfxVector3 colorWhite(1.0f);
const PfxVector3 colorGray(0.7f);
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxVector3 color = state.isAsleep()?colorGray:colorWhite;
PfxTransform3 rbT(state.getOrientation(), state.getPosition());
PfxShapeIterator itrShape(coll);
for(PfxUInt32 j=0;j<coll.getNumShapes();j++,++itrShape) {
const PfxShape &shape = *itrShape;
PfxTransform3 offsetT = shape.getOffsetTransform();
PfxTransform3 worldT = rbT * offsetT;
switch(shape.getType()) {
case kPfxShapeSphere:
render_sphere(
worldT,
color,
PfxFloatInVec(shape.getSphere().m_radius));
break;
case kPfxShapeBox:
render_box(
worldT,
color,
shape.getBox().m_half);
break;
case kPfxShapeCapsule:
render_capsule(
worldT,
color,
PfxFloatInVec(shape.getCapsule().m_radius),
PfxFloatInVec(shape.getCapsule().m_halfLen));
break;
case kPfxShapeCylinder:
render_cylinder(
worldT,
color,
PfxFloatInVec(shape.getCylinder().m_radius),
PfxFloatInVec(shape.getCylinder().m_halfLen));
break;
case kPfxShapeConvexMesh:
render_mesh(
worldT,
color,
convexMeshId);
break;
case kPfxShapeLargeTriMesh:
render_mesh(
worldT,
color,
landscapeMeshId);
break;
default:
break;
}
}
}
render_debug_begin();
#ifdef ENABLE_DEBUG_DRAW_CONTACT
for(int i=0;i<physics_get_num_contacts();i++) {
const PfxContactManifold &contact = physics_get_contact(i);
const PfxRigidState &stateA = physics_get_state(contact.getRigidBodyIdA());
const PfxRigidState &stateB = physics_get_state(contact.getRigidBodyIdB());
for(int j=0;j<contact.getNumContacts();j++) {
const PfxContactPoint &cp = contact.getContactPoint(j);
PfxVector3 pA = stateA.getPosition()+rotate(stateA.getOrientation(),pfxReadVector3(cp.m_localPointA));
const float w = 0.05f;
render_debug_line(pA+PfxVector3(-w,0.0f,0.0f),pA+PfxVector3(w,0.0f,0.0f),PfxVector3(0,0,1));
render_debug_line(pA+PfxVector3(0.0f,-w,0.0f),pA+PfxVector3(0.0f,w,0.0f),PfxVector3(0,0,1));
render_debug_line(pA+PfxVector3(0.0f,0.0f,-w),pA+PfxVector3(0.0f,0.0f,w),PfxVector3(0,0,1));
}
}
#endif
#ifdef ENABLE_DEBUG_DRAW_AABB
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxVector3 center = state.getPosition() + coll.getCenter();
PfxVector3 half = absPerElem(PfxMatrix3(state.getOrientation())) * coll.getHalf();
render_debug_box(center,half,PfxVector3(1,0,0));
}
#endif
#ifdef ENABLE_DEBUG_DRAW_ISLAND
const PfxIsland *island = physics_get_islands();
if(island) {
for(PfxUInt32 i=0;i<pfxGetNumIslands(island);i++) {
PfxIslandUnit *islandUnit = pfxGetFirstUnitInIsland(island,i);
PfxVector3 aabbMin(SCE_PFX_FLT_MAX);
PfxVector3 aabbMax(-SCE_PFX_FLT_MAX);
for(;islandUnit!=NULL;islandUnit=pfxGetNextUnitInIsland(islandUnit)) {
const PfxRigidState &state = physics_get_state(pfxGetUnitId(islandUnit));
const PfxCollidable &coll = physics_get_collidable(pfxGetUnitId(islandUnit));
PfxVector3 center = state.getPosition() + coll.getCenter();
PfxVector3 half = absPerElem(PfxMatrix3(state.getOrientation())) * coll.getHalf();
aabbMin = minPerElem(aabbMin,center-half);
aabbMax = maxPerElem(aabbMax,center+half);
}
render_debug_box((aabbMax+aabbMin)*0.5f,(aabbMax-aabbMin)*0.5f,PfxVector3(0,1,0));
}
}
#endif
for(int i=0;i<physics_get_num_rays();i++) {
const PfxRayInput& rayInput = physics_get_rayinput(i);
const PfxRayOutput& rayOutput = physics_get_rayoutput(i);
if(rayOutput.m_contactFlag) {
render_debug_line(
rayInput.m_startPosition,
rayOutput.m_contactPoint,
PfxVector3(1.0f,0.0f,1.0f));
render_debug_line(
rayOutput.m_contactPoint,
rayOutput.m_contactPoint+rayOutput.m_contactNormal,
PfxVector3(1.0f,0.0f,1.0f));
}
else {
render_debug_line(rayInput.m_startPosition,
rayInput.m_startPosition+rayInput.m_direction,
PfxVector3(0.5f,0.0f,0.5f));
}
}
extern bool doAreaRaycast;
extern PfxVector3 areaCenter;
extern PfxVector3 areaExtent;
if(doAreaRaycast) {
render_debug_box(areaCenter,areaExtent,PfxVector3(0,0,1));
}
render_debug_end();
render_end();
}
int init(void)
{
perf_init();
ctrl_init();
render_init();
physics_init();
landscapeMeshId = render_init_mesh(
LargeMeshVtx,sizeof(float)*6,
LargeMeshVtx+3,sizeof(float)*6,
LargeMeshIdx,sizeof(unsigned short)*3,
LargeMeshVtxCount,LargeMeshIdxCount/3);
convexMeshId = render_init_mesh(
BarrelVtx,sizeof(float)*6,
BarrelVtx+3,sizeof(float)*6,
BarrelIdx,sizeof(unsigned short)*3,
BarrelVtxCount,BarrelIdxCount/3);
return 0;
}
static int shutdown(void)
{
ctrl_release();
render_release();
physics_release();
perf_release();
return 0;
}
void update(void)
{
float angX,angY,r;
render_get_view_angle(angX,angY,r);
ctrl_update();
if(ctrl_button_pressed(BTN_UP)) {
angX -= 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_DOWN)) {
angX += 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_LEFT)) {
angY -= 0.05f;
}
if(ctrl_button_pressed(BTN_RIGHT)) {
angY += 0.05f;
}
if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
r *= 1.1f;
if(r > 500.0f) r = 500.0f;
}
if(ctrl_button_pressed(BTN_ZOOM_IN)) {
r *= 0.9f;
if(r < 1.0f) r = 1.0f;
}
if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
physics_create_scene(sceneId);
}
if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
physics_create_scene(++sceneId);
}
if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
simulating = !simulating;
}
if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
simulating = true;
}
else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
simulating = false;
}
render_set_view_angle(angX,angY,r);
}
#ifndef _WIN32
// ARA begin insert new code
#ifdef __ANDROID__
///////////////////////////////////////////////////////////////////////////////
// sceneChange
//
/// This function is used to change the physics scene on Android devices
///////////////////////////////////////////////////////////////////////////////
void sceneChange()
{
physics_create_scene(sceneId++);
}
#else // __ANDROID__
// ARA end
///////////////////////////////////////////////////////////////////////////////
// Main
int main(void)
{
init();
physics_create_scene(sceneId);
printf("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
while (s_isRunning) {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
shutdown();
printf("## %s: FINISHED ##\n", SAMPLE_NAME);
return 0;
}
// ARA begin insert new code
#endif // __ANDROID__
// ARA end
#else // _WIN32
///////////////////////////////////////////////////////////////////////////////
// WinMain
extern HDC hDC;
extern HGLRC hRC;
HWND hWnd;
HINSTANCE hInstance;
void releaseWindow()
{
if(hRC) {
wglMakeCurrent(0,0);
wglDeleteContext(hRC);
}
if(hDC) ReleaseDC(hWnd,hDC);
if(hWnd) DestroyWindow(hWnd);
UnregisterClass(SAMPLE_NAME,hInstance);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg) {
case WM_SYSCOMMAND:
{
switch (wParam) {
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_SIZE:
render_resize(LOWORD(lParam),HIWORD(lParam));
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
bool createWindow(char* title, int width, int height)
{
WNDCLASS wc;
RECT rect;
rect.left=0;
rect.right=width;
rect.top=0;
rect.bottom=height;
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = SAMPLE_NAME;
if(!RegisterClass(&wc)) {
return false;
}
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
if(!(hWnd=CreateWindowEx(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,SAMPLE_NAME,title,
WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
0,0,rect.right-rect.left,rect.bottom-rect.top,
NULL,NULL,hInstance,NULL))) {
releaseWindow();
return false;
}
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0,
0, 0,
0, 0,
0, 0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if(!(hDC=GetDC(hWnd)))
{
releaseWindow();
OutputDebugString("");
return FALSE;
}
int pixelformat;
if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 ){
OutputDebugString("ChoosePixelFormat Failed....");
return FALSE;
}
if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE){
OutputDebugString("SetPixelFormat Failed....");
return FALSE;
}
if (!(hRC=wglCreateContext(hDC))){
OutputDebugString("Creating HGLRC Failed....");
return FALSE;
}
// Set Vsync
//BOOL (WINAPI *wglSwapIntervalEXT)(int) = NULL;
//if(strstr((char*)glGetString( GL_EXTENSIONS ),"WGL_EXT_swap_control")== 0) {
//}
//else {
//wglSwapIntervalEXT = (BOOL (WINAPI*)(int))wglGetProcAddress("wglSwapIntervalEXT");
//if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
//}
wglMakeCurrent(hDC,hRC);
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
render_resize(width, height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return 0;
}
init();
physics_create_scene(sceneId);
SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
MSG msg;
while(s_isRunning) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if(msg.message==WM_QUIT) {
s_isRunning = false;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
}
shutdown();
SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);
releaseWindow();
return (msg.wParam);
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,58 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __PHYSICS_FUNC_H__
#define __PHYSICS_FUNC_H__
#define SCE_PFX_USE_PERFCOUNTER
#include "physics_effects.h"
using namespace sce::PhysicsEffects;
//E Simulation
//J シミュレーション
bool physics_init();
void physics_release();
void physics_create_scene(int sceneId);
void physics_simulate();
//E Picking
//J ピッキング
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2);
void physics_pick_update(const PfxVector3 &p);
void physics_pick_end();
//E Change parameters
//J パラメータの取得
int physics_get_num_rigidbodies();
const PfxRigidState& physics_get_state(int id);
const PfxRigidBody& physics_get_body(int id);
const PfxCollidable& physics_get_collidable(int id);
// Get ray information
int physics_get_num_rays();
const PfxRayInput& physics_get_rayinput(int id);
const PfxRayOutput& physics_get_rayoutput(int id);
// Get contact information
int physics_get_num_contacts();
const PfxContactManifold &physics_get_contact(int id);
// Get simulation island
const PfxIsland* physics_get_islands();
#endif /* __PHYSICS_FUNC_H__ */

View File

@@ -0,0 +1,713 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="6_joint.windows"
ProjectGUID="{A296A166-9E6A-44DE-BF58-30131687A117}"
RootNamespace="6_joint.win32"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Win32 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win32 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Debug|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffectsD.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Win64 Release|x64"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include;"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib libScePhysicsEffects.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
>
<File
RelativePath=".\physics_func.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\physics_func.cpp"
>
</File>
</Filter>
<Filter
Name="Common"
>
<File
RelativePath="..\common\common.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.h"
>
</File>
<File
RelativePath="..\common\ctrl_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\perf_func.h"
>
</File>
<File
RelativePath="..\common\perf_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\render_func.h"
>
</File>
<File
RelativePath="..\common\render_func.win32.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 2.4)
#this line has to appear before 'PROJECT' in order to be able to disable incremental linking
SET(MSVC_INCREMENTAL_DEFAULT ON)
PROJECT(App_6_Joint)
IF (NOT CMAKE_BUILD_TYPE)
# SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_BUILD_TYPE "Release")
ENDIF (NOT CMAKE_BUILD_TYPE)
OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" ON)
OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
ENDIF(COMMAND cmake_policy)
SET(App_6_Joint_SRCS
main.cpp
physics_func.cpp
../common/ctrl_func.win32.cpp
../common/perf_func.win32.cpp
../common/render_func.win32.cpp
)
SET(App_6_Joint_HDRS
physics_func.h
landscape.h
barrel.h
../common/render_func.h
../common/common.h
../common/ctrl_func.h
../common/perf_func.h
)
INCLUDE_DIRECTORIES(
${PHYSICS_EFFECTS_SOURCE_DIR}/include
# ${VECTOR_MATH_INCLUDE}
)
#LINK_DIRECTORIES(
#
#)
#ADD_DEFINITIONS(-DUNICODE)
#ADD_DEFINITIONS(-D_UNICODE)
ADD_EXECUTABLE(App_6_Joint WIN32
${App_6_Joint_SRCS}
${App_6_Joint_HDRS}
)
TARGET_LINK_LIBRARIES(App_6_Joint
PfxBaseLevel
PfxLowLevel
PfxUtil
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(App_6_Joint PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_6_Joint PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_6_Joint PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF()

View File

@@ -0,0 +1,202 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define BarrelVtxCount 57
#define BarrelIdxCount 180
static float BarrelVtx[] = {
0.0f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
-0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
0.0f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
-0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.957307f,-0.289072f,0.0f,
0.404509f,0.0f,-0.293893f, 0.809017f,0.0f,-0.587785f,
0.5f,0.0f,0.0f, 1.0f,0.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.774478f,-0.289072f,-0.562691f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
-0.154509f,0.0f,-0.475528f, -0.309017f,0.0f,-0.951057f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
-0.107853f,-0.5f,-0.331936f, -0.295824f,-0.289072f,-0.910453f,
-0.404509f,0.0f,-0.293893f, -0.809017f,0.0f,-0.587785f,
-0.282362f,-0.5f,-0.205148f, -0.774478f,-0.289072f,-0.562691f,
-0.5f,0.0f,0.0f, -1.0f,0.0f,0.0f,
-0.349018f,-0.5f,0.0f, -0.957307f,-0.289072f,0.0f,
-0.404508f,0.0f,0.293893f, -0.809017f,0.0f,0.587785f,
-0.282362f,-0.5f,0.205148f, -0.774478f,-0.289072f,0.562691f,
-0.154509f,0.0f,0.475528f, -0.309017f,0.0f,0.951056f,
-0.107853f,-0.5f,0.331936f, -0.295824f,-0.289072f,0.910453f,
0.154509f,0.0f,0.475528f, 0.309017f,0.0f,0.951056f,
0.107853f,-0.5f,0.331936f, 0.295824f,-0.289072f,0.910453f,
0.404509f,0.0f,0.293892f, 0.809017f,0.0f,0.587785f,
0.282362f,-0.5f,0.205148f, 0.774478f,-0.289072f,0.562691f,
0.282362f,0.5f,-0.205148f, 0.774478f,0.289072f,-0.562691f,
0.349018f,0.5f,0.0f, 0.957307f,0.289072f,0.0f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.107853f,0.5f,-0.331936f, -0.295824f,0.289072f,-0.910453f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.282362f,0.5f,-0.205148f, -0.774478f,0.289072f,-0.562691f,
-0.349018f,0.5f,0.0f, -0.957307f,0.289072f,0.0f,
-0.282362f,0.5f,0.205148f, -0.774478f,0.289072f,0.562691f,
-0.107853f,0.5f,0.331936f, -0.295824f,0.289072f,0.910453f,
0.107853f,0.5f,0.331936f, 0.295824f,0.289072f,0.910453f,
0.282362f,0.5f,0.205148f, 0.774478f,0.289072f,0.562691f,
};
static float BarrelTex[] = {
0.0f,0.5f,
0.0f,0.85f,
0.0f,0.75f,
0.0f,0.95f,
0.0f,0.05f,
0.0f,-0.05f,
0.0f,0.15f,
0.0f,0.25f,
0.0f,0.35f,
0.0f,0.45f,
0.0f,0.55f,
0.0f,0.65f,
1.0f,0.5f,
1.0f,0.75f,
1.0f,0.85f,
1.0f,0.95f,
1.0f,-0.05f,
1.0f,0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
0.0f,0.75f,
0.5f,0.85f,
0.5f,0.75f,
0.0f,0.85f,
0.5f,0.95f,
0.0f,0.95f,
0.0f,-0.05f,
0.5f,0.05f,
0.5f,-0.05f,
0.0f,0.05f,
0.5f,0.15f,
0.0f,0.15f,
0.5f,0.25f,
0.0f,0.25f,
0.5f,0.35f,
0.0f,0.35f,
0.5f,0.45f,
0.0f,0.45f,
0.5f,0.55f,
0.0f,0.55f,
0.5f,0.65f,
0.0f,0.65f,
1.0f,0.85f,
1.0f,0.75f,
1.0f,0.95f,
1.0f,0.05f,
1.0f,-0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
};
static unsigned short BarrelIdx[] = {
0,1,2,
0,3,1,
0,4,5,
0,6,4,
0,7,6,
0,8,7,
0,9,8,
0,10,9,
0,11,10,
0,2,11,
12,13,14,
12,14,15,
12,16,17,
12,17,18,
12,18,19,
12,19,20,
12,20,21,
12,21,22,
12,22,23,
12,23,13,
24,25,26,
24,27,25,
27,28,25,
27,29,28,
30,31,32,
30,33,31,
33,34,31,
33,35,34,
35,36,34,
35,37,36,
37,38,36,
37,39,38,
39,40,38,
39,41,40,
41,42,40,
41,43,42,
43,44,42,
43,45,44,
45,26,44,
45,24,26,
26,46,47,
26,25,46,
25,48,46,
25,28,48,
32,49,50,
32,31,49,
31,51,49,
31,34,51,
34,52,51,
34,36,52,
36,53,52,
36,38,53,
38,54,53,
38,40,54,
40,55,54,
40,42,55,
42,56,55,
42,44,56,
44,47,56,
44,26,47,
};

View File

@@ -0,0 +1,318 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define LargeMeshVtxCount 81
#define LargeMeshIdxCount 384
static float LargeMeshVtx[] = {
-25.0f,-2.19407f,18.5625f, 0.232976f,0.967754f,0.0957829f,
-25.0f,0.0644502f,24.75f, 0.188094f,0.871343f,-0.45319f,
-18.75f,-4.50287f,18.5625f, -0.0716098f,0.995449f,0.0628767f,
-18.75f,-0.39999f,24.75f, -0.0602794f,0.895848f,-0.440253f,
-12.5f,-1.2166f,18.5625f, -0.269469f,0.961403f,0.0555879f,
-12.5f,-0.942431f,24.75f, -0.0997841f,0.993258f,0.0589987f,
-6.25f,1.93598f,18.5625f, -0.283933f,0.956351f,-0.0691025f,
-6.25f,-0.445954f,24.75f, -0.180725f,0.942766f,0.280233f,
0.0f,2.76983f,18.5625f, 0.171645f,0.984908f,0.0222501f,
0.0f,2.76642f,24.75f, 0.0784993f,0.995428f,-0.0544117f,
6.25f,-2.53736f,18.5625f, 0.248298f,0.965028f,0.0840741f,
6.25f,-0.915645f,24.75f, 0.164311f,0.945856f,-0.279926f,
12.5f,-1.60054f,18.5625f, -0.180435f,0.983586f,0.00115547f,
12.5f,0.831925f,24.75f, -0.0692495f,0.964821f,-0.253623f,
18.75f,-0.800282f,18.5625f, 0.10755f,0.951538f,0.288112f,
18.75f,-1.47284f,24.75f, 0.232178f,0.972664f,0.00429361f,
25.0f,-2.78379f,18.5625f, 0.1833f,0.937477f,0.295867f,
25.0f,-0.967508f,24.75f, -0.0773477f,0.956641f,-0.280812f,
-25.0f,-0.352038f,12.375f, -0.192222f,0.972435f,0.131987f,
-18.75f,0.681228f,12.375f, -0.107779f,0.962569f,0.248686f,
-12.5f,2.72065f,12.375f, 0.0520846f,0.993034f,0.105692f,
-6.25f,-1.78776f,12.375f, -0.0133223f,0.99674f,-0.0795754f,
0.0f,1.57707f,12.375f, -0.129025f,0.969662f,-0.207627f,
6.25f,0.424356f,12.375f, 0.180995f,0.97074f,0.157815f,
12.5f,0.283234f,12.375f, -0.16285f,0.973539f,0.160316f,
18.75f,2.57015f,12.375f, -0.165454f,0.978339f,0.124408f,
25.0f,3.07363f,12.375f, -0.00454559f,0.988151f,0.153417f,
-25.0f,-0.893751f,6.1875f, -0.0836251f,0.990084f,-0.112876f,
-18.75f,0.930932f,6.1875f, 0.00269413f,0.971838f,-0.235633f,
-12.5f,-0.684529f,6.1875f, -0.010319f,0.927048f,-0.3748f,
-6.25f,-0.661383f,6.1875f, 0.012265f,0.999875f,-0.00994222f,
0.0f,0.385718f,6.1875f, -0.15435f,0.984937f,-0.0779465f,
6.25f,0.589796f,6.1875f, 0.0241717f,0.999582f,-0.0158589f,
12.5f,0.47454f,6.1875f, -0.017184f,0.997953f,-0.0616073f,
18.75f,1.59939f,6.1875f, -0.0902706f,0.957309f,-0.274609f,
25.0f,1.13434f,6.1875f, 0.0346006f,0.957441f,-0.286547f,
-25.0f,0.74548f,0.0f, 0.329903f,0.930812f,0.157334f,
-18.75f,-2.47437f,0.0f, 0.247844f,0.968142f,0.0357041f,
-12.5f,-4.16309f,1.81975e-007f, -0.0623898f,0.997626f,-0.0291436f,
-6.25f,-0.700022f,0.0f, -0.217067f,0.974987f,-0.0477624f,
0.0f,-0.0957388f,0.0f, -0.117693f,0.990712f,-0.068098f,
6.25f,0.614077f,0.0f, -0.0713214f,0.997305f,0.01722f,
12.5f,0.299109f,0.0f, 0.218606f,0.968641f,0.118094f,
18.75f,-1.71753f,0.0f, 0.0339493f,0.985612f,-0.165579f,
25.0f,-1.12638f,0.0f, -0.0547573f,0.989177f,-0.136126f,
-25.0f,-0.403319f,-6.1875f, -0.1263f,0.989211f,-0.074223f,
-18.75f,-0.0730335f,-6.1875f, 0.0173428f,0.965382f,0.260261f,
-12.5f,-0.450125f,-6.1875f, 0.0658811f,0.875f,0.479619f,
-6.25f,-0.180204f,-6.1875f, 0.0116584f,0.981445f,0.19139f,
0.0f,-0.632679f,-6.1875f, -0.0557983f,0.993041f,-0.103716f,
6.25f,0.308409f,-6.1875f, -0.191898f,0.96766f,-0.163737f,
12.5f,2.5011f,-6.1875f, 0.0758397f,0.996403f,-0.0378189f,
18.75f,-1.69303f,-6.1875f, 0.16761f,0.974057f,0.15205f,
25.0f,-0.141349f,-6.1875f, -0.204846f,0.978471f,0.0251341f,
-25.0f,-1.10316f,-12.375f, -0.0350644f,0.993748f,-0.106001f,
-18.75f,1.06711f,-12.375f, -0.309806f,0.919244f,-0.242922f,
-12.5f,3.61544f,-12.375f, -0.0506281f,0.998702f,-0.00561657f,
-6.25f,1.6504f,-12.375f, 0.322294f,0.937465f,0.131477f,
0.0f,-1.60595f,-12.375f, 0.086016f,0.995916f,0.0274459f,
6.25f,-0.849859f,-12.375f, -0.0332811f,0.997087f,0.0686255f,
12.5f,-0.942201f,-12.375f, -0.153559f,0.982185f,-0.108312f,
18.75f,0.494873f,-12.375f, 0.0753195f,0.981472f,0.176181f,
25.0f,-0.333828f,-12.375f, 0.035057f,0.987194f,0.155624f,
-25.0f,2.1862f,-18.5625f, 0.612899f,0.782306f,0.111138f,
-18.75f,-3.38259f,-18.5625f, 0.0194078f,0.992789f,-0.118297f,
-12.5f,-0.880916f,-18.5625f, -0.282251f,0.949875f,-0.13443f,
-6.25f,0.818158f,-18.5625f, 0.1476f,0.981788f,-0.119612f,
0.0f,-1.48019f,-18.5625f, -0.044551f,0.996013f,-0.0772824f,
6.25f,1.47123f,-18.5625f, -0.117036f,0.97986f,0.161792f,
12.5f,0.164076f,-18.5625f, -0.0340355f,0.978993f,0.201034f,
18.75f,2.14568f,-18.5625f, -0.0439269f,0.994859f,0.0912435f,
25.0f,0.626506f,-18.5625f, 0.208015f,0.968592f,0.136229f,
-25.0f,0.296889f,-24.75f, 0.46973f,0.844327f,-0.257809f,
-18.75f,-3.18022f,-24.75f, -0.0226758f,0.998794f,-0.0435401f,
-12.5f,1.8927f,-24.75f, -0.202772f,0.919836f,0.335836f,
-6.25f,1.46387f,-24.75f, 0.224904f,0.955746f,0.189652f,
0.0f,-2.52726f,-24.75f, -0.0435882f,0.993572f,-0.10447f,
6.25f,1.30397f,-24.75f, -0.28646f,0.956525f,-0.0547707f,
12.5f,1.85812f,-24.75f, 0.0521949f,0.979796f,0.193067f,
18.75f,1.56331f,-24.75f, -0.0270784f,0.999629f,-0.00293115f,
25.0f,1.05366f,-24.75f, 0.161f,0.986887f,-0.0115473f,
};
static float LargeMeshTex[] = {
0.125f,0.0f,
0.0f,0.0f,
0.125f,0.125f,
0.0f,0.125f,
0.125f,0.25f,
0.0f,0.25f,
0.125f,0.375f,
0.0f,0.375f,
0.125f,0.5f,
0.0f,0.5f,
0.125f,0.625f,
0.0f,0.625f,
0.125f,0.75f,
0.0f,0.75f,
0.125f,0.875f,
0.0f,0.875f,
0.125f,1.0f,
0.0f,1.0f,
0.25f,0.0f,
0.25f,0.125f,
0.25f,0.25f,
0.25f,0.375f,
0.25f,0.5f,
0.25f,0.625f,
0.25f,0.75f,
0.25f,0.875f,
0.25f,1.0f,
0.375f,0.0f,
0.375f,0.125f,
0.375f,0.25f,
0.375f,0.375f,
0.375f,0.5f,
0.375f,0.625f,
0.375f,0.75f,
0.375f,0.875f,
0.375f,1.0f,
0.5f,0.0f,
0.5f,0.125f,
0.5f,0.25f,
0.5f,0.375f,
0.5f,0.5f,
0.5f,0.625f,
0.5f,0.75f,
0.5f,0.875f,
0.5f,1.0f,
0.625f,0.0f,
0.625f,0.125f,
0.625f,0.25f,
0.625f,0.375f,
0.625f,0.5f,
0.625f,0.625f,
0.625f,0.75f,
0.625f,0.875f,
0.625f,1.0f,
0.75f,0.0f,
0.75f,0.125f,
0.75f,0.25f,
0.75f,0.375f,
0.75f,0.5f,
0.75f,0.625f,
0.75f,0.75f,
0.75f,0.875f,
0.75f,1.0f,
0.875f,0.0f,
0.875f,0.125f,
0.875f,0.25f,
0.875f,0.375f,
0.875f,0.5f,
0.875f,0.625f,
0.875f,0.75f,
0.875f,0.875f,
0.875f,1.0f,
1.0f,0.0f,
1.0f,0.125f,
1.0f,0.25f,
1.0f,0.375f,
1.0f,0.5f,
1.0f,0.625f,
1.0f,0.75f,
1.0f,0.875f,
1.0f,1.0f,
};
static unsigned short LargeMeshIdx[] = {
0,1,2,
3,2,1,
2,3,4,
5,4,3,
4,5,6,
7,6,5,
6,7,8,
9,8,7,
8,9,10,
11,10,9,
10,11,12,
13,12,11,
12,13,14,
15,14,13,
14,15,16,
17,16,15,
18,0,19,
2,19,0,
19,2,20,
4,20,2,
20,4,21,
6,21,4,
21,6,22,
8,22,6,
22,8,23,
10,23,8,
23,10,24,
12,24,10,
24,12,25,
14,25,12,
25,14,26,
16,26,14,
27,18,28,
19,28,18,
28,19,29,
20,29,19,
29,20,30,
21,30,20,
30,21,31,
22,31,21,
31,22,32,
23,32,22,
32,23,33,
24,33,23,
33,24,34,
25,34,24,
34,25,35,
26,35,25,
36,27,37,
28,37,27,
37,28,38,
29,38,28,
38,29,39,
30,39,29,
39,30,40,
31,40,30,
40,31,41,
32,41,31,
41,32,42,
33,42,32,
42,33,43,
34,43,33,
43,34,44,
35,44,34,
45,36,46,
37,46,36,
46,37,47,
38,47,37,
47,38,48,
39,48,38,
48,39,49,
40,49,39,
49,40,50,
41,50,40,
50,41,51,
42,51,41,
51,42,52,
43,52,42,
52,43,53,
44,53,43,
54,45,55,
46,55,45,
55,46,56,
47,56,46,
56,47,57,
48,57,47,
57,48,58,
49,58,48,
58,49,59,
50,59,49,
59,50,60,
51,60,50,
60,51,61,
52,61,51,
61,52,62,
53,62,52,
63,54,64,
55,64,54,
64,55,65,
56,65,55,
65,56,66,
57,66,56,
66,57,67,
58,67,57,
67,58,68,
59,68,58,
68,59,69,
60,69,59,
69,60,70,
61,70,60,
70,61,71,
62,71,61,
72,63,73,
64,73,63,
73,64,74,
65,74,64,
74,65,75,
66,75,65,
75,66,76,
67,76,66,
76,67,77,
68,77,67,
77,68,78,
69,78,68,
78,69,79,
70,79,69,
79,70,80,
71,80,70,
};

View File

@@ -0,0 +1,513 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "../common/common.h"
#include "../common/ctrl_func.h"
#include "../common/render_func.h"
#include "../common/perf_func.h"
#include "physics_func.h"
#ifdef _WIN32
#include <gl/gl.h>
#include <gl/glu.h>
#endif
// ARA begin insert new code
#ifdef __ANDROID__
#include <EGL/egl.h>
#include <GLES/gl.h>
#endif
// ARA end
#define SAMPLE_NAME "api_physics_effects/6_joint"
//#define ENABLE_DEBUG_DRAW
#ifdef ENABLE_DEBUG_DRAW
#define ENABLE_DEBUG_DRAW_CONTACT
#define ENABLE_DEBUG_DRAW_AABB
#define ENABLE_DEBUG_DRAW_ISLAND
#endif
static bool s_isRunning = true;
int sceneId = 0;
bool simulating = false;
void render(void)
{
render_begin();
const PfxVector3 colorWhite(1.0f);
const PfxVector3 colorGray(0.7f);
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxVector3 color = state.isAsleep()?colorGray:colorWhite;
PfxTransform3 rbT(state.getOrientation(), state.getPosition());
PfxShapeIterator itrShape(coll);
for(int j=0;j<coll.getNumShapes();j++,++itrShape) {
const PfxShape &shape = *itrShape;
PfxTransform3 offsetT = shape.getOffsetTransform();
PfxTransform3 worldT = rbT * offsetT;
switch(shape.getType()) {
case kPfxShapeSphere:
render_sphere(
worldT,
color,
PfxFloatInVec(shape.getSphere().m_radius));
break;
case kPfxShapeBox:
render_box(
worldT,
color,
shape.getBox().m_half);
break;
case kPfxShapeCapsule:
render_capsule(
worldT,
color,
PfxFloatInVec(shape.getCapsule().m_radius),
PfxFloatInVec(shape.getCapsule().m_halfLen));
break;
case kPfxShapeCylinder:
render_cylinder(
worldT,
color,
PfxFloatInVec(shape.getCylinder().m_radius),
PfxFloatInVec(shape.getCylinder().m_halfLen));
break;
default:
break;
}
}
}
render_debug_begin();
#ifdef ENABLE_DEBUG_DRAW_CONTACT
for(int i=0;i<physics_get_num_contacts();i++) {
const PfxContactManifold &contact = physics_get_contact(i);
const PfxRigidState &stateA = physics_get_state(contact.getRigidBodyIdA());
const PfxRigidState &stateB = physics_get_state(contact.getRigidBodyIdB());
for(int j=0;j<contact.getNumContacts();j++) {
const PfxContactPoint &cp = contact.getContactPoint(j);
PfxVector3 pA = stateA.getPosition()+rotate(stateA.getOrientation(),pfxReadVector3(cp.m_localPointA));
render_debug_point(pA,PfxVector3(0,0,1));
}
}
#endif
#ifdef ENABLE_DEBUG_DRAW_AABB
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxVector3 center = state.getPosition() + coll.getCenter();
PfxVector3 half = absPerElem(PfxMatrix3(state.getOrientation())) * coll.getHalf();
render_debug_box(center,half,PfxVector3(1,0,0));
}
#endif
#ifdef ENABLE_DEBUG_DRAW_ISLAND
const PfxIsland *island = physics_get_islands();
if(island) {
for(PfxUInt32 i=0;i<pfxGetNumIslands(island);i++) {
PfxIslandUnit *islandUnit = pfxGetFirstUnitInIsland(island,i);
PfxVector3 aabbMin(SCE_PFX_FLT_MAX);
PfxVector3 aabbMax(-SCE_PFX_FLT_MAX);
for(;islandUnit!=NULL;islandUnit=pfxGetNextUnitInIsland(islandUnit)) {
const PfxRigidState &state = physics_get_state(pfxGetUnitId(islandUnit));
const PfxCollidable &coll = physics_get_collidable(pfxGetUnitId(islandUnit));
PfxVector3 center = state.getPosition() + coll.getCenter();
PfxVector3 half = absPerElem(PfxMatrix3(state.getOrientation())) * coll.getHalf();
aabbMin = minPerElem(aabbMin,center-half);
aabbMax = maxPerElem(aabbMax,center+half);
}
render_debug_box((aabbMax+aabbMin)*0.5f,(aabbMax-aabbMin)*0.5f,PfxVector3(0,1,0));
}
}
#endif
render_debug_end();
render_end();
}
int init(void)
{
perf_init();
ctrl_init();
render_init();
physics_init();
float angX,angY,r;
render_get_view_angle(angX,angY,r);
r *= 0.5f;
render_set_view_angle(angX,angY,r);
return 0;
}
static int shutdown(void)
{
ctrl_release();
render_release();
physics_release();
perf_release();
return 0;
}
void update(void)
{
float angX,angY,r;
render_get_view_angle(angX,angY,r);
ctrl_update();
if(ctrl_button_pressed(BTN_UP)) {
angX -= 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_DOWN)) {
angX += 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_LEFT)) {
angY -= 0.05f;
}
if(ctrl_button_pressed(BTN_RIGHT)) {
angY += 0.05f;
}
if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
r *= 1.1f;
if(r > 500.0f) r = 500.0f;
}
if(ctrl_button_pressed(BTN_ZOOM_IN)) {
r *= 0.9f;
if(r < 1.0f) r = 1.0f;
}
if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
physics_create_scene(sceneId);
}
if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
physics_create_scene(++sceneId);
}
if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
simulating = !simulating;
}
if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
simulating = true;
}
else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
simulating = false;
}
int w,h;
render_get_screent_size(w,h);
ctrl_set_screen_size(w,h);
static PfxVector3 pickPos(0.0f);
if(ctrl_button_pressed(BTN_PICK) == BTN_STAT_DOWN) {
int sx,sy;
ctrl_get_cursor_position(sx,sy);
PfxVector3 wp1((float)sx,(float)sy,0.0f);
PfxVector3 wp2((float)sx,(float)sy,1.0f);
wp1 = render_get_world_position(wp1);
wp2 = render_get_world_position(wp2);
pickPos = physics_pick_start(wp1,wp2);
}
else if(ctrl_button_pressed(BTN_PICK) == BTN_STAT_KEEP) {
int sx,sy;
ctrl_get_cursor_position(sx,sy);
PfxVector3 sp = render_get_screen_position(pickPos);
PfxVector3 wp((float)sx,(float)sy,sp[2]);
wp = render_get_world_position(wp);
physics_pick_update(wp);
}
else if(ctrl_button_pressed(BTN_PICK) == BTN_STAT_UP) {
physics_pick_end();
}
render_set_view_angle(angX,angY,r);
}
#ifndef _WIN32
// ARA begin insert new code
#ifdef __ANDROID__
///////////////////////////////////////////////////////////////////////////////
// sceneChange
//
/// This function is used to change the physics scene on Android devices
///////////////////////////////////////////////////////////////////////////////
void sceneChange()
{
physics_create_scene(sceneId++);
}
#else // __ANDROID__
// ARA end
///////////////////////////////////////////////////////////////////////////////
// Main
int main(void)
{
init();
physics_create_scene(sceneId);
printf("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
while (s_isRunning) {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
shutdown();
printf("## %s: FINISHED ##\n", SAMPLE_NAME);
return 0;
}
// ARA begin insert new code
#endif // __ANDROID__
// ARA end
#else // _WIN32
///////////////////////////////////////////////////////////////////////////////
// WinMain
extern HDC hDC;
extern HGLRC hRC;
HWND hWnd;
HINSTANCE hInstance;
void releaseWindow()
{
if(hRC) {
wglMakeCurrent(0,0);
wglDeleteContext(hRC);
}
if(hDC) ReleaseDC(hWnd,hDC);
if(hWnd) DestroyWindow(hWnd);
UnregisterClass(SAMPLE_NAME,hInstance);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg) {
case WM_SYSCOMMAND:
{
switch (wParam) {
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_SIZE:
render_resize(LOWORD(lParam),HIWORD(lParam));
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
bool createWindow(char* title, int width, int height)
{
WNDCLASS wc;
RECT rect;
rect.left=0;
rect.right=width;
rect.top=0;
rect.bottom=height;
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = SAMPLE_NAME;
if(!RegisterClass(&wc)) {
return false;
}
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
if(!(hWnd=CreateWindowEx(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,SAMPLE_NAME,title,
WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
0,0,rect.right-rect.left,rect.bottom-rect.top,
NULL,NULL,hInstance,NULL))) {
releaseWindow();
return false;
}
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0,
0, 0,
0, 0,
0, 0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if(!(hDC=GetDC(hWnd)))
{
releaseWindow();
OutputDebugString("");
return FALSE;
}
int pixelformat;
if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 ){
OutputDebugString("ChoosePixelFormat Failed....");
return FALSE;
}
if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE){
OutputDebugString("SetPixelFormat Failed....");
return FALSE;
}
if (!(hRC=wglCreateContext(hDC))){
OutputDebugString("Creating HGLRC Failed....");
return FALSE;
}
// Set Vsync
//BOOL (WINAPI *wglSwapIntervalEXT)(int) = NULL;
//if(strstr((char*)glGetString( GL_EXTENSIONS ),"WGL_EXT_swap_control")== 0) {
//}
//else {
//wglSwapIntervalEXT = (BOOL (WINAPI*)(int))wglGetProcAddress("wglSwapIntervalEXT");
//if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
//}
wglMakeCurrent(hDC,hRC);
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
render_resize(width, height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return 0;
}
init();
physics_create_scene(sceneId);
SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
MSG msg;
while(s_isRunning) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if(msg.message==WM_QUIT) {
s_isRunning = false;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
}
shutdown();
SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);
releaseWindow();
return (msg.wParam);
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,53 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __PHYSICS_FUNC_H__
#define __PHYSICS_FUNC_H__
#define SCE_PFX_USE_PERFCOUNTER
#include "physics_effects.h"
using namespace sce::PhysicsEffects;
//E Simulation
//J シミュレーション
bool physics_init();
void physics_release();
void physics_create_scene(int sceneId);
void physics_simulate();
//E Picking
//J ピッキング
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2);
void physics_pick_update(const PfxVector3 &p);
void physics_pick_end();
//E Change parameters
//J パラメータの取得
int physics_get_num_rigidbodies();
const PfxRigidState& physics_get_state(int id);
const PfxRigidBody& physics_get_body(int id);
const PfxCollidable& physics_get_collidable(int id);
// Get contact information
int physics_get_num_contacts();
const PfxContactManifold &physics_get_contact(int id);
// Get simulation island
const PfxIsland* physics_get_islands();
#endif /* __PHYSICS_FUNC_H__ */

View File

@@ -0,0 +1,280 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="99_BulletPhysicsEffects"
ProjectGUID="{74D8E3A1-33A5-49FB-B822-FA4EA49C66E8}"
RootNamespace="My99_BulletPhysicsEffects"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include"
PreprocessorDefinitions="PFX_USE_FREE_VECTORMATH;WIN32;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib "
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Debug&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../include"
PreprocessorDefinitions="PFX_USE_FREE_VECTORMATH;WIN32;_WINDOWS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../../lib/Win32 Release&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btBulletPhysicsEffectsWorld.cpp"
>
</File>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btLowLevelBroadphase.cpp"
>
</File>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btLowLevelCollisionDispatcher.cpp"
>
</File>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btLowLevelConstraintSolver.cpp"
>
</File>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btLowLevelConstraintSolver2.cpp"
>
</File>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btLowLevelData.cpp"
>
</File>
<File
RelativePath=".\bullet_physics_func.cpp"
>
</File>
<File
RelativePath="..\common\ctrl_func.win32.cpp"
>
</File>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath="..\common\perf_func.win32.cpp"
>
</File>
<File
RelativePath="..\common\render_func.win32.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\barrel.h"
>
</File>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btBulletPhysicsEffectsWorld.h"
>
</File>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btlowlevelbroadphase.h"
>
</File>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btLowLevelCollisionDispatcher.h"
>
</File>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btLowLevelConstraintSolver.h"
>
</File>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btLowLevelConstraintSolver2.h"
>
</File>
<File
RelativePath="..\..\..\include\BulletPhysicsEffects\btLowLevelData.h"
>
</File>
<File
RelativePath=".\landscape.h"
>
</File>
<File
RelativePath=".\physics_func.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,89 @@
cmake_minimum_required(VERSION 2.4)
#this line has to appear before 'PROJECT' in order to be able to disable incremental linking
SET(MSVC_INCREMENTAL_DEFAULT ON)
PROJECT(App_99_BulletPhysicsEffects)
IF (NOT CMAKE_BUILD_TYPE)
# SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_BUILD_TYPE "Release")
ENDIF (NOT CMAKE_BUILD_TYPE)
OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" ON)
OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
ENDIF(COMMAND cmake_policy)
SET(App_99_BulletPhysicsEffects_SRCS
main.cpp
bullet_physics_func.cpp
../common/ctrl_func.win32.cpp
../common/perf_func.win32.cpp
../common/render_func.win32.cpp
${PHYSICS_EFFECTS_SOURCE_DIR}/include/BulletPhysicsEffects/btBulletPhysicsEffectsWorld.cpp
${PHYSICS_EFFECTS_SOURCE_DIR}/include/BulletPhysicsEffects/btLowLevelConstraintSolver2.cpp
${PHYSICS_EFFECTS_SOURCE_DIR}/include/BulletPhysicsEffects/btLowLevelCollisionDispatcher.cpp
${PHYSICS_EFFECTS_SOURCE_DIR}/include/BulletPhysicsEffects/btLowLevelBroadphase.cpp
)
SET(App_99_BulletPhysicsEffects_HDRS
physics_func.h
landscape.h
barrel.h
../common/render_func.h
../common/common.h
../common/ctrl_func.h
../common/perf_func.h
${PHYSICS_EFFECTS_SOURCE_DIR}/include/BulletPhysicsEffects/btBulletPhysicsEffectsWorld.h
${PHYSICS_EFFECTS_SOURCE_DIR}/include/BulletPhysicsEffects/btLowLevelConstraintSolver2.h
${PHYSICS_EFFECTS_SOURCE_DIR}/include/BulletPhysicsEffects/btLowLevelCollisionDispatcher.h
${PHYSICS_EFFECTS_SOURCE_DIR}/include/BulletPhysicsEffects/btLowLevelBroadphase.h
)
INCLUDE_DIRECTORIES(
../../../../../src
# ${VECTOR_MATH_INCLUDE}
)
#LINK_DIRECTORIES(
#
#)
#ADD_DEFINITIONS(-DUNICODE)
#ADD_DEFINITIONS(-D_UNICODE)
ADD_EXECUTABLE(App_99_BulletPhysicsEffects WIN32
${App_99_BulletPhysicsEffects_SRCS}
${App_99_BulletPhysicsEffects_HDRS}
)
TARGET_LINK_LIBRARIES(App_99_BulletPhysicsEffects
PfxBaseLevel
PfxLowLevel
PfxUtil
BulletDynamics
BulletCollision
LinearMath
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(App_99_BulletPhysicsEffects PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(App_99_BulletPhysicsEffects PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(App_99_BulletPhysicsEffects PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF()

View File

@@ -0,0 +1,202 @@
/*
Physics Effects Copyright(C) 2011 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define BarrelVtxCount 57
#define BarrelIdxCount 180
static float BarrelVtx[] = {
0.0f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,-0.331936f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,-0.205148f, 0.0f,-1.0f,0.0f,
-0.349018f,-0.5f,0.0f, 0.0f,-1.0f,0.0f,
-0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
-0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.107853f,-0.5f,0.331936f, 0.0f,-1.0f,0.0f,
0.282362f,-0.5f,0.205148f, 0.0f,-1.0f,0.0f,
0.0f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,-0.331936f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,-0.205148f, 0.0f,1.0f,0.0f,
-0.349018f,0.5f,0.0f, 0.0f,1.0f,0.0f,
-0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
-0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.107853f,0.5f,0.331936f, 0.0f,1.0f,0.0f,
0.282362f,0.5f,0.205148f, 0.0f,1.0f,0.0f,
0.349018f,-0.5f,0.0f, 0.957307f,-0.289072f,0.0f,
0.404509f,0.0f,-0.293893f, 0.809017f,0.0f,-0.587785f,
0.5f,0.0f,0.0f, 1.0f,0.0f,0.0f,
0.282362f,-0.5f,-0.205148f, 0.774478f,-0.289072f,-0.562691f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
0.107853f,-0.5f,-0.331936f, 0.295824f,-0.289072f,-0.910453f,
-0.154509f,0.0f,-0.475528f, -0.309017f,0.0f,-0.951057f,
0.154508f,0.0f,-0.475528f, 0.309017f,0.0f,-0.951057f,
-0.107853f,-0.5f,-0.331936f, -0.295824f,-0.289072f,-0.910453f,
-0.404509f,0.0f,-0.293893f, -0.809017f,0.0f,-0.587785f,
-0.282362f,-0.5f,-0.205148f, -0.774478f,-0.289072f,-0.562691f,
-0.5f,0.0f,0.0f, -1.0f,0.0f,0.0f,
-0.349018f,-0.5f,0.0f, -0.957307f,-0.289072f,0.0f,
-0.404508f,0.0f,0.293893f, -0.809017f,0.0f,0.587785f,
-0.282362f,-0.5f,0.205148f, -0.774478f,-0.289072f,0.562691f,
-0.154509f,0.0f,0.475528f, -0.309017f,0.0f,0.951056f,
-0.107853f,-0.5f,0.331936f, -0.295824f,-0.289072f,0.910453f,
0.154509f,0.0f,0.475528f, 0.309017f,0.0f,0.951056f,
0.107853f,-0.5f,0.331936f, 0.295824f,-0.289072f,0.910453f,
0.404509f,0.0f,0.293892f, 0.809017f,0.0f,0.587785f,
0.282362f,-0.5f,0.205148f, 0.774478f,-0.289072f,0.562691f,
0.282362f,0.5f,-0.205148f, 0.774478f,0.289072f,-0.562691f,
0.349018f,0.5f,0.0f, 0.957307f,0.289072f,0.0f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.107853f,0.5f,-0.331936f, -0.295824f,0.289072f,-0.910453f,
0.107853f,0.5f,-0.331936f, 0.295824f,0.289072f,-0.910453f,
-0.282362f,0.5f,-0.205148f, -0.774478f,0.289072f,-0.562691f,
-0.349018f,0.5f,0.0f, -0.957307f,0.289072f,0.0f,
-0.282362f,0.5f,0.205148f, -0.774478f,0.289072f,0.562691f,
-0.107853f,0.5f,0.331936f, -0.295824f,0.289072f,0.910453f,
0.107853f,0.5f,0.331936f, 0.295824f,0.289072f,0.910453f,
0.282362f,0.5f,0.205148f, 0.774478f,0.289072f,0.562691f,
};
static float BarrelTex[] = {
0.0f,0.5f,
0.0f,0.85f,
0.0f,0.75f,
0.0f,0.95f,
0.0f,0.05f,
0.0f,-0.05f,
0.0f,0.15f,
0.0f,0.25f,
0.0f,0.35f,
0.0f,0.45f,
0.0f,0.55f,
0.0f,0.65f,
1.0f,0.5f,
1.0f,0.75f,
1.0f,0.85f,
1.0f,0.95f,
1.0f,-0.05f,
1.0f,0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
0.0f,0.75f,
0.5f,0.85f,
0.5f,0.75f,
0.0f,0.85f,
0.5f,0.95f,
0.0f,0.95f,
0.0f,-0.05f,
0.5f,0.05f,
0.5f,-0.05f,
0.0f,0.05f,
0.5f,0.15f,
0.0f,0.15f,
0.5f,0.25f,
0.0f,0.25f,
0.5f,0.35f,
0.0f,0.35f,
0.5f,0.45f,
0.0f,0.45f,
0.5f,0.55f,
0.0f,0.55f,
0.5f,0.65f,
0.0f,0.65f,
1.0f,0.85f,
1.0f,0.75f,
1.0f,0.95f,
1.0f,0.05f,
1.0f,-0.05f,
1.0f,0.15f,
1.0f,0.25f,
1.0f,0.35f,
1.0f,0.45f,
1.0f,0.55f,
1.0f,0.65f,
};
static unsigned short BarrelIdx[] = {
0,1,2,
0,3,1,
0,4,5,
0,6,4,
0,7,6,
0,8,7,
0,9,8,
0,10,9,
0,11,10,
0,2,11,
12,13,14,
12,14,15,
12,16,17,
12,17,18,
12,18,19,
12,19,20,
12,20,21,
12,21,22,
12,22,23,
12,23,13,
24,25,26,
24,27,25,
27,28,25,
27,29,28,
30,31,32,
30,33,31,
33,34,31,
33,35,34,
35,36,34,
35,37,36,
37,38,36,
37,39,38,
39,40,38,
39,41,40,
41,42,40,
41,43,42,
43,44,42,
43,45,44,
45,26,44,
45,24,26,
26,46,47,
26,25,46,
25,48,46,
25,28,48,
32,49,50,
32,31,49,
31,51,49,
31,34,51,
34,52,51,
34,36,52,
36,53,52,
36,38,53,
38,54,53,
38,40,54,
40,55,54,
40,42,55,
42,56,55,
42,44,56,
44,47,56,
44,26,47,
};

View File

@@ -0,0 +1,318 @@
/*
Physics Effects Copyright(C) 2011 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define LargeMeshVtxCount 81
#define LargeMeshIdxCount 384
static float LargeMeshVtx[] = {
-25.0f,-2.19407f,18.5625f, 0.232976f,0.967754f,0.0957829f,
-25.0f,0.0644502f,24.75f, 0.188094f,0.871343f,-0.45319f,
-18.75f,-4.50287f,18.5625f, -0.0716098f,0.995449f,0.0628767f,
-18.75f,-0.39999f,24.75f, -0.0602794f,0.895848f,-0.440253f,
-12.5f,-1.2166f,18.5625f, -0.269469f,0.961403f,0.0555879f,
-12.5f,-0.942431f,24.75f, -0.0997841f,0.993258f,0.0589987f,
-6.25f,1.93598f,18.5625f, -0.283933f,0.956351f,-0.0691025f,
-6.25f,-0.445954f,24.75f, -0.180725f,0.942766f,0.280233f,
0.0f,2.76983f,18.5625f, 0.171645f,0.984908f,0.0222501f,
0.0f,2.76642f,24.75f, 0.0784993f,0.995428f,-0.0544117f,
6.25f,-2.53736f,18.5625f, 0.248298f,0.965028f,0.0840741f,
6.25f,-0.915645f,24.75f, 0.164311f,0.945856f,-0.279926f,
12.5f,-1.60054f,18.5625f, -0.180435f,0.983586f,0.00115547f,
12.5f,0.831925f,24.75f, -0.0692495f,0.964821f,-0.253623f,
18.75f,-0.800282f,18.5625f, 0.10755f,0.951538f,0.288112f,
18.75f,-1.47284f,24.75f, 0.232178f,0.972664f,0.00429361f,
25.0f,-2.78379f,18.5625f, 0.1833f,0.937477f,0.295867f,
25.0f,-0.967508f,24.75f, -0.0773477f,0.956641f,-0.280812f,
-25.0f,-0.352038f,12.375f, -0.192222f,0.972435f,0.131987f,
-18.75f,0.681228f,12.375f, -0.107779f,0.962569f,0.248686f,
-12.5f,2.72065f,12.375f, 0.0520846f,0.993034f,0.105692f,
-6.25f,-1.78776f,12.375f, -0.0133223f,0.99674f,-0.0795754f,
0.0f,1.57707f,12.375f, -0.129025f,0.969662f,-0.207627f,
6.25f,0.424356f,12.375f, 0.180995f,0.97074f,0.157815f,
12.5f,0.283234f,12.375f, -0.16285f,0.973539f,0.160316f,
18.75f,2.57015f,12.375f, -0.165454f,0.978339f,0.124408f,
25.0f,3.07363f,12.375f, -0.00454559f,0.988151f,0.153417f,
-25.0f,-0.893751f,6.1875f, -0.0836251f,0.990084f,-0.112876f,
-18.75f,0.930932f,6.1875f, 0.00269413f,0.971838f,-0.235633f,
-12.5f,-0.684529f,6.1875f, -0.010319f,0.927048f,-0.3748f,
-6.25f,-0.661383f,6.1875f, 0.012265f,0.999875f,-0.00994222f,
0.0f,0.385718f,6.1875f, -0.15435f,0.984937f,-0.0779465f,
6.25f,0.589796f,6.1875f, 0.0241717f,0.999582f,-0.0158589f,
12.5f,0.47454f,6.1875f, -0.017184f,0.997953f,-0.0616073f,
18.75f,1.59939f,6.1875f, -0.0902706f,0.957309f,-0.274609f,
25.0f,1.13434f,6.1875f, 0.0346006f,0.957441f,-0.286547f,
-25.0f,0.74548f,0.0f, 0.329903f,0.930812f,0.157334f,
-18.75f,-2.47437f,0.0f, 0.247844f,0.968142f,0.0357041f,
-12.5f,-4.16309f,1.81975e-007f, -0.0623898f,0.997626f,-0.0291436f,
-6.25f,-0.700022f,0.0f, -0.217067f,0.974987f,-0.0477624f,
0.0f,-0.0957388f,0.0f, -0.117693f,0.990712f,-0.068098f,
6.25f,0.614077f,0.0f, -0.0713214f,0.997305f,0.01722f,
12.5f,0.299109f,0.0f, 0.218606f,0.968641f,0.118094f,
18.75f,-1.71753f,0.0f, 0.0339493f,0.985612f,-0.165579f,
25.0f,-1.12638f,0.0f, -0.0547573f,0.989177f,-0.136126f,
-25.0f,-0.403319f,-6.1875f, -0.1263f,0.989211f,-0.074223f,
-18.75f,-0.0730335f,-6.1875f, 0.0173428f,0.965382f,0.260261f,
-12.5f,-0.450125f,-6.1875f, 0.0658811f,0.875f,0.479619f,
-6.25f,-0.180204f,-6.1875f, 0.0116584f,0.981445f,0.19139f,
0.0f,-0.632679f,-6.1875f, -0.0557983f,0.993041f,-0.103716f,
6.25f,0.308409f,-6.1875f, -0.191898f,0.96766f,-0.163737f,
12.5f,2.5011f,-6.1875f, 0.0758397f,0.996403f,-0.0378189f,
18.75f,-1.69303f,-6.1875f, 0.16761f,0.974057f,0.15205f,
25.0f,-0.141349f,-6.1875f, -0.204846f,0.978471f,0.0251341f,
-25.0f,-1.10316f,-12.375f, -0.0350644f,0.993748f,-0.106001f,
-18.75f,1.06711f,-12.375f, -0.309806f,0.919244f,-0.242922f,
-12.5f,3.61544f,-12.375f, -0.0506281f,0.998702f,-0.00561657f,
-6.25f,1.6504f,-12.375f, 0.322294f,0.937465f,0.131477f,
0.0f,-1.60595f,-12.375f, 0.086016f,0.995916f,0.0274459f,
6.25f,-0.849859f,-12.375f, -0.0332811f,0.997087f,0.0686255f,
12.5f,-0.942201f,-12.375f, -0.153559f,0.982185f,-0.108312f,
18.75f,0.494873f,-12.375f, 0.0753195f,0.981472f,0.176181f,
25.0f,-0.333828f,-12.375f, 0.035057f,0.987194f,0.155624f,
-25.0f,2.1862f,-18.5625f, 0.612899f,0.782306f,0.111138f,
-18.75f,-3.38259f,-18.5625f, 0.0194078f,0.992789f,-0.118297f,
-12.5f,-0.880916f,-18.5625f, -0.282251f,0.949875f,-0.13443f,
-6.25f,0.818158f,-18.5625f, 0.1476f,0.981788f,-0.119612f,
0.0f,-1.48019f,-18.5625f, -0.044551f,0.996013f,-0.0772824f,
6.25f,1.47123f,-18.5625f, -0.117036f,0.97986f,0.161792f,
12.5f,0.164076f,-18.5625f, -0.0340355f,0.978993f,0.201034f,
18.75f,2.14568f,-18.5625f, -0.0439269f,0.994859f,0.0912435f,
25.0f,0.626506f,-18.5625f, 0.208015f,0.968592f,0.136229f,
-25.0f,0.296889f,-24.75f, 0.46973f,0.844327f,-0.257809f,
-18.75f,-3.18022f,-24.75f, -0.0226758f,0.998794f,-0.0435401f,
-12.5f,1.8927f,-24.75f, -0.202772f,0.919836f,0.335836f,
-6.25f,1.46387f,-24.75f, 0.224904f,0.955746f,0.189652f,
0.0f,-2.52726f,-24.75f, -0.0435882f,0.993572f,-0.10447f,
6.25f,1.30397f,-24.75f, -0.28646f,0.956525f,-0.0547707f,
12.5f,1.85812f,-24.75f, 0.0521949f,0.979796f,0.193067f,
18.75f,1.56331f,-24.75f, -0.0270784f,0.999629f,-0.00293115f,
25.0f,1.05366f,-24.75f, 0.161f,0.986887f,-0.0115473f,
};
static float LargeMeshTex[] = {
0.125f,0.0f,
0.0f,0.0f,
0.125f,0.125f,
0.0f,0.125f,
0.125f,0.25f,
0.0f,0.25f,
0.125f,0.375f,
0.0f,0.375f,
0.125f,0.5f,
0.0f,0.5f,
0.125f,0.625f,
0.0f,0.625f,
0.125f,0.75f,
0.0f,0.75f,
0.125f,0.875f,
0.0f,0.875f,
0.125f,1.0f,
0.0f,1.0f,
0.25f,0.0f,
0.25f,0.125f,
0.25f,0.25f,
0.25f,0.375f,
0.25f,0.5f,
0.25f,0.625f,
0.25f,0.75f,
0.25f,0.875f,
0.25f,1.0f,
0.375f,0.0f,
0.375f,0.125f,
0.375f,0.25f,
0.375f,0.375f,
0.375f,0.5f,
0.375f,0.625f,
0.375f,0.75f,
0.375f,0.875f,
0.375f,1.0f,
0.5f,0.0f,
0.5f,0.125f,
0.5f,0.25f,
0.5f,0.375f,
0.5f,0.5f,
0.5f,0.625f,
0.5f,0.75f,
0.5f,0.875f,
0.5f,1.0f,
0.625f,0.0f,
0.625f,0.125f,
0.625f,0.25f,
0.625f,0.375f,
0.625f,0.5f,
0.625f,0.625f,
0.625f,0.75f,
0.625f,0.875f,
0.625f,1.0f,
0.75f,0.0f,
0.75f,0.125f,
0.75f,0.25f,
0.75f,0.375f,
0.75f,0.5f,
0.75f,0.625f,
0.75f,0.75f,
0.75f,0.875f,
0.75f,1.0f,
0.875f,0.0f,
0.875f,0.125f,
0.875f,0.25f,
0.875f,0.375f,
0.875f,0.5f,
0.875f,0.625f,
0.875f,0.75f,
0.875f,0.875f,
0.875f,1.0f,
1.0f,0.0f,
1.0f,0.125f,
1.0f,0.25f,
1.0f,0.375f,
1.0f,0.5f,
1.0f,0.625f,
1.0f,0.75f,
1.0f,0.875f,
1.0f,1.0f,
};
static unsigned short LargeMeshIdx[] = {
0,1,2,
3,2,1,
2,3,4,
5,4,3,
4,5,6,
7,6,5,
6,7,8,
9,8,7,
8,9,10,
11,10,9,
10,11,12,
13,12,11,
12,13,14,
15,14,13,
14,15,16,
17,16,15,
18,0,19,
2,19,0,
19,2,20,
4,20,2,
20,4,21,
6,21,4,
21,6,22,
8,22,6,
22,8,23,
10,23,8,
23,10,24,
12,24,10,
24,12,25,
14,25,12,
25,14,26,
16,26,14,
27,18,28,
19,28,18,
28,19,29,
20,29,19,
29,20,30,
21,30,20,
30,21,31,
22,31,21,
31,22,32,
23,32,22,
32,23,33,
24,33,23,
33,24,34,
25,34,24,
34,25,35,
26,35,25,
36,27,37,
28,37,27,
37,28,38,
29,38,28,
38,29,39,
30,39,29,
39,30,40,
31,40,30,
40,31,41,
32,41,31,
41,32,42,
33,42,32,
42,33,43,
34,43,33,
43,34,44,
35,44,34,
45,36,46,
37,46,36,
46,37,47,
38,47,37,
47,38,48,
39,48,38,
48,39,49,
40,49,39,
49,40,50,
41,50,40,
50,41,51,
42,51,41,
51,42,52,
43,52,42,
52,43,53,
44,53,43,
54,45,55,
46,55,45,
55,46,56,
47,56,46,
56,47,57,
48,57,47,
57,48,58,
49,58,48,
58,49,59,
50,59,49,
59,50,60,
51,60,50,
60,51,61,
52,61,51,
61,52,62,
53,62,52,
63,54,64,
55,64,54,
64,55,65,
56,65,55,
65,56,66,
57,66,56,
66,57,67,
58,67,57,
67,58,68,
59,68,58,
68,59,69,
60,69,59,
69,60,70,
61,70,60,
70,61,71,
62,71,61,
72,63,73,
64,73,63,
73,64,74,
65,74,64,
74,65,75,
66,75,65,
75,66,76,
67,76,66,
76,67,77,
68,77,67,
77,68,78,
69,78,68,
78,69,79,
70,79,69,
79,70,80,
71,80,70,
};

View File

@@ -0,0 +1,485 @@
/*
Physics Effects Copyright(C) 2011 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "btBulletDynamicsCommon.h"
#include "../common/common.h"
#include "../common/ctrl_func.h"
#include "../common/render_func.h"
#include "../common/perf_func.h"
#include "physics_func.h"
#include "barrel.h"
#include "landscape.h"
#ifdef WIN32
#include <gl/gl.h>
#include <gl/glu.h>
#endif
#define SAMPLE_NAME "api_physics_effects/1_simple"
static bool s_isRunning = true;
int sceneId = 2;
bool simulating = false;
int landscapeMeshId;
int convexMeshId;
/*
kPfxShapeSphere = 0,
kPfxShapeBox,
kPfxShapeCapsule,
kPfxShapeCylinder,
kPfxShapeConvexMesh,
kPfxShapeLargeTriMesh,
kPfxShapeReserved0,
kPfxShapeReserved1,
kPfxShapeReserved2,
kPfxShapeUser0,
kPfxShapeUser1,
kPfxShapeUser2,
kPfxShapeCount // =12
*/
extern void debugRenderPhysics();
static void render(void)
{
render_begin();
for(int i=0;i<physics_get_num_rigidbodies();i++) {
const PfxRigidState &state = physics_get_state(i);
const PfxCollidable &coll = physics_get_collidable(i);
PfxTransform3 rbT(state.getOrientation(), state.getPosition());
PfxShapeIterator itrShape(coll);
for(int j=0;j<coll.getNumShapes();j++,++itrShape) {
const PfxShape &shape = *itrShape;
PfxTransform3 offsetT = shape.getOffsetTransform();
PfxTransform3 worldT = rbT * offsetT;
switch(shape.getType()) {
case kPfxShapeSphere:
render_sphere(
worldT,
Vectormath::Aos::Vector3(1,1,1),
Vectormath::floatInVec(shape.getSphere().m_radius));
break;
case kPfxShapeBox:
render_box(
worldT,
Vectormath::Aos::Vector3(1,1,1),
shape.getBox().m_half);
break;
case kPfxShapeCapsule:
render_capsule(
worldT,
Vectormath::Aos::Vector3(1,1,1),
Vectormath::floatInVec(shape.getCapsule().m_radius),
Vectormath::floatInVec(shape.getCapsule().m_halfLen));
break;
case kPfxShapeCylinder:
render_cylinder(
worldT,
Vectormath::Aos::Vector3(1,1,1),
Vectormath::floatInVec(shape.getCylinder().m_radius),
Vectormath::floatInVec(shape.getCylinder().m_halfLen));
break;
case kPfxShapeConvexMesh:
render_mesh(
worldT,
Vectormath::Aos::Vector3(1,1,1),
convexMeshId);
break;
case kPfxShapeLargeTriMesh:
render_mesh(
worldT,
Vectormath::Aos::Vector3(1,1,1),
landscapeMeshId);
break;
default:
break;
}
}
}
debugRenderPhysics();
render_end();
}
static int init(void)
{
perf_init();
ctrl_init();
render_init();
physics_init();
landscapeMeshId = render_init_mesh(
LargeMeshVtx,sizeof(float)*6,
LargeMeshVtx+3,sizeof(float)*6,
LargeMeshIdx,sizeof(unsigned short)*3,
LargeMeshVtxCount,LargeMeshIdxCount/3);
convexMeshId = render_init_mesh(
BarrelVtx,sizeof(float)*6,
BarrelVtx+3,sizeof(float)*6,
BarrelIdx,sizeof(unsigned short)*3,
BarrelVtxCount,BarrelIdxCount/3);
return 0;
}
static int shutdown(void)
{
ctrl_release();
render_release();
physics_release();
perf_release();
return 0;
}
static void update(void)
{
static btClock clock;
static bool first = true;
btScalar dt=1.f;
if (first)
{
first=false;
clock.reset();
} else
{
dt = (btScalar)clock.getTimeMicroseconds()/100000.f;
clock.reset();
}
float angX,angY,r=1.f;
render_get_view_angle(angX,angY,r);
ctrl_update();
if(ctrl_button_pressed(BTN_UP)) {
angX -= 0.05f*dt;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_DOWN)) {
angX += 0.05f*dt;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
}
if(ctrl_button_pressed(BTN_LEFT)) {
angY -= 0.05f*dt;
}
if(ctrl_button_pressed(BTN_RIGHT)) {
angY += 0.05f*dt;
}
if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
r *= (1.f+0.2*dt);
if(r > 500.0f) r = 500.0f;
}
if(ctrl_button_pressed(BTN_ZOOM_IN)) {
r *= (1.f-0.2*dt);
if(r < 1.0f) r = 1.0f;
}
if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
physics_create_scene(sceneId);
}
if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
physics_create_scene(++sceneId);
}
if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
simulating = !simulating;
}
if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
simulating = true;
}
else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
simulating = false;
}
render_set_view_angle(angX,angY,r);
}
#ifndef WIN32
///////////////////////////////////////////////////////////////////////////////
// Main
int main(void)
{
init();
physics_create_scene(sceneId);
printf("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
while (s_isRunning) {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
shutdown();
printf("## %s: FINISHED ##\n", SAMPLE_NAME);
return 0;
}
#else
#include <stdio.h>
#include <setjmp.h>
static jmp_buf buf;
void second(void) {
printf("second\n"); // prints
longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1
}
void first(void) {
second();
printf("first\n"); // does not print
}
int main2() {
if ( ! setjmp(buf) ) {
first(); // when executed, setjmp returns 0
} else { // when longjmp jumps back, setjmp returns 1
printf("main\n"); // prints
}
return 0;
}
///////////////////////////////////////////////////////////////////////////////
// WinMain
extern HDC hDC;
extern HGLRC hRC;
HWND hWnd;
HINSTANCE hInstance;
void releaseWindow()
{
if(hRC) {
wglMakeCurrent(0,0);
wglDeleteContext(hRC);
}
if(hDC) ReleaseDC(hWnd,hDC);
if(hWnd) DestroyWindow(hWnd);
UnregisterClass(SAMPLE_NAME,hInstance);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg) {
case WM_SYSCOMMAND:
{
switch (wParam) {
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_SIZE:
render_resize(LOWORD(lParam),HIWORD(lParam));
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
bool createWindow(char* title, int width, int height)
{
WNDCLASS wc;
RECT rect;
rect.left=0;
rect.right=width;
rect.top=0;
rect.bottom=height;
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = SAMPLE_NAME;
if(!RegisterClass(&wc)) {
return false;
}
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
if(!(hWnd=CreateWindowEx(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,SAMPLE_NAME,title,
WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
0,0,rect.right-rect.left,rect.bottom-rect.top,
NULL,NULL,hInstance,NULL))) {
releaseWindow();
return false;
}
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0,
0, 0,
0, 0,
0, 0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if(!(hDC=GetDC(hWnd)))
{
releaseWindow();
OutputDebugString("");
return FALSE;
}
int pixelformat;
if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 ){
OutputDebugString("ChoosePixelFormat Failed....");
return FALSE;
}
if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE){
OutputDebugString("SetPixelFormat Failed....");
return FALSE;
}
if (!(hRC=wglCreateContext(hDC))){
OutputDebugString("Creating HGLRC Failed....");
return FALSE;
}
// Set Vsync
//BOOL (WINAPI *wglSwapIntervalEXT)(int) = NULL;
//if(strstr((char*)glGetString( GL_EXTENSIONS ),"WGL_EXT_swap_control")== 0) {
//}
//else {
//wglSwapIntervalEXT = (BOOL (WINAPI*)(int))wglGetProcAddress("wglSwapIntervalEXT");
//if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
//}
wglMakeCurrent(hDC,hRC);
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
render_resize(width, height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
main2();
if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return 0;
}
init();
physics_create_scene(sceneId);
SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
MSG msg;
while(s_isRunning) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if(msg.message==WM_QUIT) {
s_isRunning = false;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else {
update();
if(simulating) physics_simulate();
render();
perf_sync();
}
}
shutdown();
SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);
releaseWindow();
return (msg.wParam);
}
#endif

View File

@@ -0,0 +1,49 @@
/*
Physics Effects Copyright(C) 2011 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __PHYSICS_FUNC_H__
#define __PHYSICS_FUNC_H__
#define SCE_PFX_USE_PERFCOUNTER
#include "physics_effects.h"
using namespace sce::PhysicsEffects;
//E Simulation
//J シミュレーション
bool physics_init();
void physics_release();
void physics_create_scene(int sceneId);
void physics_simulate();
//E Picking
//J ピッキング
PfxVector3 physics_pick_start(const PfxVector3 &p1,const PfxVector3 &p2);
void physics_pick_update(const PfxVector3 &p);
void physics_pick_end();
//E Change parameters
//J パラメータの取得
int physics_get_num_rigidbodies();
const PfxRigidState& physics_get_state(int id);
const PfxRigidBody& physics_get_body(int id);
const PfxCollidable& physics_get_collidable(int id);
int physics_get_num_contacts();
const PfxContactManifold &physics_get_contact(int id);
#endif /* __PHYSICS_FUNC_H__ */

View File

@@ -0,0 +1,16 @@
SUBDIRS(
0_console
)
IF (WIN32)
SUBDIRS(
1_simple
2_stable
3_sleep
4_motion_type
5_raycast
6_joint
99_bullet_highlevel
# common
)
ENDIF()

View File

@@ -0,0 +1,164 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "1_simple.windows", "1_simple\1_simple.windows.vcproj", "{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}"
ProjectSection(ProjectDependencies) = postProject
{4908A1B7-06F4-4517-936A-D81D140004F7} = {4908A1B7-06F4-4517-936A-D81D140004F7}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "2_stable.windows", "2_stable\2_stable.winsows.vcproj", "{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}"
ProjectSection(ProjectDependencies) = postProject
{4908A1B7-06F4-4517-936A-D81D140004F7} = {4908A1B7-06F4-4517-936A-D81D140004F7}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3_sleep.windows", "3_sleep\3_sleep.windows.vcproj", "{97E051D8-9233-410D-8123-E5ED749D6640}"
ProjectSection(ProjectDependencies) = postProject
{4908A1B7-06F4-4517-936A-D81D140004F7} = {4908A1B7-06F4-4517-936A-D81D140004F7}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "4_motion_type.windows", "4_motion_type\4_motion_type.windows.vcproj", "{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}"
ProjectSection(ProjectDependencies) = postProject
{4908A1B7-06F4-4517-936A-D81D140004F7} = {4908A1B7-06F4-4517-936A-D81D140004F7}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "5_raycast.windows", "5_raycast\5_raycast.windows.vcproj", "{96B87A78-C8E3-43C5-B0E4-9A30999B2712}"
ProjectSection(ProjectDependencies) = postProject
{4908A1B7-06F4-4517-936A-D81D140004F7} = {4908A1B7-06F4-4517-936A-D81D140004F7}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "6_joint.windows", "6_joint\6_joint.windows.vcproj", "{A296A166-9E6A-44DE-BF58-30131687A117}"
ProjectSection(ProjectDependencies) = postProject
{4908A1B7-06F4-4517-936A-D81D140004F7} = {4908A1B7-06F4-4517-936A-D81D140004F7}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "physics_effects_lib.oss", "..\..\project\physics_effects_lib.oss.vcproj", "{4908A1B7-06F4-4517-936A-D81D140004F7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Win32 Debug|Win32 = Win32 Debug|Win32
Win32 Debug|x64 = Win32 Debug|x64
Win32 Release|Win32 = Win32 Release|Win32
Win32 Release|x64 = Win32 Release|x64
Win64 Debug|Win32 = Win64 Debug|Win32
Win64 Debug|x64 = Win64 Debug|x64
Win64 Release|Win32 = Win64 Release|Win32
Win64 Release|x64 = Win64 Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win32 Debug|Win32.ActiveCfg = Win32 Debug|Win32
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win32 Debug|Win32.Build.0 = Win32 Debug|Win32
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win32 Debug|x64.ActiveCfg = Win32 Debug|x64
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win32 Debug|x64.Build.0 = Win32 Debug|x64
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win32 Release|Win32.ActiveCfg = Win32 Release|Win32
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win32 Release|Win32.Build.0 = Win32 Release|Win32
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win32 Release|x64.ActiveCfg = Win32 Release|x64
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win32 Release|x64.Build.0 = Win32 Release|x64
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win64 Debug|Win32.ActiveCfg = Win64 Debug|x64
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win64 Debug|Win32.Build.0 = Win64 Debug|x64
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win64 Debug|x64.ActiveCfg = Win64 Debug|x64
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win64 Debug|x64.Build.0 = Win64 Debug|x64
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win64 Release|Win32.ActiveCfg = Win64 Release|x64
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win64 Release|Win32.Build.0 = Win64 Release|x64
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win64 Release|x64.ActiveCfg = Win64 Release|x64
{C74B57DB-C7EF-4718-8BD9-9F6AE6478FAC}.Win64 Release|x64.Build.0 = Win64 Release|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win32 Debug|Win32.ActiveCfg = Win32 Debug|Win32
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win32 Debug|Win32.Build.0 = Win32 Debug|Win32
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win32 Debug|x64.ActiveCfg = Win32 Debug|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win32 Debug|x64.Build.0 = Win32 Debug|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win32 Release|Win32.ActiveCfg = Win32 Release|Win32
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win32 Release|Win32.Build.0 = Win32 Release|Win32
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win32 Release|x64.ActiveCfg = Win32 Release|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win32 Release|x64.Build.0 = Win32 Release|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win64 Debug|Win32.ActiveCfg = Win64 Debug|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win64 Debug|Win32.Build.0 = Win64 Debug|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win64 Debug|x64.ActiveCfg = Win64 Debug|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win64 Debug|x64.Build.0 = Win64 Debug|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win64 Release|Win32.ActiveCfg = Win64 Release|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win64 Release|Win32.Build.0 = Win64 Release|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win64 Release|x64.ActiveCfg = Win64 Release|x64
{4CEE7D0E-6C26-4E94-9682-6ECB73091DF7}.Win64 Release|x64.Build.0 = Win64 Release|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win32 Debug|Win32.ActiveCfg = Win32 Debug|Win32
{97E051D8-9233-410D-8123-E5ED749D6640}.Win32 Debug|Win32.Build.0 = Win32 Debug|Win32
{97E051D8-9233-410D-8123-E5ED749D6640}.Win32 Debug|x64.ActiveCfg = Win32 Debug|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win32 Debug|x64.Build.0 = Win32 Debug|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win32 Release|Win32.ActiveCfg = Win32 Release|Win32
{97E051D8-9233-410D-8123-E5ED749D6640}.Win32 Release|Win32.Build.0 = Win32 Release|Win32
{97E051D8-9233-410D-8123-E5ED749D6640}.Win32 Release|x64.ActiveCfg = Win32 Release|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win32 Release|x64.Build.0 = Win32 Release|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win64 Debug|Win32.ActiveCfg = Win64 Debug|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win64 Debug|Win32.Build.0 = Win64 Debug|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win64 Debug|x64.ActiveCfg = Win64 Debug|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win64 Debug|x64.Build.0 = Win64 Debug|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win64 Release|Win32.ActiveCfg = Win64 Release|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win64 Release|Win32.Build.0 = Win64 Release|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win64 Release|x64.ActiveCfg = Win64 Release|x64
{97E051D8-9233-410D-8123-E5ED749D6640}.Win64 Release|x64.Build.0 = Win64 Release|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win32 Debug|Win32.ActiveCfg = Win32 Debug|Win32
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win32 Debug|Win32.Build.0 = Win32 Debug|Win32
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win32 Debug|x64.ActiveCfg = Win32 Debug|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win32 Debug|x64.Build.0 = Win32 Debug|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win32 Release|Win32.ActiveCfg = Win32 Release|Win32
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win32 Release|Win32.Build.0 = Win32 Release|Win32
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win32 Release|x64.ActiveCfg = Win32 Release|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win32 Release|x64.Build.0 = Win32 Release|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win64 Debug|Win32.ActiveCfg = Win64 Debug|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win64 Debug|Win32.Build.0 = Win64 Debug|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win64 Debug|x64.ActiveCfg = Win64 Debug|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win64 Debug|x64.Build.0 = Win64 Debug|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win64 Release|Win32.ActiveCfg = Win64 Release|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win64 Release|Win32.Build.0 = Win64 Release|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win64 Release|x64.ActiveCfg = Win64 Release|x64
{B4B4695B-055A-48F5-B9AC-A49F6BCAFCE2}.Win64 Release|x64.Build.0 = Win64 Release|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win32 Debug|Win32.ActiveCfg = Win32 Debug|Win32
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win32 Debug|Win32.Build.0 = Win32 Debug|Win32
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win32 Debug|x64.ActiveCfg = Win32 Debug|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win32 Debug|x64.Build.0 = Win32 Debug|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win32 Release|Win32.ActiveCfg = Win32 Release|Win32
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win32 Release|Win32.Build.0 = Win32 Release|Win32
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win32 Release|x64.ActiveCfg = Win32 Release|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win32 Release|x64.Build.0 = Win32 Release|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win64 Debug|Win32.ActiveCfg = Win64 Debug|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win64 Debug|Win32.Build.0 = Win64 Debug|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win64 Debug|x64.ActiveCfg = Win64 Debug|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win64 Debug|x64.Build.0 = Win64 Debug|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win64 Release|Win32.ActiveCfg = Win64 Release|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win64 Release|Win32.Build.0 = Win64 Release|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win64 Release|x64.ActiveCfg = Win64 Release|x64
{96B87A78-C8E3-43C5-B0E4-9A30999B2712}.Win64 Release|x64.Build.0 = Win64 Release|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win32 Debug|Win32.ActiveCfg = Win32 Debug|Win32
{A296A166-9E6A-44DE-BF58-30131687A117}.Win32 Debug|Win32.Build.0 = Win32 Debug|Win32
{A296A166-9E6A-44DE-BF58-30131687A117}.Win32 Debug|x64.ActiveCfg = Win32 Debug|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win32 Debug|x64.Build.0 = Win32 Debug|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win32 Release|Win32.ActiveCfg = Win32 Release|Win32
{A296A166-9E6A-44DE-BF58-30131687A117}.Win32 Release|Win32.Build.0 = Win32 Release|Win32
{A296A166-9E6A-44DE-BF58-30131687A117}.Win32 Release|x64.ActiveCfg = Win32 Release|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win32 Release|x64.Build.0 = Win32 Release|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win64 Debug|Win32.ActiveCfg = Win64 Debug|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win64 Debug|Win32.Build.0 = Win64 Debug|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win64 Debug|x64.ActiveCfg = Win64 Debug|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win64 Debug|x64.Build.0 = Win64 Debug|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win64 Release|Win32.ActiveCfg = Win64 Release|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win64 Release|Win32.Build.0 = Win64 Release|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win64 Release|x64.ActiveCfg = Win64 Release|x64
{A296A166-9E6A-44DE-BF58-30131687A117}.Win64 Release|x64.Build.0 = Win64 Release|x64
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win32 Debug|Win32.ActiveCfg = Win32 Debug|Win32
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win32 Debug|Win32.Build.0 = Win32 Debug|Win32
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win32 Debug|x64.ActiveCfg = Win32 Debug|x64
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win32 Debug|x64.Build.0 = Win32 Debug|x64
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win32 Release|Win32.ActiveCfg = Win32 Release|Win32
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win32 Release|Win32.Build.0 = Win32 Release|Win32
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win32 Release|x64.ActiveCfg = Win32 Release|x64
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win32 Release|x64.Build.0 = Win32 Release|x64
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win64 Debug|Win32.ActiveCfg = Win64 Debug|Win32
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win64 Debug|Win32.Build.0 = Win64 Debug|Win32
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win64 Debug|x64.ActiveCfg = Win64 Debug|x64
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win64 Debug|x64.Build.0 = Win64 Debug|x64
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win64 Release|Win32.ActiveCfg = Win64 Release|x64
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win64 Release|Win32.Build.0 = Win64 Release|x64
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win64 Release|x64.ActiveCfg = Win64 Release|x64
{4908A1B7-06F4-4517-936A-D81D140004F7}.Win64 Release|x64.Build.0 = Win64 Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,70 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define NUM_BOX_VTX 36
#define NUM_BOX_IDX 36
const float box_vtx[] = {
-0.500000f,-0.500000f,-0.500000f,0.000000f,0.000000f,-1.000000f,
-0.500000f,0.500000f,-0.500000f,0.000000f,0.000000f,-1.000000f,
0.500000f,0.500000f,-0.500000f,0.000000f,0.000000f,-1.000000f,
-0.500000f,-0.500000f,-0.500000f,0.000000f,0.000000f,-1.000000f,
0.500000f,0.500000f,-0.500000f,0.000000f,0.000000f,-1.000000f,
0.500000f,-0.500000f,-0.500000f,0.000000f,0.000000f,-1.000000f,
-0.500000f,-0.500000f,-0.500000f,0.000000f,-1.000000f,0.000000f,
0.500000f,-0.500000f,-0.500000f,0.000000f,-1.000000f,0.000000f,
0.500000f,-0.500000f,0.500000f,0.000000f,-1.000000f,0.000000f,
-0.500000f,-0.500000f,-0.500000f,0.000000f,-1.000000f,0.000000f,
0.500000f,-0.500000f,0.500000f,0.000000f,-1.000000f,0.000000f,
-0.500000f,-0.500000f,0.500000f,0.000000f,-1.000000f,0.000000f,
-0.500000f,-0.500000f,-0.500000f,-1.000000f,0.000000f,0.000000f,
-0.500000f,-0.500000f,0.500000f,-1.000000f,0.000000f,0.000000f,
-0.500000f,0.500000f,0.500000f,-1.000000f,0.000000f,0.000000f,
-0.500000f,-0.500000f,-0.500000f,-1.000000f,0.000000f,0.000000f,
-0.500000f,0.500000f,0.500000f,-1.000000f,0.000000f,0.000000f,
-0.500000f,0.500000f,-0.500000f,-1.000000f,0.000000f,0.000000f,
-0.500000f,-0.500000f,0.500000f,0.000000f,0.000000f,1.000000f,
0.500000f,-0.500000f,0.500000f,0.000000f,0.000000f,1.000000f,
0.500000f,0.500000f,0.500000f,0.000000f,0.000000f,1.000000f,
-0.500000f,-0.500000f,0.500000f,0.000000f,0.000000f,1.000000f,
0.500000f,0.500000f,0.500000f,0.000000f,0.000000f,1.000000f,
-0.500000f,0.500000f,0.500000f,0.000000f,0.000000f,1.000000f,
-0.500000f,0.500000f,-0.500000f,0.000000f,1.000000f,0.000000f,
-0.500000f,0.500000f,0.500000f,0.000000f,1.000000f,0.000000f,
0.500000f,0.500000f,0.500000f,0.000000f,1.000000f,0.000000f,
-0.500000f,0.500000f,-0.500000f,0.000000f,1.000000f,0.000000f,
0.500000f,0.500000f,0.500000f,0.000000f,1.000000f,0.000000f,
0.500000f,0.500000f,-0.500000f,0.000000f,1.000000f,0.000000f,
0.500000f,-0.500000f,-0.500000f,1.000000f,0.000000f,0.000000f,
0.500000f,0.500000f,-0.500000f,1.000000f,0.000000f,0.000000f,
0.500000f,0.500000f,0.500000f,1.000000f,0.000000f,0.000000f,
0.500000f,-0.500000f,-0.500000f,1.000000f,0.000000f,0.000000f,
0.500000f,0.500000f,0.500000f,1.000000f,0.000000f,0.000000f,
0.500000f,-0.500000f,0.500000f,1.000000f,0.000000f,0.000000f,
};
const unsigned short box_idx[] = {
0,1,2,
3,4,5,
6,7,8,
9,10,11,
12,13,14,
15,16,17,
18,19,20,
21,22,23,
24,25,26,
27,28,29,
30,31,32,
33,34,35,
};

View File

@@ -0,0 +1,31 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __COMMON_H__
#define __COMMON_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
// Platform specific
#ifdef _WIN32
#include <windows.h>
#endif
#endif /* __COMMON_H__ */

View File

@@ -0,0 +1,57 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "common.h"
#include "ctrl_func.h"
int keyState[2][BTN_NUM] = {0};
int keySw = 0;
void ctrl_init()
{
keySw = 0;
}
void ctrl_release()
{
}
void ctrl_update()
{
}
ButtonStatus ctrl_button_pressed(ButtonID btnId)
{
if(keyState[1-keySw][btnId] && !keyState[keySw][btnId]) {
return BTN_STAT_DOWN;
}
else if(keyState[1-keySw][btnId] && keyState[keySw][btnId]) {
return BTN_STAT_KEEP;
}
else if(!keyState[1-keySw][btnId] && keyState[keySw][btnId]) {
return BTN_STAT_UP;
}
return BTN_STAT_NONE;
}
void ctrl_set_screen_size(int w,int h)
{
}
void ctrl_get_cursor_position(int &cursorX,int &cursorY)
{
}

View File

@@ -0,0 +1,51 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __CTRL_FUNC_H__
#define __CTRL_FUNC_H__
enum ButtonID {
BTN_SCENE_RESET=0,
BTN_SCENE_NEXT,
BTN_SIMULATION,
BTN_STEP,
BTN_UP,
BTN_DOWN,
BTN_LEFT,
BTN_RIGHT,
BTN_ZOOM_IN,
BTN_ZOOM_OUT,
BTN_PICK,
BTN_NUM
};
enum ButtonStatus {
BTN_STAT_NONE = 0,
BTN_STAT_DOWN,
BTN_STAT_UP,
BTN_STAT_KEEP
};
void ctrl_init();
void ctrl_release();
void ctrl_update();
void ctrl_set_screen_size(int w,int h);
void ctrl_get_cursor_position(int &cursorX,int &cursorY);
ButtonStatus ctrl_button_pressed(ButtonID btnId);
#endif /* __CTRL_FUNC_H__ */

View File

@@ -0,0 +1,78 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "common.h"
#include "ctrl_func.h"
int keyState[2][BTN_NUM] = {0};
int keySw = 0;
void ctrl_init()
{
keySw = 0;
}
void ctrl_release()
{
}
void ctrl_update()
{
keyState[keySw][BTN_SCENE_RESET] = GetAsyncKeyState(VK_F1);
keyState[keySw][BTN_SCENE_NEXT] = GetAsyncKeyState(VK_F2);
keyState[keySw][BTN_SIMULATION] = GetAsyncKeyState(VK_F3);
keyState[keySw][BTN_STEP] = GetAsyncKeyState(VK_F4);
keyState[keySw][BTN_UP] = GetAsyncKeyState(VK_UP);
keyState[keySw][BTN_DOWN] = GetAsyncKeyState(VK_DOWN);
keyState[keySw][BTN_LEFT] = GetAsyncKeyState(VK_LEFT);
keyState[keySw][BTN_RIGHT] = GetAsyncKeyState(VK_RIGHT);
keyState[keySw][BTN_ZOOM_IN] = GetAsyncKeyState(VK_INSERT);
keyState[keySw][BTN_ZOOM_OUT] = GetAsyncKeyState(VK_DELETE);
keyState[keySw][BTN_PICK] = GetAsyncKeyState(VK_LBUTTON);
keySw = 1-keySw;
}
ButtonStatus ctrl_button_pressed(ButtonID btnId)
{
if(keyState[1-keySw][btnId] && !keyState[keySw][btnId]) {
return BTN_STAT_DOWN;
}
else if(keyState[1-keySw][btnId] && keyState[keySw][btnId]) {
return BTN_STAT_KEEP;
}
else if(!keyState[1-keySw][btnId] && keyState[keySw][btnId]) {
return BTN_STAT_UP;
}
return BTN_STAT_NONE;
}
void ctrl_set_screen_size(int w,int h)
{
}
void ctrl_get_cursor_position(int &cursorX,int &cursorY)
{
HWND hWnd = ::GetActiveWindow();
POINT pnt;
RECT rect;
::GetCursorPos(&pnt);
::ScreenToClient(hWnd,&pnt);
::GetClientRect(hWnd,&rect);
cursorX = pnt.x - (rect.right - rect.left) / 2;
cursorY = (rect.bottom-rect.top) / 2 - pnt.y;
}

View File

@@ -0,0 +1,154 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define NUM_CYLINDER_VTX 68
#define NUM_CYLINDER_IDX 192
const float cylinder_vtx[] = {
-1.0f,0.0f,0.0f, -1.0f,0.0f,0.0f,
-1.0f,-0.923879f,-0.382683f, -1.0f,0.0f,0.0f,
-1.0f,-1.0f,1.62921e-007f, -1.0f,0.0f,0.0f,
-1.0f,-0.707107f,-0.707107f, -1.0f,0.0f,0.0f,
-1.0f,-0.382683f,-0.923879f, -1.0f,0.0f,0.0f,
-1.0f,0.0f,-1.0f, -1.0f,0.0f,0.0f,
-1.0f,0.382684f,-0.923879f, -1.0f,0.0f,0.0f,
-1.0f,0.707107f,-0.707107f, -1.0f,0.0f,0.0f,
-1.0f,0.92388f,-0.382683f, -1.0f,0.0f,0.0f,
-1.0f,1.0f,-1.62921e-007f, -1.0f,0.0f,0.0f,
-1.0f,0.92388f,0.382683f, -1.0f,0.0f,0.0f,
-1.0f,0.707107f,0.707107f, -1.0f,0.0f,0.0f,
-1.0f,0.382684f,0.92388f, -1.0f,0.0f,0.0f,
-1.0f,1.50996e-007f,1.0f, -1.0f,0.0f,0.0f,
-1.0f,-0.382683f,0.92388f, -1.0f,0.0f,0.0f,
-1.0f,-0.707107f,0.707107f, -1.0f,0.0f,0.0f,
-1.0f,-0.92388f,0.382683f, -1.0f,0.0f,0.0f,
1.0f,0.0f,0.0f, 1.0f,0.0f,0.0f,
1.0f,-1.0f,0.0f, 1.0f,0.0f,0.0f,
1.0f,-0.92388f,-0.382683f, 1.0f,0.0f,0.0f,
1.0f,-0.707107f,-0.707107f, 1.0f,0.0f,0.0f,
1.0f,-0.382684f,-0.92388f, 1.0f,0.0f,0.0f,
1.0f,-1.19209e-007f,-1.0f, 1.0f,0.0f,0.0f,
1.0f,0.382683f,-0.92388f, 1.0f,0.0f,0.0f,
1.0f,0.707107f,-0.707107f, 1.0f,0.0f,0.0f,
1.0f,0.923879f,-0.382684f, 1.0f,0.0f,0.0f,
1.0f,1.0f,-3.13917e-007f, 1.0f,0.0f,0.0f,
1.0f,0.92388f,0.382683f, 1.0f,0.0f,0.0f,
1.0f,0.707107f,0.707106f, 1.0f,0.0f,0.0f,
1.0f,0.382684f,0.923879f, 1.0f,0.0f,0.0f,
1.0f,0.0f,1.0f, 1.0f,0.0f,0.0f,
1.0f,-0.382684f,0.923879f, 1.0f,0.0f,0.0f,
1.0f,-0.707107f,0.707107f, 1.0f,0.0f,0.0f,
1.0f,-0.92388f,0.382683f, 1.0f,0.0f,0.0f,
-1.0f,-1.0f,1.62921e-007f, 0.0f,-1.0f,0.0f,
1.0f,-0.92388f,-0.382683f, 0.0f,-0.92388f,-0.382683f,
1.0f,-1.0f,0.0f, 0.0f,-1.0f,0.0f,
-1.0f,-0.923879f,-0.382683f, 0.0f,-0.92388f,-0.382683f,
1.0f,-0.707107f,-0.707107f, 0.0f,-0.707107f,-0.707107f,
-1.0f,-0.707107f,-0.707107f, 0.0f,-0.707107f,-0.707107f,
1.0f,-0.382684f,-0.92388f, 0.0f,-0.382684f,-0.92388f,
-1.0f,-0.382683f,-0.923879f, 0.0f,-0.382683f,-0.92388f,
1.0f,-1.19209e-007f,-1.0f, 0.0f,0.0f,-1.0f,
-1.0f,0.0f,-1.0f, 0.0f,0.0f,-1.0f,
-1.0f,0.0f,-1.0f, 0.0f,0.0f,-1.0f,
1.0f,0.382683f,-0.92388f, 0.0f,0.382683f,-0.92388f,
1.0f,-1.19209e-007f,-1.0f, 0.0f,0.0f,-1.0f,
-1.0f,0.382684f,-0.923879f, 0.0f,0.382683f,-0.92388f,
1.0f,0.707107f,-0.707107f, 0.0f,0.707107f,-0.707107f,
-1.0f,0.707107f,-0.707107f, 0.0f,0.707107f,-0.707107f,
1.0f,0.923879f,-0.382684f, 0.0f,0.923879f,-0.382684f,
-1.0f,0.92388f,-0.382683f, 0.0f,0.923879f,-0.382684f,
1.0f,1.0f,-3.13917e-007f, 0.0f,1.0f,-2.03489e-007f,
-1.0f,1.0f,-1.62921e-007f, 0.0f,1.0f,-2.13162e-007f,
1.0f,0.92388f,0.382683f, 0.0f,0.92388f,0.382683f,
-1.0f,0.92388f,0.382683f, 0.0f,0.92388f,0.382683f,
1.0f,0.707107f,0.707106f, 0.0f,0.707107f,0.707107f,
-1.0f,0.707107f,0.707107f, 0.0f,0.707107f,0.707107f,
1.0f,0.382684f,0.923879f, 0.0f,0.382684f,0.923879f,
-1.0f,0.382684f,0.92388f, 0.0f,0.382684f,0.923879f,
1.0f,0.0f,1.0f, 0.0f,0.0f,1.0f,
-1.0f,1.50996e-007f,1.0f, 0.0f,0.0f,1.0f,
1.0f,-0.382684f,0.923879f, 0.0f,-0.382684f,0.92388f,
-1.0f,-0.382683f,0.92388f, 0.0f,-0.382683f,0.92388f,
1.0f,-0.707107f,0.707107f, 0.0f,-0.707107f,0.707107f,
-1.0f,-0.707107f,0.707107f, 0.0f,-0.707107f,0.707107f,
1.0f,-0.92388f,0.382683f, 0.0f,-0.92388f,0.382683f,
-1.0f,-0.92388f,0.382683f, 0.0f,-0.92388f,0.382683f,
};
const unsigned short cylinder_idx[] = {
0,1,2,
0,3,1,
0,4,3,
0,5,4,
0,6,5,
0,7,6,
0,8,7,
0,9,8,
0,10,9,
0,11,10,
0,12,11,
0,13,12,
0,14,13,
0,15,14,
0,16,15,
0,2,16,
17,18,19,
17,19,20,
17,20,21,
17,21,22,
17,22,23,
17,23,24,
17,24,25,
17,25,26,
17,26,27,
17,27,28,
17,28,29,
17,29,30,
17,30,31,
17,31,32,
17,32,33,
17,33,18,
34,35,36,
34,37,35,
37,38,35,
37,39,38,
39,40,38,
39,41,40,
41,42,40,
41,43,42,
44,45,46,
44,47,45,
47,48,45,
47,49,48,
49,50,48,
49,51,50,
51,52,50,
51,53,52,
53,54,52,
53,55,54,
55,56,54,
55,57,56,
57,58,56,
57,59,58,
59,60,58,
59,61,60,
61,62,60,
61,63,62,
63,64,62,
63,65,64,
65,66,64,
65,67,66,
67,36,66,
67,34,36,
};

View File

@@ -0,0 +1,241 @@
/*
Applied Research Associates Inc. (c)2011
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Applied Research Associates Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <jni.h>
#include "physicseffects-android.h"
#include "../render_func.h"
#include "../perf_func.h"
#ifdef __cplusplus
extern "C" {
#endif
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsInit
//
/// Implementation of JNI function to initilize the simulation and start the
/// first scene.
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsInit( JNIEnv* env )
{
init();
sceneChange();
}
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsSimulate
//
/// Implementation of JNI function to update the simulation and view parameters,
/// perform one simulation step, and redraw the scene.
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsSimulate( JNIEnv* env )
{
update();
physics_simulate();
render();
perf_sync();
}
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsUpdate
//
/// Implementation of JNI function to update the camera view and simulation
/// parameters.
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsUpdate( JNIEnv* env )
{
update();
}
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsPhysStep
//
/// Implementation of JNI function to perform one simulation step.
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsPhysStep( JNIEnv* env )
{
physics_simulate();
}
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsRender
//
/// Implementation of JNI function to render the scene.
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsRender( JNIEnv* env )
{
render();
}
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeSceneChange
//
/// Implementation of JNI function to change to the next scene.
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeSceneChange( JNIEnv* env )
{
sceneChange();
}
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraUp
//
/// Implementation of JNI function to tilt the camera up
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraUp( JNIEnv* env )
{
float angX, angY, r;
render_get_view_angle(angX, angY, r);
angX -= 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
render_set_view_angle(angX, angY, r);
}
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraDown
//
/// Implementation of JNI function to tilt the camera down
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraDown( JNIEnv* env )
{
float angX, angY, r;
render_get_view_angle(angX, angY, r);
angX += 0.05f;
if(angX < -1.4f) angX = -1.4f;
if(angX > -0.01f) angX = -0.01f;
render_set_view_angle(angX, angY, r);
}
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraLeft
//
/// Implementation of JNI function to tilt the camera left
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraLeft( JNIEnv* env )
{
float angX, angY, r;
render_get_view_angle(angX, angY, r);
angY -= 0.05f;
render_set_view_angle(angX, angY, r);
}
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraRight
//
/// Implementation of JNI function to tilt the camera right
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraRight( JNIEnv* env )
{
float angX, angY, r;
render_get_view_angle(angX, angY, r);
angY += 0.05f;
render_set_view_angle(angX, angY, r);
}
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraZoomOut
//
/// Implementation of JNI function to dolly the camera away from scene,
/// effectively zooming out.
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraZoomOut( JNIEnv* env )
{
float angX, angY, r;
render_get_view_angle(angX, angY, r);
r *= 1.1f;
if(r > 500.0f) r = 500.0f;
render_set_view_angle(angX, angY, r);
}
//----------------------------------------------------------------------------
// Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraZoomIn
//
/// Implementation of JNI function to dolly the camera towards scene,
/// effectively zooming in.
///
/// @param env Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsGLSurfaceView_nativeCameraZoomIn( JNIEnv* env )
{
float angX, angY, r;
render_get_view_angle(angX, angY, r);
r *= 0.9f;
if(r < 1.0f) r = 1.0f;
render_set_view_angle(angX, angY, r);
}
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,40 @@
/*
Applied Research Associates Inc. (c)2011
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Applied Research Associates Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PHYSICSEFFECTS_ANDROID_H
#define PHYSICSEFFECTS_ANDROID_H
// The following C++ functions must be provided by the
// sample application.
extern int init();
extern void render(void);
extern void sceneChange();
extern void update(void);
extern void physics_simulate();
#endif // !PHYSICSEFFECTS_ANDROID_H

View File

@@ -0,0 +1,38 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "common.h"
#include "perf_func.h"
void perf_init()
{
}
void perf_release()
{
}
void perf_push_marker(char *str)
{
}
void perf_pop_marker()
{
}
void perf_sync()
{
}

View File

@@ -0,0 +1,26 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __PERF_FUNC_H__
#define __PERF_FUNC_H__
void perf_init();
void perf_release();
void perf_push_marker(char *str);
void perf_pop_marker();
void perf_sync();
#endif /* __PERF_FUNC_H__ */

View File

@@ -0,0 +1,38 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "common.h"
#include "perf_func.h"
void perf_init()
{
}
void perf_release()
{
}
void perf_push_marker(char *str)
{
}
void perf_pop_marker()
{
}
void perf_sync()
{
}

View File

@@ -0,0 +1,486 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "render_func.h"
#include "box.h"
#include "sphere.h"
#include "cylinder.h"
#include <EGL/egl.h>
#include <GLES/gl.h>
// local variables
static int screen_width,screen_height;
static PfxMatrix4 g_pMat,g_vMat;
static PfxVector3 g_viewPos,g_lightPos,g_viewTgt;
static float lightRadius,lightRadX,lightRadY;
static float viewRadius,viewRadX,viewRadY,viewHeight;
static unsigned short *box_wire_idx;
static unsigned short *sphere_wire_idx;
static unsigned short *cylinder_wire_idx;
#define MAX_MESH 5
static struct MeshBuff {
float *vtx;
float *nml;
int numVtx;
unsigned short *idx;
unsigned short *wire_idx;
int numIdx;
} meshBuff[MAX_MESH];
int numMesh;
void render_init()
{
screen_width = DISPLAY_WIDTH;
screen_height = DISPLAY_HEIGHT;
// initalize matrix
g_pMat = PfxMatrix4::perspective(3.1415f/4.0f, (float)screen_width/(float)screen_height,0.1f, 1000.0f);
// initalize parameters
lightRadius = 40.0f;
lightRadX = -0.6f;
lightRadY = 0.6f;
viewRadius = 40.0f;
viewRadX = -0.01f;
viewRadY = 0.0f;
viewHeight = 1.0f;
g_viewTgt = PfxVector3(0.0f,viewHeight,0.0f);
box_wire_idx = new unsigned short [NUM_BOX_IDX*2];
sphere_wire_idx = new unsigned short [NUM_SPHERE_IDX*2];
cylinder_wire_idx = new unsigned short [NUM_CYLINDER_IDX*2];
for(int i=0;i<NUM_BOX_IDX/3;i++) {
box_wire_idx[i*6 ] = box_idx[i*3 ];
box_wire_idx[i*6+1] = box_idx[i*3+1];
box_wire_idx[i*6+2] = box_idx[i*3+1];
box_wire_idx[i*6+3] = box_idx[i*3+2];
box_wire_idx[i*6+4] = box_idx[i*3+2];
box_wire_idx[i*6+5] = box_idx[i*3 ];
}
for(int i=0;i<NUM_SPHERE_IDX/3;i++) {
sphere_wire_idx[i*6 ] = sphere_idx[i*3 ];
sphere_wire_idx[i*6+1] = sphere_idx[i*3+1];
sphere_wire_idx[i*6+2] = sphere_idx[i*3+1];
sphere_wire_idx[i*6+3] = sphere_idx[i*3+2];
sphere_wire_idx[i*6+4] = sphere_idx[i*3+2];
sphere_wire_idx[i*6+5] = sphere_idx[i*3 ];
}
for(int i=0;i<NUM_CYLINDER_IDX/3;i++) {
cylinder_wire_idx[i*6 ] = cylinder_idx[i*3 ];
cylinder_wire_idx[i*6+1] = cylinder_idx[i*3+1];
cylinder_wire_idx[i*6+2] = cylinder_idx[i*3+1];
cylinder_wire_idx[i*6+3] = cylinder_idx[i*3+2];
cylinder_wire_idx[i*6+4] = cylinder_idx[i*3+2];
cylinder_wire_idx[i*6+5] = cylinder_idx[i*3 ];
}
numMesh = 0;
}
void render_release()
{
delete [] box_wire_idx;
delete [] sphere_wire_idx;
delete [] cylinder_wire_idx;
if(numMesh > 0) {
for(int i=0;i<numMesh;i++) {
if(meshBuff[i].vtx) delete [] meshBuff[i].vtx;
if(meshBuff[i].nml) delete [] meshBuff[i].nml;
if(meshBuff[i].idx) delete [] meshBuff[i].idx;
if(meshBuff[i].wire_idx) delete [] meshBuff[i].wire_idx;
}
}
}
void render_begin()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFrontFace(GL_CCW);
glDepthFunc(GL_LESS);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMultMatrixf((GLfloat*)&g_pMat);
// create view matrix
g_viewPos =
PfxMatrix3::rotationY(viewRadY) *
PfxMatrix3::rotationX(viewRadX) *
PfxVector3(0,0,viewRadius);
g_lightPos =
PfxMatrix3::rotationY(lightRadY) *
PfxMatrix3::rotationX(lightRadX) *
PfxVector3(0,0,lightRadius);
PfxMatrix4 viewMtx = PfxMatrix4::lookAt(PfxPoint3(g_viewTgt + g_viewPos),PfxPoint3(g_viewTgt),PfxVector3(0,1,0));
g_vMat = g_pMat * viewMtx;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf((GLfloat*)&viewMtx);
}
void render_end()
{
}
void render_debug_begin()
{
glDepthMask(GL_FALSE);
}
void render_debug_end()
{
glDepthMask(GL_TRUE);
}
void render_get_view_angle(float &angleX,float &angleY,float &radius)
{
angleX = viewRadX;
angleY = viewRadY;
radius = viewRadius;
}
void render_set_view_angle(float angleX,float angleY,float radius)
{
viewRadX = angleX;
viewRadY = angleY;
viewRadius = radius;
}
void render_sphere(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxFloatInVec &radius)
{
PfxMatrix4 wMtx = PfxMatrix4(transform) * PfxMatrix4::scale(PfxVector3(radius));
glPushMatrix();
glMultMatrixf((GLfloat*)&wMtx);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,24,sphere_vtx);
glColor4f(color[0], color[1], color[2], 1.0);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f,1.0f);
glDrawElements(GL_TRIANGLES,NUM_SPHERE_IDX,GL_UNSIGNED_SHORT,sphere_idx);
glDisable(GL_POLYGON_OFFSET_FILL);
glColor4f(0.0f,0.0f,0.0f, 1.0);
glDrawElements(GL_LINES,NUM_SPHERE_IDX*2,GL_UNSIGNED_SHORT,sphere_wire_idx);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
void render_box(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxVector3 &halfExtent)
{
PfxMatrix4 wMtx = PfxMatrix4(transform) * PfxMatrix4::scale(2.0f*halfExtent);
glPushMatrix();
glMultMatrixf((GLfloat*)&wMtx);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,24,box_vtx);
glColor4f(color[0], color[1], color[2], 1.0);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f,1.0f);
glDrawElements(GL_TRIANGLES,NUM_BOX_IDX,GL_UNSIGNED_SHORT,box_idx);
glDisable(GL_POLYGON_OFFSET_FILL);
glColor4f(0.0f,0.0f,0.0f, 1.0);
glDrawElements(GL_LINES,NUM_BOX_IDX*2,GL_UNSIGNED_SHORT,box_wire_idx);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
void render_cylinder(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxFloatInVec &radius,
const PfxFloatInVec &halfLength)
{
PfxVector3 scale(halfLength,radius,radius);
PfxMatrix4 wMtx = PfxMatrix4(transform) * PfxMatrix4::scale(scale);
glPushMatrix();
glMultMatrixf((GLfloat*)&wMtx);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,24,cylinder_vtx);
glColor4f(color[0], color[1], color[2], 1.0);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f,1.0f);
glDrawElements(GL_TRIANGLES,NUM_CYLINDER_IDX,GL_UNSIGNED_SHORT,cylinder_idx);
glDisable(GL_POLYGON_OFFSET_FILL);
glColor4f(0.0f,0.0f,0.0f,1.0);
glDrawElements(GL_LINES,NUM_CYLINDER_IDX*2,GL_UNSIGNED_SHORT,cylinder_wire_idx);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
void render_capsule(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxFloatInVec &radius,
const PfxFloatInVec &halfLength)
{
PfxTransform3 tr1 = PfxTransform3::translation(PfxVector3(-halfLength,0.0f,0.0f));
PfxTransform3 tr2 = PfxTransform3::translation(PfxVector3(halfLength,0.0f,0.0f));
render_sphere(transform*tr1,color,radius);
render_sphere(transform*tr2,color,radius);
render_cylinder(transform,color,radius,halfLength);
}
int render_init_mesh(
const float *vtx,unsigned int vtxStrideBytes,
const float *nml,unsigned int nmlStrideBytes,
const unsigned short *tri,unsigned int triStrideBytes,
int numVtx,int numTri)
{
assert(numMesh<MAX_MESH);
MeshBuff &buff = meshBuff[numMesh++];
buff.vtx = new float [3*numVtx];
buff.nml = new float [3*numVtx];
buff.idx = new unsigned short [numTri*3];
buff.wire_idx = new unsigned short [numTri*6];
buff.numIdx = numTri*3;
buff.numVtx = numVtx;
for(int i=0;i<numVtx;i++) {
const float *v = (float*)((uintptr_t)vtx + vtxStrideBytes * i);
const float *n = (float*)((uintptr_t)nml + nmlStrideBytes * i);
buff.vtx[i*3 ] = v[0];
buff.vtx[i*3+1] = v[1];
buff.vtx[i*3+2] = v[2];
buff.nml[i*3 ] = n[0];
buff.nml[i*3+1] = n[1];
buff.nml[i*3+2] = n[2];
}
for(int i=0;i<numTri;i++) {
const unsigned short *idx = (unsigned short*)((uintptr_t)tri + triStrideBytes * i);
buff.idx[i*3 ] = idx[0];
buff.idx[i*3+1] = idx[1];
buff.idx[i*3+2] = idx[2];
buff.wire_idx[i*6 ] = buff.idx[i*3 ];
buff.wire_idx[i*6+1] = buff.idx[i*3+1];
buff.wire_idx[i*6+2] = buff.idx[i*3+1];
buff.wire_idx[i*6+3] = buff.idx[i*3+2];
buff.wire_idx[i*6+4] = buff.idx[i*3+2];
buff.wire_idx[i*6+5] = buff.idx[i*3 ];
}
return numMesh-1;
}
void render_mesh(
const PfxTransform3 &transform,
const PfxVector3 &color,
int meshId)
{
assert(meshId>=0&&meshId<MAX_MESH);
MeshBuff &buff = meshBuff[meshId];
PfxMatrix4 wMtx = PfxMatrix4(transform);
glPushMatrix();
glMultMatrixf((GLfloat*)&wMtx);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,buff.vtx);
glColor4f(color[0], color[1], color[2], 1.0);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f,1.0f);
glDrawElements(GL_TRIANGLES,buff.numIdx,GL_UNSIGNED_SHORT,buff.idx);
glDisable(GL_POLYGON_OFFSET_FILL);
glColor4f(0.0f,0.0f,0.0f,1.0);
glDrawElements(GL_LINES,buff.numIdx*2,GL_UNSIGNED_SHORT,buff.wire_idx);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
void render_resize(int width,int height)
{
glViewport(0,0,width,height);
g_pMat = PfxMatrix4::perspective(3.1415f/4.0f, (float)width/(float)height,0.1f, 1000.0f);
screen_width = width;
screen_height = height;
}
void render_debug_point(
const PfxVector3 &position,
const PfxVector3 &color)
{
glColor4f(color[0], color[1], color[2], 1.0);
glPointSize(5.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,16,(float*)&position);
glDrawArrays(GL_POINTS,0,1);
glDisableClientState(GL_VERTEX_ARRAY);
glPointSize(1.0f);
}
void render_debug_line(
const PfxVector3 &position1,
const PfxVector3 &position2,
const PfxVector3 &color)
{
glColor4f(color[0], color[1], color[2], 1.0);
const PfxVector3 points[2] = {
position1,
position2,
};
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,16,(float*)points);
glDrawArrays(GL_LINES,0,2);
glDisableClientState(GL_VERTEX_ARRAY);
}
void render_debug_box(
const PfxVector3 &center,
const PfxVector3 &extent,
const PfxVector3 &color)
{
const PfxVector3 points[8] = {
center + mulPerElem(PfxVector3(-1,-1,-1),extent),
center + mulPerElem(PfxVector3(-1,-1, 1),extent),
center + mulPerElem(PfxVector3( 1,-1, 1),extent),
center + mulPerElem(PfxVector3( 1,-1,-1),extent),
center + mulPerElem(PfxVector3(-1, 1,-1),extent),
center + mulPerElem(PfxVector3(-1, 1, 1),extent),
center + mulPerElem(PfxVector3( 1, 1, 1),extent),
center + mulPerElem(PfxVector3( 1, 1,-1),extent),
};
const unsigned short indices[] = {
0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7,
};
glColor4f(color[0], color[1], color[2], 1.0);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,16,(float*)points);
glDrawElements(GL_LINES,24,GL_UNSIGNED_SHORT,indices);
glDisableClientState(GL_VERTEX_ARRAY);
}
PfxVector3 render_get_world_position(const PfxVector3 &screenPos)
{
PfxMatrix4 mvp,mvpInv;
mvp = g_vMat;
mvpInv = inverse(mvp);
PfxVector4 wp(screenPos,1.0f);
wp[0] /= (0.5f * (float)screen_width);
wp[1] /= (0.5f * (float)screen_height);
float w = mvpInv[0][3] * wp[0] +
mvpInv[1][3] * wp[1] +
mvpInv[2][3] * wp[2] +
mvpInv[3][3];
wp = mvpInv * wp;
wp /= w;
return wp.getXYZ();
}
PfxVector3 render_get_screen_position(const PfxVector3 &worldPos)
{
PfxVector4 sp(worldPos,1.0f);
PfxMatrix4 mvp;
mvp = g_vMat;
sp = mvp * sp;
sp /= sp[3];
sp[0] *= (0.5f * (float)screen_width);
sp[1] *= (0.5f * (float)screen_height);
return sp.getXYZ();
}
void render_get_screent_size(int &width,int &height)
{
width = screen_width;
height = screen_height;
}
void render_get_view_target(PfxVector3 &targetPos)
{
targetPos = g_viewTgt;
}
void render_set_view_target(const PfxVector3 &targetPos)
{
g_viewTgt = targetPos;
}
void render_get_view_radius(float &radius)
{
radius = viewRadius;
}
void render_set_view_radius(float radius)
{
viewRadius = radius;
}

View File

@@ -0,0 +1,106 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef __RENDER_FUNC_H__
#define __RENDER_FUNC_H__
#include "common.h"
#include "physics_effects.h"
using namespace sce::PhysicsEffects;
#define DISPLAY_WIDTH 640
#define DISPLAY_HEIGHT 480
///////////////////////////////////////////////////////////////////////////////
// Draw Primitives
void render_init();
void render_release();
void render_begin();
void render_end();
void render_sphere(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxFloatInVec &radius);
void render_box(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxVector3 &halfExtent);
void render_cylinder(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxFloatInVec &radius,
const PfxFloatInVec &halfLength);
void render_capsule(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxFloatInVec &radius,
const PfxFloatInVec &halfLength);
int render_init_mesh(
const float *vtx,unsigned int vtxStrideBytes,
const float *nml,unsigned int nmlStrideBytes,
const unsigned short *tri,unsigned int triStrideBytes,
int numVtx,int numTri);
void render_mesh(
const PfxTransform3 &transform,
const PfxVector3 &color,
int meshId);
///////////////////////////////////////////////////////////////////////////////
// Debug Drawing
void render_debug_begin();
void render_debug_end();
void render_debug_point(
const PfxVector3 &position,
const PfxVector3 &color);
void render_debug_line(
const PfxVector3 &position1,
const PfxVector3 &position2,
const PfxVector3 &color);
void render_debug_box(
const PfxVector3 &center,
const PfxVector3 &extent,
const PfxVector3 &color);
///////////////////////////////////////////////////////////////////////////////
// Render Parameter
void render_get_view_angle(float &angleX,float &angleY,float &radius);
void render_set_view_angle(float angleX,float angleY,float radius);
void render_resize(int width,int height);
void render_get_view_target(PfxVector3 &targetPos);
void render_set_view_target(const PfxVector3 &targetPos);
void render_get_view_radius(float &radius);
void render_set_view_radius(float radius);
void render_get_screent_size(int &width,int &height);
PfxVector3 render_get_world_position(const PfxVector3 &screenPos);
PfxVector3 render_get_screen_position(const PfxVector3 &worldPos);
#endif /* __RENDER_FUNC_H__ */

View File

@@ -0,0 +1,491 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#include "render_func.h"
#include <gl/gl.h>
#include "box.h"
#include "sphere.h"
#include "cylinder.h"
// context
HDC hDC;
HGLRC hRC;
// local variables
static int screen_width,screen_height;
static PfxMatrix4 g_pMat,g_vMat;
static PfxVector3 g_viewPos,g_lightPos,g_viewTgt;
static float lightRadius,lightRadX,lightRadY;
static float viewRadius,viewRadX,viewRadY,viewHeight;
static unsigned short *box_wire_idx;
static unsigned short *sphere_wire_idx;
static unsigned short *cylinder_wire_idx;
#define MAX_MESH 5
static struct MeshBuff {
float *vtx;
float *nml;
int numVtx;
unsigned short *idx;
unsigned short *wire_idx;
int numIdx;
} meshBuff[MAX_MESH];
int numMesh;
void render_init()
{
screen_width = DISPLAY_WIDTH;
screen_height = DISPLAY_HEIGHT;
// initalize matrix
g_pMat = PfxMatrix4::perspective(3.1415f/4.0f, (float)screen_width/(float)screen_height,0.1f, 1000.0f);
// initalize parameters
lightRadius = 40.0f;
lightRadX = -0.6f;
lightRadY = 0.6f;
viewRadius = 40.0f;
viewRadX = -0.01f;
viewRadY = 0.0f;
viewHeight = 1.0f;
g_viewTgt = PfxVector3(0.0f,viewHeight,0.0f);
box_wire_idx = new unsigned short [NUM_BOX_IDX*2];
sphere_wire_idx = new unsigned short [NUM_SPHERE_IDX*2];
cylinder_wire_idx = new unsigned short [NUM_CYLINDER_IDX*2];
for(int i=0;i<NUM_BOX_IDX/3;i++) {
box_wire_idx[i*6 ] = box_idx[i*3 ];
box_wire_idx[i*6+1] = box_idx[i*3+1];
box_wire_idx[i*6+2] = box_idx[i*3+1];
box_wire_idx[i*6+3] = box_idx[i*3+2];
box_wire_idx[i*6+4] = box_idx[i*3+2];
box_wire_idx[i*6+5] = box_idx[i*3 ];
}
for(int i=0;i<NUM_SPHERE_IDX/3;i++) {
sphere_wire_idx[i*6 ] = sphere_idx[i*3 ];
sphere_wire_idx[i*6+1] = sphere_idx[i*3+1];
sphere_wire_idx[i*6+2] = sphere_idx[i*3+1];
sphere_wire_idx[i*6+3] = sphere_idx[i*3+2];
sphere_wire_idx[i*6+4] = sphere_idx[i*3+2];
sphere_wire_idx[i*6+5] = sphere_idx[i*3 ];
}
for(int i=0;i<NUM_CYLINDER_IDX/3;i++) {
cylinder_wire_idx[i*6 ] = cylinder_idx[i*3 ];
cylinder_wire_idx[i*6+1] = cylinder_idx[i*3+1];
cylinder_wire_idx[i*6+2] = cylinder_idx[i*3+1];
cylinder_wire_idx[i*6+3] = cylinder_idx[i*3+2];
cylinder_wire_idx[i*6+4] = cylinder_idx[i*3+2];
cylinder_wire_idx[i*6+5] = cylinder_idx[i*3 ];
}
numMesh = 0;
}
void render_release()
{
delete [] box_wire_idx;
delete [] sphere_wire_idx;
delete [] cylinder_wire_idx;
if(numMesh > 0) {
for(int i=0;i<numMesh;i++) {
if(meshBuff[i].vtx) delete [] meshBuff[i].vtx;
if(meshBuff[i].nml) delete [] meshBuff[i].nml;
if(meshBuff[i].idx) delete [] meshBuff[i].idx;
if(meshBuff[i].wire_idx) delete [] meshBuff[i].wire_idx;
}
}
}
void render_begin()
{
wglMakeCurrent(hDC, hRC);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFrontFace(GL_CCW);
glDepthFunc(GL_LESS);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMultMatrixf((GLfloat*)&g_pMat);
// create view matrix
g_viewPos =
PfxMatrix3::rotationY(viewRadY) *
PfxMatrix3::rotationX(viewRadX) *
PfxVector3(0,0,viewRadius);
g_lightPos =
PfxMatrix3::rotationY(lightRadY) *
PfxMatrix3::rotationX(lightRadX) *
PfxVector3(0,0,lightRadius);
PfxMatrix4 viewMtx = PfxMatrix4::lookAt(PfxPoint3(g_viewTgt + g_viewPos),PfxPoint3(g_viewTgt),PfxVector3(0,1,0));
g_vMat = g_pMat * viewMtx;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf((GLfloat*)&viewMtx);
}
void render_end()
{
SwapBuffers(hDC);
}
void render_debug_begin()
{
glDepthMask(GL_FALSE);
}
void render_debug_end()
{
glDepthMask(GL_TRUE);
}
void render_get_view_angle(float &angleX,float &angleY,float &radius)
{
angleX = viewRadX;
angleY = viewRadY;
radius = viewRadius;
}
void render_set_view_angle(float angleX,float angleY,float radius)
{
viewRadX = angleX;
viewRadY = angleY;
viewRadius = radius;
}
void render_sphere(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxFloatInVec &radius)
{
PfxMatrix4 wMtx = PfxMatrix4(transform) * PfxMatrix4::scale(PfxVector3(radius));
glPushMatrix();
glMultMatrixf((GLfloat*)&wMtx);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,24,sphere_vtx);
glColor3fv((float*)&color);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f,1.0f);
glDrawElements(GL_TRIANGLES,NUM_SPHERE_IDX,GL_UNSIGNED_SHORT,sphere_idx);
glDisable(GL_POLYGON_OFFSET_FILL);
glColor3f(0.0f,0.0f,0.0f);
glDrawElements(GL_LINES,NUM_SPHERE_IDX*2,GL_UNSIGNED_SHORT,sphere_wire_idx);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
void render_box(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxVector3 &halfExtent)
{
PfxMatrix4 wMtx = PfxMatrix4(transform) * PfxMatrix4::scale(2.0f*halfExtent);
glPushMatrix();
glMultMatrixf((GLfloat*)&wMtx);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,24,box_vtx);
glColor3fv((float*)&color);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f,1.0f);
glDrawElements(GL_TRIANGLES,NUM_BOX_IDX,GL_UNSIGNED_SHORT,box_idx);
glDisable(GL_POLYGON_OFFSET_FILL);
glColor3f(0.0f,0.0f,0.0f);
glDrawElements(GL_LINES,NUM_BOX_IDX*2,GL_UNSIGNED_SHORT,box_wire_idx);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
void render_cylinder(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxFloatInVec &radius,
const PfxFloatInVec &halfLength)
{
PfxVector3 scale(halfLength,radius,radius);
PfxMatrix4 wMtx = PfxMatrix4(transform) * PfxMatrix4::scale(scale);
glPushMatrix();
glMultMatrixf((GLfloat*)&wMtx);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,24,cylinder_vtx);
glColor3fv((float*)&color);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f,1.0f);
glDrawElements(GL_TRIANGLES,NUM_CYLINDER_IDX,GL_UNSIGNED_SHORT,cylinder_idx);
glDisable(GL_POLYGON_OFFSET_FILL);
glColor3f(0.0f,0.0f,0.0f);
glDrawElements(GL_LINES,NUM_CYLINDER_IDX*2,GL_UNSIGNED_SHORT,cylinder_wire_idx);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
void render_capsule(
const PfxTransform3 &transform,
const PfxVector3 &color,
const PfxFloatInVec &radius,
const PfxFloatInVec &halfLength)
{
PfxTransform3 tr1 = PfxTransform3::translation(PfxVector3(-halfLength,0.0f,0.0f));
PfxTransform3 tr2 = PfxTransform3::translation(PfxVector3(halfLength,0.0f,0.0f));
render_sphere(transform*tr1,color,radius);
render_sphere(transform*tr2,color,radius);
render_cylinder(transform,color,radius,halfLength);
}
int render_init_mesh(
const float *vtx,unsigned int vtxStrideBytes,
const float *nml,unsigned int nmlStrideBytes,
const unsigned short *tri,unsigned int triStrideBytes,
int numVtx,int numTri)
{
assert(numMesh<MAX_MESH);
MeshBuff &buff = meshBuff[numMesh++];
buff.vtx = new float [3*numVtx];
buff.nml = new float [3*numVtx];
buff.idx = new unsigned short [numTri*3];
buff.wire_idx = new unsigned short [numTri*6];
buff.numIdx = numTri*3;
buff.numVtx = numVtx;
for(int i=0;i<numVtx;i++) {
const float *v = (float*)((uintptr_t)vtx + vtxStrideBytes * i);
const float *n = (float*)((uintptr_t)nml + nmlStrideBytes * i);
buff.vtx[i*3 ] = v[0];
buff.vtx[i*3+1] = v[1];
buff.vtx[i*3+2] = v[2];
buff.nml[i*3 ] = n[0];
buff.nml[i*3+1] = n[1];
buff.nml[i*3+2] = n[2];
}
for(int i=0;i<numTri;i++) {
const unsigned short *idx = (unsigned short*)((uintptr_t)tri + triStrideBytes * i);
buff.idx[i*3 ] = idx[0];
buff.idx[i*3+1] = idx[1];
buff.idx[i*3+2] = idx[2];
buff.wire_idx[i*6 ] = buff.idx[i*3 ];
buff.wire_idx[i*6+1] = buff.idx[i*3+1];
buff.wire_idx[i*6+2] = buff.idx[i*3+1];
buff.wire_idx[i*6+3] = buff.idx[i*3+2];
buff.wire_idx[i*6+4] = buff.idx[i*3+2];
buff.wire_idx[i*6+5] = buff.idx[i*3 ];
}
return numMesh-1;
}
void render_mesh(
const PfxTransform3 &transform,
const PfxVector3 &color,
int meshId)
{
assert(meshId>=0&&meshId<MAX_MESH);
MeshBuff &buff = meshBuff[meshId];
PfxMatrix4 wMtx = PfxMatrix4(transform);
glPushMatrix();
glMultMatrixf((GLfloat*)&wMtx);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,buff.vtx);
glColor3fv((float*)&color);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f,1.0f);
glDrawElements(GL_TRIANGLES,buff.numIdx,GL_UNSIGNED_SHORT,buff.idx);
glDisable(GL_POLYGON_OFFSET_FILL);
glColor3f(0.0f,0.0f,0.0f);
glDrawElements(GL_LINES,buff.numIdx*2,GL_UNSIGNED_SHORT,buff.wire_idx);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
void render_resize(int width,int height)
{
glViewport(0,0,width,height);
g_pMat = PfxMatrix4::perspective(3.1415f/4.0f, (float)width/(float)height,0.1f, 1000.0f);
screen_width = width;
screen_height = height;
}
void render_debug_point(
const PfxVector3 &position,
const PfxVector3 &color)
{
glColor4fv((float*)&color);
glPointSize(5.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,16,(float*)&position);
glDrawArrays(GL_POINTS,0,1);
glDisableClientState(GL_VERTEX_ARRAY);
glPointSize(1.0f);
}
void render_debug_line(
const PfxVector3 &position1,
const PfxVector3 &position2,
const PfxVector3 &color)
{
glColor4fv((float*)&color);
const PfxVector3 points[2] = {
position1,
position2,
};
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,16,(float*)points);
glDrawArrays(GL_LINES,0,2);
glDisableClientState(GL_VERTEX_ARRAY);
}
void render_debug_box(
const PfxVector3 &center,
const PfxVector3 &extent,
const PfxVector3 &color)
{
const PfxVector3 points[8] = {
center + mulPerElem(PfxVector3(-1,-1,-1),extent),
center + mulPerElem(PfxVector3(-1,-1, 1),extent),
center + mulPerElem(PfxVector3( 1,-1, 1),extent),
center + mulPerElem(PfxVector3( 1,-1,-1),extent),
center + mulPerElem(PfxVector3(-1, 1,-1),extent),
center + mulPerElem(PfxVector3(-1, 1, 1),extent),
center + mulPerElem(PfxVector3( 1, 1, 1),extent),
center + mulPerElem(PfxVector3( 1, 1,-1),extent),
};
const unsigned short indices[] = {
0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7,
};
glColor4fv((float*)&color);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,16,(float*)points);
glDrawElements(GL_LINES,24,GL_UNSIGNED_SHORT,indices);
glDisableClientState(GL_VERTEX_ARRAY);
}
PfxVector3 render_get_world_position(const PfxVector3 &screenPos)
{
PfxMatrix4 mvp,mvpInv;
mvp = g_vMat;
mvpInv = inverse(mvp);
PfxVector4 wp(screenPos,1.0f);
wp[0] /= (0.5f * (float)screen_width);
wp[1] /= (0.5f * (float)screen_height);
float w = mvpInv[0][3] * wp[0] +
mvpInv[1][3] * wp[1] +
mvpInv[2][3] * wp[2] +
mvpInv[3][3];
wp = mvpInv * wp;
wp /= w;
return wp.getXYZ();
}
PfxVector3 render_get_screen_position(const PfxVector3 &worldPos)
{
PfxVector4 sp(worldPos,1.0f);
PfxMatrix4 mvp;
mvp = g_vMat;
sp = mvp * sp;
sp /= sp[3];
sp[0] *= (0.5f * (float)screen_width);
sp[1] *= (0.5f * (float)screen_height);
return sp.getXYZ();
}
void render_get_screent_size(int &width,int &height)
{
width = screen_width;
height = screen_height;
}
void render_get_view_target(PfxVector3 &targetPos)
{
targetPos = g_viewTgt;
}
void render_set_view_target(const PfxVector3 &targetPos)
{
g_viewTgt = targetPos;
}
void render_get_view_radius(float &radius)
{
radius = viewRadius;
}
void render_set_view_radius(float radius)
{
viewRadius = radius;
}

View File

@@ -0,0 +1,209 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#define NUM_SPHERE_VTX 67
#define NUM_SPHERE_IDX 360
const float sphere_vtx[] = {
0.000000f,-1.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.500000f,-0.866025f,0.000000f,0.500000f,-0.866025f,0.000000f,
0.433013f,-0.866025f,0.250000f,0.433013f,-0.866025f,0.250000f,
0.250000f,-0.866025f,0.433013f,0.250000f,-0.866025f,0.433013f,
-0.000000f,-0.866025f,0.500000f,-0.000000f,-0.866025f,0.500000f,
-0.250000f,-0.866025f,0.433013f,-0.250000f,-0.866025f,0.433013f,
-0.433013f,-0.866025f,0.250000f,-0.433013f,-0.866025f,0.250000f,
-0.500000f,-0.866025f,-0.000000f,-0.500000f,-0.866025f,-0.000000f,
-0.433013f,-0.866025f,-0.250000f,-0.433013f,-0.866025f,-0.250000f,
-0.250000f,-0.866025f,-0.433013f,-0.250000f,-0.866025f,-0.433013f,
0.000000f,-0.866025f,-0.500000f,0.000000f,-0.866025f,-0.500000f,
0.250000f,-0.866025f,-0.433013f,0.250000f,-0.866025f,-0.433013f,
0.433013f,-0.866025f,-0.250000f,0.433013f,-0.866025f,-0.250000f,
0.500000f,-0.866025f,0.000000f,0.500000f,-0.866025f,0.000000f,
0.866025f,-0.500000f,0.000000f,0.866025f,-0.500000f,0.000000f,
0.750000f,-0.500000f,0.433013f,0.750000f,-0.500000f,0.433013f,
0.433013f,-0.500000f,0.750000f,0.433013f,-0.500000f,0.750000f,
-0.000000f,-0.500000f,0.866025f,-0.000000f,-0.500000f,0.866025f,
-0.433013f,-0.500000f,0.750000f,-0.433013f,-0.500000f,0.750000f,
-0.750000f,-0.500000f,0.433013f,-0.750000f,-0.500000f,0.433013f,
-0.866025f,-0.500000f,-0.000000f,-0.866025f,-0.500000f,-0.000000f,
-0.750000f,-0.500000f,-0.433013f,-0.750000f,-0.500000f,-0.433013f,
-0.433013f,-0.500000f,-0.750000f,-0.433013f,-0.500000f,-0.750000f,
0.000000f,-0.500000f,-0.866025f,0.000000f,-0.500000f,-0.866025f,
0.433013f,-0.500000f,-0.750000f,0.433013f,-0.500000f,-0.750000f,
0.750000f,-0.500000f,-0.433012f,0.750000f,-0.500000f,-0.433012f,
0.866025f,-0.500000f,0.000000f,0.866025f,-0.500000f,0.000000f,
1.000000f,0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,
0.866025f,0.000000f,0.500000f,0.866025f,0.000000f,0.500000f,
0.500000f,0.000000f,0.866025f,0.500000f,0.000000f,0.866025f,
-0.000000f,0.000000f,1.000000f,-0.000000f,0.000000f,1.000000f,
-0.500000f,0.000000f,0.866025f,-0.500000f,0.000000f,0.866025f,
-0.866025f,0.000000f,0.500000f,-0.866025f,0.000000f,0.500000f,
-1.000000f,0.000000f,-0.000000f,-1.000000f,0.000000f,-0.000000f,
-0.866025f,0.000000f,-0.500000f,-0.866025f,0.000000f,-0.500000f,
-0.500000f,0.000000f,-0.866025f,-0.500000f,0.000000f,-0.866025f,
0.000000f,0.000000f,-1.000000f,0.000000f,0.000000f,-1.000000f,
0.500000f,0.000000f,-0.866025f,0.500000f,0.000000f,-0.866025f,
0.866026f,0.000000f,-0.500000f,0.866026f,0.000000f,-0.500000f,
1.000000f,0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,
0.866025f,0.500000f,0.000000f,0.866025f,0.500000f,0.000000f,
0.750000f,0.500000f,0.433013f,0.750000f,0.500000f,0.433013f,
0.433013f,0.500000f,0.750000f,0.433013f,0.500000f,0.750000f,
-0.000000f,0.500000f,0.866025f,-0.000000f,0.500000f,0.866025f,
-0.433013f,0.500000f,0.750000f,-0.433013f,0.500000f,0.750000f,
-0.750000f,0.500000f,0.433013f,-0.750000f,0.500000f,0.433013f,
-0.866025f,0.500000f,-0.000000f,-0.866025f,0.500000f,-0.000000f,
-0.750000f,0.500000f,-0.433013f,-0.750000f,0.500000f,-0.433013f,
-0.433013f,0.500000f,-0.750000f,-0.433013f,0.500000f,-0.750000f,
0.000000f,0.500000f,-0.866025f,0.000000f,0.500000f,-0.866025f,
0.433013f,0.500000f,-0.750000f,0.433013f,0.500000f,-0.750000f,
0.750000f,0.500000f,-0.433012f,0.750000f,0.500000f,-0.433012f,
0.866025f,0.500000f,0.000000f,0.866025f,0.500000f,0.000000f,
0.500000f,0.866025f,0.000000f,0.500000f,0.866025f,0.000000f,
0.433013f,0.866025f,0.250000f,0.433013f,0.866025f,0.250000f,
0.250000f,0.866025f,0.433013f,0.250000f,0.866025f,0.433013f,
-0.000000f,0.866025f,0.500000f,-0.000000f,0.866025f,0.500000f,
-0.250000f,0.866025f,0.433013f,-0.250000f,0.866025f,0.433013f,
-0.433013f,0.866025f,0.250000f,-0.433013f,0.866025f,0.250000f,
-0.500000f,0.866025f,-0.000000f,-0.500000f,0.866025f,-0.000000f,
-0.433013f,0.866025f,-0.250000f,-0.433013f,0.866025f,-0.250000f,
-0.250000f,0.866025f,-0.433013f,-0.250000f,0.866025f,-0.433013f,
0.000000f,0.866025f,-0.500000f,0.000000f,0.866025f,-0.500000f,
0.250000f,0.866025f,-0.433013f,0.250000f,0.866025f,-0.433013f,
0.433013f,0.866025f,-0.250000f,0.433013f,0.866025f,-0.250000f,
0.500000f,0.866025f,0.000000f,0.500000f,0.866025f,0.000000f,
0.000000f,1.000000f,0.000000f,0.000000f,1.000000f,0.000000f,
};
const unsigned short sphere_idx[] = {
0,1,2,
0,2,3,
0,3,4,
0,4,5,
0,5,6,
0,6,7,
0,7,8,
0,8,9,
0,9,10,
0,10,11,
0,11,12,
0,12,13,
1,14,15,
15,2,1,
2,15,16,
16,3,2,
3,16,17,
17,4,3,
4,17,18,
18,5,4,
5,18,19,
19,6,5,
6,19,20,
20,7,6,
7,20,21,
21,8,7,
8,21,22,
22,9,8,
9,22,23,
23,10,9,
10,23,24,
24,11,10,
11,24,25,
25,12,11,
12,25,26,
26,13,12,
14,27,28,
28,15,14,
15,28,29,
29,16,15,
16,29,30,
30,17,16,
17,30,31,
31,18,17,
18,31,32,
32,19,18,
19,32,33,
33,20,19,
20,33,34,
34,21,20,
21,34,35,
35,22,21,
22,35,36,
36,23,22,
23,36,37,
37,24,23,
24,37,38,
38,25,24,
25,38,39,
39,26,25,
27,40,41,
41,28,27,
28,41,42,
42,29,28,
29,42,43,
43,30,29,
30,43,44,
44,31,30,
31,44,45,
45,32,31,
32,45,46,
46,33,32,
33,46,47,
47,34,33,
34,47,48,
48,35,34,
35,48,49,
49,36,35,
36,49,50,
50,37,36,
37,50,51,
51,38,37,
38,51,52,
52,39,38,
40,53,54,
54,41,40,
41,54,55,
55,42,41,
42,55,56,
56,43,42,
43,56,57,
57,44,43,
44,57,58,
58,45,44,
45,58,59,
59,46,45,
46,59,60,
60,47,46,
47,60,61,
61,48,47,
48,61,62,
62,49,48,
49,62,63,
63,50,49,
50,63,64,
64,51,50,
51,64,65,
65,52,51,
54,53,66,
55,54,66,
56,55,66,
57,56,66,
58,57,66,
59,58,66,
60,59,66,
61,60,66,
62,61,66,
63,62,66,
64,63,66,
65,64,66,
};