mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-15 06:00:12 +00:00
Merge pull request #363 from erwincoumans/master
replace btgui/Demos/Demos3 with 'examples' and move all demos in 'ExampleBrowser'
This commit is contained in:
commit
4f9b9b05ad
39
AUTHORS.txt
Normal file
39
AUTHORS.txt
Normal file
@ -0,0 +1,39 @@
|
||||
Bullet Physics is created by Erwin Coumans with contributions from the following authors / copyright holders:
|
||||
|
||||
AMD
|
||||
Apple
|
||||
Steve Baker
|
||||
Gino van den Bergen
|
||||
Nicola Candussi
|
||||
Erin Catto
|
||||
Lawrence Chai
|
||||
Erwin Coumans
|
||||
Christer Ericson
|
||||
Disney Animation
|
||||
Google
|
||||
Dirk Gregorius
|
||||
Marcus Hennix
|
||||
MBSim Development Team
|
||||
Takahiro Harada
|
||||
Simon Hobbs
|
||||
John Hsu
|
||||
Ole Kniemeyer
|
||||
Jay Lee
|
||||
Francisco Leon
|
||||
Vsevolod Klementjev
|
||||
Phil Knight
|
||||
John McCutchan
|
||||
Steven Peters
|
||||
Roman Ponomarev
|
||||
Nathanael Presson
|
||||
Gabor PUHR
|
||||
Arthur Shek
|
||||
Russel Smith
|
||||
Sony
|
||||
Jakub Stephien
|
||||
Marten Svanfeldt
|
||||
Pierre Terdiman
|
||||
Steven Thompson
|
||||
Tamas Umenhoffer
|
||||
|
||||
If your name is missing, please send an email to erwin.coumans@gmail.com or file an issue at http://github.com/bulletphysics/bullet3
|
@ -126,7 +126,7 @@ ENDIF(INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES)
|
||||
ENDIF (WIN32)
|
||||
|
||||
|
||||
OPTION(BUILD_CPU_DEMOS "Build original Bullet CPU demos" ON)
|
||||
OPTION(BUILD_CPU_DEMOS "Build original Bullet CPU examples" ON)
|
||||
|
||||
|
||||
|
||||
@ -189,45 +189,9 @@ ENDIF (OPENGL_FOUND)
|
||||
OPTION(BUILD_BULLET2_DEMOS "Set when you want to build the Bullet 2 demos" ON)
|
||||
IF(BUILD_BULLET2_DEMOS)
|
||||
|
||||
IF (USE_GLUT)
|
||||
IF (MSVC)
|
||||
SET(GLUT_FOUND TRUE)
|
||||
ADD_DEFINITIONS(-DBT_USE_FREEGLUT)
|
||||
|
||||
IF (CMAKE_CL_64)
|
||||
message("Win64 using static freeglut in Demos/Glut/glut64.lib")
|
||||
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Demos/Glut/glut64.lib glu32.lib gdi32.lib winmm.lib user32.lib)
|
||||
ELSE(CMAKE_CL_64)
|
||||
message("Win32 using static freeglut in Demos/Glut/glut32.lib")
|
||||
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Demos/Glut/glut32.lib glu32.lib gdi32.lib winmm.lib user32.lib)
|
||||
ENDIF (CMAKE_CL_64)
|
||||
SET(GLUT_INCLUDE_DIR ${BULLET_PHYSICS_SOURCE_DIR}/Demos/Glut )
|
||||
ELSE()
|
||||
FIND_PACKAGE(GLUT)
|
||||
IF (GLUT_FOUND)
|
||||
MESSAGE("GLUT FOUND")
|
||||
MESSAGE(${GLUT_glut_LIBRARY})
|
||||
ELSE (GLUT_FOUND)
|
||||
# IF (MINGW)
|
||||
# MESSAGE ("GLUT NOT FOUND not found, trying to use MINGW glut32")
|
||||
# SET(GLUT_glut_LIBRARY glut32)
|
||||
# #TODO add better GLUT detection for MinGW
|
||||
# SET(GLUT_FOUND TRUE)
|
||||
# ELSE (MINGW)
|
||||
MESSAGE("GLUT NOT FOUND")
|
||||
# ENDIF (MINGW)
|
||||
ENDIF (GLUT_FOUND)
|
||||
ENDIF (MSVC)
|
||||
|
||||
IF(NOT WIN32 AND NOT APPLE AND NOT CMAKE_CROSSCOMPILING)
|
||||
# This is added for linux. This should always work if everything is installed and working fine.
|
||||
SET(GLUT_INCLUDE_DIR /usr/include /usr/local/include)
|
||||
ENDIF()
|
||||
ENDIF(USE_GLUT)
|
||||
|
||||
|
||||
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos)
|
||||
SUBDIRS(Demos)
|
||||
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/examples AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/examples)
|
||||
SUBDIRS(examples)
|
||||
ENDIF()
|
||||
ENDIF(BUILD_BULLET2_DEMOS)
|
||||
|
||||
@ -257,7 +221,6 @@ ENDIF(BUILD_BULLET3)
|
||||
IF(BUILD_OPENGL3_DEMOS)
|
||||
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos3 AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos3)
|
||||
SUBDIRS(Demos3)
|
||||
SUBDIRS(btgui)
|
||||
ENDIF()
|
||||
ENDIF(BUILD_OPENGL3_DEMOS)
|
||||
|
||||
|
@ -1,87 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/GIMPACTUtils
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/HACD
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/ConvexDecomposition
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/LibXML
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/LibXML/include
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
||||
${VECTOR_MATH_INCLUDE}
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
GLUI GIMPACTUtils HACD ConvexDecomposition OpenGLSupport BulletWorldImporter BulletSoftBody BulletDynamics BulletCollision BulletFileLoader LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
SET(AllBulletDemos_SRCS
|
||||
Main.cpp
|
||||
DemoEntries.cpp
|
||||
../CcdPhysicsDemo/CcdPhysicsDemo.cpp
|
||||
../BasicDemo/BasicDemo.cpp
|
||||
../BspDemo/BspDemo.cpp
|
||||
../BspDemo/BspConverter.cpp
|
||||
../BspDemo/BspLoader.cpp
|
||||
../DynamicControlDemo/MotorDemo.cpp
|
||||
../ConcaveDemo/ConcavePhysicsDemo.cpp
|
||||
../ConcaveRaycastDemo/ConcaveRaycastDemo.cpp
|
||||
../ConcaveConvexcastDemo/ConcaveConvexcastDemo.cpp
|
||||
../ConvexDecompositionDemo/ConvexDecompositionDemo.cpp
|
||||
../SliderConstraintDemo/SliderConstraintDemo.cpp
|
||||
../RagdollDemo/RagdollDemo.cpp
|
||||
../GimpactTestDemo/GimpactTestDemo.cpp
|
||||
../Raytracer/Raytracer.cpp
|
||||
../GjkConvexCastDemo/LinearConvexCastDemo.cpp
|
||||
../ForkLiftDemo/ForkLiftDemo.cpp
|
||||
../SoftDemo/SoftDemo.cpp
|
||||
../ConstraintDemo/ConstraintDemo.cpp
|
||||
../Benchmarks/BenchmarkDemo.cpp
|
||||
../Box2dDemo/Box2dDemo.cpp
|
||||
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppAllBulletDemos
|
||||
${AllBulletDemos_SRCS}
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppAllBulletDemos
|
||||
${AllBulletDemos_SRCS}
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
||||
|
||||
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppAllBulletDemos
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/SerializeDemo/testFile.bullet ${CMAKE_CURRENT_BINARY_DIR}/testFile.bullet
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/file.obj ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
|
||||
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppAllBulletDemos PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppAllBulletDemos PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppAllBulletDemos PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,178 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "DemoEntries.h"
|
||||
|
||||
#include "../CcdPhysicsDemo/CcdPhysicsDemo.h"
|
||||
#include "../BspDemo/BspDemo.h"
|
||||
#include "../BasicDemo/BasicDemo.h"
|
||||
#include "../ConcaveDemo/ConcaveDemo.h"
|
||||
#include "../ConcaveRaycastDemo/ConcaveRaycastDemo.h"
|
||||
#include "../ConcaveConvexcastDemo/ConcaveConvexcastDemo.h"
|
||||
#include "../ConvexDecompositionDemo/ConvexDecompositionDemo.h"
|
||||
#include "../DynamicControlDemo/MotorDemo.h"
|
||||
#include "../SliderConstraintDemo/SliderConstraintDemo.h"
|
||||
#include "../RagdollDemo/RagdollDemo.h"
|
||||
#include "../GimpactTestDemo/GimpactTestDemo.h"
|
||||
#include "../Raytracer/Raytracer.h"
|
||||
#include "../GjkConvexCastDemo/LinearConvexCastDemo.h"
|
||||
#include "../ForkLiftDemo/ForkLiftDemo.h"
|
||||
#include "../ConstraintDemo/ConstraintDemo.h"
|
||||
//#include "../Benchmarks/BenchmarkDemo.h"
|
||||
#include "../SoftDemo/SoftDemo.h"
|
||||
//#include "../Box2dDemo/Box2dDemo.h"
|
||||
|
||||
#include "GLDebugFont.h"
|
||||
|
||||
#include "GlutStuff.h"//OpenGL stuff
|
||||
|
||||
|
||||
extern int gNumAlignedAllocs;
|
||||
extern int gNumAlignedFree;
|
||||
extern int gTotalBytesAlignedAllocs;
|
||||
|
||||
class btEmptyDebugDemo : public GlutDemoApplication
|
||||
{
|
||||
public:
|
||||
btEmptyDebugDemo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual void clientMoveAndDisplay()
|
||||
{
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
float xOffset = 10.f;
|
||||
float yStart = 20.f;
|
||||
float yIncr = 20.f;
|
||||
char buf[124];
|
||||
|
||||
|
||||
glColor3f(0, 0, 0);
|
||||
|
||||
setOrthographicProjection();
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"gNumAlignedAllocs= %d",gNumAlignedAllocs);
|
||||
GLDebugDrawString(xOffset,yStart,buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"gNumAlignedFree= %d",gNumAlignedFree);
|
||||
GLDebugDrawString(xOffset,yStart,buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"# alloc-free = %d",gNumAlignedAllocs-gNumAlignedFree);
|
||||
GLDebugDrawString(xOffset,yStart,buf);
|
||||
yStart += yIncr;
|
||||
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"gTotalBytesAlignedAllocs = %d",gTotalBytesAlignedAllocs);
|
||||
GLDebugDrawString(xOffset,yStart,buf);
|
||||
yStart += yIncr;
|
||||
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
virtual void initPhysics() {}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
btEmptyDebugDemo* demo = new btEmptyDebugDemo();
|
||||
demo->myinit();
|
||||
return demo;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
btDemoEntry g_demoEntries[] =
|
||||
{
|
||||
// {"Box2dDemo",Box2dDemo::Create},
|
||||
{"ForkLift Demo",ForkLiftDemo::Create},
|
||||
{"Dynamic Control Demo",MotorDemo::Create},
|
||||
{"ConstraintDemo",ConstraintDemo::Create},
|
||||
|
||||
{"Ragdoll Demo",RagdollDemo::Create},
|
||||
{"Basic Demo", BasicDemo::Create},
|
||||
{"CcdPhysicsDemo", CcdPhysicsDemo::Create},
|
||||
{"Convex Decomposition",ConvexDecompositionDemo::Create},
|
||||
{"Concave Moving", GimpactConcaveDemo::Create},
|
||||
|
||||
{"ConcaveDemo",ConcaveDemo::Create},
|
||||
{"Concave Convexcast Demo",ConcaveConvexcastDemo::Create},
|
||||
{"SoftBody Cluster Collide1",SoftDemo19::Create},
|
||||
|
||||
{"SoftBody Ropes Attach",SoftDemo4::Create},
|
||||
|
||||
{"SoftBody Cloth Attach",SoftDemo5::Create},
|
||||
|
||||
{"SoftBody Cloth",SoftDemo0::Create},
|
||||
|
||||
// {"SoftBody Volume",SoftDemo2::Create},
|
||||
{"SoftBody Pressure",SoftDemo1::Create},
|
||||
{"SoftBody Cluster Car",SoftDemo24::Create},
|
||||
{"SoftBody Cluster Robot",SoftDemo25::Create},
|
||||
// {"SoftBody Ropes",SoftDemo3::Create},
|
||||
{"SoftBody Sticks",SoftDemo6::Create},
|
||||
{"SoftBody Collide",SoftDemo7::Create},
|
||||
{"SoftBody Collide2",SoftDemo8::Create},
|
||||
// {"SoftBody Collide3",SoftDemo9::Create},
|
||||
// {"SoftBody Impact",SoftDemo10::Create},
|
||||
{"SoftBody Aero",SoftDemo11::Create},
|
||||
{"SoftBody Friction",SoftDemo12::Create},
|
||||
// {"SoftBody Torus",SoftDemo13::Create},
|
||||
// {"SoftBody Torus Match",SoftDemo14::Create},
|
||||
// {"SoftBody Bunny",SoftDemo15::Create},
|
||||
// {"SoftBody Bunny Match",SoftDemo16::Create},
|
||||
{"SoftBody Init Cutting",SoftDemo17::Create},
|
||||
// {"SoftBody Cluster Deform",SoftDemo18::Create},
|
||||
|
||||
// {"SoftBody Cluster Collide2",SoftDemo20::Create},
|
||||
// {"SoftBody Cluster Socket",SoftDemo21::Create},
|
||||
{"SoftBody Cluster Hinge",SoftDemo22::Create},
|
||||
{"SoftBody Cluster Combine",SoftDemo23::Create},
|
||||
// {"SoftBody Cluster Stack Soft",SoftDemo26::Create},
|
||||
{"SoftBody Cluster Stack Mixed",SoftDemo27::Create},
|
||||
|
||||
{"SoftBody TetGen Tetrahedral Cube",SoftDemo28::Create},
|
||||
{"SoftBody TetGen Tetrahedral Bunny",SoftDemo29::Create},
|
||||
|
||||
|
||||
// {"SliderConstraint",SliderConstraintDemo::Create},
|
||||
|
||||
// {"ConcaveRaycastDemo",ConcaveRaycastDemo::Create},
|
||||
//{"BspDemo", BspDemo::Create},
|
||||
// {"Raytracer Test",Raytracer::Create},
|
||||
// {"GjkConvexCast",LinearConvexCastDemo::Create},
|
||||
// {"Benchmark 3000 FALL",BenchmarkDemo1::Create},
|
||||
// {"Benchmark 1000 STACK",BenchmarkDemo2::Create},
|
||||
// {"Benchmark 136 RAGDOLLS",BenchmarkDemo3::Create},
|
||||
// {"Benchmark 1000 CONVEX",BenchmarkDemo4::Create},
|
||||
// {"Benchmark Mesh-Prim",BenchmarkDemo5::Create},
|
||||
// {"Benchmark Mesh-Convex",BenchmarkDemo6::Create},
|
||||
// {"Benchmark Raycast",BenchmarkDemo7::Create},
|
||||
|
||||
{"MemoryLeak Checker",btEmptyDebugDemo::Create},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
|
@ -1,574 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
|
||||
#include "glui/GL/glui.h"
|
||||
#include "LinearMath/btScalar.h"
|
||||
#include "LinearMath/btMinMax.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
|
||||
#include "DemoApplication.h"
|
||||
#include "DemoEntries.h"
|
||||
#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
|
||||
#include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
|
||||
#include "BulletSoftBody/btSoftBodyHelpers.h"
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
static GLDebugDrawer dDebugDraw2;
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
int testIndex=1;
|
||||
int testSelection=0;
|
||||
btDemoEntry* entry;
|
||||
DemoApplication* demo;
|
||||
int iterationCount;
|
||||
int width;
|
||||
int height;
|
||||
int framePeriod;//todo: test if this value should be 0
|
||||
int mainWindow;
|
||||
GLUI *glui;
|
||||
//float hz;
|
||||
float viewZoom=20.f;
|
||||
float viewX;
|
||||
float viewY;
|
||||
int tx, ty, tw, th;
|
||||
int gDrawAabb;
|
||||
int gWireFrame;
|
||||
int gDrawNormals;
|
||||
int gHelpText;
|
||||
int gDebugConstraints;
|
||||
int gDebugContacts;
|
||||
int gDrawTextures=1;
|
||||
int gDrawShadows=0;
|
||||
int gDrawClusters=0;
|
||||
int gDebugNoDeactivation;
|
||||
int gUseWarmstarting;
|
||||
int gRandomizeConstraints;
|
||||
int gUseSplitImpulse;
|
||||
float gErp;
|
||||
float gSlop;
|
||||
float gErp2;
|
||||
float gWarmStartingParameter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setDefaultSettings()
|
||||
{
|
||||
viewX = 0.0f;
|
||||
viewY = 0.0f;
|
||||
framePeriod = 6;//16;//16;//todo: test if this value should be 0
|
||||
|
||||
width = 1280;
|
||||
height = 768;//480;
|
||||
iterationCount = 10;
|
||||
gDrawAabb=0;
|
||||
gDrawNormals=0;
|
||||
gWireFrame=0;
|
||||
gDebugContacts=0;
|
||||
//enable constraint debug visualization for first demo, only if user hasn't overridden the setting
|
||||
if (testSelection>1)
|
||||
{
|
||||
gDebugConstraints=0;
|
||||
} else
|
||||
{
|
||||
gDebugConstraints=1;
|
||||
}
|
||||
gHelpText = 0;
|
||||
gDrawTextures=1;
|
||||
gDrawShadows=0;
|
||||
gDrawClusters=0;
|
||||
|
||||
gDebugNoDeactivation = 0;
|
||||
gUseSplitImpulse = 1;
|
||||
gUseWarmstarting = 1;
|
||||
gRandomizeConstraints = 0;
|
||||
gErp = 0.2f;
|
||||
gSlop=0.0f;
|
||||
gErp2 = 0.81f;
|
||||
gWarmStartingParameter = 0.85f;
|
||||
|
||||
}
|
||||
|
||||
void setDefaultSettingsAndSync()
|
||||
{
|
||||
setDefaultSettings();
|
||||
glui->sync_live();
|
||||
}
|
||||
|
||||
|
||||
void TogglePause()
|
||||
{
|
||||
if (demo)
|
||||
demo->toggleIdle();
|
||||
}
|
||||
|
||||
void ResetScene()
|
||||
{
|
||||
if (demo)
|
||||
demo->clientResetScene();
|
||||
}
|
||||
|
||||
void NextScene()
|
||||
{
|
||||
testSelection++;
|
||||
if (testSelection>1)
|
||||
{
|
||||
gDebugConstraints=0;
|
||||
} else
|
||||
{
|
||||
gDebugConstraints=1;
|
||||
}
|
||||
|
||||
if(testSelection>28)
|
||||
testSelection=0;
|
||||
if (glui)
|
||||
glui->sync_live();
|
||||
}
|
||||
|
||||
|
||||
void SingleSimulationStep()
|
||||
{
|
||||
if (demo)
|
||||
demo->clientMoveAndDisplay();
|
||||
}
|
||||
|
||||
|
||||
void Resize(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
|
||||
GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
|
||||
glViewport( tx, ty, tw, th );
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
if (demo)
|
||||
demo->reshape(tw, th);
|
||||
}
|
||||
|
||||
DemoApplication* CreatDemo(btDemoEntry* entry)
|
||||
{
|
||||
DemoApplication* demo = entry->createFcn();
|
||||
btAssert(demo);
|
||||
if (demo->getDynamicsWorld())
|
||||
{
|
||||
demo->getDynamicsWorld()->setDebugDrawer(&dDebugDraw2);
|
||||
gDrawTextures = demo->getTexturing();
|
||||
gDrawShadows = demo->getShadows();
|
||||
if (glui)
|
||||
glui->sync_live();
|
||||
}
|
||||
|
||||
#ifndef BT_NO_PROFILE
|
||||
CProfileManager::Reset();
|
||||
#endif //BT_NO_PROFILE
|
||||
|
||||
return demo;
|
||||
|
||||
}
|
||||
|
||||
/*b2Vec2 ConvertScreenToWorld(int x, int y)
|
||||
{
|
||||
b2Vec2 p;
|
||||
|
||||
float ratio = float(tw) / float(th);
|
||||
float u = x / float(tw);
|
||||
float v = (th - y) / float(th);
|
||||
p.x = viewZoom * (viewX - ratio) * (1.0f - u) + viewZoom * (ratio + viewX) * u;
|
||||
p.y = viewZoom * (viewY - 0.1f) * (1.0f - v) + viewZoom * (viewY + 1.9f) * v;
|
||||
return p;
|
||||
}
|
||||
*/
|
||||
|
||||
// This is used to control the frame rate (60Hz).
|
||||
void Timer(int)
|
||||
{
|
||||
glutSetWindow(mainWindow);
|
||||
glutPostRedisplay();
|
||||
glutTimerFunc(framePeriod, Timer, 0);
|
||||
}
|
||||
|
||||
void SimulationLoop()
|
||||
{
|
||||
Resize(width, height);
|
||||
|
||||
|
||||
|
||||
if (gDrawAabb)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_DrawAabb);
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_DrawAabb));
|
||||
}
|
||||
if (gWireFrame)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_DrawWireframe);
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_DrawWireframe));
|
||||
}
|
||||
if (gDrawNormals)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_DrawNormals);
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_DrawNormals));
|
||||
}
|
||||
if (gHelpText)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_NoHelpText));
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_NoHelpText);
|
||||
}
|
||||
if (gDebugConstraints)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_DrawConstraints+btIDebugDraw::DBG_DrawConstraintLimits);
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_DrawConstraints+btIDebugDraw::DBG_DrawConstraintLimits));
|
||||
}
|
||||
if (gDebugContacts)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_DrawContactPoints);
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_DrawContactPoints));
|
||||
}
|
||||
|
||||
demo->setTexturing(0!=gDrawTextures);
|
||||
demo->setShadows(0!=gDrawShadows);
|
||||
demo->setDrawClusters(0!=gDrawClusters);
|
||||
|
||||
if (gDebugNoDeactivation)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_NoDeactivation);
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_NoDeactivation));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getWorldType() == BT_DISCRETE_DYNAMICS_WORLD)
|
||||
{
|
||||
btDiscreteDynamicsWorld* discreteWorld = (btDiscreteDynamicsWorld*) demo->getDynamicsWorld();
|
||||
discreteWorld->getSolverInfo().m_numIterations = iterationCount;
|
||||
discreteWorld->getSolverInfo().m_erp = gErp;
|
||||
discreteWorld->getSolverInfo().m_erp2 = gErp2;
|
||||
|
||||
discreteWorld->getSolverInfo().m_linearSlop = gSlop;
|
||||
|
||||
discreteWorld->getSolverInfo().m_warmstartingFactor = gWarmStartingParameter;
|
||||
discreteWorld->getSolverInfo().m_splitImpulse = gUseSplitImpulse;
|
||||
|
||||
// btSequentialImpulseConstraintSolver* solver = ((btSequentialImpulseConstraintSolver*) discreteWorld->getConstraintSolver());
|
||||
|
||||
if (gUseWarmstarting)
|
||||
{
|
||||
discreteWorld->getSolverInfo().m_solverMode |= SOLVER_USE_WARMSTARTING;
|
||||
} else
|
||||
{
|
||||
discreteWorld->getSolverInfo().m_solverMode &= (~SOLVER_USE_WARMSTARTING);
|
||||
}
|
||||
if (gRandomizeConstraints)
|
||||
{
|
||||
discreteWorld->getSolverInfo().m_solverMode |= SOLVER_RANDMIZE_ORDER;
|
||||
} else
|
||||
{
|
||||
discreteWorld->getSolverInfo().m_solverMode &= (~SOLVER_RANDMIZE_ORDER);
|
||||
}
|
||||
}
|
||||
|
||||
if (!demo->isIdle())
|
||||
{
|
||||
demo->clientMoveAndDisplay();
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
demo->displayCallback();
|
||||
}
|
||||
|
||||
if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getWorldType()==BT_SOFT_RIGID_DYNAMICS_WORLD)
|
||||
{
|
||||
btSoftRigidDynamicsWorld* softWorld = (btSoftRigidDynamicsWorld*)demo->getDynamicsWorld();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (testSelection != testIndex)
|
||||
{
|
||||
if (testSelection>1)
|
||||
{
|
||||
gDebugConstraints=0;
|
||||
} else
|
||||
{
|
||||
gDebugConstraints=1;
|
||||
}
|
||||
|
||||
testIndex = testSelection;
|
||||
delete demo;
|
||||
entry = g_demoEntries + testIndex;
|
||||
demo = CreatDemo(entry);
|
||||
viewZoom = 20.0f;
|
||||
viewX = 0.0f;
|
||||
viewY = 0.0f;
|
||||
Resize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
void RestartScene()
|
||||
{
|
||||
delete demo;
|
||||
entry = g_demoEntries + testIndex;
|
||||
demo = CreatDemo(entry);
|
||||
viewZoom = 20.0f;
|
||||
viewX = 0.0f;
|
||||
viewY = 0.0f;
|
||||
Resize(width, height);
|
||||
}
|
||||
|
||||
void Keyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case 27:
|
||||
exit(0);
|
||||
break;
|
||||
|
||||
// Press 'r' to reset.
|
||||
case 'r':
|
||||
delete demo;
|
||||
demo = CreatDemo(entry);
|
||||
Resize(width,height);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (demo)
|
||||
{
|
||||
demo->keyboardCallback(key,x,y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardSpecialUp(int key, int x, int y)
|
||||
{
|
||||
if (demo)
|
||||
{
|
||||
demo->specialKeyboardUp(key,x,y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GlutIdleFunc()
|
||||
{
|
||||
int current_window, new_window=-1;
|
||||
current_window = glutGetWindow();
|
||||
if (GLUI_Master.gluis.first_child() != NULL )
|
||||
{
|
||||
new_window = ((GLUI_Main*)GLUI_Master.gluis.first_child())->getMainWindowId();
|
||||
}
|
||||
if ( (new_window > 0) && (new_window != current_window ))
|
||||
{
|
||||
//--- Window is changed only if its not already the current window ---
|
||||
glutSetWindow( new_window );
|
||||
}
|
||||
|
||||
if (demo)
|
||||
demo->moveAndDisplay();
|
||||
|
||||
glutSetWindow( current_window );
|
||||
}
|
||||
|
||||
void KeyboardSpecial(int key, int x, int y)
|
||||
{
|
||||
|
||||
if (demo)
|
||||
{
|
||||
demo->specialKeyboard(key,x,y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Mouse(int button, int state, int x, int y)
|
||||
{
|
||||
if (demo)
|
||||
demo->mouseFunc(button,state,x,y);
|
||||
}
|
||||
|
||||
void MouseMotion(int x, int y)
|
||||
{
|
||||
demo->mouseMotionFunc(x,y);
|
||||
}
|
||||
|
||||
#ifdef BT_USE_FREEGLUT
|
||||
#include "GL/freeglut_ext.h"
|
||||
#endif
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
//#define CHECK_FPU_EXCEPTIONS 1
|
||||
#ifdef CHECK_FPU_EXCEPTIONS
|
||||
|
||||
int cw = _control87(0, 0);
|
||||
|
||||
// Set the exception masks off, turn exceptions on
|
||||
cw &= ~(EM_ZERODIVIDE | EM_INVALID);
|
||||
|
||||
printf("control87 = %#x\n", cw);
|
||||
|
||||
// Set the control word
|
||||
_control87(cw, MCW_EM);
|
||||
#endif //CHECK_FPU_EXCEPTIONS
|
||||
|
||||
|
||||
setDefaultSettings();
|
||||
|
||||
int bulletVersion = btGetVersion();
|
||||
printf("Bullet version %d\n",bulletVersion);
|
||||
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE |GLUT_DEPTH | GLUT_STENCIL);
|
||||
glutInitWindowSize(width, height);
|
||||
mainWindow = glutCreateWindow("http://bulletphysics.com");
|
||||
#ifdef BT_USE_FREEGLUT
|
||||
glutSetOption (GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
|
||||
#endif
|
||||
entry = g_demoEntries + testIndex;
|
||||
demo = CreatDemo(entry);
|
||||
|
||||
glutDisplayFunc(SimulationLoop);
|
||||
GLUI_Master.set_glutReshapeFunc(Resize);
|
||||
GLUI_Master.set_glutKeyboardFunc(Keyboard);
|
||||
GLUI_Master.set_glutSpecialFunc(KeyboardSpecial);
|
||||
GLUI_Master.set_glutIdleFunc(GlutIdleFunc);
|
||||
GLUI_Master.set_glutSpecialUpFunc(KeyboardSpecialUp);
|
||||
GLUI_Master.set_glutMouseFunc(Mouse);
|
||||
glutMotionFunc(MouseMotion);
|
||||
|
||||
|
||||
glui = GLUI_Master.create_glui_subwindow( mainWindow,
|
||||
GLUI_SUBWINDOW_RIGHT );
|
||||
|
||||
|
||||
|
||||
glui->add_statictext("Tests");
|
||||
GLUI_Listbox* testList =
|
||||
glui->add_listbox("", &testSelection);
|
||||
glui->add_button("Next Scene", 0,(GLUI_Update_CB)NextScene);
|
||||
|
||||
glui->add_separator();
|
||||
|
||||
GLUI_Spinner* iterationSpinner =
|
||||
glui->add_spinner("Iterations", GLUI_SPINNER_INT, &iterationCount);
|
||||
iterationSpinner->set_int_limits(1, 250);
|
||||
|
||||
/* GLUI_Spinner* hertzSpinner =
|
||||
glui->add_spinner("Hertz", GLUI_SPINNER_FLOAT, &hz);
|
||||
hertzSpinner->set_float_limits(5.0f, 200.0f);
|
||||
*/
|
||||
|
||||
|
||||
glui->add_checkbox("DisableDeactivation", &gDebugNoDeactivation);
|
||||
glui->add_checkbox("Split Impulse", &gUseSplitImpulse);
|
||||
GLUI_Spinner* spinner = 0;
|
||||
|
||||
spinner = glui->add_spinner("ERP", GLUI_SPINNER_FLOAT, &gErp);
|
||||
// spinner->set_float_limits(0.f,1.f);
|
||||
// spinner = glui->add_spinner("ERP2", GLUI_SPINNER_FLOAT, &gErp2);
|
||||
spinner->set_float_limits(0.f,1.f);
|
||||
spinner = glui->add_spinner("Slop", GLUI_SPINNER_FLOAT, &gSlop);
|
||||
spinner->set_float_limits(0.f,1.f);
|
||||
// spinner = glui->add_spinner("WSP", GLUI_SPINNER_FLOAT,&gWarmStartingParameter);
|
||||
// spinner->set_float_limits (0.f,1.0);
|
||||
glui->add_checkbox("Warmstarting", &gUseWarmstarting);
|
||||
glui->add_checkbox("Randomize Constraints", &gRandomizeConstraints);
|
||||
|
||||
|
||||
glui->add_button("Reset Defaults", 0,(GLUI_Update_CB)setDefaultSettingsAndSync);
|
||||
glui->add_separator();
|
||||
|
||||
GLUI_Panel* drawPanel = glui->add_panel("Debug Draw");
|
||||
|
||||
|
||||
glui->add_checkbox_to_panel(drawPanel, "Help", &gHelpText);
|
||||
glui->add_checkbox_to_panel(drawPanel, "AABBs", &gDrawAabb);
|
||||
glui->add_checkbox_to_panel(drawPanel, "Wireframe", &gWireFrame);
|
||||
glui->add_checkbox_to_panel(drawPanel, "Normals", &gDrawNormals);
|
||||
glui->add_checkbox_to_panel(drawPanel, "Contacts", &gDebugContacts);
|
||||
glui->add_checkbox_to_panel(drawPanel, "Constraints", &gDebugConstraints);
|
||||
|
||||
glui->add_checkbox_to_panel(drawPanel, "Textures", &gDrawTextures);
|
||||
glui->add_checkbox_to_panel(drawPanel, "Shadows", &gDrawShadows);
|
||||
glui->add_checkbox_to_panel(drawPanel, "Clusters", &gDrawClusters);
|
||||
|
||||
int testCount = 0;
|
||||
btDemoEntry* e = g_demoEntries;
|
||||
while (e->createFcn)
|
||||
{
|
||||
testList->add_item(testCount, e->name);
|
||||
++testCount;
|
||||
++e;
|
||||
}
|
||||
|
||||
glui->add_separator();
|
||||
|
||||
glui->add_button("Toggle Pause", 0,(GLUI_Update_CB)TogglePause);
|
||||
|
||||
glui->add_button("Single Step", 0,(GLUI_Update_CB)SingleSimulationStep);
|
||||
glui->add_button("Reset Scene", 0,(GLUI_Update_CB)ResetScene);
|
||||
glui->add_button("Restart Scene", 0,(GLUI_Update_CB)RestartScene);
|
||||
|
||||
glui->add_separator();
|
||||
|
||||
// glui->add_button("Exit", 0,(GLUI_Update_CB)exit);
|
||||
|
||||
glui->set_main_gfx_window( mainWindow );
|
||||
|
||||
// Use a timer to control the frame rate.
|
||||
glutTimerFunc(framePeriod, Timer, 0);
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
noinst_PROGRAMS=AllBulletDemo
|
||||
|
||||
AllBulletDemo_SOURCES=\
|
||||
../SoftDemo/SoftDemo.cpp \
|
||||
../ConstraintDemo/ConstraintDemo.cpp \
|
||||
../ForkLiftDemo/ForkLiftDemo.cpp \
|
||||
../RagdollDemo/RagdollDemo.cpp \
|
||||
../BasicDemo/BasicDemo.cpp \
|
||||
../CcdPhysicsDemo/CcdPhysicsDemo.cpp \
|
||||
../SliderConstraintDemo/SliderConstraintDemo.cpp \
|
||||
../ConcaveRaycastDemo/ConcaveRaycastDemo.cpp \
|
||||
../Raytracer/Raytracer.cpp \
|
||||
../BspDemo/BspDemo.cpp \
|
||||
../BspDemo/BspLoader.cpp \
|
||||
../BspDemo/BspConverter.cpp \
|
||||
../ConcaveConvexcastDemo/ConcaveConvexcastDemo.cpp \
|
||||
../ConvexDecompositionDemo/ConvexDecompositionDemo.cpp \
|
||||
../GimpactTestDemo/GimpactTestDemo.cpp \
|
||||
../GjkConvexCastDemo/LinearConvexCastDemo.cpp \
|
||||
../ConcaveDemo/ConcavePhysicsDemo.cpp \
|
||||
../DynamicControlDemo/MotorDemo.cpp \
|
||||
DemoEntries.cpp \
|
||||
DemoEntries.h\
|
||||
Main.cpp
|
||||
AllBulletDemo_CXXFLAGS=\
|
||||
-I@top_builddir@/src \
|
||||
-I@top_builddir@/Extras/GIMPACTUtils \
|
||||
-I@top_builddir@/Extras/ConvexDecomposition \
|
||||
-I@top_builddir@/Extras/HACD \
|
||||
-I@top_builddir@/Extras \
|
||||
-I@top_builddir@/Demos/OpenGL \
|
||||
-I@top_builddir@/Demos/SoftDemo \
|
||||
$(CXXFLAGS)
|
||||
AllBulletDemo_LDADD=-L../OpenGL -lbulletopenglsupport -L../../src -L../../Extras -lgimpactutils -lconvexdecomposition -lHACD -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath -lglui @opengl_LIBS@
|
@ -1,147 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
///create 125 (5x5x5) dynamic object
|
||||
#define ARRAY_SIZE_X 5
|
||||
#define ARRAY_SIZE_Y 5
|
||||
#define ARRAY_SIZE_Z 5
|
||||
|
||||
//maximum number of objects (and allow user to shoot additional boxes)
|
||||
#define MAX_PROXIES (ARRAY_SIZE_X*ARRAY_SIZE_Y*ARRAY_SIZE_Z + 1024)
|
||||
|
||||
///scaling of the objects (0.1 = 20 centimeter boxes )
|
||||
#define SCALING 1.
|
||||
#define START_POS_X -5
|
||||
#define START_POS_Y -5
|
||||
#define START_POS_Z -3
|
||||
|
||||
#include "BasicDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
#include <stdio.h> //printf debugging
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "LinearMath/btAabbUtil2.h"
|
||||
|
||||
static GLDebugDrawer gDebugDraw;
|
||||
|
||||
///The MyOverlapCallback is used to show how to collect object that overlap with a given bounding box defined by aabbMin and aabbMax.
|
||||
///See m_physicsSetup.m_dynamicsWorld->getBroadphase()->aabbTest.
|
||||
struct MyOverlapCallback : public btBroadphaseAabbCallback
|
||||
{
|
||||
btVector3 m_queryAabbMin;
|
||||
btVector3 m_queryAabbMax;
|
||||
|
||||
int m_numOverlap;
|
||||
MyOverlapCallback(const btVector3& aabbMin, const btVector3& aabbMax ) : m_queryAabbMin(aabbMin),m_queryAabbMax(aabbMax),m_numOverlap(0) {}
|
||||
virtual bool process(const btBroadphaseProxy* proxy)
|
||||
{
|
||||
btVector3 proxyAabbMin,proxyAabbMax;
|
||||
btCollisionObject* colObj0 = (btCollisionObject*)proxy->m_clientObject;
|
||||
colObj0->getCollisionShape()->getAabb(colObj0->getWorldTransform(),proxyAabbMin,proxyAabbMax);
|
||||
if (TestAabbAgainstAabb2(proxyAabbMin,proxyAabbMax,m_queryAabbMin,m_queryAabbMax))
|
||||
{
|
||||
m_numOverlap++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void BasicDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//simple dynamics world doesn't handle fixed-time-stepping
|
||||
float ms = getDeltaTimeMicroseconds();
|
||||
|
||||
m_physicsSetup.stepSimulation(ms/1000000.f);
|
||||
m_physicsSetup.m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
/*
|
||||
///step the simulation
|
||||
if (m_physicsSetup.m_dynamicsWorld)
|
||||
{
|
||||
m_physicsSetup.m_dynamicsWorld->stepSimulation(ms / 1000000.f);
|
||||
//optional but useful: debug drawing
|
||||
m_physicsSetup.m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
btVector3 aabbMin(1,1,1);
|
||||
btVector3 aabbMax(2,2,2);
|
||||
|
||||
MyOverlapCallback aabbOverlap(aabbMin,aabbMax);
|
||||
m_physicsSetup.m_dynamicsWorld->getBroadphase()->aabbTest(aabbMin,aabbMax,aabbOverlap);
|
||||
|
||||
//if (aabbOverlap.m_numOverlap)
|
||||
// printf("#aabb overlap = %d\n", aabbOverlap.m_numOverlap);
|
||||
}
|
||||
*/
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
|
||||
swapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BasicDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
renderme();
|
||||
|
||||
//optional but useful: debug drawing to detect problems
|
||||
if (m_physicsSetup.m_dynamicsWorld)
|
||||
m_physicsSetup.m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
glFlush();
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void BasicDemo::initPhysics()
|
||||
{
|
||||
setTexturing(true);
|
||||
setShadows(true);
|
||||
|
||||
setCameraDistance(btScalar(SCALING*50.));
|
||||
GraphicsPhysicsBridge gfxBridge;
|
||||
m_physicsSetup.initPhysics(gfxBridge);
|
||||
|
||||
m_dynamicsWorld = m_physicsSetup.m_dynamicsWorld;
|
||||
m_dynamicsWorld->setDebugDrawer(&gDebugDraw);
|
||||
|
||||
}
|
||||
void BasicDemo::clientResetScene()
|
||||
{
|
||||
exitPhysics();
|
||||
initPhysics();
|
||||
}
|
||||
|
||||
|
||||
void BasicDemo::exitPhysics()
|
||||
{
|
||||
m_physicsSetup.exitPhysics();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 BASIC_DEMO_H
|
||||
#define BASIC_DEMO_H
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "BasicDemoPhysicsSetup.h"
|
||||
|
||||
|
||||
///BasicDemo is good starting point for learning the code base and porting.
|
||||
|
||||
class BasicDemo : public PlatformDemoApplication
|
||||
{
|
||||
|
||||
BasicDemoPhysicsSetup m_physicsSetup;
|
||||
|
||||
public:
|
||||
|
||||
BasicDemo()
|
||||
{
|
||||
}
|
||||
virtual ~BasicDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
virtual void clientResetScene();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BasicDemo* demo = new BasicDemo;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //BASIC_DEMO_H
|
||||
|
@ -1,91 +0,0 @@
|
||||
|
||||
|
||||
#include "BasicDemoPhysicsSetup.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#define ARRAY_SIZE_Y 5
|
||||
#define ARRAY_SIZE_X 5
|
||||
#define ARRAY_SIZE_Z 5
|
||||
|
||||
void BasicDemoPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
|
||||
{
|
||||
createEmptyDynamicsWorld();
|
||||
gfxBridge.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.)));
|
||||
gfxBridge.createCollisionShapeGraphicsObject(groundShape);
|
||||
|
||||
//groundShape->initializePolyhedralFeatures();
|
||||
// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50);
|
||||
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
|
||||
btTransform groundTransform;
|
||||
groundTransform.setIdentity();
|
||||
groundTransform.setOrigin(btVector3(0,-50,0));
|
||||
|
||||
{
|
||||
btScalar mass(0.);
|
||||
btRigidBody* body = createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1));
|
||||
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(0, 1, 0));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
//create a few dynamic rigidbodies
|
||||
// Re-using the same collision is better for memory usage and performance
|
||||
|
||||
btBoxShape* colShape = createBoxShape(btVector3(1,1,1));
|
||||
gfxBridge.createCollisionShapeGraphicsObject(colShape);
|
||||
|
||||
//btCollisionShape* colShape = new btSphereShape(btScalar(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 k=0;k<ARRAY_SIZE_Y;k++)
|
||||
{
|
||||
for (int i=0;i<ARRAY_SIZE_X;i++)
|
||||
{
|
||||
for(int j = 0;j<ARRAY_SIZE_Z;j++)
|
||||
{
|
||||
startTransform.setOrigin(btVector3(
|
||||
btScalar(2.0*i),
|
||||
btScalar(20+2.0*k),
|
||||
btScalar(2.0*j)));
|
||||
|
||||
|
||||
btRigidBody* body = createRigidBody(mass,startTransform,colShape);
|
||||
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(1, 1, 0));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
#ifndef BASIC_DEMO_PHYSICS_SETUP_H
|
||||
#define BASIC_DEMO_PHYSICS_SETUP_H
|
||||
|
||||
class btRigidBody;
|
||||
class btCollisionShape;
|
||||
class btBroadphaseInterface;
|
||||
class btConstraintSolver;
|
||||
class btCollisionDispatcher;
|
||||
class btDefaultCollisionConfiguration;
|
||||
class btDiscreteDynamicsWorld;
|
||||
class btTransform;
|
||||
class btVector3;
|
||||
class btBoxShape;
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
|
||||
#include "Bullet3AppSupport/CommonRigidBodySetup.h"
|
||||
|
||||
struct BasicDemoPhysicsSetup : public CommonRigidBodySetup
|
||||
{
|
||||
|
||||
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);
|
||||
|
||||
};
|
||||
|
||||
#endif //BASIC_DEMO_PHYSICS_SETUP_H
|
@ -1,71 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# This is the variable for Windows. I use this to define the root of my directory structure.
|
||||
SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ../OpenGL ../../btgui
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
|
||||
|
||||
IF (USE_GLUT)
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppBasicDemo
|
||||
main.cpp
|
||||
BasicDemo.cpp
|
||||
BasicDemo.h
|
||||
BasicDemoPhysicsSetup.cpp
|
||||
BasicDemoPhysicsSetup.h
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppBasicDemo
|
||||
main.cpp
|
||||
BasicDemo.cpp
|
||||
BasicDemo.h
|
||||
BasicDemoPhysicsSetup.cpp
|
||||
BasicDemoPhysicsSetup.h
|
||||
)
|
||||
ENDIF()
|
||||
ELSE (USE_GLUT)
|
||||
|
||||
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
|
||||
ADD_EXECUTABLE(AppBasicDemo
|
||||
WIN32
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
Win32BasicDemo.cpp
|
||||
BasicDemo.cpp
|
||||
BasicDemo.h
|
||||
BasicDemoPhysicsSetup.cpp
|
||||
BasicDemoPhysicsSetup.h
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
|
||||
|
||||
ENDIF (USE_GLUT)
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppBasicDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppBasicDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppBasicDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,5 +0,0 @@
|
||||
noinst_PROGRAMS=BasicDemo
|
||||
|
||||
BasicDemo_SOURCES=BasicDemo.cpp BasicDemo.h main.cpp
|
||||
BasicDemo_CXXFLAGS=-I@top_builddir@/src -I@top_builddir@/Demos/OpenGL $(CXXFLAGS)
|
||||
BasicDemo_LDADD=-L../OpenGL -lbulletopenglsupport -L../../src -lBulletDynamics -lBulletCollision -lLinearMath @opengl_LIBS@
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "BasicDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
BasicDemo ccdDemo;
|
||||
ccdDemo.initPhysics();
|
||||
|
||||
|
||||
#ifdef CHECK_MEMORY_LEAKS
|
||||
ccdDemo.exitPhysics();
|
||||
#else
|
||||
return glutmain(argc, argv,1024,600,"Bullet Physics Demo. http://bulletphysics.org",&ccdDemo);
|
||||
#endif
|
||||
|
||||
//default glut doesn't return from mainloop
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,269 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 BENCHMARK_DEMO_H
|
||||
#define BENCHMARK_DEMO_H
|
||||
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "LinearMath/btTransform.h"
|
||||
|
||||
class btDynamicsWorld;
|
||||
|
||||
#define NUMRAYS 500
|
||||
|
||||
class btRigidBody;
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
|
||||
|
||||
#ifndef USE_GRAPHICAL_BENCHMARK
|
||||
///empty placeholder
|
||||
class DemoApplication
|
||||
{
|
||||
protected:
|
||||
|
||||
btDynamicsWorld* m_dynamicsWorld;
|
||||
btScalar m_defaultContactProcessingThreshold;
|
||||
|
||||
public:
|
||||
DemoApplication()
|
||||
:m_defaultContactProcessingThreshold(BT_LARGE_FLOAT)
|
||||
{
|
||||
}
|
||||
virtual void myinit() {}
|
||||
virtual btDynamicsWorld* getDynamicsWorld()
|
||||
{
|
||||
return m_dynamicsWorld;
|
||||
}
|
||||
|
||||
btScalar getDeltaTimeMicroseconds()
|
||||
{
|
||||
return 1.f;
|
||||
}
|
||||
|
||||
void renderme() {}
|
||||
void setCameraDistance(btScalar dist){}
|
||||
void clientResetScene(){}
|
||||
btRigidBody* localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape);
|
||||
|
||||
};
|
||||
///BenchmarkDemo is provides several performance tests
|
||||
#define PlatformDemoApplication DemoApplication
|
||||
#else //USE_GRAPHICAL_BENCHMARK
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
#endif //USE_GRAPHICAL_BENCHMARK
|
||||
|
||||
|
||||
class BenchmarkDemo : public PlatformDemoApplication
|
||||
{
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btAlignedObjectArray<class RagDoll*> m_ragdolls;
|
||||
|
||||
btBroadphaseInterface* m_overlappingPairCache;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
int m_benchmark;
|
||||
|
||||
void createTest1();
|
||||
void createTest2();
|
||||
void createTest3();
|
||||
void createTest4();
|
||||
void createTest5();
|
||||
void createTest6();
|
||||
void createTest7();
|
||||
|
||||
void createWall(const btVector3& offsetPosition,int stackSize,const btVector3& boxSize);
|
||||
void createPyramid(const btVector3& offsetPosition,int stackSize,const btVector3& boxSize);
|
||||
void createTowerCircle(const btVector3& offsetPosition,int stackSize,int rotSize,const btVector3& boxSize);
|
||||
void createLargeMeshBody();
|
||||
|
||||
|
||||
class SpuBatchRaycaster* m_batchRaycaster;
|
||||
class btThreadSupportInterface* m_batchRaycasterThreadSupport;
|
||||
|
||||
void castRays();
|
||||
void initRays();
|
||||
|
||||
public:
|
||||
|
||||
BenchmarkDemo(int benchmark)
|
||||
:m_benchmark(benchmark),
|
||||
m_overlappingPairCache(0),
|
||||
m_dispatcher(0),
|
||||
m_solver(0),
|
||||
m_collisionConfiguration(0)
|
||||
{
|
||||
}
|
||||
virtual ~BenchmarkDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
class BenchmarkDemo1 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo1()
|
||||
:BenchmarkDemo(1)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo1* demo = new BenchmarkDemo1;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
class BenchmarkDemo2 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo2()
|
||||
:BenchmarkDemo(2)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo2* demo = new BenchmarkDemo2;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
class BenchmarkDemo3 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo3()
|
||||
:BenchmarkDemo(3)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo3* demo = new BenchmarkDemo3;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
class BenchmarkDemo4 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo4()
|
||||
:BenchmarkDemo(4)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo4* demo = new BenchmarkDemo4;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class BenchmarkDemo5 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo5()
|
||||
:BenchmarkDemo(5)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo5* demo = new BenchmarkDemo5;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class BenchmarkDemo6 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo6()
|
||||
:BenchmarkDemo(6)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo6* demo = new BenchmarkDemo6;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
class BenchmarkDemo7 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo7()
|
||||
:BenchmarkDemo(7)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo7* demo = new BenchmarkDemo7;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //BENCHMARK_DEMO_H
|
||||
|
@ -1,93 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
IF (USE_GRAPHICAL_BENCHMARK)
|
||||
IF (USE_GLUT)
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
IF (USE_MULTITHREADED_BENCHMARK)
|
||||
INCLUDE_DIRECTORIES( ${VECTOR_MATH_INCLUDE} )
|
||||
LINK_LIBRARIES( OpenGLSupport BulletMultiThreaded BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
|
||||
ELSE()
|
||||
LINK_LIBRARIES( OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
|
||||
ENDIF(USE_MULTITHREADED_BENCHMARK)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppBenchmarks
|
||||
main.cpp
|
||||
BenchmarkDemo.cpp
|
||||
BenchmarkDemo.h
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppBenchmarks
|
||||
main.cpp
|
||||
BenchmarkDemo.cpp
|
||||
BenchmarkDemo.h
|
||||
)
|
||||
ENDIF ()
|
||||
IF (WIN32)
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
|
||||
ENDIF(WIN32)
|
||||
ELSE (USE_GLUT)
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
)
|
||||
|
||||
IF (USE_MULTITHREADED_BENCHMARK)
|
||||
INCLUDE_DIRECTORIES( ${VECTOR_MATH_INCLUDE} )
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletMultiThreaded BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
ELSE()
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ENDIF()
|
||||
|
||||
ADD_EXECUTABLE(AppBenchmarks
|
||||
WIN32
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
BenchmarkDemo.cpp
|
||||
BenchmarkDemo.h
|
||||
Win32BenchmarkDemo.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ENDIF (USE_GLUT)
|
||||
ELSE (USE_GRAPHICAL_BENCHMARK)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
)
|
||||
|
||||
IF (USE_MULTITHREADED_BENCHMARK)
|
||||
LINK_LIBRARIES( BulletMultiThreaded BulletDynamics BulletCollision LinearMath )
|
||||
ELSE()
|
||||
LINK_LIBRARIES( BulletDynamics BulletCollision LinearMath )
|
||||
ENDIF()
|
||||
|
||||
|
||||
ADD_EXECUTABLE(AppBenchmarks
|
||||
main.cpp
|
||||
BenchmarkDemo.cpp
|
||||
)
|
||||
ENDIF (USE_GRAPHICAL_BENCHMARK)
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "BenchmarkDemo.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef USE_GRAPHICAL_BENCHMARK
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
#define benchmarkDemo benchmarkDemo2
|
||||
#endif //USE_GRAPHICAL_BENCHMARK
|
||||
|
||||
|
||||
#define NUM_DEMOS 7
|
||||
#define NUM_TESTS 200
|
||||
|
||||
extern bool gDisableDeactivation;
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
gDisableDeactivation = true;
|
||||
|
||||
BenchmarkDemo1 benchmarkDemo1;
|
||||
BenchmarkDemo2 benchmarkDemo2;
|
||||
BenchmarkDemo3 benchmarkDemo3;
|
||||
BenchmarkDemo4 benchmarkDemo4;
|
||||
BenchmarkDemo5 benchmarkDemo5;
|
||||
BenchmarkDemo6 benchmarkDemo6;
|
||||
BenchmarkDemo7 benchmarkDemo7;
|
||||
|
||||
BenchmarkDemo* demoArray[NUM_DEMOS] = {&benchmarkDemo1,&benchmarkDemo2,&benchmarkDemo3,&benchmarkDemo4,&benchmarkDemo5,&benchmarkDemo6,&benchmarkDemo7};
|
||||
const char* demoNames[NUM_DEMOS] = {"3000 fall", "1000 stack", "136 ragdolls","1000 convex", "prim-trimesh", "convex-trimesh","raytests"};
|
||||
float totalTime[NUM_DEMOS] = {0.f,0.f,0.f,0.f,0.f,0.f,0.f};
|
||||
|
||||
#ifdef USE_GRAPHICAL_BENCHMARK
|
||||
benchmarkDemo.initPhysics();
|
||||
benchmarkDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
benchmarkDemo.setDebugMode(benchmarkDemo.getDebugMode() | btIDebugDraw::DBG_NoDeactivation);
|
||||
return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.com",&benchmarkDemo);
|
||||
|
||||
#else //USE_GRAPHICAL_BENCHMARK
|
||||
int d;
|
||||
|
||||
for (d=0;d<NUM_DEMOS;d++)
|
||||
{
|
||||
demoArray[d]->initPhysics();
|
||||
|
||||
|
||||
for (int i=0;i<NUM_TESTS;i++)
|
||||
{
|
||||
demoArray[d]->clientMoveAndDisplay();
|
||||
float frameTime = CProfileManager::Get_Time_Since_Reset();
|
||||
if ((i % 25)==0)
|
||||
{
|
||||
printf("BenchmarkDemo: %s, Frame %d, Duration (ms): %f\n",demoNames[d],i,frameTime);
|
||||
}
|
||||
totalTime[d] += frameTime;
|
||||
if (i==NUM_TESTS-1)
|
||||
CProfileManager::dumpAll();
|
||||
|
||||
|
||||
}
|
||||
demoArray[d]->exitPhysics();
|
||||
}
|
||||
|
||||
for (d=0;d<NUM_DEMOS;d++)
|
||||
{
|
||||
printf("\nResults for %s: %f",demoNames[d],totalTime[d]*(1.f/NUM_TESTS));
|
||||
}
|
||||
|
||||
#endif //USE_GRAPHICAL_BENCHMARK
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 BOX2D_DEMO_H
|
||||
#define BOX2D_DEMO_H
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
class GL_DialogDynamicsWorld;
|
||||
|
||||
///Box2dDemo is good starting point for learning the code base and porting.
|
||||
class Box2dDemo : public PlatformDemoApplication
|
||||
{
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
GL_DialogDynamicsWorld* m_dialogDynamicsWorld;
|
||||
|
||||
public:
|
||||
|
||||
Box2dDemo() : m_dialogDynamicsWorld(0)
|
||||
{
|
||||
}
|
||||
virtual ~Box2dDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
|
||||
virtual void reshape(int w, int h);
|
||||
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
Box2dDemo* demo = new Box2dDemo;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
|
||||
virtual void mouseFunc(int button, int state, int x, int y);
|
||||
virtual void mouseMotionFunc(int x,int y);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //BOX2D_DEMO_H
|
||||
|
@ -1,59 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# This is the variable for Windows. I use this to define the root of my directory structure.
|
||||
SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
)
|
||||
|
||||
IF (USE_GLUT)
|
||||
INCLUDE_DIRECTORIES( ${GLUT_INCLUDE_DIR} )
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppBox2dDemo
|
||||
main.cpp
|
||||
Box2dDemo.cpp
|
||||
Box2dDemo.h
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppBox2dDemo
|
||||
main.cpp
|
||||
Box2dDemo.cpp
|
||||
Box2dDemo.h
|
||||
)
|
||||
ENDIF()
|
||||
ELSE (USE_GLUT)
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppBox2dDemo
|
||||
WIN32
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
Win32Box2dDemo.cpp
|
||||
Box2dDemo.cpp
|
||||
Box2dDemo.h
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ENDIF (USE_GLUT)
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppBox2dDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppBox2dDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppBox2dDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
|
@ -1,25 +0,0 @@
|
||||
#ifdef _WINDOWS
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "Box2dDemo.h"
|
||||
|
||||
///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo
|
||||
DemoApplication* createDemo()
|
||||
{
|
||||
return new Box2dDemo();
|
||||
}
|
||||
|
||||
#endif
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "Box2dDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
|
||||
class OurValue
|
||||
{
|
||||
int m_uid;
|
||||
|
||||
public:
|
||||
OurValue(const btVector3& initialPos)
|
||||
:m_position(initialPos)
|
||||
{
|
||||
static int gUid=0;
|
||||
m_uid=gUid;
|
||||
gUid++;
|
||||
}
|
||||
|
||||
btVector3 m_position;
|
||||
int getUid() const
|
||||
{
|
||||
return m_uid;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
|
||||
Box2dDemo ccdDemo;
|
||||
ccdDemo.initPhysics();
|
||||
ccdDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
|
||||
#ifdef CHECK_MEMORY_LEAKS
|
||||
ccdDemo.exitPhysics();
|
||||
#else
|
||||
return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.com",&ccdDemo);
|
||||
#endif
|
||||
|
||||
//default glut doesn't return from mainloop
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 BSP_DEMO_H
|
||||
#define BSP_DEMO_H
|
||||
|
||||
#include "GlutDemoApplication.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
|
||||
|
||||
///BspDemo shows the convex collision detection, by converting a Quake BSP file into convex objects and allowing interaction with boxes.
|
||||
class BspDemo : public GlutDemoApplication
|
||||
{
|
||||
public:
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
|
||||
|
||||
|
||||
virtual ~BspDemo();
|
||||
|
||||
virtual void initPhysics();
|
||||
|
||||
void initPhysics(const char* bspfilename);
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BspDemo* demo = new BspDemo;
|
||||
demo->myinit();
|
||||
demo->initPhysics("BspDemo.bsp");
|
||||
return demo;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //BSP_DEMO_H
|
||||
|
||||
|
@ -1,46 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppBspPhysicsDemo
|
||||
main.cpp
|
||||
BspDemo.cpp
|
||||
BspLoader.cpp
|
||||
BspConverter.cpp
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppBspPhysicsDemo
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/BspDemo/BspDemo.bsp ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppBspPhysicsDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppBspPhysicsDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppBspPhysicsDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "BspDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
char* makeExeToBspFilename(const char* lpCmdLine);
|
||||
char* getLastFileName();
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
BspDemo* bspDemo = new BspDemo();
|
||||
|
||||
const char* bspfilename = "BspDemo.bsp";
|
||||
|
||||
printf("argc=%i\n",argc);
|
||||
{
|
||||
for (int i=0;i<argc;i++)
|
||||
{
|
||||
printf("argv[%i]=%s\n",i,argv[i]);
|
||||
}
|
||||
|
||||
bspfilename = makeExeToBspFilename(argv[0]);
|
||||
printf("new name=%s\n",bspfilename);
|
||||
}
|
||||
if (argc>1)
|
||||
{
|
||||
bspfilename = argv[1];
|
||||
}
|
||||
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
|
||||
// Enrico: TODO: Should change parameter type of initPhysics() to std::string or at least const char *
|
||||
bspDemo->initPhysics((char*)bspfilename);
|
||||
|
||||
bspDemo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
|
||||
|
||||
return glutmain(argc, argv,640,480,"Bullet Quake BSP Physics Viewer http://bulletphysics.org",bspDemo);
|
||||
}
|
||||
|
@ -1,996 +0,0 @@
|
||||
|
||||
/* This demo has been modified to use the Bullet C-API.
|
||||
The C-API is minimal, and will develop based on developer feedback.
|
||||
The C++ API is recommended, and compatible with the C-API.
|
||||
*/
|
||||
|
||||
/* Copyright (c) Mark J. Kilgard, 1994, 1997. */
|
||||
|
||||
/* This program is freely distributable without licensing fees
|
||||
and is provided without guarantee or warrantee expressed or
|
||||
implied. This program is -not- in the public domain. */
|
||||
|
||||
/* Example for PC game developers to show how to *combine* texturing,
|
||||
reflections, and projected shadows all in real-time with OpenGL.
|
||||
Robust reflections use stenciling. Robust projected shadows
|
||||
use both stenciling and polygon offset. PC game programmers
|
||||
should realize that neither stenciling nor polygon offset are
|
||||
supported by Direct3D, so these real-time rendering algorithms
|
||||
are only really viable with OpenGL.
|
||||
|
||||
The program has modes for disabling the stenciling and polygon
|
||||
offset uses. It is worth running this example with these features
|
||||
toggled off so you can see the sort of artifacts that result.
|
||||
|
||||
Notice that the floor texturing, reflections, and shadowing
|
||||
all co-exist properly. */
|
||||
|
||||
/* When you run this program: Left mouse button controls the
|
||||
view. Middle mouse button controls light position (left &
|
||||
right rotates light around dino; up & down moves light
|
||||
position up and down). Right mouse button pops up menu. */
|
||||
|
||||
/* Check out the comments in the "redraw" routine to see how the
|
||||
reflection blending and surface stenciling is done. You can
|
||||
also see in "redraw" how the projected shadows are rendered,
|
||||
including the use of stenciling and polygon offset. */
|
||||
|
||||
/* This program is derived from glutdino.c */
|
||||
|
||||
/* Compile: cc -o dinoshade dinoshade.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h> /* for cos(), sin(), and sqrt() */
|
||||
#ifdef WIN32//for glut.h
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef CALLBACK
|
||||
#define CALLBACK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//think different
|
||||
#if defined(__APPLE__) && !defined (VMDMESA)
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#include <GLUT/glut.h>
|
||||
#define GLVOIDPTR GLvoid(*)()
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#include <GL/glext.h>
|
||||
#define GLVOIDPTR void(CALLBACK*)()
|
||||
#endif
|
||||
|
||||
/* Some <math.h> files do not define M_PI... */
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
|
||||
//#include "../../include/Bullet-C-Api.h"
|
||||
#include "Bullet-C-Api.h"
|
||||
|
||||
|
||||
|
||||
plPhysicsSdkHandle physicsSdk=0;
|
||||
plDynamicsWorldHandle dynamicsWorld=0;
|
||||
plRigidBodyHandle floorRigidBody;
|
||||
plRigidBodyHandle dinoRigidBody;
|
||||
|
||||
/* Variable controlling various rendering modes. */
|
||||
static int stencilReflection = 1, stencilShadow = 1, offsetShadow = 1;
|
||||
static int renderShadow = 1, renderDinosaur = 1, renderReflection = 1;
|
||||
static int linearFiltering = 0, useMipmaps = 0, useTexture = 1;
|
||||
static int reportSpeed = 0;
|
||||
static int animation = 1;
|
||||
static GLboolean lightSwitch = GL_TRUE;
|
||||
static int directionalLight = 1;
|
||||
static int forceExtension = 0;
|
||||
|
||||
/* Time varying or user-controled variables. */
|
||||
static float jump = 0.0;
|
||||
static float lightAngle = 0.0, lightHeight = 20;
|
||||
GLfloat angle = -150; /* in degrees */
|
||||
GLfloat angle2 = 30; /* in degrees */
|
||||
|
||||
int moving, startx, starty;
|
||||
int lightMoving = 0, lightStartX, lightStartY;
|
||||
|
||||
enum {
|
||||
MISSING, EXTENSION, ONE_DOT_ONE
|
||||
};
|
||||
int polygonOffsetVersion;
|
||||
|
||||
static GLdouble bodyWidth = 3.0;
|
||||
/* *INDENT-OFF* */
|
||||
static GLfloat body[][2] = { {0, 3}, {1, 1}, {5, 1}, {8, 4}, {10, 4}, {11, 5},
|
||||
{11, 11.5}, {13, 12}, {13, 13}, {10, 13.5}, {13, 14}, {13, 15}, {11, 16},
|
||||
{8, 16}, {7, 15}, {7, 13}, {8, 12}, {7, 11}, {6, 6}, {4, 3}, {3, 2},
|
||||
{1, 2} };
|
||||
static GLfloat arm[][2] = { {8, 10}, {9, 9}, {10, 9}, {13, 8}, {14, 9}, {16, 9},
|
||||
{15, 9.5}, {16, 10}, {15, 10}, {15.5, 11}, {14.5, 10}, {14, 11}, {14, 10},
|
||||
{13, 9}, {11, 11}, {9, 11} };
|
||||
static GLfloat leg[][2] = { {8, 6}, {8, 4}, {9, 3}, {9, 2}, {8, 1}, {8, 0.5}, {9, 0},
|
||||
{12, 0}, {10, 1}, {10, 2}, {12, 4}, {11, 6}, {10, 7}, {9, 7} };
|
||||
static GLfloat eye[][2] = { {8.75, 15}, {9, 14.7}, {9.6, 14.7}, {10.1, 15},
|
||||
{9.6, 15.25}, {9, 15.25} };
|
||||
static GLfloat lightPosition[4];
|
||||
static GLfloat lightColor[] = {0.8, 1.0, 0.8, 1.0}; /* green-tinted */
|
||||
static GLfloat skinColor[] = {0.1, 1.0, 0.1, 1.0}, eyeColor[] = {1.0, 0.2, 0.2, 1.0};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* Nice floor texture tiling pattern. */
|
||||
static char *circles[] = {
|
||||
"....xxxx........",
|
||||
"..xxxxxxxx......",
|
||||
".xxxxxxxxxx.....",
|
||||
".xxx....xxx.....",
|
||||
"xxx......xxx....",
|
||||
"xxx......xxx....",
|
||||
"xxx......xxx....",
|
||||
"xxx......xxx....",
|
||||
".xxx....xxx.....",
|
||||
".xxxxxxxxxx.....",
|
||||
"..xxxxxxxx......",
|
||||
"....xxxx........",
|
||||
"................",
|
||||
"................",
|
||||
"................",
|
||||
"................",
|
||||
};
|
||||
|
||||
static void
|
||||
makeFloorTexture(void)
|
||||
{
|
||||
GLubyte floorTexture[16][16][3];
|
||||
GLubyte *loc;
|
||||
int s, t;
|
||||
loc=0;
|
||||
|
||||
/* Setup RGB image for the texture. */
|
||||
loc = (GLubyte*) floorTexture;
|
||||
for (t = 0; t < 16; t++) {
|
||||
for (s = 0; s < 16; s++) {
|
||||
if (circles[t][s] == 'x') {
|
||||
/* Nice green. */
|
||||
loc[0] = 0x1f;
|
||||
loc[1] = 0x8f;
|
||||
loc[2] = 0x1f;
|
||||
} else {
|
||||
/* Light gray. */
|
||||
loc[0] = 0xaa;
|
||||
loc[1] = 0xaa;
|
||||
loc[2] = 0xaa;
|
||||
}
|
||||
loc += 3;
|
||||
}
|
||||
}
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
if (useMipmaps) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
GL_LINEAR_MIPMAP_LINEAR);
|
||||
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 16, 16,
|
||||
GL_RGB, GL_UNSIGNED_BYTE, floorTexture);
|
||||
} else {
|
||||
if (linearFiltering) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
} else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,
|
||||
GL_RGB, GL_UNSIGNED_BYTE, floorTexture);
|
||||
}
|
||||
}
|
||||
|
||||
enum {
|
||||
X, Y, Z, W
|
||||
};
|
||||
enum {
|
||||
A, B, C, D
|
||||
};
|
||||
|
||||
/* Create a matrix that will project the desired shadow. */
|
||||
void
|
||||
shadowMatrix(GLfloat shadowMat[4][4],
|
||||
GLfloat groundplane[4],
|
||||
GLfloat lightpos[4])
|
||||
{
|
||||
GLfloat dot;
|
||||
|
||||
/* Find dot product between light position vector and ground plane normal. */
|
||||
dot = groundplane[X] * lightpos[X] +
|
||||
groundplane[Y] * lightpos[Y] +
|
||||
groundplane[Z] * lightpos[Z] +
|
||||
groundplane[W] * lightpos[W];
|
||||
|
||||
shadowMat[0][0] = dot - lightpos[X] * groundplane[X];
|
||||
shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y];
|
||||
shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z];
|
||||
shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W];
|
||||
|
||||
shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X];
|
||||
shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y];
|
||||
shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z];
|
||||
shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W];
|
||||
|
||||
shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X];
|
||||
shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y];
|
||||
shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z];
|
||||
shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W];
|
||||
|
||||
shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X];
|
||||
shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y];
|
||||
shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z];
|
||||
shadowMat[3][3] = dot - lightpos[W] * groundplane[W];
|
||||
|
||||
}
|
||||
|
||||
/* Find the plane equation given 3 points. */
|
||||
void
|
||||
findPlane(GLfloat plane[4],
|
||||
GLfloat v0[3], GLfloat v1[3], GLfloat v2[3])
|
||||
{
|
||||
GLfloat vec0[3], vec1[3];
|
||||
|
||||
/* Need 2 vectors to find cross product. */
|
||||
vec0[X] = v1[X] - v0[X];
|
||||
vec0[Y] = v1[Y] - v0[Y];
|
||||
vec0[Z] = v1[Z] - v0[Z];
|
||||
|
||||
vec1[X] = v2[X] - v0[X];
|
||||
vec1[Y] = v2[Y] - v0[Y];
|
||||
vec1[Z] = v2[Z] - v0[Z];
|
||||
|
||||
/* find cross product to get A, B, and C of plane equation */
|
||||
plane[A] = vec0[Y] * vec1[Z] - vec0[Z] * vec1[Y];
|
||||
plane[B] = -(vec0[X] * vec1[Z] - vec0[Z] * vec1[X]);
|
||||
plane[C] = vec0[X] * vec1[Y] - vec0[Y] * vec1[X];
|
||||
|
||||
plane[D] = -(plane[A] * v0[X] + plane[B] * v0[Y] + plane[C] * v0[Z]);
|
||||
}
|
||||
|
||||
void
|
||||
extrudeSolidFromPolygon(GLfloat data[][2], unsigned int dataSize,
|
||||
GLdouble thickness, GLuint side, GLuint edge, GLuint whole)
|
||||
{
|
||||
static GLUtriangulatorObj *tobj = NULL;
|
||||
GLdouble vertex[3], dx, dy, len;
|
||||
int i;
|
||||
int count = dataSize / (2 * sizeof(GLfloat));
|
||||
|
||||
if (tobj == NULL) {
|
||||
tobj = gluNewTess(); /* create and initialize a GLU
|
||||
polygon * * tesselation object */
|
||||
gluTessCallback(tobj, (GLenum)GLU_BEGIN, (GLVOIDPTR)glBegin);
|
||||
gluTessCallback(tobj, (GLenum)GLU_VERTEX, (GLVOIDPTR)glVertex2fv); /* semi-tricky */
|
||||
gluTessCallback(tobj, (GLenum)GLU_END, (GLVOIDPTR)glEnd);
|
||||
}
|
||||
glNewList(side, GL_COMPILE);
|
||||
glShadeModel(GL_SMOOTH); /* smooth minimizes seeing
|
||||
tessellation */
|
||||
gluBeginPolygon(tobj);
|
||||
for (i = 0; i < count; i++) {
|
||||
vertex[0] = data[i][0];
|
||||
vertex[1] = data[i][1];
|
||||
vertex[2] = 0;
|
||||
gluTessVertex(tobj, vertex, data[i]);
|
||||
}
|
||||
gluEndPolygon(tobj);
|
||||
glEndList();
|
||||
glNewList(edge, GL_COMPILE);
|
||||
glShadeModel(GL_FLAT); /* flat shade keeps angular hands
|
||||
from being "smoothed" */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= count; i++) {
|
||||
/* mod function handles closing the edge */
|
||||
glVertex3f(data[i % count][0], data[i % count][1], 0.0);
|
||||
glVertex3f(data[i % count][0], data[i % count][1], thickness);
|
||||
/* Calculate a unit normal by dividing by Euclidean
|
||||
distance. We * could be lazy and use
|
||||
glEnable(GL_NORMALIZE) so we could pass in * arbitrary
|
||||
normals for a very slight performance hit. */
|
||||
dx = data[(i + 1) % count][1] - data[i % count][1];
|
||||
dy = data[i % count][0] - data[(i + 1) % count][0];
|
||||
len = sqrt(dx * dx + dy * dy);
|
||||
glNormal3f(dx / len, dy / len, 0.0);
|
||||
}
|
||||
glEnd();
|
||||
glEndList();
|
||||
glNewList(whole, GL_COMPILE);
|
||||
glFrontFace(GL_CW);
|
||||
glCallList(edge);
|
||||
glNormal3f(0.0, 0.0, -1.0); /* constant normal for side */
|
||||
glCallList(side);
|
||||
glPushMatrix();
|
||||
glTranslatef(0.0, 0.0, thickness);
|
||||
glFrontFace(GL_CCW);
|
||||
glNormal3f(0.0, 0.0, 1.0); /* opposite normal for other side */
|
||||
glCallList(side);
|
||||
glPopMatrix();
|
||||
glEndList();
|
||||
}
|
||||
|
||||
/* Enumerants for refering to display lists. */
|
||||
typedef enum {
|
||||
RESERVED, BODY_SIDE, BODY_EDGE, BODY_WHOLE, ARM_SIDE, ARM_EDGE, ARM_WHOLE,
|
||||
LEG_SIDE, LEG_EDGE, LEG_WHOLE, EYE_SIDE, EYE_EDGE, EYE_WHOLE
|
||||
} displayLists;
|
||||
|
||||
static void
|
||||
makeDinosaur(void)
|
||||
{
|
||||
extrudeSolidFromPolygon(body, sizeof(body), bodyWidth,
|
||||
BODY_SIDE, BODY_EDGE, BODY_WHOLE);
|
||||
extrudeSolidFromPolygon(arm, sizeof(arm), bodyWidth / 4,
|
||||
ARM_SIDE, ARM_EDGE, ARM_WHOLE);
|
||||
extrudeSolidFromPolygon(leg, sizeof(leg), bodyWidth / 2,
|
||||
LEG_SIDE, LEG_EDGE, LEG_WHOLE);
|
||||
extrudeSolidFromPolygon(eye, sizeof(eye), bodyWidth + 0.2,
|
||||
EYE_SIDE, EYE_EDGE, EYE_WHOLE);
|
||||
}
|
||||
|
||||
static void
|
||||
drawDinosaur(void)
|
||||
|
||||
{
|
||||
plReal matrix[16];
|
||||
|
||||
glPushMatrix();
|
||||
/* Translate the dinosaur to be at (0,8,0). */
|
||||
|
||||
plGetOpenGLMatrix(dinoRigidBody,matrix);
|
||||
// plGetPosition(dinoRigidBody,dinoWorldPos);
|
||||
// glTranslatef(-8, 0, -bodyWidth / 2);
|
||||
//glTranslatef(0.0, jump, 0.0);
|
||||
// glTranslatef(dinoWorldPos[0],dinoWorldPos[1],dinoWorldPos[2]);
|
||||
|
||||
#ifdef BT_USE_DOUBLE_PRECISION
|
||||
glMultMatrixd(matrix);
|
||||
#else
|
||||
glMultMatrixf(matrix);
|
||||
#endif
|
||||
// glutSolidCube(15);
|
||||
glTranslatef(-8.5, -8.5, 0);
|
||||
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, skinColor);
|
||||
glCallList(BODY_WHOLE);
|
||||
glTranslatef(0.0, 0.0, bodyWidth);
|
||||
glCallList(ARM_WHOLE);
|
||||
glCallList(LEG_WHOLE);
|
||||
glTranslatef(0.0, 0.0, -bodyWidth - bodyWidth / 4);
|
||||
glCallList(ARM_WHOLE);
|
||||
glTranslatef(0.0, 0.0, -bodyWidth / 4);
|
||||
glCallList(LEG_WHOLE);
|
||||
glTranslatef(0.0, 0.0, bodyWidth / 2 - 0.1);
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, eyeColor);
|
||||
glCallList(EYE_WHOLE);
|
||||
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
static GLfloat floorVertices[4][3] = {
|
||||
{ -20.0, 0.0, 20.0 },
|
||||
{ 20.0, 0.0, 20.0 },
|
||||
{ 20.0, 0.0, -20.0 },
|
||||
{ -20.0, 0.0, -20.0 },
|
||||
};
|
||||
|
||||
/* Draw a floor (possibly textured). */
|
||||
static void
|
||||
drawFloor(void)
|
||||
{
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
if (useTexture) {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0, 0.0);
|
||||
glVertex3fv(floorVertices[0]);
|
||||
glTexCoord2f(0.0, 16.0);
|
||||
glVertex3fv(floorVertices[1]);
|
||||
glTexCoord2f(16.0, 16.0);
|
||||
glVertex3fv(floorVertices[2]);
|
||||
glTexCoord2f(16.0, 0.0);
|
||||
glVertex3fv(floorVertices[3]);
|
||||
glEnd();
|
||||
|
||||
if (useTexture) {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
static GLfloat floorPlane[4];
|
||||
static GLfloat floorShadow[4][4];
|
||||
|
||||
static void
|
||||
redraw(void)
|
||||
{
|
||||
int start = 0, end = 0 ;
|
||||
|
||||
if (reportSpeed) {
|
||||
start = glutGet(GLUT_ELAPSED_TIME);
|
||||
}
|
||||
|
||||
/* Clear; default stencil clears to zero. */
|
||||
if ((stencilReflection && renderReflection) || (stencilShadow && renderShadow)) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
} else {
|
||||
/* Avoid clearing stencil when not using it. */
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
/* Reposition the light source. */
|
||||
lightPosition[0] = 12*cos(lightAngle);
|
||||
lightPosition[1] = lightHeight;
|
||||
lightPosition[2] = 12*sin(lightAngle);
|
||||
if (directionalLight) {
|
||||
lightPosition[3] = 0.0;
|
||||
} else {
|
||||
lightPosition[3] = 1.0;
|
||||
}
|
||||
|
||||
shadowMatrix(floorShadow, floorPlane, lightPosition);
|
||||
|
||||
glPushMatrix();
|
||||
/* Perform scene rotations based on user mouse input. */
|
||||
glRotatef(angle2, 1.0, 0.0, 0.0);
|
||||
glRotatef(angle, 0.0, 1.0, 0.0);
|
||||
|
||||
/* Tell GL new light source position. */
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
|
||||
|
||||
if (renderReflection) {
|
||||
if (stencilReflection) {
|
||||
/* We can eliminate the visual "artifact" of seeing the "flipped"
|
||||
dinosaur underneath the floor by using stencil. The idea is
|
||||
draw the floor without color or depth update but so that
|
||||
a stencil value of one is where the floor will be. Later when
|
||||
rendering the dinosaur reflection, we will only update pixels
|
||||
with a stencil value of 1 to make sure the reflection only
|
||||
lives on the floor, not below the floor. */
|
||||
|
||||
/* Don't update color or depth. */
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
|
||||
/* Draw 1 into the stencil buffer. */
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
||||
glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
|
||||
|
||||
/* Now render floor; floor pixels just get their stencil set to 1. */
|
||||
drawFloor();
|
||||
|
||||
/* Re-enable update of color and depth. */
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* Now, only render where stencil is set to 1. */
|
||||
glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if ==1 */
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
/* The critical reflection step: Reflect dinosaur through the floor
|
||||
(the Y=0 plane) to make a relection. */
|
||||
glScalef(1.0, -1.0, 1.0);
|
||||
|
||||
/* Reflect the light position. */
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
|
||||
|
||||
/* To avoid our normals getting reversed and hence botched lighting
|
||||
on the reflection, turn on normalize. */
|
||||
glEnable(GL_NORMALIZE);
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
/* Draw the reflected dinosaur. */
|
||||
drawDinosaur();
|
||||
|
||||
/* Disable noramlize again and re-enable back face culling. */
|
||||
glDisable(GL_NORMALIZE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
/* Switch back to the unreflected light position. */
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
|
||||
|
||||
if (stencilReflection) {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
/* Back face culling will get used to only draw either the top or the
|
||||
bottom floor. This let's us get a floor with two distinct
|
||||
appearances. The top floor surface is reflective and kind of red.
|
||||
The bottom floor surface is not reflective and blue. */
|
||||
|
||||
/* Draw "bottom" of floor in blue. */
|
||||
glFrontFace(GL_CW); /* Switch face orientation. */
|
||||
glColor4f(0.1, 0.1, 0.7, 1.0);
|
||||
drawFloor();
|
||||
glFrontFace(GL_CCW);
|
||||
|
||||
if (renderShadow) {
|
||||
if (stencilShadow) {
|
||||
/* Draw the floor with stencil value 3. This helps us only
|
||||
draw the shadow once per floor pixel (and only on the
|
||||
floor pixels). */
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glStencilFunc(GL_ALWAYS, 3, 0xffffffff);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw "top" of floor. Use blending to blend in reflection. */
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor4f(0.7, 0.0, 0.0, 0.3);
|
||||
glColor4f(1.0, 1.0, 1.0, 0.3);
|
||||
drawFloor();
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
if (renderDinosaur) {
|
||||
/* Draw "actual" dinosaur, not its reflection. */
|
||||
drawDinosaur();
|
||||
}
|
||||
|
||||
if (renderShadow) {
|
||||
|
||||
/* Render the projected shadow. */
|
||||
|
||||
if (stencilShadow) {
|
||||
|
||||
/* Now, only render where stencil is set above 2 (ie, 3 where
|
||||
the top floor is). Update stencil with 2 where the shadow
|
||||
gets drawn so we don't redraw (and accidently reblend) the
|
||||
shadow). */
|
||||
glStencilFunc(GL_LESS, 2, 0xffffffff); /* draw if ==1 */
|
||||
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
||||
}
|
||||
|
||||
/* To eliminate depth buffer artifacts, we use polygon offset
|
||||
to raise the depth of the projected shadow slightly so
|
||||
that it does not depth buffer alias with the floor. */
|
||||
if (offsetShadow) {
|
||||
switch (polygonOffsetVersion) {
|
||||
case EXTENSION:
|
||||
#ifdef GL_VERSION_1_1
|
||||
case ONE_DOT_ONE:
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
break;
|
||||
#endif
|
||||
case MISSING:
|
||||
/* Oh well. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Render 50% black shadow color on top of whatever the
|
||||
floor appareance is. */
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_LIGHTING); /* Force the 50% black. */
|
||||
glColor4f(0.0, 0.0, 0.0, 0.5);
|
||||
|
||||
glPushMatrix();
|
||||
/* Project the shadow. */
|
||||
glMultMatrixf((GLfloat *) floorShadow);
|
||||
drawDinosaur();
|
||||
glPopMatrix();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
if (offsetShadow) {
|
||||
switch (polygonOffsetVersion) {
|
||||
#ifdef GL_VERSION_1_1
|
||||
case ONE_DOT_ONE:
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
break;
|
||||
#endif
|
||||
case MISSING:
|
||||
/* Oh well. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (stencilShadow) {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor3f(1.0, 1.0, 0.0);
|
||||
if (directionalLight) {
|
||||
/* Draw an arrowhead. */
|
||||
glDisable(GL_CULL_FACE);
|
||||
glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);
|
||||
glRotatef(lightAngle * -180.0 / M_PI, 0, 1, 0);
|
||||
glRotatef(atan(lightHeight/12) * 180.0 / M_PI, 0, 0, 1);
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glVertex3f(0, 0, 0);
|
||||
glVertex3f(2, 1, 1);
|
||||
glVertex3f(2, -1, 1);
|
||||
glVertex3f(2, -1, -1);
|
||||
glVertex3f(2, 1, -1);
|
||||
glVertex3f(2, 1, 1);
|
||||
glEnd();
|
||||
/* Draw a white line from light direction. */
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(0, 0, 0);
|
||||
glVertex3f(5, 0, 0);
|
||||
glEnd();
|
||||
glEnable(GL_CULL_FACE);
|
||||
} else {
|
||||
/* Draw a yellow ball at the light source. */
|
||||
glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);
|
||||
glutSolidSphere(1.0, 5, 5);
|
||||
}
|
||||
glEnable(GL_LIGHTING);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
if (reportSpeed) {
|
||||
glFinish();
|
||||
end = glutGet(GLUT_ELAPSED_TIME);
|
||||
printf("Speed %.3g frames/sec (%d ms)\n", 1000.0/(end-start), end-start);
|
||||
}
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
/* ARGSUSED2 */
|
||||
static void
|
||||
mouse(int button, int state, int x, int y)
|
||||
{
|
||||
if (button == GLUT_LEFT_BUTTON) {
|
||||
if (state == GLUT_DOWN) {
|
||||
moving = 1;
|
||||
startx = x;
|
||||
starty = y;
|
||||
}
|
||||
if (state == GLUT_UP) {
|
||||
moving = 0;
|
||||
}
|
||||
}
|
||||
if (button == GLUT_MIDDLE_BUTTON) {
|
||||
if (state == GLUT_DOWN) {
|
||||
lightMoving = 1;
|
||||
lightStartX = x;
|
||||
lightStartY = y;
|
||||
}
|
||||
if (state == GLUT_UP) {
|
||||
lightMoving = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ARGSUSED1 */
|
||||
static void
|
||||
motion(int x, int y)
|
||||
{
|
||||
if (moving) {
|
||||
angle = angle + (x - startx);
|
||||
angle2 = angle2 + (y - starty);
|
||||
startx = x;
|
||||
starty = y;
|
||||
glutPostRedisplay();
|
||||
}
|
||||
if (0){//lightMoving) {
|
||||
lightAngle += (x - lightStartX)/40.0;
|
||||
lightHeight += (lightStartY - y)/20.0;
|
||||
lightStartX = x;
|
||||
lightStartY = y;
|
||||
glutPostRedisplay();
|
||||
}
|
||||
}
|
||||
|
||||
/* Advance time varying state when idle callback registered. */
|
||||
static void
|
||||
idle(void)
|
||||
{
|
||||
static float time = 0.0;
|
||||
static float prevtime = 0.0;
|
||||
float dtime;
|
||||
prevtime = time;
|
||||
|
||||
time = glutGet(GLUT_ELAPSED_TIME) / 500.0;
|
||||
dtime = time - prevtime;
|
||||
|
||||
jump = 4.0 * fabs(sin(time)*0.5);
|
||||
if (!lightMoving) {
|
||||
lightAngle = time;
|
||||
}
|
||||
|
||||
if (dynamicsWorld)
|
||||
plStepSimulation(dynamicsWorld,dtime);
|
||||
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
enum {
|
||||
M_NONE, M_MOTION, M_LIGHT, M_TEXTURE, M_SHADOWS, M_REFLECTION, M_DINOSAUR,
|
||||
M_STENCIL_REFLECTION, M_STENCIL_SHADOW, M_OFFSET_SHADOW,
|
||||
M_POSITIONAL, M_DIRECTIONAL, M_PERFORMANCE
|
||||
};
|
||||
|
||||
static void
|
||||
controlLights(int value)
|
||||
{
|
||||
switch (value) {
|
||||
case M_NONE:
|
||||
return;
|
||||
case M_MOTION:
|
||||
animation = 1 - animation;
|
||||
if (animation) {
|
||||
glutIdleFunc(idle);
|
||||
} else {
|
||||
glutIdleFunc(NULL);
|
||||
}
|
||||
break;
|
||||
case M_LIGHT:
|
||||
lightSwitch = !lightSwitch;
|
||||
if (lightSwitch) {
|
||||
glEnable(GL_LIGHT0);
|
||||
} else {
|
||||
glDisable(GL_LIGHT0);
|
||||
}
|
||||
break;
|
||||
case M_TEXTURE:
|
||||
useTexture = !useTexture;
|
||||
break;
|
||||
case M_SHADOWS:
|
||||
renderShadow = 1 - renderShadow;
|
||||
break;
|
||||
case M_REFLECTION:
|
||||
renderReflection = 1 - renderReflection;
|
||||
break;
|
||||
case M_DINOSAUR:
|
||||
renderDinosaur = 1 - renderDinosaur;
|
||||
break;
|
||||
case M_STENCIL_REFLECTION:
|
||||
stencilReflection = 1 - stencilReflection;
|
||||
break;
|
||||
case M_STENCIL_SHADOW:
|
||||
stencilShadow = 1 - stencilShadow;
|
||||
break;
|
||||
case M_OFFSET_SHADOW:
|
||||
offsetShadow = 1 - offsetShadow;
|
||||
break;
|
||||
case M_POSITIONAL:
|
||||
directionalLight = 0;
|
||||
break;
|
||||
case M_DIRECTIONAL:
|
||||
directionalLight = 1;
|
||||
break;
|
||||
case M_PERFORMANCE:
|
||||
reportSpeed = 1 - reportSpeed;
|
||||
break;
|
||||
}
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
/* When not visible, stop animating. Restart when visible again. */
|
||||
static void
|
||||
visible(int vis)
|
||||
{
|
||||
if (vis == GLUT_VISIBLE) {
|
||||
if (animation)
|
||||
glutIdleFunc(idle);
|
||||
} else {
|
||||
if (!animation)
|
||||
glutIdleFunc(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Press any key to redraw; good when motion stopped and
|
||||
performance reporting on. */
|
||||
/* ARGSUSED */
|
||||
static void
|
||||
key(unsigned char c, int x, int y)
|
||||
{
|
||||
if (c == 27) {
|
||||
exit(0); /* IRIS GLism, Escape quits. */
|
||||
}
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
/* Press any key to redraw; good when motion stopped and
|
||||
performance reporting on. */
|
||||
/* ARGSUSED */
|
||||
static void
|
||||
special(int k, int x, int y)
|
||||
{
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
static int
|
||||
supportsOneDotOne(void)
|
||||
{
|
||||
const char *version;
|
||||
int major, minor;
|
||||
|
||||
version = (char *) glGetString(GL_VERSION);
|
||||
if (sscanf(version, "%d.%d", &major, &minor) == 2)
|
||||
return ((major > 1) || (major >= 1 && minor >= 1));
|
||||
return 0; /* OpenGL version string malformed! */
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
plCollisionShapeHandle floorShape;
|
||||
plCollisionShapeHandle dinoShape,dinoChildShape;
|
||||
plVector3 floorPos,childPos;
|
||||
plVector3 dinoPos;
|
||||
plQuaternion childOrn,dinoOrient;
|
||||
|
||||
void* user_data=NULL;
|
||||
|
||||
physicsSdk = plNewBulletSdk();
|
||||
dynamicsWorld = plCreateDynamicsWorld(physicsSdk);
|
||||
|
||||
//create ground plane
|
||||
|
||||
floorShape = plNewConvexHullShape();
|
||||
|
||||
for (i=0;i<4;i++)
|
||||
{
|
||||
// floorVertices
|
||||
plAddVertex(floorShape,floorVertices[i][0],floorVertices[i][1],floorVertices[i][2]);
|
||||
}
|
||||
|
||||
|
||||
floorShape = plNewBoxShape(120,0,120);
|
||||
|
||||
floorRigidBody = plCreateRigidBody(user_data,0.f,floorShape);
|
||||
floorPos[0] = 0;
|
||||
floorPos[1] = 0;
|
||||
floorPos[2] = 0;
|
||||
|
||||
plSetPosition(floorRigidBody,floorPos);
|
||||
plAddRigidBody(dynamicsWorld,floorRigidBody);
|
||||
|
||||
//create dino rigidbody
|
||||
dinoChildShape = plNewBoxShape(8.5,8.5,8.5);
|
||||
dinoShape = plNewCompoundShape();
|
||||
childPos[0] = 0;
|
||||
childPos[1] = 0;
|
||||
childPos[2] = 0;
|
||||
childOrn[0] = 0;
|
||||
childOrn[1] = 0;
|
||||
childOrn[2] = 0;
|
||||
childOrn[3] = 1;
|
||||
|
||||
plAddChildShape(dinoShape,dinoChildShape,childPos,childOrn);
|
||||
|
||||
dinoPos[0] = -10; dinoPos[1] = 28; dinoPos[2] = 0;
|
||||
dinoRigidBody = plCreateRigidBody(0,1.0,dinoShape);
|
||||
plSetPosition(dinoRigidBody,dinoPos);
|
||||
plSetEuler(0,0,3.15*0.20,dinoOrient);
|
||||
plSetOrientation(dinoRigidBody,dinoOrient);
|
||||
|
||||
plAddRigidBody(dynamicsWorld,dinoRigidBody);
|
||||
|
||||
printf("BulletDino\n");
|
||||
glutInit(&argc, argv);
|
||||
|
||||
for (i=1; i<argc; i++) {
|
||||
if (!strcmp("-linear", argv[i])) {
|
||||
linearFiltering = 1;
|
||||
} else if (!strcmp("-mipmap", argv[i])) {
|
||||
useMipmaps = 1;
|
||||
} else if (!strcmp("-ext", argv[i])) {
|
||||
forceExtension = 1;
|
||||
}
|
||||
}
|
||||
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL | GLUT_MULTISAMPLE);
|
||||
|
||||
#if 0
|
||||
/* In GLUT 4.0, you'll be able to do this an be sure to
|
||||
get 2 bits of stencil if the machine has it for you. */
|
||||
glutInitDisplayString("samples stencil>=2 rgb double depth");
|
||||
#endif
|
||||
|
||||
glutCreateWindow("Shadowy Leapin' Lizards");
|
||||
|
||||
if (glutGet(GLUT_WINDOW_STENCIL_SIZE) <= 1) {
|
||||
printf("dinoshade: Sorry, I need at least 2 bits of stencil.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Register GLUT callbacks. */
|
||||
glutDisplayFunc(redraw);
|
||||
glutMouseFunc(mouse);
|
||||
glutMotionFunc(motion);
|
||||
glutVisibilityFunc(visible);
|
||||
glutKeyboardFunc(key);
|
||||
glutSpecialFunc(special);
|
||||
|
||||
glutCreateMenu(controlLights);
|
||||
|
||||
glutAddMenuEntry("Toggle motion", M_MOTION);
|
||||
glutAddMenuEntry("-----------------------", M_NONE);
|
||||
glutAddMenuEntry("Toggle light", M_LIGHT);
|
||||
glutAddMenuEntry("Toggle texture", M_TEXTURE);
|
||||
glutAddMenuEntry("Toggle shadows", M_SHADOWS);
|
||||
glutAddMenuEntry("Toggle reflection", M_REFLECTION);
|
||||
glutAddMenuEntry("Toggle dinosaur", M_DINOSAUR);
|
||||
glutAddMenuEntry("-----------------------", M_NONE);
|
||||
glutAddMenuEntry("Toggle reflection stenciling", M_STENCIL_REFLECTION);
|
||||
glutAddMenuEntry("Toggle shadow stenciling", M_STENCIL_SHADOW);
|
||||
glutAddMenuEntry("Toggle shadow offset", M_OFFSET_SHADOW);
|
||||
glutAddMenuEntry("----------------------", M_NONE);
|
||||
glutAddMenuEntry("Positional light", M_POSITIONAL);
|
||||
glutAddMenuEntry("Directional light", M_DIRECTIONAL);
|
||||
glutAddMenuEntry("-----------------------", M_NONE);
|
||||
glutAddMenuEntry("Toggle performance", M_PERFORMANCE);
|
||||
glutAttachMenu(GLUT_RIGHT_BUTTON);
|
||||
makeDinosaur();
|
||||
|
||||
#ifdef GL_VERSION_1_1
|
||||
if (supportsOneDotOne() && !forceExtension) {
|
||||
polygonOffsetVersion = ONE_DOT_ONE;
|
||||
glPolygonOffset(-2.0, -1.0);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
{
|
||||
polygonOffsetVersion = MISSING;
|
||||
printf("\ndinoshine: Missing polygon offset.\n");
|
||||
printf(" Expect shadow depth aliasing artifacts.\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glLineWidth(3.0);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
gluPerspective( /* field of view in degree */ 40.0,
|
||||
/* aspect ratio */ 1.0,
|
||||
/* Z near */ 20.0, /* Z far */ 100.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
gluLookAt(0.0, 8.0, 60.0, /* eye is at (0,0,30) */
|
||||
0.0, 8.0, 0.0, /* center is at (0,0,0) */
|
||||
0.0, 1.0, 0.); /* up is in postivie Y direction */
|
||||
|
||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
|
||||
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
|
||||
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
makeFloorTexture();
|
||||
|
||||
/* Setup floor plane for projected shadow calculations. */
|
||||
findPlane(floorPlane, floorVertices[1], floorVertices[2], floorVertices[3]);
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
plDeleteDynamicsWorld(dynamicsWorld);
|
||||
plDeletePhysicsSdk(physicsSdk);
|
||||
|
||||
|
||||
return 0; /* ANSI C requires main to return int. */
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# This is the variable for Windows. I use this to define the root of my directory structure.
|
||||
SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
# This is the shortcut to finding GLU, GLUT and OpenGL if they are properly installed on your system
|
||||
# This should be the case.
|
||||
INCLUDE (${CMAKE_ROOT}/Modules/FindGLU.cmake)
|
||||
INCLUDE (${CMAKE_ROOT}/Modules/FindGLUT.cmake)
|
||||
INCLUDE (${CMAKE_ROOT}/Modules/FindOpenGL.cmake)
|
||||
|
||||
|
||||
IF (WIN32)
|
||||
# This is the Windows code for which Opengl, and Glut are not properly installed
|
||||
# since I can't install them I must cheat and copy libraries around
|
||||
INCLUDE_DIRECTORIES(${GLUT_ROOT})
|
||||
# LINK_DIRECTORIES(${GLUT_ROOT}\\lib)
|
||||
IF (${GLUT_glut_LIBRARY} MATCHES "GLUT_glut_LIBRARY-NOTFOUND")
|
||||
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Glut/glut32.lib)
|
||||
# LINK_LIBRARIES(${GLUT_ROOT}\\lib\\glut32 ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY})
|
||||
# TARGET_LINK_LIBRARIES(table ${GLUT_ROOT}\\lib\\glut32)
|
||||
#
|
||||
# ADD_CUSTOM_COMMAND(TARGET table POST_BUILD COMMAND copy ${GLUT_ROOT}\\lib\\glut32.dll ${GLUT_ROOT}\\bin\\vs2005\\Debug
|
||||
# COMMAND copy ${GLUT_ROOT}\\lib\\glut32.dll ${GLUT_ROOT}\\bin\\vs2003\\Debug
|
||||
# COMMAND copy ${GLUT_ROOT}\\lib\\glut32.dll ${GLUT_ROOT}\\bin\\vs6\\Debug)
|
||||
ELSE (${GLUT_glut_LIBRARY} MATCHES "GLUT_glut_LIBRARY-NOTFOUND")
|
||||
# LINK_LIBRARIES(${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY})
|
||||
# TARGET_LINK_LIBRARIES(table ${GLUT_glut_LIBRARY})
|
||||
ENDIF(${GLUT_glut_LIBRARY} MATCHES "GLUT_glut_LIBRARY-NOTFOUND")
|
||||
# TARGET_LINK_LIBRARIES(table ${OPENGL_gl_LIBRARY})
|
||||
# TARGET_LINK_LIBRARIES(table ${OPENGL_glu_LIBRARY})
|
||||
ELSE (WIN32)
|
||||
# This is the lines for linux. This should always work if everything is installed and working fine.
|
||||
# SET(CMAKE_BUILD_TYPE Debug)
|
||||
# SET(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
INCLUDE_DIRECTORIES(/usr/include /usr/local/include ${GLUT_INCLUDE_DIR})
|
||||
# TARGET_LINK_LIBRARIES(table ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY})
|
||||
# TARGET_LINK_LIBRARIES(checker ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY})
|
||||
ENDIF (WIN32)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(BulletDino
|
||||
BulletDino.c
|
||||
)
|
||||
|
@ -1,198 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2010 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "BulletXmlImportDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btSerializer.h"
|
||||
#include "btBulletFile.h"
|
||||
#include "btBulletWorldImporter.h"
|
||||
#include "btBulletXmlWorldImporter.h"
|
||||
|
||||
#include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
|
||||
|
||||
void BulletXmlImportDemo::initPhysics()
|
||||
{
|
||||
setTexturing(true);
|
||||
setShadows(true);
|
||||
|
||||
|
||||
|
||||
setupEmptyDynamicsWorld();
|
||||
|
||||
|
||||
m_dynamicsWorld->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
|
||||
btBulletXmlWorldImporter* importer = new btBulletXmlWorldImporter(m_dynamicsWorld);
|
||||
static const char* filename = "bullet_basic.xml";
|
||||
|
||||
const char* prefix[]={"./","../","../../","../../../","../../../../", "BulletXmlImportDemo/", "Demos/BulletXmlImportDemo/",
|
||||
"../Demos/BulletXmlImportDemo/","../../Demos/BulletXmlImportDemo/"};
|
||||
int numPrefixes = sizeof(prefix)/sizeof(const char*);
|
||||
char relativeFileName[1024];
|
||||
bool fileFound = false;
|
||||
|
||||
for (int i=0;i<numPrefixes;i++)
|
||||
{
|
||||
sprintf(relativeFileName,"%s%s",prefix[i],filename);
|
||||
FILE* f = fopen(relativeFileName,"r");
|
||||
if (f)
|
||||
{
|
||||
fclose(f);
|
||||
fileFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
importer->loadFile(relativeFileName);
|
||||
// importer->loadFile("bulletser.xml");
|
||||
// importer->loadFile("bullet_constraints.xml");
|
||||
|
||||
}
|
||||
|
||||
void BulletXmlImportDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//simple dynamics world doesn't handle fixed-time-stepping
|
||||
float ms = getDeltaTimeMicroseconds();
|
||||
|
||||
///step the simulation
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
|
||||
|
||||
m_dynamicsWorld->stepSimulation(ms / 1000000.f);
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
}
|
||||
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
|
||||
swapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BulletXmlImportDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
renderme();
|
||||
|
||||
//optional but useful: debug drawing to detect problems
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
glFlush();
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
void BulletXmlImportDemo::setupEmptyDynamicsWorld()
|
||||
{
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
|
||||
btGImpactCollisionAlgorithm::registerAlgorithm(m_dispatcher);
|
||||
|
||||
m_broadphase = new btDbvtBroadphase();
|
||||
|
||||
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
|
||||
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
|
||||
m_solver = sol;
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
|
||||
//btGImpactCollisionAlgorithm::registerAlgorithm((btCollisionDispatcher*)m_dynamicsWorld->getDispatcher());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BulletXmlImportDemo::~BulletXmlImportDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
|
||||
void BulletXmlImportDemo::clientResetScene()
|
||||
{
|
||||
exitPhysics();
|
||||
initPhysics();
|
||||
}
|
||||
|
||||
|
||||
void BulletXmlImportDemo::exitPhysics()
|
||||
{
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
m_collisionShapes.clear();
|
||||
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
delete m_solver;
|
||||
|
||||
delete m_broadphase;
|
||||
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,85 +0,0 @@
|
||||
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2010 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 SERIALIZE_DEMO_H
|
||||
#define SERIALIZE_DEMO_H
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
|
||||
///BulletXmlImportDemo shows how to use save and load XML Bullet physics files (work-in-progress)
|
||||
class BulletXmlImportDemo : public PlatformDemoApplication
|
||||
{
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
public:
|
||||
|
||||
BulletXmlImportDemo()
|
||||
{
|
||||
//m_idle=true;
|
||||
setCameraDistance(btScalar(30.));
|
||||
}
|
||||
virtual ~BulletXmlImportDemo();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
void initPhysics();
|
||||
|
||||
void setupEmptyDynamicsWorld();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BulletXmlImportDemo* demo = new BulletXmlImportDemo;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //SERIALIZE_DEMO_H
|
||||
|
@ -1,78 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# This is the variable for Windows. I use this to define the root of my directory structure.
|
||||
SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletXmlWorldImporter
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(-DDESERIALIZE_SOFT_BODIES)
|
||||
|
||||
IF (USE_GLUT)
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletXmlWorldImporter BulletWorldImporter BulletSoftBody BulletDynamics BulletCollision BulletFileLoader LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppBulletXmlImportDemo
|
||||
main.cpp
|
||||
BulletXmlImportDemo.cpp
|
||||
BulletXmlImportDemo.h
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppBulletXmlImportDemo
|
||||
main.cpp
|
||||
BulletXmlImportDemo.cpp
|
||||
BulletXmlImportDemo.h
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
ELSE (USE_GLUT)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletXmlWorldImporter BulletWorldImporter BulletSoftBody BulletDynamics BulletCollision BulletFileLoader LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppBulletXmlImportDemo
|
||||
WIN32
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
Win32BulletXmlImportDemo.cpp
|
||||
BulletXmlImportDemo.cpp
|
||||
BulletXmlImportDemo.h
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ENDIF (USE_GLUT)
|
||||
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES AND NOT INTERNAL_UPDATE_SERIALIZATION_STRUCTURES)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppBulletXmlImportDemo
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/BulletXmlImportDemo/bullet_basic.xml ${CMAKE_CURRENT_BINARY_DIR}/bullet_basic.xml
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/BulletXmlImportDemo/bullet_basic.xml ${CMAKE_CURRENT_BINARY_DIR}/Debug/bullet_basic.xml
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppBulletXmlImportDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppBulletXmlImportDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppBulletXmlImportDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
#ifdef _WINDOWS
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2010 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "BulletXmlImportDemo.h"
|
||||
|
||||
///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo
|
||||
DemoApplication* createDemo()
|
||||
{
|
||||
return new BulletXmlImportDemo();
|
||||
}
|
||||
|
||||
#endif
|
@ -1,668 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<bullet_physics version=281 itemcount = 9>
|
||||
<btDynamicsWorldFloatData pointer=2>
|
||||
<m_solverInfo type="btContactSolverInfoFloatData">
|
||||
<m_tau type="float"> 0.600000 </m_tau>
|
||||
<m_damping type="float"> 1.000000 </m_damping>
|
||||
<m_friction type="float"> 0.300000 </m_friction>
|
||||
<m_timeStep type="float"> 0.016667 </m_timeStep>
|
||||
<m_restitution type="float"> 0.000000 </m_restitution>
|
||||
<m_maxErrorReduction type="float"> 20.000000 </m_maxErrorReduction>
|
||||
<m_sor type="float"> 1.000000 </m_sor>
|
||||
<m_erp type="float"> 0.200000 </m_erp>
|
||||
<m_erp2 type="float"> 0.800000 </m_erp2>
|
||||
<m_globalCfm type="float"> 0.000000 </m_globalCfm>
|
||||
<m_splitImpulsePenetrationThreshold type="float"> -0.040000 </m_splitImpulsePenetrationThreshold>
|
||||
<m_splitImpulseTurnErp type="float"> 0.100000 </m_splitImpulseTurnErp>
|
||||
<m_linearSlop type="float"> 0.000000 </m_linearSlop>
|
||||
<m_warmstartingFactor type="float"> 0.850000 </m_warmstartingFactor>
|
||||
<m_maxGyroscopicForce type="float"> 100.000000 </m_maxGyroscopicForce>
|
||||
<m_singleAxisRollingFrictionThreshold type="float"> 1000000015047466200000000000000.000000 </m_singleAxisRollingFrictionThreshold>
|
||||
<m_numIterations type="int"> 10 </m_numIterations>
|
||||
<m_solverMode type="int"> 260 </m_solverMode>
|
||||
<m_restingContactRestitutionThreshold type="int"> 2 </m_restingContactRestitutionThreshold>
|
||||
<m_minimumSolverBatchSize type="int"> 128 </m_minimumSolverBatchSize>
|
||||
<m_splitImpulse type="int"> 1 </m_splitImpulse>
|
||||
<m_padding type="char" count=4> 0 0 0 0 </m_padding>
|
||||
</m_solverInfo>
|
||||
<m_gravity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -10.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity>
|
||||
</btDynamicsWorldFloatData>
|
||||
<btRigidBodyFloatData pointer=4>
|
||||
<m_collisionObjectData type="btCollisionObjectFloatData">
|
||||
<m_broadphaseHandle type="pointer"> 0 </m_broadphaseHandle>
|
||||
<m_collisionShape type="pointer"> 3 </m_collisionShape>
|
||||
<m_rootCollisionShape type="pointer"> 0 </m_rootCollisionShape>
|
||||
<m_name type="pointer"> 0 </m_name>
|
||||
<m_worldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -50.000000 0.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_worldTransform>
|
||||
<m_interpolationWorldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_interpolationWorldTransform>
|
||||
<m_interpolationLinearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationLinearVelocity>
|
||||
<m_interpolationAngularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationAngularVelocity>
|
||||
<m_anisotropicFriction type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_anisotropicFriction>
|
||||
<m_contactProcessingThreshold type="float"> 999999984306749440.000000 </m_contactProcessingThreshold>
|
||||
<m_deactivationTime type="float"> 0.000000 </m_deactivationTime>
|
||||
<m_friction type="float"> 0.500000 </m_friction>
|
||||
<m_rollingFriction type="float"> -431602080.000000 </m_rollingFriction>
|
||||
<m_restitution type="float"> 0.000000 </m_restitution>
|
||||
<m_hitFraction type="float"> 1.000000 </m_hitFraction>
|
||||
<m_ccdSweptSphereRadius type="float"> 0.000000 </m_ccdSweptSphereRadius>
|
||||
<m_ccdMotionThreshold type="float"> 0.000000 </m_ccdMotionThreshold>
|
||||
<m_hasAnisotropicFriction type="int"> 0 </m_hasAnisotropicFriction>
|
||||
<m_collisionFlags type="int"> 1 </m_collisionFlags>
|
||||
<m_islandTag1 type="int"> -1 </m_islandTag1>
|
||||
<m_companionId type="int"> -2 </m_companionId>
|
||||
<m_activationState1 type="int"> 2 </m_activationState1>
|
||||
<m_internalType type="int"> 2 </m_internalType>
|
||||
<m_checkCollideWith type="int"> 0 </m_checkCollideWith>
|
||||
<m_padding type="char" count=4> -51 -51 -51 -51 </m_padding>
|
||||
</m_collisionObjectData>
|
||||
<m_invInertiaTensorWorld type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_invInertiaTensorWorld>
|
||||
<m_linearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_linearVelocity>
|
||||
<m_angularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_angularVelocity>
|
||||
<m_angularFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_angularFactor>
|
||||
<m_linearFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_linearFactor>
|
||||
<m_gravity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity>
|
||||
<m_gravity_acceleration type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity_acceleration>
|
||||
<m_invInertiaLocal type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_invInertiaLocal>
|
||||
<m_totalForce type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalForce>
|
||||
<m_totalTorque type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalTorque>
|
||||
<m_inverseMass type="float"> 0.000000 </m_inverseMass>
|
||||
<m_linearDamping type="float"> 0.000000 </m_linearDamping>
|
||||
<m_angularDamping type="float"> 0.000000 </m_angularDamping>
|
||||
<m_additionalDampingFactor type="float"> 0.005000 </m_additionalDampingFactor>
|
||||
<m_additionalLinearDampingThresholdSqr type="float"> 0.010000 </m_additionalLinearDampingThresholdSqr>
|
||||
<m_additionalAngularDampingThresholdSqr type="float"> 0.010000 </m_additionalAngularDampingThresholdSqr>
|
||||
<m_additionalAngularDampingFactor type="float"> 0.010000 </m_additionalAngularDampingFactor>
|
||||
<m_linearSleepingThreshold type="float"> 0.800000 </m_linearSleepingThreshold>
|
||||
<m_angularSleepingThreshold type="float"> 1.000000 </m_angularSleepingThreshold>
|
||||
<m_additionalDamping type="int"> 0 </m_additionalDamping>
|
||||
</btRigidBodyFloatData>
|
||||
<btRigidBodyFloatData pointer=6>
|
||||
<m_collisionObjectData type="btCollisionObjectFloatData">
|
||||
<m_broadphaseHandle type="pointer"> 0 </m_broadphaseHandle>
|
||||
<m_collisionShape type="pointer"> 5 </m_collisionShape>
|
||||
<m_rootCollisionShape type="pointer"> 0 </m_rootCollisionShape>
|
||||
<m_name type="pointer"> 0 </m_name>
|
||||
<m_worldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> -5.000000 14.166666 -3.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_worldTransform>
|
||||
<m_interpolationWorldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> -5.000000 14.166666 -3.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_interpolationWorldTransform>
|
||||
<m_interpolationLinearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -4.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationLinearVelocity>
|
||||
<m_interpolationAngularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationAngularVelocity>
|
||||
<m_anisotropicFriction type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_anisotropicFriction>
|
||||
<m_contactProcessingThreshold type="float"> 999999984306749440.000000 </m_contactProcessingThreshold>
|
||||
<m_deactivationTime type="float"> 0.000000 </m_deactivationTime>
|
||||
<m_friction type="float"> 0.500000 </m_friction>
|
||||
<m_rollingFriction type="float"> -431602080.000000 </m_rollingFriction>
|
||||
<m_restitution type="float"> 0.000000 </m_restitution>
|
||||
<m_hitFraction type="float"> 1.000000 </m_hitFraction>
|
||||
<m_ccdSweptSphereRadius type="float"> 0.000000 </m_ccdSweptSphereRadius>
|
||||
<m_ccdMotionThreshold type="float"> 0.000000 </m_ccdMotionThreshold>
|
||||
<m_hasAnisotropicFriction type="int"> 0 </m_hasAnisotropicFriction>
|
||||
<m_collisionFlags type="int"> 0 </m_collisionFlags>
|
||||
<m_islandTag1 type="int"> 4 </m_islandTag1>
|
||||
<m_companionId type="int"> -1 </m_companionId>
|
||||
<m_activationState1 type="int"> 1 </m_activationState1>
|
||||
<m_internalType type="int"> 2 </m_internalType>
|
||||
<m_checkCollideWith type="int"> 0 </m_checkCollideWith>
|
||||
<m_padding type="char" count=4> -51 -51 -51 -51 </m_padding>
|
||||
</m_collisionObjectData>
|
||||
<m_invInertiaTensorWorld type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.500000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.500000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.500000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_invInertiaTensorWorld>
|
||||
<m_linearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -4.000000 0.000000 0.000000 </m_floats>
|
||||
</m_linearVelocity>
|
||||
<m_angularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_angularVelocity>
|
||||
<m_angularFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_angularFactor>
|
||||
<m_linearFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_linearFactor>
|
||||
<m_gravity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -10.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity>
|
||||
<m_gravity_acceleration type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -10.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity_acceleration>
|
||||
<m_invInertiaLocal type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.500000 1.500000 1.500000 0.000000 </m_floats>
|
||||
</m_invInertiaLocal>
|
||||
<m_totalForce type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalForce>
|
||||
<m_totalTorque type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalTorque>
|
||||
<m_inverseMass type="float"> 1.000000 </m_inverseMass>
|
||||
<m_linearDamping type="float"> 0.000000 </m_linearDamping>
|
||||
<m_angularDamping type="float"> 0.000000 </m_angularDamping>
|
||||
<m_additionalDampingFactor type="float"> 0.005000 </m_additionalDampingFactor>
|
||||
<m_additionalLinearDampingThresholdSqr type="float"> 0.010000 </m_additionalLinearDampingThresholdSqr>
|
||||
<m_additionalAngularDampingThresholdSqr type="float"> 0.010000 </m_additionalAngularDampingThresholdSqr>
|
||||
<m_additionalAngularDampingFactor type="float"> 0.010000 </m_additionalAngularDampingFactor>
|
||||
<m_linearSleepingThreshold type="float"> 0.800000 </m_linearSleepingThreshold>
|
||||
<m_angularSleepingThreshold type="float"> 1.000000 </m_angularSleepingThreshold>
|
||||
<m_additionalDamping type="int"> 0 </m_additionalDamping>
|
||||
</btRigidBodyFloatData>
|
||||
<btRigidBodyFloatData pointer=7>
|
||||
<m_collisionObjectData type="btCollisionObjectFloatData">
|
||||
<m_broadphaseHandle type="pointer"> 0 </m_broadphaseHandle>
|
||||
<m_collisionShape type="pointer"> 5 </m_collisionShape>
|
||||
<m_rootCollisionShape type="pointer"> 0 </m_rootCollisionShape>
|
||||
<m_name type="pointer"> 0 </m_name>
|
||||
<m_worldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> -5.000000 16.166668 -3.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_worldTransform>
|
||||
<m_interpolationWorldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> -5.000000 16.166668 -3.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_interpolationWorldTransform>
|
||||
<m_interpolationLinearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -4.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationLinearVelocity>
|
||||
<m_interpolationAngularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationAngularVelocity>
|
||||
<m_anisotropicFriction type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_anisotropicFriction>
|
||||
<m_contactProcessingThreshold type="float"> 999999984306749440.000000 </m_contactProcessingThreshold>
|
||||
<m_deactivationTime type="float"> 0.000000 </m_deactivationTime>
|
||||
<m_friction type="float"> 0.500000 </m_friction>
|
||||
<m_rollingFriction type="float"> -431602080.000000 </m_rollingFriction>
|
||||
<m_restitution type="float"> 0.000000 </m_restitution>
|
||||
<m_hitFraction type="float"> 1.000000 </m_hitFraction>
|
||||
<m_ccdSweptSphereRadius type="float"> 0.000000 </m_ccdSweptSphereRadius>
|
||||
<m_ccdMotionThreshold type="float"> 0.000000 </m_ccdMotionThreshold>
|
||||
<m_hasAnisotropicFriction type="int"> 0 </m_hasAnisotropicFriction>
|
||||
<m_collisionFlags type="int"> 0 </m_collisionFlags>
|
||||
<m_islandTag1 type="int"> 4 </m_islandTag1>
|
||||
<m_companionId type="int"> -1 </m_companionId>
|
||||
<m_activationState1 type="int"> 1 </m_activationState1>
|
||||
<m_internalType type="int"> 2 </m_internalType>
|
||||
<m_checkCollideWith type="int"> 0 </m_checkCollideWith>
|
||||
<m_padding type="char" count=4> -51 -51 -51 -51 </m_padding>
|
||||
</m_collisionObjectData>
|
||||
<m_invInertiaTensorWorld type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.500000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.500000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.500000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_invInertiaTensorWorld>
|
||||
<m_linearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -4.000000 0.000000 0.000000 </m_floats>
|
||||
</m_linearVelocity>
|
||||
<m_angularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_angularVelocity>
|
||||
<m_angularFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_angularFactor>
|
||||
<m_linearFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_linearFactor>
|
||||
<m_gravity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -10.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity>
|
||||
<m_gravity_acceleration type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -10.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity_acceleration>
|
||||
<m_invInertiaLocal type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.500000 1.500000 1.500000 0.000000 </m_floats>
|
||||
</m_invInertiaLocal>
|
||||
<m_totalForce type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalForce>
|
||||
<m_totalTorque type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalTorque>
|
||||
<m_inverseMass type="float"> 1.000000 </m_inverseMass>
|
||||
<m_linearDamping type="float"> 0.000000 </m_linearDamping>
|
||||
<m_angularDamping type="float"> 0.000000 </m_angularDamping>
|
||||
<m_additionalDampingFactor type="float"> 0.005000 </m_additionalDampingFactor>
|
||||
<m_additionalLinearDampingThresholdSqr type="float"> 0.010000 </m_additionalLinearDampingThresholdSqr>
|
||||
<m_additionalAngularDampingThresholdSqr type="float"> 0.010000 </m_additionalAngularDampingThresholdSqr>
|
||||
<m_additionalAngularDampingFactor type="float"> 0.010000 </m_additionalAngularDampingFactor>
|
||||
<m_linearSleepingThreshold type="float"> 0.800000 </m_linearSleepingThreshold>
|
||||
<m_angularSleepingThreshold type="float"> 1.000000 </m_angularSleepingThreshold>
|
||||
<m_additionalDamping type="int"> 0 </m_additionalDamping>
|
||||
</btRigidBodyFloatData>
|
||||
<btRigidBodyFloatData pointer=8>
|
||||
<m_collisionObjectData type="btCollisionObjectFloatData">
|
||||
<m_broadphaseHandle type="pointer"> 0 </m_broadphaseHandle>
|
||||
<m_collisionShape type="pointer"> 5 </m_collisionShape>
|
||||
<m_rootCollisionShape type="pointer"> 0 </m_rootCollisionShape>
|
||||
<m_name type="pointer"> 0 </m_name>
|
||||
<m_worldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> -5.000000 18.166668 -3.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_worldTransform>
|
||||
<m_interpolationWorldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> -5.000000 18.166668 -3.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_interpolationWorldTransform>
|
||||
<m_interpolationLinearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -4.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationLinearVelocity>
|
||||
<m_interpolationAngularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationAngularVelocity>
|
||||
<m_anisotropicFriction type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_anisotropicFriction>
|
||||
<m_contactProcessingThreshold type="float"> 999999984306749440.000000 </m_contactProcessingThreshold>
|
||||
<m_deactivationTime type="float"> 0.000000 </m_deactivationTime>
|
||||
<m_friction type="float"> 0.500000 </m_friction>
|
||||
<m_rollingFriction type="float"> -431602080.000000 </m_rollingFriction>
|
||||
<m_restitution type="float"> 0.000000 </m_restitution>
|
||||
<m_hitFraction type="float"> 1.000000 </m_hitFraction>
|
||||
<m_ccdSweptSphereRadius type="float"> 0.000000 </m_ccdSweptSphereRadius>
|
||||
<m_ccdMotionThreshold type="float"> 0.000000 </m_ccdMotionThreshold>
|
||||
<m_hasAnisotropicFriction type="int"> 0 </m_hasAnisotropicFriction>
|
||||
<m_collisionFlags type="int"> 0 </m_collisionFlags>
|
||||
<m_islandTag1 type="int"> 4 </m_islandTag1>
|
||||
<m_companionId type="int"> -1 </m_companionId>
|
||||
<m_activationState1 type="int"> 1 </m_activationState1>
|
||||
<m_internalType type="int"> 2 </m_internalType>
|
||||
<m_checkCollideWith type="int"> 0 </m_checkCollideWith>
|
||||
<m_padding type="char" count=4> -51 -51 -51 -51 </m_padding>
|
||||
</m_collisionObjectData>
|
||||
<m_invInertiaTensorWorld type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.500000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.500000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.500000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_invInertiaTensorWorld>
|
||||
<m_linearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -4.000000 0.000000 0.000000 </m_floats>
|
||||
</m_linearVelocity>
|
||||
<m_angularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_angularVelocity>
|
||||
<m_angularFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_angularFactor>
|
||||
<m_linearFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_linearFactor>
|
||||
<m_gravity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -10.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity>
|
||||
<m_gravity_acceleration type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -10.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity_acceleration>
|
||||
<m_invInertiaLocal type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.500000 1.500000 1.500000 0.000000 </m_floats>
|
||||
</m_invInertiaLocal>
|
||||
<m_totalForce type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalForce>
|
||||
<m_totalTorque type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalTorque>
|
||||
<m_inverseMass type="float"> 1.000000 </m_inverseMass>
|
||||
<m_linearDamping type="float"> 0.000000 </m_linearDamping>
|
||||
<m_angularDamping type="float"> 0.000000 </m_angularDamping>
|
||||
<m_additionalDampingFactor type="float"> 0.005000 </m_additionalDampingFactor>
|
||||
<m_additionalLinearDampingThresholdSqr type="float"> 0.010000 </m_additionalLinearDampingThresholdSqr>
|
||||
<m_additionalAngularDampingThresholdSqr type="float"> 0.010000 </m_additionalAngularDampingThresholdSqr>
|
||||
<m_additionalAngularDampingFactor type="float"> 0.010000 </m_additionalAngularDampingFactor>
|
||||
<m_linearSleepingThreshold type="float"> 0.800000 </m_linearSleepingThreshold>
|
||||
<m_angularSleepingThreshold type="float"> 1.000000 </m_angularSleepingThreshold>
|
||||
<m_additionalDamping type="int"> 0 </m_additionalDamping>
|
||||
</btRigidBodyFloatData>
|
||||
<btRigidBodyFloatData pointer=9>
|
||||
<m_collisionObjectData type="btCollisionObjectFloatData">
|
||||
<m_broadphaseHandle type="pointer"> 0 </m_broadphaseHandle>
|
||||
<m_collisionShape type="pointer"> 5 </m_collisionShape>
|
||||
<m_rootCollisionShape type="pointer"> 0 </m_rootCollisionShape>
|
||||
<m_name type="pointer"> 0 </m_name>
|
||||
<m_worldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> -5.000000 20.166668 -3.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_worldTransform>
|
||||
<m_interpolationWorldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> -5.000000 20.166668 -3.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_interpolationWorldTransform>
|
||||
<m_interpolationLinearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -4.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationLinearVelocity>
|
||||
<m_interpolationAngularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationAngularVelocity>
|
||||
<m_anisotropicFriction type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_anisotropicFriction>
|
||||
<m_contactProcessingThreshold type="float"> 999999984306749440.000000 </m_contactProcessingThreshold>
|
||||
<m_deactivationTime type="float"> 0.000000 </m_deactivationTime>
|
||||
<m_friction type="float"> 0.500000 </m_friction>
|
||||
<m_rollingFriction type="float"> -431602080.000000 </m_rollingFriction>
|
||||
<m_restitution type="float"> 0.000000 </m_restitution>
|
||||
<m_hitFraction type="float"> 1.000000 </m_hitFraction>
|
||||
<m_ccdSweptSphereRadius type="float"> 0.000000 </m_ccdSweptSphereRadius>
|
||||
<m_ccdMotionThreshold type="float"> 0.000000 </m_ccdMotionThreshold>
|
||||
<m_hasAnisotropicFriction type="int"> 0 </m_hasAnisotropicFriction>
|
||||
<m_collisionFlags type="int"> 0 </m_collisionFlags>
|
||||
<m_islandTag1 type="int"> 4 </m_islandTag1>
|
||||
<m_companionId type="int"> -1 </m_companionId>
|
||||
<m_activationState1 type="int"> 1 </m_activationState1>
|
||||
<m_internalType type="int"> 2 </m_internalType>
|
||||
<m_checkCollideWith type="int"> 0 </m_checkCollideWith>
|
||||
<m_padding type="char" count=4> -51 -51 -51 -51 </m_padding>
|
||||
</m_collisionObjectData>
|
||||
<m_invInertiaTensorWorld type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.500000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.500000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.500000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_invInertiaTensorWorld>
|
||||
<m_linearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -4.000000 0.000000 0.000000 </m_floats>
|
||||
</m_linearVelocity>
|
||||
<m_angularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_angularVelocity>
|
||||
<m_angularFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_angularFactor>
|
||||
<m_linearFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_linearFactor>
|
||||
<m_gravity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -10.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity>
|
||||
<m_gravity_acceleration type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -10.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity_acceleration>
|
||||
<m_invInertiaLocal type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.500000 1.500000 1.500000 0.000000 </m_floats>
|
||||
</m_invInertiaLocal>
|
||||
<m_totalForce type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalForce>
|
||||
<m_totalTorque type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalTorque>
|
||||
<m_inverseMass type="float"> 1.000000 </m_inverseMass>
|
||||
<m_linearDamping type="float"> 0.000000 </m_linearDamping>
|
||||
<m_angularDamping type="float"> 0.000000 </m_angularDamping>
|
||||
<m_additionalDampingFactor type="float"> 0.005000 </m_additionalDampingFactor>
|
||||
<m_additionalLinearDampingThresholdSqr type="float"> 0.010000 </m_additionalLinearDampingThresholdSqr>
|
||||
<m_additionalAngularDampingThresholdSqr type="float"> 0.010000 </m_additionalAngularDampingThresholdSqr>
|
||||
<m_additionalAngularDampingFactor type="float"> 0.010000 </m_additionalAngularDampingFactor>
|
||||
<m_linearSleepingThreshold type="float"> 0.800000 </m_linearSleepingThreshold>
|
||||
<m_angularSleepingThreshold type="float"> 1.000000 </m_angularSleepingThreshold>
|
||||
<m_additionalDamping type="int"> 0 </m_additionalDamping>
|
||||
</btRigidBodyFloatData>
|
||||
<btRigidBodyFloatData pointer=10>
|
||||
<m_collisionObjectData type="btCollisionObjectFloatData">
|
||||
<m_broadphaseHandle type="pointer"> 0 </m_broadphaseHandle>
|
||||
<m_collisionShape type="pointer"> 5 </m_collisionShape>
|
||||
<m_rootCollisionShape type="pointer"> 0 </m_rootCollisionShape>
|
||||
<m_name type="pointer"> 0 </m_name>
|
||||
<m_worldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> -5.000000 22.166668 -3.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_worldTransform>
|
||||
<m_interpolationWorldTransform type="btTransformFloatData">
|
||||
<m_basis type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.000000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_basis>
|
||||
<m_origin type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> -5.000000 22.166668 -3.000000 0.000000 </m_floats>
|
||||
</m_origin>
|
||||
</m_interpolationWorldTransform>
|
||||
<m_interpolationLinearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -4.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationLinearVelocity>
|
||||
<m_interpolationAngularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_interpolationAngularVelocity>
|
||||
<m_anisotropicFriction type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_anisotropicFriction>
|
||||
<m_contactProcessingThreshold type="float"> 999999984306749440.000000 </m_contactProcessingThreshold>
|
||||
<m_deactivationTime type="float"> 0.000000 </m_deactivationTime>
|
||||
<m_friction type="float"> 0.500000 </m_friction>
|
||||
<m_rollingFriction type="float"> -431602080.000000 </m_rollingFriction>
|
||||
<m_restitution type="float"> 0.000000 </m_restitution>
|
||||
<m_hitFraction type="float"> 1.000000 </m_hitFraction>
|
||||
<m_ccdSweptSphereRadius type="float"> 0.000000 </m_ccdSweptSphereRadius>
|
||||
<m_ccdMotionThreshold type="float"> 0.000000 </m_ccdMotionThreshold>
|
||||
<m_hasAnisotropicFriction type="int"> 0 </m_hasAnisotropicFriction>
|
||||
<m_collisionFlags type="int"> 0 </m_collisionFlags>
|
||||
<m_islandTag1 type="int"> 4 </m_islandTag1>
|
||||
<m_companionId type="int"> -1 </m_companionId>
|
||||
<m_activationState1 type="int"> 1 </m_activationState1>
|
||||
<m_internalType type="int"> 2 </m_internalType>
|
||||
<m_checkCollideWith type="int"> 0 </m_checkCollideWith>
|
||||
<m_padding type="char" count=4> -51 -51 -51 -51 </m_padding>
|
||||
</m_collisionObjectData>
|
||||
<m_invInertiaTensorWorld type="btMatrix3x3FloatData">
|
||||
<m_el type="btVector3FloatData" count=3>
|
||||
<m_floats type="float" count=4> 1.500000 0.000000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 1.500000 0.000000 0.000000 </m_floats>
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 1.500000 0.000000 </m_floats>
|
||||
</m_el>
|
||||
</m_invInertiaTensorWorld>
|
||||
<m_linearVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -4.000000 0.000000 0.000000 </m_floats>
|
||||
</m_linearVelocity>
|
||||
<m_angularVelocity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_angularVelocity>
|
||||
<m_angularFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_angularFactor>
|
||||
<m_linearFactor type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_linearFactor>
|
||||
<m_gravity type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -10.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity>
|
||||
<m_gravity_acceleration type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 -10.000000 0.000000 0.000000 </m_floats>
|
||||
</m_gravity_acceleration>
|
||||
<m_invInertiaLocal type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.500000 1.500000 1.500000 0.000000 </m_floats>
|
||||
</m_invInertiaLocal>
|
||||
<m_totalForce type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalForce>
|
||||
<m_totalTorque type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.000000 0.000000 0.000000 0.000000 </m_floats>
|
||||
</m_totalTorque>
|
||||
<m_inverseMass type="float"> 1.000000 </m_inverseMass>
|
||||
<m_linearDamping type="float"> 0.000000 </m_linearDamping>
|
||||
<m_angularDamping type="float"> 0.000000 </m_angularDamping>
|
||||
<m_additionalDampingFactor type="float"> 0.005000 </m_additionalDampingFactor>
|
||||
<m_additionalLinearDampingThresholdSqr type="float"> 0.010000 </m_additionalLinearDampingThresholdSqr>
|
||||
<m_additionalAngularDampingThresholdSqr type="float"> 0.010000 </m_additionalAngularDampingThresholdSqr>
|
||||
<m_additionalAngularDampingFactor type="float"> 0.010000 </m_additionalAngularDampingFactor>
|
||||
<m_linearSleepingThreshold type="float"> 0.800000 </m_linearSleepingThreshold>
|
||||
<m_angularSleepingThreshold type="float"> 1.000000 </m_angularSleepingThreshold>
|
||||
<m_additionalDamping type="int"> 0 </m_additionalDamping>
|
||||
</btRigidBodyFloatData>
|
||||
<btConvexInternalShapeData pointer=3>
|
||||
<m_collisionShapeData type="btCollisionShapeData">
|
||||
<m_name type="pointer"> 0 </m_name>
|
||||
<m_shapeType type="int"> 0 </m_shapeType>
|
||||
<m_padding type="char" count=4> -51 -51 -51 -51 </m_padding>
|
||||
</m_collisionShapeData>
|
||||
<m_localScaling type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_localScaling>
|
||||
<m_implicitShapeDimensions type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 49.959999 49.959999 49.959999 0.000000 </m_floats>
|
||||
</m_implicitShapeDimensions>
|
||||
<m_collisionMargin type="float"> 0.040000 </m_collisionMargin>
|
||||
<m_padding type="int"> -842150451 </m_padding>
|
||||
</btConvexInternalShapeData>
|
||||
<btConvexInternalShapeData pointer=5>
|
||||
<m_collisionShapeData type="btCollisionShapeData">
|
||||
<m_name type="pointer"> 0 </m_name>
|
||||
<m_shapeType type="int"> 0 </m_shapeType>
|
||||
<m_padding type="char" count=4> -51 -51 -51 -51 </m_padding>
|
||||
</m_collisionShapeData>
|
||||
<m_localScaling type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 1.000000 1.000000 1.000000 0.000000 </m_floats>
|
||||
</m_localScaling>
|
||||
<m_implicitShapeDimensions type="btVector3FloatData">
|
||||
<m_floats type="float" count=4> 0.960000 0.960000 0.960000 0.000000 </m_floats>
|
||||
</m_implicitShapeDimensions>
|
||||
<m_collisionMargin type="float"> 0.040000 </m_collisionMargin>
|
||||
<m_padding type="int"> -842150451 </m_padding>
|
||||
</btConvexInternalShapeData>
|
||||
</bullet_physics>
|
File diff suppressed because it is too large
Load Diff
@ -1,107 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "BulletXmlImportDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
|
||||
|
||||
#ifdef USE_AMD_OPENCL
|
||||
|
||||
|
||||
|
||||
#include "btOpenCLUtils.h"
|
||||
|
||||
#include <LinearMath/btScalar.h>
|
||||
|
||||
cl_context g_cxMainContext;
|
||||
cl_device_id g_cdDevice;
|
||||
cl_command_queue g_cqCommandQue;
|
||||
|
||||
|
||||
// Returns true if OpenCL is initialized properly, false otherwise.
|
||||
bool initCL( void* glCtx, void* glDC )
|
||||
{
|
||||
const char* vendorSDK = btOpenCLUtils::getSdkVendorName();
|
||||
printf("This program was compiled using the %s OpenCL SDK\n",vendorSDK);
|
||||
|
||||
int ciErrNum = 0;
|
||||
|
||||
#ifdef BT_USE_CLEW
|
||||
ciErrNum = clewInit( "OpenCL.dll" );
|
||||
if ( ciErrNum != CLEW_SUCCESS ) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CL_PLATFORM_MINI_CL)
|
||||
cl_device_type deviceType = CL_DEVICE_TYPE_CPU;
|
||||
#elif defined(CL_PLATFORM_AMD)
|
||||
cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
|
||||
#elif defined(CL_PLATFORM_NVIDIA)
|
||||
cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
|
||||
#else
|
||||
cl_device_type deviceType = CL_DEVICE_TYPE_CPU;
|
||||
#endif
|
||||
|
||||
g_cxMainContext = btOpenCLUtils::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);
|
||||
oclCHECKERROR(ciErrNum, CL_SUCCESS);
|
||||
|
||||
int numDev = btOpenCLUtils::getNumDevices(g_cxMainContext);
|
||||
if (!numDev)
|
||||
return false;
|
||||
|
||||
g_cdDevice = btOpenCLUtils::getDevice(g_cxMainContext,0);
|
||||
|
||||
btOpenCLDeviceInfo clInfo;
|
||||
btOpenCLUtils::getDeviceInfo(g_cdDevice,clInfo);
|
||||
btOpenCLUtils::printDeviceInfo(g_cdDevice);
|
||||
|
||||
// create a command-queue
|
||||
g_cqCommandQue = clCreateCommandQueue(g_cxMainContext, g_cdDevice, 0, &ciErrNum);
|
||||
oclCHECKERROR(ciErrNum, CL_SUCCESS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif //#ifdef USE_AMD_OPENCL
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
#ifdef USE_AMD_OPENCL
|
||||
|
||||
bool initialized = initCL(0,0);
|
||||
btAssert(initialized);
|
||||
#endif //USE_AMD_OPENCL
|
||||
|
||||
|
||||
BulletXmlImportDemo serializeDemo;
|
||||
serializeDemo.initPhysics();
|
||||
|
||||
|
||||
#ifdef CHECK_MEMORY_LEAKS
|
||||
serializeDemo.exitPhysics();
|
||||
#else
|
||||
return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.org",&serializeDemo);
|
||||
#endif
|
||||
|
||||
//default glut doesn't return from mainloop
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
|
||||
SUBDIRS( HelloWorld )
|
||||
|
||||
|
||||
IF (USE_GLUT)
|
||||
IF (GLUT_FOUND)
|
||||
IF(BUILD_CPU_DEMOS)
|
||||
IF(BUILD_EXTRAS)
|
||||
SUBDIRS( BulletXmlImportDemo ConcaveDemo ConvexDecompositionDemo SerializeDemo )
|
||||
ENDIF()
|
||||
SET(SharedDemoSubdirs
|
||||
OpenGL
|
||||
CcdPhysicsDemo ConstraintDemo SliderConstraintDemo GenericJointDemo Raytracer
|
||||
RagdollDemo ForkLiftDemo BasicDemo FeatherstoneMultiBodyDemo RollingFrictionDemo RaytestDemo VoronoiFractureDemo
|
||||
GyroscopicDemo FractureDemo Box2dDemo BspDemo MovingConcaveDemo VehicleDemo
|
||||
UserCollisionAlgorithm CharacterDemo SoftDemo
|
||||
CollisionInterfaceDemo ConcaveConvexcastDemo SimplexDemo DynamicControlDemo
|
||||
ConvexHullDistance
|
||||
DoublePrecisionDemo CollisionDemo
|
||||
ContinuousConvexCollision ConcaveRaycastDemo GjkConvexCastDemo
|
||||
MultiMaterialDemo InternalEdgeDemo
|
||||
)
|
||||
ELSE()
|
||||
SET(SharedDemoSubdirs OpenGL )
|
||||
ENDIF(BUILD_CPU_DEMOS)
|
||||
|
||||
|
||||
SUBDIRS(
|
||||
${SharedDemoSubdirs}
|
||||
Benchmarks
|
||||
)
|
||||
|
||||
|
||||
ENDIF(GLUT_FOUND)
|
||||
ELSE (USE_GLUT)
|
||||
IF (WIN32)
|
||||
SUBDIRS(
|
||||
OpenGL
|
||||
BasicDemo
|
||||
RaytestDemo
|
||||
FractureDemo
|
||||
Benchmarks
|
||||
Box2dDemo
|
||||
CollisionInterfaceDemo
|
||||
ConcaveDemo
|
||||
ConstraintDemo
|
||||
RollingFrictionDemo
|
||||
ConvexDecompositionDemo
|
||||
InternalEdgeDemo
|
||||
GyroscopicDemo
|
||||
FeatherstoneMultiBodyDemo
|
||||
GenericJointDemo
|
||||
SerializeDemo
|
||||
SoftDemo
|
||||
VoronoiFractureDemo
|
||||
)
|
||||
ENDIF(WIN32)
|
||||
ENDIF (USE_GLUT)
|
||||
|
@ -1,48 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
../../btgui
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppCcdPhysicsDemo
|
||||
main.cpp
|
||||
CcdPhysicsDemo.cpp
|
||||
CcdPhysicsSetup.h
|
||||
CcdPhysicsSetup.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppCcdPhysicsDemo
|
||||
main.cpp
|
||||
CcdPhysicsDemo.cpp
|
||||
CcdPhysicsSetup.h
|
||||
CcdPhysicsSetup.cpp
|
||||
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppCcdPhysicsDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppCcdPhysicsDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppCcdPhysicsDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,275 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#define CUBE_HALF_EXTENTS 1
|
||||
|
||||
#define EXTRA_HEIGHT 1.f
|
||||
|
||||
#include "CcdPhysicsDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugFont.h"
|
||||
|
||||
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
#include <stdio.h> //printf debugging
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
#if 0
|
||||
extern btAlignedObjectArray<btVector3> debugContacts;
|
||||
extern btAlignedObjectArray<btVector3> debugNormals;
|
||||
#endif
|
||||
|
||||
static GLDebugDrawer sDebugDrawer;
|
||||
|
||||
|
||||
CcdPhysicsDemo::CcdPhysicsDemo()
|
||||
:m_ccdMode(USE_CCD)
|
||||
{
|
||||
setDebugMode(btIDebugDraw::DBG_DrawText+btIDebugDraw::DBG_NoHelpText);
|
||||
setCameraDistance(btScalar(40.));
|
||||
}
|
||||
|
||||
|
||||
void CcdPhysicsDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//simple dynamics world doesn't handle fixed-time-stepping
|
||||
//float ms = getDeltaTimeMicroseconds();
|
||||
|
||||
///step the simulation
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
m_dynamicsWorld->stepSimulation(1./60.,0);//ms / 1000000.f);
|
||||
//optional but useful: debug drawing
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
}
|
||||
|
||||
renderme();
|
||||
|
||||
displayText();
|
||||
#if 0
|
||||
for (int i=0;i<debugContacts.size();i++)
|
||||
{
|
||||
getDynamicsWorld()->getDebugDrawer()->drawContactPoint(debugContacts[i],debugNormals[i],0,0,btVector3(1,0,0));
|
||||
}
|
||||
#endif
|
||||
|
||||
glFlush();
|
||||
|
||||
swapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CcdPhysicsDemo::displayText()
|
||||
{
|
||||
int lineWidth=440;
|
||||
int xStart = m_glutScreenWidth - lineWidth;
|
||||
int yStart = 20;
|
||||
|
||||
if((getDebugMode() & btIDebugDraw::DBG_DrawText)!=0)
|
||||
{
|
||||
setOrthographicProjection();
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor3f(0, 0, 0);
|
||||
char buf[124];
|
||||
|
||||
glRasterPos3f(xStart, yStart, 0);
|
||||
switch (m_ccdMode)
|
||||
{
|
||||
case USE_CCD:
|
||||
{
|
||||
sprintf(buf,"Predictive contacts and motion clamping");
|
||||
break;
|
||||
}
|
||||
case USE_NO_CCD:
|
||||
{
|
||||
sprintf(buf,"CCD handling disabled");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
sprintf(buf,"unknown CCD setting");
|
||||
};
|
||||
};
|
||||
|
||||
GLDebugDrawString(xStart,20,buf);
|
||||
glRasterPos3f(xStart, yStart, 0);
|
||||
sprintf(buf,"Press 'p' to change CCD mode");
|
||||
yStart+=20;
|
||||
GLDebugDrawString(xStart,yStart,buf);
|
||||
glRasterPos3f(xStart, yStart, 0);
|
||||
sprintf(buf,"Press '.' or right mouse to shoot bullets");
|
||||
yStart+=20;
|
||||
GLDebugDrawString(xStart,yStart,buf);
|
||||
glRasterPos3f(xStart, yStart, 0);
|
||||
sprintf(buf,"space to restart, h(elp), t(ext), w(ire)");
|
||||
yStart+=20;
|
||||
GLDebugDrawString(xStart,yStart,buf);
|
||||
|
||||
resetPerspectiveProjection();
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CcdPhysicsDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
renderme();
|
||||
|
||||
displayText();
|
||||
|
||||
//optional but useful: debug drawing to detect problems
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
}
|
||||
#if 0
|
||||
for (int i=0;i<debugContacts.size();i++)
|
||||
{
|
||||
getDynamicsWorld()->getDebugDrawer()->drawContactPoint(debugContacts[i],debugNormals[i],0,0,btVector3(1,0,0));
|
||||
}
|
||||
#endif
|
||||
|
||||
glFlush();
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void CcdPhysicsDemo::initPhysics()
|
||||
{
|
||||
setTexturing(true);
|
||||
setShadows(true);
|
||||
|
||||
m_ShootBoxInitialSpeed = 4000.f;
|
||||
|
||||
m_defaultContactProcessingThreshold = 0.f;
|
||||
GraphicsPhysicsBridge bridge;
|
||||
m_physicsSetup.initPhysics(bridge);
|
||||
m_dynamicsWorld = m_physicsSetup.m_dynamicsWorld;
|
||||
m_dynamicsWorld->getSolverInfo().m_solverMode |=SOLVER_USE_2_FRICTION_DIRECTIONS|SOLVER_RANDMIZE_ORDER;
|
||||
|
||||
m_dynamicsWorld ->setDebugDrawer(&sDebugDrawer);
|
||||
|
||||
//m_dynamicsWorld->getSolverInfo().m_splitImpulse=false;
|
||||
|
||||
|
||||
|
||||
if (m_ccdMode==USE_CCD)
|
||||
{
|
||||
m_dynamicsWorld->getDispatchInfo().m_useContinuous=true;
|
||||
} else
|
||||
{
|
||||
m_dynamicsWorld->getDispatchInfo().m_useContinuous=false;
|
||||
}
|
||||
|
||||
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
|
||||
|
||||
}
|
||||
|
||||
void CcdPhysicsDemo::clientResetScene()
|
||||
{
|
||||
exitPhysics();
|
||||
initPhysics();
|
||||
}
|
||||
|
||||
void CcdPhysicsDemo::keyboardCallback(unsigned char key, int x, int y)
|
||||
{
|
||||
if (key=='p')
|
||||
{
|
||||
switch (m_ccdMode)
|
||||
{
|
||||
case USE_CCD:
|
||||
{
|
||||
m_ccdMode = USE_NO_CCD;
|
||||
break;
|
||||
}
|
||||
case USE_NO_CCD:
|
||||
default:
|
||||
{
|
||||
m_ccdMode = USE_CCD;
|
||||
}
|
||||
};
|
||||
clientResetScene();
|
||||
} else
|
||||
{
|
||||
DemoApplication::keyboardCallback(key,x,y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CcdPhysicsDemo::shootBox(const btVector3& destination)
|
||||
{
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
float mass = 1.f;
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
btVector3 camPos = getCameraPosition();
|
||||
startTransform.setOrigin(camPos);
|
||||
|
||||
setShootBoxShape ();
|
||||
|
||||
|
||||
btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_shootBoxShape);
|
||||
body->setLinearFactor(btVector3(1,1,1));
|
||||
//body->setRestitution(1);
|
||||
|
||||
btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
|
||||
linVel.normalize();
|
||||
linVel*=m_ShootBoxInitialSpeed;
|
||||
|
||||
body->getWorldTransform().setOrigin(camPos);
|
||||
body->getWorldTransform().setRotation(btQuaternion(0,0,0,1));
|
||||
body->setLinearVelocity(linVel);
|
||||
body->setAngularVelocity(btVector3(0,0,0));
|
||||
body->setContactProcessingThreshold(1e30);
|
||||
|
||||
///when using m_ccdMode, disable regular CCD
|
||||
if (m_ccdMode==USE_CCD)
|
||||
{
|
||||
body->setCcdMotionThreshold(CUBE_HALF_EXTENTS);
|
||||
body->setCcdSweptSphereRadius(0.4f);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void CcdPhysicsDemo::exitPhysics()
|
||||
{
|
||||
m_physicsSetup.exitPhysics();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 BT_CCD_PHYSICS_DEMO_H
|
||||
#define BT_CCD_PHYSICS_DEMO_H
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
|
||||
#include "CcdPhysicsSetup.h"
|
||||
|
||||
///CcdPhysicsDemo is good starting point for learning the code base and porting.
|
||||
|
||||
class CcdPhysicsDemo : public PlatformDemoApplication
|
||||
{
|
||||
|
||||
CcdPhysicsSetup m_physicsSetup;
|
||||
|
||||
enum
|
||||
{
|
||||
USE_CCD=1,
|
||||
USE_NO_CCD
|
||||
};
|
||||
int m_ccdMode;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
CcdPhysicsDemo();
|
||||
|
||||
virtual ~CcdPhysicsDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
void displayText();
|
||||
|
||||
virtual void keyboardCallback(unsigned char key, int x, int y);
|
||||
|
||||
virtual void displayCallback();
|
||||
virtual void shootBox(const btVector3& destination);
|
||||
virtual void clientResetScene();
|
||||
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
CcdPhysicsDemo* demo = new CcdPhysicsDemo;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_CCD_PHYSICS_DEMO_H
|
||||
|
@ -1,179 +0,0 @@
|
||||
|
||||
#include "CcdPhysicsSetup.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#define CUBE_HALF_EXTENTS 1.f
|
||||
#define EXTRA_HEIGHT 1.f
|
||||
|
||||
|
||||
void KinematicObjectSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
|
||||
{
|
||||
createEmptyDynamicsWorld();
|
||||
{
|
||||
btBoxShape* box = new btBoxShape(btVector3(btScalar(10.), btScalar(1.), btScalar(10.)));
|
||||
gfxBridge.createCollisionShapeGraphicsObject(box);
|
||||
btTransform startTrans;
|
||||
startTrans.setIdentity();
|
||||
startTrans.setOrigin(btVector3(0, -1, 0));
|
||||
btRigidBody* body = createRigidBody(0, startTrans, box);
|
||||
body->setMotionState(0);
|
||||
body->setFriction(1);
|
||||
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
body->setActivationState(DISABLE_DEACTIVATION);
|
||||
|
||||
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(0,1,0));
|
||||
}
|
||||
{
|
||||
btBoxShape* box = new btBoxShape(btVector3(btScalar(1.), btScalar(1.), btScalar(1.)));
|
||||
gfxBridge.createCollisionShapeGraphicsObject(box);
|
||||
btTransform startTrans;
|
||||
startTrans.setIdentity();
|
||||
startTrans.setOrigin(btVector3(0, 1, 0));
|
||||
btRigidBody* body = createRigidBody(1, startTrans, box);
|
||||
body->setFriction(1);
|
||||
body->setActivationState(DISABLE_DEACTIVATION);
|
||||
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(1, 1, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void KinematicObjectSetup::stepSimulation(float deltaTime)
|
||||
{
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[0];
|
||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
if (body)
|
||||
{
|
||||
btMotionState* ms = body->getMotionState();
|
||||
|
||||
btTransform startTrans;
|
||||
startTrans.setIdentity();
|
||||
static float time = 0.f;
|
||||
time += 0.01f;
|
||||
static float xPos = 0.f;
|
||||
xPos = sinf(time)*10.f;
|
||||
startTrans.setOrigin(btVector3(xPos, -1, 0));
|
||||
if (ms)
|
||||
{
|
||||
|
||||
ms->setWorldTransform(startTrans);
|
||||
}
|
||||
else
|
||||
{
|
||||
body->setWorldTransform(startTrans);
|
||||
}
|
||||
}
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void CcdPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
|
||||
{
|
||||
createEmptyDynamicsWorld();
|
||||
|
||||
|
||||
///create a few basic rigid bodies
|
||||
btBoxShape* box = new btBoxShape(btVector3(btScalar(110.), btScalar(1.), btScalar(110.)));
|
||||
gfxBridge.createCollisionShapeGraphicsObject(box);
|
||||
// box->initializePolyhedralFeatures();
|
||||
btCollisionShape* groundShape = box;
|
||||
|
||||
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
//m_collisionShapes.push_back(new btCylinderShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)));
|
||||
m_collisionShapes.push_back(new btBoxShape(btVector3(CUBE_HALF_EXTENTS, CUBE_HALF_EXTENTS, CUBE_HALF_EXTENTS)));
|
||||
|
||||
btTransform groundTransform;
|
||||
groundTransform.setIdentity();
|
||||
//groundTransform.setOrigin(btVector3(5,5,5));
|
||||
|
||||
//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
|
||||
{
|
||||
btScalar mass(0.);
|
||||
|
||||
//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)
|
||||
groundShape->calculateLocalInertia(mass, localInertia);
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(0, 1, 0));
|
||||
body->setFriction(0.5);
|
||||
//body->setRollingFriction(0.3);
|
||||
//add the body to the dynamics world
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
//create a few dynamic rigidbodies
|
||||
// Re-using the same collision is better for memory usage and performance
|
||||
|
||||
btCollisionShape* colShape = new btBoxShape(btVector3(1, 1, 1));
|
||||
gfxBridge.createCollisionShapeGraphicsObject(colShape);
|
||||
//btCollisionShape* colShape = new btSphereShape(btScalar(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);
|
||||
|
||||
int gNumObjects = 120;//120;
|
||||
int i;
|
||||
for (i = 0; i<gNumObjects; i++)
|
||||
{
|
||||
btCollisionShape* shape = colShape;// m_collisionShapes[1];
|
||||
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
|
||||
//stack them
|
||||
int colsize = 10;
|
||||
int row = (i*CUBE_HALF_EXTENTS * 2) / (colsize * 2 * CUBE_HALF_EXTENTS);
|
||||
int row2 = row;
|
||||
int col = (i) % (colsize)-colsize / 2;
|
||||
|
||||
|
||||
if (col>3)
|
||||
{
|
||||
col = 11;
|
||||
row2 |= 1;
|
||||
}
|
||||
|
||||
btVector3 pos(col * 2 * CUBE_HALF_EXTENTS + (row2 % 2)*CUBE_HALF_EXTENTS,
|
||||
row * 2 * CUBE_HALF_EXTENTS + CUBE_HALF_EXTENTS + EXTRA_HEIGHT, 0);
|
||||
|
||||
trans.setOrigin(pos);
|
||||
|
||||
float mass = 1.f;
|
||||
|
||||
btRigidBody* body = createRigidBody(mass, trans, shape);
|
||||
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(1, 1, 0));
|
||||
|
||||
body->setAnisotropicFriction(shape->getAnisotropicRollingFrictionDirection(), btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION);
|
||||
body->setFriction(0.5);
|
||||
|
||||
//body->setRollingFriction(.3);
|
||||
///when using m_ccdMode
|
||||
//if (m_ccdMode == USE_CCD)
|
||||
{
|
||||
body->setCcdMotionThreshold(CUBE_HALF_EXTENTS);
|
||||
body->setCcdSweptSphereRadius(0.9*CUBE_HALF_EXTENTS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
|
||||
#ifndef CCD_PHYSICS_SETUP_H
|
||||
#define CCD_PHYSICS_SETUP_H
|
||||
|
||||
|
||||
#include "Bullet3AppSupport/CommonRigidBodySetup.h"
|
||||
|
||||
struct CcdPhysicsSetup : public CommonRigidBodySetup
|
||||
{
|
||||
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);
|
||||
|
||||
};
|
||||
|
||||
struct KinematicObjectSetup : public CommonRigidBodySetup
|
||||
{
|
||||
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);
|
||||
|
||||
virtual void stepSimulation(float deltaTime);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //CCD_PHYSICS_SETUP_H
|
@ -1,5 +0,0 @@
|
||||
noinst_PROGRAMS=CcdPhysicsDemo
|
||||
|
||||
CcdPhysicsDemo_SOURCES=CcdPhysicsDemo.cpp CcdPhysicsDemo.h main.cpp
|
||||
CcdPhysicsDemo_CXXFLAGS=-I@top_builddir@/src -I@top_builddir@/Demos/OpenGL $(CXXFLAGS)
|
||||
CcdPhysicsDemo_LDADD=-L../OpenGL -lbulletopenglsupport -L../../src -lBulletDynamics -lBulletCollision -lLinearMath @opengl_LIBS@
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "CcdPhysicsDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#ifdef __DEBUG_FPU_ISSUES
|
||||
#define _GNU_SOURCE
|
||||
#include <fenv.h>
|
||||
#endif
|
||||
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
CcdPhysicsDemo* ccdDemo = new CcdPhysicsDemo();
|
||||
|
||||
#ifdef __DEBUG_FPU_ISSUES
|
||||
// feenableexcept (FE_DIVBYZERO);
|
||||
// feenableexcept (FE_INEXACT);
|
||||
// feenableexcept (FE_INVALID);
|
||||
// feenableexcept (FE_OVERFLOW|FE_DIVBYZERO|FE_UNDERFLOW);
|
||||
// feenableexcept (FE_UNDERFLOW);
|
||||
#endif
|
||||
|
||||
ccdDemo->initPhysics();
|
||||
ccdDemo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
|
||||
glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.com",ccdDemo);
|
||||
|
||||
delete ccdDemo;
|
||||
return 0;
|
||||
|
||||
}
|
@ -1,277 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
//#define USE_GROUND_BOX 1
|
||||
#define PRINT_CONTACT_STATISTICS 1
|
||||
#define USE_PARALLEL_DISPATCHER 1
|
||||
|
||||
|
||||
//#define USE_SIMPLE_DYNAMICS_WORLD 1
|
||||
|
||||
int gNumObjects = 5;
|
||||
#define HALF_EXTENTS btScalar(1.)
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
btScalar deltaTime = btScalar(1./60.);
|
||||
btScalar gCollisionMargin = btScalar(0.05);
|
||||
#include "BasicDemo2.h"
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#include "BulletMultiThreaded/SpuGatheringCollisionDispatcher.h"
|
||||
#include "BulletMultiThreaded/Win32ThreadSupport.h"
|
||||
#include "BulletMultiThreaded/SpuLibspe2Support.h"
|
||||
#include "BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h"
|
||||
#endif//USE_PARALLEL_DISPATCHER
|
||||
|
||||
|
||||
#include <LinearMath/btAlignedObjectArray.h>
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
BasicDemo ccdDemo;
|
||||
ccdDemo.initPhysics();
|
||||
|
||||
int i;
|
||||
for (i=0;i<5;i++)
|
||||
ccdDemo.clientMoveAndDisplay();
|
||||
ccdDemo.exitPhysics();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern int gNumManifold;
|
||||
|
||||
void BasicDemo::clientMoveAndDisplay()
|
||||
{
|
||||
|
||||
//simple dynamics world doesn't handle fixed-time-stepping
|
||||
float ms = m_clock.getTimeMicroseconds();
|
||||
m_clock.reset();
|
||||
float minFPS = 1000000.f/60.f;
|
||||
if (ms > minFPS)
|
||||
ms = minFPS;
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->stepSimulation(ms / 1000000.f);
|
||||
|
||||
//some additional debugging info
|
||||
#ifdef PRINT_CONTACT_STATISTICS
|
||||
printf("num contact manifolds: %i\n",gNumManifold);
|
||||
int numManifolds = m_dynamicsWorld->getDispatcher()->getNumManifolds();
|
||||
for (int i=0;i<numManifolds;i++)
|
||||
{
|
||||
btPersistentManifold* contactManifold = m_dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
|
||||
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
|
||||
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
|
||||
|
||||
int numContacts = contactManifold->getNumContacts();
|
||||
for (int j=0;j<numContacts;j++)
|
||||
{
|
||||
btManifoldPoint& pt = contactManifold->getContactPoint(j);
|
||||
btVector3 ptA = pt.getPositionWorldOnA();
|
||||
btVector3 ptB = pt.getPositionWorldOnB();
|
||||
printf("contact manifold[%d],pointA[%d]=(%f,%f,%f)\n",i,j,ptA[0],ptA[1],ptA[2]);
|
||||
}
|
||||
}
|
||||
#endif //PRINT_CONTACT_STATISTICS
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void BasicDemo::initPhysics()
|
||||
{
|
||||
|
||||
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
|
||||
int maxNumOutstandingTasks = 1;//number of maximum outstanding tasks
|
||||
#ifdef USE_WIN32_THREADING
|
||||
|
||||
Win32ThreadSupport* threadSupport = new Win32ThreadSupport(Win32ThreadSupport::Win32ThreadConstructionInfo(
|
||||
"collision",
|
||||
processCollisionTask,
|
||||
createCollisionLocalStoreMemory,
|
||||
maxNumOutstandingTasks));
|
||||
#else
|
||||
|
||||
spe_program_handle_t * program_handle;
|
||||
#ifndef USE_CESOF
|
||||
char* spuFileName = "../../../src/BulletMultiThreaded/out/spuCollision.elf";
|
||||
|
||||
program_handle = spe_image_open (spuFileName);
|
||||
if (program_handle == NULL)
|
||||
{
|
||||
printf( "SPU OPEN IMAGE ERROR:%s\n",spuFileName);
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "IMAGE OPENED:%s\n",spuFileName);
|
||||
}
|
||||
#else
|
||||
extern spe_program_handle_t spu_program;
|
||||
program_handle = &spu_program;
|
||||
#endif
|
||||
SpuLibspe2Support* threadSupport = new SpuLibspe2Support( program_handle, maxNumOutstandingTasks);
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
|
||||
m_dispatcher = new SpuGatheringCollisionDispatcher(threadSupport,maxNumOutstandingTasks,collisionConfiguration);
|
||||
#else
|
||||
m_dispatcher = new btCollisionDispatcher(collisionConfiguration);
|
||||
#endif //USE_PARALLEL_DISPATCHER
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
|
||||
#define USE_SWEEP_AND_PRUNE 1
|
||||
#ifdef USE_SWEEP_AND_PRUNE
|
||||
#define maxProxies 8192
|
||||
btVector3 worldAabbMin(-10000,-10000,-10000);
|
||||
btVector3 worldAabbMax(10000,10000,10000);
|
||||
m_overlappingPairCache = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
|
||||
//m_overlappingPairCache = new btMultiSapBroadphase();
|
||||
|
||||
|
||||
#else
|
||||
m_overlappingPairCache = new btSimpleBroadphase;
|
||||
#endif //USE_SWEEP_AND_PRUNE
|
||||
|
||||
|
||||
|
||||
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
|
||||
m_solver = sol;
|
||||
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver,m_collisionConfiguration);
|
||||
m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
|
||||
|
||||
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
|
||||
|
||||
|
||||
///create a few basic rigid bodies
|
||||
|
||||
|
||||
//static ground
|
||||
#ifdef USE_GROUND_BOX
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
|
||||
#else
|
||||
btCollisionShape* groundShape = new btSphereShape(btScalar(50.));
|
||||
#endif//USE_GROUND_BOX
|
||||
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
|
||||
btTransform groundTransform;
|
||||
groundTransform.setIdentity();
|
||||
groundTransform.setOrigin(btVector3(0,-50,0));
|
||||
localCreateRigidBody(btScalar(0.),groundTransform,groundShape);
|
||||
|
||||
//create a few dynamic sphere rigidbodies (re-using the same sphere shape)
|
||||
//btCollisionShape* sphereShape = new btBoxShape(btVector3(1,1,1));
|
||||
btCollisionShape* sphereShape = new btSphereShape(btScalar(1.));
|
||||
m_collisionShapes.push_back(sphereShape);
|
||||
|
||||
int i;
|
||||
for (i=0;i<gNumObjects;i++)
|
||||
{
|
||||
|
||||
sphereShape->setMargin(gCollisionMargin);
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
//stack them
|
||||
int colsize = 2;
|
||||
int row = (int)((i*HALF_EXTENTS*2)/(colsize*2*HALF_EXTENTS));
|
||||
int row2 = row;
|
||||
int col = (i)%(colsize)-colsize/2;
|
||||
btVector3 pos(col*2*HALF_EXTENTS + (row2%2)*HALF_EXTENTS,
|
||||
row*2*HALF_EXTENTS+HALF_EXTENTS,0);
|
||||
|
||||
trans.setOrigin(pos);
|
||||
//btRigidBody* body = localCreateRigidBody(btScalar(1.),trans,sphereShape);
|
||||
localCreateRigidBody(btScalar(1.),trans,sphereShape);
|
||||
}
|
||||
|
||||
//clientResetScene();
|
||||
}
|
||||
|
||||
btRigidBody* BasicDemo::localCreateRigidBody(btScalar mass,const btTransform& startTrans,btCollisionShape* colShape)
|
||||
{
|
||||
btVector3 inertia(0,0,0);
|
||||
if (mass)
|
||||
colShape->calculateLocalInertia(mass,inertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbci(mass,0,colShape,inertia);
|
||||
rbci.m_startWorldTransform = startTrans;
|
||||
|
||||
btRigidBody* body = new btRigidBody(rbci);
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
return body;
|
||||
|
||||
}
|
||||
void BasicDemo::exitPhysics()
|
||||
{
|
||||
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
//delete solver
|
||||
delete m_solver;
|
||||
|
||||
//delete broadphase
|
||||
delete m_overlappingPairCache;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 BASIC_DEMO_H
|
||||
#define BASIC_DEMO_H
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
|
||||
class btDiscreteDynamicsworld;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
|
||||
///BasicDemo is good starting point for learning the code base and porting.
|
||||
class BasicDemo
|
||||
{
|
||||
btClock m_clock;
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btBroadphaseInterface* m_overlappingPairCache;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
btConstraintSolver* m_solver;
|
||||
btDiscreteDynamicsWorld* m_dynamicsWorld;
|
||||
|
||||
btCollisionAlgorithmCreateFunc* m_sphereSphereCF;
|
||||
btCollisionAlgorithmCreateFunc* m_sphereBoxCF;
|
||||
btCollisionAlgorithmCreateFunc* m_boxSphereCF;
|
||||
|
||||
btRigidBody* localCreateRigidBody(btScalar mass,const btTransform& startTrans,btCollisionShape* colShape);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //BASIC_DEMO_H
|
||||
|
@ -1,59 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
SET(CharacterDemo_SRCS
|
||||
|
||||
DynamicCharacterController.cpp
|
||||
DynamicCharacterController.h
|
||||
CharacterDemo.cpp
|
||||
CharacterDemo.h
|
||||
../BspDemo/BspConverter.cpp
|
||||
../BspDemo/BspConverter.h
|
||||
../BspDemo/BspLoader.cpp
|
||||
../BspDemo/BspLoader.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppCharacterDemo
|
||||
${CharacterDemo_SRCS}
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppCharacterDemo
|
||||
${CharacterDemo_SRCS}
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppCharacterDemo
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/BspDemo/BspDemo.bsp ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppCharacterDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppCharacterDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppCharacterDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,526 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "btBulletDynamicsCommon.h"
|
||||
#include "BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"
|
||||
#include "BulletCollision/CollisionDispatch/btGhostObject.h"
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
#include "GL_ShapeDrawer.h"
|
||||
|
||||
#include "GlutStuff.h"
|
||||
#include "CharacterDemo.h"
|
||||
#ifdef DYNAMIC_CHARACTER_CONTROLLER
|
||||
#include "DynamicCharacterController.h"
|
||||
#else
|
||||
#include "BulletDynamics/Character/btKinematicCharacterController.h"
|
||||
#endif
|
||||
|
||||
const int maxProxies = 32766;
|
||||
const int maxOverlap = 65535;
|
||||
|
||||
static int gForward = 0;
|
||||
static int gBackward = 0;
|
||||
static int gLeft = 0;
|
||||
static int gRight = 0;
|
||||
static int gJump = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
CharacterDemo::CharacterDemo()
|
||||
:
|
||||
m_indexVertexArrays(0),
|
||||
m_vertices(0),
|
||||
m_cameraHeight(4.f),
|
||||
m_minCameraDistance(3.f),
|
||||
m_maxCameraDistance(10.f)
|
||||
{
|
||||
m_character = 0;
|
||||
m_cameraPosition = btVector3(30,30,30);
|
||||
}
|
||||
|
||||
|
||||
void CharacterDemo::initPhysics()
|
||||
{
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50));
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
btVector3 worldMin(-1000,-1000,-1000);
|
||||
btVector3 worldMax(1000,1000,1000);
|
||||
btAxisSweep3* sweepBP = new btAxisSweep3(worldMin,worldMax);
|
||||
m_overlappingPairCache = sweepBP;
|
||||
|
||||
m_constraintSolver = new btSequentialImpulseConstraintSolver();
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_constraintSolver,m_collisionConfiguration);
|
||||
m_dynamicsWorld->getDispatchInfo().m_allowedCcdPenetration=0.0001f;
|
||||
|
||||
#ifdef DYNAMIC_CHARACTER_CONTROLLER
|
||||
m_character = new DynamicCharacterController ();
|
||||
#else
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity ();
|
||||
//startTransform.setOrigin (btVector3(0.0, 4.0, 0.0));
|
||||
startTransform.setOrigin (btVector3(10.210098,-1.6433364,16.453260));
|
||||
|
||||
|
||||
m_ghostObject = new btPairCachingGhostObject();
|
||||
m_ghostObject->setWorldTransform(startTransform);
|
||||
sweepBP->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
|
||||
btScalar characterHeight=1.75;
|
||||
btScalar characterWidth =1.75;
|
||||
btConvexShape* capsule = new btCapsuleShape(characterWidth,characterHeight);
|
||||
m_ghostObject->setCollisionShape (capsule);
|
||||
m_ghostObject->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);
|
||||
|
||||
btScalar stepHeight = btScalar(0.35);
|
||||
m_character = new btKinematicCharacterController (m_ghostObject,capsule,stepHeight);
|
||||
#endif
|
||||
|
||||
////////////////
|
||||
|
||||
/// Create some basic environment from a Quake level
|
||||
|
||||
//m_dynamicsWorld->setGravity(btVector3(0,0,0));
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
|
||||
const char* filename = "BspDemo.bsp";
|
||||
|
||||
const char* prefix[]={"./","../","../../","../../../","../../../../", "BspDemo/", "Demos/BspDemo/",
|
||||
"../Demos/BspDemo/","../../Demos/BspDemo/"};
|
||||
int numPrefixes = sizeof(prefix)/sizeof(const char*);
|
||||
char relativeFileName[1024];
|
||||
FILE* file=0;
|
||||
|
||||
for (int i=0;i<numPrefixes;i++)
|
||||
{
|
||||
sprintf(relativeFileName,"%s%s",prefix[i],filename);
|
||||
file = fopen(relativeFileName,"r");
|
||||
if (file)
|
||||
break;
|
||||
}
|
||||
void* memoryBuffer = 0;
|
||||
|
||||
|
||||
if (file)
|
||||
{
|
||||
BspLoader bspLoader;
|
||||
int size=0;
|
||||
if (fseek(file, 0, SEEK_END) || (size = ftell(file)) == EOF || fseek(file, 0, SEEK_SET)) { /* File operations denied? ok, just close and return failure */
|
||||
printf("Error: cannot get filesize from %s\n", filename);
|
||||
} else
|
||||
{
|
||||
//how to detect file size?
|
||||
memoryBuffer = malloc(size+1);
|
||||
fread(memoryBuffer,1,size,file);
|
||||
bspLoader.loadBSPFile( memoryBuffer);
|
||||
|
||||
BspToBulletConverter bsp2bullet(this);
|
||||
float bspScaling = 0.1f;
|
||||
bsp2bullet.convertBsp(bspLoader,bspScaling);
|
||||
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
///only collide with static for now (no interaction with dynamic objects)
|
||||
m_dynamicsWorld->addCollisionObject(m_ghostObject,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
|
||||
|
||||
m_dynamicsWorld->addAction(m_character);
|
||||
|
||||
|
||||
///////////////
|
||||
|
||||
clientResetScene();
|
||||
|
||||
setCameraDistance(56.f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//to be implemented by the demo
|
||||
void CharacterDemo::renderme()
|
||||
{
|
||||
updateCamera();
|
||||
|
||||
DemoApplication::renderme();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CharacterDemo::debugDrawContacts()
|
||||
{
|
||||
// printf("numPairs = %d\n",m_customPairCallback->getOverlappingPairArray().size());
|
||||
{
|
||||
btManifoldArray manifoldArray;
|
||||
btBroadphasePairArray& pairArray = m_ghostObject->getOverlappingPairCache()->getOverlappingPairArray();
|
||||
int numPairs = pairArray.size();
|
||||
|
||||
for (int i=0;i<numPairs;i++)
|
||||
{
|
||||
manifoldArray.clear();
|
||||
|
||||
const btBroadphasePair& pair = pairArray[i];
|
||||
|
||||
btBroadphasePair* collisionPair = m_overlappingPairCache->getOverlappingPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1);
|
||||
if (!collisionPair)
|
||||
continue;
|
||||
|
||||
if (collisionPair->m_algorithm)
|
||||
collisionPair->m_algorithm->getAllContactManifolds(manifoldArray);
|
||||
|
||||
for (int j=0;j<manifoldArray.size();j++)
|
||||
{
|
||||
btPersistentManifold* manifold = manifoldArray[j];
|
||||
for (int p=0;p<manifold->getNumContacts();p++)
|
||||
{
|
||||
const btManifoldPoint&pt = manifold->getContactPoint(p);
|
||||
|
||||
btVector3 color(255,255,255);
|
||||
m_dynamicsWorld->getDebugDrawer()->drawContactPoint(pt.getPositionWorldOnB(),pt.m_normalWorldOnB,pt.getDistance(),pt.getLifeTime(),color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CharacterDemo::clientMoveAndDisplay()
|
||||
{
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
float dt = getDeltaTimeMicroseconds() * 0.000001f;
|
||||
|
||||
/* Character stuff &*/
|
||||
if (m_character)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
debugDrawContacts();
|
||||
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
//during idle mode, just run 1 simulation step maximum
|
||||
int maxSimSubSteps = m_idle ? 1 : 2;
|
||||
if (m_idle)
|
||||
dt = 1.0/420.f;
|
||||
|
||||
///set walkDirection for our character
|
||||
btTransform xform;
|
||||
xform = m_ghostObject->getWorldTransform ();
|
||||
|
||||
btVector3 forwardDir = xform.getBasis()[2];
|
||||
// printf("forwardDir=%f,%f,%f\n",forwardDir[0],forwardDir[1],forwardDir[2]);
|
||||
btVector3 upDir = xform.getBasis()[1];
|
||||
btVector3 strafeDir = xform.getBasis()[0];
|
||||
forwardDir.normalize ();
|
||||
upDir.normalize ();
|
||||
strafeDir.normalize ();
|
||||
|
||||
btVector3 walkDirection = btVector3(0.0, 0.0, 0.0);
|
||||
btScalar walkVelocity = btScalar(1.1) * 4.0; // 4 km/h -> 1.1 m/s
|
||||
btScalar walkSpeed = walkVelocity * dt;
|
||||
|
||||
//rotate view
|
||||
if (gLeft)
|
||||
{
|
||||
btMatrix3x3 orn = m_ghostObject->getWorldTransform().getBasis();
|
||||
orn *= btMatrix3x3(btQuaternion(btVector3(0,1,0),0.01));
|
||||
m_ghostObject->getWorldTransform ().setBasis(orn);
|
||||
}
|
||||
|
||||
if (gRight)
|
||||
{
|
||||
btMatrix3x3 orn = m_ghostObject->getWorldTransform().getBasis();
|
||||
orn *= btMatrix3x3(btQuaternion(btVector3(0,1,0),-0.01));
|
||||
m_ghostObject->getWorldTransform ().setBasis(orn);
|
||||
}
|
||||
|
||||
if (gForward)
|
||||
walkDirection += forwardDir;
|
||||
|
||||
if (gBackward)
|
||||
walkDirection -= forwardDir;
|
||||
|
||||
|
||||
m_character->setWalkDirection(walkDirection*walkSpeed);
|
||||
|
||||
|
||||
int numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps);
|
||||
|
||||
//optional but useful: debug drawing
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
//#define VERBOSE_FEEDBACK
|
||||
#ifdef VERBOSE_FEEDBACK
|
||||
if (!numSimSteps)
|
||||
printf("Interpolated transforms\n");
|
||||
else
|
||||
{
|
||||
if (numSimSteps > maxSimSubSteps)
|
||||
{
|
||||
//detect dropping frames
|
||||
printf("Dropped (%i) simulation steps out of %i\n",numSimSteps - maxSimSubSteps,numSimSteps);
|
||||
} else
|
||||
{
|
||||
printf("Simulated (%i) steps\n",numSimSteps);
|
||||
}
|
||||
}
|
||||
#endif //VERBOSE_FEEDBACK
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
btProfiler::beginBlock("render");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
|
||||
renderme();
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
btProfiler::endBlock("render");
|
||||
#endif
|
||||
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CharacterDemo::displayCallback(void)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
renderme();
|
||||
|
||||
//optional but useful: debug drawing
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
debugDrawContacts();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
void CharacterDemo::clientResetScene()
|
||||
{
|
||||
m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(m_ghostObject->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher());
|
||||
|
||||
m_character->reset (m_dynamicsWorld);
|
||||
///WTF
|
||||
m_character->warp (btVector3(10.210001,-2.0306311,16.576973));
|
||||
|
||||
}
|
||||
|
||||
void CharacterDemo::specialKeyboardUp(int key, int x, int y)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case GLUT_KEY_UP:
|
||||
{
|
||||
gForward = 0;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_DOWN:
|
||||
{
|
||||
gBackward = 0;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_LEFT:
|
||||
{
|
||||
gLeft = 0;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_RIGHT:
|
||||
{
|
||||
gRight = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DemoApplication::specialKeyboardUp(key,x,y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CharacterDemo::specialKeyboard(int key, int x, int y)
|
||||
{
|
||||
|
||||
// printf("key = %i x=%i y=%i\n",key,x,y);
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case GLUT_KEY_UP:
|
||||
{
|
||||
gForward = 1;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_DOWN:
|
||||
{
|
||||
gBackward = 1;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_LEFT:
|
||||
{
|
||||
gLeft = 1;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_RIGHT:
|
||||
{
|
||||
gRight = 1;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_F1:
|
||||
{
|
||||
if (m_character && m_character->canJump())
|
||||
gJump = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DemoApplication::specialKeyboard(key,x,y);
|
||||
break;
|
||||
}
|
||||
|
||||
// glutPostRedisplay();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CharacterDemo::updateCamera()
|
||||
{
|
||||
|
||||
//#define DISABLE_CAMERA 1
|
||||
#ifdef DISABLE_CAMERA
|
||||
DemoApplication::updateCamera();
|
||||
return;
|
||||
#endif //DISABLE_CAMERA
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
btTransform characterWorldTrans;
|
||||
|
||||
//look at the vehicle
|
||||
characterWorldTrans = m_ghostObject->getWorldTransform();
|
||||
btVector3 up = characterWorldTrans.getBasis()[1];
|
||||
btVector3 backward = -characterWorldTrans.getBasis()[2];
|
||||
up.normalize ();
|
||||
backward.normalize ();
|
||||
|
||||
m_cameraTargetPosition = characterWorldTrans.getOrigin();
|
||||
m_cameraPosition = m_cameraTargetPosition + up * 10.0 + backward * 12.0;
|
||||
|
||||
//use the convex sweep test to find a safe position for the camera (not blocked by static geometry)
|
||||
btSphereShape cameraSphere(0.2f);
|
||||
btTransform cameraFrom,cameraTo;
|
||||
cameraFrom.setIdentity();
|
||||
cameraFrom.setOrigin(characterWorldTrans.getOrigin());
|
||||
cameraTo.setIdentity();
|
||||
cameraTo.setOrigin(m_cameraPosition);
|
||||
|
||||
btCollisionWorld::ClosestConvexResultCallback cb( characterWorldTrans.getOrigin(), cameraTo.getOrigin() );
|
||||
cb.m_collisionFilterMask = btBroadphaseProxy::StaticFilter;
|
||||
|
||||
m_dynamicsWorld->convexSweepTest(&cameraSphere,cameraFrom,cameraTo,cb);
|
||||
if (cb.hasHit())
|
||||
{
|
||||
|
||||
btScalar minFraction = cb.m_closestHitFraction;//btMax(btScalar(0.3),cb.m_closestHitFraction);
|
||||
m_cameraPosition.setInterpolate3(cameraFrom.getOrigin(),cameraTo.getOrigin(),minFraction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//update OpenGL camera settings
|
||||
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10000.0);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
gluLookAt(m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2],
|
||||
m_cameraTargetPosition[0],m_cameraTargetPosition[1], m_cameraTargetPosition[2],
|
||||
m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
CharacterDemo::~CharacterDemo()
|
||||
{
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
if (m_character)
|
||||
{
|
||||
m_dynamicsWorld->removeCollisionObject(m_ghostObject);
|
||||
}
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
delete m_indexVertexArrays;
|
||||
delete m_vertices;
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
//delete solver
|
||||
delete m_constraintSolver;
|
||||
|
||||
//delete broadphase
|
||||
delete m_overlappingPairCache;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
}
|
||||
|
@ -1,153 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 CHARACTER_DEMO_H
|
||||
#define CHARACTER_DEMO_H
|
||||
|
||||
|
||||
///DYNAMIC_CHARACTER_CONTROLLER is not fully implemented yet at the moment
|
||||
//#define DYNAMIC_CHARACTER_CONTROLLER 1
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btConvexHullShape.h"
|
||||
|
||||
class btCharacterControllerInterface;
|
||||
class btDynamicCharacterController;
|
||||
class btKinematicCharacterController;
|
||||
|
||||
class btCollisionShape;
|
||||
|
||||
|
||||
#include "GlutDemoApplication.h"
|
||||
|
||||
///CharacterDemo shows how to setup and use the built-in raycast vehicle
|
||||
class CharacterDemo : public GlutDemoApplication
|
||||
{
|
||||
public:
|
||||
|
||||
#ifdef DYNAMIC_CHARACTER_CONTROLLER
|
||||
btCharacterControllerInterface* m_character;
|
||||
#else
|
||||
btKinematicCharacterController* m_character;
|
||||
class btPairCachingGhostObject* m_ghostObject;
|
||||
#endif
|
||||
|
||||
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
class btBroadphaseInterface* m_overlappingPairCache;
|
||||
|
||||
class btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
class btConstraintSolver* m_constraintSolver;
|
||||
|
||||
class btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
class btTriangleIndexVertexArray* m_indexVertexArrays;
|
||||
|
||||
btVector3* m_vertices;
|
||||
|
||||
void debugDrawContacts();
|
||||
|
||||
float m_cameraHeight;
|
||||
|
||||
float m_minCameraDistance;
|
||||
float m_maxCameraDistance;
|
||||
|
||||
|
||||
CharacterDemo();
|
||||
|
||||
virtual ~CharacterDemo();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
///a very basic camera following the character
|
||||
virtual void updateCamera();
|
||||
|
||||
virtual void specialKeyboard(int key, int x, int y);
|
||||
|
||||
virtual void specialKeyboardUp(int key, int x, int y);
|
||||
|
||||
void renderme();
|
||||
|
||||
void initPhysics();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
CharacterDemo* demo = new CharacterDemo();
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define QUAKE_BSP_IMPORTING 1
|
||||
#ifdef QUAKE_BSP_IMPORTING
|
||||
#include "../BspDemo/BspLoader.h"
|
||||
#include "../BspDemo/BspConverter.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class BspToBulletConverter : public BspConverter
|
||||
{
|
||||
CharacterDemo* m_demoApp;
|
||||
|
||||
public:
|
||||
|
||||
BspToBulletConverter(CharacterDemo* demoApp)
|
||||
:m_demoApp(demoApp)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void addConvexVerticesCollider(btAlignedObjectArray<btVector3>& vertices, bool isEntity, const btVector3& entityTargetLocation)
|
||||
{
|
||||
///perhaps we can do something special with entities (isEntity)
|
||||
///like adding a collision Triggering (as example)
|
||||
|
||||
if (vertices.size() > 0)
|
||||
{
|
||||
float mass = 0.f;
|
||||
btTransform startTransform;
|
||||
//can use a shift
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-10.0f,0.0f));
|
||||
//this create an internal copy of the vertices
|
||||
for (int i = 0; i < vertices.size(); i++)
|
||||
{
|
||||
vertices[i] *= btScalar(0.5);
|
||||
float t = vertices[i].getZ() * btScalar(0.75);
|
||||
vertices[i].setZ(-vertices[i].getY());
|
||||
vertices[i].setY(t);
|
||||
}
|
||||
|
||||
btCollisionShape* shape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
|
||||
m_demoApp->m_collisionShapes.push_back(shape);
|
||||
|
||||
//btRigidBody* body = m_demoApp->localCreateRigidBody(mass, startTransform,shape);
|
||||
m_demoApp->localCreateRigidBody(mass, startTransform,shape);
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif //QUAKE_BSP_IMPORTING
|
||||
|
||||
|
||||
#endif //CHARACTER_DEMO_H
|
||||
|
||||
|
@ -1,204 +0,0 @@
|
||||
#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
|
||||
#include "LinearMath/btDefaultMotionState.h"
|
||||
#include "DynamicCharacterController.h"
|
||||
|
||||
DynamicCharacterController::DynamicCharacterController ()
|
||||
{
|
||||
m_rayLambda[0] = 1.0;
|
||||
m_rayLambda[1] = 1.0;
|
||||
m_halfHeight = 1.0;
|
||||
m_turnAngle = 0.0;
|
||||
m_maxLinearVelocity = 10.0;
|
||||
m_walkVelocity = 8.0; // meters/sec
|
||||
m_turnVelocity = 1.0; // radians/sec
|
||||
m_shape = NULL;
|
||||
m_rigidBody = NULL;
|
||||
}
|
||||
|
||||
DynamicCharacterController::~DynamicCharacterController ()
|
||||
{
|
||||
}
|
||||
|
||||
void DynamicCharacterController::setup (btScalar height, btScalar width, btScalar stepHeight)
|
||||
{
|
||||
btVector3 spherePositions[2];
|
||||
btScalar sphereRadii[2];
|
||||
|
||||
sphereRadii[0] = width;
|
||||
sphereRadii[1] = width;
|
||||
spherePositions[0] = btVector3 (0.0, (height/btScalar(2.0) - width), 0.0);
|
||||
spherePositions[1] = btVector3 (0.0, (-height/btScalar(2.0) + width), 0.0);
|
||||
|
||||
m_halfHeight = height/btScalar(2.0);
|
||||
|
||||
m_shape = new btMultiSphereShape (&spherePositions[0], &sphereRadii[0], 2);
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity ();
|
||||
startTransform.setOrigin (btVector3(0.0, 2.0, 0.0));
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo cInfo(1.0, myMotionState, m_shape);
|
||||
m_rigidBody = new btRigidBody(cInfo);
|
||||
// kinematic vs. static doesn't work
|
||||
//m_rigidBody->setCollisionFlags( m_rigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
m_rigidBody->setSleepingThresholds (0.0, 0.0);
|
||||
m_rigidBody->setAngularFactor (0.0);
|
||||
|
||||
}
|
||||
|
||||
void DynamicCharacterController::destroy ()
|
||||
{
|
||||
if (m_shape)
|
||||
{
|
||||
delete m_shape;
|
||||
}
|
||||
|
||||
if (m_rigidBody)
|
||||
{
|
||||
delete m_rigidBody;
|
||||
m_rigidBody = 0;
|
||||
}
|
||||
}
|
||||
|
||||
btCollisionObject* DynamicCharacterController::getCollisionObject ()
|
||||
{
|
||||
return m_rigidBody;
|
||||
}
|
||||
|
||||
void DynamicCharacterController::preStep (const btCollisionWorld* collisionWorld)
|
||||
{
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
btVector3 down = -xform.getBasis()[1];
|
||||
btVector3 forward = xform.getBasis()[2];
|
||||
down.normalize ();
|
||||
forward.normalize();
|
||||
|
||||
m_raySource[0] = xform.getOrigin();
|
||||
m_raySource[1] = xform.getOrigin();
|
||||
|
||||
m_rayTarget[0] = m_raySource[0] + down * m_halfHeight * btScalar(1.1);
|
||||
m_rayTarget[1] = m_raySource[1] + forward * m_halfHeight * btScalar(1.1);
|
||||
|
||||
class ClosestNotMe : public btCollisionWorld::ClosestRayResultCallback
|
||||
{
|
||||
public:
|
||||
ClosestNotMe (btRigidBody* me) : btCollisionWorld::ClosestRayResultCallback(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 0.0, 0.0))
|
||||
{
|
||||
m_me = me;
|
||||
}
|
||||
|
||||
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
|
||||
{
|
||||
if (rayResult.m_collisionObject == m_me)
|
||||
return 1.0;
|
||||
|
||||
return ClosestRayResultCallback::addSingleResult (rayResult, normalInWorldSpace
|
||||
);
|
||||
}
|
||||
protected:
|
||||
btRigidBody* m_me;
|
||||
};
|
||||
|
||||
ClosestNotMe rayCallback(m_rigidBody);
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
rayCallback.m_closestHitFraction = 1.0;
|
||||
collisionWorld->rayTest (m_raySource[i], m_rayTarget[i], rayCallback);
|
||||
if (rayCallback.hasHit())
|
||||
{
|
||||
m_rayLambda[i] = rayCallback.m_closestHitFraction;
|
||||
} else {
|
||||
m_rayLambda[i] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicCharacterController::playerStep (const btCollisionWorld* dynaWorld,btScalar dt,
|
||||
int forward,
|
||||
int backward,
|
||||
int left,
|
||||
int right,
|
||||
int jump)
|
||||
{
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
|
||||
/* Handle turning */
|
||||
if (left)
|
||||
m_turnAngle -= dt * m_turnVelocity;
|
||||
if (right)
|
||||
m_turnAngle += dt * m_turnVelocity;
|
||||
|
||||
xform.setRotation (btQuaternion (btVector3(0.0, 1.0, 0.0), m_turnAngle));
|
||||
|
||||
btVector3 linearVelocity = m_rigidBody->getLinearVelocity();
|
||||
btScalar speed = m_rigidBody->getLinearVelocity().length();
|
||||
|
||||
btVector3 forwardDir = xform.getBasis()[2];
|
||||
forwardDir.normalize ();
|
||||
btVector3 walkDirection = btVector3(0.0, 0.0, 0.0);
|
||||
btScalar walkSpeed = m_walkVelocity * dt;
|
||||
|
||||
if (forward)
|
||||
walkDirection += forwardDir;
|
||||
if (backward)
|
||||
walkDirection -= forwardDir;
|
||||
|
||||
|
||||
|
||||
if (!forward && !backward && onGround())
|
||||
{
|
||||
/* Dampen when on the ground and not being moved by the player */
|
||||
linearVelocity *= btScalar(0.2);
|
||||
m_rigidBody->setLinearVelocity (linearVelocity);
|
||||
} else {
|
||||
if (speed < m_maxLinearVelocity)
|
||||
{
|
||||
btVector3 velocity = linearVelocity + walkDirection * walkSpeed;
|
||||
m_rigidBody->setLinearVelocity (velocity);
|
||||
}
|
||||
}
|
||||
|
||||
m_rigidBody->getMotionState()->setWorldTransform (xform);
|
||||
m_rigidBody->setCenterOfMassTransform (xform);
|
||||
}
|
||||
|
||||
bool DynamicCharacterController::canJump () const
|
||||
{
|
||||
return onGround();
|
||||
}
|
||||
|
||||
void DynamicCharacterController::jump ()
|
||||
{
|
||||
if (!canJump())
|
||||
return;
|
||||
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
btVector3 up = xform.getBasis()[1];
|
||||
up.normalize ();
|
||||
btScalar magnitude = (btScalar(1.0)/m_rigidBody->getInvMass()) * btScalar(8.0);
|
||||
m_rigidBody->applyCentralImpulse (up * magnitude);
|
||||
}
|
||||
|
||||
bool DynamicCharacterController::onGround () const
|
||||
{
|
||||
return m_rayLambda[0] < btScalar(1.0);
|
||||
}
|
||||
|
||||
void DynamicCharacterController::reset ()
|
||||
{
|
||||
}
|
||||
void DynamicCharacterController::warp (const btVector3& origin)
|
||||
{
|
||||
}
|
||||
void DynamicCharacterController::registerPairCacheAndDispatcher (btOverlappingPairCache* pairCache, btCollisionDispatcher* dispatcher)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
#ifndef CHARACTER_CONTROLLER_H
|
||||
#define CHARACTER_CONTROLLER_H
|
||||
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
#include "BulletDynamics/Character/btCharacterControllerInterface.h"
|
||||
|
||||
class btCollisionShape;
|
||||
class btRigidBody;
|
||||
class btCollisionWorld;
|
||||
|
||||
///DynamicCharacterController is obsolete/unsupported at the moment
|
||||
class DynamicCharacterController : public btCharacterControllerInterface
|
||||
{
|
||||
protected:
|
||||
btScalar m_halfHeight;
|
||||
btCollisionShape* m_shape;
|
||||
btRigidBody* m_rigidBody;
|
||||
|
||||
btVector3 m_raySource[2];
|
||||
btVector3 m_rayTarget[2];
|
||||
btScalar m_rayLambda[2];
|
||||
btVector3 m_rayNormal[2];
|
||||
|
||||
btScalar m_turnAngle;
|
||||
|
||||
btScalar m_maxLinearVelocity;
|
||||
btScalar m_walkVelocity;
|
||||
btScalar m_turnVelocity;
|
||||
public:
|
||||
DynamicCharacterController ();
|
||||
~DynamicCharacterController ();
|
||||
void setup (btScalar height = 2.0, btScalar width = 0.25, btScalar stepHeight = 0.25);
|
||||
void destroy ();
|
||||
|
||||
virtual void reset ();
|
||||
virtual void warp (const btVector3& origin);
|
||||
virtual void registerPairCacheAndDispatcher (btOverlappingPairCache* pairCache, btCollisionDispatcher* dispatcher);
|
||||
|
||||
btCollisionObject* getCollisionObject ();
|
||||
|
||||
void preStep (const btCollisionWorld* collisionWorld);
|
||||
void playerStep (const btCollisionWorld* collisionWorld,btScalar dt,
|
||||
int forward,
|
||||
int backward,
|
||||
int left,
|
||||
int right,
|
||||
int jump);
|
||||
bool canJump () const;
|
||||
void jump ();
|
||||
|
||||
bool onGround () const;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,19 +0,0 @@
|
||||
|
||||
#include "CharacterDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
CharacterDemo* characterDemo = new CharacterDemo;
|
||||
|
||||
characterDemo->initPhysics();
|
||||
characterDemo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
return glutmain(argc, argv,640,480,"Bullet Character Demo. http://www.continuousphysics.com/Bullet/phpBB2/", characterDemo);
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppCollisionDemo
|
||||
CollisionDemo.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppCollisionDemo
|
||||
CollisionDemo.cpp
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppCollisionDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppCollisionDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppCollisionDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,380 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
///
|
||||
/// Collision Demo shows a degenerate case, where the Simplex solver has to deal with near-affine dependent cases
|
||||
/// See the define CATCH_DEGENERATE_TETRAHEDRON in Bullet's btVoronoiSimplexSolver.cpp
|
||||
///
|
||||
|
||||
|
||||
//#define CHECK_GENSHER_TRIANGLE_CASE 1
|
||||
|
||||
|
||||
///This low-level internal demo does intentionally NOT use the btBulletCollisionCommon.h header
|
||||
///It needs internal access
|
||||
#include "GL_Simplex1to4.h"
|
||||
#include "LinearMath/btQuaternion.h"
|
||||
#include "LinearMath/btTransform.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
||||
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btPointCollector.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
|
||||
#include "LinearMath/btTransformUtil.h"
|
||||
|
||||
#include "CollisionDemo.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "../OpenGL/GLDebugDrawer.h"
|
||||
GLDebugDrawer debugDrawer;
|
||||
|
||||
|
||||
float yaw=0.f,pitch=0.f,roll=0.f;
|
||||
const int maxNumObjects = 4;
|
||||
const int numObjects = 2;
|
||||
|
||||
GL_Simplex1to4 simplex;
|
||||
|
||||
btPolyhedralConvexShape* shapePtr[maxNumObjects];
|
||||
|
||||
btTransform tr[numObjects];
|
||||
int screenWidth = 640;
|
||||
int screenHeight = 480;
|
||||
|
||||
void DrawRasterizerLine(float const* , float const*, int)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
CollisionDemo* colDemo = new CollisionDemo();
|
||||
|
||||
#ifdef CHECK_GENSHER_TRIANGLE_CASE
|
||||
colDemo->setCameraDistance(8.f);
|
||||
#else
|
||||
colDemo->setCameraDistance(4.f);
|
||||
|
||||
#endif //
|
||||
colDemo->initPhysics();
|
||||
|
||||
|
||||
|
||||
return glutmain(argc, argv,screenWidth,screenHeight,"Collision Demo",colDemo);
|
||||
}
|
||||
|
||||
void CollisionDemo::initPhysics()
|
||||
{
|
||||
setTexturing(false);
|
||||
setShadows(false);
|
||||
|
||||
//m_debugMode |= btIDebugDraw::DBG_DrawWireframe;
|
||||
#ifdef CHECK_GENSHER_TRIANGLE_CASE
|
||||
m_azi = 140.f;
|
||||
#else
|
||||
m_azi = 250.f;
|
||||
#endif
|
||||
m_ele = 25.f;
|
||||
|
||||
m_azi = 0;
|
||||
m_ele = 0;
|
||||
m_cameraTargetPosition.setValue(8.12,0.39,0);
|
||||
|
||||
tr[0].setIdentity();
|
||||
tr[0].setOrigin(btVector3(10,0,0));
|
||||
tr[1].setIdentity();
|
||||
tr[1].setOrigin(btVector3(0,0,0));
|
||||
|
||||
|
||||
#ifdef CHECK_GENSHER_TRIANGLE_CASE
|
||||
tr[0].setIdentity();
|
||||
tr[1].setIdentity();
|
||||
#endif //CHECK_GENSHER_TRIANGLE_CASE
|
||||
|
||||
btVector3 boxHalfExtentsA(1,1,1);//1.0000004768371582f,1.0000004768371582f,1.0000001192092896f);
|
||||
btVector3 boxHalfExtentsB(4,4,4);//3.2836332321166992f,3.2836332321166992f,3.2836320400238037f);
|
||||
|
||||
#ifndef CHECK_GENSHER_TRIANGLE_CASE
|
||||
btBoxShape* boxA = new btBoxShape(boxHalfExtentsA);
|
||||
btBoxShape* boxB = new btBoxShape(boxHalfExtentsB);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef CHECK_GENSHER_TRIANGLE_CASE
|
||||
shapePtr[0] = trishapeA;
|
||||
shapePtr[1] = trishapeB;
|
||||
#else
|
||||
shapePtr[0] = boxA;
|
||||
shapePtr[1] = boxB;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void CollisionDemo::clientMoveAndDisplay()
|
||||
{
|
||||
|
||||
displayCallback();
|
||||
}
|
||||
|
||||
|
||||
static btVoronoiSimplexSolver sGjkSimplexSolver;
|
||||
btSimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
|
||||
|
||||
static btScalar gContactBreakingThreshold=.02f;
|
||||
int myiter = 1;
|
||||
int mystate = 2;
|
||||
|
||||
int checkPerturbation = 1;
|
||||
int numPerturbationIterations = 20;
|
||||
void CollisionDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
btVoronoiSimplexSolver sGjkSimplexSolver;
|
||||
btGjkEpaPenetrationDepthSolver epaSolver;
|
||||
btPointCollector gjkOutput;
|
||||
btVector3 worldBoundsMin(-1000,-1000,-1000);
|
||||
btVector3 worldBoundsMax(1000,1000,1000);
|
||||
{
|
||||
btGjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,&epaSolver);
|
||||
|
||||
btGjkPairDetector::ClosestPointInput input;
|
||||
input.m_transformA = tr[0];
|
||||
input.m_transformB = tr[1];
|
||||
|
||||
|
||||
convexConvex.getClosestPoints(input, gjkOutput, 0);
|
||||
}
|
||||
|
||||
ATTRIBUTE_ALIGNED16(btScalar) m[16];
|
||||
int i;
|
||||
|
||||
//m_ele = 21.2;
|
||||
//m_azi = -56.6;
|
||||
|
||||
|
||||
|
||||
|
||||
for (i=0;i<numObjects;i++)
|
||||
{
|
||||
tr[i].getOpenGLMatrix( m );
|
||||
//m_shapeDrawer->drawOpenGL(m,shapePtr[i],btVector3(119./255.,147./255.,60./255.),btIDebugDraw::DBG_FastWireframe,worldBoundsMin,worldBoundsMax);
|
||||
m_shapeDrawer->drawOpenGL(m,shapePtr[i],btVector3(0.6,0.6,0.6),btIDebugDraw::DBG_FastWireframe,worldBoundsMin,worldBoundsMax);
|
||||
}
|
||||
|
||||
if (gjkOutput.m_hasResult)
|
||||
{
|
||||
printf("original distance: %10.4f\n", gjkOutput.m_distance);
|
||||
btVector3 endPt = gjkOutput.m_pointInWorld +
|
||||
gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
|
||||
|
||||
debugDrawer.drawLine(gjkOutput.m_pointInWorld,endPt,btVector3(0,0,0));
|
||||
debugDrawer.drawSphere(gjkOutput.m_pointInWorld,0.05,btVector3(0,0,0));
|
||||
debugDrawer.drawSphere(endPt,0.05,btVector3(0,0,0));
|
||||
|
||||
bool perturbeA = false;//true;
|
||||
const btScalar angleLimit = 0.125f * SIMD_PI;
|
||||
btScalar perturbeAngle;
|
||||
btScalar radiusA = shapePtr[0]->getAngularMotionDisc();
|
||||
btScalar radiusB = shapePtr[1]->getAngularMotionDisc();
|
||||
|
||||
if (radiusA < radiusB)
|
||||
{
|
||||
perturbeAngle = gContactBreakingThreshold /radiusA;
|
||||
perturbeA = true;
|
||||
} else
|
||||
{
|
||||
perturbeAngle = gContactBreakingThreshold / radiusB;
|
||||
perturbeA = false;
|
||||
}
|
||||
if ( perturbeAngle > angleLimit )
|
||||
perturbeAngle = angleLimit;
|
||||
|
||||
perturbeAngle*=5;
|
||||
|
||||
btVector3 v0,v1;
|
||||
btPlaneSpace1(gjkOutput.m_normalOnBInWorld,v0,v1);
|
||||
|
||||
glLineWidth(5);
|
||||
int i;
|
||||
i=0;
|
||||
if (myiter>=numPerturbationIterations)
|
||||
myiter=0;
|
||||
if (mystate<2)
|
||||
{
|
||||
i= myiter;
|
||||
}
|
||||
|
||||
for ( ;i<numPerturbationIterations;i++)
|
||||
{
|
||||
|
||||
|
||||
|
||||
btGjkPairDetector::ClosestPointInput input;
|
||||
input.m_transformA = tr[0];
|
||||
input.m_transformB = tr[1];
|
||||
sGjkSimplexSolver.reset();
|
||||
|
||||
btQuaternion perturbeRot(v0,perturbeAngle);
|
||||
btScalar iterationAngle = i*(SIMD_2_PI/btScalar(numPerturbationIterations));
|
||||
btQuaternion rotq(gjkOutput.m_normalOnBInWorld,iterationAngle);
|
||||
if (perturbeA)
|
||||
{
|
||||
input.m_transformA.setBasis( btMatrix3x3(rotq*perturbeRot*rotq.inverse())*tr[0].getBasis());
|
||||
} else
|
||||
{
|
||||
input.m_transformB.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*tr[1].getBasis());
|
||||
}
|
||||
debugDrawer.drawTransform(input.m_transformA,1.0);
|
||||
btGjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,&epaSolver);
|
||||
input.m_maximumDistanceSquared = BT_LARGE_FLOAT;
|
||||
gjkOutput.m_distance = BT_LARGE_FLOAT;
|
||||
convexConvex.getClosestPoints(input, gjkOutput, 0);
|
||||
|
||||
|
||||
|
||||
if (mystate!=2 || i==myiter)
|
||||
|
||||
{
|
||||
ATTRIBUTE_ALIGNED16(btScalar) m[16];
|
||||
|
||||
input.m_transformA.getOpenGLMatrix( m );
|
||||
//m_shapeDrawer->drawOpenGL(m,shapePtr[0],btVector3(108./255.,131./255.,158./255),btIDebugDraw::DBG_FastWireframe,worldBoundsMin,worldBoundsMax);
|
||||
m_shapeDrawer->drawOpenGL(m,shapePtr[0],btVector3(0.3,0.3,1),btIDebugDraw::DBG_FastWireframe,worldBoundsMin,worldBoundsMax);
|
||||
|
||||
}
|
||||
|
||||
if (1)//gjkOutput.m_hasResult)
|
||||
{
|
||||
|
||||
printf("perturbed distance: %10.4f\n", gjkOutput.m_distance);
|
||||
btVector3 startPt,endPt;
|
||||
btScalar depth = 0;
|
||||
if (perturbeA)
|
||||
{
|
||||
btVector3 endPtOrg = gjkOutput.m_pointInWorld + gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
|
||||
endPt = (tr[0]*input.m_transformA.inverse())(endPtOrg);
|
||||
depth = (endPt - gjkOutput.m_pointInWorld).dot(gjkOutput.m_normalOnBInWorld);
|
||||
startPt = endPt-gjkOutput.m_normalOnBInWorld*depth;
|
||||
} else
|
||||
{
|
||||
endPt = gjkOutput.m_pointInWorld + gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
|
||||
startPt = (tr[1]*input.m_transformB.inverse())(gjkOutput.m_pointInWorld);
|
||||
depth = (endPt - startPt).dot(gjkOutput.m_normalOnBInWorld);
|
||||
}
|
||||
|
||||
printf("corrected distance: %10.4f\n", depth);
|
||||
|
||||
|
||||
|
||||
debugDrawer.drawLine(startPt,endPt,btVector3(1,0,0));
|
||||
debugDrawer.drawSphere(startPt,0.05,btVector3(0,1,0));
|
||||
debugDrawer.drawSphere(endPt,0.05,btVector3(0,0,1));
|
||||
}
|
||||
if (mystate<2)
|
||||
break;
|
||||
if (mystate==2 && i>myiter)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static int looper = 0;
|
||||
if (looper++>10)
|
||||
{
|
||||
looper =0;
|
||||
checkPerturbation++;
|
||||
if (checkPerturbation>numPerturbationIterations)
|
||||
checkPerturbation=0;
|
||||
}
|
||||
|
||||
GL_ShapeDrawer::drawCoordSystem();
|
||||
|
||||
|
||||
|
||||
if (mystate==1 || mystate==2)
|
||||
{
|
||||
static int count = 10;
|
||||
count--;
|
||||
if (count<0)
|
||||
{
|
||||
count=10;
|
||||
myiter++;
|
||||
}
|
||||
}
|
||||
|
||||
btQuaternion orn;
|
||||
orn.setEuler(yaw,pitch,roll);
|
||||
//let it rotate
|
||||
//tr[0].setRotation(orn);
|
||||
|
||||
pitch += 0.005f;
|
||||
yaw += 0.01f;
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
void CollisionDemo::specialKeyboard(int key, int x, int y)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case GLUT_KEY_DOWN:
|
||||
case GLUT_KEY_UP:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
DemoApplication::specialKeyboard(key,x,y);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CollisionDemo::specialKeyboardUp(int key, int x, int y)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case GLUT_KEY_UP :
|
||||
{
|
||||
myiter++;
|
||||
break;
|
||||
}
|
||||
|
||||
case GLUT_KEY_DOWN:
|
||||
{
|
||||
mystate++;
|
||||
if (mystate>1)
|
||||
myiter=0;
|
||||
if (mystate>=4)
|
||||
mystate = 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
DemoApplication::specialKeyboardUp(key,x,y);
|
||||
break;
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 COLLISION_DEMO_H
|
||||
#define COLLISION_DEMO_H
|
||||
|
||||
#include "GlutDemoApplication.h"
|
||||
|
||||
///CollisionDemo shows the low-level direct access to GJK
|
||||
class CollisionDemo : public GlutDemoApplication
|
||||
{
|
||||
public:
|
||||
|
||||
void initPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void specialKeyboardUp(int key, int x, int y);
|
||||
|
||||
virtual void specialKeyboard(int key, int x, int y);
|
||||
|
||||
};
|
||||
|
||||
#endif //COLLISION_DEMO_H
|
||||
|
@ -1,63 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
IF (USE_GLUT)
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppCollisionInterfaceDemo
|
||||
CollisionInterfaceDemo.cpp
|
||||
CollisionInterfaceDemo.h
|
||||
main.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppCollisionInterfaceDemo
|
||||
CollisionInterfaceDemo.cpp
|
||||
CollisionInterfaceDemo.h
|
||||
main.cpp
|
||||
)
|
||||
ENDIF()
|
||||
ELSE (USE_GLUT)
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppCollisionInterfaceDemo
|
||||
WIN32
|
||||
CollisionInterfaceDemo.cpp
|
||||
CollisionInterfaceDemo.h
|
||||
Win32CollisionInterfaceDemo.cpp
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ENDIF (USE_GLUT)
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppCollisionInterfaceDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppCollisionInterfaceDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppCollisionInterfaceDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,292 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
///
|
||||
/// CollisionInterfaceDemo shows high level usage of the Collision Detection.
|
||||
///
|
||||
#define TEST_NOT_ADDING_OBJECTS_TO_WORLD
|
||||
|
||||
#include "GL_Simplex1to4.h"
|
||||
|
||||
//include common Bullet Collision Detection headerfiles
|
||||
#include "btBulletCollisionCommon.h"
|
||||
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "CollisionInterfaceDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
btScalar yaw=0.f,pitch=0.f,roll=0.f;
|
||||
const int maxNumObjects = 4;
|
||||
const int numObjects = 2;
|
||||
|
||||
GL_Simplex1to4 simplex;
|
||||
|
||||
btCollisionObject objects[maxNumObjects];
|
||||
btCollisionWorld* collisionWorld = 0;
|
||||
|
||||
GLDebugDrawer debugDrawer;
|
||||
|
||||
|
||||
void CollisionInterfaceDemo::initPhysics()
|
||||
{
|
||||
|
||||
m_debugMode |= btIDebugDraw::DBG_DrawWireframe;
|
||||
|
||||
btMatrix3x3 basisA;
|
||||
basisA.setIdentity();
|
||||
|
||||
btMatrix3x3 basisB;
|
||||
basisB.setIdentity();
|
||||
|
||||
objects[0].getWorldTransform().setBasis(basisA);
|
||||
objects[1].getWorldTransform().setBasis(basisB);
|
||||
|
||||
btBoxShape* boxA = new btBoxShape(btVector3(1,1,1));
|
||||
boxA->setMargin(0.f);
|
||||
|
||||
btBoxShape* boxB = new btBoxShape(btVector3(0.5,0.5,0.5));
|
||||
boxB->setMargin(0.f);
|
||||
//ConvexHullShape hullA(points0,3);
|
||||
//hullA.setLocalScaling(btVector3(3,3,3));
|
||||
//ConvexHullShape hullB(points1,4);
|
||||
//hullB.setLocalScaling(btVector3(4,4,4));
|
||||
|
||||
objects[0].setCollisionShape(boxA);//&hullA;
|
||||
objects[1].setCollisionShape(boxB);//&hullB;
|
||||
|
||||
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
|
||||
btVector3 worldAabbMin(-1000,-1000,-1000);
|
||||
btVector3 worldAabbMax(1000,1000,1000);
|
||||
|
||||
btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
|
||||
|
||||
//SimpleBroadphase is a brute force alternative, performing N^2 aabb overlap tests
|
||||
//SimpleBroadphase* broadphase = new btSimpleBroadphase;
|
||||
|
||||
collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);
|
||||
collisionWorld->setDebugDrawer(&debugDrawer);
|
||||
|
||||
#ifdef TEST_NOT_ADDING_OBJECTS_TO_WORLD
|
||||
// collisionWorld->addCollisionObject(&objects[0]);
|
||||
collisionWorld->addCollisionObject(&objects[1]);
|
||||
#endif //TEST_NOT_ADDING_OBJECTS_TO_WORLD
|
||||
|
||||
}
|
||||
|
||||
|
||||
//to be implemented by the demo
|
||||
|
||||
void CollisionInterfaceDemo::clientMoveAndDisplay()
|
||||
{
|
||||
|
||||
displayCallback();
|
||||
}
|
||||
|
||||
|
||||
static btVoronoiSimplexSolver sGjkSimplexSolver;
|
||||
btSimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
|
||||
|
||||
struct btDrawingResult : public btCollisionWorld::ContactResultCallback
|
||||
{
|
||||
virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1)
|
||||
{
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(0, 0, 0);
|
||||
|
||||
btVector3 ptA = cp.getPositionWorldOnA();
|
||||
btVector3 ptB = cp.getPositionWorldOnB();
|
||||
|
||||
glVertex3d(ptA.x(),ptA.y(),ptA.z());
|
||||
glVertex3d(ptB.x(),ptB.y(),ptB.z());
|
||||
glEnd();
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
void CollisionInterfaceDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
btScalar m[16];
|
||||
|
||||
btVector3 worldBoundsMin,worldBoundsMax;
|
||||
collisionWorld->getBroadphase()->getBroadphaseAabb(worldBoundsMin,worldBoundsMax);
|
||||
|
||||
|
||||
int i;
|
||||
for (i=0;i<numObjects;i++)
|
||||
{
|
||||
|
||||
objects[i].getWorldTransform().getOpenGLMatrix( m );
|
||||
m_shapeDrawer->drawOpenGL(m,objects[i].getCollisionShape(),btVector3(1,1,1),getDebugMode(),worldBoundsMin,worldBoundsMax);
|
||||
}
|
||||
|
||||
collisionWorld->getDispatchInfo().m_debugDraw = &debugDrawer;
|
||||
|
||||
if (collisionWorld)
|
||||
collisionWorld->performDiscreteCollisionDetection();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef TEST_NOT_ADDING_OBJECTS_TO_WORLD
|
||||
|
||||
collisionWorld->debugDrawWorld();
|
||||
///one way to draw all the contact points is iterating over contact manifolds in the dispatcher:
|
||||
|
||||
int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
|
||||
for (i=0;i<numManifolds;i++)
|
||||
{
|
||||
btPersistentManifold* contactManifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
|
||||
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
|
||||
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
|
||||
|
||||
int numContacts = contactManifold->getNumContacts();
|
||||
for (int j=0;j<numContacts;j++)
|
||||
{
|
||||
btManifoldPoint& pt = contactManifold->getContactPoint(j);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(0, 0, 0);
|
||||
|
||||
btVector3 ptA = pt.getPositionWorldOnA();
|
||||
btVector3 ptB = pt.getPositionWorldOnB();
|
||||
|
||||
glVertex3d(ptA.x(),ptA.y(),ptA.z());
|
||||
glVertex3d(ptB.x(),ptB.y(),ptB.z());
|
||||
glEnd();
|
||||
}
|
||||
|
||||
//you can un-comment out this line, and then all points are removed
|
||||
//contactManifold->clearManifold();
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
for (i=0;i<numObjects;i++)
|
||||
{
|
||||
collisionWorld->debugDrawObject(objects[i].getWorldTransform(),objects[i].getCollisionShape(), btVector3(1,1,0));
|
||||
}
|
||||
|
||||
btDrawingResult renderCallback;
|
||||
|
||||
//collisionWorld->contactPairTest(&objects[0],&objects[1], renderCallback);
|
||||
collisionWorld->contactTest(&objects[0],renderCallback);
|
||||
|
||||
#if 0
|
||||
|
||||
//another way is to directly query the dispatcher for both objects. The objects don't need to be inserted into the world
|
||||
|
||||
btCollisionAlgorithm* algo = collisionWorld->getDispatcher()->findAlgorithm(&objects[0],&objects[1]);
|
||||
btManifoldResult contactPointResult(&objects[0],&objects[1]);
|
||||
algo->processCollision(&objects[0],&objects[1],collisionWorld->getDispatchInfo(),&contactPointResult);
|
||||
|
||||
btManifoldArray manifoldArray;
|
||||
algo->getAllContactManifolds(manifoldArray);
|
||||
|
||||
int numManifolds = manifoldArray.size();
|
||||
for (i=0;i<numManifolds;i++)
|
||||
{
|
||||
btPersistentManifold* contactManifold = manifoldArray[i];
|
||||
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
|
||||
// btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
int numContacts = contactManifold->getNumContacts();
|
||||
bool swap = obA == &objects[0];
|
||||
|
||||
for (int j=0;j<numContacts;j++)
|
||||
{
|
||||
btManifoldPoint& pt = contactManifold->getContactPoint(j);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(0, 0, 0);
|
||||
|
||||
btVector3 ptA = swap ?pt.getPositionWorldOnA():pt.getPositionWorldOnB();
|
||||
btVector3 ptB = swap ? pt.getPositionWorldOnB():pt.getPositionWorldOnA();
|
||||
|
||||
glVertex3d(ptA.x(),ptA.y(),ptA.z());
|
||||
glVertex3d(ptB.x(),ptB.y(),ptB.z());
|
||||
glEnd();
|
||||
}
|
||||
|
||||
//you can un-comment out this line, and then all points are removed
|
||||
//contactManifold->clearManifold();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//GL_ShapeDrawer::drawCoordSystem();
|
||||
|
||||
|
||||
// btQuaternion qA = objects[0].getWorldTransform().getRotation();
|
||||
// btQuaternion qB = objects[1].getWorldTransform().getRotation();
|
||||
|
||||
|
||||
if (!m_idle)
|
||||
{
|
||||
|
||||
|
||||
btScalar timeInSeconds = getDeltaTimeMicroseconds()/1000.f;
|
||||
|
||||
btQuaternion orn;
|
||||
|
||||
objects[0].getWorldTransform().getBasis().getEulerYPR(yaw,pitch,roll);
|
||||
pitch += 0.00005f*timeInSeconds;
|
||||
yaw += 0.0001f*timeInSeconds;
|
||||
objects[0].getWorldTransform().getBasis().setEulerYPR(yaw,pitch,roll);
|
||||
|
||||
orn.setEuler(yaw,pitch,roll);
|
||||
objects[1].getWorldTransform().setOrigin(objects[1].getWorldTransform().getOrigin()+btVector3(0,-0.00001*timeInSeconds,0));
|
||||
|
||||
//objects[0].getWorldTransform().setRotation(orn);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
glFlush();
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
void CollisionInterfaceDemo::clientResetScene()
|
||||
{
|
||||
objects[0].getWorldTransform().setOrigin(btVector3(0.0f,3.f,0.f));
|
||||
|
||||
btQuaternion rotA(0.739f,-0.204f,0.587f,0.257f);
|
||||
rotA.normalize();
|
||||
|
||||
objects[0].getWorldTransform().setRotation(rotA);
|
||||
|
||||
objects[1].getWorldTransform().setOrigin(btVector3(0.0f,4.248f,0.f));
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 COLLISION_INTERFACE_DEMO_H
|
||||
#define COLLISION_INTERFACE_DEMO_H
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
///CollisionInterfaceDemo shows how to use the collision detection without dynamics (btCollisionWorld/CollisionObject)
|
||||
class CollisionInterfaceDemo : public PlatformDemoApplication
|
||||
{
|
||||
public:
|
||||
|
||||
void initPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
};
|
||||
|
||||
#endif //COLLISION_INTERFACE_DEMO_H
|
||||
|
@ -1,25 +0,0 @@
|
||||
#ifdef _WINDOWS
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "CollisionInterfaceDemo.h"
|
||||
|
||||
///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo
|
||||
DemoApplication* createDemo()
|
||||
{
|
||||
return new CollisionInterfaceDemo();
|
||||
}
|
||||
|
||||
#endif
|
@ -1,19 +0,0 @@
|
||||
|
||||
#include "CollisionInterfaceDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
int screenWidth = 640;
|
||||
int screenHeight = 480;
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
CollisionInterfaceDemo* collisionInterfaceDemo = new CollisionInterfaceDemo();
|
||||
|
||||
collisionInterfaceDemo->initPhysics();
|
||||
|
||||
collisionInterfaceDemo->clientResetScene();
|
||||
|
||||
return glutmain(argc, argv,screenWidth,screenHeight,"Collision Interface Demo",collisionInterfaceDemo);
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppConcaveConvexCastDemo
|
||||
ConcaveConvexcastDemo.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppConcaveConvexCastDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppConcaveConvexCastDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppConcaveConvexCastDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,516 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "ConcaveConvexcastDemo.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
#define NUM_DYNAMIC_BOXES_X 30
|
||||
#define NUM_DYNAMIC_BOXES_Y 30
|
||||
|
||||
static btVector3* gVertices=0;
|
||||
static int* gIndices=0;
|
||||
static btBvhTriangleMeshShape* trimeshShape =0;
|
||||
static btRigidBody* staticBody = 0;
|
||||
static float waveheight = 5.f;
|
||||
|
||||
const float TRIANGLE_SIZE=8.f;
|
||||
|
||||
|
||||
/* Scrolls back and forth over terrain */
|
||||
#define NUMRAYS_IN_BAR 100
|
||||
class btConvexcastBatch
|
||||
{
|
||||
public:
|
||||
btVector3 source[NUMRAYS_IN_BAR];
|
||||
btVector3 dest[NUMRAYS_IN_BAR];
|
||||
btVector3 direction[NUMRAYS_IN_BAR];
|
||||
btVector3 hit_com[NUMRAYS_IN_BAR];
|
||||
btVector3 hit_surface[NUMRAYS_IN_BAR];
|
||||
btScalar hit_fraction[NUMRAYS_IN_BAR];
|
||||
btVector3 normal[NUMRAYS_IN_BAR];
|
||||
|
||||
int frame_counter;
|
||||
int ms;
|
||||
int sum_ms;
|
||||
int sum_ms_samples;
|
||||
int min_ms;
|
||||
int max_ms;
|
||||
|
||||
#ifdef USE_BT_CLOCK
|
||||
btClock frame_timer;
|
||||
#endif //USE_BT_CLOCK
|
||||
|
||||
btScalar dx;
|
||||
btScalar min_x;
|
||||
btScalar max_x;
|
||||
btScalar min_y;
|
||||
btScalar max_y;
|
||||
btScalar sign;
|
||||
|
||||
btVector3 boxShapeHalfExtents;
|
||||
btBoxShape boxShape;
|
||||
|
||||
btConvexcastBatch () : boxShape(btVector3(0.0, 0.0, 0.0))
|
||||
{
|
||||
ms = 0;
|
||||
max_ms = 0;
|
||||
min_ms = 9999.0;
|
||||
sum_ms_samples = 0;
|
||||
sum_ms = 0;
|
||||
}
|
||||
|
||||
btConvexcastBatch (bool unused, btScalar ray_length, btScalar min_z, btScalar max_z, btScalar min_y , btScalar max_y ) : boxShape(btVector3(0.0, 0.0, 0.0))
|
||||
{
|
||||
boxShapeHalfExtents = btVector3(1.0, 1.0, 1.0);
|
||||
boxShape = btBoxShape(boxShapeHalfExtents);
|
||||
frame_counter = 0;
|
||||
ms = 0;
|
||||
max_ms = 0;
|
||||
min_ms = 9999.0;
|
||||
sum_ms_samples = 0;
|
||||
sum_ms = 0;
|
||||
dx = 10.0;
|
||||
min_x = -40;
|
||||
max_x = 20;
|
||||
this->min_y = min_y;
|
||||
this->max_y = max_y;
|
||||
sign = 1.0;
|
||||
// btScalar dalpha = 2*SIMD_2_PI/NUMRAYS_IN_BAR;
|
||||
for (int i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
btScalar z = (max_z-min_z)/NUMRAYS_IN_BAR * i + min_z;
|
||||
source[i] = btVector3(min_x, max_y, z);
|
||||
dest[i] = btVector3(min_x + ray_length, min_y, z);
|
||||
normal[i] = btVector3(1.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
btConvexcastBatch (btScalar ray_length, btScalar z, btScalar min_y = -1000, btScalar max_y = 10) : boxShape(btVector3(0.0, 0.0, 0.0))
|
||||
{
|
||||
boxShapeHalfExtents = btVector3(1.0, 1.0, 1.0);
|
||||
boxShape = btBoxShape(boxShapeHalfExtents);
|
||||
frame_counter = 0;
|
||||
ms = 0;
|
||||
max_ms = 0;
|
||||
min_ms = 9999.0;
|
||||
sum_ms_samples = 0;
|
||||
sum_ms = 0;
|
||||
dx = 10.0;
|
||||
min_x = -40;
|
||||
max_x = 20;
|
||||
this->min_y = min_y;
|
||||
this->max_y = max_y;
|
||||
sign = 1.0;
|
||||
btScalar dalpha = btScalar(2)*SIMD_2_PI/btScalar(NUMRAYS_IN_BAR);
|
||||
for (int i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
btScalar alpha = dalpha * btScalar(i);
|
||||
// rotate around by alpha degrees y
|
||||
btTransform tr(btQuaternion(btVector3(0.0, 1.0, 0.0), alpha));
|
||||
direction[i] = btVector3(1.0, 0.0, 0.0);
|
||||
direction[i] = tr * direction[i];
|
||||
source[i] = btVector3(min_x, max_y, z);
|
||||
dest[i] = source[i] + direction[i] * ray_length;
|
||||
dest[i][1] = min_y;
|
||||
normal[i] = btVector3(1.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
void move (btScalar dt)
|
||||
{
|
||||
if (dt > (1.0/60.0))
|
||||
dt = 1.0/60.0;
|
||||
for (int i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
source[i][0] += dx * dt * sign;
|
||||
dest[i][0] += dx * dt * sign;
|
||||
}
|
||||
if (source[0][0] < min_x)
|
||||
sign = 1.0;
|
||||
else if (source[0][0] > max_x)
|
||||
sign = -1.0;
|
||||
}
|
||||
|
||||
void cast (btCollisionWorld* cw)
|
||||
{
|
||||
#ifdef USE_BT_CLOCK
|
||||
frame_timer.reset ();
|
||||
#endif //USE_BT_CLOCK
|
||||
for (int i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
btCollisionWorld::ClosestConvexResultCallback cb(source[i], dest[i]);
|
||||
btQuaternion qFrom;
|
||||
btQuaternion qTo;
|
||||
qFrom.setRotation (btVector3(1.0, 0.0, 0.0), 0.0);
|
||||
qTo.setRotation (btVector3(1.0, 0.0, 0.0), 0.7);
|
||||
btTransform from(qFrom, source[i]);
|
||||
btTransform to(qTo, dest[i]);
|
||||
cw->convexSweepTest (&boxShape, from, to, cb);
|
||||
if (cb.hasHit ())
|
||||
{
|
||||
hit_surface[i] = cb.m_hitPointWorld;
|
||||
hit_com[i].setInterpolate3(source[i], dest[i], cb.m_closestHitFraction);
|
||||
hit_fraction[i] = cb.m_closestHitFraction;
|
||||
normal[i] = cb.m_hitNormalWorld;
|
||||
normal[i].normalize ();
|
||||
} else {
|
||||
hit_com[i] = dest[i];
|
||||
hit_surface[i] = dest[i];
|
||||
hit_fraction[i] = 1.0f;
|
||||
normal[i] = btVector3(1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
}
|
||||
#ifdef USE_BT_CLOCK
|
||||
ms += frame_timer.getTimeMilliseconds ();
|
||||
#endif //USE_BT_CLOCK
|
||||
frame_counter++;
|
||||
if (frame_counter > 50)
|
||||
{
|
||||
min_ms = ms < min_ms ? ms : min_ms;
|
||||
max_ms = ms > max_ms ? ms : max_ms;
|
||||
sum_ms += ms;
|
||||
sum_ms_samples++;
|
||||
btScalar mean_ms = (btScalar)sum_ms/(btScalar)sum_ms_samples;
|
||||
printf("%d rays in %d ms %d %d %f\n", NUMRAYS_IN_BAR * frame_counter, ms, min_ms, max_ms, mean_ms);
|
||||
ms = 0;
|
||||
frame_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawCube (const btTransform& T)
|
||||
{
|
||||
ATTRIBUTE_ALIGNED16(btScalar) m[16];
|
||||
T.getOpenGLMatrix (&m[0]);
|
||||
glPushMatrix ();
|
||||
#ifdef BT_USE_DOUBLE_PRECISION
|
||||
glMultMatrixd (&m[0]);
|
||||
glScaled (2.0 * boxShapeHalfExtents[0], 2.0 * boxShapeHalfExtents[1], 2.0 * boxShapeHalfExtents[2]);
|
||||
#else
|
||||
glMultMatrixf (&m[0]);
|
||||
glScalef (2.0 * boxShapeHalfExtents[0], 2.0 * boxShapeHalfExtents[1], 2.0 * boxShapeHalfExtents[2]);
|
||||
#endif //BT_USE_DOUBLE_PRECISION
|
||||
glutSolidCube (1.0);
|
||||
glPopMatrix ();
|
||||
}
|
||||
|
||||
void draw ()
|
||||
{
|
||||
glDisable (GL_LIGHTING);
|
||||
glColor3f (0.0, 1.0, 0.0);
|
||||
glBegin (GL_LINES);
|
||||
int i;
|
||||
for (i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
glVertex3f (source[i][0], source[i][1], source[i][2]);
|
||||
glVertex3f (hit_com[i][0], hit_com[i][1], hit_com[i][2]);
|
||||
}
|
||||
glColor3f (1.0, 1.0, 1.0);
|
||||
glBegin (GL_LINES);
|
||||
btScalar normal_scale = 10.0; // easier to see if this is big
|
||||
for (i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
glVertex3f (hit_surface[i][0], hit_surface[i][1], hit_surface[i][2]);
|
||||
glVertex3f (hit_surface[i][0] + normal_scale * normal[i][0], hit_surface[i][1] + normal_scale * normal[i][1], hit_surface[i][2] + normal_scale * normal[i][2]);
|
||||
}
|
||||
glEnd ();
|
||||
glColor3f (0.0, 1.0, 1.0);
|
||||
btQuaternion qFrom;
|
||||
btQuaternion qTo;
|
||||
qFrom.setRotation (btVector3(1.0, 0.0, 0.0), 0.0);
|
||||
qTo.setRotation (btVector3(1.0, 0.0, 0.0), 0.7);
|
||||
for ( i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
btTransform from(qFrom, source[i]);
|
||||
btTransform to(qTo, dest[i]);
|
||||
btVector3 linVel, angVel;
|
||||
btTransformUtil::calculateVelocity (from, to, 1.0, linVel, angVel);
|
||||
btTransform T;
|
||||
btTransformUtil::integrateTransform (from, linVel, angVel, hit_fraction[i], T);
|
||||
drawCube (T);
|
||||
}
|
||||
glEnable (GL_LIGHTING);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static btConvexcastBatch convexcastBatch;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const int NUM_VERTS_X = 30;
|
||||
const int NUM_VERTS_Y = 30;
|
||||
const int totalVerts = NUM_VERTS_X*NUM_VERTS_Y;
|
||||
|
||||
void ConcaveConvexcastDemo::setVertexPositions(float waveheight, float offset)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for ( i=0;i<NUM_VERTS_X;i++)
|
||||
{
|
||||
for (j=0;j<NUM_VERTS_Y;j++)
|
||||
{
|
||||
gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
|
||||
//0.f,
|
||||
waveheight*sinf((float)i+offset)*cosf((float)j+offset),
|
||||
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConcaveConvexcastDemo::keyboardCallback(unsigned char key, int x, int y)
|
||||
{
|
||||
if (key == 'g')
|
||||
{
|
||||
m_animatedMesh = !m_animatedMesh;
|
||||
if (m_animatedMesh)
|
||||
{
|
||||
staticBody->setCollisionFlags( staticBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
staticBody->setActivationState(DISABLE_DEACTIVATION);
|
||||
} else
|
||||
{
|
||||
staticBody->setCollisionFlags( staticBody->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
staticBody->forceActivationState(ACTIVE_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
DemoApplication::keyboardCallback(key,x,y);
|
||||
|
||||
}
|
||||
|
||||
void ConcaveConvexcastDemo::initPhysics()
|
||||
{
|
||||
#define TRISIZE 10.f
|
||||
|
||||
setCameraDistance(100.f);
|
||||
|
||||
|
||||
int vertStride = sizeof(btVector3);
|
||||
int indexStride = 3*sizeof(int);
|
||||
|
||||
|
||||
const int totalTriangles = 2*(NUM_VERTS_X-1)*(NUM_VERTS_Y-1);
|
||||
|
||||
gVertices = new btVector3[totalVerts];
|
||||
gIndices = new int[totalTriangles*3];
|
||||
|
||||
int i;
|
||||
|
||||
|
||||
setVertexPositions(waveheight,0.f);
|
||||
|
||||
int index=0;
|
||||
for ( i=0;i<NUM_VERTS_X-1;i++)
|
||||
{
|
||||
for (int j=0;j<NUM_VERTS_Y-1;j++)
|
||||
{
|
||||
gIndices[index++] = j*NUM_VERTS_X+i;
|
||||
gIndices[index++] = j*NUM_VERTS_X+i+1;
|
||||
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
|
||||
|
||||
gIndices[index++] = j*NUM_VERTS_X+i;
|
||||
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
|
||||
gIndices[index++] = (j+1)*NUM_VERTS_X+i;
|
||||
}
|
||||
}
|
||||
|
||||
m_indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles,
|
||||
gIndices,
|
||||
indexStride,
|
||||
totalVerts,(btScalar*) &gVertices[0].x(),vertStride);
|
||||
|
||||
bool useQuantizedAabbCompression = true;
|
||||
|
||||
trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression);
|
||||
|
||||
m_collisionShapes.push_back(trimeshShape);
|
||||
|
||||
btCollisionShape* groundShape = trimeshShape;
|
||||
|
||||
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
|
||||
btVector3 worldMin(-1000,-1000,-1000);
|
||||
btVector3 worldMax(1000,1000,1000);
|
||||
m_broadphase = new btAxisSweep3(worldMin,worldMax);
|
||||
m_solver = new btSequentialImpulseConstraintSolver();
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
|
||||
float mass = 0.f;
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-2,0));
|
||||
|
||||
btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
|
||||
m_collisionShapes.push_back(colShape);
|
||||
|
||||
{
|
||||
for (int j=0;j<NUM_DYNAMIC_BOXES_X;j++)
|
||||
for (int i=0;i<NUM_DYNAMIC_BOXES_Y;i++)
|
||||
{
|
||||
//btCollisionShape* colShape = new btCapsuleShape(0.5,2.0);//boxShape = new btSphereShape(1.f);
|
||||
startTransform.setOrigin(btVector3(5*(i-NUM_DYNAMIC_BOXES_X/2),10,5*(j-NUM_DYNAMIC_BOXES_Y/2)));
|
||||
localCreateRigidBody(1, startTransform,colShape);
|
||||
}
|
||||
}
|
||||
|
||||
startTransform.setIdentity();
|
||||
//startTransform = btTransform(btQuaternion (btVector3(1,1,1), 1.5));
|
||||
staticBody = localCreateRigidBody(mass, startTransform,groundShape);
|
||||
|
||||
staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
|
||||
|
||||
//enable custom material callback
|
||||
staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
|
||||
|
||||
convexcastBatch = btConvexcastBatch (40.0, 0.0, -10.0,80.0);
|
||||
//convexcastBatch = btConvexcastBatch (true, 40.0, -50.0, 50.0);
|
||||
}
|
||||
|
||||
void ConcaveConvexcastDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
float dt = getDeltaTimeMicroseconds() * 0.000001f;
|
||||
|
||||
if (m_animatedMesh)
|
||||
{
|
||||
static float offset=0.f;
|
||||
offset+=0.01f;
|
||||
|
||||
|
||||
|
||||
int i;
|
||||
int j;
|
||||
btVector3 aabbMin(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
|
||||
btVector3 aabbMax(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
|
||||
|
||||
for ( i=NUM_VERTS_X/2-3;i<NUM_VERTS_X/2+2;i++)
|
||||
{
|
||||
for (j=NUM_VERTS_X/2-3;j<NUM_VERTS_Y/2+2;j++)
|
||||
{
|
||||
|
||||
aabbMax.setMax(gVertices[i+j*NUM_VERTS_X]);
|
||||
aabbMin.setMin(gVertices[i+j*NUM_VERTS_X]);
|
||||
|
||||
gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
|
||||
//0.f,
|
||||
waveheight*sinf((float)i+offset)*cosf((float)j+offset),
|
||||
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
|
||||
|
||||
aabbMin.setMin(gVertices[i+j*NUM_VERTS_X]);
|
||||
aabbMax.setMax(gVertices[i+j*NUM_VERTS_X]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
trimeshShape->partialRefitTree(aabbMin,aabbMax);
|
||||
|
||||
|
||||
//clear all contact points involving mesh proxy. Note: this is a slow/unoptimized operation.
|
||||
m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(staticBody->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher());
|
||||
}
|
||||
|
||||
m_dynamicsWorld->stepSimulation(dt);
|
||||
|
||||
//optional but useful: debug drawing
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
convexcastBatch.move (dt);
|
||||
convexcastBatch.cast (m_dynamicsWorld);
|
||||
renderme();
|
||||
convexcastBatch.draw ();
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ConcaveConvexcastDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
renderme();
|
||||
convexcastBatch.draw ();
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConcaveConvexcastDemo::exitPhysics()
|
||||
{
|
||||
|
||||
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
if (m_indexVertexArrays)
|
||||
delete m_indexVertexArrays;
|
||||
|
||||
//delete solver
|
||||
delete m_solver;
|
||||
|
||||
//delete broadphase
|
||||
delete m_broadphase;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 CONCAVE_CONVEXCAST_DEMO_H
|
||||
#define CONCAVE_CONVEXCAST_DEMO_H
|
||||
|
||||
#include "GlutDemoApplication.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
class btTriangleIndexVertexArray;
|
||||
|
||||
///ConcaveRaycaseDemo shows usage of static concave triangle meshes
|
||||
///It also shows per-triangle material (friction/restitution) through CustomMaterialCombinerCallback
|
||||
class ConcaveConvexcastDemo : public GlutDemoApplication
|
||||
{
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btTriangleIndexVertexArray* m_indexVertexArrays;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
bool m_animatedMesh;
|
||||
|
||||
public:
|
||||
|
||||
ConcaveConvexcastDemo() : m_animatedMesh(true)
|
||||
{
|
||||
|
||||
}
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual ~ConcaveConvexcastDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
//to show refit works
|
||||
void setVertexPositions(float waveheight, float offset);
|
||||
|
||||
virtual void keyboardCallback(unsigned char key, int x, int y);
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
ConcaveConvexcastDemo* demo = new ConcaveConvexcastDemo();
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
};
|
||||
};
|
||||
|
||||
#endif //CONCAVE_CONVEXCAST_DEMO_H
|
||||
|
@ -1,15 +0,0 @@
|
||||
|
||||
#include "ConcaveConvexcastDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
ConcaveConvexcastDemo* concaveConvexcastDemo = new ConcaveConvexcastDemo();
|
||||
concaveConvexcastDemo->initPhysics();
|
||||
concaveConvexcastDemo->setCameraDistance(30.f);
|
||||
|
||||
return glutmain(argc, argv,640,480,"Concave Convexcast Demo",concaveConvexcastDemo);
|
||||
}
|
||||
|
@ -1,67 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
IF (USE_GLUT)
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
||||
${GLUT_INCLUDE_DIR}
|
||||
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision BulletFileLoader LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppConcaveDemo
|
||||
ConcavePhysicsDemo.cpp
|
||||
main.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppConcaveDemo
|
||||
ConcavePhysicsDemo.cpp
|
||||
main.cpp
|
||||
)
|
||||
ENDIF()
|
||||
ELSE (USE_GLUT)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision BulletFileLoader LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppConcaveDemo
|
||||
WIN32
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
ConcavePhysicsDemo.cpp
|
||||
ConcaveDemo.h
|
||||
Win32ConcaveDemo.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
|
||||
ENDIF (USE_GLUT)
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppConcaveDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppConcaveDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppConcaveDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 CONCAVE_DEMO_H
|
||||
#define CONCAVE_DEMO_H
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
class btTriangleIndexVertexArray;
|
||||
|
||||
///ConcaveDemo shows usage of static concave triangle meshes
|
||||
///It also shows per-triangle material (friction/restitution) through CustomMaterialCombinerCallback
|
||||
class ConcaveDemo : public PlatformDemoApplication
|
||||
{
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btTriangleIndexVertexArray* m_indexVertexArrays;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
bool m_animatedMesh;
|
||||
|
||||
public:
|
||||
|
||||
ConcaveDemo() : m_animatedMesh(true)
|
||||
{
|
||||
|
||||
}
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual ~ConcaveDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
//to show refit works
|
||||
void setVertexPositions(float waveheight, float offset);
|
||||
|
||||
virtual void keyboardCallback(unsigned char key, int x, int y);
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
ConcaveDemo* demo = new ConcaveDemo();
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
};
|
||||
};
|
||||
|
||||
#endif //CONCAVE_DEMO_H
|
||||
|
@ -1,474 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "ConcaveDemo.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
#define SERIALIZE_TO_DISK 1
|
||||
|
||||
#ifndef SERIALIZE_TO_DISK
|
||||
#include "btBulletWorldImporter.h"
|
||||
#endif //SERIALIZE_TO_DISK
|
||||
|
||||
//by default, the sample only (de)serializes the BVH to disk.
|
||||
//If you enable the SERIALIZE_SHAPE define then it will serialize the entire collision shape
|
||||
//then the animation will not play, because it is using the deserialized vertices
|
||||
//#define SERIALIZE_SHAPE
|
||||
|
||||
|
||||
|
||||
|
||||
//#define USE_PARALLEL_DISPATCHER 1
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#include "../../Extras/BulletMultiThreaded/SpuGatheringCollisionDispatcher.h"
|
||||
#include "../../Extras/BulletMultiThreaded/Win32ThreadSupport.h"
|
||||
#include "../../Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h"
|
||||
#endif//USE_PARALLEL_DISPATCHER
|
||||
|
||||
|
||||
|
||||
|
||||
static btVector3* gVertices=0;
|
||||
static int* gIndices=0;
|
||||
static btBvhTriangleMeshShape* trimeshShape =0;
|
||||
static btRigidBody* staticBody = 0;
|
||||
static float waveheight = 5.f;
|
||||
|
||||
const float TRIANGLE_SIZE=8.f;
|
||||
|
||||
|
||||
|
||||
///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= btCollisionObject::customMaterialCallback;
|
||||
inline btScalar calculateCombinedFriction(float friction0,float friction1)
|
||||
{
|
||||
btScalar friction = friction0 * friction1;
|
||||
|
||||
const btScalar MAX_FRICTION = 10.f;
|
||||
if (friction < -MAX_FRICTION)
|
||||
friction = -MAX_FRICTION;
|
||||
if (friction > MAX_FRICTION)
|
||||
friction = MAX_FRICTION;
|
||||
return friction;
|
||||
|
||||
}
|
||||
|
||||
inline btScalar calculateCombinedRestitution(float restitution0,float restitution1)
|
||||
{
|
||||
return restitution0 * restitution1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static bool CustomMaterialCombinerCallback(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1)
|
||||
{
|
||||
|
||||
float friction0 = colObj0Wrap->getCollisionObject()->getFriction();
|
||||
float friction1 = colObj1Wrap->getCollisionObject()->getFriction();
|
||||
float restitution0 = colObj0Wrap->getCollisionObject()->getRestitution();
|
||||
float restitution1 = colObj1Wrap->getCollisionObject()->getRestitution();
|
||||
|
||||
if (colObj0Wrap->getCollisionObject()->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)
|
||||
{
|
||||
friction0 = 1.0;//partId0,index0
|
||||
restitution0 = 0.f;
|
||||
}
|
||||
if (colObj1Wrap->getCollisionObject()->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)
|
||||
{
|
||||
if (index1&1)
|
||||
{
|
||||
friction1 = 1.0f;//partId1,index1
|
||||
} else
|
||||
{
|
||||
friction1 = 0.f;
|
||||
}
|
||||
restitution1 = 0.f;
|
||||
}
|
||||
|
||||
cp.m_combinedFriction = calculateCombinedFriction(friction0,friction1);
|
||||
cp.m_combinedRestitution = calculateCombinedRestitution(restitution0,restitution1);
|
||||
|
||||
//this return value is currently ignored, but to be on the safe side: return false if you don't calculate friction
|
||||
return true;
|
||||
}
|
||||
|
||||
extern ContactAddedCallback gContactAddedCallback;
|
||||
|
||||
const int NUM_VERTS_X = 30;
|
||||
const int NUM_VERTS_Y = 30;
|
||||
const int totalVerts = NUM_VERTS_X*NUM_VERTS_Y;
|
||||
|
||||
void ConcaveDemo::setVertexPositions(float waveheight, float offset)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for ( i=0;i<NUM_VERTS_X;i++)
|
||||
{
|
||||
for (j=0;j<NUM_VERTS_Y;j++)
|
||||
{
|
||||
gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
|
||||
//0.f,
|
||||
waveheight*sinf((float)i+offset)*cosf((float)j+offset),
|
||||
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConcaveDemo::keyboardCallback(unsigned char key, int x, int y)
|
||||
{
|
||||
if (key == 'g')
|
||||
{
|
||||
m_animatedMesh = !m_animatedMesh;
|
||||
if (m_animatedMesh)
|
||||
{
|
||||
staticBody->setCollisionFlags( staticBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
staticBody->setActivationState(DISABLE_DEACTIVATION);
|
||||
} else
|
||||
{
|
||||
staticBody->setCollisionFlags( staticBody->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
staticBody->forceActivationState(ACTIVE_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
DemoApplication::keyboardCallback(key,x,y);
|
||||
|
||||
}
|
||||
|
||||
void ConcaveDemo::initPhysics()
|
||||
{
|
||||
|
||||
setTexturing(true);
|
||||
setShadows(false);//true);
|
||||
|
||||
#define TRISIZE 10.f
|
||||
|
||||
gContactAddedCallback = CustomMaterialCombinerCallback;
|
||||
|
||||
#define USE_TRIMESH_SHAPE 1
|
||||
#ifdef USE_TRIMESH_SHAPE
|
||||
|
||||
int vertStride = sizeof(btVector3);
|
||||
int indexStride = 3*sizeof(int);
|
||||
|
||||
|
||||
const int totalTriangles = 2*(NUM_VERTS_X-1)*(NUM_VERTS_Y-1);
|
||||
|
||||
gVertices = new btVector3[totalVerts];
|
||||
gIndices = new int[totalTriangles*3];
|
||||
|
||||
int i;
|
||||
|
||||
|
||||
setVertexPositions(waveheight,0.f);
|
||||
|
||||
int index=0;
|
||||
for ( i=0;i<NUM_VERTS_X-1;i++)
|
||||
{
|
||||
for (int j=0;j<NUM_VERTS_Y-1;j++)
|
||||
{
|
||||
gIndices[index++] = j*NUM_VERTS_X+i;
|
||||
gIndices[index++] = j*NUM_VERTS_X+i+1;
|
||||
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
|
||||
|
||||
gIndices[index++] = j*NUM_VERTS_X+i;
|
||||
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
|
||||
gIndices[index++] = (j+1)*NUM_VERTS_X+i;
|
||||
}
|
||||
}
|
||||
|
||||
m_indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles,
|
||||
gIndices,
|
||||
indexStride,
|
||||
totalVerts,(btScalar*) &gVertices[0].x(),vertStride);
|
||||
|
||||
bool useQuantizedAabbCompression = true;
|
||||
|
||||
//comment out the next line to read the BVH from disk (first run the demo once to create the BVH)
|
||||
|
||||
#ifdef SERIALIZE_TO_DISK
|
||||
|
||||
|
||||
btVector3 aabbMin(-1000,-1000,-1000),aabbMax(1000,1000,1000);
|
||||
|
||||
trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,aabbMin,aabbMax);
|
||||
m_collisionShapes.push_back(trimeshShape);
|
||||
|
||||
int maxSerializeBufferSize = 1024*1024*5;
|
||||
btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize);
|
||||
//serializer->setSerializationFlags(BT_SERIALIZE_NO_BVH);// or BT_SERIALIZE_NO_TRIANGLEINFOMAP
|
||||
serializer->startSerialization();
|
||||
//registering a name is optional, it allows you to retrieve the shape by name
|
||||
//serializer->registerNameForPointer(trimeshShape,"mymesh");
|
||||
#ifdef SERIALIZE_SHAPE
|
||||
trimeshShape->serializeSingleShape(serializer);
|
||||
#else
|
||||
trimeshShape->serializeSingleBvh(serializer);
|
||||
#endif
|
||||
serializer->finishSerialization();
|
||||
FILE* f2 = fopen("myShape.bullet","wb");
|
||||
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1,f2);
|
||||
fclose(f2);
|
||||
|
||||
#else
|
||||
btBulletWorldImporter import(0);//don't store info into the world
|
||||
if (import.loadFile("myShape.bullet"))
|
||||
{
|
||||
int numBvh = import.getNumBvhs();
|
||||
if (numBvh)
|
||||
{
|
||||
btOptimizedBvh* bvh = import.getBvhByIndex(0);
|
||||
btVector3 aabbMin(-1000,-1000,-1000),aabbMax(1000,1000,1000);
|
||||
|
||||
trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,aabbMin,aabbMax,false);
|
||||
trimeshShape->setOptimizedBvh(bvh);
|
||||
//trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,aabbMin,aabbMax);
|
||||
//trimeshShape->setOptimizedBvh(bvh);
|
||||
|
||||
}
|
||||
int numShape = import.getNumCollisionShapes();
|
||||
if (numShape)
|
||||
{
|
||||
trimeshShape = (btBvhTriangleMeshShape*)import.getCollisionShapeByIndex(0);
|
||||
|
||||
//if you know the name, you can also try to get the shape by name:
|
||||
const char* meshName = import.getNameForPointer(trimeshShape);
|
||||
if (meshName)
|
||||
trimeshShape = (btBvhTriangleMeshShape*)import.getCollisionShapeByName(meshName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
btCollisionShape* groundShape = trimeshShape;
|
||||
|
||||
#else
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50));
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
|
||||
#endif //USE_TRIMESH_SHAPE
|
||||
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
|
||||
#ifdef USE_WIN32_THREADING
|
||||
|
||||
int maxNumOutstandingTasks = 4;//number of maximum outstanding tasks
|
||||
Win32ThreadSupport* threadSupport = new Win32ThreadSupport(Win32ThreadSupport::Win32ThreadConstructionInfo(
|
||||
"collision",
|
||||
processCollisionTask,
|
||||
createCollisionLocalStoreMemory,
|
||||
maxNumOutstandingTasks));
|
||||
#else
|
||||
///@todo show other platform threading
|
||||
///Playstation 3 SPU (SPURS) version is available through PS3 Devnet
|
||||
///Libspe2 SPU support will be available soon
|
||||
///pthreads version
|
||||
///you can hook it up to your custom task scheduler by deriving from btThreadSupportInterface
|
||||
#endif
|
||||
|
||||
m_dispatcher = new SpuGatheringCollisionDispatcher(threadSupport,maxNumOutstandingTasks,m_collisionConfiguration);
|
||||
#else
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
#endif//USE_PARALLEL_DISPATCHER
|
||||
|
||||
|
||||
btVector3 worldMin(-1000,-1000,-1000);
|
||||
btVector3 worldMax(1000,1000,1000);
|
||||
m_broadphase = new btAxisSweep3(worldMin,worldMax);
|
||||
m_solver = new btSequentialImpulseConstraintSolver();
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
m_dynamicsWorld->getDispatchInfo().m_enableSPU=true;
|
||||
#endif //USE_PARALLEL_DISPATCHER
|
||||
|
||||
float mass = 0.f;
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-2,0));
|
||||
|
||||
#ifdef USE_BOX_SHAPE
|
||||
btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
|
||||
#else
|
||||
|
||||
btCompoundShape* colShape = new btCompoundShape;
|
||||
btCollisionShape* cylinderShape = new btCylinderShapeX(btVector3(4,1,1));
|
||||
btCollisionShape* boxShape = new btBoxShape(btVector3(4,1,1));
|
||||
btTransform localTransform;
|
||||
localTransform.setIdentity();
|
||||
colShape->addChildShape(localTransform,boxShape);
|
||||
btQuaternion orn(SIMD_HALF_PI,0,0);
|
||||
localTransform.setRotation(orn);
|
||||
colShape->addChildShape(localTransform,cylinderShape);
|
||||
|
||||
#endif //USE_BOX_SHAPE
|
||||
|
||||
|
||||
m_collisionShapes.push_back(colShape);
|
||||
|
||||
{
|
||||
for (int i=0;i<10;i++)
|
||||
{
|
||||
startTransform.setOrigin(btVector3(2,10+i*2,1));
|
||||
localCreateRigidBody(1, startTransform,colShape);
|
||||
}
|
||||
}
|
||||
|
||||
startTransform.setIdentity();
|
||||
staticBody = localCreateRigidBody(mass, startTransform,groundShape);
|
||||
|
||||
staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);//STATIC_OBJECT);
|
||||
|
||||
//enable custom material callback
|
||||
staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ConcaveDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
float dt = getDeltaTimeMicroseconds() * 0.000001f;
|
||||
|
||||
if (m_animatedMesh)
|
||||
{
|
||||
static float offset=0.f;
|
||||
offset+=dt;
|
||||
|
||||
// setVertexPositions(waveheight,offset);
|
||||
|
||||
int i;
|
||||
int j;
|
||||
btVector3 aabbMin(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
|
||||
btVector3 aabbMax(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
|
||||
|
||||
for ( i=NUM_VERTS_X/2-3;i<NUM_VERTS_X/2+2;i++)
|
||||
{
|
||||
for (j=NUM_VERTS_X/2-3;j<NUM_VERTS_Y/2+2;j++)
|
||||
{
|
||||
|
||||
aabbMax.setMax(gVertices[i+j*NUM_VERTS_X]);
|
||||
aabbMin.setMin(gVertices[i+j*NUM_VERTS_X]);
|
||||
|
||||
gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
|
||||
//0.f,
|
||||
waveheight*sinf((float)i+offset)*cosf((float)j+offset),
|
||||
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
|
||||
|
||||
aabbMin.setMin(gVertices[i+j*NUM_VERTS_X]);
|
||||
aabbMax.setMax(gVertices[i+j*NUM_VERTS_X]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
trimeshShape->partialRefitTree(aabbMin,aabbMax);
|
||||
|
||||
//clear all contact points involving mesh proxy. Note: this is a slow/unoptimized operation.
|
||||
m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(staticBody->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher());
|
||||
}
|
||||
|
||||
m_dynamicsWorld->stepSimulation(dt);
|
||||
|
||||
//optional but useful: debug drawing
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
swapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ConcaveDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
renderme();
|
||||
|
||||
//optional but useful: debug drawing
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
|
||||
glFlush();
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConcaveDemo::exitPhysics()
|
||||
{
|
||||
|
||||
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
if (m_indexVertexArrays)
|
||||
delete m_indexVertexArrays;
|
||||
|
||||
//delete solver
|
||||
delete m_solver;
|
||||
|
||||
//delete broadphase
|
||||
delete m_broadphase;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
SubDir TOP Demos ConcaveDemo ;
|
||||
|
||||
BulletDemo ConcaveDemo : [ Wildcard *.h *.cpp ] ;
|
@ -1,25 +0,0 @@
|
||||
#ifdef _WINDOWS
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "ConcaveDemo.h"
|
||||
|
||||
///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo
|
||||
DemoApplication* createDemo()
|
||||
{
|
||||
return new ConcaveDemo();
|
||||
}
|
||||
|
||||
#endif
|
@ -1,19 +0,0 @@
|
||||
|
||||
#include "ConcaveDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
ConcaveDemo* concaveDemo = new ConcaveDemo();
|
||||
concaveDemo->initPhysics();
|
||||
concaveDemo->setCameraDistance(30.f);
|
||||
concaveDemo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
return glutmain(argc, argv,640,480,"Static Concave Mesh Demo",concaveDemo);
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppConcaveRayCastDemo
|
||||
ConcaveRaycastDemo.cpp
|
||||
main.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppConcaveRayCastDemo
|
||||
ConcaveRaycastDemo.cpp
|
||||
main.cpp
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppConcaveRayCastDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppConcaveRayCastDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppConcaveRayCastDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,490 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "ConcaveRaycastDemo.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
static GLDebugDrawer sDebugDraw;
|
||||
|
||||
static btVector3* gVertices=0;
|
||||
static int* gIndices=0;
|
||||
static btBvhTriangleMeshShape* trimeshShape =0;
|
||||
static btRigidBody* staticBody = 0;
|
||||
static float waveheight = 5.f;
|
||||
|
||||
const float TRIANGLE_SIZE=8.f;
|
||||
|
||||
|
||||
/* Scrolls back and forth over terrain */
|
||||
#define NUMRAYS_IN_BAR 100
|
||||
class btRaycastBar
|
||||
{
|
||||
public:
|
||||
btVector3 source[NUMRAYS_IN_BAR];
|
||||
btVector3 dest[NUMRAYS_IN_BAR];
|
||||
btVector3 direction[NUMRAYS_IN_BAR];
|
||||
btVector3 hit[NUMRAYS_IN_BAR];
|
||||
btVector3 normal[NUMRAYS_IN_BAR];
|
||||
|
||||
int frame_counter;
|
||||
int ms;
|
||||
int sum_ms;
|
||||
int sum_ms_samples;
|
||||
int min_ms;
|
||||
int max_ms;
|
||||
|
||||
#ifdef USE_BT_CLOCK
|
||||
btClock frame_timer;
|
||||
#endif //USE_BT_CLOCK
|
||||
|
||||
btScalar dx;
|
||||
btScalar min_x;
|
||||
btScalar max_x;
|
||||
btScalar min_y;
|
||||
btScalar max_y;
|
||||
btScalar sign;
|
||||
|
||||
btRaycastBar ()
|
||||
{
|
||||
ms = 0;
|
||||
max_ms = 0;
|
||||
min_ms = 9999.0;
|
||||
sum_ms_samples = 0;
|
||||
sum_ms = 0;
|
||||
}
|
||||
|
||||
btRaycastBar (bool unused, btScalar ray_length, btScalar min_z, btScalar max_z, btScalar min_y = -10, btScalar max_y = 10)
|
||||
{
|
||||
frame_counter = 0;
|
||||
ms = 0;
|
||||
max_ms = 0;
|
||||
min_ms = 9999.0;
|
||||
sum_ms_samples = 0;
|
||||
sum_ms = 0;
|
||||
dx = 10.0;
|
||||
min_x = -40;
|
||||
max_x = 20;
|
||||
this->min_y = min_y;
|
||||
this->max_y = max_y;
|
||||
sign = 1.0;
|
||||
// btScalar dalpha = 2*SIMD_2_PI/NUMRAYS_IN_BAR;
|
||||
for (int i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
btScalar z = (max_z-min_z)/btScalar(NUMRAYS_IN_BAR) * btScalar(i) + min_z;
|
||||
source[i] = btVector3(min_x, max_y, z);
|
||||
dest[i] = btVector3(min_x + ray_length, min_y, z);
|
||||
normal[i] = btVector3(1.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
btRaycastBar (btScalar ray_length, btScalar z, btScalar min_y = -1000, btScalar max_y = 10)
|
||||
{
|
||||
frame_counter = 0;
|
||||
ms = 0;
|
||||
max_ms = 0;
|
||||
min_ms = 9999.0;
|
||||
sum_ms_samples = 0;
|
||||
sum_ms = 0;
|
||||
dx = 10.0;
|
||||
min_x = -40;
|
||||
max_x = 20;
|
||||
this->min_y = min_y;
|
||||
this->max_y = max_y;
|
||||
sign = 1.0;
|
||||
btScalar dalpha = 2*SIMD_2_PI/NUMRAYS_IN_BAR;
|
||||
for (int i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
btScalar alpha = dalpha * i;
|
||||
// rotate around by alpha degrees y
|
||||
btTransform tr (btQuaternion (btVector3(0.0, 1.0, 0.0), alpha));
|
||||
direction[i] = btVector3(1.0, 0.0, 0.0);
|
||||
direction[i] = tr* direction[i];
|
||||
direction[i] = direction[i] * ray_length;
|
||||
source[i] = btVector3(min_x, max_y, z);
|
||||
dest[i] = source[i] + direction[i];
|
||||
dest[i][1] = min_y;
|
||||
normal[i] = btVector3(1.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
void move (btScalar dt)
|
||||
{
|
||||
if (dt > (1.0/60.0))
|
||||
dt = 1.0/60.0;
|
||||
for (int i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
source[i][0] += dx * dt * sign;
|
||||
dest[i][0] += dx * dt * sign;
|
||||
}
|
||||
if (source[0][0] < min_x)
|
||||
sign = 1.0;
|
||||
else if (source[0][0] > max_x)
|
||||
sign = -1.0;
|
||||
}
|
||||
|
||||
void cast (btCollisionWorld* cw)
|
||||
{
|
||||
#ifdef USE_BT_CLOCK
|
||||
frame_timer.reset ();
|
||||
#endif //USE_BT_CLOCK
|
||||
|
||||
#ifdef BATCH_RAYCASTER
|
||||
if (!gBatchRaycaster)
|
||||
return;
|
||||
|
||||
gBatchRaycaster->clearRays ();
|
||||
for (int i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
gBatchRaycaster->addRay (source[i], dest[i]);
|
||||
}
|
||||
gBatchRaycaster->performBatchRaycast ();
|
||||
for (int i = 0; i < gBatchRaycaster->getNumRays (); i++)
|
||||
{
|
||||
const SpuRaycastTaskWorkUnitOut& out = (*gBatchRaycaster)[i];
|
||||
hit[i].setInterpolate3(source[i],dest[i],out.hitFraction);
|
||||
normal[i] = out.hitNormal;
|
||||
normal[i].normalize ();
|
||||
}
|
||||
#else
|
||||
for (int i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
btCollisionWorld::ClosestRayResultCallback cb(source[i], dest[i]);
|
||||
|
||||
cw->rayTest (source[i], dest[i], cb);
|
||||
if (cb.hasHit ())
|
||||
{
|
||||
hit[i] = cb.m_hitPointWorld;
|
||||
normal[i] = cb.m_hitNormalWorld;
|
||||
normal[i].normalize ();
|
||||
} else {
|
||||
hit[i] = dest[i];
|
||||
normal[i] = btVector3(1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
}
|
||||
#ifdef USE_BT_CLOCK
|
||||
ms += frame_timer.getTimeMilliseconds ();
|
||||
#endif //USE_BT_CLOCK
|
||||
frame_counter++;
|
||||
if (frame_counter > 50)
|
||||
{
|
||||
min_ms = ms < min_ms ? ms : min_ms;
|
||||
max_ms = ms > max_ms ? ms : max_ms;
|
||||
sum_ms += ms;
|
||||
sum_ms_samples++;
|
||||
btScalar mean_ms = (btScalar)sum_ms/(btScalar)sum_ms_samples;
|
||||
printf("%d rays in %d ms %d %d %f\n", NUMRAYS_IN_BAR * frame_counter, ms, min_ms, max_ms, mean_ms);
|
||||
ms = 0;
|
||||
frame_counter = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void draw ()
|
||||
{
|
||||
glDisable (GL_LIGHTING);
|
||||
glColor3f (0.0, 1.0, 0.0);
|
||||
glBegin (GL_LINES);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
glVertex3f (source[i][0], source[i][1], source[i][2]);
|
||||
glVertex3f (hit[i][0], hit[i][1], hit[i][2]);
|
||||
}
|
||||
glEnd ();
|
||||
glColor3f (1.0, 1.0, 1.0);
|
||||
glBegin (GL_LINES);
|
||||
for (i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
glVertex3f (hit[i][0], hit[i][1], hit[i][2]);
|
||||
glVertex3f (hit[i][0] + normal[i][0], hit[i][1] + normal[i][1], hit[i][2] + normal[i][2]);
|
||||
}
|
||||
glEnd ();
|
||||
glColor3f (0.0, 1.0, 1.0);
|
||||
glBegin (GL_POINTS);
|
||||
for ( i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
glVertex3f (hit[i][0], hit[i][1], hit[i][2]);
|
||||
}
|
||||
glEnd ();
|
||||
glEnable (GL_LIGHTING);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static btRaycastBar raycastBar;
|
||||
|
||||
|
||||
const int NUM_VERTS_X = 30;
|
||||
const int NUM_VERTS_Y = 30;
|
||||
const int totalVerts = NUM_VERTS_X*NUM_VERTS_Y;
|
||||
|
||||
void ConcaveRaycastDemo::setVertexPositions(float waveheight, float offset)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for ( i=0;i<NUM_VERTS_X;i++)
|
||||
{
|
||||
for (j=0;j<NUM_VERTS_Y;j++)
|
||||
{
|
||||
gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
|
||||
//0.f,
|
||||
waveheight*sinf((float)i+offset)*cosf((float)j+offset),
|
||||
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConcaveRaycastDemo::keyboardCallback(unsigned char key, int x, int y)
|
||||
{
|
||||
if (key == 'g')
|
||||
{
|
||||
m_animatedMesh = !m_animatedMesh;
|
||||
if (m_animatedMesh)
|
||||
{
|
||||
staticBody->setCollisionFlags( staticBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
staticBody->setActivationState(DISABLE_DEACTIVATION);
|
||||
} else
|
||||
{
|
||||
staticBody->setCollisionFlags( staticBody->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
staticBody->forceActivationState(ACTIVE_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
DemoApplication::keyboardCallback(key,x,y);
|
||||
|
||||
}
|
||||
|
||||
void ConcaveRaycastDemo::initPhysics()
|
||||
{
|
||||
|
||||
#define TRISIZE 10.f
|
||||
|
||||
|
||||
|
||||
int vertStride = sizeof(btVector3);
|
||||
int indexStride = 3*sizeof(int);
|
||||
|
||||
|
||||
const int totalTriangles = 2*(NUM_VERTS_X-1)*(NUM_VERTS_Y-1);
|
||||
|
||||
gVertices = new btVector3[totalVerts];
|
||||
gIndices = new int[totalTriangles*3];
|
||||
|
||||
int i;
|
||||
|
||||
|
||||
setVertexPositions(waveheight,0.f);
|
||||
|
||||
int index=0;
|
||||
for ( i=0;i<NUM_VERTS_X-1;i++)
|
||||
{
|
||||
for (int j=0;j<NUM_VERTS_Y-1;j++)
|
||||
{
|
||||
gIndices[index++] = j*NUM_VERTS_X+i;
|
||||
gIndices[index++] = j*NUM_VERTS_X+i+1;
|
||||
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
|
||||
|
||||
gIndices[index++] = j*NUM_VERTS_X+i;
|
||||
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
|
||||
gIndices[index++] = (j+1)*NUM_VERTS_X+i;
|
||||
}
|
||||
}
|
||||
|
||||
m_indexVertexArrays = new btTriangleIndexVertexArray(totalTriangles,
|
||||
gIndices,
|
||||
indexStride,
|
||||
totalVerts,(btScalar*) &gVertices[0].x(),vertStride);
|
||||
|
||||
bool useQuantizedAabbCompression = true;
|
||||
|
||||
trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression);
|
||||
m_collisionShapes.push_back(trimeshShape);
|
||||
|
||||
btCollisionShape* groundShape = trimeshShape;
|
||||
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
|
||||
|
||||
btVector3 worldMin(-1000,-1000,-1000);
|
||||
btVector3 worldMax(1000,1000,1000);
|
||||
m_broadphase = new btAxisSweep3(worldMin,worldMax);
|
||||
m_solver = new btSequentialImpulseConstraintSolver();
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
m_dynamicsWorld->getSolverInfo().m_splitImpulse=true;
|
||||
m_dynamicsWorld->setDebugDrawer(&sDebugDraw);
|
||||
|
||||
float mass = 0.f;
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-2,0));
|
||||
|
||||
btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
|
||||
m_collisionShapes.push_back(colShape);
|
||||
|
||||
{
|
||||
for (int i=0;i<10;i++)
|
||||
{
|
||||
//btCollisionShape* colShape = new btCapsuleShape(0.5,2.0);//boxShape = new btSphereShape(1.f);
|
||||
startTransform.setOrigin(btVector3(2*i,10,1));
|
||||
localCreateRigidBody(1, startTransform,colShape);
|
||||
}
|
||||
}
|
||||
|
||||
startTransform.setIdentity();
|
||||
staticBody = localCreateRigidBody(mass, startTransform,groundShape);
|
||||
|
||||
staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
|
||||
|
||||
#ifdef BATCH_RAYCASTER
|
||||
int maxNumOutstandingTasks = 4;
|
||||
|
||||
#ifdef USE_WIN32_THREADING
|
||||
Win32ThreadSupport::Win32ThreadConstructionInfo tci("batch raycast",
|
||||
processRaycastTask,
|
||||
createRaycastLocalStoreMemory,
|
||||
maxNumOutstandingTasks);
|
||||
m_threadSupportRaycast = new Win32ThreadSupport(tci);
|
||||
printf("m_threadSupportRaycast = %p\n", m_threadSupportRaycast);
|
||||
#endif
|
||||
|
||||
gBatchRaycaster = new SpuBatchRaycaster (m_threadSupportRaycast, maxNumOutstandingTasks, m_dynamicsWorld->getCollisionObjectArray(), m_dynamicsWorld->getNumCollisionObjects());
|
||||
#endif
|
||||
|
||||
raycastBar = btRaycastBar (4000.0, 0.0);
|
||||
//raycastBar = btRaycastBar (true, 40.0, -50.0, 50.0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ConcaveRaycastDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
float dt = getDeltaTimeMicroseconds() * 0.000001f;
|
||||
|
||||
if (m_animatedMesh)
|
||||
{
|
||||
static float offset=0.f;
|
||||
offset+=0.01f;
|
||||
|
||||
setVertexPositions(waveheight,offset);
|
||||
|
||||
btVector3 worldMin(-1000,-1000,-1000);
|
||||
btVector3 worldMax(1000,1000,1000);
|
||||
|
||||
trimeshShape->refitTree(worldMin,worldMax);
|
||||
|
||||
//clear all contact points involving mesh proxy. Note: this is a slow/unoptimized operation.
|
||||
m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(staticBody->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher());
|
||||
}
|
||||
|
||||
m_dynamicsWorld->stepSimulation(1./60.,0);
|
||||
|
||||
//optional but useful: debug drawing
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
raycastBar.move (dt);
|
||||
raycastBar.cast (m_dynamicsWorld);
|
||||
renderme();
|
||||
raycastBar.draw ();
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ConcaveRaycastDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//optional but useful: debug drawing
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
renderme();
|
||||
raycastBar.draw ();
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConcaveRaycastDemo::exitPhysics()
|
||||
{
|
||||
|
||||
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
if (m_indexVertexArrays)
|
||||
delete m_indexVertexArrays;
|
||||
|
||||
//delete solver
|
||||
delete m_solver;
|
||||
|
||||
//delete broadphase
|
||||
delete m_broadphase;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
delete[] gVertices;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,85 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 CONCAVE_RAYCAST_DEMO_H
|
||||
#define CONCAVE_RAYCAST_DEMO_H
|
||||
|
||||
#include "GlutDemoApplication.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
class btTriangleIndexVertexArray;
|
||||
|
||||
///ConcaveRaycastDemo shows usage of static concave triangle meshes
|
||||
class ConcaveRaycastDemo : public GlutDemoApplication
|
||||
{
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btTriangleIndexVertexArray* m_indexVertexArrays;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
class btThreadSupportInterface* m_threadSupportRaycast;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
bool m_animatedMesh;
|
||||
|
||||
public:
|
||||
|
||||
ConcaveRaycastDemo() : m_animatedMesh(false)
|
||||
{
|
||||
|
||||
}
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual ~ConcaveRaycastDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
//to show refit works
|
||||
void setVertexPositions(float waveheight, float offset);
|
||||
|
||||
virtual void keyboardCallback(unsigned char key, int x, int y);
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
ConcaveRaycastDemo* demo = new ConcaveRaycastDemo();
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
};
|
||||
};
|
||||
|
||||
#endif //CONCAVE_RAYCAST_DEMO_H
|
||||
|
@ -1,15 +0,0 @@
|
||||
|
||||
#include "ConcaveRaycastDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
ConcaveRaycastDemo* concaveRaycastDemo = new ConcaveRaycastDemo();
|
||||
concaveRaycastDemo->initPhysics();
|
||||
concaveRaycastDemo->setCameraDistance(30.f);
|
||||
|
||||
return glutmain(argc, argv,640,480,"Concave Raycast Demo",concaveRaycastDemo);
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
|
||||
IF (USE_GLUT)
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY}
|
||||
${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppConstraintDemo
|
||||
ConstraintDemo.cpp
|
||||
ConstraintDemo.h
|
||||
main.cpp
|
||||
)
|
||||
ELSE (USE_GLUT)
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppConstraintDemo
|
||||
WIN32
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
Win32ConstraintDemo.cpp
|
||||
ConstraintDemo.cpp
|
||||
ConstraintDemo.h
|
||||
)
|
||||
ENDIF (USE_GLUT)
|
||||
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppConstraintDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppConstraintDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppConstraintDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 CONSTRAINT_DEMO_H
|
||||
#define CONSTRAINT_DEMO_H
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
///ConstraintDemo shows how to create a constraint, like Hinge or btGenericD6constraint
|
||||
class ConstraintDemo : public PlatformDemoApplication
|
||||
{
|
||||
//keep track of variables to delete memory at the end
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
class btBroadphaseInterface* m_overlappingPairCache;
|
||||
|
||||
class btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
class btConstraintSolver* m_constraintSolver;
|
||||
|
||||
class btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
void setupEmptyDynamicsWorld();
|
||||
|
||||
void clientResetScene();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
virtual ~ConstraintDemo();
|
||||
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
ConstraintDemo* demo = new ConstraintDemo();
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
|
||||
virtual void keyboardCallback(unsigned char key, int x, int y);
|
||||
|
||||
// for cone-twist motor driving
|
||||
float m_Time;
|
||||
class btConeTwistConstraint* m_ctc;
|
||||
|
||||
};
|
||||
|
||||
#endif //CONSTRAINT_DEMO_H
|
||||
|
@ -1,25 +0,0 @@
|
||||
#ifdef _WINDOWS
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "ConstraintDemo.h"
|
||||
|
||||
///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo
|
||||
DemoApplication* createDemo()
|
||||
{
|
||||
return new ConstraintDemo();
|
||||
}
|
||||
|
||||
#endif
|
@ -1,20 +0,0 @@
|
||||
#include "ConstraintDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
|
||||
|
||||
ConstraintDemo* constraintDemo = new ConstraintDemo();
|
||||
|
||||
|
||||
constraintDemo->initPhysics();
|
||||
constraintDemo->setDebugMode(btIDebugDraw::DBG_DrawConstraints+btIDebugDraw::DBG_DrawConstraintLimits);
|
||||
|
||||
return glutmain(argc, argv,640,480,"Constraint Demo. http://www.continuousphysics.com/Bullet/phpBB2/",constraintDemo);
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppContinuousConvexCollisionDemo
|
||||
ContinuousConvexCollisionDemo.cpp
|
||||
)
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppContinuousConvexCollisionDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppContinuousConvexCollisionDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppContinuousConvexCollisionDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 CONTINUOUS_CONVEX_COLLISION_DEMO_H
|
||||
#define CONTINUOUS_CONVEX_COLLISION_DEMO_H
|
||||
|
||||
|
||||
|
||||
///ContinuousConvexCollisionDemo shows the working of the continuous collision detection, including linear and angular motion
|
||||
#include "GlutDemoApplication.h"
|
||||
class btContinuousConvexCollisionDemo : public GlutDemoApplication
|
||||
{
|
||||
public:
|
||||
|
||||
void initPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //CONTINUOUS_CONVEX_COLLISION_DEMO_H
|
||||
|
@ -1,287 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies.
|
||||
* Erwin Coumans makes no representations about the suitability
|
||||
* of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Continuous Convex Collision Demo demonstrates an efficient continuous collision detection algorithm.
|
||||
Both linear and angular velocities are supported. Convex Objects are sampled using Supporting Vertex.
|
||||
Motion using Exponential Map.
|
||||
Future ideas: Comparison with Screwing Motion.
|
||||
Also comparision with Algebraic CCD and Interval Arithmetic methods (Stephane Redon)
|
||||
*/
|
||||
|
||||
|
||||
///This low level demo need internal access, and intentionally doesn't include the btBulletCollisionCommon.h headerfile
|
||||
#include "LinearMath/btQuaternion.h"
|
||||
#include "LinearMath/btTransform.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
||||
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h"
|
||||
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
|
||||
|
||||
#include "LinearMath/btTransformUtil.h"
|
||||
#include "DebugCastResult.h"
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btSphereShape.h"
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btTetrahedronShape.h"
|
||||
|
||||
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h"
|
||||
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "ContinuousConvexCollision.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
|
||||
float yaw=0.f,pitch=0.f,roll=0.f;
|
||||
const int maxNumObjects = 4;
|
||||
const int numObjects = 2;
|
||||
|
||||
btVector3 angVels[numObjects];
|
||||
btVector3 linVels[numObjects];
|
||||
|
||||
btPolyhedralConvexShape* shapePtr[maxNumObjects];
|
||||
|
||||
|
||||
btTransform fromTrans[maxNumObjects];
|
||||
btTransform toTrans[maxNumObjects];
|
||||
|
||||
|
||||
int screenWidth = 640;
|
||||
int screenHeight = 480;
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
btContinuousConvexCollisionDemo* ccdDemo = new btContinuousConvexCollisionDemo();
|
||||
|
||||
ccdDemo->setCameraDistance(40.f);
|
||||
|
||||
ccdDemo->initPhysics();
|
||||
|
||||
return glutmain(argc, argv,screenWidth,screenHeight,"Continuous Convex Collision Demo",ccdDemo);
|
||||
}
|
||||
|
||||
|
||||
void btContinuousConvexCollisionDemo::initPhysics()
|
||||
{
|
||||
fromTrans[0].setOrigin(btVector3(0,10,20));
|
||||
toTrans[0].setOrigin(btVector3(0,10,-20));
|
||||
fromTrans[1].setOrigin(btVector3(-2,7,0));
|
||||
toTrans[1].setOrigin(btVector3(-2,10,0));
|
||||
|
||||
btMatrix3x3 identBasis;
|
||||
identBasis.setIdentity();
|
||||
|
||||
btMatrix3x3 basisA;
|
||||
basisA.setIdentity();
|
||||
basisA.setEulerZYX(0.f,-SIMD_HALF_PI,0.f);
|
||||
|
||||
fromTrans[0].setBasis(identBasis);
|
||||
toTrans[0].setBasis(basisA);
|
||||
|
||||
fromTrans[1].setBasis(identBasis);
|
||||
toTrans[1].setBasis(identBasis);
|
||||
|
||||
toTrans[1].setBasis(identBasis);
|
||||
btVector3 boxHalfExtentsA(10,1,1);
|
||||
btVector3 boxHalfExtentsB(1.1f,1.1f,1.1f);
|
||||
btBoxShape* boxA = new btBoxShape(boxHalfExtentsA);
|
||||
// btBU_Simplex1to4* boxA = new btBU_Simplex1to4(btVector3(-2,0,-2),btVector3(2,0,-2),btVector3(0,0,2),btVector3(0,2,0));
|
||||
// btBU_Simplex1to4* boxA = new btBU_Simplex1to4(btVector3(-12,0,0),btVector3(12,0,0));
|
||||
|
||||
|
||||
btBoxShape* boxB = new btBoxShape(boxHalfExtentsB);
|
||||
|
||||
shapePtr[0] = boxA;
|
||||
shapePtr[1] = boxB;
|
||||
|
||||
shapePtr[0]->setMargin(0.01f);
|
||||
shapePtr[1]->setMargin(0.01f);
|
||||
|
||||
for (int i=0;i<numObjects;i++)
|
||||
{
|
||||
btTransformUtil::calculateVelocity(fromTrans[i],toTrans[i],1.f,linVels[i],angVels[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//to be implemented by the demo
|
||||
|
||||
void btContinuousConvexCollisionDemo::clientMoveAndDisplay()
|
||||
{
|
||||
displayCallback();
|
||||
}
|
||||
|
||||
|
||||
static btVoronoiSimplexSolver sVoronoiSimplexSolver;
|
||||
|
||||
btSimplexSolverInterface& gGjkSimplexSolver = sVoronoiSimplexSolver;
|
||||
|
||||
bool drawLine= false;
|
||||
|
||||
int minlines = 0;
|
||||
|
||||
int maxlines = 512;
|
||||
|
||||
|
||||
void btContinuousConvexCollisionDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
//GL_ShapeDrawer::drawCoordSystem();
|
||||
|
||||
btScalar m[16];
|
||||
int i;
|
||||
|
||||
btVector3 worldBoundsMin(-1000,-1000,-1000);
|
||||
btVector3 worldBoundsMax(1000,1000,1000);
|
||||
|
||||
|
||||
/*for (i=0;i<numObjects;i++)
|
||||
{
|
||||
fromTrans[i].getOpenGLMatrix( m );
|
||||
m_shapeDrawer.drawOpenGL(m,shapePtr[i]);
|
||||
}
|
||||
*/
|
||||
|
||||
if (getDebugMode()==btIDebugDraw::DBG_DrawAabb)
|
||||
{
|
||||
i=0;//for (i=1;i<numObjects;i++)
|
||||
{
|
||||
//for each object, subdivide the from/to transform in 10 equal steps
|
||||
|
||||
int numSubSteps = 10;
|
||||
for (int s=0;s<10;s++)
|
||||
{
|
||||
btScalar subStep = s * 1.f/(float)numSubSteps;
|
||||
btTransform interpolatedTrans;
|
||||
|
||||
btTransformUtil::integrateTransform(fromTrans[i],linVels[i],angVels[i],subStep,interpolatedTrans);
|
||||
|
||||
//fromTrans[i].getOpenGLMatrix(m);
|
||||
//m_shapeDrawer.drawOpenGL(m,shapePtr[i]);
|
||||
|
||||
//toTrans[i].getOpenGLMatrix(m);
|
||||
//m_shapeDrawer.drawOpenGL(m,shapePtr[i]);
|
||||
|
||||
interpolatedTrans.getOpenGLMatrix( m );
|
||||
m_shapeDrawer->drawOpenGL(m,shapePtr[i],btVector3(1,0,1),getDebugMode(),worldBoundsMin,worldBoundsMax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
btMatrix3x3 mat;
|
||||
mat.setEulerZYX(yaw,pitch,roll);
|
||||
btQuaternion orn;
|
||||
mat.getRotation(orn);
|
||||
orn.setEuler(yaw,pitch,roll);
|
||||
fromTrans[1].setRotation(orn);
|
||||
toTrans[1].setRotation(orn);
|
||||
|
||||
|
||||
if (m_stepping || m_singleStep)
|
||||
{
|
||||
m_singleStep = false;
|
||||
pitch += 0.005f;
|
||||
// yaw += 0.01f;
|
||||
}
|
||||
// btVector3 fromA(-25,11,0);
|
||||
// btVector3 toA(-15,11,0);
|
||||
|
||||
// btQuaternion ornFromA(0.f,0.f,0.f,1.f);
|
||||
// btQuaternion ornToA(0.f,0.f,0.f,1.f);
|
||||
|
||||
// btTransform rayFromWorld(ornFromA,fromA);
|
||||
// btTransform rayToWorld(ornToA,toA);
|
||||
|
||||
btTransform rayFromWorld = fromTrans[0];
|
||||
btTransform rayToWorld = toTrans[0];
|
||||
|
||||
|
||||
if (drawLine)
|
||||
{
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(0, 0, 1);
|
||||
glVertex3d(rayFromWorld.getOrigin().x(), rayFromWorld.getOrigin().y(),rayFromWorld.getOrigin().z());
|
||||
glVertex3d(rayToWorld.getOrigin().x(),rayToWorld.getOrigin().y(),rayToWorld.getOrigin().z());
|
||||
glEnd();
|
||||
}
|
||||
|
||||
//now perform a raycast on the shapes, in local (shape) space
|
||||
gGjkSimplexSolver.reset();
|
||||
|
||||
//choose one of the following lines
|
||||
|
||||
|
||||
for (i=0;i<numObjects;i++)
|
||||
{
|
||||
fromTrans[i].getOpenGLMatrix(m);
|
||||
m_shapeDrawer->drawOpenGL(m,shapePtr[i],btVector3(1,1,1),getDebugMode(),worldBoundsMin,worldBoundsMax);
|
||||
}
|
||||
|
||||
btDebugCastResult rayResult1(fromTrans[0],shapePtr[0],linVels[0],angVels[0],m_shapeDrawer);
|
||||
|
||||
|
||||
for (i=1;i<numObjects;i++)
|
||||
{
|
||||
btConvexCast::CastResult rayResult2;
|
||||
btConvexCast::CastResult* rayResultPtr;
|
||||
if (btIDebugDraw::DBG_DrawAabb)
|
||||
{
|
||||
rayResultPtr = &rayResult1;
|
||||
} else
|
||||
{
|
||||
rayResultPtr = &rayResult2;
|
||||
}
|
||||
|
||||
//GjkConvexCast convexCaster(&gGjkSimplexSolver);
|
||||
//SubsimplexConvexCast convexCaster(&gGjkSimplexSolver);
|
||||
|
||||
//optional
|
||||
btConvexPenetrationDepthSolver* penetrationDepthSolver = 0;
|
||||
btContinuousConvexCollision convexCaster(shapePtr[0],shapePtr[i],&gGjkSimplexSolver,penetrationDepthSolver );
|
||||
|
||||
gGjkSimplexSolver.reset();
|
||||
|
||||
|
||||
|
||||
if (convexCaster.calcTimeOfImpact(fromTrans[0],toTrans[0],fromTrans[i] ,toTrans[i] ,*rayResultPtr))
|
||||
{
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
btTransform hitTrans;
|
||||
btTransformUtil::integrateTransform(fromTrans[0],linVels[0],angVels[0],rayResultPtr->m_fraction,hitTrans);
|
||||
|
||||
hitTrans.getOpenGLMatrix(m);
|
||||
m_shapeDrawer->drawOpenGL(m,shapePtr[0],btVector3(0,1,0),getDebugMode(),worldBoundsMin,worldBoundsMax);
|
||||
|
||||
btTransformUtil::integrateTransform(fromTrans[i],linVels[i],angVels[i],rayResultPtr->m_fraction,hitTrans);
|
||||
|
||||
hitTrans.getOpenGLMatrix(m);
|
||||
m_shapeDrawer->drawOpenGL(m,shapePtr[i],btVector3(0,1,1),getDebugMode(),worldBoundsMin,worldBoundsMax);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
@ -1,69 +0,0 @@
|
||||
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# This is the variable for Windows. I use this to define the root of my directory structure.
|
||||
SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/HACD
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/ConvexDecomposition
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
||||
${GLUT_INCLUDE_DIR}
|
||||
|
||||
)
|
||||
|
||||
IF (USE_GLUT)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision LinearMath BulletFileLoader HACD ConvexDecomposition ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppConvexDecompositionDemo
|
||||
main.cpp
|
||||
ConvexDecompositionDemo.cpp
|
||||
ConvexDecompositionDemo.h
|
||||
)
|
||||
ELSE (USE_GLUT)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision LinearMath BulletFileLoader HACD ConvexDecomposition ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppConvexDecompositionDemo
|
||||
WIN32
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
ConvexDecompositionDemo.cpp
|
||||
ConvexDecompositionDemo.h
|
||||
Win32ConvexDecompositionDemo.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
|
||||
ENDIF (USE_GLUT)
|
||||
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppConvexDecompositionDemo
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/SerializeDemo/testFile.bullet ${CMAKE_CURRENT_BINARY_DIR}/testFile.bullet
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/ConvexDecompositionDemo/file.obj ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppConvexDecompositionDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppConvexDecompositionDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppConvexDecompositionDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,778 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "hacdCircularList.h"
|
||||
#include "hacdVector.h"
|
||||
#include "hacdICHull.h"
|
||||
#include "hacdGraph.h"
|
||||
#include "hacdHACD.h"
|
||||
|
||||
#include "cd_wavefront.h"
|
||||
#include "ConvexBuilder.h"
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "LinearMath/btGeometryUtil.h"
|
||||
#include "BulletCollision/CollisionShapes/btShapeHull.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
//#define TEST_SERIALIZATION
|
||||
//#define NO_OBJ_TO_BULLET
|
||||
|
||||
#ifdef TEST_SERIALIZATION
|
||||
#include "LinearMath/btSerializer.h"
|
||||
#include "btBulletFile.h"
|
||||
#include "btBulletWorldImporter.h"
|
||||
#endif
|
||||
|
||||
//#define USE_PARALLEL_DISPATCHER 1
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#include "../../Extras/BulletMultiThreaded/SpuGatheringCollisionDispatcher.h"
|
||||
#include "../../Extras/BulletMultiThreaded/Win32ThreadSupport.h"
|
||||
#include "../../Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h"
|
||||
#endif//USE_PARALLEL_DISPATCHER
|
||||
|
||||
#include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"//for the callback
|
||||
|
||||
bool MyCompoundChildShapeCallback(const btCollisionShape* pShape0, const btCollisionShape* pShape1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#include "GLDebugFont.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
|
||||
#include "ConvexDecompositionDemo.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
|
||||
#include "GlutStuff.h"
|
||||
|
||||
|
||||
btVector3 centroid=btVector3(0,0,0);
|
||||
btVector3 convexDecompositionObjectOffset(10,0,0);
|
||||
|
||||
#define CUBE_HALF_EXTENTS 4
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
unsigned int tcount = 0;
|
||||
|
||||
//sEnableSAT creates the data structures required for performing SAT tests between convex polyhedra, as alternative to GJK
|
||||
bool sEnableSAT = false;
|
||||
|
||||
void ConvexDecompositionDemo::initPhysics()
|
||||
{
|
||||
initPhysics("file.obj");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///MyContactCallback is just an example to show how to get access to the child shape that collided
|
||||
bool MyContactCallback (
|
||||
btManifoldPoint& cp,
|
||||
const btCollisionObjectWrapper* colObj0Wrap,
|
||||
int partId0,
|
||||
int index0,
|
||||
const btCollisionObjectWrapper* colObj1Wrap,
|
||||
int partId1,
|
||||
int index1)
|
||||
{
|
||||
|
||||
if (colObj0Wrap->getCollisionObject()->getCollisionShape()->getShapeType()==COMPOUND_SHAPE_PROXYTYPE)
|
||||
{
|
||||
btCompoundShape* compound = (btCompoundShape*)colObj0Wrap->getCollisionObject()->getCollisionShape();
|
||||
btCollisionShape* childShape;
|
||||
childShape = compound->getChildShape(index0);
|
||||
}
|
||||
|
||||
if (colObj1Wrap->getCollisionObject()->getCollisionShape()->getShapeType()==COMPOUND_SHAPE_PROXYTYPE)
|
||||
{
|
||||
btCompoundShape* compound = (btCompoundShape*)colObj1Wrap->getCollisionObject()->getCollisionShape();
|
||||
btCollisionShape* childShape;
|
||||
childShape = compound->getChildShape(index1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ConvexDecompositionDemo::setupEmptyDynamicsWorld()
|
||||
{
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#ifdef USE_WIN32_THREADING
|
||||
|
||||
int maxNumOutstandingTasks = 4;//number of maximum outstanding tasks
|
||||
Win32ThreadSupport* threadSupport = new Win32ThreadSupport(Win32ThreadSupport::Win32ThreadConstructionInfo(
|
||||
"collision",
|
||||
processCollisionTask,
|
||||
createCollisionLocalStoreMemory,
|
||||
maxNumOutstandingTasks));
|
||||
#else
|
||||
///@todo other platform threading
|
||||
///Playstation 3 SPU (SPURS) version is available through PS3 Devnet
|
||||
///Libspe2 SPU support will be available soon
|
||||
///pthreads version
|
||||
///you can hook it up to your custom task scheduler by deriving from btThreadSupportInterface
|
||||
#endif
|
||||
|
||||
m_dispatcher = new SpuGatheringCollisionDispatcher(threadSupport,maxNumOutstandingTasks,m_collisionConfiguration);
|
||||
#else
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
#endif//USE_PARALLEL_DISPATCHER
|
||||
|
||||
gCompoundChildShapePairCallback = MyCompoundChildShapeCallback;
|
||||
|
||||
convexDecompositionObjectOffset.setValue(10,0,0);
|
||||
|
||||
btVector3 worldAabbMin(-10000,-10000,-10000);
|
||||
btVector3 worldAabbMax(10000,10000,10000);
|
||||
|
||||
m_broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
|
||||
//m_broadphase = new btSimpleBroadphase();
|
||||
|
||||
m_solver = new btSequentialImpulseConstraintSolver();
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
|
||||
#endif //USE_PARALLEL_DISPATCHER
|
||||
|
||||
}
|
||||
|
||||
void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
{
|
||||
|
||||
gContactAddedCallback = &MyContactCallback;
|
||||
|
||||
setupEmptyDynamicsWorld();
|
||||
|
||||
getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
setTexturing(true);
|
||||
setShadows(true);
|
||||
|
||||
setCameraDistance(26.f);
|
||||
|
||||
|
||||
#ifndef NO_OBJ_TO_BULLET
|
||||
|
||||
ConvexDecomposition::WavefrontObj wo;
|
||||
|
||||
tcount = 0;
|
||||
const char* prefix[]={"./","../","../../","../../../","../../../../", "ConvexDecompositionDemo/", "Demos/ConvexDecompositionDemo/",
|
||||
"../Demos/ConvexDecompositionDemo/","../../Demos/ConvexDecompositionDemo/"};
|
||||
int numPrefixes = sizeof(prefix)/sizeof(const char*);
|
||||
char relativeFileName[1024];
|
||||
|
||||
for (int i=0;i<numPrefixes;i++)
|
||||
{
|
||||
sprintf(relativeFileName,"%s%s",prefix[i],filename);
|
||||
tcount = wo.loadObj(relativeFileName);
|
||||
if (tcount)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-4.5,0));
|
||||
|
||||
btCollisionShape* boxShape = new btBoxShape(btVector3(30,2,30));
|
||||
m_collisionShapes.push_back(boxShape);
|
||||
localCreateRigidBody(0.f,startTransform,boxShape);
|
||||
|
||||
class MyConvexDecomposition : public ConvexDecomposition::ConvexDecompInterface
|
||||
{
|
||||
ConvexDecompositionDemo* m_convexDemo;
|
||||
|
||||
public:
|
||||
|
||||
btAlignedObjectArray<btConvexHullShape*> m_convexShapes;
|
||||
btAlignedObjectArray<btVector3> m_convexCentroids;
|
||||
|
||||
MyConvexDecomposition (FILE* outputFile,ConvexDecompositionDemo* demo)
|
||||
:m_convexDemo(demo),
|
||||
mBaseCount(0),
|
||||
mHullCount(0),
|
||||
mOutputFile(outputFile)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
virtual void ConvexDecompResult(ConvexDecomposition::ConvexResult &result)
|
||||
{
|
||||
|
||||
btTriangleMesh* trimesh = new btTriangleMesh();
|
||||
m_convexDemo->m_trimeshes.push_back(trimesh);
|
||||
|
||||
btVector3 localScaling(6.f,6.f,6.f);
|
||||
|
||||
//export data to .obj
|
||||
printf("ConvexResult. ");
|
||||
if (mOutputFile)
|
||||
{
|
||||
fprintf(mOutputFile,"## Hull Piece %d with %d vertices and %d triangles.\r\n", mHullCount, result.mHullVcount, result.mHullTcount );
|
||||
|
||||
fprintf(mOutputFile,"usemtl Material%i\r\n",mBaseCount);
|
||||
fprintf(mOutputFile,"o Object%i\r\n",mBaseCount);
|
||||
|
||||
for (unsigned int i=0; i<result.mHullVcount; i++)
|
||||
{
|
||||
const float *p = &result.mHullVertices[i*3];
|
||||
fprintf(mOutputFile,"v %0.9f %0.9f %0.9f\r\n", p[0], p[1], p[2] );
|
||||
}
|
||||
|
||||
//calc centroid, to shift vertices around center of mass
|
||||
centroid.setValue(0,0,0);
|
||||
|
||||
btAlignedObjectArray<btVector3> vertices;
|
||||
if ( 1 )
|
||||
{
|
||||
//const unsigned int *src = result.mHullIndices;
|
||||
for (unsigned int i=0; i<result.mHullVcount; i++)
|
||||
{
|
||||
btVector3 vertex(result.mHullVertices[i*3],result.mHullVertices[i*3+1],result.mHullVertices[i*3+2]);
|
||||
vertex *= localScaling;
|
||||
centroid += vertex;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
centroid *= 1.f/(float(result.mHullVcount) );
|
||||
|
||||
if ( 1 )
|
||||
{
|
||||
//const unsigned int *src = result.mHullIndices;
|
||||
for (unsigned int i=0; i<result.mHullVcount; i++)
|
||||
{
|
||||
btVector3 vertex(result.mHullVertices[i*3],result.mHullVertices[i*3+1],result.mHullVertices[i*3+2]);
|
||||
vertex *= localScaling;
|
||||
vertex -= centroid ;
|
||||
vertices.push_back(vertex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ( 1 )
|
||||
{
|
||||
const unsigned int *src = result.mHullIndices;
|
||||
for (unsigned int i=0; i<result.mHullTcount; i++)
|
||||
{
|
||||
unsigned int index0 = *src++;
|
||||
unsigned int index1 = *src++;
|
||||
unsigned int index2 = *src++;
|
||||
|
||||
|
||||
btVector3 vertex0(result.mHullVertices[index0*3], result.mHullVertices[index0*3+1],result.mHullVertices[index0*3+2]);
|
||||
btVector3 vertex1(result.mHullVertices[index1*3], result.mHullVertices[index1*3+1],result.mHullVertices[index1*3+2]);
|
||||
btVector3 vertex2(result.mHullVertices[index2*3], result.mHullVertices[index2*3+1],result.mHullVertices[index2*3+2]);
|
||||
vertex0 *= localScaling;
|
||||
vertex1 *= localScaling;
|
||||
vertex2 *= localScaling;
|
||||
|
||||
vertex0 -= centroid;
|
||||
vertex1 -= centroid;
|
||||
vertex2 -= centroid;
|
||||
|
||||
|
||||
trimesh->addTriangle(vertex0,vertex1,vertex2);
|
||||
|
||||
index0+=mBaseCount;
|
||||
index1+=mBaseCount;
|
||||
index2+=mBaseCount;
|
||||
|
||||
fprintf(mOutputFile,"f %d %d %d\r\n", index0+1, index1+1, index2+1 );
|
||||
}
|
||||
}
|
||||
|
||||
// float mass = 1.f;
|
||||
|
||||
|
||||
//this is a tools issue: due to collision margin, convex objects overlap, compensate for it here:
|
||||
//#define SHRINK_OBJECT_INWARDS 1
|
||||
#ifdef SHRINK_OBJECT_INWARDS
|
||||
|
||||
float collisionMargin = 0.01f;
|
||||
|
||||
btAlignedObjectArray<btVector3> planeEquations;
|
||||
btGeometryUtil::getPlaneEquationsFromVertices(vertices,planeEquations);
|
||||
|
||||
btAlignedObjectArray<btVector3> shiftedPlaneEquations;
|
||||
for (int p=0;p<planeEquations.size();p++)
|
||||
{
|
||||
btVector3 plane = planeEquations[p];
|
||||
plane[3] += collisionMargin;
|
||||
shiftedPlaneEquations.push_back(plane);
|
||||
}
|
||||
btAlignedObjectArray<btVector3> shiftedVertices;
|
||||
btGeometryUtil::getVerticesFromPlaneEquations(shiftedPlaneEquations,shiftedVertices);
|
||||
|
||||
|
||||
btConvexHullShape* convexShape = new btConvexHullShape(&(shiftedVertices[0].getX()),shiftedVertices.size());
|
||||
|
||||
#else //SHRINK_OBJECT_INWARDS
|
||||
|
||||
btConvexHullShape* convexShape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
|
||||
#endif
|
||||
if (sEnableSAT)
|
||||
convexShape->initializePolyhedralFeatures();
|
||||
convexShape->setMargin(0.01f);
|
||||
m_convexShapes.push_back(convexShape);
|
||||
m_convexCentroids.push_back(centroid);
|
||||
m_convexDemo->m_collisionShapes.push_back(convexShape);
|
||||
mBaseCount+=result.mHullVcount; // advance the 'base index' counter.
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int mBaseCount;
|
||||
int mHullCount;
|
||||
FILE* mOutputFile;
|
||||
|
||||
};
|
||||
|
||||
if (tcount)
|
||||
{
|
||||
btTriangleMesh* trimesh = new btTriangleMesh();
|
||||
m_trimeshes.push_back(trimesh);
|
||||
|
||||
btVector3 localScaling(6.f,6.f,6.f);
|
||||
|
||||
int i;
|
||||
for ( i=0;i<wo.mTriCount;i++)
|
||||
{
|
||||
int index0 = wo.mIndices[i*3];
|
||||
int index1 = wo.mIndices[i*3+1];
|
||||
int index2 = wo.mIndices[i*3+2];
|
||||
|
||||
btVector3 vertex0(wo.mVertices[index0*3], wo.mVertices[index0*3+1],wo.mVertices[index0*3+2]);
|
||||
btVector3 vertex1(wo.mVertices[index1*3], wo.mVertices[index1*3+1],wo.mVertices[index1*3+2]);
|
||||
btVector3 vertex2(wo.mVertices[index2*3], wo.mVertices[index2*3+1],wo.mVertices[index2*3+2]);
|
||||
|
||||
vertex0 *= localScaling;
|
||||
vertex1 *= localScaling;
|
||||
vertex2 *= localScaling;
|
||||
|
||||
trimesh->addTriangle(vertex0,vertex1,vertex2);
|
||||
}
|
||||
|
||||
|
||||
btConvexShape* tmpConvexShape = new btConvexTriangleMeshShape(trimesh);
|
||||
|
||||
printf("old numTriangles= %d\n",wo.mTriCount);
|
||||
printf("old numIndices = %d\n",wo.mTriCount*3);
|
||||
printf("old numVertices = %d\n",wo.mVertexCount);
|
||||
|
||||
printf("reducing vertices by creating a convex hull\n");
|
||||
|
||||
//create a hull approximation
|
||||
btShapeHull* hull = new btShapeHull(tmpConvexShape);
|
||||
btScalar margin = tmpConvexShape->getMargin();
|
||||
hull->buildHull(margin);
|
||||
tmpConvexShape->setUserPointer(hull);
|
||||
|
||||
|
||||
printf("new numTriangles = %d\n", hull->numTriangles ());
|
||||
printf("new numIndices = %d\n", hull->numIndices ());
|
||||
printf("new numVertices = %d\n", hull->numVertices ());
|
||||
|
||||
btConvexHullShape* convexShape = new btConvexHullShape();
|
||||
bool updateLocalAabb = false;
|
||||
|
||||
for (i=0;i<hull->numVertices();i++)
|
||||
{
|
||||
convexShape->addPoint(hull->getVertexPointer()[i],updateLocalAabb);
|
||||
}
|
||||
convexShape->recalcLocalAabb();
|
||||
|
||||
if (sEnableSAT)
|
||||
convexShape->initializePolyhedralFeatures();
|
||||
delete tmpConvexShape;
|
||||
delete hull;
|
||||
|
||||
|
||||
|
||||
m_collisionShapes.push_back(convexShape);
|
||||
|
||||
float mass = 1.f;
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,2,14));
|
||||
|
||||
localCreateRigidBody(mass, startTransform,convexShape);
|
||||
|
||||
bool useQuantization = true;
|
||||
btCollisionShape* concaveShape = new btBvhTriangleMeshShape(trimesh,useQuantization);
|
||||
startTransform.setOrigin(convexDecompositionObjectOffset);
|
||||
localCreateRigidBody(0.f,startTransform,concaveShape);
|
||||
|
||||
m_collisionShapes.push_back (concaveShape);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (tcount)
|
||||
{
|
||||
//-----------------------------------
|
||||
// Bullet Convex Decomposition
|
||||
//-----------------------------------
|
||||
|
||||
char outputFileName[512];
|
||||
strcpy(outputFileName,filename);
|
||||
char *dot = strstr(outputFileName,".");
|
||||
if ( dot )
|
||||
*dot = 0;
|
||||
strcat(outputFileName,"_convex.obj");
|
||||
FILE* outputFile = fopen(outputFileName,"wb");
|
||||
|
||||
unsigned int depth = 5;
|
||||
float cpercent = 5;
|
||||
float ppercent = 15;
|
||||
unsigned int maxv = 16;
|
||||
float skinWidth = 0.0;
|
||||
|
||||
printf("WavefrontObj num triangles read %i\n",tcount);
|
||||
ConvexDecomposition::DecompDesc desc;
|
||||
desc.mVcount = wo.mVertexCount;
|
||||
desc.mVertices = wo.mVertices;
|
||||
desc.mTcount = wo.mTriCount;
|
||||
desc.mIndices = (unsigned int *)wo.mIndices;
|
||||
desc.mDepth = depth;
|
||||
desc.mCpercent = cpercent;
|
||||
desc.mPpercent = ppercent;
|
||||
desc.mMaxVertices = maxv;
|
||||
desc.mSkinWidth = skinWidth;
|
||||
|
||||
MyConvexDecomposition convexDecomposition(outputFile,this);
|
||||
desc.mCallback = &convexDecomposition;
|
||||
|
||||
|
||||
//-----------------------------------------------
|
||||
// HACD
|
||||
//-----------------------------------------------
|
||||
|
||||
std::vector< HACD::Vec3<HACD::Real> > points;
|
||||
std::vector< HACD::Vec3<long> > triangles;
|
||||
|
||||
for(int i=0; i<wo.mVertexCount; i++ )
|
||||
{
|
||||
int index = i*3;
|
||||
HACD::Vec3<HACD::Real> vertex(wo.mVertices[index], wo.mVertices[index+1],wo.mVertices[index+2]);
|
||||
points.push_back(vertex);
|
||||
}
|
||||
|
||||
for(int i=0;i<wo.mTriCount;i++)
|
||||
{
|
||||
int index = i*3;
|
||||
HACD::Vec3<long> triangle(wo.mIndices[index], wo.mIndices[index+1], wo.mIndices[index+2]);
|
||||
triangles.push_back(triangle);
|
||||
}
|
||||
|
||||
|
||||
HACD::HACD myHACD;
|
||||
myHACD.SetPoints(&points[0]);
|
||||
myHACD.SetNPoints(points.size());
|
||||
myHACD.SetTriangles(&triangles[0]);
|
||||
myHACD.SetNTriangles(triangles.size());
|
||||
myHACD.SetCompacityWeight(0.1);
|
||||
myHACD.SetVolumeWeight(0.0);
|
||||
|
||||
// HACD parameters
|
||||
// Recommended parameters: 2 100 0 0 0 0
|
||||
size_t nClusters = 2;
|
||||
double concavity = 100;
|
||||
bool invert = false;
|
||||
bool addExtraDistPoints = false;
|
||||
bool addNeighboursDistPoints = false;
|
||||
bool addFacesPoints = false;
|
||||
|
||||
myHACD.SetNClusters(nClusters); // minimum number of clusters
|
||||
myHACD.SetNVerticesPerCH(100); // max of 100 vertices per convex-hull
|
||||
myHACD.SetConcavity(concavity); // maximum concavity
|
||||
myHACD.SetAddExtraDistPoints(addExtraDistPoints);
|
||||
myHACD.SetAddNeighboursDistPoints(addNeighboursDistPoints);
|
||||
myHACD.SetAddFacesPoints(addFacesPoints);
|
||||
|
||||
myHACD.Compute();
|
||||
nClusters = myHACD.GetNClusters();
|
||||
|
||||
myHACD.Save("output.wrl", false);
|
||||
|
||||
|
||||
//convexDecomposition.performConvexDecomposition(desc);
|
||||
|
||||
// ConvexBuilder cb(desc.mCallback);
|
||||
// cb.process(desc);
|
||||
//now create some bodies
|
||||
|
||||
if (1)
|
||||
{
|
||||
btCompoundShape* compound = new btCompoundShape();
|
||||
m_collisionShapes.push_back (compound);
|
||||
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
|
||||
for (int c=0;c<nClusters;c++)
|
||||
{
|
||||
//generate convex result
|
||||
size_t nPoints = myHACD.GetNPointsCH(c);
|
||||
size_t nTriangles = myHACD.GetNTrianglesCH(c);
|
||||
|
||||
float* vertices = new float[nPoints*3];
|
||||
unsigned int* triangles = new unsigned int[nTriangles*3];
|
||||
|
||||
HACD::Vec3<HACD::Real> * pointsCH = new HACD::Vec3<HACD::Real>[nPoints];
|
||||
HACD::Vec3<long> * trianglesCH = new HACD::Vec3<long>[nTriangles];
|
||||
myHACD.GetCH(c, pointsCH, trianglesCH);
|
||||
|
||||
// points
|
||||
for(size_t v = 0; v < nPoints; v++)
|
||||
{
|
||||
vertices[3*v] = pointsCH[v].X();
|
||||
vertices[3*v+1] = pointsCH[v].Y();
|
||||
vertices[3*v+2] = pointsCH[v].Z();
|
||||
}
|
||||
// triangles
|
||||
for(size_t f = 0; f < nTriangles; f++)
|
||||
{
|
||||
triangles[3*f] = trianglesCH[f].X();
|
||||
triangles[3*f+1] = trianglesCH[f].Y();
|
||||
triangles[3*f+2] = trianglesCH[f].Z();
|
||||
}
|
||||
|
||||
delete [] pointsCH;
|
||||
delete [] trianglesCH;
|
||||
|
||||
ConvexResult r(nPoints, vertices, nTriangles, triangles);
|
||||
convexDecomposition.ConvexDecompResult(r);
|
||||
}
|
||||
|
||||
for (int i=0;i<convexDecomposition.m_convexShapes.size();i++)
|
||||
{
|
||||
btVector3 centroid = convexDecomposition.m_convexCentroids[i];
|
||||
trans.setOrigin(centroid);
|
||||
btConvexHullShape* convexShape = convexDecomposition.m_convexShapes[i];
|
||||
compound->addChildShape(trans,convexShape);
|
||||
|
||||
btRigidBody* body;
|
||||
body = localCreateRigidBody( 1.0, trans,convexShape);
|
||||
}
|
||||
/* for (int i=0;i<convexDecomposition.m_convexShapes.size();i++)
|
||||
{
|
||||
|
||||
btVector3 centroid = convexDecomposition.m_convexCentroids[i];
|
||||
trans.setOrigin(centroid);
|
||||
btConvexHullShape* convexShape = convexDecomposition.m_convexShapes[i];
|
||||
compound->addChildShape(trans,convexShape);
|
||||
|
||||
btRigidBody* body;
|
||||
body = localCreateRigidBody( 1.0, trans,convexShape);
|
||||
}*/
|
||||
|
||||
#if 1
|
||||
btScalar mass=10.f;
|
||||
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||
btRigidBody* body = localCreateRigidBody( mass, trans,compound);
|
||||
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
|
||||
|
||||
convexDecompositionObjectOffset.setZ(6);
|
||||
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||
body = localCreateRigidBody( mass, trans,compound);
|
||||
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
|
||||
|
||||
convexDecompositionObjectOffset.setZ(-6);
|
||||
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||
body = localCreateRigidBody( mass, trans,compound);
|
||||
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
if (outputFile)
|
||||
fclose(outputFile);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef TEST_SERIALIZATION
|
||||
//test serializing this
|
||||
|
||||
int maxSerializeBufferSize = 1024*1024*5;
|
||||
|
||||
btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize);
|
||||
m_dynamicsWorld->serialize(serializer);
|
||||
|
||||
FILE* f2 = fopen("testFile.bullet","wb");
|
||||
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1,f2);
|
||||
fclose(f2);
|
||||
|
||||
exitPhysics();
|
||||
|
||||
//now try again from the loaded file
|
||||
setupEmptyDynamicsWorld();
|
||||
#endif //TEST_SERIALIZATION
|
||||
|
||||
#endif //NO_OBJ_TO_BULLET
|
||||
|
||||
#ifdef TEST_SERIALIZATION
|
||||
|
||||
btBulletWorldImporter* fileLoader = new btBulletWorldImporter(m_dynamicsWorld);
|
||||
//fileLoader->setVerboseMode(true);
|
||||
|
||||
fileLoader->loadFile("testFile.bullet");
|
||||
//fileLoader->loadFile("testFile64Double.bullet");
|
||||
//fileLoader->loadFile("testFile64Single.bullet");
|
||||
//fileLoader->loadFile("testFile32Single.bullet");
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //TEST_SERIALIZATION
|
||||
|
||||
}
|
||||
|
||||
void ConvexDecompositionDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
float dt = getDeltaTimeMicroseconds() * 0.000001f;
|
||||
|
||||
m_dynamicsWorld->stepSimulation(dt);
|
||||
|
||||
//optional but useful: debug drawing
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
swapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConvexDecompositionDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
renderme();
|
||||
|
||||
|
||||
glFlush();
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ConvexDecompositionDemo::exitPhysics()
|
||||
{
|
||||
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (i=0;i<m_collisionShapes.size();i++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[i];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
m_collisionShapes.clear();
|
||||
|
||||
for (i=0;i<m_trimeshes.size();i++)
|
||||
{
|
||||
btTriangleMesh* mesh = m_trimeshes[i];
|
||||
delete mesh;
|
||||
}
|
||||
|
||||
m_trimeshes.clear();
|
||||
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
//delete solver
|
||||
delete m_solver;
|
||||
|
||||
//delete broadphase
|
||||
delete m_broadphase;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ConvexDecompositionDemo::clientResetScene()
|
||||
{
|
||||
exitPhysics();
|
||||
initPhysics("file.obj");
|
||||
}
|
||||
|
||||
void ConvexDecompositionDemo::keyboardCallback(unsigned char key, int x, int y)
|
||||
{
|
||||
if (key=='S')
|
||||
{
|
||||
sEnableSAT= !sEnableSAT;
|
||||
if (sEnableSAT)
|
||||
{
|
||||
printf("SAT enabled after the next restart of the demo\n");
|
||||
} else
|
||||
{
|
||||
printf("SAT disabled after the next restart of the demo\n");
|
||||
}
|
||||
} else
|
||||
{
|
||||
PlatformDemoApplication::keyboardCallback(key,x,y);
|
||||
}
|
||||
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 CONVEX_DECOMPOSITION_DEMO_H
|
||||
#define CONVEX_DECOMPOSITION_DEMO_H
|
||||
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
class btTriangleMesh;
|
||||
|
||||
///ConvexDecompositionDemo shows automatic convex decomposition of a concave mesh
|
||||
ATTRIBUTE_ALIGNED16(class) ConvexDecompositionDemo : public PlatformDemoApplication
|
||||
{
|
||||
|
||||
void setupEmptyDynamicsWorld();
|
||||
public:
|
||||
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btAlignedObjectArray<btTriangleMesh*> m_trimeshes;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
|
||||
virtual void initPhysics();
|
||||
|
||||
void initPhysics(const char* filename);
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
virtual ~ConvexDecompositionDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void keyboardCallback(unsigned char key, int x, int y);
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
ConvexDecompositionDemo* demo = new ConvexDecompositionDemo();
|
||||
demo->myinit();
|
||||
demo->initPhysics("file.obj");
|
||||
return demo;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //CONVEX_DECOMPOSITION_DEMO_H
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
#ifdef _WINDOWS
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2010 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "ConvexDecompositionDemo.h"
|
||||
|
||||
///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo
|
||||
DemoApplication* createDemo()
|
||||
{
|
||||
return new ConvexDecompositionDemo();
|
||||
}
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,27 +0,0 @@
|
||||
|
||||
|
||||
#include "ConvexDecompositionDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
const char* filename = "file.obj";
|
||||
|
||||
|
||||
ConvexDecompositionDemo* convexDecompDemo = new ConvexDecompositionDemo();
|
||||
|
||||
convexDecompDemo->initPhysics(filename);
|
||||
|
||||
|
||||
|
||||
|
||||
glutmain(argc, argv,640,480,"Bullet Physics Demo. http://www.continuousphysics.com/Bullet/phpBB2/",convexDecompDemo);
|
||||
|
||||
delete convexDecompDemo;
|
||||
|
||||
return 0;
|
||||
}
|
Binary file not shown.
@ -1,65 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# This is the variable for Windows. I use this to define the root of my directory structure.
|
||||
SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
|
||||
|
||||
IF (USE_GLUT)
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppConvexHullDistanceDemo
|
||||
|
||||
ConvexHullDistanceDemo.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppConvexHullDistanceDemo
|
||||
ConvexHullDistanceDemo.cpp
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
||||
|
||||
|
||||
ELSE (USE_GLUT)
|
||||
|
||||
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
|
||||
ADD_EXECUTABLE(AppConvexHullDistanceDemo
|
||||
WIN32
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
ConvexHullDistanceDemo.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
|
||||
|
||||
ENDIF (USE_GLUT)
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppConvexHullDistanceDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppConvexHullDistanceDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppConvexHullDistanceDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,509 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
///
|
||||
/// Convex Hull Distance Demo shows distance calculation between two convex hulls of points.
|
||||
/// GJK with the btVoronoiSimplexSolver is used.
|
||||
///
|
||||
|
||||
#include "GL_Simplex1to4.h"
|
||||
#include "LinearMath/btQuaternion.h"
|
||||
#include "LinearMath/btTransform.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
||||
#include "BulletCollision/CollisionShapes/btConvexHullShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCylinderShape.h"
|
||||
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btPointCollector.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "LinearMath/btConvexHullComputer.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define TaruVtxCount 43
|
||||
|
||||
static btScalar TaruVtx[] = {
|
||||
1.08664f,-1.99237f,0.0f,
|
||||
0.768369f,-1.99237f,-0.768369f,
|
||||
1.28852f,1.34412e-007f,-1.28852f,
|
||||
1.82224f,1.90735e-007f,0.0f,
|
||||
0.0f,-1.99237f,-1.08664f,
|
||||
0.0f,0.0f,-1.82224f,
|
||||
0.0f,-1.99237f,-1.08664f,
|
||||
-0.768369f,-1.99237f,-0.768369f,
|
||||
-1.28852f,1.34412e-007f,-1.28852f,
|
||||
0.0f,0.0f,-1.82224f,
|
||||
-1.08664f,-1.99237f,1.82086e-007f,
|
||||
-1.82224f,1.90735e-007f,1.59305e-007f,
|
||||
-0.768369f,-1.99237f,0.76837f,
|
||||
-1.28852f,2.47058e-007f,1.28852f,
|
||||
1.42495e-007f,-1.99237f,1.08664f,
|
||||
2.38958e-007f,2.70388e-007f,1.82224f,
|
||||
0.768369f,-1.99237f,0.768369f,
|
||||
1.28852f,2.47058e-007f,1.28852f,
|
||||
0.768369f,1.99237f,-0.768369f,
|
||||
1.08664f,1.99237f,0.0f,
|
||||
0.0f,1.99237f,-1.08664f,
|
||||
-0.768369f,1.99237f,-0.768369f,
|
||||
0.0f,1.99237f,-1.08664f,
|
||||
-1.08664f,1.99237f,0.0f,
|
||||
-0.768369f,1.99237f,0.768369f,
|
||||
1.42495e-007f,1.99237f,1.08664f,
|
||||
0.768369f,1.99237f,0.768369f,
|
||||
1.42495e-007f,-1.99237f,1.08664f,
|
||||
-0.768369f,-1.99237f,0.76837f,
|
||||
-1.08664f,-1.99237f,1.82086e-007f,
|
||||
-0.768369f,-1.99237f,-0.768369f,
|
||||
0.0f,-1.99237f,-1.08664f,
|
||||
0.768369f,-1.99237f,-0.768369f,
|
||||
1.08664f,-1.99237f,0.0f,
|
||||
0.768369f,-1.99237f,0.768369f,
|
||||
0.768369f,1.99237f,-0.768369f,
|
||||
0.0f,1.99237f,-1.08664f,
|
||||
-0.768369f,1.99237f,-0.768369f,
|
||||
-1.08664f,1.99237f,0.0f,
|
||||
-0.768369f,1.99237f,0.768369f,
|
||||
1.42495e-007f,1.99237f,1.08664f,
|
||||
0.768369f,1.99237f,0.768369f,
|
||||
1.08664f,1.99237f,0.0f,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#define USE_GJK
|
||||
|
||||
#ifndef USE_GJK
|
||||
#include "btBulletCollisionCommon.h"
|
||||
|
||||
#endif //USE_GJK
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#ifdef WIN32 //needed for glut.h
|
||||
#include <windows.h>
|
||||
#endif
|
||||
//think different
|
||||
#if defined(__APPLE__) && !defined (VMDMESA)
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#include <GLUT/glut.h>
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#endif
|
||||
#include "GlutStuff.h"
|
||||
|
||||
|
||||
float yaw=0.f,pitch=0.f,roll=0.f;
|
||||
const int maxNumObjects = 4;
|
||||
const int numObjects = 2;
|
||||
|
||||
GL_Simplex1to4 simplex;
|
||||
|
||||
btConvexShape* shapePtr[maxNumObjects];
|
||||
|
||||
btTransform tr[numObjects];
|
||||
int screenWidth = 640.f;
|
||||
int screenHeight = 480.f;
|
||||
|
||||
void clientResetScene()
|
||||
{
|
||||
tr[0].setOrigin(btVector3(0.0f,3.f,7.f));
|
||||
tr[1].setOrigin(btVector3(0.0f,9.f,2.f));
|
||||
}
|
||||
|
||||
int debugMode = btIDebugDraw::DBG_DrawWireframe;
|
||||
GL_ShapeDrawer shapeDrawer;
|
||||
int m_glutScreenWidth=0;
|
||||
int m_glutScreenHeight=0;
|
||||
float m_frustumZNear = 1.f;
|
||||
float m_frustumZFar = 10000.f;
|
||||
bool m_ortho = false;
|
||||
|
||||
int myglutmain(int argc, char **argv,int width,int height,const char* title);
|
||||
|
||||
|
||||
void updateCamera() {
|
||||
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
btScalar rele = 0;
|
||||
btScalar razi = 0;
|
||||
btVector3 m_cameraUp(0,1,0);
|
||||
btScalar m_cameraDistance = 10.f;
|
||||
btVector3 m_cameraPosition;
|
||||
|
||||
|
||||
btVector3 m_cameraTargetPosition = (tr[0].getOrigin()+tr[1].getOrigin())*0.5;
|
||||
|
||||
|
||||
btQuaternion rot(m_cameraUp,razi);
|
||||
|
||||
|
||||
int m_forwardAxis = 2;
|
||||
|
||||
btVector3 eyePos(0,0,0);
|
||||
eyePos[m_forwardAxis] = -m_cameraDistance;
|
||||
|
||||
btVector3 forward(eyePos[0],eyePos[1],eyePos[2]);
|
||||
if (forward.length2() < SIMD_EPSILON)
|
||||
{
|
||||
forward.setValue(1.f,0.f,0.f);
|
||||
}
|
||||
btVector3 right = m_cameraUp.cross(forward);
|
||||
btQuaternion roll(right,-rele);
|
||||
|
||||
eyePos = btMatrix3x3(rot) * btMatrix3x3(roll) * eyePos;
|
||||
|
||||
m_cameraPosition[0] = eyePos.getX();
|
||||
m_cameraPosition[1] = eyePos.getY();
|
||||
m_cameraPosition[2] = eyePos.getZ();
|
||||
m_cameraPosition += m_cameraTargetPosition;
|
||||
|
||||
if (m_glutScreenWidth == 0 && m_glutScreenHeight == 0)
|
||||
return;
|
||||
|
||||
btScalar aspect;
|
||||
btVector3 extents;
|
||||
|
||||
if (m_glutScreenWidth > m_glutScreenHeight)
|
||||
{
|
||||
aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight;
|
||||
extents.setValue(aspect * 1.0f, 1.0f,0);
|
||||
} else
|
||||
{
|
||||
aspect = m_glutScreenHeight / (btScalar)m_glutScreenWidth;
|
||||
extents.setValue(1.0f, aspect*1.f,0);
|
||||
}
|
||||
|
||||
|
||||
if (m_ortho)
|
||||
{
|
||||
// reset matrix
|
||||
glLoadIdentity();
|
||||
|
||||
|
||||
extents *= m_cameraDistance;
|
||||
btVector3 lower = m_cameraTargetPosition - extents;
|
||||
btVector3 upper = m_cameraTargetPosition + extents;
|
||||
//gluOrtho2D(lower.x, upper.x, lower.y, upper.y);
|
||||
glOrtho(lower.getX(), upper.getX(), lower.getY(), upper.getY(),-1000,1000);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
//glTranslatef(100,210,0);
|
||||
} else
|
||||
{
|
||||
if (m_glutScreenWidth > m_glutScreenHeight)
|
||||
{
|
||||
// glFrustum (-aspect, aspect, -1.0, 1.0, 1.0, 10000.0);
|
||||
glFrustum (-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar);
|
||||
} else
|
||||
{
|
||||
// glFrustum (-1.0, 1.0, -aspect, aspect, 1.0, 10000.0);
|
||||
glFrustum (-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar);
|
||||
}
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(m_cameraPosition[0], m_cameraPosition[1], m_cameraPosition[2],
|
||||
m_cameraTargetPosition[0], m_cameraTargetPosition[1], m_cameraTargetPosition[2],
|
||||
m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
clientResetScene();
|
||||
|
||||
btMatrix3x3 basisA;
|
||||
basisA.setIdentity();
|
||||
|
||||
btMatrix3x3 basisB;
|
||||
basisB.setIdentity();
|
||||
|
||||
tr[0].setBasis(basisA);
|
||||
tr[1].setBasis(basisB);
|
||||
|
||||
btVector3 points0[3]={btVector3(1,0,0),btVector3(0,1,0),btVector3(0,0,1)};
|
||||
//btVector3 points1[5]={btVector3(1,0,0),btVector3(0,1,0),btVector3(0,0,1),btVector3(0,0,-1),btVector3(-1,-1,0)};
|
||||
|
||||
btConvexHullShape hullA(&points0[0].getX(),3);
|
||||
btConvexHullShape hullB(TaruVtx,TaruVtxCount,3*sizeof(btScalar));
|
||||
|
||||
shapePtr[0] = &hullA;
|
||||
shapePtr[1] = &hullB;
|
||||
|
||||
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
|
||||
|
||||
return myglutmain(argc, argv,screenWidth,screenHeight,"Convex Hull Distance Demo");
|
||||
}
|
||||
|
||||
|
||||
static btVoronoiSimplexSolver sGjkSimplexSolver;
|
||||
btSimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void clientDisplay(void) {
|
||||
|
||||
|
||||
updateCamera();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
//GL_ShapeDrawer::drawCoordSystem();
|
||||
|
||||
ATTRIBUTE_ALIGNED16(btScalar) m[16];
|
||||
int i;
|
||||
#ifdef USE_GJK
|
||||
btGjkEpaPenetrationDepthSolver epa;
|
||||
btGjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,&epa);
|
||||
|
||||
btVector3 seperatingAxis(0.00000000f,0.059727669f,0.29259586f);
|
||||
convexConvex.setCachedSeperatingAxis(seperatingAxis);
|
||||
|
||||
btPointCollector gjkOutput;
|
||||
btGjkPairDetector::ClosestPointInput input;
|
||||
input.m_transformA = tr[0];
|
||||
input.m_transformB = tr[1];
|
||||
|
||||
convexConvex.getClosestPoints(input ,gjkOutput,0);
|
||||
|
||||
if (gjkOutput.m_hasResult)
|
||||
{
|
||||
btVector3 endPt = gjkOutput.m_pointInWorld +
|
||||
gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1, 0, 0);
|
||||
glVertex3d(gjkOutput.m_pointInWorld.x(), gjkOutput.m_pointInWorld.y(),gjkOutput.m_pointInWorld.z());
|
||||
glVertex3d(endPt.x(),endPt.y(),endPt.z());
|
||||
glEnd();
|
||||
|
||||
}
|
||||
#else //USE_GJK
|
||||
|
||||
|
||||
struct MyContactResultCallback : public btCollisionWorld::ContactResultCallback
|
||||
{
|
||||
virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1)
|
||||
{
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1, 0, 0);
|
||||
|
||||
glVertex3d(cp.m_positionWorldOnA.getX(),cp.m_positionWorldOnA.getY(),cp.m_positionWorldOnA.getZ());
|
||||
glVertex3d(cp.m_positionWorldOnB.getX(),cp.m_positionWorldOnB.getY(),cp.m_positionWorldOnB.getZ());
|
||||
glEnd();
|
||||
|
||||
return 1.f;
|
||||
}
|
||||
};
|
||||
|
||||
btDefaultCollisionConfiguration collisionConfiguration;
|
||||
btCollisionDispatcher dispatcher(&collisionConfiguration);
|
||||
btDbvtBroadphase pairCache;
|
||||
btCollisionWorld world (&dispatcher,&pairCache,&collisionConfiguration);
|
||||
gContactBreakingThreshold=1e10f;
|
||||
|
||||
MyContactResultCallback result;
|
||||
btCollisionObject obA;
|
||||
obA.setCollisionShape(shapePtr[0]);
|
||||
obA.setWorldTransform(tr[0]);
|
||||
btCollisionObject obB;
|
||||
obB.setCollisionShape(shapePtr[1]);
|
||||
obB.setWorldTransform(tr[1]);
|
||||
world.contactPairTest(&obA,&obB,result);
|
||||
|
||||
#endif//USE_GJK
|
||||
|
||||
btVector3 worldMin(-1000,-1000,-1000);
|
||||
btVector3 worldMax(1000,1000,1000);
|
||||
|
||||
for (i=0;i<numObjects;i++)
|
||||
{
|
||||
|
||||
tr[i].getOpenGLMatrix( m );
|
||||
|
||||
if (debugMode)
|
||||
{
|
||||
/// for polyhedral shapes
|
||||
if (shapePtr[i]->isPolyhedral())
|
||||
{
|
||||
if (!shapePtr[i]->getUserPointer())
|
||||
{
|
||||
btConvexHullComputer* convexUtil = new btConvexHullComputer();
|
||||
shapePtr[i]->setUserPointer(convexUtil);
|
||||
|
||||
btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shapePtr[i];
|
||||
|
||||
btAlignedObjectArray<btVector3> vertices;
|
||||
vertices.resize(polyshape->getNumVertices());
|
||||
for (int i=0;i<polyshape->getNumVertices();i++)
|
||||
{
|
||||
polyshape->getVertex(i,vertices[i]);
|
||||
}
|
||||
|
||||
bool useDoublePrecision = false;
|
||||
convexUtil->compute(&vertices[0].getX(),sizeof(btVector3), polyshape->getNumVertices(),0,0);
|
||||
}
|
||||
|
||||
if (shapePtr[i]->getUserPointer())
|
||||
{
|
||||
btConvexHullComputer* convexUtil = (btConvexHullComputer*)shapePtr[i]->getUserPointer();
|
||||
//printf("num faces = %d\n",convexUtil->faces.size());
|
||||
for (int j=0;j<convexUtil->faces.size();j++)
|
||||
{
|
||||
int face = convexUtil->faces[j];
|
||||
//printf("face=%d\n",face);
|
||||
const btConvexHullComputer::Edge* firstEdge = &convexUtil->edges[face];
|
||||
const btConvexHullComputer::Edge* edge = firstEdge;
|
||||
|
||||
do
|
||||
{
|
||||
int src = edge->getSourceVertex();
|
||||
int targ = edge->getTargetVertex();
|
||||
//printf("src=%d target = %d\n", src,targ);
|
||||
|
||||
btVector3 wa = tr[i] * convexUtil->vertices[src];
|
||||
btVector3 wb = tr[i] * convexUtil->vertices[targ];
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1, 1, 1);
|
||||
glVertex3f(wa.getX(),wa.getY(),wa.getZ());
|
||||
glVertex3f(wb.getX(),wb.getY(),wb.getZ());
|
||||
glEnd();
|
||||
|
||||
edge = edge->getNextEdgeOfFace();
|
||||
} while (edge!=firstEdge);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
shapeDrawer.drawOpenGL(m,shapePtr[i],btVector3(1,1,1),debugMode, worldMin, worldMax);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
simplex.setSimplexSolver(&sGjkSimplexSolver);
|
||||
btVector3 ybuf[4],pbuf[4],qbuf[4];
|
||||
int numpoints = sGjkSimplexSolver.getSimplex(pbuf,qbuf,ybuf);
|
||||
simplex.reset();
|
||||
|
||||
for (i=0;i<numpoints;i++)
|
||||
simplex.addVertex(ybuf[i]);
|
||||
|
||||
btTransform ident;
|
||||
ident.setIdentity();
|
||||
ident.getOpenGLMatrix(m);
|
||||
shapeDrawer.drawOpenGL(m,&simplex,btVector3(1,1,1),debugMode, worldMin,worldMax);
|
||||
|
||||
|
||||
btQuaternion orn;
|
||||
orn.setEuler(yaw,pitch,roll);
|
||||
tr[0].setRotation(orn);
|
||||
tr[1].setRotation(orn);
|
||||
|
||||
pitch += 0.005f;
|
||||
yaw += 0.01f;
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
void clientMoveAndDisplay()
|
||||
{
|
||||
clientDisplay();
|
||||
}
|
||||
|
||||
static void glutReshapeCallback(int w, int h)
|
||||
{
|
||||
m_glutScreenWidth=w;
|
||||
m_glutScreenHeight=h;
|
||||
}
|
||||
|
||||
|
||||
int myglutmain(int argc, char **argv,int width,int height,const char* title) {
|
||||
|
||||
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
|
||||
glutInitWindowPosition(0, 0);
|
||||
glutInitWindowSize(width, height);
|
||||
|
||||
glutCreateWindow(title);
|
||||
#ifdef BT_USE_FREEGLUT
|
||||
glutSetOption (GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
|
||||
#endif
|
||||
|
||||
|
||||
glutIdleFunc( clientDisplay );
|
||||
glutDisplayFunc( clientDisplay );
|
||||
glutReshapeFunc(glutReshapeCallback);
|
||||
|
||||
//enable vsync to avoid tearing on Apple (todo: for Windows)
|
||||
|
||||
#if defined(__APPLE__) && !defined (VMDMESA)
|
||||
int swap_interval = 1;
|
||||
CGLContextObj cgl_context = CGLGetCurrentContext();
|
||||
CGLSetParameter(cgl_context, kCGLCPSwapInterval, &swap_interval);
|
||||
#endif
|
||||
|
||||
GLfloat light_ambient[] = { btScalar(0.2), btScalar(0.2), btScalar(0.2), btScalar(1.0) };
|
||||
GLfloat light_diffuse[] = { btScalar(1.0), btScalar(1.0), btScalar(1.0), btScalar(1.0) };
|
||||
GLfloat light_specular[] = { btScalar(1.0), btScalar(1.0), btScalar(1.0), btScalar(1.0 )};
|
||||
/* light_position is NOT default value */
|
||||
GLfloat light_position0[] = { btScalar(1.0), btScalar(10.0), btScalar(1.0), btScalar(0.0 )};
|
||||
GLfloat light_position1[] = { btScalar(-1.0), btScalar(-10.0), btScalar(-1.0), btScalar(0.0) };
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHT1);
|
||||
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
glClearColor(btScalar(0.7),btScalar(0.7),btScalar(0.7),btScalar(0));
|
||||
|
||||
|
||||
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppDoublePrecisionDemo
|
||||
DoublePrecisionDemo.cpp
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppDoublePrecisionDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppDoublePrecisionDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppDoublePrecisionDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,280 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
///
|
||||
/// DoublePrecisionDemo shows high level usage of the Collision Detection.
|
||||
///
|
||||
|
||||
#include "GL_Simplex1to4.h"
|
||||
|
||||
//include common Bullet Collision Detection headerfiles
|
||||
#include "btBulletCollisionCommon.h"
|
||||
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "GLDebugFont.h"
|
||||
|
||||
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "DoublePrecisionDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
btScalar yaw=btScalar(0.);
|
||||
btScalar pitch=btScalar(0.);
|
||||
btScalar roll=btScalar(0.);
|
||||
const int maxNumObjects = 4;
|
||||
const int numObjects = 2;
|
||||
|
||||
GL_Simplex1to4 simplex;
|
||||
|
||||
|
||||
btCollisionObject objects[maxNumObjects];
|
||||
btCollisionWorld* collisionWorld = 0;
|
||||
|
||||
// so pixel ratio is 1:1
|
||||
int screenWidth = 640;
|
||||
int screenHeight = 640;
|
||||
GLDebugDrawer debugDrawer;
|
||||
|
||||
const btScalar LARGE_DISTANCE_FROM_ORIGIN = btScalar(999999.0);
|
||||
const btScalar VERY_SMALL_INCREMENT = btScalar(0.000009);
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
DoublePrecisionDemo* doublePrecisionDemo = new DoublePrecisionDemo();
|
||||
|
||||
doublePrecisionDemo->initPhysics();
|
||||
doublePrecisionDemo->setCameraDistance(btScalar(2.0));
|
||||
|
||||
doublePrecisionDemo->clientResetScene();
|
||||
|
||||
return glutmain(argc, argv,screenWidth,screenHeight,"Double Precision Demo",doublePrecisionDemo);
|
||||
}
|
||||
|
||||
void DoublePrecisionDemo::initPhysics()
|
||||
{
|
||||
m_debugMode |= btIDebugDraw::DBG_DrawWireframe;
|
||||
|
||||
btMatrix3x3 basisA;
|
||||
basisA.setIdentity();
|
||||
|
||||
btMatrix3x3 basisB;
|
||||
basisB.setIdentity();
|
||||
|
||||
objects[0].getWorldTransform().setBasis(basisA);
|
||||
objects[1].getWorldTransform().setBasis(basisB);
|
||||
|
||||
|
||||
btBoxShape* boxA = new btBoxShape(btVector3(0.5,0.5,0.5));
|
||||
btBoxShape* boxB = new btBoxShape(btVector3(0.5,0.5,0.5));
|
||||
|
||||
objects[0].setCollisionShape(boxA);//&hullA;
|
||||
objects[1].setCollisionShape(boxB);//&hullB;
|
||||
|
||||
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
|
||||
btVector3 worldAabbMin(80000,80000,80000);
|
||||
btVector3 worldAabbMax(120000,120000,120000);
|
||||
|
||||
btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
|
||||
|
||||
collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);
|
||||
|
||||
collisionWorld->addCollisionObject(&objects[0]);
|
||||
collisionWorld->addCollisionObject(&objects[1]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//to be implemented by the demo
|
||||
|
||||
void DoublePrecisionDemo::clientMoveAndDisplay()
|
||||
{
|
||||
|
||||
displayCallback();
|
||||
}
|
||||
|
||||
|
||||
static btVoronoiSimplexSolver sGjkSimplexSolver;
|
||||
btSimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
|
||||
|
||||
void DoublePrecisionDemo::displayCallback(void)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
collisionWorld->getDispatchInfo().m_debugDraw = &debugDrawer;
|
||||
|
||||
if (collisionWorld)
|
||||
collisionWorld->performDiscreteCollisionDetection();
|
||||
|
||||
int i;
|
||||
|
||||
btVector3 worldBoundsMin,worldBoundsMax;
|
||||
collisionWorld->getBroadphase()->getBroadphaseAabb(worldBoundsMin,worldBoundsMax);
|
||||
|
||||
|
||||
///one way to draw all the contact points is iterating over contact manifolds / points:
|
||||
int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
|
||||
for (i=0;i<numManifolds;i++)
|
||||
{
|
||||
btPersistentManifold* contactManifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
|
||||
const btCollisionObject* obA = static_cast<const btCollisionObject*>(contactManifold->getBody0());
|
||||
const btCollisionObject* obB = static_cast<const btCollisionObject*>(contactManifold->getBody1());
|
||||
contactManifold->refreshContactPoints(obA->getWorldTransform(),obB->getWorldTransform());
|
||||
|
||||
int numContacts = contactManifold->getNumContacts();
|
||||
for (int j=0;j<numContacts;j++)
|
||||
{
|
||||
btManifoldPoint& pt = contactManifold->getContactPoint(j);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1, 1, 1);
|
||||
|
||||
btVector3 ptA = pt.getPositionWorldOnA() - m_cameraPosition;
|
||||
btVector3 ptB = pt.getPositionWorldOnB() - m_cameraPosition;
|
||||
|
||||
glVertex3d(ptA.x(),ptA.y(),ptA.z());
|
||||
glVertex3d(ptB.x(),ptB.y(),ptB.z());
|
||||
glEnd();
|
||||
}
|
||||
|
||||
//you can un-comment out this line, and then all points are removed
|
||||
//contactManifold->clearManifold();
|
||||
}
|
||||
|
||||
btScalar m[16];
|
||||
btTransform temp;
|
||||
|
||||
|
||||
btVector3 color;
|
||||
//int i;
|
||||
for (i=0;i<numObjects;i++)
|
||||
{
|
||||
if (i % 2)
|
||||
{
|
||||
color = btVector3(1,0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = btVector3(0,0,1);
|
||||
}
|
||||
temp = objects[i].getWorldTransform();
|
||||
temp.setOrigin(temp.getOrigin() - m_cameraPosition);
|
||||
temp.getOpenGLMatrix( m );
|
||||
m_shapeDrawer->drawOpenGL(m,objects[i].getCollisionShape(),color,getDebugMode(),worldBoundsMin,worldBoundsMax);
|
||||
}
|
||||
|
||||
objects[1].getWorldTransform().setOrigin(objects[1].getWorldTransform().getOrigin()+btVector3(-VERY_SMALL_INCREMENT,-VERY_SMALL_INCREMENT,0));
|
||||
objects[0].getWorldTransform().setOrigin(objects[0].getWorldTransform().getOrigin()+btVector3(VERY_SMALL_INCREMENT,VERY_SMALL_INCREMENT,0));
|
||||
|
||||
float yStart = 20.f;
|
||||
float yIncr = 20.f;
|
||||
char buf[124];
|
||||
|
||||
glColor3f(0, 0, 0);
|
||||
|
||||
setOrthographicProjection();
|
||||
|
||||
glRasterPos3f(10.0f,yStart,0);
|
||||
#ifdef BT_USE_DOUBLE_PRECISION
|
||||
GLDebugDrawString(10.f,yStart,"Double Precision Mode");
|
||||
#else
|
||||
GLDebugDrawString(10.f,yStart,"Single Precision Mode");
|
||||
#endif
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(10.0f,yStart,0);
|
||||
sprintf(buf,"Movement distance in x and y axis = %lf", VERY_SMALL_INCREMENT);
|
||||
|
||||
GLDebugDrawString(10.f,yStart,buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(10.0f,yStart,0);
|
||||
btScalar xValue = objects[0].getWorldTransform().getOrigin().x();
|
||||
btScalar yValue = objects[0].getWorldTransform().getOrigin().y();
|
||||
btScalar zValue = objects[0].getWorldTransform().getOrigin().z();
|
||||
sprintf(buf,"Cube 0 location = ( %lf, %lf, %lf )", xValue, yValue, zValue);
|
||||
GLDebugDrawString(10.f,yStart,buf);
|
||||
yStart += yIncr;
|
||||
|
||||
xValue = objects[1].getWorldTransform().getOrigin().x();
|
||||
yValue = objects[1].getWorldTransform().getOrigin().y();
|
||||
zValue = objects[1].getWorldTransform().getOrigin().z();
|
||||
glRasterPos3f(10.0f,yStart,0);
|
||||
sprintf(buf,"Cube 1 location = ( %lf, %lf, %lf )", xValue, yValue, zValue);
|
||||
GLDebugDrawString(10.f,yStart,buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(10.0f,yStart,0);
|
||||
GLDebugDrawString(10.f,yStart,"w=toggle wireframe/solid");
|
||||
|
||||
resetPerspectiveProjection();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
void DoublePrecisionDemo::clientResetScene()
|
||||
{
|
||||
objects[0].getWorldTransform().setOrigin(btVector3(LARGE_DISTANCE_FROM_ORIGIN,LARGE_DISTANCE_FROM_ORIGIN,LARGE_DISTANCE_FROM_ORIGIN));
|
||||
objects[1].getWorldTransform().setOrigin(btVector3(LARGE_DISTANCE_FROM_ORIGIN-VERY_SMALL_INCREMENT,LARGE_DISTANCE_FROM_ORIGIN-VERY_SMALL_INCREMENT,LARGE_DISTANCE_FROM_ORIGIN));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DoublePrecisionDemo::updateCamera()
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
// look at the stationary cube
|
||||
m_cameraTargetPosition = objects[0].getWorldTransform().getOrigin();
|
||||
|
||||
m_cameraPosition = m_cameraTargetPosition;
|
||||
m_cameraPosition[2] = m_cameraTargetPosition[2] - m_cameraDistance;
|
||||
|
||||
//update OpenGL camera settings
|
||||
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10000.0);
|
||||
|
||||
// To not loose precision in the rendering process, we shift the object to the origin
|
||||
gluLookAt(0.0, 0.0, 0.0,
|
||||
m_cameraTargetPosition[0]-m_cameraPosition[0],m_cameraTargetPosition[1]-m_cameraPosition[1], m_cameraTargetPosition[2]-m_cameraPosition[2],
|
||||
m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ());
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
void DoublePrecisionDemo::keyboardCallback(unsigned char key, int x, int y)
|
||||
{
|
||||
if (key == 'w')
|
||||
{
|
||||
if (m_debugMode & btIDebugDraw::DBG_DrawWireframe)
|
||||
{
|
||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawWireframe);
|
||||
m_debugMode |= btIDebugDraw::DBG_DrawAabb;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawAabb);
|
||||
m_debugMode |= btIDebugDraw::DBG_DrawWireframe;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
DemoApplication::keyboardCallback(key, x, y);
|
||||
}
|
||||
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 COLLISION_INTERFACE_DEMO_H
|
||||
#define COLLISION_INTERFACE_DEMO_H
|
||||
|
||||
#include "GlutDemoApplication.h"
|
||||
|
||||
///DoublePrecisionDemo shows how to use the collision detection without dynamics (btCollisionWorld/CollisionObject)
|
||||
class DoublePrecisionDemo : public GlutDemoApplication
|
||||
{
|
||||
public:
|
||||
|
||||
void initPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
virtual void updateCamera();
|
||||
|
||||
virtual void keyboardCallback(unsigned char key, int x, int y);
|
||||
|
||||
};
|
||||
|
||||
#endif //COLLISION_INTERFACE_DEMO_H
|
||||
|
||||
|
@ -1,34 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppMotorDemo
|
||||
MotorDemo.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppMotorDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppMotorDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppMotorDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,468 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library Copyright (c) 2007 Erwin Coumans
|
||||
Motor Demo
|
||||
|
||||
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 "btBulletDynamicsCommon.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "MotorDemo.h"
|
||||
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
#ifndef M_PI_2
|
||||
#define M_PI_2 1.57079632679489661923
|
||||
#endif
|
||||
|
||||
#ifndef M_PI_4
|
||||
#define M_PI_4 0.785398163397448309616
|
||||
#endif
|
||||
|
||||
#ifndef M_PI_8
|
||||
#define M_PI_8 0.5 * M_PI_4
|
||||
#endif
|
||||
|
||||
|
||||
// LOCAL FUNCTIONS
|
||||
|
||||
void vertex(btVector3 &v)
|
||||
{
|
||||
glVertex3d(v.getX(), v.getY(), v.getZ());
|
||||
}
|
||||
|
||||
void drawFrame(btTransform &tr)
|
||||
{
|
||||
const float fSize = 1.f;
|
||||
|
||||
glBegin(GL_LINES);
|
||||
|
||||
// x
|
||||
glColor3f(255.f,0,0);
|
||||
btVector3 vX = tr*btVector3(fSize,0,0);
|
||||
vertex(tr.getOrigin()); vertex(vX);
|
||||
|
||||
// y
|
||||
glColor3f(0,255.f,0);
|
||||
btVector3 vY = tr*btVector3(0,fSize,0);
|
||||
vertex(tr.getOrigin()); vertex(vY);
|
||||
|
||||
// z
|
||||
glColor3f(0,0,255.f);
|
||||
btVector3 vZ = tr*btVector3(0,0,fSize);
|
||||
vertex(tr.getOrigin()); vertex(vZ);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
// /LOCAL FUNCTIONS
|
||||
|
||||
|
||||
|
||||
#define NUM_LEGS 6
|
||||
#define BODYPART_COUNT 2 * NUM_LEGS + 1
|
||||
#define JOINT_COUNT BODYPART_COUNT - 1
|
||||
|
||||
class TestRig
|
||||
{
|
||||
btDynamicsWorld* m_ownerWorld;
|
||||
btCollisionShape* m_shapes[BODYPART_COUNT];
|
||||
btRigidBody* m_bodies[BODYPART_COUNT];
|
||||
btTypedConstraint* m_joints[JOINT_COUNT];
|
||||
|
||||
btRigidBody* localCreateRigidBody (btScalar mass, const btTransform& startTransform, btCollisionShape* shape)
|
||||
{
|
||||
bool isDynamic = (mass != 0.f);
|
||||
|
||||
btVector3 localInertia(0,0,0);
|
||||
if (isDynamic)
|
||||
shape->calculateLocalInertia(mass,localInertia);
|
||||
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
|
||||
m_ownerWorld->addRigidBody(body);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
TestRig (btDynamicsWorld* ownerWorld, const btVector3& positionOffset, bool bFixed)
|
||||
: m_ownerWorld (ownerWorld)
|
||||
{
|
||||
btVector3 vUp(0, 1, 0);
|
||||
|
||||
//
|
||||
// Setup geometry
|
||||
//
|
||||
float fBodySize = 0.25f;
|
||||
float fLegLength = 0.45f;
|
||||
float fForeLegLength = 0.75f;
|
||||
m_shapes[0] = new btCapsuleShape(btScalar(fBodySize), btScalar(0.10));
|
||||
int i;
|
||||
for ( i=0; i<NUM_LEGS; i++)
|
||||
{
|
||||
m_shapes[1 + 2*i] = new btCapsuleShape(btScalar(0.10), btScalar(fLegLength));
|
||||
m_shapes[2 + 2*i] = new btCapsuleShape(btScalar(0.08), btScalar(fForeLegLength));
|
||||
}
|
||||
|
||||
//
|
||||
// Setup rigid bodies
|
||||
//
|
||||
float fHeight = 0.5;
|
||||
btTransform offset; offset.setIdentity();
|
||||
offset.setOrigin(positionOffset);
|
||||
|
||||
// root
|
||||
btVector3 vRoot = btVector3(btScalar(0.), btScalar(fHeight), btScalar(0.));
|
||||
btTransform transform;
|
||||
transform.setIdentity();
|
||||
transform.setOrigin(vRoot);
|
||||
if (bFixed)
|
||||
{
|
||||
m_bodies[0] = localCreateRigidBody(btScalar(0.), offset*transform, m_shapes[0]);
|
||||
} else
|
||||
{
|
||||
m_bodies[0] = localCreateRigidBody(btScalar(1.), offset*transform, m_shapes[0]);
|
||||
}
|
||||
// legs
|
||||
for ( i=0; i<NUM_LEGS; i++)
|
||||
{
|
||||
float fAngle = 2 * M_PI * i / NUM_LEGS;
|
||||
float fSin = sin(fAngle);
|
||||
float fCos = cos(fAngle);
|
||||
|
||||
transform.setIdentity();
|
||||
btVector3 vBoneOrigin = btVector3(btScalar(fCos*(fBodySize+0.5*fLegLength)), btScalar(fHeight), btScalar(fSin*(fBodySize+0.5*fLegLength)));
|
||||
transform.setOrigin(vBoneOrigin);
|
||||
|
||||
// thigh
|
||||
btVector3 vToBone = (vBoneOrigin - vRoot).normalize();
|
||||
btVector3 vAxis = vToBone.cross(vUp);
|
||||
transform.setRotation(btQuaternion(vAxis, M_PI_2));
|
||||
m_bodies[1+2*i] = localCreateRigidBody(btScalar(1.), offset*transform, m_shapes[1+2*i]);
|
||||
|
||||
// shin
|
||||
transform.setIdentity();
|
||||
transform.setOrigin(btVector3(btScalar(fCos*(fBodySize+fLegLength)), btScalar(fHeight-0.5*fForeLegLength), btScalar(fSin*(fBodySize+fLegLength))));
|
||||
m_bodies[2+2*i] = localCreateRigidBody(btScalar(1.), offset*transform, m_shapes[2+2*i]);
|
||||
}
|
||||
|
||||
// Setup some damping on the m_bodies
|
||||
for (i = 0; i < BODYPART_COUNT; ++i)
|
||||
{
|
||||
m_bodies[i]->setDamping(0.05, 0.85);
|
||||
m_bodies[i]->setDeactivationTime(0.8);
|
||||
//m_bodies[i]->setSleepingThresholds(1.6, 2.5);
|
||||
m_bodies[i]->setSleepingThresholds(0.5f, 0.5f);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Setup the constraints
|
||||
//
|
||||
btHingeConstraint* hingeC;
|
||||
//btConeTwistConstraint* coneC;
|
||||
|
||||
btTransform localA, localB, localC;
|
||||
|
||||
for ( i=0; i<NUM_LEGS; i++)
|
||||
{
|
||||
float fAngle = 2 * M_PI * i / NUM_LEGS;
|
||||
float fSin = sin(fAngle);
|
||||
float fCos = cos(fAngle);
|
||||
|
||||
// hip joints
|
||||
localA.setIdentity(); localB.setIdentity();
|
||||
localA.getBasis().setEulerZYX(0,-fAngle,0); localA.setOrigin(btVector3(btScalar(fCos*fBodySize), btScalar(0.), btScalar(fSin*fBodySize)));
|
||||
localB = m_bodies[1+2*i]->getWorldTransform().inverse() * m_bodies[0]->getWorldTransform() * localA;
|
||||
hingeC = new btHingeConstraint(*m_bodies[0], *m_bodies[1+2*i], localA, localB);
|
||||
hingeC->setLimit(btScalar(-0.75 * M_PI_4), btScalar(M_PI_8));
|
||||
//hingeC->setLimit(btScalar(-0.1), btScalar(0.1));
|
||||
m_joints[2*i] = hingeC;
|
||||
m_ownerWorld->addConstraint(m_joints[2*i], true);
|
||||
|
||||
// knee joints
|
||||
localA.setIdentity(); localB.setIdentity(); localC.setIdentity();
|
||||
localA.getBasis().setEulerZYX(0,-fAngle,0); localA.setOrigin(btVector3(btScalar(fCos*(fBodySize+fLegLength)), btScalar(0.), btScalar(fSin*(fBodySize+fLegLength))));
|
||||
localB = m_bodies[1+2*i]->getWorldTransform().inverse() * m_bodies[0]->getWorldTransform() * localA;
|
||||
localC = m_bodies[2+2*i]->getWorldTransform().inverse() * m_bodies[0]->getWorldTransform() * localA;
|
||||
hingeC = new btHingeConstraint(*m_bodies[1+2*i], *m_bodies[2+2*i], localB, localC);
|
||||
//hingeC->setLimit(btScalar(-0.01), btScalar(0.01));
|
||||
hingeC->setLimit(btScalar(-M_PI_8), btScalar(0.2));
|
||||
m_joints[1+2*i] = hingeC;
|
||||
m_ownerWorld->addConstraint(m_joints[1+2*i], true);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~TestRig ()
|
||||
{
|
||||
int i;
|
||||
|
||||
// Remove all constraints
|
||||
for ( i = 0; i < JOINT_COUNT; ++i)
|
||||
{
|
||||
m_ownerWorld->removeConstraint(m_joints[i]);
|
||||
delete m_joints[i]; m_joints[i] = 0;
|
||||
}
|
||||
|
||||
// Remove all bodies and shapes
|
||||
for ( i = 0; i < BODYPART_COUNT; ++i)
|
||||
{
|
||||
m_ownerWorld->removeRigidBody(m_bodies[i]);
|
||||
|
||||
delete m_bodies[i]->getMotionState();
|
||||
|
||||
delete m_bodies[i]; m_bodies[i] = 0;
|
||||
delete m_shapes[i]; m_shapes[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
btTypedConstraint** GetJoints() {return &m_joints[0];}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
void motorPreTickCallback (btDynamicsWorld *world, btScalar timeStep)
|
||||
{
|
||||
MotorDemo* motorDemo = (MotorDemo*)world->getWorldUserInfo();
|
||||
|
||||
motorDemo->setMotorTargets(timeStep);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MotorDemo::initPhysics()
|
||||
{
|
||||
setTexturing(true);
|
||||
setShadows(true);
|
||||
|
||||
// Setup the basic world
|
||||
|
||||
m_Time = 0;
|
||||
m_fCyclePeriod = 2000.f; // in milliseconds
|
||||
|
||||
// m_fMuscleStrength = 0.05f;
|
||||
// new SIMD solver for joints clips accumulated impulse, so the new limits for the motor
|
||||
// should be (numberOfsolverIterations * oldLimits)
|
||||
// currently solver uses 10 iterations, so:
|
||||
m_fMuscleStrength = 0.5f;
|
||||
|
||||
setCameraDistance(btScalar(5.));
|
||||
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
|
||||
btVector3 worldAabbMin(-10000,-10000,-10000);
|
||||
btVector3 worldAabbMax(10000,10000,10000);
|
||||
m_broadphase = new btAxisSweep3 (worldAabbMin, worldAabbMax);
|
||||
|
||||
m_solver = new btSequentialImpulseConstraintSolver;
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
|
||||
m_dynamicsWorld->setInternalTickCallback(motorPreTickCallback,this,true);
|
||||
|
||||
|
||||
// Setup a big ground box
|
||||
{
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(200.),btScalar(10.),btScalar(200.)));
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
btTransform groundTransform;
|
||||
groundTransform.setIdentity();
|
||||
groundTransform.setOrigin(btVector3(0,-10,0));
|
||||
localCreateRigidBody(btScalar(0.),groundTransform,groundShape);
|
||||
}
|
||||
|
||||
// Spawn one ragdoll
|
||||
btVector3 startOffset(1,0.5,0);
|
||||
spawnTestRig(startOffset, false);
|
||||
startOffset.setValue(-2,0.5,0);
|
||||
spawnTestRig(startOffset, true);
|
||||
|
||||
clientResetScene();
|
||||
}
|
||||
|
||||
|
||||
void MotorDemo::spawnTestRig(const btVector3& startOffset, bool bFixed)
|
||||
{
|
||||
TestRig* rig = new TestRig(m_dynamicsWorld, startOffset, bFixed);
|
||||
m_rigs.push_back(rig);
|
||||
}
|
||||
|
||||
void PreStep()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MotorDemo::setMotorTargets(btScalar deltaTime)
|
||||
{
|
||||
|
||||
float ms = deltaTime*1000000.;
|
||||
float minFPS = 1000000.f/60.f;
|
||||
if (ms > minFPS)
|
||||
ms = minFPS;
|
||||
|
||||
m_Time += ms;
|
||||
|
||||
//
|
||||
// set per-frame sinusoidal position targets using angular motor (hacky?)
|
||||
//
|
||||
for (int r=0; r<m_rigs.size(); r++)
|
||||
{
|
||||
for (int i=0; i<2*NUM_LEGS; i++)
|
||||
{
|
||||
btHingeConstraint* hingeC = static_cast<btHingeConstraint*>(m_rigs[r]->GetJoints()[i]);
|
||||
btScalar fCurAngle = hingeC->getHingeAngle();
|
||||
|
||||
btScalar fTargetPercent = (int(m_Time / 1000) % int(m_fCyclePeriod)) / m_fCyclePeriod;
|
||||
btScalar fTargetAngle = 0.5 * (1 + sin(2 * M_PI * fTargetPercent));
|
||||
btScalar fTargetLimitAngle = hingeC->getLowerLimit() + fTargetAngle * (hingeC->getUpperLimit() - hingeC->getLowerLimit());
|
||||
btScalar fAngleError = fTargetLimitAngle - fCurAngle;
|
||||
btScalar fDesiredAngularVel = 1000000.f * fAngleError/ms;
|
||||
hingeC->enableAngularMotor(true, fDesiredAngularVel, m_fMuscleStrength);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void MotorDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//simple dynamics world doesn't handle fixed-time-stepping
|
||||
float deltaTime = getDeltaTimeMicroseconds()/1000000.f;
|
||||
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
}
|
||||
|
||||
renderme();
|
||||
|
||||
for (int i=2; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
drawFrame(body->getWorldTransform());
|
||||
}
|
||||
|
||||
glFlush();
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
void MotorDemo::displayCallback()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
void MotorDemo::keyboardCallback(unsigned char key, int x, int y)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case '+': case '=':
|
||||
m_fCyclePeriod /= 1.1f;
|
||||
if (m_fCyclePeriod < 1.f)
|
||||
m_fCyclePeriod = 1.f;
|
||||
break;
|
||||
case '-': case '_':
|
||||
m_fCyclePeriod *= 1.1f;
|
||||
break;
|
||||
case '[':
|
||||
m_fMuscleStrength /= 1.1f;
|
||||
break;
|
||||
case ']':
|
||||
m_fMuscleStrength *= 1.1f;
|
||||
break;
|
||||
default:
|
||||
DemoApplication::keyboardCallback(key, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MotorDemo::exitPhysics()
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
for (i=0;i<m_rigs.size();i++)
|
||||
{
|
||||
TestRig* rig = m_rigs[i];
|
||||
delete rig;
|
||||
}
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
//delete solver
|
||||
delete m_solver;
|
||||
|
||||
//delete broadphase
|
||||
delete m_broadphase;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library Copyright (c) 2007 Erwin Coumans
|
||||
Motor Demo
|
||||
|
||||
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 MOTORDEMO_H
|
||||
#define MOTORDEMO_H
|
||||
|
||||
#include "GlutDemoApplication.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
|
||||
class MotorDemo : public GlutDemoApplication
|
||||
{
|
||||
float m_Time;
|
||||
float m_fCyclePeriod; // in milliseconds
|
||||
float m_fMuscleStrength;
|
||||
|
||||
btAlignedObjectArray<class TestRig*> m_rigs;
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
public:
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual ~MotorDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
|
||||
void spawnTestRig(const btVector3& startOffset, bool bFixed);
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void keyboardCallback(unsigned char key, int x, int y);
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
MotorDemo* demo = new MotorDemo();
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
|
||||
void setMotorTargets(btScalar deltaTime);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,855 +0,0 @@
|
||||
|
||||
///contribution by Pierre Terdiman to check penetration depth solvers
|
||||
///see http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=638
|
||||
|
||||
#ifdef WIN32//for glut.h
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
//think different
|
||||
#if defined(__APPLE__) && !defined (VMDMESA)
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#include <GLUT/glut.h>
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#define VERBOSE_TEXT_ONSCREEN 1
|
||||
#ifdef VERBOSE_TEXT_ONSCREEN
|
||||
#include "GLDebugFont.h"
|
||||
#endif
|
||||
|
||||
#include "btBulletCollisionCommon.h"
|
||||
|
||||
#include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
|
||||
|
||||
|
||||
//We can use the Bullet EPA or sampling penetration depth solver, but comparison might be useful
|
||||
//#define COMPARE_WITH_SOLID35_AND_OTHER_EPA 1
|
||||
#ifdef COMPARE_WITH_SOLID35_AND_OTHER_EPA
|
||||
#include "../Extras/ExtraSolid35/Solid3EpaPenetrationDepth.h"
|
||||
#include "../Extras/ExtraSolid35/Solid3JohnsonSimplexSolver.h"
|
||||
#include "../Extras/EPA/EpaPenetrationDepthSolver.h"
|
||||
#endif //COMPARE_WITH_SOLID35_AND_OTHER_EPA
|
||||
|
||||
#define USE_ORIGINAL 1
|
||||
#ifndef USE_ORIGINAL
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
|
||||
#endif //USE_ORIGINAL
|
||||
|
||||
static bool gRefMode = false;
|
||||
static int gMethod = 0;
|
||||
static int gLastUsedMethod = -1;
|
||||
static int gNumGjkIterations = -1;
|
||||
static int gLastDegenerateSimplex = -1;
|
||||
|
||||
static const float gDisp = 0.01f;
|
||||
static const float gCamSpeed = 0.1f;
|
||||
static btVector3 Eye(3.0616338f, 1.1985892f, 2.5769043f);
|
||||
static btVector3 Dir(-0.66853905,-0.14004262,-0.73037237);
|
||||
static btVector3 N;
|
||||
static int mx = 0;
|
||||
static int my = 0;
|
||||
static int glutScreenHeight = 512;
|
||||
static int glutScreenWidth = 512;
|
||||
|
||||
static void DrawLine(const btVector3& p0, const btVector3& p1, const btVector3& color, float line_width)
|
||||
{
|
||||
glDisable(GL_LIGHTING);
|
||||
glLineWidth(line_width);
|
||||
glColor4f(color.x(), color.y(), color.z(), 1.0f);
|
||||
btVector3 tmp[] = {p0, p1};
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
#ifndef BT_USE_DOUBLE_PRECISION
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(btVector3), &tmp[0].x());
|
||||
#else
|
||||
glVertexPointer(3, GL_DOUBLE, sizeof(btVector3), &tmp[0].x());
|
||||
#endif
|
||||
glDrawArrays(GL_LINES, 0, 2);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
void DrawTriangle(const btVector3& p0, const btVector3& p1, const btVector3& p2, const btVector3& color)
|
||||
{
|
||||
// glDisable(GL_LIGHTING);
|
||||
glColor4f(color.x(), color.y(), color.z(), 1.0f);
|
||||
btVector3 tmp[] = {p0, p1, p2};
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
#ifndef BT_USE_DOUBLE_PRECISION
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(btVector3), &tmp[0].x());
|
||||
#else
|
||||
glVertexPointer(3, GL_DOUBLE, sizeof(btVector3), &tmp[0].x());
|
||||
#endif
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
// glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
// glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
class MyPoly
|
||||
{
|
||||
public:
|
||||
MyPoly() : mNbVerts(0), mIndices(NULL) {}
|
||||
~MyPoly() { delete[]mIndices; }
|
||||
|
||||
short mNbVerts;
|
||||
char* mIndices;
|
||||
float mPlane[4];
|
||||
};
|
||||
|
||||
class MyConvex
|
||||
{
|
||||
public:
|
||||
MyConvex();
|
||||
~MyConvex();
|
||||
|
||||
bool LoadFromFile(const char* filename);
|
||||
void Render(bool only_wireframe, const btVector3& wire_color) const;
|
||||
void Project(const btVector3& dir, float& min, float& max) const;
|
||||
|
||||
int mNbVerts;
|
||||
btVector3* mVerts;
|
||||
int mNbPolys;
|
||||
MyPoly* mPolys;
|
||||
btTransform mTransform;
|
||||
};
|
||||
|
||||
MyConvex::MyConvex() :
|
||||
mNbVerts (0),
|
||||
mVerts (NULL),
|
||||
mNbPolys (0),
|
||||
mPolys (NULL)
|
||||
{
|
||||
mTransform.setIdentity();
|
||||
}
|
||||
|
||||
MyConvex::~MyConvex()
|
||||
{
|
||||
delete[]mPolys;
|
||||
delete[]mVerts;
|
||||
}
|
||||
|
||||
bool MyConvex::LoadFromFile(const char* filename)
|
||||
{
|
||||
FILE* fp = fopen(filename, "rb");
|
||||
if(!fp) return false;
|
||||
|
||||
fread(&mNbVerts, sizeof(int), 1, fp);
|
||||
|
||||
int i;
|
||||
|
||||
mVerts = new btVector3[mNbVerts];
|
||||
for( i=0;i<mNbVerts;i++)
|
||||
{
|
||||
float vals[3];
|
||||
fread(vals, sizeof(float)*3, 1, fp);
|
||||
mVerts[i].setX(vals[0]);
|
||||
mVerts[i].setY(vals[1]);
|
||||
mVerts[i].setZ(vals[2]);
|
||||
}
|
||||
|
||||
fread(&mNbPolys, sizeof(int), 1, fp);
|
||||
mPolys = new MyPoly[mNbPolys];
|
||||
|
||||
for(i=0;i<mNbPolys;i++)
|
||||
{
|
||||
fread(&mPolys[i].mNbVerts, sizeof(short), 1, fp);
|
||||
mPolys[i].mIndices = new char[mPolys[i].mNbVerts];
|
||||
fread(mPolys[i].mIndices, mPolys[i].mNbVerts, 1, fp);
|
||||
fread(mPolys[i].mPlane, sizeof(float)*4, 1, fp);
|
||||
}
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//See http://www.lighthouse3d.com/opengl/glut/index.php?bmpfontortho
|
||||
static void setOrthographicProjection()
|
||||
{
|
||||
|
||||
// switch to projection mode
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
// save previous matrix which contains the
|
||||
//settings for the perspective projection
|
||||
glPushMatrix();
|
||||
// reset matrix
|
||||
glLoadIdentity();
|
||||
// set a 2D orthographic projection
|
||||
gluOrtho2D(0, glutScreenWidth, 0, glutScreenHeight);
|
||||
// invert the y axis, down is positive
|
||||
glScalef(1, -1, 1);
|
||||
// mover the origin from the bottom left corner
|
||||
// to the upper left corner
|
||||
glTranslatef(0, -glutScreenHeight, 0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
static void resetPerspectiveProjection()
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
void MyConvex::Render(bool only_wireframe, const btVector3& wire_color) const
|
||||
{
|
||||
const float Scale = 1.0f;
|
||||
glPushMatrix();
|
||||
|
||||
ATTRIBUTE_ALIGNED16(btScalar) glmat[16]; //4x4 column major matrix for OpenGL.
|
||||
|
||||
mTransform.getOpenGLMatrix(glmat);
|
||||
#ifndef BT_USE_DOUBLE_PRECISION
|
||||
glMultMatrixf(&(glmat[0]));
|
||||
#else
|
||||
glMultMatrixd(&(glmat[0]));
|
||||
#endif
|
||||
if(!only_wireframe)
|
||||
{
|
||||
btVector3 color(0.0f, 0.5f, 1.0f);
|
||||
for(int i=0;i<mNbPolys;i++)
|
||||
{
|
||||
glNormal3f(mPolys[i].mPlane[0], mPolys[i].mPlane[1], mPolys[i].mPlane[2]);
|
||||
|
||||
int NbTris = mPolys[i].mNbVerts-2;
|
||||
const btVector3& p0 = mVerts[mPolys[i].mIndices[0]]*Scale;
|
||||
for(int j=1;j<=NbTris;j++)
|
||||
{
|
||||
int k = (j+1)%mPolys[i].mNbVerts;
|
||||
|
||||
const btVector3& p1 = mVerts[mPolys[i].mIndices[j]]*Scale;
|
||||
const btVector3& p2 = mVerts[mPolys[i].mIndices[k]]*Scale;
|
||||
|
||||
DrawTriangle(p0, p1, p2, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
btVector3 color;
|
||||
if(only_wireframe)
|
||||
color = wire_color;
|
||||
else
|
||||
color = btVector3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
for(int i=0;i<mNbPolys;i++)
|
||||
{
|
||||
for(int j=0;j<mPolys[i].mNbVerts;j++)
|
||||
{
|
||||
int k = (j+1)%mPolys[i].mNbVerts;
|
||||
DrawLine(mVerts[mPolys[i].mIndices[j]]*Scale, mVerts[mPolys[i].mIndices[k]]*Scale, color, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void MyConvex::Project(const btVector3& dir, float& min, float& max) const
|
||||
{
|
||||
min = FLT_MAX;
|
||||
max = -FLT_MAX;
|
||||
for(int i=0;i<mNbVerts;i++)
|
||||
{
|
||||
btVector3 pt = mTransform * mVerts[i];
|
||||
float dp = pt.dot(dir);
|
||||
if(dp < min) min = dp;
|
||||
if(dp > max) max = dp;
|
||||
}
|
||||
if(min>max)
|
||||
{
|
||||
float tmp = min;
|
||||
min = max;
|
||||
max = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
static btVector3 gNormal;
|
||||
static btVector3 gPoint;
|
||||
static float gDepth;
|
||||
|
||||
struct MyResult : public btDiscreteCollisionDetectorInterface::Result
|
||||
{
|
||||
virtual void setShapeIdentifiersA(int partId0, int index0)
|
||||
{
|
||||
}
|
||||
virtual void setShapeIdentifiersB(int partId1, int index1)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void addContactPoint(const btVector3& normalOnBInWorld, const btVector3& pointInWorld, btScalar depth)
|
||||
{
|
||||
gNormal = normalOnBInWorld;
|
||||
gPoint = pointInWorld;
|
||||
gDepth = depth;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
static bool TestEPA(const MyConvex& hull0, const MyConvex& hull1)
|
||||
{
|
||||
static btSimplexSolverInterface simplexSolver;
|
||||
#ifdef COMPARE_WITH_SOLID35_AND_OTHER_EPA
|
||||
// static Solid3JohnsonSimplexSolver simplexSolver2;
|
||||
#endif //COMPARE_WITH_SOLID35_AND_OTHER_EPA
|
||||
|
||||
simplexSolver.reset();
|
||||
|
||||
btConvexHullShape convexA((btScalar*)hull0.mVerts, hull0.mNbVerts, sizeof(btVector3));
|
||||
btConvexHullShape convexB((btScalar*)hull1.mVerts, hull1.mNbVerts, sizeof(btVector3));
|
||||
|
||||
static btGjkEpaPenetrationDepthSolver Solver0;
|
||||
static btMinkowskiPenetrationDepthSolver Solver1;
|
||||
|
||||
#ifdef COMPARE_WITH_SOLID35_AND_OTHER_EPA
|
||||
static Solid3EpaPenetrationDepth Solver2;
|
||||
static EpaPenetrationDepthSolver Solver3;
|
||||
#endif
|
||||
|
||||
|
||||
btConvexPenetrationDepthSolver* Solver = NULL ;
|
||||
if(gMethod==0)
|
||||
Solver = &Solver0;
|
||||
else if(gMethod==1)
|
||||
Solver = &Solver1;
|
||||
#ifdef COMPARE_WITH_SOLID35_AND_OTHER_EPA
|
||||
else if(gMethod==2)
|
||||
Solver = &Solver2;
|
||||
else
|
||||
Solver = &Solver3;
|
||||
#endif //COMPARE_WITH_SOLID35_AND_OTHER_EPA
|
||||
|
||||
|
||||
#ifdef USE_ORIGINAL
|
||||
|
||||
btGjkPairDetector GJK(&convexA, &convexB, &simplexSolver, Solver);
|
||||
GJK.m_catchDegeneracies = 1;
|
||||
convexA.setMargin(0.01f);
|
||||
convexB.setMargin(0.01f);
|
||||
|
||||
btDiscreteCollisionDetectorInterface::ClosestPointInput input;
|
||||
input.m_transformA = hull0.mTransform;
|
||||
input.m_transformB = hull1.mTransform;
|
||||
|
||||
|
||||
MyResult output;
|
||||
GJK.getClosestPoints(input, output, 0);
|
||||
gLastUsedMethod = GJK.m_lastUsedMethod;
|
||||
gNumGjkIterations = GJK.m_curIter;
|
||||
gLastDegenerateSimplex= GJK.m_degenerateSimplex;
|
||||
#else
|
||||
MyResult output;
|
||||
btVector3 witnesses[2];
|
||||
btVector3 normal;
|
||||
btScalar depth;
|
||||
|
||||
btGjkEpaSolver::sResults results;
|
||||
btScalar radialMargin = 0.01f;
|
||||
|
||||
btGjkEpaSolver::Collide(&convexA,hull0.mTransform,
|
||||
&convexB,hull1.mTransform,
|
||||
radialMargin,
|
||||
results);
|
||||
if (results.depth>0)
|
||||
{
|
||||
output.addContactPoint(results.normal,results.witnesses[1],-results.depth);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool TestSepAxis(const btVector3& sep_axis, const MyConvex& hull0, const MyConvex& hull1, float& depth)
|
||||
{
|
||||
float Min0,Max0;
|
||||
float Min1,Max1;
|
||||
hull0.Project(sep_axis, Min0, Max0);
|
||||
hull1.Project(sep_axis, Min1, Max1);
|
||||
|
||||
if(Max0<Min1 || Max1<Min0)
|
||||
return false;
|
||||
|
||||
float d0 = Max0 - Min1;
|
||||
btAssert(d0>=0.0f);
|
||||
float d1 = Max1 - Min0;
|
||||
btAssert(d1>=0.0f);
|
||||
depth = d0<d1 ? d0:d1;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool IsAlmostZero(const btVector3& v)
|
||||
{
|
||||
if(fabsf(v.x())>1e-6 || fabsf(v.y())>1e-6 || fabsf(v.z())>1e-6) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ReferenceCode(const MyConvex& hull0, const MyConvex& hull1, float& dmin, btVector3& sep)
|
||||
{
|
||||
dmin = FLT_MAX;
|
||||
|
||||
int i;
|
||||
|
||||
// Test normals from hull0
|
||||
for( i=0;i<hull0.mNbPolys;i++)
|
||||
{
|
||||
btVector3 Normal(hull0.mPolys[i].mPlane[0], hull0.mPolys[i].mPlane[1], hull0.mPolys[i].mPlane[2]);
|
||||
|
||||
// btVector3 WorldNormal = hull0.mTransform * Normal;
|
||||
btVector3 WorldNormal = hull0.mTransform.getBasis() * Normal;
|
||||
|
||||
float d;
|
||||
if(!TestSepAxis(WorldNormal, hull0, hull1, d))
|
||||
return false;
|
||||
|
||||
if(d<dmin)
|
||||
{
|
||||
dmin = d;
|
||||
sep = WorldNormal;
|
||||
}
|
||||
}
|
||||
|
||||
// Test normals from hull1
|
||||
for( i=0;i<hull1.mNbPolys;i++)
|
||||
{
|
||||
btVector3 Normal(hull1.mPolys[i].mPlane[0], hull1.mPolys[i].mPlane[1], hull1.mPolys[i].mPlane[2]);
|
||||
|
||||
// btVector3 WorldNormal = hull1.mTransform * Normal;
|
||||
btVector3 WorldNormal = hull1.mTransform.getBasis() * Normal;
|
||||
|
||||
float d;
|
||||
if(!TestSepAxis(WorldNormal, hull0, hull1, d))
|
||||
return false;
|
||||
|
||||
if(d<dmin)
|
||||
{
|
||||
dmin = d;
|
||||
sep = WorldNormal;
|
||||
}
|
||||
}
|
||||
|
||||
// Test edges
|
||||
for(int j=0;j<hull0.mNbPolys;j++)
|
||||
{
|
||||
const MyPoly& poly0 = hull0.mPolys[j];
|
||||
|
||||
for(int i=0;i<hull1.mNbPolys;i++)
|
||||
{
|
||||
const MyPoly& poly1 = hull1.mPolys[i];
|
||||
|
||||
for(int e0=0;e0<poly0.mNbVerts;e0++)
|
||||
{
|
||||
const btVector3& a = hull0.mVerts[poly0.mIndices[e0]];
|
||||
const btVector3& b = hull0.mVerts[poly0.mIndices[(e0+1)%poly0.mNbVerts]];
|
||||
|
||||
btVector3 edge0 = a - b;
|
||||
btVector3 WorldEdge0 = hull0.mTransform.getBasis() * edge0;
|
||||
|
||||
for(int e1=0;e1<poly1.mNbVerts;e1++)
|
||||
{
|
||||
const btVector3& c = hull1.mVerts[poly1.mIndices[e1]];
|
||||
const btVector3& d = hull1.mVerts[poly1.mIndices[(e1+1)%poly1.mNbVerts]];
|
||||
|
||||
btVector3 edge1 = c - d;
|
||||
btVector3 WorldEdge1 = hull1.mTransform.getBasis() * edge1;
|
||||
|
||||
btVector3 Cross = WorldEdge0.cross(WorldEdge1);
|
||||
if(!IsAlmostZero(Cross))
|
||||
{
|
||||
Cross = Cross.normalize();
|
||||
|
||||
float d;
|
||||
if(!TestSepAxis(Cross, hull0, hull1, d))
|
||||
return false;
|
||||
|
||||
if(d<dmin)
|
||||
{
|
||||
dmin = d;
|
||||
sep = Cross;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
btVector3 DeltaC = (hull1.mTransform * hull1.mTransform.getOrigin()) - (hull0.mTransform * hull0.mTransform.getOrigin());
|
||||
if((DeltaC.dot(sep))>0.0f) sep = -sep;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static MyConvex gConvex0;
|
||||
static MyConvex gConvex1;
|
||||
|
||||
static void KeyboardCallback(unsigned char key, int x, int y)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 27: exit(0); break;
|
||||
|
||||
case 'R':
|
||||
case 'r':
|
||||
gRefMode = !gRefMode;
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
gMethod++;
|
||||
#ifdef COMPARE_WITH_SOLID35_AND_OTHER_EPA
|
||||
if(gMethod==4) gMethod=0;
|
||||
#else
|
||||
if(gMethod==2) gMethod=0;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case '4':
|
||||
gConvex0.mTransform.setOrigin(gConvex0.mTransform.getOrigin() + btVector3(-gDisp,0,0));
|
||||
break;
|
||||
case '7':
|
||||
gConvex0.mTransform.setRotation(gConvex0.mTransform.getRotation()*btQuaternion(btVector3(1,0,0),0.01));
|
||||
break;
|
||||
case '9':
|
||||
gConvex0.mTransform.setRotation(gConvex0.mTransform.getRotation()*btQuaternion(btVector3(1,0,0),-0.01));
|
||||
break;
|
||||
case '1':
|
||||
gConvex0.mTransform.setRotation(gConvex0.mTransform.getRotation()*btQuaternion(btVector3(0,1,0),0.01));
|
||||
break;
|
||||
case '3':
|
||||
gConvex0.mTransform.setRotation(gConvex0.mTransform.getRotation()*btQuaternion(btVector3(0,1,0),-0.01));
|
||||
break;
|
||||
case '5':
|
||||
gConvex0.mTransform.setRotation(gConvex0.mTransform.getRotation()*btQuaternion(btVector3(0,0,1),0.01));
|
||||
break;
|
||||
|
||||
case '6':
|
||||
gConvex0.mTransform.setOrigin(gConvex0.mTransform.getOrigin() + btVector3(gDisp,0,0));
|
||||
break;
|
||||
case '8':
|
||||
gConvex0.mTransform.setOrigin(gConvex0.mTransform.getOrigin() + btVector3(0,gDisp,0));
|
||||
break;
|
||||
case '2':
|
||||
gConvex0.mTransform.setOrigin(gConvex0.mTransform.getOrigin() + btVector3(0,-gDisp,0));
|
||||
break;
|
||||
|
||||
case 101: Eye += Dir * gCamSpeed; break;
|
||||
case 103: Eye -= Dir * gCamSpeed; break;
|
||||
case 100: Eye -= N * gCamSpeed; break;
|
||||
case 102: Eye += N * gCamSpeed; break;
|
||||
}
|
||||
}
|
||||
|
||||
static void ArrowKeyCallback(int key, int x, int y)
|
||||
{
|
||||
KeyboardCallback(key,x,y);
|
||||
}
|
||||
|
||||
static void MouseCallback(int button, int state, int x, int y)
|
||||
{
|
||||
mx = x;
|
||||
my = y;
|
||||
}
|
||||
|
||||
static const float NxPiF32 = 3.141592653589793f;
|
||||
|
||||
float degToRad(float a)
|
||||
{
|
||||
return (float)0.01745329251994329547 * a;
|
||||
}
|
||||
|
||||
class NxQuat
|
||||
{
|
||||
public:
|
||||
NxQuat(){}
|
||||
|
||||
NxQuat(const float angle, const btVector3 & axis)
|
||||
{
|
||||
x = axis.x();
|
||||
y = axis.y();
|
||||
z = axis.z();
|
||||
|
||||
const float i_length = 1.0f / sqrtf( x*x + y*y + z*z );
|
||||
x = x * i_length;
|
||||
y = y * i_length;
|
||||
z = z * i_length;
|
||||
|
||||
float Half = degToRad(angle * 0.5f);
|
||||
|
||||
w = cosf(Half);
|
||||
const float sin_theta_over_two = sinf(Half );
|
||||
x = x * sin_theta_over_two;
|
||||
y = y * sin_theta_over_two;
|
||||
z = z * sin_theta_over_two;
|
||||
}
|
||||
|
||||
void multiply(const NxQuat& left, const btVector3& right)
|
||||
{
|
||||
float a,b,c,d;
|
||||
|
||||
a = - left.x*right.x() - left.y*right.y() - left.z *right.z();
|
||||
b = left.w*right.x() + left.y*right.z() - right.y()*left.z;
|
||||
c = left.w*right.y() + left.z*right.x() - right.z()*left.x;
|
||||
d = left.w*right.z() + left.x*right.y() - right.x()*left.y;
|
||||
|
||||
w = a;
|
||||
x = b;
|
||||
y = c;
|
||||
z = d;
|
||||
}
|
||||
|
||||
void rotate(btVector3 & v) const
|
||||
{
|
||||
NxQuat myInverse;
|
||||
myInverse.x = -x;
|
||||
myInverse.y = -y;
|
||||
myInverse.z = -z;
|
||||
myInverse.w = w;
|
||||
|
||||
NxQuat left;
|
||||
left.multiply(*this,v);
|
||||
float vx = left.w*myInverse.x + myInverse.w*left.x + left.y*myInverse.z - myInverse.y*left.z;
|
||||
float vy = left.w*myInverse.y + myInverse.w*left.y + left.z*myInverse.x - myInverse.z*left.x;
|
||||
float vz = left.w*myInverse.z + myInverse.w*left.z + left.x*myInverse.y - myInverse.x*left.y;
|
||||
v.setValue(vx, vy, vz);
|
||||
}
|
||||
|
||||
float x,y,z,w;
|
||||
};
|
||||
|
||||
|
||||
static void MotionCallback(int x, int y)
|
||||
{
|
||||
int dx = mx - x;
|
||||
int dy = my - y;
|
||||
|
||||
Dir = Dir.normalize();
|
||||
N = Dir.cross(btVector3(0,1,0));
|
||||
|
||||
NxQuat qx(NxPiF32 * dx * 20/ 180.0f, btVector3(0,1,0));
|
||||
qx.rotate(Dir);
|
||||
NxQuat qy(NxPiF32 * dy * 20/ 180.0f, N);
|
||||
qy.rotate(Dir);
|
||||
|
||||
mx = x;
|
||||
my = y;
|
||||
}
|
||||
|
||||
static void RenderCallback()
|
||||
{
|
||||
// Clear buffers
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Setup camera
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(60.0f, ((float)glutGet(GLUT_WINDOW_WIDTH))/((float)glutGet(GLUT_WINDOW_HEIGHT)), 1.0f, 10000.0f);
|
||||
gluLookAt(Eye.x(), Eye.y(), Eye.z(), Eye.x() + Dir.x(), Eye.y() + Dir.y(), Eye.z() + Dir.z(), 0.0f, 1.0f, 0.0f);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
//clear previous frames result
|
||||
gNormal.setValue(10,0,0);
|
||||
gPoint.setValue(0,0,0);
|
||||
gDepth = 999.999;
|
||||
gLastUsedMethod = -1;
|
||||
gNumGjkIterations = -1;
|
||||
|
||||
|
||||
TestEPA(gConvex0, gConvex1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
btVector3 RefSep(btScalar(0.), btScalar(0.), btScalar(0.));
|
||||
float RefDMin=0.f;
|
||||
bool RefResult = false;
|
||||
if(gRefMode)
|
||||
RefResult = ReferenceCode(gConvex0, gConvex1, RefDMin, RefSep);
|
||||
|
||||
// DrawLine(gPoint, gPoint + gNormal*20.0f, btVector3(1,0,0), 2.0f);
|
||||
// printf("%f: %f %f %f\n", gDepth, gNormal.x(), gNormal.y(), gNormal.z());
|
||||
|
||||
#ifdef VERBOSE_TEXT_ONSCREEN
|
||||
glColor3f(255.f, 255.f, 255.f);
|
||||
|
||||
setOrthographicProjection();
|
||||
float xOffset = 10.f;
|
||||
float yStart = 20.f;
|
||||
float yIncr = 20.f;
|
||||
char buf[124];
|
||||
|
||||
sprintf(buf,"gDepth=%f: gNormal=(%f %f %f)\n", gDepth, gNormal.x(), gNormal.y(), gNormal.z());
|
||||
GLDebugDrawString(xOffset,yStart,buf);
|
||||
yStart += yIncr;
|
||||
|
||||
sprintf(buf,"num GJK iterations =%d\n", gNumGjkIterations);
|
||||
GLDebugDrawString(xOffset,yStart,buf);
|
||||
yStart += yIncr;
|
||||
|
||||
sprintf(buf,"gLastUsedMethod=%d\n", gLastUsedMethod);
|
||||
GLDebugDrawString(xOffset,yStart,buf);
|
||||
yStart += yIncr;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (gLastUsedMethod >= 3)
|
||||
{
|
||||
switch ( gMethod)
|
||||
{
|
||||
case 0:
|
||||
sprintf(buf,"Bullet GjkEpa Penetration depth solver (zlib free\n" );
|
||||
break;
|
||||
case 1:
|
||||
sprintf(buf,"Bullet Minkowski sampling Penetration depth solver\n" );
|
||||
break;
|
||||
case 2:
|
||||
sprintf(buf,"Solid35 EPA Penetration depth solver\n" );
|
||||
break;
|
||||
case 3:
|
||||
sprintf(buf,"EPA Penetration depth solver (Experimental/WorkInProgress, zlib free\n" );
|
||||
break;
|
||||
default:
|
||||
sprintf(buf,"Unknown Penetration Depth\n" );
|
||||
}
|
||||
GLDebugDrawString(xOffset,yStart,buf);
|
||||
yStart += yIncr;
|
||||
|
||||
} else
|
||||
{
|
||||
sprintf(buf,"Hybrid GJK method %d\n", gLastUsedMethod);
|
||||
GLDebugDrawString(xOffset,yStart,buf);
|
||||
yStart += yIncr;
|
||||
}
|
||||
|
||||
if (gLastDegenerateSimplex)
|
||||
{
|
||||
sprintf(buf,"DegenerateSimplex %d\n", gLastDegenerateSimplex);
|
||||
GLDebugDrawString(xOffset,yStart,buf);
|
||||
yStart += yIncr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
resetPerspectiveProjection();
|
||||
#endif //VERBOSE_TEXT_ONSCREEN
|
||||
|
||||
btVector3 color(0,0,0);
|
||||
gConvex0.Render(false, color);
|
||||
gConvex1.Render(false, color);
|
||||
|
||||
if(gDepth<0.0f)
|
||||
{
|
||||
btTransform Saved = gConvex0.mTransform;
|
||||
gConvex0.mTransform.setOrigin(gConvex0.mTransform.getOrigin() - btVector3(gNormal*gDepth));
|
||||
gConvex0.Render(true, btVector3(1.0f, 0.5f, 0.0f));
|
||||
gConvex0.mTransform = Saved;
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLine(gPoint, gPoint + gNormal, btVector3(0,1,0), 2.0f);
|
||||
}
|
||||
|
||||
if(RefResult & gRefMode)
|
||||
{
|
||||
btTransform Saved = gConvex0.mTransform;
|
||||
gConvex0.mTransform.setOrigin(gConvex0.mTransform.getOrigin() + btVector3(RefSep*RefDMin));
|
||||
gConvex0.Render(true, btVector3(0.0f, 0.5f, 1.0f));
|
||||
gConvex0.mTransform = Saved;
|
||||
}
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
static void ReshapeCallback(int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void IdleCallback()
|
||||
{
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// Initialize Glut
|
||||
glutInit(&argc, argv);
|
||||
glutInitWindowSize(glutScreenWidth, glutScreenHeight);
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
int mainHandle = glutCreateWindow("TestBullet");
|
||||
glutSetWindow(mainHandle);
|
||||
glutDisplayFunc(RenderCallback);
|
||||
glutReshapeFunc(ReshapeCallback);
|
||||
glutIdleFunc(IdleCallback);
|
||||
glutKeyboardFunc(KeyboardCallback);
|
||||
glutSpecialFunc(ArrowKeyCallback);
|
||||
glutMouseFunc(MouseCallback);
|
||||
glutMotionFunc(MotionCallback);
|
||||
MotionCallback(0,0);
|
||||
|
||||
// Setup default render states
|
||||
glClearColor(0.3f, 0.4f, 0.5f, 1.0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
// Setup lighting
|
||||
glEnable(GL_LIGHTING);
|
||||
float AmbientColor[] = { 0.0f, 0.1f, 0.2f, 0.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, AmbientColor);
|
||||
float DiffuseColor[] = { 1.0f, 1.0f, 1.0f, 0.0f }; glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseColor);
|
||||
float SpecularColor[] = { 0.0f, 0.0f, 0.0f, 0.0f }; glLightfv(GL_LIGHT0, GL_SPECULAR, SpecularColor);
|
||||
float Position[] = { -10.0f, 1000.0f, -4.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_POSITION, Position);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
//
|
||||
bool Status = gConvex0.LoadFromFile("convex0.bin");
|
||||
if(!Status)
|
||||
{
|
||||
Status = gConvex0.LoadFromFile("../../convex0.bin");
|
||||
if(!Status)
|
||||
{
|
||||
printf("Failed to load object!\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
Status = gConvex1.LoadFromFile("convex0.bin");
|
||||
if(!Status)
|
||||
{
|
||||
Status = gConvex1.LoadFromFile("../../convex0.bin");
|
||||
if(!Status)
|
||||
{
|
||||
printf("Failed to load object!\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// gConvex0.mTransform.setOrigin(btVector3(1.0f, 1.0f, 0.0f));
|
||||
gConvex0.mTransform.setOrigin(btVector3(0.20000069f, 0.95000005f, 0.0f));
|
||||
|
||||
// Run
|
||||
glutMainLoop();
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# This is the variable for Windows. I use this to define the root of my directory structure.
|
||||
SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
|
||||
|
||||
IF (USE_GLUT)
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppFeatherstoneMultiBodyDemo
|
||||
main.cpp
|
||||
FeatherstoneMultiBodyDemo.cpp
|
||||
FeatherstoneMultiBodyDemo.h
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppFeatherstoneMultiBodyDemo
|
||||
main.cpp
|
||||
FeatherstoneMultiBodyDemo.cpp
|
||||
FeatherstoneMultiBodyDemo.h
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
||||
|
||||
|
||||
ELSE (USE_GLUT)
|
||||
|
||||
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
|
||||
ADD_EXECUTABLE(AppFeatherstoneMultiBodyDemo
|
||||
WIN32
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
Win32FeatherstoneMultiBodyDemo.cpp
|
||||
FeatherstoneMultiBodyDemo.cpp
|
||||
FeatherstoneMultiBodyDemo.h
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
|
||||
|
||||
ENDIF (USE_GLUT)
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppBasicDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppBasicDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppBasicDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
@ -1,575 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
///experimental support for Featherstone multi body (articulated hierarchies)
|
||||
|
||||
|
||||
///create 125 (5x5x5) dynamic object
|
||||
#define ARRAY_SIZE_X 5
|
||||
#define ARRAY_SIZE_Y 5
|
||||
#define ARRAY_SIZE_Z 5
|
||||
float friction = 1.;
|
||||
|
||||
|
||||
//maximum number of objects (and allow user to shoot additional boxes)
|
||||
#define MAX_PROXIES (ARRAY_SIZE_X*ARRAY_SIZE_Y*ARRAY_SIZE_Z + 1024)
|
||||
|
||||
|
||||
#define START_POS_X -5
|
||||
//#define START_POS_Y 12
|
||||
#define START_POS_Y 2
|
||||
#define START_POS_Z -3
|
||||
|
||||
#include "FeatherstoneMultiBodyDemo.h"
|
||||
|
||||
#include "BulletDynamics/Featherstone/btMultiBody.h"
|
||||
#include "BulletDynamics/Featherstone/btMultiBodyConstraintSolver.h"
|
||||
#include "BulletDynamics/Featherstone/btMultiBodyDynamicsWorld.h"
|
||||
#include "BulletDynamics/Featherstone/btMultiBodyLinkCollider.h"
|
||||
#include "BulletDynamics/Featherstone/btMultiBodyLink.h"
|
||||
#include "BulletDynamics/Featherstone/btMultiBodyJointLimitConstraint.h"
|
||||
#include "BulletDynamics/Featherstone/btMultiBodyJointMotor.h"
|
||||
#include "BulletDynamics/Featherstone/btMultiBodyPoint2Point.h"
|
||||
|
||||
|
||||
#include "GlutStuff.h"
|
||||
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
#include <stdio.h> //printf debugging
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "LinearMath/btAabbUtil2.h"
|
||||
|
||||
static GLDebugDrawer gDebugDraw;
|
||||
//btVector3 scaling(0.1,0.1,0.1);
|
||||
float scaling = 0.4f;
|
||||
|
||||
|
||||
void FeatherstoneMultiBodyDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//simple dynamics world doesn't handle fixed-time-stepping
|
||||
float ms = getDeltaTimeMicroseconds();
|
||||
|
||||
///step the simulation
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
m_dynamicsWorld->stepSimulation(ms / 1000000.f);
|
||||
//optional but useful: debug drawing
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
btVector3 aabbMin(1,1,1);
|
||||
btVector3 aabbMax(2,2,2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
|
||||
swapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FeatherstoneMultiBodyDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
renderme();
|
||||
|
||||
//optional but useful: debug drawing to detect problems
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
glFlush();
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void FeatherstoneMultiBodyDemo::initPhysics()
|
||||
{
|
||||
//m_idle=true;
|
||||
setTexturing(true);
|
||||
setShadows(true);
|
||||
|
||||
setCameraDistance(btScalar(100.*scaling));
|
||||
this->m_azi = 130;
|
||||
///collision configuration contains default setup for memory, collision setup
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
|
||||
m_broadphase = new btDbvtBroadphase();
|
||||
|
||||
//Use the btMultiBodyConstraintSolver for Featherstone btMultiBody support
|
||||
btMultiBodyConstraintSolver* sol = new btMultiBodyConstraintSolver;
|
||||
m_solver = sol;
|
||||
|
||||
//use btMultiBodyDynamicsWorld for Featherstone btMultiBody support
|
||||
btMultiBodyDynamicsWorld* world = new btMultiBodyDynamicsWorld(m_dispatcher,m_broadphase,sol,m_collisionConfiguration);
|
||||
m_dynamicsWorld = world;
|
||||
m_dynamicsWorld->setDebugDrawer(&gDebugDraw);
|
||||
|
||||
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
|
||||
|
||||
///create a few basic rigid bodies
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
|
||||
//groundShape->initializePolyhedralFeatures();
|
||||
// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50);
|
||||
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
|
||||
btTransform groundTransform;
|
||||
groundTransform.setIdentity();
|
||||
groundTransform.setOrigin(btVector3(0,-50,00));
|
||||
|
||||
//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
|
||||
if (1)
|
||||
{
|
||||
//create a few dynamic rigidbodies
|
||||
// Re-using the same collision is better for memory usage and performance
|
||||
|
||||
btBoxShape* colShape = new btBoxShape(btVector3(1,1,1));
|
||||
//btCollisionShape* colShape = new btSphereShape(btScalar(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);
|
||||
|
||||
float start_x = START_POS_X - ARRAY_SIZE_X/2;
|
||||
float start_y = START_POS_Y;
|
||||
float start_z = START_POS_Z - ARRAY_SIZE_Z/2;
|
||||
|
||||
for (int k=0;k<ARRAY_SIZE_Y;k++)
|
||||
{
|
||||
for (int i=0;i<ARRAY_SIZE_X;i++)
|
||||
{
|
||||
for(int j = 0;j<ARRAY_SIZE_Z;j++)
|
||||
{
|
||||
startTransform.setOrigin(btVector3(
|
||||
btScalar(3.0*i + start_x),
|
||||
btScalar(3.0*k + start_y),
|
||||
btScalar(3.0*j + start_z)));
|
||||
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
|
||||
m_dynamicsWorld->addRigidBody(body);//,1,1+2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
btMultiBodySettings settings;
|
||||
settings.m_numLinks = 2;
|
||||
settings.m_basePosition = btVector3 (60,29.5,-2)*scaling;
|
||||
settings.m_isFixedBase = false;
|
||||
settings.m_disableParentCollision = true;//the self-collision has conflicting/non-resolvable contact normals
|
||||
|
||||
settings.m_usePrismatic = true;
|
||||
settings.m_canSleep = true;
|
||||
settings.m_createConstraints = true;
|
||||
|
||||
//btMultiBody* createFeatherstoneMultiBody(class btMultiBodyDynamicsWorld* world, int numLinks, const btVector3& basePosition,bool isFixedBase, bool usePrismatic, bool canSleep, bool createConstraints);
|
||||
|
||||
btMultiBody* mbA = createFeatherstoneMultiBody(world, settings);
|
||||
|
||||
settings.m_numLinks = 10;
|
||||
settings.m_basePosition = btVector3 (0,29.5,-settings.m_numLinks*4.f);
|
||||
settings.m_isFixedBase = true;
|
||||
settings.m_usePrismatic = false;
|
||||
|
||||
btMultiBody* mbB = createFeatherstoneMultiBody(world, settings);
|
||||
settings.m_basePosition = btVector3 (-20*scaling,29.5*scaling,-settings.m_numLinks*4.f*scaling);
|
||||
settings.m_isFixedBase = false;
|
||||
btMultiBody* mbC = createFeatherstoneMultiBody(world, settings);
|
||||
|
||||
settings.m_basePosition = btVector3 (-20,9.5,-settings.m_numLinks*4.f);
|
||||
settings.m_isFixedBase = true;
|
||||
settings.m_usePrismatic = true;
|
||||
settings.m_disableParentCollision = true;
|
||||
|
||||
btMultiBody* mbPrim= createFeatherstoneMultiBody(world, settings);
|
||||
|
||||
//btMultiBody* mbB = createFeatherstoneMultiBody(world, 15, btVector3 (0,29.5,-2), false,true,true);
|
||||
#if 0
|
||||
if (0)//!useGroundShape && i==4)
|
||||
{
|
||||
//attach two multibody using a point2point constraint
|
||||
|
||||
//btVector3 pivotInAworld(0,20,46);
|
||||
btVector3 pivotInAworld(-0.3,29,-3.5);
|
||||
|
||||
int linkA = -1;
|
||||
int linkB = -1;
|
||||
|
||||
btVector3 pivotInAlocal = mbA->worldPosToLocal(linkA, pivotInAworld);
|
||||
btVector3 pivotInBlocal = mbB->worldPosToLocal(linkB, pivotInAworld);
|
||||
btMultiBodyPoint2Point* p2p = new btMultiBodyPoint2Point(mbA,linkA,mbB,linkB,pivotInAlocal,pivotInBlocal);
|
||||
world->addMultiBodyConstraint(p2p);
|
||||
}
|
||||
#endif
|
||||
bool testRemoveLinks = false;
|
||||
if (testRemoveLinks)
|
||||
{
|
||||
while (mbA->getNumLinks())
|
||||
{
|
||||
btCollisionObject* col = mbA->getLink(mbA->getNumLinks()-1).m_collider;
|
||||
m_dynamicsWorld->removeCollisionObject(col);
|
||||
delete col;
|
||||
mbA->setNumLinks(mbA->getNumLinks()-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (1)//useGroundShape
|
||||
{
|
||||
btScalar mass(0.);
|
||||
|
||||
//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)
|
||||
groundShape->calculateLocalInertia(mass,localInertia);
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
|
||||
//add the body to the dynamics world
|
||||
m_dynamicsWorld->addRigidBody(body,1,1+2);//,1,1+2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
btMultiBody* FeatherstoneMultiBodyDemo::createFeatherstoneMultiBody(class btMultiBodyDynamicsWorld* world, const btMultiBodySettings& settings)
|
||||
{
|
||||
|
||||
int n_links = settings.m_numLinks;
|
||||
float mass = 13.5*scaling;
|
||||
btVector3 inertia = btVector3 (91,344,253)*scaling*scaling;
|
||||
|
||||
|
||||
bool multiDof = false;
|
||||
btMultiBody * bod = new btMultiBody(n_links, mass, inertia, settings.m_isFixedBase, settings.m_canSleep,multiDof);
|
||||
// bod->setHasSelfCollision(false);
|
||||
|
||||
//btQuaternion orn(btVector3(0,0,1),-0.25*SIMD_HALF_PI);//0,0,0,1);
|
||||
btQuaternion orn(0,0,0,1);
|
||||
bod->setBasePos(settings.m_basePosition);
|
||||
bod->setWorldToBaseRot(orn);
|
||||
btVector3 vel(0,0,0);
|
||||
bod->setBaseVel(vel);
|
||||
|
||||
{
|
||||
|
||||
btVector3 joint_axis_hinge(1,0,0);
|
||||
btVector3 joint_axis_prismatic(0,0,1);
|
||||
btQuaternion parent_to_child = orn.inverse();
|
||||
btVector3 joint_axis_child_prismatic = quatRotate(parent_to_child ,joint_axis_prismatic);
|
||||
btVector3 joint_axis_child_hinge = quatRotate(parent_to_child , joint_axis_hinge);
|
||||
|
||||
int this_link_num = -1;
|
||||
int link_num_counter = 0;
|
||||
|
||||
|
||||
|
||||
btVector3 pos = btVector3 (0,0,9.0500002)*scaling;
|
||||
|
||||
btVector3 joint_axis_position = btVector3 (0,0,4.5250001)*scaling;
|
||||
|
||||
for (int i=0;i<n_links;i++)
|
||||
{
|
||||
float initial_joint_angle=0.3;
|
||||
if (i>0)
|
||||
initial_joint_angle = -0.06f;
|
||||
|
||||
const int child_link_num = link_num_counter++;
|
||||
|
||||
|
||||
|
||||
if (settings.m_usePrismatic)// && i==(n_links-1))
|
||||
{
|
||||
bod->setupPrismatic(child_link_num, mass, inertia, this_link_num,
|
||||
parent_to_child, joint_axis_child_prismatic, quatRotate(parent_to_child , pos),btVector3(0,0,0),settings.m_disableParentCollision);
|
||||
|
||||
} else
|
||||
{
|
||||
bod->setupRevolute(child_link_num, mass, inertia, this_link_num,parent_to_child, joint_axis_child_hinge,
|
||||
joint_axis_position,quatRotate(parent_to_child , (pos - joint_axis_position)),settings.m_disableParentCollision);
|
||||
}
|
||||
bod->setJointPos(child_link_num, initial_joint_angle);
|
||||
this_link_num = i;
|
||||
|
||||
if (0)//!useGroundShape && i==4)
|
||||
{
|
||||
btVector3 pivotInAworld(0,20,46);
|
||||
btVector3 pivotInAlocal = bod->worldPosToLocal(i, pivotInAworld);
|
||||
btVector3 pivotInBworld = pivotInAworld;
|
||||
btMultiBodyPoint2Point* p2p = new btMultiBodyPoint2Point(bod,i,&btTypedConstraint::getFixedBody(),pivotInAlocal,pivotInBworld);
|
||||
world->addMultiBodyConstraint(p2p);
|
||||
}
|
||||
//add some constraint limit
|
||||
if (settings.m_usePrismatic)
|
||||
{
|
||||
// btMultiBodyConstraint* con = new btMultiBodyJointLimitConstraint(bod,n_links-1,2,3);
|
||||
|
||||
if (settings.m_createConstraints)
|
||||
{
|
||||
btMultiBodyConstraint* con = new btMultiBodyJointLimitConstraint(bod,i,-1,1);
|
||||
world->addMultiBodyConstraint(con);
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
if (settings.m_createConstraints)
|
||||
{
|
||||
if (1)
|
||||
{
|
||||
btMultiBodyJointMotor* con = new btMultiBodyJointMotor(bod,i,0,0,500000);
|
||||
world->addMultiBodyConstraint(con);
|
||||
}
|
||||
|
||||
btMultiBodyConstraint* con = new btMultiBodyJointLimitConstraint(bod,i,-1,1);
|
||||
world->addMultiBodyConstraint(con);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//add a collider for the base
|
||||
{
|
||||
|
||||
btAlignedObjectArray<btQuaternion> world_to_local;
|
||||
world_to_local.resize(n_links+1);
|
||||
|
||||
btAlignedObjectArray<btVector3> local_origin;
|
||||
local_origin.resize(n_links+1);
|
||||
world_to_local[0] = bod->getWorldToBaseRot();
|
||||
local_origin[0] = bod->getBasePos();
|
||||
//float halfExtents[3]={7.5,0.05,4.5};
|
||||
float halfExtents[3]={7.5,0.45,4.5};
|
||||
{
|
||||
|
||||
float pos[4]={local_origin[0].x(),local_origin[0].y(),local_origin[0].z(),1};
|
||||
float quat[4]={-world_to_local[0].x(),-world_to_local[0].y(),-world_to_local[0].z(),world_to_local[0].w()};
|
||||
|
||||
|
||||
if (1)
|
||||
{
|
||||
btCollisionShape* box = new btBoxShape(btVector3(halfExtents[0],halfExtents[1],halfExtents[2])*scaling);
|
||||
btMultiBodyLinkCollider* col= new btMultiBodyLinkCollider(bod,-1);
|
||||
col->setCollisionShape(box);
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
tr.setOrigin(local_origin[0]);
|
||||
tr.setRotation(btQuaternion(quat[0],quat[1],quat[2],quat[3]));
|
||||
col->setWorldTransform(tr);
|
||||
world->addCollisionObject(col, 2,1+2);
|
||||
col->setFriction(friction);
|
||||
bod->setBaseCollider(col);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i=0;i<bod->getNumLinks();i++)
|
||||
{
|
||||
const int parent = bod->getParent(i);
|
||||
world_to_local[i+1] = bod->getParentToLocalRot(i) * world_to_local[parent+1];
|
||||
local_origin[i+1] = local_origin[parent+1] + (quatRotate(world_to_local[i+1].inverse() , bod->getRVector(i)));
|
||||
}
|
||||
|
||||
|
||||
for (int i=0;i<bod->getNumLinks();i++)
|
||||
{
|
||||
|
||||
btVector3 posr = local_origin[i+1];
|
||||
float pos[4]={posr.x(),posr.y(),posr.z(),1};
|
||||
|
||||
float quat[4]={-world_to_local[i+1].x(),-world_to_local[i+1].y(),-world_to_local[i+1].z(),world_to_local[i+1].w()};
|
||||
|
||||
btCollisionShape* box = new btBoxShape(btVector3(halfExtents[0],halfExtents[1],halfExtents[2])*scaling);
|
||||
btMultiBodyLinkCollider* col = new btMultiBodyLinkCollider(bod,i);
|
||||
|
||||
col->setCollisionShape(box);
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
tr.setOrigin(posr);
|
||||
tr.setRotation(btQuaternion(quat[0],quat[1],quat[2],quat[3]));
|
||||
col->setWorldTransform(tr);
|
||||
col->setFriction(friction);
|
||||
world->addCollisionObject(col,2,1+2);
|
||||
|
||||
bod->getLink(i).m_collider=col;
|
||||
//app->drawBox(halfExtents, pos,quat);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
world->addMultiBody(bod);
|
||||
|
||||
return bod;
|
||||
}
|
||||
|
||||
extern btScalar gOldPickingDist;
|
||||
void FeatherstoneMultiBodyDemo::mouseMotionFunc(int x,int y)
|
||||
{
|
||||
if (m_pickingMultiBodyPoint2Point)
|
||||
{
|
||||
//keep it at the same picking distance
|
||||
|
||||
btVector3 newRayTo = getRayTo(x,y);
|
||||
btVector3 rayFrom;
|
||||
btVector3 oldPivotInB = m_pickingMultiBodyPoint2Point->getPivotInB();
|
||||
btVector3 newPivotB;
|
||||
if (m_ortho)
|
||||
{
|
||||
newPivotB = oldPivotInB;
|
||||
newPivotB.setX(newRayTo.getX());
|
||||
newPivotB.setY(newRayTo.getY());
|
||||
} else
|
||||
{
|
||||
rayFrom = m_cameraPosition;
|
||||
btVector3 dir = newRayTo-rayFrom;
|
||||
dir.normalize();
|
||||
dir *= gOldPickingDist;
|
||||
|
||||
newPivotB = rayFrom + dir;
|
||||
}
|
||||
m_pickingMultiBodyPoint2Point->setPivotInB(newPivotB);
|
||||
}
|
||||
DemoApplication::mouseMotionFunc(x,y);
|
||||
}
|
||||
|
||||
void FeatherstoneMultiBodyDemo::removePickingConstraint()
|
||||
{
|
||||
if (m_pickingMultiBodyPoint2Point)
|
||||
{
|
||||
m_pickingMultiBodyPoint2Point->getMultiBodyA()->setCanSleep(true);
|
||||
|
||||
btMultiBodyDynamicsWorld* world = (btMultiBodyDynamicsWorld*) m_dynamicsWorld;
|
||||
world->removeMultiBodyConstraint(m_pickingMultiBodyPoint2Point);
|
||||
delete m_pickingMultiBodyPoint2Point;
|
||||
m_pickingMultiBodyPoint2Point = 0;
|
||||
}
|
||||
|
||||
DemoApplication::removePickingConstraint();
|
||||
|
||||
}
|
||||
|
||||
void FeatherstoneMultiBodyDemo::pickObject(const btVector3& pickPos, const class btCollisionObject* hitObj)
|
||||
{
|
||||
btVector3 pivotInA(0,0,0);
|
||||
btMultiBodyLinkCollider* multiCol = (btMultiBodyLinkCollider*)btMultiBodyLinkCollider::upcast(hitObj);
|
||||
if (multiCol && multiCol->m_multiBody)
|
||||
{
|
||||
multiCol->m_multiBody->setCanSleep(false);
|
||||
|
||||
btVector3 pivotInA = multiCol->m_multiBody->worldPosToLocal(multiCol->m_link, pickPos);
|
||||
|
||||
btMultiBodyPoint2Point* p2p = new btMultiBodyPoint2Point(multiCol->m_multiBody,multiCol->m_link,0,pivotInA,pickPos);
|
||||
//if you add too much energy to the system, causing high angular velocities, simulation 'explodes'
|
||||
//see also http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=4&t=949
|
||||
//so we try to avoid it by clamping the maximum impulse (force) that the mouse pick can apply
|
||||
//it is not satisfying, hopefully we find a better solution (higher order integrator, using joint friction using a zero-velocity target motor with limited force etc?)
|
||||
|
||||
p2p->setMaxAppliedImpulse(200*scaling);
|
||||
|
||||
btMultiBodyDynamicsWorld* world = (btMultiBodyDynamicsWorld*) m_dynamicsWorld;
|
||||
world->addMultiBodyConstraint(p2p);
|
||||
m_pickingMultiBodyPoint2Point =p2p;
|
||||
} else
|
||||
{
|
||||
DemoApplication::pickObject(pickPos,hitObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FeatherstoneMultiBodyDemo::clientResetScene()
|
||||
{
|
||||
exitPhysics();
|
||||
initPhysics();
|
||||
}
|
||||
|
||||
|
||||
void FeatherstoneMultiBodyDemo::exitPhysics()
|
||||
{
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
m_collisionShapes.clear();
|
||||
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
delete m_solver;
|
||||
|
||||
delete m_broadphase;
|
||||
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
///experimental support for Featherstone multi body (articulated hierarchies)
|
||||
|
||||
#ifndef FEATHERSTONE_MULTIBODY_DEMO_H
|
||||
#define FEATHERSTONE_MULTIBODY_DEMO_H
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btMultiBody;
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
|
||||
///FeatherstoneMultiBodyDemo is good starting point for learning the code base and porting.
|
||||
|
||||
struct btMultiBodySettings
|
||||
{
|
||||
btMultiBodySettings()
|
||||
{
|
||||
m_numLinks = 0;
|
||||
m_basePosition.setZero();
|
||||
m_isFixedBase = true;
|
||||
m_usePrismatic = false;
|
||||
m_canSleep = true;
|
||||
m_createConstraints = false;
|
||||
m_disableParentCollision = false;
|
||||
}
|
||||
int m_numLinks;
|
||||
btVector3 m_basePosition;
|
||||
bool m_isFixedBase;
|
||||
bool m_usePrismatic;
|
||||
bool m_canSleep;
|
||||
bool m_createConstraints;
|
||||
bool m_disableParentCollision;
|
||||
};
|
||||
|
||||
class FeatherstoneMultiBodyDemo : public PlatformDemoApplication
|
||||
{
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
virtual void mouseMotionFunc(int x,int y);
|
||||
virtual void removePickingConstraint();
|
||||
virtual void pickObject(const btVector3& pickPos, const class btCollisionObject* hitObj);
|
||||
class btMultiBodyPoint2Point* m_pickingMultiBodyPoint2Point;
|
||||
|
||||
btMultiBody* createFeatherstoneMultiBody(class btMultiBodyDynamicsWorld* world, const btMultiBodySettings& settings);
|
||||
|
||||
public:
|
||||
|
||||
FeatherstoneMultiBodyDemo()
|
||||
:m_pickingMultiBodyPoint2Point(0)
|
||||
{
|
||||
}
|
||||
virtual ~FeatherstoneMultiBodyDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
virtual void clientResetScene();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
FeatherstoneMultiBodyDemo* demo = new FeatherstoneMultiBodyDemo;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //FEATHERSTONE_MULTIBODY_DEMO_H
|
||||
|
@ -1,5 +0,0 @@
|
||||
noinst_PROGRAMS=FeatherstoneMultiBodyDemo
|
||||
|
||||
FeatherstoneMultiBodyDemo_SOURCES=FeatherstoneMultiBodyDemo.cpp FeatherstoneMultiBodyDemo.h main.cpp
|
||||
FeatherstoneMultiBodyDemo_CXXFLAGS=-I@top_builddir@/src -I@top_builddir@/Demos/OpenGL $(CXXFLAGS)
|
||||
FeatherstoneMultiBodyDemo_LDADD=-L../OpenGL -lbulletopenglsupport -L../../src -lBulletDynamics -lBulletCollision -lLinearMath @opengl_LIBS@
|
@ -1,28 +0,0 @@
|
||||
#ifdef _WINDOWS
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
///experimental support for Featherstone multi body (articulated hierarchies)
|
||||
|
||||
|
||||
#include "FeatherstoneMultiBodyDemo.h"
|
||||
|
||||
///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo
|
||||
DemoApplication* createDemo()
|
||||
{
|
||||
return new FeatherstoneMultiBodyDemo();
|
||||
}
|
||||
|
||||
#endif
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
///experimental support for Featherstone multi body (articulated hierarchies)
|
||||
|
||||
|
||||
#include "FeatherstoneMultiBodyDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
FeatherstoneMultiBodyDemo demo;
|
||||
demo.initPhysics();
|
||||
|
||||
|
||||
#ifdef CHECK_MEMORY_LEAKS
|
||||
ccdDemo.exitPhysics();
|
||||
#else
|
||||
return glutmain(argc, argv,1024,600,"Bullet Physics Demo. http://bulletphysics.org",&demo);
|
||||
#endif
|
||||
|
||||
//default glut doesn't return from mainloop
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# This is the variable for Windows. I use this to define the root of my directory structure.
|
||||
SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
../OpenGL
|
||||
${GLUT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppForkLiftDemo
|
||||
ForkLiftDemo.cpp
|
||||
main.cpp
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
|
||||
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppForkLiftDemo
|
||||
ForkLiftDemo.cpp
|
||||
main.cpp
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppForkLiftDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppForkLiftDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppForkLiftDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user