From 9bcc19a98f15523102cb042ec5d3603de87a1d4a Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Tue, 19 Jan 2010 23:37:14 +0000 Subject: [PATCH] enable Box2dDemo for Win32 app. --- Demos/BasicDemo/Win32BasicDemo.cpp | 25 +++++++++++++++++++++++++ Demos/Box2dDemo/Box2dDemo.cpp | 14 +++++++------- Demos/Box2dDemo/Box2dDemo.h | 9 ++++++++- Demos/Box2dDemo/CMakeLists.txt | 29 +++++++++++++++++++++-------- Demos/Box2dDemo/Win32Box2dDemo.cpp | 25 +++++++++++++++++++++++++ Demos/CMakeLists.txt | 2 +- 6 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 Demos/BasicDemo/Win32BasicDemo.cpp create mode 100644 Demos/Box2dDemo/Win32Box2dDemo.cpp diff --git a/Demos/BasicDemo/Win32BasicDemo.cpp b/Demos/BasicDemo/Win32BasicDemo.cpp new file mode 100644 index 000000000..a55fb67eb --- /dev/null +++ b/Demos/BasicDemo/Win32BasicDemo.cpp @@ -0,0 +1,25 @@ +#ifdef _WINDOWS +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "BasicDemo.h" + +///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo +DemoApplication* createDemo() +{ + return new BasicDemo(); +} + +#endif diff --git a/Demos/Box2dDemo/Box2dDemo.cpp b/Demos/Box2dDemo/Box2dDemo.cpp index 9e3ee53b3..c131772a0 100644 --- a/Demos/Box2dDemo/Box2dDemo.cpp +++ b/Demos/Box2dDemo/Box2dDemo.cpp @@ -69,7 +69,7 @@ void Box2dDemo::clientMoveAndDisplay() glFlush(); - glutSwapBuffers(); + swapBuffers(); } @@ -89,7 +89,7 @@ void Box2dDemo::displayCallback(void) { m_dialogDynamicsWorld->draw(0.f); glFlush(); - glutSwapBuffers(); + swapBuffers(); } @@ -98,7 +98,7 @@ void Box2dDemo::reshape(int w, int h) { if (m_dialogDynamicsWorld) m_dialogDynamicsWorld->setScreenSize(w,h); - GlutDemoApplication::reshape(w,h); + PlatformDemoApplication::reshape(w,h); } void Box2dDemo::initPhysics() @@ -210,20 +210,20 @@ void Box2dDemo::initPhysics() //create a few dynamic rigidbodies // Re-using the same collision is better for memory usage and performance - btScalar u = 1*SCALING-0.04; + btScalar u= btScalar(1*SCALING-0.04); btVector3 points[3] = {btVector3(0,u,0),btVector3(-u,-u,0),btVector3(u,-u,0)}; - btConvexShape* colShape= new btConvex2dShape(new btBoxShape(btVector3(SCALING*1,SCALING*1,0.04))); + btConvexShape* colShape= new btConvex2dShape(new btBoxShape(btVector3(btScalar(SCALING*1),btScalar(SCALING*1),btScalar(0.04)))); //btCollisionShape* colShape = new btBox2dShape(btVector3(SCALING*1,SCALING*1,0.04)); btConvexShape* colShape2= new btConvex2dShape(new btConvexHullShape(&points[0].getX(),3)); - btConvexShape* colShape3= new btConvex2dShape(new btCylinderShapeZ(btVector3(SCALING*1,SCALING*1,0.04))); + btConvexShape* colShape3= new btConvex2dShape(new btCylinderShapeZ(btVector3(btScalar(SCALING*1),btScalar(SCALING*1),btScalar(0.04)))); //btUniformScalingShape* colShape = new btUniformScalingShape(convexColShape,1.f); - colShape->setMargin(0.03); + colShape->setMargin(btScalar(0.03)); //btCollisionShape* colShape = new btSphereShape(btScalar(1.)); m_collisionShapes.push_back(colShape); m_collisionShapes.push_back(colShape2); diff --git a/Demos/Box2dDemo/Box2dDemo.h b/Demos/Box2dDemo/Box2dDemo.h index 8fccfbd09..ce69ec0c0 100644 --- a/Demos/Box2dDemo/Box2dDemo.h +++ b/Demos/Box2dDemo/Box2dDemo.h @@ -15,7 +15,14 @@ subject to the following restrictions: #ifndef BOX2D_DEMO_H #define BOX2D_DEMO_H +#ifdef _WINDOWS +#include "Win32DemoApplication.h" +#define PlatformDemoApplication Win32DemoApplication +#else #include "GlutDemoApplication.h" +#define PlatformDemoApplication GlutDemoApplication +#endif + #include "LinearMath/btAlignedObjectArray.h" class btBroadphaseInterface; @@ -28,7 +35,7 @@ class btDefaultCollisionConfiguration; class GL_DialogDynamicsWorld; ///Box2dDemo is good starting point for learning the code base and porting. -class Box2dDemo : public GlutDemoApplication +class Box2dDemo : public PlatformDemoApplication { //keep the collision shapes, for deletion/cleanup diff --git a/Demos/Box2dDemo/CMakeLists.txt b/Demos/Box2dDemo/CMakeLists.txt index 3469a69de..bd7d47915 100644 --- a/Demos/Box2dDemo/CMakeLists.txt +++ b/Demos/Box2dDemo/CMakeLists.txt @@ -15,14 +15,27 @@ INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL ) +IF (USE_GLUT) + LINK_LIBRARIES( + OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + ) + + ADD_EXECUTABLE(AppBox2dDemo + main.cpp + Box2dDemo.cpp + Box2dDemo.h + ) +ELSE (USE_GLUT) LINK_LIBRARIES( -OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} -) - -ADD_EXECUTABLE(AppBox2dDemo - main.cpp - Box2dDemo.cpp - Box2dDemo.h -) + OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + ) + ADD_EXECUTABLE(AppBox2dDemo + WIN32 + ../OpenGL/Win32AppMain.cpp + Win32Box2dDemo.cpp + Box2dDemo.cpp + Box2dDemo.h + ) +ENDIF (USE_GLUT) diff --git a/Demos/Box2dDemo/Win32Box2dDemo.cpp b/Demos/Box2dDemo/Win32Box2dDemo.cpp new file mode 100644 index 000000000..146cf9a6f --- /dev/null +++ b/Demos/Box2dDemo/Win32Box2dDemo.cpp @@ -0,0 +1,25 @@ +#ifdef _WINDOWS +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "Box2dDemo.h" + +///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo +DemoApplication* createDemo() +{ + return new Box2dDemo(); +} + +#endif diff --git a/Demos/CMakeLists.txt b/Demos/CMakeLists.txt index 7cd472fd3..abe0bd466 100644 --- a/Demos/CMakeLists.txt +++ b/Demos/CMakeLists.txt @@ -1,4 +1,4 @@ -SUBDIRS( OpenGL BasicDemo Benchmarks) +SUBDIRS( OpenGL BasicDemo Benchmarks Box2dDemo) #todo: re-enable the rest of the demos again