improve usability of ExampleBrowser
store command-line arguments in bulletDemo.txt save/load of configuration, save demo name instead of index add setBackgroundColor as example (background_color_red) and mouse move/wheel speed config (mouse_wheel_multiplier and mouse_move_multiplier) (saved after changing the demo) default btIDebugDraw colors can be changed b3CommandLineArgs::GetCmdLineArgument returns bool, and b3CommandLineArgs::addArgs added fix copy/paste
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include "gwenUserInterface.h"
|
||||
#include "gwenInternalData.h"
|
||||
#include "Gwen/Controls/ImagePanel.h"
|
||||
#include "Gwen/Controls/ColorPicker.h"
|
||||
//#include "Gwen/Controls/HSVColorPicker.h"
|
||||
|
||||
class MyGraphWindow* graphWindow = 0;
|
||||
|
||||
@@ -365,18 +367,21 @@ void GwenUserInterface::init(int width, int height,Gwen::Renderer::Base* rendere
|
||||
|
||||
Gwen::UnicodeString explorerStr1(L"Explorer");
|
||||
m_data->m_explorerPage = explorerTab->AddPage(explorerStr1);
|
||||
Gwen::UnicodeString shapesStr1(L"Shapes");
|
||||
explorerTab->AddPage(shapesStr1);
|
||||
Gwen::UnicodeString testStr1(L"Test");
|
||||
explorerTab->AddPage(testStr1);
|
||||
Gwen::UnicodeString shapesStr1(L"Test");
|
||||
Gwen::Controls::TabButton* shapes = explorerTab->AddPage(shapesStr1);
|
||||
|
||||
///todo(erwincoumans) figure out why the HSV color picker is extremely slow
|
||||
//Gwen::Controls::HSVColorPicker* color = new Gwen::Controls::HSVColorPicker(shapes->GetPage());
|
||||
Gwen::Controls::ColorPicker* color = new Gwen::Controls::ColorPicker(shapes->GetPage());
|
||||
color->SetKeyboardInputEnabled(true);
|
||||
|
||||
Gwen::Controls::TreeControl* ctrl = new Gwen::Controls::TreeControl(m_data->m_explorerPage->GetPage());
|
||||
m_data->m_explorerTreeCtrl = ctrl;
|
||||
ctrl->SetKeyboardInputEnabled(true);
|
||||
ctrl->Focus();
|
||||
ctrl->SetBounds(2, 10, 236, 300);
|
||||
|
||||
m_data->m_exampleInfoGroupBox = new Gwen::Controls::Label( m_data->m_explorerPage->GetPage() );
|
||||
m_data->m_exampleInfoGroupBox = new Gwen::Controls::Label( m_data->m_explorerPage->GetPage() );
|
||||
m_data->m_exampleInfoGroupBox->SetPos(2, 314);
|
||||
m_data->m_exampleInfoGroupBox->SetHeight( 15 );
|
||||
m_data->m_exampleInfoGroupBox->SetWidth(234);
|
||||
@@ -517,38 +522,83 @@ bool GwenUserInterface::mouseMoveCallback( float x, float y)
|
||||
|
||||
bool GwenUserInterface::keyboardCallback(int bulletKey, int state)
|
||||
{
|
||||
int key = -1;
|
||||
int gwenKey = -1;
|
||||
if (m_data->pCanvas)
|
||||
{
|
||||
//convert 'Bullet' keys into 'Gwen' keys
|
||||
switch (bulletKey)
|
||||
{
|
||||
case B3G_RETURN:
|
||||
case B3G_LEFT_ARROW:
|
||||
{
|
||||
key = Gwen::Key::Return;
|
||||
break;
|
||||
gwenKey = Gwen::Key::Left;
|
||||
break;
|
||||
}
|
||||
case B3G_LEFT_ARROW:
|
||||
key = Gwen::Key::Left;
|
||||
case B3G_RIGHT_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Right;
|
||||
break;
|
||||
case B3G_RIGHT_ARROW:
|
||||
key = Gwen::Key::Right;
|
||||
}
|
||||
case B3G_UP_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Up;
|
||||
break;
|
||||
}
|
||||
case B3G_DOWN_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Down;
|
||||
break;
|
||||
}
|
||||
case B3G_BACKSPACE:
|
||||
{
|
||||
gwenKey = Gwen::Key::Backspace;
|
||||
break;
|
||||
}
|
||||
case B3G_DELETE:
|
||||
{
|
||||
gwenKey = Gwen::Key::Delete;
|
||||
break;
|
||||
}
|
||||
case B3G_HOME:
|
||||
{
|
||||
gwenKey = Gwen::Key::Home;
|
||||
break;
|
||||
}
|
||||
case B3G_END:
|
||||
{
|
||||
gwenKey = Gwen::Key::End;
|
||||
break;
|
||||
}
|
||||
case B3G_SHIFT:
|
||||
{
|
||||
gwenKey = Gwen::Key::Shift;
|
||||
break;
|
||||
}
|
||||
case B3G_CONTROL:
|
||||
{
|
||||
gwenKey = Gwen::Key::Control;
|
||||
break;
|
||||
}
|
||||
|
||||
case B3G_UP_ARROW:
|
||||
key = Gwen::Key::Up;
|
||||
break;
|
||||
case B3G_DOWN_ARROW:
|
||||
key = Gwen::Key::Down;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
bool bDown = (state == 1);
|
||||
|
||||
return m_data->pCanvas->InputKey(key, bDown);
|
||||
if (gwenKey>=0)
|
||||
{
|
||||
return m_data->pCanvas->InputKey(gwenKey,state==1);
|
||||
} else
|
||||
{
|
||||
if (bulletKey<256 && state)
|
||||
{
|
||||
Gwen::UnicodeChar c = ( Gwen::UnicodeChar ) bulletKey;
|
||||
return m_data->pCanvas->InputCharacter(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ extern bool useShadowMap;
|
||||
static bool visualWireframe=false;
|
||||
static bool renderVisualGeometry=true;
|
||||
static bool renderGrid = true;
|
||||
static bool enable_experimental_opencl = false;
|
||||
|
||||
int gDebugDrawFlags = 0;
|
||||
static bool pauseSimulation=false;
|
||||
int midiBaseIndex = 176;
|
||||
@@ -101,6 +103,10 @@ void deleteDemo()
|
||||
}
|
||||
}
|
||||
|
||||
const char* gPngFileName = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
b3KeyboardCallback prevKeyboardCallback = 0;
|
||||
|
||||
@@ -172,6 +178,29 @@ void MyKeyboardCallback(int key, int state)
|
||||
useShadowMap=!useShadowMap;
|
||||
}
|
||||
#endif
|
||||
if (key==B3G_F1)
|
||||
{
|
||||
static int count=0;
|
||||
if (state)
|
||||
{
|
||||
b3Printf("F1 pressed %d", count++);
|
||||
|
||||
if (gPngFileName)
|
||||
{
|
||||
b3Printf("disable image dump");
|
||||
|
||||
gPngFileName=0;
|
||||
} else
|
||||
{
|
||||
gPngFileName = gAllExamples->getExampleName(sCurrentDemoIndex);
|
||||
b3Printf("enable image dump %s",gPngFileName);
|
||||
|
||||
}
|
||||
} else
|
||||
{
|
||||
b3Printf("F1 released %d",count++);
|
||||
}
|
||||
}
|
||||
if (key==B3G_ESCAPE && s_window)
|
||||
{
|
||||
|
||||
@@ -182,6 +211,7 @@ void MyKeyboardCallback(int key, int state)
|
||||
prevKeyboardCallback(key,state);
|
||||
}
|
||||
|
||||
|
||||
b3MouseMoveCallback prevMouseMoveCallback = 0;
|
||||
static void MyMouseMoveCallback( float x, float y)
|
||||
{
|
||||
@@ -313,31 +343,59 @@ void selectDemo(int demoIndex)
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static void saveCurrentDemoEntry(int currentEntry,const char* startFileName)
|
||||
static void saveCurrentSettings(int currentEntry,const char* startFileName)
|
||||
{
|
||||
FILE* f = fopen(startFileName,"w");
|
||||
if (f)
|
||||
{
|
||||
fprintf(f,"%d\n",currentEntry);
|
||||
fprintf(f,"--start_demo_name=%s\n", gAllExamples->getExampleName(sCurrentDemoIndex));
|
||||
fprintf(f,"--mouse_move_multiplier=%f\n", s_app->getMouseMoveMultiplier());
|
||||
fprintf(f,"--mouse_wheel_multiplier=%f\n", s_app->getMouseWheelMultiplier());
|
||||
float red,green,blue;
|
||||
s_app->getBackgroundColor(&red,&green,&blue);
|
||||
fprintf(f,"--background_color_red= %f\n", red);
|
||||
fprintf(f,"--background_color_green= %f\n", green);
|
||||
fprintf(f,"--background_color_blue= %f\n", blue);
|
||||
|
||||
if (enable_experimental_opencl)
|
||||
{
|
||||
fprintf(f,"--enable_experimental_opencl\n");
|
||||
} else
|
||||
{
|
||||
fprintf(f,"//enable_experimental_opencl\n");
|
||||
}
|
||||
if (sUseOpenGL2 )
|
||||
{
|
||||
fprintf(f,"--opengl2\n");
|
||||
} else
|
||||
{
|
||||
fprintf(f,"//opengl2\n");
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
};
|
||||
|
||||
static int loadCurrentDemoEntry(const char* startFileName)
|
||||
static void loadCurrentSettings(const char* startFileName, b3CommandLineArgs& args)
|
||||
{
|
||||
int currentEntry= 0;
|
||||
FILE* f = fopen(startFileName,"r");
|
||||
if (f)
|
||||
{
|
||||
int result;
|
||||
result = fscanf(f,"%d",¤tEntry);
|
||||
if (result)
|
||||
char oneline[1024];
|
||||
char* argv[] = {0,&oneline[0]};
|
||||
|
||||
while( fgets (oneline, 1024, f)!=NULL )
|
||||
{
|
||||
return currentEntry;
|
||||
char *pos;
|
||||
if ((pos=strchr(oneline, '\n')) != NULL)
|
||||
*pos = '\0';
|
||||
args.addArgs(2,argv);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
return 0;
|
||||
|
||||
};
|
||||
|
||||
void MyComboBoxCallback(int comboId, const char* item)
|
||||
@@ -351,7 +409,7 @@ void MyComboBoxCallback(int comboId, const char* item)
|
||||
if (strcmp(item,allNames[i])==0)
|
||||
{
|
||||
selectDemo(i);
|
||||
saveCurrentDemoEntry(sCurrentDemoIndex,startFileName);
|
||||
saveCurrentSettings(sCurrentDemoIndex,startFileName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -429,7 +487,7 @@ struct MyMenuItemHander :public Gwen::Event::Handler
|
||||
|
||||
|
||||
selectDemo(sCurrentHightlighted);
|
||||
saveCurrentDemoEntry(sCurrentDemoIndex, startFileName);
|
||||
saveCurrentSettings(sCurrentDemoIndex, startFileName);
|
||||
}
|
||||
void onButtonC(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
@@ -452,7 +510,7 @@ struct MyMenuItemHander :public Gwen::Event::Handler
|
||||
|
||||
// printf("onKeyReturn ! \n");
|
||||
selectDemo(sCurrentHightlighted);
|
||||
saveCurrentDemoEntry(sCurrentDemoIndex, startFileName);
|
||||
saveCurrentSettings(sCurrentDemoIndex, startFileName);
|
||||
|
||||
}
|
||||
|
||||
@@ -607,6 +665,8 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
{
|
||||
b3CommandLineArgs args(argc,argv);
|
||||
|
||||
loadCurrentSettings(startFileName, args);
|
||||
|
||||
|
||||
///The OpenCL rigid body pipeline is experimental and
|
||||
///most OpenCL drivers and OpenCL compilers have issues with our kernels.
|
||||
@@ -615,6 +675,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
///Note that several old OpenCL physics examples still have to be ported over to this new Example Browser
|
||||
if (args.CheckCmdLineFlag("enable_experimental_opencl"))
|
||||
{
|
||||
enable_experimental_opencl = true;
|
||||
gAllExamples->initOpenCLExampleEntries();
|
||||
}
|
||||
|
||||
@@ -671,6 +732,27 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
s_app->m_renderer->getActiveCamera()->setCameraPitch(0);
|
||||
s_app->m_renderer->getActiveCamera()->setCameraTargetPosition(0,0,0);
|
||||
|
||||
float mouseMoveMult= s_app->getMouseMoveMultiplier();
|
||||
if (args.GetCmdLineArgument("mouse_move_multiplier", mouseMoveMult))
|
||||
{
|
||||
s_app->setMouseMoveMultiplier(mouseMoveMult);
|
||||
}
|
||||
|
||||
|
||||
float mouseWheelMult= s_app->getMouseWheelMultiplier();
|
||||
if (args.GetCmdLineArgument("mouse_wheel_multiplier",mouseWheelMult))
|
||||
{
|
||||
s_app->setMouseWheelMultiplier(mouseWheelMult);
|
||||
}
|
||||
|
||||
|
||||
float red,green,blue;
|
||||
s_app->getBackgroundColor(&red,&green,&blue);
|
||||
args.GetCmdLineArgument("background_color_red",red);
|
||||
args.GetCmdLineArgument("background_color_green",green);
|
||||
args.GetCmdLineArgument("background_color_blue",blue);
|
||||
s_app->setBackgroundColor(red,green,blue);
|
||||
|
||||
b3SetCustomWarningMessageFunc(MyGuiPrintf);
|
||||
b3SetCustomPrintfFunc(MyGuiPrintf);
|
||||
b3SetCustomErrorMessageFunc(MyStatusBarError);
|
||||
@@ -725,12 +807,12 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
|
||||
//char nodeText[1024];
|
||||
//int curDemo = 0;
|
||||
int selectedDemo = loadCurrentDemoEntry(startFileName);
|
||||
int selectedDemo = 0;
|
||||
Gwen::Controls::TreeNode* curNode = tree;
|
||||
MyMenuItemHander* handler2 = new MyMenuItemHander(-1);
|
||||
|
||||
char* demoNameFromCommandOption = 0;
|
||||
args.GetCmdLineArgument("demo-name", demoNameFromCommandOption);
|
||||
args.GetCmdLineArgument("start_demo_name", demoNameFromCommandOption);
|
||||
if (demoNameFromCommandOption) {
|
||||
selectedDemo = -1;
|
||||
}
|
||||
@@ -770,9 +852,16 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
|
||||
|
||||
}
|
||||
if (demoNameFromCommandOption && strcmp(gAllExamples->getExampleName(d), demoNameFromCommandOption) == 0) {
|
||||
firstAvailableDemoIndex = d;
|
||||
firstNode = pNode;
|
||||
|
||||
if (demoNameFromCommandOption )
|
||||
{
|
||||
const char* demoName = gAllExamples->getExampleName(d);
|
||||
int res = strcmp(demoName, demoNameFromCommandOption);
|
||||
if (res==0)
|
||||
{
|
||||
firstAvailableDemoIndex = d;
|
||||
firstNode = pNode;
|
||||
}
|
||||
}
|
||||
|
||||
MyMenuItemHander* handler = new MyMenuItemHander(d);
|
||||
@@ -883,6 +972,25 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
||||
//printf("---------------------------------------------------\n");
|
||||
//printf("Framecount = %d\n",frameCount);
|
||||
|
||||
if (gPngFileName)
|
||||
{
|
||||
|
||||
static int skip = 0;
|
||||
skip++;
|
||||
if (skip>10)
|
||||
{
|
||||
skip=0;
|
||||
//printf("gPngFileName=%s\n",gPngFileName);
|
||||
static int s_frameCount = 0;
|
||||
char fileName[1024];
|
||||
sprintf(fileName,"%s%d.png",gPngFileName,s_frameCount++);
|
||||
b3Printf("Made screenshot %s",fileName);
|
||||
s_app->dumpNextFrameToPng(fileName);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sCurrentDemo->stepSimulation(deltaTime);//1./60.f);
|
||||
}
|
||||
|
||||
@@ -937,6 +1045,10 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
toggle=1-toggle;
|
||||
{
|
||||
BT_PROFILE("Sync Parameters");
|
||||
|
||||
@@ -36,6 +36,7 @@ class MyDebugDrawer : public btIDebugDraw
|
||||
btAlignedObjectArray<MyDebugVec3> m_linePoints;
|
||||
btAlignedObjectArray<unsigned int> m_lineIndices;
|
||||
btVector3 m_currentLineColor;
|
||||
DefaultColors m_ourColors;
|
||||
|
||||
public:
|
||||
|
||||
@@ -44,8 +45,20 @@ public:
|
||||
,m_debugMode(btIDebugDraw::DBG_DrawWireframe|btIDebugDraw::DBG_DrawAabb),
|
||||
m_currentLineColor(-1,-1,-1)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
virtual DefaultColors getDefaultColors() const
|
||||
{
|
||||
return m_ourColors;
|
||||
}
|
||||
///the default implementation for setDefaultColors has no effect. A derived class can implement it and store the colors.
|
||||
virtual void setDefaultColors(const DefaultColors& colors)
|
||||
{
|
||||
m_ourColors = colors;
|
||||
}
|
||||
|
||||
|
||||
virtual void drawLine(const btVector3& from1,const btVector3& to1,const btVector3& color1)
|
||||
{
|
||||
//float from[4] = {from1[0],from1[1],from1[2],from1[3]};
|
||||
@@ -174,7 +187,8 @@ void OpenGLGuiHelper::createCollisionObjectGraphicsObject(btCollisionObject* bod
|
||||
if (graphicsShapeId>=0)
|
||||
{
|
||||
// btAssert(graphicsShapeId >= 0);
|
||||
btVector3 localScaling = shape->getLocalScaling();
|
||||
//the graphics shape is already scaled
|
||||
btVector3 localScaling(1,1,1);
|
||||
int graphicsInstanceId = m_data->m_glApp->m_renderer->registerGraphicsInstance(graphicsShapeId, startTransform.getOrigin(), startTransform.getRotation(), color, localScaling);
|
||||
body->setUserIndex(graphicsInstanceId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user