From 218e9f9bf93dabca46720b3d22d9dc6499b87a26 Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Fri, 1 May 2015 11:42:14 -0700 Subject: [PATCH] enable URDF loading throught the 'File/Open' menu set a default camera targets for each demo. note that it is only reset when switching to a different demo, so you can restart at your chosen location. no OpenCL pairbench drawing in OpenGL2 (there is no VBO available etc) --- examples/BasicDemo/BasicExample.cpp | 14 ++- examples/BasicDemo/BasicExample.h | 2 +- examples/BasicDemo/main.cpp | 4 +- examples/Benchmarks/BenchmarkDemo.cpp | 4 +- examples/Benchmarks/BenchmarkDemo.h | 2 +- .../CommonInterfaces/CommonExampleInterface.h | 22 ++++- .../CommonGUIHelperInterface.h | 5 ++ .../CommonInterfaces/CommonRenderInterface.h | 4 + examples/Constraints/ConstraintDemo.cpp | 19 +++-- examples/Constraints/ConstraintDemo.h | 2 +- .../Constraints/ConstraintPhysicsSetup.cpp | 15 +++- examples/Constraints/ConstraintPhysicsSetup.h | 2 +- examples/Constraints/Dof6Spring2Setup.cpp | 13 ++- examples/Constraints/Dof6Spring2Setup.h | 2 +- examples/ExampleBrowser/EmptyExample.h | 2 +- examples/ExampleBrowser/ExampleEntries.cpp | 25 ++++-- examples/ExampleBrowser/ExampleEntries.h | 2 + .../ExampleBrowser/OpenGLExampleBrowser.cpp | 80 +++++++++++++---- examples/ExampleBrowser/OpenGLGuiHelper.cpp | 27 +++--- examples/ExampleBrowser/OpenGLGuiHelper.h | 4 +- examples/ExampleBrowser/main.cpp | 1 + .../ImplicitCloth/ImplicitClothExample.cpp | 13 ++- .../ImplicitCloth/ImplicitClothExample.h | 2 +- examples/ForkLift/ForkLiftDemo.cpp | 13 ++- examples/ForkLift/ForkLiftDemo.h | 2 +- examples/GyroscopicDemo/GyroscopicSetup.cpp | 13 ++- examples/GyroscopicDemo/GyroscopicSetup.h | 2 +- examples/HelloWorld/premake4.lua | 2 +- .../Importers/ImportBsp/ImportBspExample.cpp | 12 ++- .../Importers/ImportBsp/ImportBspExample.h | 2 +- .../Importers/ImportBullet/SerializeSetup.cpp | 14 ++- .../Importers/ImportBullet/SerializeSetup.h | 2 +- .../ImportColladaDemo/ImportColladaSetup.cpp | 13 ++- .../ImportColladaDemo/ImportColladaSetup.h | 2 +- .../ImportObjDemo/ImportObjExample.cpp | 14 ++- .../ImportObjDemo/ImportObjExample.h | 2 +- .../ImportSTLDemo/ImportSTLSetup.cpp | 13 ++- .../Importers/ImportSTLDemo/ImportSTLSetup.h | 2 +- .../ImportURDFDemo/ImportURDFSetup.cpp | 85 +++++++++++-------- .../ImportURDFDemo/ImportURDFSetup.h | 3 +- examples/MultiBody/MultiDofDemo.cpp | 16 +++- examples/MultiBody/MultiDofDemo.h | 2 +- examples/MultiBody/TestJointTorqueSetup.cpp | 14 ++- examples/MultiBody/TestJointTorqueSetup.h | 2 +- examples/OpenCL/broadphase/PairBench.cpp | 70 +++++++++------ examples/OpenCL/broadphase/PairBench.h | 2 +- .../GLInstanceRendererInternalData.h | 3 + .../OpenGLWindow/GLInstancingRenderer.cpp | 57 ++++++++----- examples/OpenGLWindow/GLInstancingRenderer.h | 17 ++-- examples/OpenGLWindow/SimpleOpenGL2Renderer.h | 5 ++ examples/Planar2D/Planar2D.cpp | 13 ++- examples/Planar2D/Planar2D.h | 2 +- examples/Raycast/RaytestDemo.cpp | 14 ++- examples/Raycast/RaytestDemo.h | 2 +- .../CoordinateSystemDemo.cpp | 21 ++++- .../RenderingExamples/CoordinateSystemDemo.h | 2 +- examples/RenderingExamples/RaytracerSetup.cpp | 4 +- examples/RenderingExamples/RaytracerSetup.h | 2 +- .../RenderInstancingDemo.cpp | 19 ++++- .../RenderingExamples/RenderInstancingDemo.h | 2 +- examples/SoftDemo/SoftDemo.cpp | 16 +++- examples/SoftDemo/SoftDemo.h | 2 +- examples/Vehicles/Hinge2Vehicle.cpp | 13 ++- examples/Vehicles/Hinge2Vehicle.h | 2 +- .../VoronoiFracture/VoronoiFractureDemo.cpp | 13 ++- .../VoronoiFracture/VoronoiFractureDemo.h | 2 +- 66 files changed, 562 insertions(+), 217 deletions(-) diff --git a/examples/BasicDemo/BasicExample.cpp b/examples/BasicDemo/BasicExample.cpp index 5e251e6c2..4a6a4c5c5 100644 --- a/examples/BasicDemo/BasicExample.cpp +++ b/examples/BasicDemo/BasicExample.cpp @@ -37,6 +37,14 @@ struct BasicExample : public CommonRigidBodyBase virtual ~BasicExample(){} virtual void initPhysics(); virtual void renderScene(); + void resetCamera() + { + float dist = 41; + float pitch = 52; + float yaw = 35; + float targetPos[3]={0,0.46,0}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } }; void BasicExample::initPhysics() @@ -128,9 +136,11 @@ void BasicExample::renderScene() -CommonExampleInterface* BasicExampleCreateFunc(PhysicsInterface* pint, GUIHelperInterface* helper, int option) + + +CommonExampleInterface* BasicExampleCreateFunc(CommonExampleOptions& options) { - return new BasicExample(helper); + return new BasicExample(options.m_guiHelper); } diff --git a/examples/BasicDemo/BasicExample.h b/examples/BasicDemo/BasicExample.h index 831244b9b..a72db8482 100644 --- a/examples/BasicDemo/BasicExample.h +++ b/examples/BasicDemo/BasicExample.h @@ -16,7 +16,7 @@ subject to the following restrictions: #ifndef BASIC_EXAMPLE_H #define BASIC_EXAMPLE_H -class CommonExampleInterface* BasicExampleCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* BasicExampleCreateFunc(struct CommonExampleOptions& options); #endif //BASIC_DEMO_PHYSICS_SETUP_H diff --git a/examples/BasicDemo/main.cpp b/examples/BasicDemo/main.cpp index b829f6773..cf4dd5baa 100644 --- a/examples/BasicDemo/main.cpp +++ b/examples/BasicDemo/main.cpp @@ -28,9 +28,7 @@ int main(int argc, char* argv[]) DummyGUIHelper noGfx; - int option = 0; - - CommonExampleInterface* example = BasicExampleCreateFunc(pint, &noGfx, option); + CommonExampleInterface* example = BasicExampleCreateFunc(CommonExampleOptions(&noGfx)); example->initPhysics(); example->stepSimulation(1.f/60.f); diff --git a/examples/Benchmarks/BenchmarkDemo.cpp b/examples/Benchmarks/BenchmarkDemo.cpp index 0e33c57d8..a1ede8ff4 100644 --- a/examples/Benchmarks/BenchmarkDemo.cpp +++ b/examples/Benchmarks/BenchmarkDemo.cpp @@ -1234,7 +1234,7 @@ void BenchmarkDemo::exitPhysics() -struct CommonExampleInterface* BenchmarkCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +struct CommonExampleInterface* BenchmarkCreateFunc(struct CommonExampleOptions& options) { - return new BenchmarkDemo(helper,option); + return new BenchmarkDemo(options.m_guiHelper,options.m_option); } \ No newline at end of file diff --git a/examples/Benchmarks/BenchmarkDemo.h b/examples/Benchmarks/BenchmarkDemo.h index 473d783bd..cd9507943 100644 --- a/examples/Benchmarks/BenchmarkDemo.h +++ b/examples/Benchmarks/BenchmarkDemo.h @@ -15,7 +15,7 @@ subject to the following restrictions: #ifndef BENCHMARK_EXAMPLE_H #define BENCHMARK_EXAMPLE_H -class CommonExampleInterface* BenchmarkCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* BenchmarkCreateFunc(struct CommonExampleOptions& options); diff --git a/examples/CommonInterfaces/CommonExampleInterface.h b/examples/CommonInterfaces/CommonExampleInterface.h index a9ccda4ba..5d2c0027e 100644 --- a/examples/CommonInterfaces/CommonExampleInterface.h +++ b/examples/CommonInterfaces/CommonExampleInterface.h @@ -3,23 +3,43 @@ #ifndef COMMON_EXAMPLE_INTERFACE_H #define COMMON_EXAMPLE_INTERFACE_H +struct CommonExampleOptions +{ + struct GUIHelperInterface* m_guiHelper; + + //Those are optional, some examples will use them others don't. Each example should work with them being 0. + int m_option; + const char* m_fileName; + + + CommonExampleOptions(struct GUIHelperInterface* helper, int option=0) + :m_guiHelper(helper), + m_option(option), + m_fileName(0) + { + } + +}; class CommonExampleInterface { public: - typedef class CommonExampleInterface* (CreateFunc)(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); + typedef class CommonExampleInterface* (CreateFunc)(CommonExampleOptions& options); virtual ~CommonExampleInterface() { } + virtual void initPhysics()=0; virtual void exitPhysics()=0; virtual void stepSimulation(float deltaTime)=0; virtual void renderScene()=0; virtual void physicsDebugDraw(int debugFlags)=0;//for now we reuse the flags in Bullet/src/LinearMath/btIDebugDraw.h + //reset camera is only called when switching demo. this way you can restart (initPhysics) and watch in a specific location easier + virtual void resetCamera(){}; virtual bool mouseMoveCallback(float x,float y)=0; virtual bool mouseButtonCallback(int button, int state, float x, float y)=0; virtual bool keyboardCallback(int key, int state)=0; diff --git a/examples/CommonInterfaces/CommonGUIHelperInterface.h b/examples/CommonInterfaces/CommonGUIHelperInterface.h index 43ada3f59..0930399c9 100644 --- a/examples/CommonInterfaces/CommonGUIHelperInterface.h +++ b/examples/CommonInterfaces/CommonGUIHelperInterface.h @@ -43,6 +43,8 @@ struct GUIHelperInterface virtual void setUpAxis(int axis)=0; + virtual void resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ)=0; + virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld) =0; virtual void drawText3D( const char* txt, float posX, float posZY, float posZ, float size)=0; @@ -97,6 +99,9 @@ struct DummyGUIHelper : public GUIHelperInterface virtual void setUpAxis(int axis) { } + virtual void resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ) + { + } virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld) { diff --git a/examples/CommonInterfaces/CommonRenderInterface.h b/examples/CommonInterfaces/CommonRenderInterface.h index cc4862905..d3dcc8ea1 100644 --- a/examples/CommonInterfaces/CommonRenderInterface.h +++ b/examples/CommonInterfaces/CommonRenderInterface.h @@ -51,6 +51,10 @@ struct CommonRenderInterface virtual void writeTransforms()=0; virtual void enableBlend(bool blend)=0; + + //This is internal access to OpenGL3+ features, mainly used for OpenCL-OpenGL interop + //Only the GLInstancingRenderer supports it, just return 0 otherwise. + virtual struct GLInstanceRendererInternalData* getInternalData()=0; }; template diff --git a/examples/Constraints/ConstraintDemo.cpp b/examples/Constraints/ConstraintDemo.cpp index 14bc2504c..8c5fced4a 100644 --- a/examples/Constraints/ConstraintDemo.cpp +++ b/examples/Constraints/ConstraintDemo.cpp @@ -43,12 +43,19 @@ class AllConstraintDemo : public CommonRigidBodyBase virtual ~AllConstraintDemo(); - void initPhysics(); + virtual void initPhysics(); - void exitPhysics(); + virtual void exitPhysics(); + + virtual void resetCamera() + { + float dist = 27; + float pitch = 720; + float yaw = 30; + float targetPos[3]={2,0,-10}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } - - virtual void keyboardCallback(unsigned char key, int x, int y); // for cone-twist motor driving @@ -872,7 +879,7 @@ void AllConstraintDemo::keyboardCallback(unsigned char key, int x, int y) } } -class CommonExampleInterface* AllConstraintCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* AllConstraintCreateFunc(struct CommonExampleOptions& options) { - return new AllConstraintDemo(helper); + return new AllConstraintDemo(options.m_guiHelper); } \ No newline at end of file diff --git a/examples/Constraints/ConstraintDemo.h b/examples/Constraints/ConstraintDemo.h index 6b21d5709..0b48c0ce2 100644 --- a/examples/Constraints/ConstraintDemo.h +++ b/examples/Constraints/ConstraintDemo.h @@ -15,7 +15,7 @@ subject to the following restrictions: #ifndef ALL_CONSTRAINT_DEMO_H #define ALL_CONSTRAINT_DEMO_H -class CommonExampleInterface* AllConstraintCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* AllConstraintCreateFunc(struct CommonExampleOptions& options); #endif //ALL_CONSTRAINT_DEMO_H diff --git a/examples/Constraints/ConstraintPhysicsSetup.cpp b/examples/Constraints/ConstraintPhysicsSetup.cpp index f6bf81a88..71b3b2e97 100644 --- a/examples/Constraints/ConstraintPhysicsSetup.cpp +++ b/examples/Constraints/ConstraintPhysicsSetup.cpp @@ -14,6 +14,17 @@ struct ConstraintPhysicsSetup : public CommonRigidBodyBase virtual void stepSimulation(float deltaTime); + + virtual void resetCamera() + { + float dist = 7; + float pitch = 721; + float yaw = 44; + float targetPos[3]={8,1,-11}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + + }; ConstraintPhysicsSetup::ConstraintPhysicsSetup(struct GUIHelperInterface* helper) @@ -144,7 +155,7 @@ void ConstraintPhysicsSetup::initPhysics() m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); } -class CommonExampleInterface* ConstraintCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* ConstraintCreateFunc(CommonExampleOptions& options) { - return new ConstraintPhysicsSetup(helper); + return new ConstraintPhysicsSetup(options.m_guiHelper); } diff --git a/examples/Constraints/ConstraintPhysicsSetup.h b/examples/Constraints/ConstraintPhysicsSetup.h index 241a2b02f..3cf28d126 100644 --- a/examples/Constraints/ConstraintPhysicsSetup.h +++ b/examples/Constraints/ConstraintPhysicsSetup.h @@ -1,6 +1,6 @@ #ifndef CONSTAINT_PHYSICS_SETUP_H #define CONSTAINT_PHYSICS_SETUP_H -class CommonExampleInterface* ConstraintCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* ConstraintCreateFunc(struct CommonExampleOptions& options); #endif //CONSTAINT_PHYSICS_SETUP_H diff --git a/examples/Constraints/Dof6Spring2Setup.cpp b/examples/Constraints/Dof6Spring2Setup.cpp index 1860bd173..2531616c7 100644 --- a/examples/Constraints/Dof6Spring2Setup.cpp +++ b/examples/Constraints/Dof6Spring2Setup.cpp @@ -51,6 +51,15 @@ struct Dof6Spring2Setup : public CommonRigidBodyBase virtual void stepSimulation(float deltaTime); void animate(); + + virtual void resetCamera() + { + float dist = 5; + float pitch = 722; + float yaw = 35; + float targetPos[3]={4,2,-11}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } }; @@ -475,7 +484,7 @@ void Dof6Spring2Setup::stepSimulation(float deltaTime) m_dynamicsWorld->stepSimulation(deltaTime); } -class CommonExampleInterface* Dof6Spring2CreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* Dof6Spring2CreateFunc( CommonExampleOptions& options) { - return new Dof6Spring2Setup(helper); + return new Dof6Spring2Setup(options.m_guiHelper); } diff --git a/examples/Constraints/Dof6Spring2Setup.h b/examples/Constraints/Dof6Spring2Setup.h index 8cda64578..3c7dc92b8 100644 --- a/examples/Constraints/Dof6Spring2Setup.h +++ b/examples/Constraints/Dof6Spring2Setup.h @@ -1,6 +1,6 @@ #ifndef GENERIC_6DOF_SPRING2_CONSTRAINT_DEMO_H #define GENERIC_6DOF_SPRING2_CONSTRAINT_DEMO_H -class CommonExampleInterface* Dof6Spring2CreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* Dof6Spring2CreateFunc(struct CommonExampleOptions& options); #endif //GENERIC_6DOF_SPRING2_CONSTRAINT_DEMO_H diff --git a/examples/ExampleBrowser/EmptyExample.h b/examples/ExampleBrowser/EmptyExample.h index 862f97d0f..af41f8af8 100644 --- a/examples/ExampleBrowser/EmptyExample.h +++ b/examples/ExampleBrowser/EmptyExample.h @@ -10,7 +10,7 @@ public: EmptyExample() {} virtual ~EmptyExample(){} - static CommonExampleInterface* CreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) + static CommonExampleInterface* CreateFunc(struct CommonExampleOptions& /* unusedOptions*/) { return new EmptyExample; } diff --git a/examples/ExampleBrowser/ExampleEntries.cpp b/examples/ExampleBrowser/ExampleEntries.cpp index 468d002e0..dcfa8f80d 100644 --- a/examples/ExampleBrowser/ExampleEntries.cpp +++ b/examples/ExampleBrowser/ExampleEntries.cpp @@ -61,14 +61,14 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(1,"Gyroscopic", "Show the Dzhanibekov effect using various settings of the gyroscopic term. You can select the gyroscopic term computation using btRigidBody::setFlags, with arguments BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT (using explicit integration, which adds energy and can lead to explosions), BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_WORLD, BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_BODY. If you don't set any of these flags, there is no gyroscopic term used.", GyroscopicCreateFunc), ExampleEntry(1,"Planar 2D","Show the use of 2D collision shapes and rigid body simulation. The collision shape is wrapped into a btConvex2dShape. The rigid bodies are restricted in a plane using the 'setAngularFactor' and 'setLinearFactor' API call.",Planar2DCreateFunc), - ExampleEntry(1,"Constraints","Use of a btHingeConstraint. You can adjust the first slider to change the target velocity, and the second slider to adjust the maximum impulse applied to reach the target velocity. Note that the hinge angle can reach beyond -360 and 360 degrees.", ConstraintCreateFunc), ExampleEntry(1,"6DofSpring2","Show the use of the btGeneric6DofSpring2Constraint.", Dof6Spring2CreateFunc), ExampleEntry(1,"Constraints","Show the use of the various constraints in Bullet.", AllConstraintCreateFunc), - + ExampleEntry(1,"Motorized Hinge","Use of a btHingeConstraint. You can adjust the first slider to change the target velocity, and the second slider to adjust the maximum impulse applied to reach the target velocity. Note that the hinge angle can reach beyond -360 and 360 degrees.", ConstraintCreateFunc), + ExampleEntry(0,"MultiBody"), ExampleEntry(1,"MultiDofCreateFunc","Create a basic btMultiBody with 3-DOF spherical joints (mobilizers). The demo uses a fixed base or a floating base at restart.", MultiDofCreateFunc), ExampleEntry(1,"TestJointTorque","Apply a torque to a btMultiBody with 1-DOF joints (mobilizers).", TestJointTorqueCreateFunc), @@ -164,16 +164,20 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(1,"Implicit Cloth", "Cloth simulation using implicit integration, by Stan Melax. The cloth is only attached at the corners. Note the stability using a large time step even with high stiffness.", ImplicitClothCreateFunc), -#ifdef B3_USE_CLEW - ExampleEntry(0,"OpenCL (experimental)"), - ExampleEntry(1,"Pair Bench", "Benchmark of overlapping pair search using OpenCL.", PairBenchOpenCLCreateFunc), -#endif // + ExampleEntry(0,"Rendering"), ExampleEntry(1,"Instanced Rendering", "Simple example of fast instanced rendering, only active when using OpenGL3+.",RenderInstancingCreateFunc), ExampleEntry(1,"CoordinateSystemDemo","Show the axis and positive rotation direction around the axis.", CoordinateSystemCreateFunc), }; +static ExampleEntry gOpenCLExamples[]= +{ +#ifdef B3_USE_CLEW + ExampleEntry(0,"OpenCL (experimental)"), + ExampleEntry(1,"Pair Bench", "Benchmark of overlapping pair search using OpenCL.", PairBenchOpenCLCreateFunc), +#endif // +}; static btAlignedObjectArray gAdditionalRegisteredExamples; @@ -193,6 +197,15 @@ ExampleEntries::~ExampleEntries() delete m_data; } +void ExampleEntries::initOpenCLExampleEntries() +{ + int numDefaultEntries = sizeof(gOpenCLExamples)/sizeof(ExampleEntry); + for (int i=0;im_allExamples.push_back(gOpenCLExamples[i]); + } +} + void ExampleEntries::initExampleEntries() { m_data->m_allExamples.clear(); diff --git a/examples/ExampleBrowser/ExampleEntries.h b/examples/ExampleBrowser/ExampleEntries.h index 1e6c56e42..f6d661adb 100644 --- a/examples/ExampleBrowser/ExampleEntries.h +++ b/examples/ExampleBrowser/ExampleEntries.h @@ -20,6 +20,8 @@ public: static void registerExampleEntry(int menuLevel, const char* name,const char* description, CommonExampleInterface::CreateFunc* createFunc, int option=0); void initExampleEntries(); + + void initOpenCLExampleEntries(); int getNumRegisteredExamples(); diff --git a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp index d56a7a835..b5d3e36e3 100644 --- a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp +++ b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp @@ -34,6 +34,9 @@ #include "ExampleEntries.h" #include "OpenGLGuiHelper.h" #include "LinearMath/btIDebugDraw.h" +//quick test for file import, @todo(erwincoumans) make it more general and add other file formats +#include "../Importers/ImportURDFDemo/ImportURDFSetup.h" + static CommonGraphicsApp* s_app=0; static CommonWindowInterface* s_window = 0; @@ -46,7 +49,7 @@ static MyProfileWindow* s_profWindow =0; const char* startFileName = "bulletDemo.txt"; static GwenUserInterface* gui = 0; -static int sCurrentDemoIndex = 0; +static int sCurrentDemoIndex = -1; static int sCurrentHightlighted = 0; static CommonExampleInterface* sCurrentDemo = 0; static b3AlignedObjectArray allNames; @@ -190,38 +193,49 @@ static void MyMouseButtonCallback(int button, int state, float x, float y) void openURDFDemo(const char* filename) { -#if 0 + if (sCurrentDemo) { - sCurrentDemo->exitPhysics(); - s_instancingRenderer->removeAllInstances(); - delete sCurrentDemo; - sCurrentDemo=0; + sCurrentDemo->exitPhysics(); + s_instancingRenderer->removeAllInstances(); + delete sCurrentDemo; + sCurrentDemo=0; + delete s_guiHelper; + s_guiHelper = 0; } - + + s_guiHelper= new OpenGLGuiHelper(s_app, sUseOpenGL2); s_parameterInterface->removeAllParameters(); - ImportUrdfSetup* physicsSetup = new ImportUrdfSetup(); - physicsSetup->setFileName(filename); - sCurrentDemo = new BasicDemo(s_app, physicsSetup); - s_app->setUpAxis(2); - + CommonExampleOptions options(s_guiHelper,0); + options.m_fileName = filename; + + sCurrentDemo = ImportURDFCreateFunc(options); + + //physicsSetup->setFileName(filename); + + if (sCurrentDemo) { sCurrentDemo->initPhysics(); + sCurrentDemo->resetCamera(); } -#endif + } void selectDemo(int demoIndex) { + bool resetCamera = (sCurrentDemoIndex != demoIndex); sCurrentDemoIndex = demoIndex; sCurrentHightlighted = demoIndex; int numDemos = gAllExamples->getNumRegisteredExamples(); + + + if (demoIndex>numDemos) { demoIndex = 0; @@ -241,7 +255,7 @@ void selectDemo(int demoIndex) s_parameterInterface->removeAllParameters(); int option = gAllExamples->getExampleOption(demoIndex); s_guiHelper= new OpenGLGuiHelper(s_app, sUseOpenGL2); - sCurrentDemo = (*func)(0,s_guiHelper, option); + sCurrentDemo = (*func)(CommonExampleOptions(s_guiHelper, option)); if (sCurrentDemo) { if (gui) @@ -251,7 +265,12 @@ void selectDemo(int demoIndex) } b3Printf("Selected demo: %s",gAllExamples->getExampleName(demoIndex)); gui->setExampleDescription(gAllExamples->getExampleDescription(demoIndex)); + sCurrentDemo->initPhysics(); + if(resetCamera) + { + sCurrentDemo->resetCamera(); + } } } @@ -544,14 +563,24 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) SimpleOpenGL3App* simpleApp=0; sUseOpenGL2 =args.CheckCmdLineFlag("opengl2"); + const char* appTitle = "Bullet Physics ExampleBrowser"; +#if defined (_DEBUG) || defined (DEBUG) + const char* optMode = "Debug build (slow)"; +#else + const char* optMode = "Release build"; +#endif + if (sUseOpenGL2 ) { - - s_app = new SimpleOpenGL2App("AllBullet2Demos",width,height); + char title[1024]; + sprintf(title,"%s using OpenGL2 fallback. %s", appTitle,optMode); + s_app = new SimpleOpenGL2App(title,width,height); s_app->m_renderer = new SimpleOpenGL2Renderer(width,height); } else { - simpleApp = new SimpleOpenGL3App("AllBullet2Demos",width,height); + char title[1024]; + sprintf(title,"%s using OpenGL3+. %s", appTitle,optMode); + simpleApp = new SimpleOpenGL3App(title,width,height); s_app = simpleApp; } char* gVideoFileName = 0; @@ -692,6 +721,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) } gui->registerFileOpenCallback(fileOpenCallback); + return true; } @@ -775,6 +805,22 @@ void OpenGLExampleBrowser::update(float deltaTime) } } + { + + if (s_guiHelper && s_guiHelper->getRenderInterface() && s_guiHelper->getRenderInterface()->getActiveCamera()) + { + char msg[1024]; + float camDist = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraDistance(); + float pitch = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraPitch(); + float yaw = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraYaw(); + float camTarget[3]; + s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraTargetPosition(camTarget); + sprintf(msg,"dist=%f, pitch=%f, yaw=%f,target=%f,%f,%f", camDist,pitch,yaw,camTarget[0],camTarget[1],camTarget[2]); + gui->setStatusBarMessage(msg, true); + } + + } + static int toggle = 1; if (1) { diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.cpp b/examples/ExampleBrowser/OpenGLGuiHelper.cpp index 71061ac30..a2c93fc89 100644 --- a/examples/ExampleBrowser/OpenGLGuiHelper.cpp +++ b/examples/ExampleBrowser/OpenGLGuiHelper.cpp @@ -117,7 +117,7 @@ public: static btVector4 sColors[4] = { btVector4(0.3,0.3,1,1), - btVector4(1,0,0,1), + btVector4(0.6,0.6,1,1), btVector4(0,1,0,1), btVector4(0,1,1,1), //btVector4(1,1,0,1), @@ -128,7 +128,6 @@ struct OpenGLGuiHelperInternalData { struct CommonGraphicsApp* m_glApp; class MyDebugDrawer* m_debugDraw; - int m_curColor; GL_ShapeDrawer* m_gl2ShapeDrawer; }; @@ -139,7 +138,7 @@ OpenGLGuiHelper::OpenGLGuiHelper(CommonGraphicsApp* glApp, bool useOpenGL2) m_data = new OpenGLGuiHelperInternalData; m_data->m_glApp = glApp; m_data->m_debugDraw = 0; - m_data->m_curColor = 0; + m_data->m_gl2ShapeDrawer = 0; if (useOpenGL2) @@ -487,15 +486,20 @@ void OpenGLGuiHelper::setUpAxis(int axis) m_data->m_glApp->setUpAxis(axis); } - -btVector3 OpenGLGuiHelper::selectColor() +void OpenGLGuiHelper::resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ) { - btVector4 color = sColors[m_data->m_curColor]; - m_data->m_curColor++; - m_data->m_curColor&=3; - return color; + if (getRenderInterface() && getRenderInterface()->getActiveCamera()) + { + getRenderInterface()->getActiveCamera()->setCameraDistance(camDist); + getRenderInterface()->getActiveCamera()->setCameraPitch(pitch); + getRenderInterface()->getActiveCamera()->setCameraYaw(yaw); + getRenderInterface()->getActiveCamera()->setCameraTargetPosition(camPosX,camPosY,camPosZ); + } } + + + struct MyConvertPointerSizeT { union @@ -530,7 +534,9 @@ void OpenGLGuiHelper::autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWor //btRigidBody* body = btRigidBody::upcast(colObj); //does this also work for btMultiBody/btMultiBodyLinkCollider? createCollisionShapeGraphicsObject(colObj->getCollisionShape()); - btVector3 color= selectColor(); + int colorIndex = colObj->getBroadphaseHandle()->getUid() & 3; + + btVector3 color= sColors[colorIndex]; createCollisionObjectGraphicsObject(colObj,color); } @@ -546,3 +552,4 @@ struct CommonGraphicsApp* OpenGLGuiHelper::getAppInterface() { return m_data->m_glApp; } + diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.h b/examples/ExampleBrowser/OpenGLGuiHelper.h index 96045bf91..631218d58 100644 --- a/examples/ExampleBrowser/OpenGLGuiHelper.h +++ b/examples/ExampleBrowser/OpenGLGuiHelper.h @@ -31,7 +31,6 @@ struct OpenGLGuiHelper : public GUIHelperInterface virtual void syncPhysicsToGraphics(const btDiscreteDynamicsWorld* rbWorld); - virtual void render(const btDiscreteDynamicsWorld* rbWorld); virtual void createPhysicsDebugDrawer(btDiscreteDynamicsWorld* rbWorld); @@ -42,10 +41,9 @@ struct OpenGLGuiHelper : public GUIHelperInterface virtual struct CommonGraphicsApp* getAppInterface(); - virtual void setUpAxis(int axis); - btVector3 selectColor(); + virtual void resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ); virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld) ; diff --git a/examples/ExampleBrowser/main.cpp b/examples/ExampleBrowser/main.cpp index f1e103e76..50b94d6b4 100644 --- a/examples/ExampleBrowser/main.cpp +++ b/examples/ExampleBrowser/main.cpp @@ -20,6 +20,7 @@ int main(int argc, char* argv[]) ExampleEntries examples; examples.initExampleEntries(); + examples.initOpenCLExampleEntries(); ExampleBrowserInterface* exampleBrowser = new DefaultBrowser(&examples); bool init = exampleBrowser->init(argc,argv); diff --git a/examples/Experiments/ImplicitCloth/ImplicitClothExample.cpp b/examples/Experiments/ImplicitCloth/ImplicitClothExample.cpp index 7e2d409de..ab102be56 100644 --- a/examples/Experiments/ImplicitCloth/ImplicitClothExample.cpp +++ b/examples/Experiments/ImplicitCloth/ImplicitClothExample.cpp @@ -56,6 +56,14 @@ public: return false; } + virtual void resetCamera() + { + float dist = 10; + float pitch = 62; + float yaw = 33; + float targetPos[3]={-3,2.4,-3.6}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } }; @@ -64,6 +72,7 @@ public: void ImplicitClothExample::initPhysics() { float size=10; + m_guiHelper->setUpAxis(1); m_cloth = ClothCreate(numX,numY,size); } @@ -114,7 +123,7 @@ void ImplicitClothExample::physicsDebugDraw(int debugFlags) } -class CommonExampleInterface* ImplicitClothCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* ImplicitClothCreateFunc(struct CommonExampleOptions& options) { - return new ImplicitClothExample(helper, option); + return new ImplicitClothExample(options.m_guiHelper, options.m_option); } diff --git a/examples/Experiments/ImplicitCloth/ImplicitClothExample.h b/examples/Experiments/ImplicitCloth/ImplicitClothExample.h index 1856a5ed1..634e354dc 100644 --- a/examples/Experiments/ImplicitCloth/ImplicitClothExample.h +++ b/examples/Experiments/ImplicitCloth/ImplicitClothExample.h @@ -1,7 +1,7 @@ #ifndef IMPLICIT_CLOTH_EXAMPLE_H #define IMPLICIT_CLOTH_EXAMPLE_H -class CommonExampleInterface* ImplicitClothCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* ImplicitClothCreateFunc(struct CommonExampleOptions& options); #endif //IMPLICIT_CLOTH_EXAMPLE_H diff --git a/examples/ForkLift/ForkLiftDemo.cpp b/examples/ForkLift/ForkLiftDemo.cpp index c606c492e..971438401 100644 --- a/examples/ForkLift/ForkLiftDemo.cpp +++ b/examples/ForkLift/ForkLiftDemo.cpp @@ -141,6 +141,15 @@ class ForkLiftDemo : public CommonExampleInterface void initPhysics(); void exitPhysics(); + virtual void resetCamera() + { + float dist = 8; + float pitch = -45; + float yaw = 32; + float targetPos[3]={-0.33,-0.72,4.5}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + /*static DemoApplication* Create() { ForkLiftDemo* demo = new ForkLiftDemo(); @@ -1200,7 +1209,7 @@ btRigidBody* ForkLiftDemo::localCreateRigidBody(btScalar mass, const btTransform return body; } -CommonExampleInterface* ForkLiftCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +CommonExampleInterface* ForkLiftCreateFunc(struct CommonExampleOptions& options) { - return new ForkLiftDemo(helper); + return new ForkLiftDemo(options.m_guiHelper); } diff --git a/examples/ForkLift/ForkLiftDemo.h b/examples/ForkLift/ForkLiftDemo.h index 0510a0088..030acf4e1 100644 --- a/examples/ForkLift/ForkLiftDemo.h +++ b/examples/ForkLift/ForkLiftDemo.h @@ -15,7 +15,7 @@ subject to the following restrictions: #ifndef FORKLIFT_DEMO_H #define FORKLIFT_DEMO_H -class CommonExampleInterface* ForkLiftCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* ForkLiftCreateFunc(struct CommonExampleOptions& options); #endif // FORKLIFT_DEMO_H diff --git a/examples/GyroscopicDemo/GyroscopicSetup.cpp b/examples/GyroscopicDemo/GyroscopicSetup.cpp index dfa24df33..e8eb55026 100644 --- a/examples/GyroscopicDemo/GyroscopicSetup.cpp +++ b/examples/GyroscopicDemo/GyroscopicSetup.cpp @@ -18,6 +18,15 @@ struct GyroscopicSetup : public CommonRigidBodyBase virtual void physicsDebugDraw(int debugFlags); + void resetCamera() + { + float dist = 20; + float pitch = 180; + float yaw = 16; + float targetPos[3]={-2.4,0.4,-0.24}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + }; @@ -123,7 +132,7 @@ void GyroscopicSetup::physicsDebugDraw(int debugFlags) } -class CommonExampleInterface* GyroscopicCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* GyroscopicCreateFunc(CommonExampleOptions& options) { - return new GyroscopicSetup(helper); + return new GyroscopicSetup(options.m_guiHelper); } \ No newline at end of file diff --git a/examples/GyroscopicDemo/GyroscopicSetup.h b/examples/GyroscopicDemo/GyroscopicSetup.h index 9ffcbd4c5..94cad4169 100644 --- a/examples/GyroscopicDemo/GyroscopicSetup.h +++ b/examples/GyroscopicDemo/GyroscopicSetup.h @@ -2,6 +2,6 @@ #ifndef GYROSCOPIC_SETUP_H #define GYROSCOPIC_SETUP_H -class CommonExampleInterface* GyroscopicCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* GyroscopicCreateFunc(struct CommonExampleOptions& options); #endif //GYROSCOPIC_SETUP_H diff --git a/examples/HelloWorld/premake4.lua b/examples/HelloWorld/premake4.lua index b3f1028ab..3a9436842 100644 --- a/examples/HelloWorld/premake4.lua +++ b/examples/HelloWorld/premake4.lua @@ -1,5 +1,5 @@ -project "AppHelloWorld" +project "App_HelloWorld" if _OPTIONS["ios"] then kind "WindowedApp" diff --git a/examples/Importers/ImportBsp/ImportBspExample.cpp b/examples/Importers/ImportBsp/ImportBspExample.cpp index 7045d2bf4..038342379 100644 --- a/examples/Importers/ImportBsp/ImportBspExample.cpp +++ b/examples/Importers/ImportBsp/ImportBspExample.cpp @@ -64,6 +64,14 @@ class BspDemo : public CommonRigidBodyBase void initPhysics(const char* bspfilename); + virtual void resetCamera() + { + float dist = 43; + float pitch = -175; + float yaw = 12; + float targetPos[3]={4,-25,-6}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } }; @@ -277,9 +285,9 @@ char* makeExeToBspFilename(const char* lpCmdLine) } -struct CommonExampleInterface* ImportBspCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +struct CommonExampleInterface* ImportBspCreateFunc(struct CommonExampleOptions& options) { - BspDemo* demo = new BspDemo(helper); + BspDemo* demo = new BspDemo(options.m_guiHelper); demo->initPhysics("BspDemo.bsp"); return demo; diff --git a/examples/Importers/ImportBsp/ImportBspExample.h b/examples/Importers/ImportBsp/ImportBspExample.h index 297aa6216..b1d51ab95 100644 --- a/examples/Importers/ImportBsp/ImportBspExample.h +++ b/examples/Importers/ImportBsp/ImportBspExample.h @@ -15,7 +15,7 @@ subject to the following restrictions: #ifndef BSP_DEMO_H #define BSP_DEMO_H -class CommonExampleInterface* ImportBspCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* ImportBspCreateFunc(struct CommonExampleOptions& options); #endif //BSP_DEMO_H diff --git a/examples/Importers/ImportBullet/SerializeSetup.cpp b/examples/Importers/ImportBullet/SerializeSetup.cpp index 7351b0cbd..fbc385722 100644 --- a/examples/Importers/ImportBullet/SerializeSetup.cpp +++ b/examples/Importers/ImportBullet/SerializeSetup.cpp @@ -12,6 +12,16 @@ public: virtual void initPhysics(); virtual void stepSimulation(float deltaTime); + + virtual void resetCamera() + { + float dist = 9.5; + float pitch = -2.8; + float yaw = 20; + float targetPos[3]={-0.2,-1.4,3.5}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + }; @@ -89,7 +99,7 @@ void SerializeSetup::stepSimulation(float deltaTime) CommonRigidBodyBase::stepSimulation(deltaTime); } -class CommonExampleInterface* SerializeBulletCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* SerializeBulletCreateFunc(struct CommonExampleOptions& options) { - return new SerializeSetup(helper); + return new SerializeSetup(options.m_guiHelper); } diff --git a/examples/Importers/ImportBullet/SerializeSetup.h b/examples/Importers/ImportBullet/SerializeSetup.h index 81a0500e6..673f65d82 100644 --- a/examples/Importers/ImportBullet/SerializeSetup.h +++ b/examples/Importers/ImportBullet/SerializeSetup.h @@ -1,7 +1,7 @@ #ifndef SERIALIZE_SETUP_H #define SERIALIZE_SETUP_H -class CommonExampleInterface* SerializeBulletCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* SerializeBulletCreateFunc(struct CommonExampleOptions& options); #endif //SERIALIZE_SETUP_H diff --git a/examples/Importers/ImportColladaDemo/ImportColladaSetup.cpp b/examples/Importers/ImportColladaDemo/ImportColladaSetup.cpp index 746edab27..b9a967737 100644 --- a/examples/Importers/ImportColladaDemo/ImportColladaSetup.cpp +++ b/examples/Importers/ImportColladaDemo/ImportColladaSetup.cpp @@ -37,6 +37,15 @@ public: virtual ~ImportColladaSetup(); virtual void initPhysics(); + virtual void resetCamera() + { + float dist = 16; + float pitch = -140; + float yaw = 28; + float targetPos[3]={-4,-3,-3}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + }; ImportColladaSetup::ImportColladaSetup(struct GUIHelperInterface* helper) @@ -197,7 +206,7 @@ void ImportColladaSetup::initPhysics() } -class CommonExampleInterface* ImportColladaCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* ImportColladaCreateFunc(struct CommonExampleOptions& options) { - return new ImportColladaSetup(helper); + return new ImportColladaSetup(options.m_guiHelper); } \ No newline at end of file diff --git a/examples/Importers/ImportColladaDemo/ImportColladaSetup.h b/examples/Importers/ImportColladaDemo/ImportColladaSetup.h index 954167025..f53c65579 100644 --- a/examples/Importers/ImportColladaDemo/ImportColladaSetup.h +++ b/examples/Importers/ImportColladaDemo/ImportColladaSetup.h @@ -19,7 +19,7 @@ subject to the following restrictions: #ifndef IMPORT_COLLADA_SETUP_H #define IMPORT_COLLADA_SETUP_H -class CommonExampleInterface* ImportColladaCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* ImportColladaCreateFunc(struct CommonExampleOptions& options); #endif //IMPORT_COLLADA_SETUP_H diff --git a/examples/Importers/ImportObjDemo/ImportObjExample.cpp b/examples/Importers/ImportObjDemo/ImportObjExample.cpp index 5088733db..bb13fda82 100644 --- a/examples/Importers/ImportObjDemo/ImportObjExample.cpp +++ b/examples/Importers/ImportObjDemo/ImportObjExample.cpp @@ -19,6 +19,16 @@ public: virtual ~ImportObjSetup(); virtual void initPhysics(); + + virtual void resetCamera() + { + float dist = 50; + float pitch = 61; + float yaw = 18; + float targetPos[3]={-15,-15,47}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + }; ImportObjSetup::ImportObjSetup(struct GUIHelperInterface* helper) @@ -99,7 +109,7 @@ void ImportObjSetup::initPhysics() } } - CommonExampleInterface* ImportObjCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) + CommonExampleInterface* ImportObjCreateFunc(struct CommonExampleOptions& options) { - return new ImportObjSetup(helper); + return new ImportObjSetup(options.m_guiHelper); } diff --git a/examples/Importers/ImportObjDemo/ImportObjExample.h b/examples/Importers/ImportObjDemo/ImportObjExample.h index 305736830..e2fcd9900 100644 --- a/examples/Importers/ImportObjDemo/ImportObjExample.h +++ b/examples/Importers/ImportObjDemo/ImportObjExample.h @@ -1,7 +1,7 @@ #ifndef IMPORT_OBJ_EXAMPLE_H #define IMPORT_OBJ_EXAMPLE_H -class CommonExampleInterface* ImportObjCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* ImportObjCreateFunc(struct CommonExampleOptions& options); #endif //IMPORT_OBJ_EXAMPLE_H diff --git a/examples/Importers/ImportSTLDemo/ImportSTLSetup.cpp b/examples/Importers/ImportSTLDemo/ImportSTLSetup.cpp index 7af6ccc96..92996d9fe 100644 --- a/examples/Importers/ImportSTLDemo/ImportSTLSetup.cpp +++ b/examples/Importers/ImportSTLDemo/ImportSTLSetup.cpp @@ -18,6 +18,15 @@ public: virtual ~ImportSTLSetup(); virtual void initPhysics(); + virtual void resetCamera() + { + float dist = 3.5; + float pitch = -136; + float yaw = 28; + float targetPos[3]={0.47,0,-0.64}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + }; @@ -92,7 +101,7 @@ void ImportSTLSetup::initPhysics() } } -class CommonExampleInterface* ImportSTLCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* ImportSTLCreateFunc(struct CommonExampleOptions& options) { - return new ImportSTLSetup(helper); + return new ImportSTLSetup(options.m_guiHelper); } diff --git a/examples/Importers/ImportSTLDemo/ImportSTLSetup.h b/examples/Importers/ImportSTLDemo/ImportSTLSetup.h index 75c5da01c..4eb39645e 100644 --- a/examples/Importers/ImportSTLDemo/ImportSTLSetup.h +++ b/examples/Importers/ImportSTLDemo/ImportSTLSetup.h @@ -1,6 +1,6 @@ #ifndef IMPORT_STL_SETUP_H #define IMPORT_STL_SETUP_H -class CommonExampleInterface* ImportSTLCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* ImportSTLCreateFunc(struct CommonExampleOptions& options); #endif //IMPORT_OBJ_SETUP_H diff --git a/examples/Importers/ImportURDFDemo/ImportURDFSetup.cpp b/examples/Importers/ImportURDFDemo/ImportURDFSetup.cpp index ff21149d1..a9143fa86 100644 --- a/examples/Importers/ImportURDFDemo/ImportURDFSetup.cpp +++ b/examples/Importers/ImportURDFDemo/ImportURDFSetup.cpp @@ -34,13 +34,22 @@ class ImportUrdfSetup : public CommonMultiBodyBase bool m_useMultiBody; public: - ImportUrdfSetup(struct GUIHelperInterface* helper, int option); + ImportUrdfSetup(struct GUIHelperInterface* helper, int option, const char* fileName); virtual ~ImportUrdfSetup(); virtual void initPhysics(); virtual void stepSimulation(float deltaTime); void setFileName(const char* urdfFileName); + + virtual void resetCamera() + { + float dist = 3.5; + float pitch = -136; + float yaw = 28; + float targetPos[3]={0.47,0,-0.64}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } }; @@ -62,9 +71,11 @@ struct ImportUrdfInternalData }; -ImportUrdfSetup::ImportUrdfSetup(struct GUIHelperInterface* helper, int option) +ImportUrdfSetup::ImportUrdfSetup(struct GUIHelperInterface* helper, int option, const char* fileName) :CommonMultiBodyBase(helper) { + m_data = new ImportUrdfInternalData; + if (option==1) { m_useMultiBody = true; @@ -74,38 +85,44 @@ ImportUrdfSetup::ImportUrdfSetup(struct GUIHelperInterface* helper, int option) } static int count = 0; - gFileNameArray.clear(); - gFileNameArray.push_back("r2d2.urdf"); - - m_data = new ImportUrdfInternalData; - - //load additional urdf file names from file - - FILE* f = fopen("urdf_files.txt","r"); - if (f) - { - int result; - //warning: we don't avoid string buffer overflow in this basic example in fscanf - char fileName[1024]; - do - { - result = fscanf(f,"%s",fileName); - if (result==1) - { - gFileNameArray.push_back(fileName); - } - } while (result==1); - - fclose(f); - } - - int numFileNames = gFileNameArray.size(); - - if (count>=numFileNames) + if (fileName) { - count=0; + setFileName(fileName); + } else + { + gFileNameArray.clear(); + gFileNameArray.push_back("r2d2.urdf"); + + + + //load additional urdf file names from file + + FILE* f = fopen("urdf_files.txt","r"); + if (f) + { + int result; + //warning: we don't avoid string buffer overflow in this basic example in fscanf + char fileName[1024]; + do + { + result = fscanf(f,"%s",fileName); + if (result==1) + { + gFileNameArray.push_back(fileName); + } + } while (result==1); + + fclose(f); + } + + int numFileNames = gFileNameArray.size(); + + if (count>=numFileNames) + { + count=0; + } + sprintf(m_fileName,gFileNameArray[count++].c_str()); } - sprintf(m_fileName,gFileNameArray[count++].c_str()); } ImportUrdfSetup::~ImportUrdfSetup() @@ -270,8 +287,8 @@ void ImportUrdfSetup::stepSimulation(float deltaTime) } } -class CommonExampleInterface* ImportURDFCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* ImportURDFCreateFunc(struct CommonExampleOptions& options) { - return new ImportUrdfSetup(helper, option); + return new ImportUrdfSetup(options.m_guiHelper, options.m_option,options.m_fileName); } \ No newline at end of file diff --git a/examples/Importers/ImportURDFDemo/ImportURDFSetup.h b/examples/Importers/ImportURDFDemo/ImportURDFSetup.h index fb7732a39..f908758db 100644 --- a/examples/Importers/ImportURDFDemo/ImportURDFSetup.h +++ b/examples/Importers/ImportURDFDemo/ImportURDFSetup.h @@ -2,6 +2,7 @@ #define IMPORT_URDF_SETUP_H -class CommonExampleInterface* ImportURDFCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* ImportURDFCreateFunc(struct CommonExampleOptions& options); + #endif //IMPORT_URDF_SETUP_H diff --git a/examples/MultiBody/MultiDofDemo.cpp b/examples/MultiBody/MultiDofDemo.cpp index e7a4fa585..8d7eb5a3f 100644 --- a/examples/MultiBody/MultiDofDemo.cpp +++ b/examples/MultiBody/MultiDofDemo.cpp @@ -29,6 +29,15 @@ public: virtual void stepSimulation(float deltaTime); + virtual void resetCamera() + { + float dist = 1; + float pitch = 50; + float yaw = 35; + float targetPos[3]={-3,2.8,-2.5}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + btMultiBody* createFeatherstoneMultiBody_testMultiDof(class btMultiBodyDynamicsWorld* world, int numLinks, const btVector3& basePosition, const btVector3 &baseHalfExtents, const btVector3 &linkHalfExtents, bool spherical = false, bool floating = false); void addColliders_testMultiDof(btMultiBody *pMultiBody, btMultiBodyDynamicsWorld *pWorld, const btVector3 &baseHalfExtents, const btVector3 &linkHalfExtents); @@ -76,6 +85,7 @@ void MultiDofDemo::stepSimulation(float deltaTime) void MultiDofDemo::initPhysics() { + m_guiHelper->setUpAxis(1); if(g_firstInit) @@ -100,7 +110,7 @@ void MultiDofDemo::initPhysics() btMultiBodyDynamicsWorld* world = new btMultiBodyDynamicsWorld(m_dispatcher,m_broadphase,sol,m_collisionConfiguration); m_dynamicsWorld = world; // m_dynamicsWorld->setDebugDrawer(&gDebugDraw); - + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); m_dynamicsWorld->setGravity(btVector3(0,-10,0)); ///create a few basic rigid bodies @@ -418,7 +428,7 @@ void MultiDofDemo::addBoxes_testMultiDof() } } -class CommonExampleInterface* MultiDofCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* MultiDofCreateFunc(struct CommonExampleOptions& options) { - return new MultiDofDemo(helper); + return new MultiDofDemo(options.m_guiHelper); } \ No newline at end of file diff --git a/examples/MultiBody/MultiDofDemo.h b/examples/MultiBody/MultiDofDemo.h index 4a5a54873..acf1a6db3 100644 --- a/examples/MultiBody/MultiDofDemo.h +++ b/examples/MultiBody/MultiDofDemo.h @@ -2,7 +2,7 @@ #ifndef MULTI_DOF_DEMO_H #define MULTI_DOF_DEMO_H -class CommonExampleInterface* MultiDofCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* MultiDofCreateFunc(struct CommonExampleOptions& options); #endif //MULTI_DOF_DEMO_H diff --git a/examples/MultiBody/TestJointTorqueSetup.cpp b/examples/MultiBody/TestJointTorqueSetup.cpp index 95bbc4db2..9d14ecbfd 100644 --- a/examples/MultiBody/TestJointTorqueSetup.cpp +++ b/examples/MultiBody/TestJointTorqueSetup.cpp @@ -18,6 +18,16 @@ public: virtual void stepSimulation(float deltaTime); + virtual void resetCamera() + { + float dist = 5; + float pitch = 270; + float yaw = 21; + float targetPos[3]={-1.34,3.4,-0.44}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + + }; TestJointTorqueSetup::TestJointTorqueSetup(struct GUIHelperInterface* helper) @@ -270,7 +280,7 @@ void TestJointTorqueSetup::stepSimulation(float deltaTime) } -class CommonExampleInterface* TestJointTorqueCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* TestJointTorqueCreateFunc(struct CommonExampleOptions& options) { - return new TestJointTorqueSetup(helper); + return new TestJointTorqueSetup(options.m_guiHelper); } \ No newline at end of file diff --git a/examples/MultiBody/TestJointTorqueSetup.h b/examples/MultiBody/TestJointTorqueSetup.h index 26cb530a2..5eed98a57 100644 --- a/examples/MultiBody/TestJointTorqueSetup.h +++ b/examples/MultiBody/TestJointTorqueSetup.h @@ -1,7 +1,7 @@ #ifndef TEST_JOINT_TORQUE_SETUP_H #define TEST_JOINT_TORQUE_SETUP_H -class CommonExampleInterface* TestJointTorqueCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* TestJointTorqueCreateFunc(struct CommonExampleOptions& options); #endif //TEST_JOINT_TORQUE_SETUP_H diff --git a/examples/OpenCL/broadphase/PairBench.cpp b/examples/OpenCL/broadphase/PairBench.cpp index b05bda95c..1eaecc667 100644 --- a/examples/OpenCL/broadphase/PairBench.cpp +++ b/examples/OpenCL/broadphase/PairBench.cpp @@ -32,14 +32,13 @@ #include "../OpenGLWindow/GLInstanceRendererInternalData.h" +char* gPairBenchFileName = 0; class PairBench : public CommonOpenCLBase { struct PairBenchInternalData* m_data; - GLInstancingRenderer* m_instancingRenderer; - public: PairBench(GUIHelperInterface* helper); @@ -56,6 +55,24 @@ public: virtual void stepSimulation(float deltaTime); virtual void renderScene(); + + virtual void resetCamera() + { + float dist = 10; + + if (gPairBenchFileName) + { + dist = 830; + } else + { + dist = 130; + } + + float pitch = 62; + float yaw = 33; + float targetPos[4]={15.5,12.5,15.5,0}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } }; @@ -67,7 +84,7 @@ public: -char* gPairBenchFileName = 0; + extern bool useShadowMap; float maxExtents = -1e30f; int largeCount = 0; @@ -143,7 +160,8 @@ PairBench::PairBench(GUIHelperInterface* helper) :CommonOpenCLBase(helper) { m_data = new PairBenchInternalData; - m_instancingRenderer = (GLInstancingRenderer*) helper->getRenderInterface(); + + m_data->m_validationBroadphase = 0; } PairBench::~PairBench() @@ -182,7 +200,7 @@ void PairBench::initPhysics() dimensions[1] = 10; dimensions[2] = 10; - //m_instancingRenderer = ci.m_instancingRenderer; + //m_guiHelper->getRenderInterface() = ci.m_guiHelper->getRenderInterface(); sPairDemo = this; useShadowMap = false; @@ -228,7 +246,7 @@ void PairBench::createBroadphase(int arraySizeX, int arraySizeY, int arraySizeZ) int strideInBytes = 9*sizeof(float); int numVertices = sizeof(cube_vertices)/strideInBytes; int numIndices = sizeof(cube_vertices)/sizeof(int); - int shapeId = m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); + int shapeId = m_guiHelper->getRenderInterface()->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); int group=1; int mask=1; int index=TEST_INDEX_OFFSET; @@ -316,12 +334,12 @@ void PairBench::createBroadphase(int arraySizeX, int arraySizeY, int arraySizeZ) if (l>500) { b3Vector4 color=b3MakeVector4(0,1,0,0.1); - int id = m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); + int id = m_guiHelper->getRenderInterface()->registerGraphicsInstance(shapeId,position,orn,color,scaling); m_data->m_broadphaseGPU->createLargeProxy(aabbMin,aabbMax,index,group,mask); } else { b3Vector4 color=b3MakeVector4(1,0,0,1); - int id = m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); + int id = m_guiHelper->getRenderInterface()->registerGraphicsInstance(shapeId,position,orn,color,scaling); m_data->m_broadphaseGPU->createProxy(aabbMin,aabbMax,index,group,mask); index++; } @@ -384,7 +402,7 @@ void PairBench::createBroadphase(int arraySizeX, int arraySizeY, int arraySizeZ) }*/ - int id = m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); + int id = m_guiHelper->getRenderInterface()->registerGraphicsInstance(shapeId,position,orn,color,scaling); b3Vector3 aabbMin = position-scaling; @@ -404,21 +422,13 @@ void PairBench::createBroadphase(int arraySizeX, int arraySizeY, int arraySizeZ) } } - float camPos[4]={15.5,12.5,15.5,0}; - m_instancingRenderer->getActiveCamera()->setCameraTargetPosition(camPos[0],camPos[1],camPos[2]); - if (gPairBenchFileName) - { - m_instancingRenderer->getActiveCamera()->setCameraDistance(830); - } else - { - m_instancingRenderer->getActiveCamera()->setCameraDistance(130); - } - m_instancingRenderer->writeTransforms(); + m_guiHelper->getRenderInterface()->writeTransforms(); m_data->m_broadphaseGPU->writeAabbsToGpu(); } + void PairBench::deleteBroadphase() { delete m_data->m_broadphaseGPU; @@ -429,11 +439,13 @@ void PairBench::deleteBroadphase() m_data->m_bodyTimes = 0; m_data->m_broadphaseGPU = 0; - m_instancingRenderer->removeAllInstances(); + m_guiHelper->getRenderInterface()->removeAllInstances(); } void PairBench::exitPhysics() { + //reset the state to 'on' + useShadowMap = true; if(m_data->m_validationBroadphase) { delete m_data->m_validationBroadphase; @@ -449,7 +461,7 @@ void PairBench::exitPhysics() void PairBench::renderScene() { - m_instancingRenderer->renderScene(); + m_guiHelper->getRenderInterface()->renderScene(); } struct OverlappingPairSortPredicate @@ -467,17 +479,23 @@ void PairBench::stepSimulation(float deltaTime) { //color all objects blue + GLInstanceRendererInternalData* internalData = m_guiHelper->getRenderInterface()->getInternalData(); + + if (internalData==0) + return; + + bool animate=true; int numObjects= 0; { B3_PROFILE("Num Objects"); - numObjects = m_instancingRenderer->getInternalData()->m_totalNumInstances; + numObjects = internalData->m_totalNumInstances; } b3Vector4* positions = 0; if (numObjects) { B3_PROFILE("Sync"); - GLuint vbo = m_instancingRenderer->getInternalData()->m_vbo; + GLuint vbo = internalData->m_vbo; @@ -488,7 +506,7 @@ void PairBench::stepSimulation(float deltaTime) char* hostPtr= 0; { B3_PROFILE("glMapBufferRange"); - hostPtr = (char*)glMapBufferRange( GL_ARRAY_BUFFER,m_instancingRenderer->getMaxShapeCapacity(),arraySizeInBytes, GL_MAP_WRITE_BIT|GL_MAP_READ_BIT );//GL_READ_WRITE);//GL_WRITE_ONLY + hostPtr = (char*)glMapBufferRange( GL_ARRAY_BUFFER,internalData->m_maxShapeCapacityInBytes,arraySizeInBytes, GL_MAP_WRITE_BIT|GL_MAP_READ_BIT );//GL_READ_WRITE);//GL_WRITE_ONLY } GLint err = glGetError(); assert(err==GL_NO_ERROR); @@ -767,7 +785,7 @@ void PairBench::stepSimulation(float deltaTime) } -class CommonExampleInterface* PairBenchOpenCLCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* PairBenchOpenCLCreateFunc(struct CommonExampleOptions& options) { - return new PairBench(helper); + return new PairBench(options.m_guiHelper); } diff --git a/examples/OpenCL/broadphase/PairBench.h b/examples/OpenCL/broadphase/PairBench.h index def128055..a9706614d 100644 --- a/examples/OpenCL/broadphase/PairBench.h +++ b/examples/OpenCL/broadphase/PairBench.h @@ -1,7 +1,7 @@ #ifndef PAIR_BENCH_H #define PAIR_BENCH_H -class CommonExampleInterface* PairBenchOpenCLCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* PairBenchOpenCLCreateFunc(struct CommonExampleOptions& options); #endif diff --git a/examples/OpenGLWindow/GLInstanceRendererInternalData.h b/examples/OpenGLWindow/GLInstanceRendererInternalData.h index 3cc24b47f..8594e778d 100644 --- a/examples/OpenGLWindow/GLInstanceRendererInternalData.h +++ b/examples/OpenGLWindow/GLInstanceRendererInternalData.h @@ -15,6 +15,9 @@ struct GLInstanceRendererInternalData int m_vboSize; GLuint m_vbo; int m_totalNumInstances; + int m_maxNumObjectCapacity; + int m_maxShapeCapacityInBytes; + }; #endif //GL_INSTANCE_RENDERER_INTERNAL_DATA_H diff --git a/examples/OpenGLWindow/GLInstancingRenderer.cpp b/examples/OpenGLWindow/GLInstancingRenderer.cpp index 11709002e..faae50d41 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.cpp +++ b/examples/OpenGLWindow/GLInstancingRenderer.cpp @@ -152,6 +152,7 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData GLRenderToTexture* m_shadowMap; GLuint m_shadowTexture; + InternalDataRenderer() : m_shadowMap(0), m_shadowTexture(0) @@ -223,8 +224,7 @@ static GLint ProjectionMatrixPointSprite=0; GLInstancingRenderer::GLInstancingRenderer(int maxNumObjectCapacity, int maxShapeCapacityInBytes) - :m_maxNumObjectCapacity(maxNumObjectCapacity), - m_maxShapeCapacityInBytes(maxShapeCapacityInBytes), + : m_textureenabled(true), m_textureinitialized(false), m_screenWidth(0), @@ -234,14 +234,17 @@ GLInstancingRenderer::GLInstancingRenderer(int maxNumObjectCapacity, int maxShap { m_data = new InternalDataRenderer; + m_data->m_maxNumObjectCapacity = maxNumObjectCapacity; + m_data->m_maxShapeCapacityInBytes=maxShapeCapacityInBytes; + m_data->m_totalNumInstances = 0; sData2 = m_data; - m_data->m_instance_positions_ptr.resize(m_maxNumObjectCapacity*4); - m_data->m_instance_quaternion_ptr.resize(m_maxNumObjectCapacity*4); - m_data->m_instance_colors_ptr.resize(m_maxNumObjectCapacity*4); - m_data->m_instance_scale_ptr.resize(m_maxNumObjectCapacity*3); + m_data->m_instance_positions_ptr.resize(m_data->m_maxNumObjectCapacity*4); + m_data->m_instance_quaternion_ptr.resize(m_data->m_maxNumObjectCapacity*4); + m_data->m_instance_colors_ptr.resize(m_data->m_maxNumObjectCapacity*4); + m_data->m_instance_scale_ptr.resize(m_data->m_maxNumObjectCapacity*3); } @@ -346,8 +349,8 @@ void GLInstancingRenderer::writeSingleInstanceTransformToGPU(float* position, fl char* base = orgBase; - float* positions = (float*)(base+m_maxShapeCapacityInBytes); - float* orientations = (float*)(base+m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE); + float* positions = (float*)(base+m_data->m_maxShapeCapacityInBytes); + float* orientations = (float*)(base+m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE); positions[objectIndex*4] = position[0]; @@ -406,10 +409,10 @@ void GLInstancingRenderer::writeTransforms() char* base = orgBase; - float* positions = (float*)(base+m_maxShapeCapacityInBytes); - float* orientations = (float*)(base+m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE); - float* colors= (float*)(base+m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE); - float* scaling= (float*)(base+m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE+COLOR_BUFFER_SIZE); + float* positions = (float*)(base+m_data->m_maxShapeCapacityInBytes); + float* orientations = (float*)(base+m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE); + float* colors= (float*)(base+m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE); + float* scaling= (float*)(base+m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE+COLOR_BUFFER_SIZE); //static int offset=0; //offset++; @@ -470,7 +473,7 @@ int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const double* int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling) { b3Assert(shapeIndex == (m_graphicsInstances.size()-1)); - b3Assert(m_graphicsInstances.size()m_maxNumObjectCapacity-1); b3GraphicsInstance* gfxObj = m_graphicsInstances[shapeIndex]; @@ -579,7 +582,7 @@ int GLInstancingRenderer::registerShape(const float* vertices, int numvertices, int sz = numvertices*vertexStrideInBytes; #ifdef B3_DEBUG int totalUsed = vertexStrideInBytes*gfxObj->m_vertexArrayOffset+sz; - b3Assert(totalUsedm_maxShapeCapacityInBytes); + b3Assert(totalUsedm_maxShapeCapacityInBytes); #endif//B3_DEBUG memcpy(dest+vertexStrideInBytes*gfxObj->m_vertexArrayOffset,vertices,sz); @@ -611,10 +614,10 @@ int GLInstancingRenderer::registerShape(const float* vertices, int numvertices, void GLInstancingRenderer::InitShaders() { - int POSITION_BUFFER_SIZE = (m_maxNumObjectCapacity*sizeof(float)*4); - int ORIENTATION_BUFFER_SIZE = (m_maxNumObjectCapacity*sizeof(float)*4); - int COLOR_BUFFER_SIZE = (m_maxNumObjectCapacity*sizeof(float)*4); - int SCALE_BUFFER_SIZE = (m_maxNumObjectCapacity*sizeof(float)*3); + int POSITION_BUFFER_SIZE = (m_data->m_maxNumObjectCapacity*sizeof(float)*4); + int ORIENTATION_BUFFER_SIZE = (m_data->m_maxNumObjectCapacity*sizeof(float)*4); + int COLOR_BUFFER_SIZE = (m_data->m_maxNumObjectCapacity*sizeof(float)*4); + int SCALE_BUFFER_SIZE = (m_data->m_maxNumObjectCapacity*sizeof(float)*3); linesShader = gltLoadShaderPair(linesVertexShader,linesFragmentShader); lines_ModelViewMatrix = glGetUniformLocation(linesShader, "ModelViewMatrix"); @@ -702,7 +705,7 @@ void GLInstancingRenderer::InitShaders() glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo); - int size = m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE+COLOR_BUFFER_SIZE+SCALE_BUFFER_SIZE; + int size = m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE+COLOR_BUFFER_SIZE+SCALE_BUFFER_SIZE; m_data->m_vboSize = size; glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW);//GL_STATIC_DRAW); @@ -1460,8 +1463,8 @@ b3Assert(glGetError() ==GL_NO_ERROR); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 9*sizeof(float), vertex.m_pointer); - glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_maxShapeCapacityInBytes)); - glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE)); + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_data->m_maxShapeCapacityInBytes)); + glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_data->m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE)); PointerCaster uv; uv.m_baseIndex = 7*sizeof(float)+vertex.m_baseIndex; @@ -1471,8 +1474,8 @@ b3Assert(glGetError() ==GL_NO_ERROR); glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 9*sizeof(float), uv.m_pointer); glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 9*sizeof(float), normal.m_pointer); - glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE)); - glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*3*sizeof(float)+m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE+COLOR_BUFFER_SIZE)); + glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_data->m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE)); + glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*3*sizeof(float)+m_data->m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE+COLOR_BUFFER_SIZE)); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); @@ -1630,3 +1633,11 @@ void GLInstancingRenderer::enableShadowMap() } +int GLInstancingRenderer::getMaxShapeCapacity() const +{ + return m_data->m_maxShapeCapacityInBytes; +} +int GLInstancingRenderer::getInstanceCapacity() const +{ + return m_data->m_maxNumObjectCapacity; +} diff --git a/examples/OpenGLWindow/GLInstancingRenderer.h b/examples/OpenGLWindow/GLInstancingRenderer.h index 97ab43a86..98b29b8bb 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.h +++ b/examples/OpenGLWindow/GLInstancingRenderer.h @@ -29,8 +29,7 @@ class GLInstancingRenderer : public CommonRenderInterface b3AlignedObjectArray m_graphicsInstances; - int m_maxNumObjectCapacity; - int m_maxShapeCapacityInBytes; + struct InternalDataRenderer* m_data; bool m_textureenabled; @@ -94,7 +93,7 @@ public: virtual void writeSingleInstanceColorToCPU(double* color, int srcIndex); - struct GLInstanceRendererInternalData* getInternalData(); + virtual struct GLInstanceRendererInternalData* getInternalData(); virtual void drawLine(const float from[4], const float to[4], const float color[4], float lineWidth=1); virtual void drawLine(const double from[4], const double to[4], const double color[4], double lineWidth=1); @@ -119,14 +118,10 @@ public: return m_screenHeight; } - virtual int getMaxShapeCapacity() const - { - return m_maxShapeCapacityInBytes; - } - virtual int getInstanceCapacity() const - { - return m_maxNumObjectCapacity; - } + virtual int getMaxShapeCapacity() const; + + virtual int getInstanceCapacity() const; + virtual void enableShadowMap(); virtual void enableBlend(bool blend) { diff --git a/examples/OpenGLWindow/SimpleOpenGL2Renderer.h b/examples/OpenGLWindow/SimpleOpenGL2Renderer.h index 766d0a2e4..c92c529a9 100644 --- a/examples/OpenGLWindow/SimpleOpenGL2Renderer.h +++ b/examples/OpenGLWindow/SimpleOpenGL2Renderer.h @@ -71,6 +71,11 @@ struct SimpleOpenGL2Renderer : public CommonRenderInterface virtual void updateShape(int shapeIndex, const float* vertices); virtual void enableBlend(bool blend); + + virtual struct GLInstanceRendererInternalData* getInternalData() + { + return 0; + } }; #endif //SIMPLE_OPENGL2_RENDERER_H diff --git a/examples/Planar2D/Planar2D.cpp b/examples/Planar2D/Planar2D.cpp index c74c21744..c9fa4959f 100644 --- a/examples/Planar2D/Planar2D.cpp +++ b/examples/Planar2D/Planar2D.cpp @@ -93,7 +93,14 @@ class Planar2D : public CommonRigidBodyBase void exitPhysics(); - + void resetCamera() + { + float dist = 9; + float pitch = 539; + float yaw = 11; + float targetPos[3]={8.6,10.5,-20.6}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } }; @@ -325,7 +332,7 @@ void Planar2D::exitPhysics() m_box2dbox2dAlgo = 0; } -CommonExampleInterface* Planar2DCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +CommonExampleInterface* Planar2DCreateFunc(struct CommonExampleOptions& options) { - return new Planar2D(helper); + return new Planar2D(options.m_guiHelper); } diff --git a/examples/Planar2D/Planar2D.h b/examples/Planar2D/Planar2D.h index cdae4d6b4..0759bba6e 100644 --- a/examples/Planar2D/Planar2D.h +++ b/examples/Planar2D/Planar2D.h @@ -15,7 +15,7 @@ subject to the following restrictions: #ifndef PLANAR2D_H #define PLANAR2D_H -class CommonExampleInterface* Planar2DCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* Planar2DCreateFunc(struct CommonExampleOptions& options); #endif //BOX2D_DEMO_H diff --git a/examples/Raycast/RaytestDemo.cpp b/examples/Raycast/RaytestDemo.cpp index ad27bc3d0..1c4318186 100644 --- a/examples/Raycast/RaytestDemo.cpp +++ b/examples/Raycast/RaytestDemo.cpp @@ -52,7 +52,14 @@ public: virtual void stepSimulation(float deltaTime); - + virtual void resetCamera() + { + float dist = 18; + float pitch = 129; + float yaw = 30; + float targetPos[3]={-4.6,-4.7,-5.75}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } }; @@ -147,6 +154,7 @@ void RaytestDemo::castRays() void RaytestDemo::initPhysics() { + m_guiHelper->setUpAxis(1); ///collision configuration contains default setup for memory, collision setup m_collisionConfiguration = new btDefaultCollisionConfiguration(); @@ -318,9 +326,9 @@ void RaytestDemo::exitPhysics() } -class CommonExampleInterface* RaytestCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* RaytestCreateFunc(struct CommonExampleOptions& options) { - return new RaytestDemo(helper); + return new RaytestDemo(options.m_guiHelper); } diff --git a/examples/Raycast/RaytestDemo.h b/examples/Raycast/RaytestDemo.h index 5d647379d..3b9eaf7fc 100644 --- a/examples/Raycast/RaytestDemo.h +++ b/examples/Raycast/RaytestDemo.h @@ -15,7 +15,7 @@ subject to the following restrictions: #ifndef BT_RAYTEST_DEMO_H #define BT_RAYTEST_DEMO_H -class CommonExampleInterface* RaytestCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* RaytestCreateFunc(struct CommonExampleOptions& options); #endif //BT_RAYTEST_DEMO_H diff --git a/examples/RenderingExamples/CoordinateSystemDemo.cpp b/examples/RenderingExamples/CoordinateSystemDemo.cpp index ed8df0677..37ecc7f30 100644 --- a/examples/RenderingExamples/CoordinateSystemDemo.cpp +++ b/examples/RenderingExamples/CoordinateSystemDemo.cpp @@ -138,11 +138,26 @@ public: { return false; } - + + + virtual void resetCamera() + { + float dist = 3.5; + float pitch = 136; + float yaw = 32; + float targetPos[3]={0,0,0}; + if (m_app->m_renderer && m_app->m_renderer->getActiveCamera()) + { + m_app->m_renderer->getActiveCamera()->setCameraDistance(dist); + m_app->m_renderer->getActiveCamera()->setCameraPitch(pitch); + m_app->m_renderer->getActiveCamera()->setCameraYaw(yaw); + m_app->m_renderer->getActiveCamera()->setCameraTargetPosition(targetPos[0],targetPos[1],targetPos[2]); + } + } }; -struct CommonExampleInterface* CoordinateSystemCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +struct CommonExampleInterface* CoordinateSystemCreateFunc(struct CommonExampleOptions& options) { - return new CoordinateSystemDemo(helper->getAppInterface()); + return new CoordinateSystemDemo(options.m_guiHelper->getAppInterface()); } diff --git a/examples/RenderingExamples/CoordinateSystemDemo.h b/examples/RenderingExamples/CoordinateSystemDemo.h index 8e3085c72..b560a199b 100644 --- a/examples/RenderingExamples/CoordinateSystemDemo.h +++ b/examples/RenderingExamples/CoordinateSystemDemo.h @@ -1,7 +1,7 @@ #ifndef COORDINATE_SYSTEM_DEMO_H #define COORDINATE_SYSTEM_DEMO_H -class CommonExampleInterface* CoordinateSystemCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* CoordinateSystemCreateFunc(struct CommonExampleOptions& options); #endif //COORDINATE_SYSTEM_DEMO_H diff --git a/examples/RenderingExamples/RaytracerSetup.cpp b/examples/RenderingExamples/RaytracerSetup.cpp index 859f0f64a..2aba3f32f 100644 --- a/examples/RenderingExamples/RaytracerSetup.cpp +++ b/examples/RenderingExamples/RaytracerSetup.cpp @@ -378,7 +378,7 @@ void RaytracerPhysicsSetup::syncPhysicsToGraphics(GraphicsPhysicsBridge& gfxBrid { } - CommonExampleInterface* RayTracerCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) + CommonExampleInterface* RayTracerCreateFunc(struct CommonExampleOptions& options) { - return new RaytracerPhysicsSetup(helper->getAppInterface()); + return new RaytracerPhysicsSetup(options.m_guiHelper->getAppInterface()); } diff --git a/examples/RenderingExamples/RaytracerSetup.h b/examples/RenderingExamples/RaytracerSetup.h index f3692af33..473c300eb 100644 --- a/examples/RenderingExamples/RaytracerSetup.h +++ b/examples/RenderingExamples/RaytracerSetup.h @@ -1,6 +1,6 @@ #ifndef RAYTRACER_SETUP_H #define RAYTRACER_SETUP_H -class CommonExampleInterface* RayTracerCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* RayTracerCreateFunc(struct CommonExampleOptions& options); #endif //RAYTRACER_SETUP_H diff --git a/examples/RenderingExamples/RenderInstancingDemo.cpp b/examples/RenderingExamples/RenderInstancingDemo.cpp index 61d0d37cc..aa0d40f2b 100644 --- a/examples/RenderingExamples/RenderInstancingDemo.cpp +++ b/examples/RenderingExamples/RenderInstancingDemo.cpp @@ -125,12 +125,27 @@ public: return false; } + virtual void resetCamera() + { + float dist = 13; + float pitch = 50; + float yaw = 13; + float targetPos[3]={-1,0,-0.3}; + if (m_app->m_renderer && m_app->m_renderer->getActiveCamera()) + { + m_app->m_renderer->getActiveCamera()->setCameraDistance(dist); + m_app->m_renderer->getActiveCamera()->setCameraPitch(pitch); + m_app->m_renderer->getActiveCamera()->setCameraYaw(yaw); + m_app->m_renderer->getActiveCamera()->setCameraTargetPosition(targetPos[0],targetPos[1],targetPos[2]); + } + } + }; -class CommonExampleInterface* RenderInstancingCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* RenderInstancingCreateFunc(struct CommonExampleOptions& options) { - return new RenderInstancingDemo(helper->getAppInterface()); + return new RenderInstancingDemo(options.m_guiHelper->getAppInterface()); } #endif //RENDER_INSTANCING_DEMO_H diff --git a/examples/RenderingExamples/RenderInstancingDemo.h b/examples/RenderingExamples/RenderInstancingDemo.h index e71136c22..2ae9ac91e 100644 --- a/examples/RenderingExamples/RenderInstancingDemo.h +++ b/examples/RenderingExamples/RenderInstancingDemo.h @@ -1,6 +1,6 @@ #ifndef RENDER_INSTANCING_DEMO_H #define RENDER_INSTANCING_DEMO_H -class CommonExampleInterface* RenderInstancingCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* RenderInstancingCreateFunc(struct CommonExampleOptions& options); #endif //RENDER_INSTANCING_DEMO_H diff --git a/examples/SoftDemo/SoftDemo.cpp b/examples/SoftDemo/SoftDemo.cpp index 67ee63d6e..68d4a9e9e 100644 --- a/examples/SoftDemo/SoftDemo.cpp +++ b/examples/SoftDemo/SoftDemo.cpp @@ -103,6 +103,16 @@ public: void exitPhysics(); + virtual void resetCamera() + { + //@todo depends on current_demo? + float dist = 45; + float pitch = 27; + float yaw = 31; + float targetPos[3]={10-1,0}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + SoftDemo(struct GUIHelperInterface* helper) : CommonRigidBodyBase(helper), m_drag(false) @@ -2322,10 +2332,10 @@ void SoftDemo::exitPhysics() } -class CommonExampleInterface* SoftDemoCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +class CommonExampleInterface* SoftDemoCreateFunc(struct CommonExampleOptions& options) { - current_demo = option; - return new SoftDemo(helper); + current_demo = options.m_option; + return new SoftDemo(options.m_guiHelper); } diff --git a/examples/SoftDemo/SoftDemo.h b/examples/SoftDemo/SoftDemo.h index c2d974ecb..e1cd2ddec 100644 --- a/examples/SoftDemo/SoftDemo.h +++ b/examples/SoftDemo/SoftDemo.h @@ -19,7 +19,7 @@ subject to the following restrictions: #ifndef SOFT_DEMO_H #define SOFT_DEMO_H -class CommonExampleInterface* SoftDemoCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* SoftDemoCreateFunc(struct CommonExampleOptions& options); #endif //CCD_PHYSICS_DEMO_H diff --git a/examples/Vehicles/Hinge2Vehicle.cpp b/examples/Vehicles/Hinge2Vehicle.cpp index ec4f7fcbd..1ed665190 100644 --- a/examples/Vehicles/Hinge2Vehicle.cpp +++ b/examples/Vehicles/Hinge2Vehicle.cpp @@ -118,6 +118,15 @@ class Hinge2Vehicle : public CommonRigidBodyBase void initPhysics(); void exitPhysics(); + virtual void resetCamera() + { + float dist = 8; + float pitch = -45; + float yaw = 32; + float targetPos[3]={-0.33,-0.72,4.5}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + /*static DemoApplication* Create() { Hinge2Vehicle* demo = new Hinge2Vehicle(); @@ -1170,7 +1179,7 @@ btRigidBody* Hinge2Vehicle::localCreateRigidBody(btScalar mass, const btTransfor return body; } -CommonExampleInterface* Hinge2VehicleCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) +CommonExampleInterface* Hinge2VehicleCreateFunc(struct CommonExampleOptions& options) { - return new Hinge2Vehicle(helper); + return new Hinge2Vehicle(options.m_guiHelper); } diff --git a/examples/Vehicles/Hinge2Vehicle.h b/examples/Vehicles/Hinge2Vehicle.h index 30e347a96..02af743bd 100644 --- a/examples/Vehicles/Hinge2Vehicle.h +++ b/examples/Vehicles/Hinge2Vehicle.h @@ -16,7 +16,7 @@ subject to the following restrictions: #ifndef HINGE2_VEHICLE_H #define HINGE2_VEHICLE_H -class CommonExampleInterface* Hinge2VehicleCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* Hinge2VehicleCreateFunc(struct CommonExampleOptions& options); #endif // HINGE2_VEHICLE_H diff --git a/examples/VoronoiFracture/VoronoiFractureDemo.cpp b/examples/VoronoiFracture/VoronoiFractureDemo.cpp index c3926b2ad..e9d097bb4 100644 --- a/examples/VoronoiFracture/VoronoiFractureDemo.cpp +++ b/examples/VoronoiFracture/VoronoiFractureDemo.cpp @@ -105,7 +105,14 @@ class VoronoiFractureDemo : public CommonRigidBodyBase void attachFixedConstraints(); - + virtual void resetCamera() + { + float dist = 18; + float pitch = 129; + float yaw = 30; + float targetPos[3]={-1.5,4.7,-2}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } }; @@ -817,7 +824,7 @@ static DemoApplication* Create() */ -CommonExampleInterface* VoronoiFractureCreateFunc(PhysicsInterface* pint, GUIHelperInterface* helper, int option) +CommonExampleInterface* VoronoiFractureCreateFunc(struct CommonExampleOptions& options) { - return new VoronoiFractureDemo(helper); + return new VoronoiFractureDemo(options.m_guiHelper); } diff --git a/examples/VoronoiFracture/VoronoiFractureDemo.h b/examples/VoronoiFracture/VoronoiFractureDemo.h index de8b8f8bb..dd0a2c166 100644 --- a/examples/VoronoiFracture/VoronoiFractureDemo.h +++ b/examples/VoronoiFracture/VoronoiFractureDemo.h @@ -15,7 +15,7 @@ subject to the following restrictions: #ifndef VORONOI_FRACTURE_DEMO_H #define VORONOI_FRACTURE_DEMO_H -class CommonExampleInterface* VoronoiFractureCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option); +class CommonExampleInterface* VoronoiFractureCreateFunc(struct CommonExampleOptions& options); #endif //VORONOI_FRACTURE_DEMO_H