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
This commit is contained in:
150
examples/ExtendedTutorials/Bridge.cpp
Normal file
150
examples/ExtendedTutorials/Bridge.cpp
Normal file
@@ -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<btRigidBody*> boxes;
|
||||
int lastBoxIndex = TOTAL_PLANKS-1;
|
||||
for(int i=0;i<TOTAL_PLANKS;++i) {
|
||||
float t = float(i)/lastBoxIndex;
|
||||
t = -(t*2-1.0f) * halfBridgeWidth;
|
||||
startTransform.setOrigin(btVector3(
|
||||
btScalar(t),
|
||||
bridgeHeight,
|
||||
btScalar(0)
|
||||
)
|
||||
);
|
||||
boxes.push_back(createRigidBody((i==0 || i==lastBoxIndex)?0:mass,startTransform,colShape));
|
||||
}
|
||||
|
||||
|
||||
//add N-1 spring constraints
|
||||
for(int i=0;i<TOTAL_PLANKS-1;++i) {
|
||||
btRigidBody* b1 = boxes[i];
|
||||
btRigidBody* b2 = boxes[i+1];
|
||||
|
||||
btPoint2PointConstraint* leftSpring = new btPoint2PointConstraint(*b1, *b2, btVector3(-0.5,0,-0.5), btVector3(0.5,0,-0.5));
|
||||
m_dynamicsWorld->addConstraint(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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
22
examples/ExtendedTutorials/Bridge.h
Normal file
22
examples/ExtendedTutorials/Bridge.h
Normal file
@@ -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
|
||||
137
examples/ExtendedTutorials/Chain.cpp
Normal file
137
examples/ExtendedTutorials/Chain.cpp
Normal file
@@ -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<btRigidBody*> boxes;
|
||||
int lastBoxIndex = TOTAL_BOXES-1;
|
||||
for(int i=0;i<TOTAL_BOXES;++i) {
|
||||
startTransform.setOrigin(btVector3(
|
||||
btScalar(0),
|
||||
btScalar(5+i*2),
|
||||
btScalar(0)
|
||||
)
|
||||
);
|
||||
boxes.push_back(createRigidBody((i==lastBoxIndex)?0:mass,startTransform,colShape));
|
||||
}
|
||||
|
||||
//add N-1 spring constraints
|
||||
for(int i=0;i<TOTAL_BOXES-1;++i) {
|
||||
btRigidBody* b1 = boxes[i];
|
||||
btRigidBody* b2 = boxes[i+1];
|
||||
|
||||
btPoint2PointConstraint* leftSpring = new btPoint2PointConstraint(*b1, *b2, btVector3(-0.5,1,0), btVector3(-0.5,-1,0));
|
||||
|
||||
m_dynamicsWorld->addConstraint(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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
22
examples/ExtendedTutorials/Chain.h
Normal file
22
examples/ExtendedTutorials/Chain.h
Normal file
@@ -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
|
||||
120
examples/ExtendedTutorials/MultipleBoxes.cpp
Normal file
120
examples/ExtendedTutorials/MultipleBoxes.cpp
Normal file
@@ -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;i<TOTAL_BOXES;++i) {
|
||||
startTransform.setOrigin(btVector3(
|
||||
btScalar(0),
|
||||
btScalar(20+i*2),
|
||||
btScalar(0)));
|
||||
createRigidBody(mass,startTransform,colShape);
|
||||
}
|
||||
}
|
||||
|
||||
m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld);
|
||||
}
|
||||
|
||||
|
||||
void MultipleBoxesExample::renderScene()
|
||||
{
|
||||
CommonRigidBodyBase::renderScene();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
CommonExampleInterface* ET_MultipleBoxesCreateFunc(CommonExampleOptions& options)
|
||||
{
|
||||
return new MultipleBoxesExample(options.m_guiHelper);
|
||||
}
|
||||
|
||||
|
||||
|
||||
22
examples/ExtendedTutorials/MultipleBoxes.h
Normal file
22
examples/ExtendedTutorials/MultipleBoxes.h
Normal file
@@ -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
|
||||
159
examples/ExtendedTutorials/RigidBodyFromObj.cpp
Normal file
159
examples/ExtendedTutorials/RigidBodyFromObj.cpp
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
28
examples/ExtendedTutorials/RigidBodyFromObj.h
Normal file
28
examples/ExtendedTutorials/RigidBodyFromObj.h
Normal file
@@ -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
|
||||
118
examples/ExtendedTutorials/SimpleBox.cpp
Normal file
118
examples/ExtendedTutorials/SimpleBox.cpp
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
22
examples/ExtendedTutorials/SimpleBox.h
Normal file
22
examples/ExtendedTutorials/SimpleBox.h
Normal file
@@ -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
|
||||
162
examples/ExtendedTutorials/SimpleCloth.cpp
Normal file
162
examples/ExtendedTutorials/SimpleCloth.cpp
Normal file
@@ -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;i<softWorld->getSoftBodyArray().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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
22
examples/ExtendedTutorials/SimpleCloth.h
Normal file
22
examples/ExtendedTutorials/SimpleCloth.h
Normal file
@@ -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
|
||||
133
examples/ExtendedTutorials/SimpleJoint.cpp
Normal file
133
examples/ExtendedTutorials/SimpleJoint.cpp
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
22
examples/ExtendedTutorials/SimpleJoint.h
Normal file
22
examples/ExtendedTutorials/SimpleJoint.h
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user