2 Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
\r
5 Physics Effects is open software; you can redistribute it and/or
\r
6 modify it under the terms of the BSD License.
\r
8 Physics Effects is distributed in the hope that it will be useful,
\r
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\r
11 See the BSD License for more details.
\r
13 A copy of the BSD License is distributed with
\r
14 Physics Effects under the filename: physics_effects_license.txt
\r
17 #include "../common/common.h"
\r
18 #include "../common/ctrl_func.h"
\r
19 #include "../common/render_func.h"
\r
20 #include "../common/perf_func.h"
\r
21 #include "physics_func.h"
\r
23 #include "landscape.h"
\r
30 // ARA begin insert new code
\r
32 #include <EGL/egl.h>
\r
33 #include <GLES/gl.h>
\r
37 #define SAMPLE_NAME "api_physics_effects/2_stable"
\r
39 static bool s_isRunning = true;
\r
42 bool simulating = false;
\r
44 int landscapeMeshId;
\r
51 for(int i=0;i<physics_get_num_rigidbodies();i++) {
\r
52 const PfxRigidState &state = physics_get_state(i);
\r
53 const PfxCollidable &coll = physics_get_collidable(i);
\r
55 PfxTransform3 rbT(state.getOrientation(), state.getPosition());
\r
57 PfxShapeIterator itrShape(coll);
\r
58 for(int j=0;j<coll.getNumShapes();j++,++itrShape) {
\r
59 const PfxShape &shape = *itrShape;
\r
60 PfxTransform3 offsetT = shape.getOffsetTransform();
\r
61 PfxTransform3 worldT = rbT * offsetT;
\r
63 switch(shape.getType()) {
\r
64 case kPfxShapeSphere:
\r
68 PfxFloatInVec(shape.getSphere().m_radius));
\r
75 shape.getBox().m_half);
\r
78 case kPfxShapeCapsule:
\r
82 PfxFloatInVec(shape.getCapsule().m_radius),
\r
83 PfxFloatInVec(shape.getCapsule().m_halfLen));
\r
86 case kPfxShapeCylinder:
\r
90 PfxFloatInVec(shape.getCylinder().m_radius),
\r
91 PfxFloatInVec(shape.getCylinder().m_halfLen));
\r
94 case kPfxShapeConvexMesh:
\r
101 case kPfxShapeLargeTriMesh:
\r
124 landscapeMeshId = render_init_mesh(
\r
125 LargeMeshVtx,sizeof(float)*6,
\r
126 LargeMeshVtx+3,sizeof(float)*6,
\r
127 LargeMeshIdx,sizeof(unsigned short)*3,
\r
128 LargeMeshVtxCount,LargeMeshIdxCount/3);
\r
130 convexMeshId = render_init_mesh(
\r
131 BarrelVtx,sizeof(float)*6,
\r
132 BarrelVtx+3,sizeof(float)*6,
\r
133 BarrelIdx,sizeof(unsigned short)*3,
\r
134 BarrelVtxCount,BarrelIdxCount/3);
\r
139 static int shutdown(void)
\r
152 render_get_view_angle(angX,angY,r);
\r
156 if(ctrl_button_pressed(BTN_UP)) {
\r
158 if(angX < -1.4f) angX = -1.4f;
\r
159 if(angX > -0.01f) angX = -0.01f;
\r
162 if(ctrl_button_pressed(BTN_DOWN)) {
\r
164 if(angX < -1.4f) angX = -1.4f;
\r
165 if(angX > -0.01f) angX = -0.01f;
\r
168 if(ctrl_button_pressed(BTN_LEFT)) {
\r
172 if(ctrl_button_pressed(BTN_RIGHT)) {
\r
176 if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
\r
178 if(r > 500.0f) r = 500.0f;
\r
181 if(ctrl_button_pressed(BTN_ZOOM_IN)) {
\r
183 if(r < 1.0f) r = 1.0f;
\r
186 if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
\r
187 physics_create_scene(sceneId);
\r
190 if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
\r
191 physics_create_scene(++sceneId);
\r
194 if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
\r
195 simulating = !simulating;
\r
198 if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
\r
201 else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
\r
202 simulating = false;
\r
205 render_set_view_angle(angX,angY,r);
\r
210 // ARA begin insert new code
\r
213 ///////////////////////////////////////////////////////////////////////////////
\r
216 /// This function is used to change the physics scene on Android devices
\r
217 ///////////////////////////////////////////////////////////////////////////////
\r
220 physics_create_scene(sceneId++);
\r
223 #else // __ANDROID__
\r
226 ///////////////////////////////////////////////////////////////////////////////
\r
233 physics_create_scene(sceneId);
\r
235 printf("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
\r
237 while (s_isRunning) {
\r
239 if(simulating) physics_simulate();
\r
247 printf("## %s: FINISHED ##\n", SAMPLE_NAME);
\r
252 // ARA begin insert new code
\r
253 #endif // __ANDROID__
\r
258 ///////////////////////////////////////////////////////////////////////////////
\r
264 HINSTANCE hInstance;
\r
266 void releaseWindow()
\r
269 wglMakeCurrent(0,0);
\r
270 wglDeleteContext(hRC);
\r
273 if(hDC) ReleaseDC(hWnd,hDC);
\r
274 if(hWnd) DestroyWindow(hWnd);
\r
276 UnregisterClass(SAMPLE_NAME,hInstance);
\r
279 LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
\r
282 case WM_SYSCOMMAND:
\r
285 case SC_SCREENSAVE:
\r
286 case SC_MONITORPOWER:
\r
293 PostQuitMessage(0);
\r
297 render_resize(LOWORD(lParam),HIWORD(lParam));
\r
301 return DefWindowProc(hWnd,uMsg,wParam,lParam);
\r
304 bool createWindow(char* title, int width, int height)
\r
311 rect.bottom=height;
\r
313 hInstance = GetModuleHandle(NULL);
\r
314 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
\r
315 wc.lpfnWndProc = (WNDPROC) WndProc;
\r
318 wc.hInstance = hInstance;
\r
319 wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
\r
320 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
\r
321 wc.hbrBackground = NULL;
\r
322 wc.lpszMenuName = NULL;
\r
323 wc.lpszClassName = SAMPLE_NAME;
\r
325 if(!RegisterClass(&wc)) {
\r
329 AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
\r
331 if(!(hWnd=CreateWindowEx(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,SAMPLE_NAME,title,
\r
332 WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
\r
333 0,0,rect.right-rect.left,rect.bottom-rect.top,
\r
334 NULL,NULL,hInstance,NULL))) {
\r
339 static PIXELFORMATDESCRIPTOR pfd = {
\r
340 sizeof(PIXELFORMATDESCRIPTOR),
\r
342 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
\r
359 if(!(hDC=GetDC(hWnd)))
\r
362 OutputDebugString("");
\r
368 if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 ){
\r
369 OutputDebugString("ChoosePixelFormat Failed....");
\r
373 if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE){
\r
374 OutputDebugString("SetPixelFormat Failed....");
\r
378 if (!(hRC=wglCreateContext(hDC))){
\r
379 OutputDebugString("Creating HGLRC Failed....");
\r
384 //BOOL (WINAPI *wglSwapIntervalEXT)(int) = NULL;
\r
386 //if(strstr((char*)glGetString( GL_EXTENSIONS ),"WGL_EXT_swap_control")== 0) {
\r
389 //wglSwapIntervalEXT = (BOOL (WINAPI*)(int))wglGetProcAddress("wglSwapIntervalEXT");
\r
390 //if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
\r
393 wglMakeCurrent(hDC,hRC);
\r
395 ShowWindow(hWnd,SW_SHOW);
\r
396 SetForegroundWindow(hWnd);
\r
399 render_resize(width, height);
\r
401 glClearColor(0.0f,0.0f,0.0f,0.0f);
\r
402 glClearDepth(1.0f);
\r
407 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
\r
409 if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
\r
410 MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
\r
416 physics_create_scene(sceneId);
\r
418 SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
\r
421 while(s_isRunning) {
\r
422 if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
\r
423 if(msg.message==WM_QUIT) {
\r
424 s_isRunning = false;
\r
427 TranslateMessage(&msg);
\r
428 DispatchMessage(&msg);
\r
433 if(simulating) physics_simulate();
\r
442 SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);
\r
445 return (msg.wParam);
\r