enable URDF loading throught the 'File/Open' menu
set a default camera targets for each demo. note that it is only reset when switching to a different demo, so you can restart at your chosen location. no OpenCL pairbench drawing in OpenGL2 (there is no VBO available etc)
This commit is contained in:
@@ -10,7 +10,7 @@ public:
|
||||
EmptyExample() {}
|
||||
virtual ~EmptyExample(){}
|
||||
|
||||
static CommonExampleInterface* CreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
||||
static CommonExampleInterface* CreateFunc(struct CommonExampleOptions& /* unusedOptions*/)
|
||||
{
|
||||
return new EmptyExample;
|
||||
}
|
||||
|
||||
@@ -61,14 +61,14 @@ static ExampleEntry gDefaultExamples[]=
|
||||
ExampleEntry(1,"Gyroscopic", "Show the Dzhanibekov effect using various settings of the gyroscopic term. You can select the gyroscopic term computation using btRigidBody::setFlags, with arguments BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT (using explicit integration, which adds energy and can lead to explosions), BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_WORLD, BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_BODY. If you don't set any of these flags, there is no gyroscopic term used.", GyroscopicCreateFunc),
|
||||
|
||||
ExampleEntry(1,"Planar 2D","Show the use of 2D collision shapes and rigid body simulation. The collision shape is wrapped into a btConvex2dShape. The rigid bodies are restricted in a plane using the 'setAngularFactor' and 'setLinearFactor' API call.",Planar2DCreateFunc),
|
||||
ExampleEntry(1,"Constraints","Use of a btHingeConstraint. You can adjust the first slider to change the target velocity, and the second slider to adjust the maximum impulse applied to reach the target velocity. Note that the hinge angle can reach beyond -360 and 360 degrees.", ConstraintCreateFunc),
|
||||
ExampleEntry(1,"6DofSpring2","Show the use of the btGeneric6DofSpring2Constraint.",
|
||||
Dof6Spring2CreateFunc),
|
||||
|
||||
ExampleEntry(1,"Constraints","Show the use of the various constraints in Bullet.",
|
||||
AllConstraintCreateFunc),
|
||||
|
||||
|
||||
ExampleEntry(1,"Motorized Hinge","Use of a btHingeConstraint. You can adjust the first slider to change the target velocity, and the second slider to adjust the maximum impulse applied to reach the target velocity. Note that the hinge angle can reach beyond -360 and 360 degrees.", ConstraintCreateFunc),
|
||||
|
||||
ExampleEntry(0,"MultiBody"),
|
||||
ExampleEntry(1,"MultiDofCreateFunc","Create a basic btMultiBody with 3-DOF spherical joints (mobilizers). The demo uses a fixed base or a floating base at restart.", MultiDofCreateFunc),
|
||||
ExampleEntry(1,"TestJointTorque","Apply a torque to a btMultiBody with 1-DOF joints (mobilizers).", TestJointTorqueCreateFunc),
|
||||
@@ -164,16 +164,20 @@ static ExampleEntry gDefaultExamples[]=
|
||||
ExampleEntry(1,"Implicit Cloth", "Cloth simulation using implicit integration, by Stan Melax. The cloth is only attached at the corners. Note the stability using a large time step even with high stiffness.",
|
||||
ImplicitClothCreateFunc),
|
||||
|
||||
#ifdef B3_USE_CLEW
|
||||
ExampleEntry(0,"OpenCL (experimental)"),
|
||||
ExampleEntry(1,"Pair Bench", "Benchmark of overlapping pair search using OpenCL.", PairBenchOpenCLCreateFunc),
|
||||
#endif //
|
||||
|
||||
ExampleEntry(0,"Rendering"),
|
||||
ExampleEntry(1,"Instanced Rendering", "Simple example of fast instanced rendering, only active when using OpenGL3+.",RenderInstancingCreateFunc),
|
||||
ExampleEntry(1,"CoordinateSystemDemo","Show the axis and positive rotation direction around the axis.", CoordinateSystemCreateFunc),
|
||||
|
||||
};
|
||||
|
||||
static ExampleEntry gOpenCLExamples[]=
|
||||
{
|
||||
#ifdef B3_USE_CLEW
|
||||
ExampleEntry(0,"OpenCL (experimental)"),
|
||||
ExampleEntry(1,"Pair Bench", "Benchmark of overlapping pair search using OpenCL.", PairBenchOpenCLCreateFunc),
|
||||
#endif //
|
||||
};
|
||||
|
||||
static btAlignedObjectArray<ExampleEntry> gAdditionalRegisteredExamples;
|
||||
|
||||
@@ -193,6 +197,15 @@ ExampleEntries::~ExampleEntries()
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
void ExampleEntries::initOpenCLExampleEntries()
|
||||
{
|
||||
int numDefaultEntries = sizeof(gOpenCLExamples)/sizeof(ExampleEntry);
|
||||
for (int i=0;i<numDefaultEntries;i++)
|
||||
{
|
||||
m_data->m_allExamples.push_back(gOpenCLExamples[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ExampleEntries::initExampleEntries()
|
||||
{
|
||||
m_data->m_allExamples.clear();
|
||||
|
||||
@@ -20,6 +20,8 @@ public:
|
||||
static void registerExampleEntry(int menuLevel, const char* name,const char* description, CommonExampleInterface::CreateFunc* createFunc, int option=0);
|
||||
|
||||
void initExampleEntries();
|
||||
|
||||
void initOpenCLExampleEntries();
|
||||
|
||||
int getNumRegisteredExamples();
|
||||
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
#include "ExampleEntries.h"
|
||||
#include "OpenGLGuiHelper.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
//quick test for file import, @todo(erwincoumans) make it more general and add other file formats
|
||||
#include "../Importers/ImportURDFDemo/ImportURDFSetup.h"
|
||||
|
||||
static CommonGraphicsApp* s_app=0;
|
||||
|
||||
static CommonWindowInterface* s_window = 0;
|
||||
@@ -46,7 +49,7 @@ static MyProfileWindow* s_profWindow =0;
|
||||
const char* startFileName = "bulletDemo.txt";
|
||||
|
||||
static GwenUserInterface* gui = 0;
|
||||
static int sCurrentDemoIndex = 0;
|
||||
static int sCurrentDemoIndex = -1;
|
||||
static int sCurrentHightlighted = 0;
|
||||
static CommonExampleInterface* sCurrentDemo = 0;
|
||||
static b3AlignedObjectArray<const char*> allNames;
|
||||
@@ -190,38 +193,49 @@ static void MyMouseButtonCallback(int button, int state, float x, float y)
|
||||
|
||||
void openURDFDemo(const char* filename)
|
||||
{
|
||||
#if 0
|
||||
|
||||
if (sCurrentDemo)
|
||||
{
|
||||
sCurrentDemo->exitPhysics();
|
||||
s_instancingRenderer->removeAllInstances();
|
||||
delete sCurrentDemo;
|
||||
sCurrentDemo=0;
|
||||
sCurrentDemo->exitPhysics();
|
||||
s_instancingRenderer->removeAllInstances();
|
||||
delete sCurrentDemo;
|
||||
sCurrentDemo=0;
|
||||
delete s_guiHelper;
|
||||
s_guiHelper = 0;
|
||||
}
|
||||
|
||||
|
||||
s_guiHelper= new OpenGLGuiHelper(s_app, sUseOpenGL2);
|
||||
s_parameterInterface->removeAllParameters();
|
||||
|
||||
ImportUrdfSetup* physicsSetup = new ImportUrdfSetup();
|
||||
physicsSetup->setFileName(filename);
|
||||
|
||||
sCurrentDemo = new BasicDemo(s_app, physicsSetup);
|
||||
s_app->setUpAxis(2);
|
||||
|
||||
CommonExampleOptions options(s_guiHelper,0);
|
||||
options.m_fileName = filename;
|
||||
|
||||
sCurrentDemo = ImportURDFCreateFunc(options);
|
||||
|
||||
//physicsSetup->setFileName(filename);
|
||||
|
||||
|
||||
if (sCurrentDemo)
|
||||
{
|
||||
sCurrentDemo->initPhysics();
|
||||
sCurrentDemo->resetCamera();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void selectDemo(int demoIndex)
|
||||
{
|
||||
bool resetCamera = (sCurrentDemoIndex != demoIndex);
|
||||
sCurrentDemoIndex = demoIndex;
|
||||
sCurrentHightlighted = demoIndex;
|
||||
int numDemos = gAllExamples->getNumRegisteredExamples();
|
||||
|
||||
|
||||
|
||||
if (demoIndex>numDemos)
|
||||
{
|
||||
demoIndex = 0;
|
||||
@@ -241,7 +255,7 @@ void selectDemo(int demoIndex)
|
||||
s_parameterInterface->removeAllParameters();
|
||||
int option = gAllExamples->getExampleOption(demoIndex);
|
||||
s_guiHelper= new OpenGLGuiHelper(s_app, sUseOpenGL2);
|
||||
sCurrentDemo = (*func)(0,s_guiHelper, option);
|
||||
sCurrentDemo = (*func)(CommonExampleOptions(s_guiHelper, option));
|
||||
if (sCurrentDemo)
|
||||
{
|
||||
if (gui)
|
||||
@@ -251,7 +265,12 @@ void selectDemo(int demoIndex)
|
||||
}
|
||||
b3Printf("Selected demo: %s",gAllExamples->getExampleName(demoIndex));
|
||||
gui->setExampleDescription(gAllExamples->getExampleDescription(demoIndex));
|
||||
|
||||
sCurrentDemo->initPhysics();
|
||||
if(resetCamera)
|
||||
{
|
||||
sCurrentDemo->resetCamera();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,14 +563,24 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
SimpleOpenGL3App* simpleApp=0;
|
||||
sUseOpenGL2 =args.CheckCmdLineFlag("opengl2");
|
||||
|
||||
const char* appTitle = "Bullet Physics ExampleBrowser";
|
||||
#if defined (_DEBUG) || defined (DEBUG)
|
||||
const char* optMode = "Debug build (slow)";
|
||||
#else
|
||||
const char* optMode = "Release build";
|
||||
#endif
|
||||
|
||||
if (sUseOpenGL2 )
|
||||
{
|
||||
|
||||
s_app = new SimpleOpenGL2App("AllBullet2Demos",width,height);
|
||||
char title[1024];
|
||||
sprintf(title,"%s using OpenGL2 fallback. %s", appTitle,optMode);
|
||||
s_app = new SimpleOpenGL2App(title,width,height);
|
||||
s_app->m_renderer = new SimpleOpenGL2Renderer(width,height);
|
||||
} else
|
||||
{
|
||||
simpleApp = new SimpleOpenGL3App("AllBullet2Demos",width,height);
|
||||
char title[1024];
|
||||
sprintf(title,"%s using OpenGL3+. %s", appTitle,optMode);
|
||||
simpleApp = new SimpleOpenGL3App(title,width,height);
|
||||
s_app = simpleApp;
|
||||
}
|
||||
char* gVideoFileName = 0;
|
||||
@@ -692,6 +721,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
}
|
||||
|
||||
gui->registerFileOpenCallback(fileOpenCallback);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -775,6 +805,22 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if (s_guiHelper && s_guiHelper->getRenderInterface() && s_guiHelper->getRenderInterface()->getActiveCamera())
|
||||
{
|
||||
char msg[1024];
|
||||
float camDist = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraDistance();
|
||||
float pitch = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraPitch();
|
||||
float yaw = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraYaw();
|
||||
float camTarget[3];
|
||||
s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraTargetPosition(camTarget);
|
||||
sprintf(msg,"dist=%f, pitch=%f, yaw=%f,target=%f,%f,%f", camDist,pitch,yaw,camTarget[0],camTarget[1],camTarget[2]);
|
||||
gui->setStatusBarMessage(msg, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int toggle = 1;
|
||||
if (1)
|
||||
{
|
||||
|
||||
@@ -117,7 +117,7 @@ public:
|
||||
static btVector4 sColors[4] =
|
||||
{
|
||||
btVector4(0.3,0.3,1,1),
|
||||
btVector4(1,0,0,1),
|
||||
btVector4(0.6,0.6,1,1),
|
||||
btVector4(0,1,0,1),
|
||||
btVector4(0,1,1,1),
|
||||
//btVector4(1,1,0,1),
|
||||
@@ -128,7 +128,6 @@ struct OpenGLGuiHelperInternalData
|
||||
{
|
||||
struct CommonGraphicsApp* m_glApp;
|
||||
class MyDebugDrawer* m_debugDraw;
|
||||
int m_curColor;
|
||||
GL_ShapeDrawer* m_gl2ShapeDrawer;
|
||||
};
|
||||
|
||||
@@ -139,7 +138,7 @@ OpenGLGuiHelper::OpenGLGuiHelper(CommonGraphicsApp* glApp, bool useOpenGL2)
|
||||
m_data = new OpenGLGuiHelperInternalData;
|
||||
m_data->m_glApp = glApp;
|
||||
m_data->m_debugDraw = 0;
|
||||
m_data->m_curColor = 0;
|
||||
|
||||
m_data->m_gl2ShapeDrawer = 0;
|
||||
|
||||
if (useOpenGL2)
|
||||
@@ -487,15 +486,20 @@ void OpenGLGuiHelper::setUpAxis(int axis)
|
||||
m_data->m_glApp->setUpAxis(axis);
|
||||
}
|
||||
|
||||
|
||||
btVector3 OpenGLGuiHelper::selectColor()
|
||||
void OpenGLGuiHelper::resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ)
|
||||
{
|
||||
btVector4 color = sColors[m_data->m_curColor];
|
||||
m_data->m_curColor++;
|
||||
m_data->m_curColor&=3;
|
||||
return color;
|
||||
if (getRenderInterface() && getRenderInterface()->getActiveCamera())
|
||||
{
|
||||
getRenderInterface()->getActiveCamera()->setCameraDistance(camDist);
|
||||
getRenderInterface()->getActiveCamera()->setCameraPitch(pitch);
|
||||
getRenderInterface()->getActiveCamera()->setCameraYaw(yaw);
|
||||
getRenderInterface()->getActiveCamera()->setCameraTargetPosition(camPosX,camPosY,camPosZ);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
struct MyConvertPointerSizeT
|
||||
{
|
||||
union
|
||||
@@ -530,7 +534,9 @@ void OpenGLGuiHelper::autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWor
|
||||
//btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
//does this also work for btMultiBody/btMultiBodyLinkCollider?
|
||||
createCollisionShapeGraphicsObject(colObj->getCollisionShape());
|
||||
btVector3 color= selectColor();
|
||||
int colorIndex = colObj->getBroadphaseHandle()->getUid() & 3;
|
||||
|
||||
btVector3 color= sColors[colorIndex];
|
||||
createCollisionObjectGraphicsObject(colObj,color);
|
||||
|
||||
}
|
||||
@@ -546,3 +552,4 @@ struct CommonGraphicsApp* OpenGLGuiHelper::getAppInterface()
|
||||
{
|
||||
return m_data->m_glApp;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ struct OpenGLGuiHelper : public GUIHelperInterface
|
||||
virtual void syncPhysicsToGraphics(const btDiscreteDynamicsWorld* rbWorld);
|
||||
|
||||
|
||||
|
||||
virtual void render(const btDiscreteDynamicsWorld* rbWorld);
|
||||
|
||||
virtual void createPhysicsDebugDrawer(btDiscreteDynamicsWorld* rbWorld);
|
||||
@@ -42,10 +41,9 @@ struct OpenGLGuiHelper : public GUIHelperInterface
|
||||
|
||||
virtual struct CommonGraphicsApp* getAppInterface();
|
||||
|
||||
|
||||
virtual void setUpAxis(int axis);
|
||||
|
||||
btVector3 selectColor();
|
||||
virtual void resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ);
|
||||
|
||||
virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld) ;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
ExampleEntries examples;
|
||||
examples.initExampleEntries();
|
||||
examples.initOpenCLExampleEntries();
|
||||
|
||||
ExampleBrowserInterface* exampleBrowser = new DefaultBrowser(&examples);
|
||||
bool init = exampleBrowser->init(argc,argv);
|
||||
|
||||
Reference in New Issue
Block a user