From 5151519b9494e7b33e3868f300ea848bb9b3e16d Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Fri, 6 May 2016 15:07:54 -0700 Subject: [PATCH 1/2] https://github.com/bulletphysics/bullet3/pull/618 by Mobeen Summary of changes: 1) Changed include paths to be relative to the current sources (affected files: LoadMeshFromObj.cpp, Wavefront2GLInstanceGraphicsShape.h/cpp) 2) Added new tutorials in the ExtendedTutorials folder 3) Modified the main_opengl_single_example.cpp file to enable picking support in standalone demos --- examples/ExampleBrowser/CMakeLists.txt | 11 +- examples/ExampleBrowser/ExampleEntries.cpp | 30 +++- examples/ExampleBrowser/premake4.lua | 1 + examples/ExtendedTutorials/Bridge.cpp | 150 ++++++++++++++++ examples/ExtendedTutorials/Bridge.h | 22 +++ examples/ExtendedTutorials/Chain.cpp | 137 +++++++++++++++ examples/ExtendedTutorials/Chain.h | 22 +++ examples/ExtendedTutorials/MultipleBoxes.cpp | 120 +++++++++++++ examples/ExtendedTutorials/MultipleBoxes.h | 22 +++ .../ExtendedTutorials/RigidBodyFromObj.cpp | 159 +++++++++++++++++ examples/ExtendedTutorials/RigidBodyFromObj.h | 28 +++ examples/ExtendedTutorials/SimpleBox.cpp | 118 +++++++++++++ examples/ExtendedTutorials/SimpleBox.h | 22 +++ examples/ExtendedTutorials/SimpleCloth.cpp | 162 ++++++++++++++++++ examples/ExtendedTutorials/SimpleCloth.h | 22 +++ examples/ExtendedTutorials/SimpleJoint.cpp | 133 ++++++++++++++ examples/ExtendedTutorials/SimpleJoint.h | 22 +++ .../main_opengl_single_example.cpp | 33 +++- 18 files changed, 1206 insertions(+), 8 deletions(-) create mode 100644 examples/ExtendedTutorials/Bridge.cpp create mode 100644 examples/ExtendedTutorials/Bridge.h create mode 100644 examples/ExtendedTutorials/Chain.cpp create mode 100644 examples/ExtendedTutorials/Chain.h create mode 100644 examples/ExtendedTutorials/MultipleBoxes.cpp create mode 100644 examples/ExtendedTutorials/MultipleBoxes.h create mode 100644 examples/ExtendedTutorials/RigidBodyFromObj.cpp create mode 100644 examples/ExtendedTutorials/RigidBodyFromObj.h create mode 100644 examples/ExtendedTutorials/SimpleBox.cpp create mode 100644 examples/ExtendedTutorials/SimpleBox.h create mode 100644 examples/ExtendedTutorials/SimpleCloth.cpp create mode 100644 examples/ExtendedTutorials/SimpleCloth.h create mode 100644 examples/ExtendedTutorials/SimpleJoint.cpp create mode 100644 examples/ExtendedTutorials/SimpleJoint.h diff --git a/examples/ExampleBrowser/CMakeLists.txt b/examples/ExampleBrowser/CMakeLists.txt index b3f06d557..68ffa8f0a 100644 --- a/examples/ExampleBrowser/CMakeLists.txt +++ b/examples/ExampleBrowser/CMakeLists.txt @@ -7,7 +7,15 @@ INCLUDE_DIRECTORIES( FILE(GLOB GwenGUISupport_SRCS "GwenGUISupport/*" ) FILE(GLOB GwenGUISupport_HDRS "GwenGUISupport/*" ) - +SET(ExtendedTutorialsSources + ../ExtendedTutorials/SimpleBox.cpp + ../ExtendedTutorials/MultipleBoxes.cpp + ../ExtendedTutorials/SimpleJoint.cpp + ../ExtendedTutorials/SimpleCloth.cpp + ../ExtendedTutorials/Chain.cpp + ../ExtendedTutorials/Bridge.cpp + ../ExtendedTutorials/RigidBodyFromObj.cpp +) SET(BulletExampleBrowser_SRCS OpenGLExampleBrowser.cpp @@ -178,6 +186,7 @@ SET(BulletExampleBrowser_SRCS ../Utils/b3ResourcePath.h ${GwenGUISupport_SRCS} ${GwenGUISupport_HDRS} + ${ExtendedTutorialsSources} ${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc ) diff --git a/examples/ExampleBrowser/ExampleEntries.cpp b/examples/ExampleBrowser/ExampleEntries.cpp index 08f71cf69..20b14ef8a 100644 --- a/examples/ExampleBrowser/ExampleEntries.cpp +++ b/examples/ExampleBrowser/ExampleEntries.cpp @@ -54,7 +54,14 @@ #endif #endif //B3_USE_CLEW - +//Extended Tutorial Includes Added by Mobeen +#include "../ExtendedTutorials/SimpleBox.h" +#include "../ExtendedTutorials/MultipleBoxes.h" +#include "../ExtendedTutorials/SimpleJoint.h" +#include "../ExtendedTutorials/SimpleCloth.h" +#include "../ExtendedTutorials/Chain.h" +#include "../ExtendedTutorials/Bridge.h" +#include "../ExtendedTutorials/RigidBodyFromObj.h" struct ExampleEntry { @@ -78,11 +85,12 @@ struct ExampleEntry static ExampleEntry gDefaultExamples[]= { - - - - + ExampleEntry(0,"API"), + ExampleEntry(1,"Obj2RigidBody (Show Obj)", "Load a triangle mesh from Wavefront .obj and turn it in a convex hull collision shape, connected to a rigid body. We can use the original .obj mesh data to visualize the rigid body. In 'debug' wireframe mode (press 'w' to toggle) we still see the convex hull data.", ET_RigidBodyFromObjCreateFunc,ObjUseConvexHullForRendering), + ExampleEntry(1,"Obj2RigidBody (Show Hull)", "Load a triangle mesh from Wavefront .obj and turn it in a convex hull collision shape, connected to a rigid body", ET_RigidBodyFromObjCreateFunc), + ExampleEntry(1,"Obj2RigidBody Optimize", "Load a triangle mesh from Wavefront .obj, remove the vertices that are not on the convex hull", ET_RigidBodyFromObjCreateFunc,OptimizeConvexObj), + ExampleEntry(1,"Obj2RigidBody Add Features", "Load a triangle mesh from Wavefront .obj and create polyhedral features to perform the separating axis test (instead of GJK/MPR). It is best to combine optimization and polyhedral feature generation.", ET_RigidBodyFromObjCreateFunc,OptimizeConvexObj+ComputePolyhedralFeatures), ExampleEntry(1,"Basic Example","Create some rigid bodies using box collision shapes. This is a good example to familiarize with the basic initialization of Bullet. The Basic Example can also be compiled without graphical user interface, as a console application. Press W for wireframe, A to show AABBs, I to suspend/restart physics simulation. Press D to toggle auto-deactivation of the simulation. ", BasicExampleCreateFunc), @@ -252,8 +260,18 @@ static ExampleEntry gDefaultExamples[]= 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), - ExampleEntry(1,"Time Series", "Render some value(s) in a 2D graph window, shifting to the left", TimeSeriesCreateFunc) + ExampleEntry(1,"Time Series", "Render some value(s) in a 2D graph window, shifting to the left", TimeSeriesCreateFunc), + //Extended Tutorials Added by Mobeen + ExampleEntry(0,"Extended Tutorials"), + ExampleEntry(1,"Simple Box", "Simplest possible demo creating a single box rigid body that falls under gravity", ET_SimpleBoxCreateFunc), + ExampleEntry(1,"Multiple Boxes", "Adding multiple box rigid bodies that fall under gravity", ET_MultipleBoxesCreateFunc), + ExampleEntry(1,"Simple Joint", "Creating a single distance constraint between two box rigid bodies", ET_SimpleJointCreateFunc), + ExampleEntry(1,"Simple Cloth", "Creating a simple piece of cloth", ET_SimpleClothCreateFunc), + ExampleEntry(1,"Simple Chain", "Creating a simple chain using a pair of point2point/distance constraints. You may click and drag any box to see the chain respond.", ET_ChainCreateFunc), + ExampleEntry(1,"Simple Bridge", "Creating a simple bridge using a pair of point2point/distance constraints. You may click and drag any plank to see the bridge respond.", ET_BridgeCreateFunc), + + }; #ifdef B3_USE_CLEW diff --git a/examples/ExampleBrowser/premake4.lua b/examples/ExampleBrowser/premake4.lua index f671d5a0d..5bbbf51f7 100644 --- a/examples/ExampleBrowser/premake4.lua +++ b/examples/ExampleBrowser/premake4.lua @@ -136,6 +136,7 @@ project "BulletExampleBrowserLib" "../InverseDynamics/InverseDynamicsExample.h", "../BasicDemo/BasicExample.*", "../Tutorial/*", + "../ExtendedTutorials/*", "../Collision/*", "../Collision/Internal/*", "../Benchmarks/*", diff --git a/examples/ExtendedTutorials/Bridge.cpp b/examples/ExtendedTutorials/Bridge.cpp new file mode 100644 index 000000000..269b5c4d0 --- /dev/null +++ b/examples/ExtendedTutorials/Bridge.cpp @@ -0,0 +1,150 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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 "Bridge.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + +const int TOTAL_PLANKS = 10; +struct BridgeExample : public CommonRigidBodyBase +{ + BridgeExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~BridgeExample(){} + 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 BridgeExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + //create two fixed boxes to hold the planks + + + + { + //create a few dynamic rigidbodies + // Re-using the same collision is better for memory usage and performance + btScalar plankWidth = 0.4; + btScalar plankHeight = 0.2; + btScalar plankBreadth = 1; + btScalar plankOffset = plankWidth; //distance between two planks + btScalar bridgeWidth = plankWidth*TOTAL_PLANKS + plankOffset*(TOTAL_PLANKS-1); + btScalar bridgeHeight = 5; + btScalar halfBridgeWidth = bridgeWidth*0.5f; + + btBoxShape* colShape = createBoxShape(btVector3(plankWidth,plankHeight,plankBreadth)); + + m_collisionShapes.push_back(colShape); + + /// Create Dynamic Objects + btTransform startTransform; + startTransform.setIdentity(); + + btScalar mass(1.f); + + //rigidbody is dynamic if and only if mass is non zero, otherwise static + bool isDynamic = (mass != 0.f); + + btVector3 localInertia(0,0,0); + if (isDynamic) + colShape->calculateLocalInertia(mass,localInertia); + + //create a set of boxes to represent bridge + btAlignedObjectArray boxes; + int lastBoxIndex = TOTAL_PLANKS-1; + for(int i=0;iaddConstraint(leftSpring); + + btPoint2PointConstraint* rightSpring = new btPoint2PointConstraint(*b1, *b2, btVector3(-0.5,0,0.5), btVector3(0.5,0,0.5)); + m_dynamicsWorld->addConstraint(rightSpring); + } + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void BridgeExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_BridgeCreateFunc(CommonExampleOptions& options) +{ + return new BridgeExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/Bridge.h b/examples/ExtendedTutorials/Bridge.h new file mode 100644 index 000000000..5f8331183 --- /dev/null +++ b/examples/ExtendedTutorials/Bridge.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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. +*/ + +#ifndef ET_BRIDGE_EXAMPLE_H +#define ET_BRIDGE_EXAMPLE_H + +class CommonExampleInterface* ET_BridgeCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_BRIDGE_EXAMPLE_H diff --git a/examples/ExtendedTutorials/Chain.cpp b/examples/ExtendedTutorials/Chain.cpp new file mode 100644 index 000000000..e78952db9 --- /dev/null +++ b/examples/ExtendedTutorials/Chain.cpp @@ -0,0 +1,137 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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 "Chain.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + +const int TOTAL_BOXES = 10; +struct ChainExample : public CommonRigidBodyBase +{ + ChainExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~ChainExample(){} + 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 ChainExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + + { + //create a few dynamic rigidbodies + // Re-using the same collision is better for memory usage and performance + btBoxShape* colShape = createBoxShape(btVector3(1,1,0.25)); + + m_collisionShapes.push_back(colShape); + + /// Create Dynamic Objects + btTransform startTransform; + startTransform.setIdentity(); + + btScalar mass(1.f); + + //rigidbody is dynamic if and only if mass is non zero, otherwise static + bool isDynamic = (mass != 0.f); + + btVector3 localInertia(0,0,0); + if (isDynamic) + colShape->calculateLocalInertia(mass,localInertia); + + btAlignedObjectArray boxes; + int lastBoxIndex = TOTAL_BOXES-1; + for(int i=0;iaddConstraint(leftSpring); + + btPoint2PointConstraint* rightSpring = new btPoint2PointConstraint(*b1, *b2, btVector3(0.5,1,0), btVector3(0.5,-1,0)); + + m_dynamicsWorld->addConstraint(rightSpring); + } + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void ChainExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_ChainCreateFunc(CommonExampleOptions& options) +{ + return new ChainExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/Chain.h b/examples/ExtendedTutorials/Chain.h new file mode 100644 index 000000000..b9cea1195 --- /dev/null +++ b/examples/ExtendedTutorials/Chain.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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. +*/ + +#ifndef ET_CHAIN_EXAMPLE_H +#define ET_CHAIN_EXAMPLE_H + +class CommonExampleInterface* ET_ChainCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_CHAIN_EXAMPLE_H diff --git a/examples/ExtendedTutorials/MultipleBoxes.cpp b/examples/ExtendedTutorials/MultipleBoxes.cpp new file mode 100644 index 000000000..c9555936a --- /dev/null +++ b/examples/ExtendedTutorials/MultipleBoxes.cpp @@ -0,0 +1,120 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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 "MultipleBoxes.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + +const int TOTAL_BOXES = 10; +struct MultipleBoxesExample : public CommonRigidBodyBase +{ + MultipleBoxesExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~MultipleBoxesExample(){} + 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 MultipleBoxesExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + + { + //create a few dynamic rigidbodies + // Re-using the same collision is better for memory usage and performance + btBoxShape* colShape = createBoxShape(btVector3(1,1,1)); + + m_collisionShapes.push_back(colShape); + + /// Create Dynamic Objects + btTransform startTransform; + startTransform.setIdentity(); + + btScalar mass(1.f); + + //rigidbody is dynamic if and only if mass is non zero, otherwise static + bool isDynamic = (mass != 0.f); + + btVector3 localInertia(0,0,0); + if (isDynamic) + colShape->calculateLocalInertia(mass,localInertia); + + + for(int i=0;iautogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void MultipleBoxesExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_MultipleBoxesCreateFunc(CommonExampleOptions& options) +{ + return new MultipleBoxesExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/MultipleBoxes.h b/examples/ExtendedTutorials/MultipleBoxes.h new file mode 100644 index 000000000..56e28b61d --- /dev/null +++ b/examples/ExtendedTutorials/MultipleBoxes.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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. +*/ + +#ifndef ET_MULTIPLE_BOXES_EXAMPLE_H +#define ET_MULTIPLE_BOXES_EXAMPLE_H + +class CommonExampleInterface* ET_MultipleBoxesCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_MULTIPLE_BOXES_EXAMPLE_H diff --git a/examples/ExtendedTutorials/RigidBodyFromObj.cpp b/examples/ExtendedTutorials/RigidBodyFromObj.cpp new file mode 100644 index 000000000..ffda148ce --- /dev/null +++ b/examples/ExtendedTutorials/RigidBodyFromObj.cpp @@ -0,0 +1,159 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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 "RigidBodyFromObj.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + +#include "../Utils/b3ResourcePath.h" +#include "Bullet3Common/b3FileUtils.h" +#include "../Importers/ImportObjDemo/LoadMeshFromObj.h" +#include "../OpenGLWindow/GLInstanceGraphicsShape.h" + + +struct RigidBodyFromObjExample : public CommonRigidBodyBase +{ + int m_options; + + RigidBodyFromObjExample(struct GUIHelperInterface* helper, int options) + :CommonRigidBodyBase(helper), + m_options(options) + { + } + virtual ~RigidBodyFromObjExample(){} + 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 RigidBodyFromObjExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + //if (m_dynamicsWorld->getDebugDrawer()) + // m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + //load our obj mesh + const char* fileName = "teddy.obj";//sphere8.obj";//sponza_closed.obj";//sphere8.obj"; + char relativeFileName[1024]; + if (b3ResourcePath::findResourcePath(fileName, relativeFileName, 1024)) + { + char pathPrefix[1024]; + b3FileUtils::extractPath(relativeFileName, pathPrefix, 1024); + } + + GLInstanceGraphicsShape* glmesh = LoadMeshFromObj(relativeFileName, ""); + printf("[INFO] Obj loaded: Extracted %d verticed from obj file [%s]\n", glmesh->m_numvertices, fileName); + + const GLInstanceVertex& v = glmesh->m_vertices->at(0); + btConvexHullShape* shape = new btConvexHullShape((const btScalar*)(&(v.xyzw[0])), glmesh->m_numvertices, sizeof(GLInstanceVertex)); + + shape->setLocalScaling(btVector3(0.1,0.1,0.1)); + + if (m_options & OptimizeConvexObj) + { + shape->optimizeConvexHull(); + } + + if (m_options & ComputePolyhedralFeatures) + { + shape->initializePolyhedralFeatures(); + } + + + + //shape->setMargin(0.001); + m_collisionShapes.push_back(shape); + + btTransform startTransform; + startTransform.setIdentity(); + + btScalar mass(1.f); + bool isDynamic = (mass != 0.f); + btVector3 localInertia(0,0,0); + if (isDynamic) + shape->calculateLocalInertia(mass,localInertia); + + btVector3 position(0,20,0); + startTransform.setOrigin(position); + btRigidBody* body = createRigidBody(mass,startTransform,shape); + + btVector3 color(1,1,1); + btVector3 scaling(0.1,0.1,0.1); + bool useObjForRendering = ((m_options & ObjUseConvexHullForRendering)!=0); + + + if (useObjForRendering) + { + int shapeId = m_guiHelper->getRenderInterface()->registerShape(&glmesh->m_vertices->at(0).xyzw[0], + glmesh->m_numvertices, + &glmesh->m_indices->at(0), + glmesh->m_numIndices, + B3_GL_TRIANGLES,-1); + shape->setUserIndex(shapeId); + int renderInstance = m_guiHelper->getRenderInterface()->registerGraphicsInstance(shapeId,position,startTransform.getRotation(),color,scaling); + body->setUserIndex(renderInstance); + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void RigidBodyFromObjExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_RigidBodyFromObjCreateFunc(CommonExampleOptions& options) +{ + return new RigidBodyFromObjExample(options.m_guiHelper,options.m_option); +} + + + diff --git a/examples/ExtendedTutorials/RigidBodyFromObj.h b/examples/ExtendedTutorials/RigidBodyFromObj.h new file mode 100644 index 000000000..829e9e14a --- /dev/null +++ b/examples/ExtendedTutorials/RigidBodyFromObj.h @@ -0,0 +1,28 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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. +*/ + +#ifndef ET_RIGIDBODYFROMOBJ_EXAMPLE_H +#define ET_RIGIDBODYFROMOBJ_EXAMPLE_H + +enum ObjToRigidBodyOptionsEnum +{ + ObjUseConvexHullForRendering=1, + OptimizeConvexObj=2, + ComputePolyhedralFeatures=4, +}; +class CommonExampleInterface* ET_RigidBodyFromObjCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_RIGIDBODYFROMOBJ_EXAMPLE_H diff --git a/examples/ExtendedTutorials/SimpleBox.cpp b/examples/ExtendedTutorials/SimpleBox.cpp new file mode 100644 index 000000000..474a507f0 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleBox.cpp @@ -0,0 +1,118 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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 "SimpleBox.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + + +struct SimpleBoxExample : public CommonRigidBodyBase +{ + SimpleBoxExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~SimpleBoxExample(){} + 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 SimpleBoxExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + + { + //create a few dynamic rigidbodies + // Re-using the same collision is better for memory usage and performance + btBoxShape* colShape = createBoxShape(btVector3(1,1,1)); + + m_collisionShapes.push_back(colShape); + + /// Create Dynamic Objects + btTransform startTransform; + startTransform.setIdentity(); + + btScalar mass(1.f); + + //rigidbody is dynamic if and only if mass is non zero, otherwise static + bool isDynamic = (mass != 0.f); + + btVector3 localInertia(0,0,0); + if (isDynamic) + colShape->calculateLocalInertia(mass,localInertia); + + + startTransform.setOrigin(btVector3( + btScalar(0), + btScalar(20), + btScalar(0))); + createRigidBody(mass,startTransform,colShape); + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void SimpleBoxExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_SimpleBoxCreateFunc(CommonExampleOptions& options) +{ + return new SimpleBoxExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/SimpleBox.h b/examples/ExtendedTutorials/SimpleBox.h new file mode 100644 index 000000000..494b3fd03 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleBox.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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. +*/ + +#ifndef ET_SIMPLE_BOX_EXAMPLE_H +#define ET_SIMPLE_BOX_EXAMPLE_H + +class CommonExampleInterface* ET_SimpleBoxCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_SIMPLE_BOX_EXAMPLE_H diff --git a/examples/ExtendedTutorials/SimpleCloth.cpp b/examples/ExtendedTutorials/SimpleCloth.cpp new file mode 100644 index 000000000..33a3815b1 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleCloth.cpp @@ -0,0 +1,162 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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 "SimpleCloth.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + +#include "BulletSoftBody/btSoftRigidDynamicsWorld.h" +#include "BulletSoftBody/btSoftBodyHelpers.h" +#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h" + +struct SimpleClothExample : public CommonRigidBodyBase +{ + SimpleClothExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~SimpleClothExample(){} + virtual void initPhysics(); + virtual void renderScene(); + void createEmptyDynamicsWorld() + { + m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration(); + m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); + + m_broadphase = new btDbvtBroadphase(); + + m_solver = new btSequentialImpulseConstraintSolver; + + m_dynamicsWorld = new btSoftRigidDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration); + m_dynamicsWorld->setGravity(btVector3(0, -10, 0)); + + softBodyWorldInfo.m_broadphase = m_broadphase; + softBodyWorldInfo.m_dispatcher = m_dispatcher; + softBodyWorldInfo.m_gravity = m_dynamicsWorld->getGravity(); + softBodyWorldInfo.m_sparsesdf.Initialize(); + } + virtual btSoftRigidDynamicsWorld* getSoftDynamicsWorld() + { + ///just make it a btSoftRigidDynamicsWorld please + ///or we will add type checking + return (btSoftRigidDynamicsWorld*) m_dynamicsWorld; + } + 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 createSoftBody(const btScalar size, const int num_x, const int num_z, const int fixed=1+2); + btSoftBodyWorldInfo softBodyWorldInfo; +}; + +void SimpleClothExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + + { + const btScalar s=4; //size of cloth patch + const int NUM_X=31; //vertices on X axis + const int NUM_Z=31; //vertices on Z axis + createSoftBody(s,NUM_X, NUM_Z); + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + +void SimpleClothExample::createSoftBody(const btScalar s, + const int numX, + const int numY, + const int fixed) { + + + + btSoftBody* cloth=btSoftBodyHelpers::CreatePatch(softBodyWorldInfo, + btVector3(-s/2,s+1,0), + btVector3(+s/2,s+1,0), + btVector3(-s/2,s+1,+s), + btVector3(+s/2,s+1,+s), + numX,numY, + fixed,true); + + cloth->getCollisionShape()->setMargin(0.001f); + cloth->generateBendingConstraints(2,cloth->appendMaterial()); + cloth->setTotalMass(10); + //cloth->m_cfg.citerations = 10; +// cloth->m_cfg.diterations = 10; + cloth->m_cfg.piterations = 5; + cloth->m_cfg.kDP = 0.005f; + getSoftDynamicsWorld()->addSoftBody(cloth); + +} + +void SimpleClothExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); + btSoftRigidDynamicsWorld* softWorld = getSoftDynamicsWorld(); + + for ( int i=0;igetSoftBodyArray().size();i++) + { + btSoftBody* psb=(btSoftBody*)softWorld->getSoftBodyArray()[i]; + //if (softWorld->getDebugDrawer() && !(softWorld->getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe))) + { + btSoftBodyHelpers::DrawFrame(psb,softWorld->getDebugDrawer()); + btSoftBodyHelpers::Draw(psb,softWorld->getDebugDrawer(),softWorld->getDrawFlags()); + } + } +} + + + + + + + +CommonExampleInterface* ET_SimpleClothCreateFunc(CommonExampleOptions& options) +{ + return new SimpleClothExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/SimpleCloth.h b/examples/ExtendedTutorials/SimpleCloth.h new file mode 100644 index 000000000..d956833e9 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleCloth.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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. +*/ + +#ifndef ET_SIMPLE_CLOTH_EXAMPLE_H +#define ET_SIMPLE_CLOTH_EXAMPLE_H + +class CommonExampleInterface* ET_SimpleClothCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_SIMPLE_CLOTH_EXAMPLE_H diff --git a/examples/ExtendedTutorials/SimpleJoint.cpp b/examples/ExtendedTutorials/SimpleJoint.cpp new file mode 100644 index 000000000..da30449b4 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleJoint.cpp @@ -0,0 +1,133 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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 "SimpleJoint.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + + +struct SimpleJointExample : public CommonRigidBodyBase +{ + SimpleJointExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~SimpleJointExample(){} + 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 SimpleJointExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + + { + //create a few dynamic rigidbodies + // Re-using the same collision is better for memory usage and performance + btBoxShape* colShape = createBoxShape(btVector3(1,1,1)); + + m_collisionShapes.push_back(colShape); + + /// Create Dynamic Objects + btTransform startTransform; + startTransform.setIdentity(); + + btScalar mass(1.f); + + //rigidbody is dynamic if and only if mass is non zero, otherwise static + bool isDynamic = (mass != 0.f); + + btVector3 localInertia(0,0,0); + if (isDynamic) + colShape->calculateLocalInertia(mass,localInertia); + + + startTransform.setOrigin(btVector3( + btScalar(0), + btScalar(10), + btScalar(0))); + btRigidBody* dynamicBox = createRigidBody(mass,startTransform,colShape); + + //create a static rigid body + mass = 0; + startTransform.setOrigin(btVector3( + btScalar(0), + btScalar(20), + btScalar(0))); + + btRigidBody* staticBox = createRigidBody(mass,startTransform,colShape); + + //create a simple p2pjoint constraint + btPoint2PointConstraint* p2p = new btPoint2PointConstraint(*dynamicBox, *staticBox, btVector3(0,3,0), btVector3(0,0,0)); + p2p->m_setting.m_damping = 0.0625; + p2p->m_setting.m_impulseClamp = 0.95; + m_dynamicsWorld->addConstraint(p2p); + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void SimpleJointExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_SimpleJointCreateFunc(CommonExampleOptions& options) +{ + return new SimpleJointExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/SimpleJoint.h b/examples/ExtendedTutorials/SimpleJoint.h new file mode 100644 index 000000000..a3d245a23 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleJoint.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. 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. +*/ + +#ifndef ET_SIMPLE_JOINT_EXAMPLE_H +#define ET_SIMPLE_JOINT_EXAMPLE_H + +class CommonExampleInterface* ET_SimpleJointCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_SIMPLE_JOINT_EXAMPLE_H diff --git a/examples/StandaloneMain/main_opengl_single_example.cpp b/examples/StandaloneMain/main_opengl_single_example.cpp index 4fd1ff422..e74cda181 100644 --- a/examples/StandaloneMain/main_opengl_single_example.cpp +++ b/examples/StandaloneMain/main_opengl_single_example.cpp @@ -31,16 +31,47 @@ subject to the following restrictions: #include #include "../ExampleBrowser/OpenGLGuiHelper.h" +CommonExampleInterface* example; + +b3MouseMoveCallback prevMouseMoveCallback = 0; +static void OnMouseMove( float x, float y) +{ + bool handled = false; + handled = example->mouseMoveCallback(x,y); + if (!handled) + { + if (prevMouseMoveCallback) + prevMouseMoveCallback (x,y); + } +} + +b3MouseButtonCallback prevMouseButtonCallback = 0; +static void OnMouseDown(int button, int state, float x, float y) { + bool handled = false; + + handled = example->mouseButtonCallback(button, state, x,y); + if (!handled) + { + if (prevMouseButtonCallback ) + prevMouseButtonCallback (button,state,x,y); + } +} int main(int argc, char* argv[]) { SimpleOpenGL3App* app = new SimpleOpenGL3App("Bullet Standalone Example",1024,768,true); + prevMouseButtonCallback = app->m_window->getMouseButtonCallback(); + prevMouseMoveCallback = app->m_window->getMouseMoveCallback(); + + app->m_window->setMouseButtonCallback((b3MouseButtonCallback)OnMouseDown); + app->m_window->setMouseMoveCallback((b3MouseMoveCallback)OnMouseMove); + OpenGLGuiHelper gui(app,false); CommonExampleOptions options(&gui); - CommonExampleInterface* example = StandaloneExampleCreateFunc(options); + example = StandaloneExampleCreateFunc(options); example->initPhysics(); From 8a68e27bb74fe92dde90a8fde14f279fe94ee27e Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Sat, 7 May 2016 16:36:14 -0700 Subject: [PATCH 2/2] move the RigidBodyFromObj to Importers section. --- examples/ExampleBrowser/ExampleEntries.cpp | 20 +++++++++---------- .../ExtendedTutorials/RigidBodyFromObj.cpp | 4 ++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/examples/ExampleBrowser/ExampleEntries.cpp b/examples/ExampleBrowser/ExampleEntries.cpp index 20b14ef8a..6c66e2716 100644 --- a/examples/ExampleBrowser/ExampleEntries.cpp +++ b/examples/ExampleBrowser/ExampleEntries.cpp @@ -87,10 +87,6 @@ static ExampleEntry gDefaultExamples[]= { ExampleEntry(0,"API"), - ExampleEntry(1,"Obj2RigidBody (Show Obj)", "Load a triangle mesh from Wavefront .obj and turn it in a convex hull collision shape, connected to a rigid body. We can use the original .obj mesh data to visualize the rigid body. In 'debug' wireframe mode (press 'w' to toggle) we still see the convex hull data.", ET_RigidBodyFromObjCreateFunc,ObjUseConvexHullForRendering), - ExampleEntry(1,"Obj2RigidBody (Show Hull)", "Load a triangle mesh from Wavefront .obj and turn it in a convex hull collision shape, connected to a rigid body", ET_RigidBodyFromObjCreateFunc), - ExampleEntry(1,"Obj2RigidBody Optimize", "Load a triangle mesh from Wavefront .obj, remove the vertices that are not on the convex hull", ET_RigidBodyFromObjCreateFunc,OptimizeConvexObj), - ExampleEntry(1,"Obj2RigidBody Add Features", "Load a triangle mesh from Wavefront .obj and create polyhedral features to perform the separating axis test (instead of GJK/MPR). It is best to combine optimization and polyhedral feature generation.", ET_RigidBodyFromObjCreateFunc,OptimizeConvexObj+ComputePolyhedralFeatures), ExampleEntry(1,"Basic Example","Create some rigid bodies using box collision shapes. This is a good example to familiarize with the basic initialization of Bullet. The Basic Example can also be compiled without graphical user interface, as a console application. Press W for wireframe, A to show AABBs, I to suspend/restart physics simulation. Press D to toggle auto-deactivation of the simulation. ", BasicExampleCreateFunc), @@ -203,6 +199,10 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(0,"Importers"), ExampleEntry(1,"Import .bullet", "Load a binary .bullet file. The serialization mechanism can deal with versioning, differences in endianess, 32 and 64bit, double/single precision. It is easy to save a .bullet file, see the examples/Importers/ImportBullet/SerializeDemo.cpp for a code example how to export a .bullet file.", SerializeBulletCreateFunc), ExampleEntry(1,"Wavefront Obj", "Import a Wavefront .obj file", ImportObjCreateFunc, 0), + ExampleEntry(1,"Obj2RigidBody (Show Obj)", "Load a triangle mesh from Wavefront .obj and turn it in a convex hull collision shape, connected to a rigid body. We can use the original .obj mesh data to visualize the rigid body. In 'debug' wireframe mode (press 'w' to toggle) we still see the convex hull data.", ET_RigidBodyFromObjCreateFunc), + ExampleEntry(1,"Obj2RigidBody (Show Hull)", "Load a triangle mesh from Wavefront .obj and turn it in a convex hull collision shape, connected to a rigid body", ET_RigidBodyFromObjCreateFunc,ObjUseConvexHullForRendering), + ExampleEntry(1,"Obj2RigidBody Optimize", "Load a triangle mesh from Wavefront .obj, remove the vertices that are not on the convex hull", ET_RigidBodyFromObjCreateFunc,OptimizeConvexObj), + ExampleEntry(1,"Quake BSP", "Import a Quake .bsp file", ImportBspCreateFunc, 0), ExampleEntry(1,"COLLADA dae", "Import the geometric mesh data from a COLLADA file. This is used as part of the URDF importer. This loader can also be used to import collision geometry in general. ", ImportColladaCreateFunc, 0), @@ -211,6 +211,7 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(1,"URDF (MultiBody)", "Import a URDF file and create a single multibody (btMultiBody) with tree hierarchy of links (mobilizers).", ImportURDFCreateFunc, 1), + ExampleEntry(0,"Vehicles"), ExampleEntry(1,"Hinge2 Vehicle", "A rigid body chassis with 4 rigid body wheels attached by a btHinge2Constraint",Hinge2VehicleCreateFunc), ExampleEntry(1,"ForkLift","Simulate a fork lift vehicle with a working fork lift that can be moved using the cursor keys. The wheels collision is simplified using ray tests." @@ -226,13 +227,6 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(0,"Experiments"), -// ExampleEntry(1,"Robot Control (Velocity)", "Perform some robot control tasks, using physics server and client that communicate over shared memory", -// RobotControlExampleCreateFunc,ROBOT_VELOCITY_CONTROL), -// ExampleEntry(1,"Robot Control (PD)", "Perform some robot control tasks, using physics server and client that communicate over shared memory", -// RobotControlExampleCreateFunc,ROBOT_PD_CONTROL), -// ExampleEntry(1,"Robot Joint Feedback", "Apply some small ping-pong target velocity jitter, and read the joint reaction forces, using physics server and client that communicate over shared memory.", - // RobotControlExampleCreateFunc,ROBOT_PING_PONG_JOINT_FEEDBACK), - ExampleEntry(1,"Physics Server", "Create a physics server that communicates with a physics client over shared memory", PhysicsServerCreateFunc), ExampleEntry(1,"Physics Server (Logging)", "Create a physics server that communicates with a physics client over shared memory. It will log all commands to a file.", @@ -271,6 +265,10 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(1,"Simple Chain", "Creating a simple chain using a pair of point2point/distance constraints. You may click and drag any box to see the chain respond.", ET_ChainCreateFunc), ExampleEntry(1,"Simple Bridge", "Creating a simple bridge using a pair of point2point/distance constraints. You may click and drag any plank to see the bridge respond.", ET_BridgeCreateFunc), + //todo: create a category/tutorial about advanced topics, such as optimizations, using different collision detection algorithm, different constraint solvers etc. + //ExampleEntry(0,"Advanced"), + //ExampleEntry(1,"Obj2RigidBody Add Features", "Load a triangle mesh from Wavefront .obj and create polyhedral features to perform the separating axis test (instead of GJK/MPR). It is best to combine optimization and polyhedral feature generation.", ET_RigidBodyFromObjCreateFunc,OptimizeConvexObj+ComputePolyhedralFeatures), + }; diff --git a/examples/ExtendedTutorials/RigidBodyFromObj.cpp b/examples/ExtendedTutorials/RigidBodyFromObj.cpp index ffda148ce..1a8835dfd 100644 --- a/examples/ExtendedTutorials/RigidBodyFromObj.cpp +++ b/examples/ExtendedTutorials/RigidBodyFromObj.cpp @@ -120,10 +120,10 @@ void RigidBodyFromObjExample::initPhysics() btVector3 color(1,1,1); btVector3 scaling(0.1,0.1,0.1); - bool useObjForRendering = ((m_options & ObjUseConvexHullForRendering)!=0); + bool useConvexHullForRendering = ((m_options & ObjUseConvexHullForRendering)!=0); - if (useObjForRendering) + if (!useConvexHullForRendering) { int shapeId = m_guiHelper->getRenderInterface()->registerShape(&glmesh->m_vertices->at(0).xyzw[0], glmesh->m_numvertices,