expose basic parameters in SimpleOpenGL3App, test with accumulated hinge angle, GUI is still preliminary

This commit is contained in:
Erwin Coumans
2014-07-31 11:47:04 -07:00
parent d798144167
commit 4b8c8e7910
13 changed files with 310 additions and 81 deletions

View File

@@ -7,11 +7,14 @@ class btBoxShape;
class btTransform;
class btCollisionShape;
#include "LinearMath/btVector3.h"
#include "CommonParameterInterface.h"
class btDiscreteDynamicsWorld;
///The GraphicsPhysicsBridge let's the graphics engine create graphics representation and synchronize
struct GraphicsPhysicsBridge
{
virtual void createRigidBodyGraphicsObject(btRigidBody* body,const btVector3& color)
{
}
@@ -24,6 +27,12 @@ struct GraphicsPhysicsBridge
virtual void createPhysicsDebugDrawer( btDiscreteDynamicsWorld* rbWorld)
{
}
virtual CommonParameterInterface* getParameterInterface()
{
return 0;
}
};
struct CommonPhysicsSetup

View File

@@ -0,0 +1,70 @@
#include "ConstraintPhysicsSetup.h"
ConstraintPhysicsSetup::ConstraintPhysicsSetup()
{
}
ConstraintPhysicsSetup::~ConstraintPhysicsSetup()
{
}
btScalar val;
btHingeAccumulatedAngleConstraint* spDoorHinge=0;
void ConstraintPhysicsSetup::stepSimulation(float deltaTime)
{
val=spDoorHinge->getAccumulatedHingeAngle()*SIMD_DEGS_PER_RAD;// spDoorHinge->getHingeAngle()*SIMD_DEGS_PER_RAD;
if (m_dynamicsWorld)
{
m_dynamicsWorld->stepSimulation(deltaTime);
}
}
void ConstraintPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
{
createEmptyDynamicsWorld();
gfxBridge.createPhysicsDebugDrawer(m_dynamicsWorld);
int mode = btIDebugDraw::DBG_DrawWireframe
+btIDebugDraw::DBG_DrawConstraints
+btIDebugDraw::DBG_DrawConstraintLimits;
m_dynamicsWorld->getDebugDrawer()->setDebugMode(mode);
val=1.f;
SliderParams slider("hinge angle",&val);
slider.m_minVal=-720;
slider.m_maxVal=720;
gfxBridge.getParameterInterface()->registerSliderFloatParameter(slider);
{ // create a door using hinge constraint attached to the world
btCollisionShape* pDoorShape = new btBoxShape(btVector3(2.0f, 5.0f, 0.2f));
m_collisionShapes.push_back(pDoorShape);
btTransform doorTrans;
doorTrans.setIdentity();
doorTrans.setOrigin(btVector3(-5.0f, -2.0f, 0.0f));
btRigidBody* pDoorBody = createRigidBody( 1.0, doorTrans, pDoorShape);
pDoorBody->setActivationState(DISABLE_DEACTIVATION);
const btVector3 btPivotA(10.f + 2.1f, -2.0f, 0.0f ); // right next to the door slightly outside
btVector3 btAxisA( 0.0f, 1.0f, 0.0f ); // pointing upwards, aka Y-axis
spDoorHinge = new btHingeAccumulatedAngleConstraint( *pDoorBody, btPivotA, btAxisA );
// spDoorHinge->setLimit( 0.0f, SIMD_PI_2 );
// test problem values
// spDoorHinge->setLimit( -SIMD_PI, SIMD_PI*0.8f);
// spDoorHinge->setLimit( 1.f, -1.f);
// spDoorHinge->setLimit( -SIMD_PI*0.8f, SIMD_PI);
// spDoorHinge->setLimit( -SIMD_PI*0.8f, SIMD_PI, 0.9f, 0.3f, 0.0f);
// spDoorHinge->setLimit( -SIMD_PI*0.8f, SIMD_PI, 0.9f, 0.01f, 0.0f); // "sticky limits"
// spDoorHinge->setLimit( -SIMD_PI * 0.25f, SIMD_PI * 0.25f );
// spDoorHinge->setLimit( 0.0f, 0.0f );
m_dynamicsWorld->addConstraint(spDoorHinge);
spDoorHinge->setDbgDrawSize(btScalar(5.f));
//doorTrans.setOrigin(btVector3(-5.0f, 2.0f, 0.0f));
//btRigidBody* pDropBody = localCreateRigidBody( 10.0, doorTrans, shape);
}
}

View File

@@ -0,0 +1,16 @@
#ifndef CONSTAINT_PHYSICS_SETUP_H
#define CONSTAINT_PHYSICS_SETUP_H
#include "../CommonRigidBodySetup.h"
struct ConstraintPhysicsSetup : public CommonRigidBodySetup
{
ConstraintPhysicsSetup();
virtual ~ConstraintPhysicsSetup();
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);
virtual void stepSimulation(float deltaTime);
};
#endif //CONSTAINT_PHYSICS_SETUP_H

View File

@@ -5,6 +5,8 @@
#include "BulletDemoInterface.h"
#include "../bullet2/BasicDemo/BasicDemo.h"
#include "../bullet2/BasicDemo/HingeDemo.h"
#include "../bullet2/BasicDemo/HingeDemo.h"
#include "../bullet2/FeatherstoneMultiBodyDemo/BulletMultiBodyDemos.h"
#include "../bullet2/FeatherstoneMultiBodyDemo/MultiDofDemo.h"
@@ -12,6 +14,8 @@
#include "../bullet2/LuaDemo/LuaDemo.h"
#include "../bullet2/ChainDemo/ChainDemo.h"
#include "../../Demos/CcdPhysicsDemo/CcdPhysicsSetup.h"
#include "../../Demos/ConstraintDemo/ConstraintPhysicsSetup.h"
static BulletDemoInterface* MyCcdPhysicsDemoCreateFunc(SimpleOpenGL3App* app)
{
@@ -25,6 +29,13 @@ static BulletDemoInterface* MyKinematicObjectCreateFunc(SimpleOpenGL3App* app)
return new BasicDemo(app, physicsSetup);
}
static BulletDemoInterface* MyConstraintCreateFunc(SimpleOpenGL3App* app)
{
CommonPhysicsSetup* physicsSetup = new ConstraintPhysicsSetup();
return new BasicDemo(app, physicsSetup);
}
struct BulletDemoEntry
{
int m_menuLevel;
@@ -42,6 +53,7 @@ static BulletDemoEntry allDemos[]=
{1,"BasicDemo",BasicDemo::MyCreateFunc},
{ 1, "CcdDemo", MyCcdPhysicsDemoCreateFunc },
{ 1, "Kinematic", MyKinematicObjectCreateFunc },
{ 1, "Constraints", MyConstraintCreateFunc },
/* {1,"ChainDemo",ChainDemo::MyCreateFunc},
// {0, "Stress tests", 0 },

View File

@@ -0,0 +1,142 @@
#include "GwenParameterInterface.h"
#include "../GpuDemos/gwenInternalData.h"
template<typename T>
struct MySliderEventHandler : public Gwen::Event::Handler
{
Gwen::Controls::TextBox* m_label;
Gwen::Controls::Slider* m_pSlider;
char m_variableName[1024];
T* m_targetValue;
MySliderEventHandler(const char* varName, Gwen::Controls::TextBox* label, Gwen::Controls::Slider* pSlider,T* target)
:m_label(label),
m_pSlider(pSlider),
m_targetValue(target)
{
memcpy(m_variableName,varName,strlen(varName)+1);
}
void SliderMoved( Gwen::Controls::Base* pControl )
{
Gwen::Controls::Slider* pSlider = (Gwen::Controls::Slider*)pControl;
//printf("value = %f\n", pSlider->GetValue());//UnitPrint( Utility::Format( L"Slider Value: %.2f", pSlider->GetValue() ) );
float bla = pSlider->GetValue();
T v = T(bla);
SetValue(v);
}
void SetValue(T v)
{
if (v < m_pSlider->GetRangeMin())
{
printf("?\n");
}
if (v > m_pSlider->GetRangeMax())
{
printf("?\n");
}
m_pSlider->SetValue(v,true);
(*m_targetValue) = v;
float val = float(v);//todo: specialize on template type
char txt[1024];
sprintf(txt,"%s : %.3f", m_variableName,val);
m_label->SetText(txt);
}
};
struct GwenParameters
{
b3AlignedObjectArray<MySliderEventHandler<btScalar>*> m_sliderEventHandlers;
b3AlignedObjectArray<Gwen::Controls::HorizontalSlider*> m_sliders;
b3AlignedObjectArray<Gwen::Controls::TextBox*> m_textLabels;
int m_savedYposition;
};
GwenParameterInterface::GwenParameterInterface(GwenInternalData* gwenInternalData)
:m_gwenInternalData(gwenInternalData)
{
m_paramInternalData = new GwenParameters;
m_paramInternalData->m_savedYposition = m_gwenInternalData->m_curYposition;
}
GwenParameterInterface::~GwenParameterInterface()
{
removeAllParameters();
delete m_paramInternalData;
}
#include <stdio.h>
void GwenParameterInterface::registerSliderFloatParameter(SliderParams& params)
{
Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox(m_gwenInternalData->m_demoPage->GetPage());
m_paramInternalData->m_textLabels.push_back(label);
//m_data->m_myControls.push_back(label);
label->SetText( params.m_name);
label->SetPos( 10, 10 + 25 );
label->SetWidth(110);
label->SetPos(10,m_gwenInternalData->m_curYposition);
m_gwenInternalData->m_curYposition+=22;
Gwen::Controls::HorizontalSlider* pSlider = new Gwen::Controls::HorizontalSlider( m_gwenInternalData->m_demoPage->GetPage());
m_paramInternalData->m_sliders.push_back(pSlider);
//m_data->m_myControls.push_back(pSlider);
pSlider->SetPos( 10, m_gwenInternalData->m_curYposition );
pSlider->SetSize( 100, 20 );
pSlider->SetRange( params.m_minVal, params.m_maxVal);
pSlider->SetNotchCount(20);//float(params.m_maxVal-params.m_minVal)/100.f);
pSlider->SetClampToNotches( params.m_clampToNotches );
pSlider->SetValue( *params.m_paramValuePointer);//dimensions[i] );
char labelName[1024];
sprintf(labelName,"%s",params.m_name);//axisNames[0]);
MySliderEventHandler<btScalar>* handler = new MySliderEventHandler<btScalar>(labelName,label,pSlider,params.m_paramValuePointer);
m_paramInternalData->m_sliderEventHandlers.push_back(handler);
pSlider->onValueChanged.Add( handler, &MySliderEventHandler<btScalar>::SliderMoved );
handler->SliderMoved(pSlider);
float v = pSlider->GetValue();
m_gwenInternalData->m_curYposition+=22;
}
void GwenParameterInterface::syncParameters()
{
for (int i=0;i<m_paramInternalData->m_sliderEventHandlers.size();i++)
{
MySliderEventHandler<btScalar>* handler = m_paramInternalData->m_sliderEventHandlers[i];
handler->m_pSlider->SetValue(*handler->m_targetValue,true);
}
}
void GwenParameterInterface::removeAllParameters()
{
for (int i=0;i<m_paramInternalData->m_sliders.size();i++)
{
delete m_paramInternalData->m_sliders[i];
}
m_paramInternalData->m_sliders.clear();
for (int i=0;i<m_paramInternalData->m_sliderEventHandlers.size();i++)
{
delete m_paramInternalData->m_sliderEventHandlers[i];
}
m_paramInternalData->m_sliderEventHandlers.clear();
for (int i=0;i<m_paramInternalData->m_textLabels.size();i++)
{
delete m_paramInternalData->m_textLabels[i];
}
m_paramInternalData->m_textLabels.clear();
m_gwenInternalData->m_curYposition = this->m_paramInternalData->m_savedYposition;
}

View File

@@ -0,0 +1,20 @@
#ifndef GWEN_PARAMETER_INTERFACE_H
#define GWEN_PARAMETER_INTERFACE_H
#include "../../Demos/CommonParameterInterface.h"
struct GwenParameterInterface : public CommonParameterInterface
{
struct GwenInternalData* m_gwenInternalData;
struct GwenParameters* m_paramInternalData;
GwenParameterInterface(struct GwenInternalData* gwenInternalData);
virtual ~GwenParameterInterface();
virtual void registerSliderFloatParameter(SliderParams& params);
virtual void syncParameters();
virtual void removeAllParameters();
};
#endif//GWEN_PARAMETER_INTERFACE_H

View File

@@ -6,6 +6,8 @@
#include "../GpuDemos/gwenUserInterface.h"
#include "BulletDemoEntries.h"
#include "../../btgui/Timing/b3Clock.h"
#include "GwenParameterInterface.h"
#define DEMO_SELECTION_COMBOBOX 13
const char* startFileName = "bulletDemo.txt";
static SimpleOpenGL3App* app=0;
@@ -114,6 +116,7 @@ void selectDemo(int demoIndex)
}
if (allDemos[demoIndex].m_createFunc && app)
{
app->m_parameterInterface->removeAllParameters();
sCurrentDemo = (*allDemos[demoIndex].m_createFunc)(app);
if (sCurrentDemo)
{
@@ -225,81 +228,6 @@ struct MyMenuItemHander :public Gwen::Event::Handler
template<typename T>
struct MySliderEventHandler : public Gwen::Event::Handler
{
Gwen::Controls::TextBox* m_label;
Gwen::Controls::Slider* m_pSlider;
char m_variableName[1024];
T* m_targetValue;
MySliderEventHandler(const char* varName, Gwen::Controls::TextBox* label, Gwen::Controls::Slider* pSlider,T* target)
:m_label(label),
m_pSlider(pSlider),
m_targetValue(target)
{
memcpy(m_variableName,varName,strlen(varName)+1);
}
void SliderMoved( Gwen::Controls::Base* pControl )
{
Gwen::Controls::Slider* pSlider = (Gwen::Controls::Slider*)pControl;
//printf("value = %f\n", pSlider->GetValue());//UnitPrint( Utility::Format( L"Slider Value: %.2f", pSlider->GetValue() ) );
float bla = pSlider->GetValue();
T v = T(bla);
SetValue(v);
}
void SetValue(T v)
{
if (v < m_pSlider->GetRangeMin())
{
printf("?\n");
}
if (v > m_pSlider->GetRangeMax())
{
printf("?\n");
}
m_pSlider->SetValue(v,true);
(*m_targetValue) = v;
int val = int(v);//todo: specialize on template type
char txt[1024];
sprintf(txt,"%s : %d", m_variableName,val);
m_label->SetText(txt);
}
};
void MyParameter(const char* name, GwenInternalData* data, double* param)
{
Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox(data->m_demoPage->GetPage());
//m_data->m_myControls.push_back(label);
label->SetText( name);
label->SetPos( 10, 10 + 25 );
label->SetWidth(110);
label->SetPos(10,data->m_curYposition);
data->m_curYposition+=22;
Gwen::Controls::HorizontalSlider* pSlider = new Gwen::Controls::HorizontalSlider( data->m_demoPage->GetPage());
//m_data->m_myControls.push_back(pSlider);
pSlider->SetPos( 10, data->m_curYposition );
pSlider->SetSize( 100, 20 );
pSlider->SetRange( -10, 10 );
pSlider->SetNotchCount(10);
pSlider->SetClampToNotches( true );
pSlider->SetValue( *param);//dimensions[i] );
char labelName[1024];
sprintf(labelName,"%s",name);//axisNames[0]);
MySliderEventHandler<double>* handler = new MySliderEventHandler<double>(labelName,label,pSlider,param);
pSlider->onValueChanged.Add( handler, &MySliderEventHandler<double>::SliderMoved );
handler->SliderMoved(pSlider);
float v = pSlider->GetValue();
data->m_curYposition+=22;
}
extern float shadowMapWorldSize;
int main(int argc, char* argv[])
{
@@ -318,6 +246,7 @@ int main(int argc, char* argv[])
app->m_window->setMouseMoveCallback(MyMouseMoveCallback);
app->m_window->setMouseButtonCallback(MyMouseButtonCallback);
app->m_window->setKeyboardCallback(MyKeyboardCallback);
GLint err = glGetError();
assert(err==GL_NO_ERROR);
@@ -328,6 +257,10 @@ int main(int argc, char* argv[])
// gui->getInternalData()->m_explorerPage
Gwen::Controls::TreeControl* tree = gui->getInternalData()->m_explorerTreeCtrl;
app->m_parameterInterface = new GwenParameterInterface(gui->getInternalData());
//gui->getInternalData()->m_demoPage;
int numDemos = sizeof(allDemos)/sizeof(BulletDemoEntry);
@@ -390,9 +323,7 @@ int main(int argc, char* argv[])
*/
unsigned long int prevTimeInMicroseconds = clock.getTimeMicroseconds();
MyParameter("Motor A",gui->getInternalData(),&motorA);
MyParameter("Motor B",gui->getInternalData(),&motorB);
do
{
@@ -438,6 +369,7 @@ int main(int argc, char* argv[])
gui->draw(app->m_instancingRenderer->getScreenWidth(),app->m_instancingRenderer->getScreenHeight());
}
toggle=1-toggle;
app->m_parameterInterface->syncParameters();
app->swapBuffer();
} while (!app->m_window->requestedExit());

View File

@@ -27,6 +27,8 @@
"../../Demos/BasicDemo/BasicDemoPhysicsSetup.h",
"../../Demos/CcdPhysicsDemo/CcdPhysicsSetup.cpp",
"../../Demos/CcdPhysicsDemo/CcdPhysicsSetup.h",
"../../Demos/ConstraintDemo/ConstraintPhysicsSetup.cpp",
"../../Demos/ConstraintDemo/ConstraintPhysicsSetup.h",
"../bullet2/FeatherstoneMultiBodyDemo/BulletMultiBodyDemos.cpp",
"../bullet2/FeatherstoneMultiBodyDemo/BulletMultiBodyDemos.h",
"../bullet2/FeatherstoneMultiBodyDemo/MultiDofDemo.cpp",

View File

@@ -31,12 +31,25 @@ GwenUserInterface::~GwenUserInterface()
delete coreRend;
}
class MyMenuItems : public Gwen::Controls::Base
{
public:
MyMenuItems() :Gwen::Controls::Base(0)
{
}
void myQuitApp( Gwen::Controls::Base* pControl )
{
exit(0);
}
};
struct MyTestMenuBar : public Gwen::Controls::MenuStrip
{
MyMenuItems* menuItems = new MyMenuItems;
MyTestMenuBar(Gwen::Controls::Base* pParent)
:Gwen::Controls::MenuStrip(pParent)
@@ -44,7 +57,7 @@ struct MyTestMenuBar : public Gwen::Controls::MenuStrip
// Gwen::Controls::MenuStrip* menu = new Gwen::Controls::MenuStrip( pParent );
{
Gwen::Controls::MenuItem* pRoot = AddItem( L"File" );
pRoot->GetMenu()->AddItem(L"Quit",menuItems,(Gwen::Event::Handler::Function)&MyMenuItems::myQuitApp);
pRoot = AddItem( L"View" );
// Gwen::Event::Handler* handler = GWEN_MCALL(&MyTestMenuBar::MenuItemSelect );
pRoot->GetMenu()->AddItem( L"Profiler");//,,m_profileWindow,(Gwen::Event::Handler::Function)&MyProfileWindow::MenuItemSelect);

View File

@@ -140,6 +140,11 @@ struct MyGraphicsPhysicsBridge : public GraphicsPhysicsBridge
);
}
virtual CommonParameterInterface* getParameterInterface()
{
return m_glApp->m_parameterInterface;
}
};
Bullet2RigidBodyDemo::Bullet2RigidBodyDemo(SimpleOpenGL3App* app, CommonPhysicsSetup* physicsSetup)

View File

@@ -28,7 +28,10 @@ public:
virtual void renderScene();
virtual void physicsDebugDraw();
virtual void stepSimulation(float dt);
virtual CommonPhysicsSetup* getPhysicsSetup()
{
return m_physicsSetup;
}
virtual ~Bullet2RigidBodyDemo();
btVector3 getRayTo(int x,int y);

View File

@@ -41,6 +41,7 @@ struct SimpleInternalData
const char* m_frameDumpPngFileName;
FILE* m_ffmpegFile;
GLRenderToTexture* m_renderTexture;
void* m_userPointer;
};
@@ -83,6 +84,7 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
m_data->m_frameDumpPngFileName = 0;
m_data->m_renderTexture = 0;
m_data->m_ffmpegFile = 0;
m_data->m_userPointer = 0;
m_window = new b3gDefaultOpenGLWindow();
b3gWindowConstructionInfo ci;
@@ -117,6 +119,7 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
b3Assert(glGetError() ==GL_NO_ERROR);
m_primRenderer = new GLPrimitiveRenderer(width,height);
m_parameterInterface = 0;
b3Assert(glGetError() ==GL_NO_ERROR);

View File

@@ -31,6 +31,7 @@ struct SimpleOpenGL3App
class b3gWindowInterface* m_window;
class GLPrimitiveRenderer* m_primRenderer;
class GLInstancingRenderer* m_instancingRenderer;
struct CommonParameterInterface* m_parameterInterface;
SimpleOpenGL3App(const char* title, int width,int height);
virtual ~SimpleOpenGL3App();
@@ -46,6 +47,7 @@ struct SimpleOpenGL3App
void drawText( const char* txt, int posX, int posY);
struct sth_stash* getFontStash();
};
#endif //SIMPLE_OPENGL3_APP_H