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:
@@ -42,6 +42,7 @@ struct CommonGraphicsApp
|
||||
float m_mouseXpos;
|
||||
float m_mouseYpos;
|
||||
bool m_mouseInitialized;
|
||||
float m_backgroundColorRGB[3];
|
||||
|
||||
CommonGraphicsApp()
|
||||
:m_window(0),
|
||||
@@ -57,6 +58,9 @@ struct CommonGraphicsApp
|
||||
m_mouseYpos(0.f),
|
||||
m_mouseInitialized(false)
|
||||
{
|
||||
m_backgroundColorRGB[0] = 0.9;
|
||||
m_backgroundColorRGB[1] = 0.9;
|
||||
m_backgroundColorRGB[2] = 1;
|
||||
}
|
||||
virtual ~CommonGraphicsApp()
|
||||
{
|
||||
@@ -64,7 +68,42 @@ struct CommonGraphicsApp
|
||||
|
||||
virtual void dumpNextFrameToPng(const char* pngFilename){}
|
||||
virtual void dumpFramesToVideo(const char* mp4Filename){}
|
||||
|
||||
virtual void getBackgroundColor(float* red, float* green, float* blue) const
|
||||
{
|
||||
if (red)
|
||||
*red = m_backgroundColorRGB[0];
|
||||
if (green)
|
||||
*green = m_backgroundColorRGB[1];
|
||||
if (blue)
|
||||
*blue = m_backgroundColorRGB[2];
|
||||
}
|
||||
virtual void setBackgroundColor(float red, float green, float blue)
|
||||
{
|
||||
m_backgroundColorRGB[0] = red;
|
||||
m_backgroundColorRGB[1] = green;
|
||||
m_backgroundColorRGB[2] = blue;
|
||||
}
|
||||
virtual void setMouseWheelMultiplier(float mult)
|
||||
{
|
||||
m_wheelMultiplier = mult;
|
||||
}
|
||||
virtual float getMouseWheelMultiplier() const
|
||||
{
|
||||
return m_wheelMultiplier;
|
||||
}
|
||||
|
||||
virtual void setMouseMoveMultiplier(float mult)
|
||||
{
|
||||
m_mouseMoveMultiplier = mult;
|
||||
}
|
||||
|
||||
virtual float getMouseMoveMultiplier() const
|
||||
{
|
||||
return m_mouseMoveMultiplier;
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual void drawGrid(DrawGridData data=DrawGridData()) = 0;
|
||||
virtual void setUpAxis(int axis) = 0;
|
||||
virtual int getUpAxis() const = 0;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,11 @@ SimpleOpenGL2App::SimpleOpenGL2App(const char* title, int width, int height)
|
||||
|
||||
|
||||
glGetError();//don't remove this call, it is needed for Ubuntu
|
||||
glClearColor(0.9,0.9,1,1);
|
||||
glClearColor( m_backgroundColorRGB[0],
|
||||
m_backgroundColorRGB[1],
|
||||
m_backgroundColorRGB[2],
|
||||
1.f);
|
||||
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
@@ -168,6 +172,12 @@ SimpleOpenGL2App::~SimpleOpenGL2App()
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
void SimpleOpenGL2App::setBackgroundColor(float red, float green, float blue)
|
||||
{
|
||||
CommonGraphicsApp::setBackgroundColor(red,green,blue);
|
||||
glClearColor(m_backgroundColorRGB[0],m_backgroundColorRGB[1],m_backgroundColorRGB[2],1.f);
|
||||
}
|
||||
|
||||
void SimpleOpenGL2App::drawGrid(DrawGridData data)
|
||||
{
|
||||
int gridSize = data.gridSize;
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
|
||||
virtual void swapBuffer();
|
||||
virtual void drawText( const char* txt, int posX, int posY);
|
||||
|
||||
virtual void setBackgroundColor(float red, float green, float blue);
|
||||
virtual int registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ)
|
||||
{
|
||||
return 0;
|
||||
|
||||
@@ -133,7 +133,11 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
glClearColor(0.9,0.9,1,1);
|
||||
glClearColor( m_backgroundColorRGB[0],
|
||||
m_backgroundColorRGB[1],
|
||||
m_backgroundColorRGB[2],
|
||||
1.f);
|
||||
|
||||
m_window->startRendering();
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
@@ -609,6 +613,12 @@ void SimpleOpenGL3App::drawGrid(DrawGridData data)
|
||||
m_instancingRenderer->drawPoint(b3MakeVector3(0,0,1),b3MakeVector3(0,0,1),6);
|
||||
}
|
||||
|
||||
void SimpleOpenGL3App::setBackgroundColor(float red, float green, float blue)
|
||||
{
|
||||
CommonGraphicsApp::setBackgroundColor(red,green,blue);
|
||||
glClearColor(m_backgroundColorRGB[0],m_backgroundColorRGB[1],m_backgroundColorRGB[2],1.f);
|
||||
}
|
||||
|
||||
SimpleOpenGL3App::~SimpleOpenGL3App()
|
||||
{
|
||||
delete m_primRenderer ;
|
||||
@@ -692,7 +702,7 @@ void SimpleOpenGL3App::swapBuffer()
|
||||
writeTextureToFile((int)m_window->getRetinaScale()*m_instancingRenderer->getScreenWidth(),
|
||||
(int) m_window->getRetinaScale()*this->m_instancingRenderer->getScreenHeight(),m_data->m_frameDumpPngFileName,
|
||||
m_data->m_ffmpegFile);
|
||||
//m_data->m_renderTexture->disable();
|
||||
m_data->m_renderTexture->disable();
|
||||
//if (m_data->m_ffmpegFile==0)
|
||||
//{
|
||||
m_data->m_frameDumpPngFileName = 0;
|
||||
@@ -755,7 +765,7 @@ void SimpleOpenGL3App::dumpNextFrameToPng(const char* filename)
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, g_OpenGLWidth,g_OpenGLHeight, 0,GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA32F, g_OpenGLWidth,g_OpenGLHeight, 0,GL_RGBA, GL_FLOAT, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA32F,
|
||||
m_instancingRenderer->getScreenWidth(),m_instancingRenderer->getScreenHeight()
|
||||
m_instancingRenderer->getScreenWidth()*m_window->getRetinaScale(),m_instancingRenderer->getScreenHeight()*m_window->getRetinaScale()
|
||||
, 0,GL_RGBA, GL_FLOAT, 0);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
@@ -763,7 +773,7 @@ void SimpleOpenGL3App::dumpNextFrameToPng(const char* filename)
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
m_data->m_renderTexture->init(m_instancingRenderer->getScreenWidth(),this->m_instancingRenderer->getScreenHeight(),renderTextureId, RENDERTEXTURE_COLOR);
|
||||
m_data->m_renderTexture->init(m_instancingRenderer->getScreenWidth()*m_window->getRetinaScale(),this->m_instancingRenderer->getScreenHeight()*m_window->getRetinaScale(),renderTextureId, RENDERTEXTURE_COLOR);
|
||||
}
|
||||
|
||||
m_data->m_renderTexture->enable();
|
||||
|
||||
@@ -14,7 +14,7 @@ struct SimpleOpenGL3App : public CommonGraphicsApp
|
||||
|
||||
class GLPrimitiveRenderer* m_primRenderer;
|
||||
class GLInstancingRenderer* m_instancingRenderer;
|
||||
|
||||
virtual void setBackgroundColor(float red, float green, float blue);
|
||||
|
||||
SimpleOpenGL3App(const char* title, int width,int height);
|
||||
virtual ~SimpleOpenGL3App();
|
||||
|
||||
@@ -199,7 +199,7 @@ void RollingFrictionDemo::initPhysics()
|
||||
for(int j = 0;j<ARRAY_SIZE_Z;j++)
|
||||
{
|
||||
startTransform.setOrigin(SCALING*btVector3(
|
||||
btScalar(2.0*i + start_x)+25,
|
||||
btScalar(2.0*i + start_x),
|
||||
btScalar(2.0*j + start_z),
|
||||
btScalar(20+2.0*k + start_y)));
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ using namespace Gwen::ControlsInternal;
|
||||
GWEN_CONTROL_CONSTRUCTOR( ColorPicker )
|
||||
{
|
||||
SetMouseInputEnabled( true );
|
||||
|
||||
SetKeyboardInputEnabled(true);
|
||||
SetSize( 256, 150 );
|
||||
CreateControls();
|
||||
SetColor( Gwen::Color( 50, 60, 70, 255 ) );
|
||||
|
||||
@@ -73,7 +73,8 @@ bool Gwen::Platform::SetClipboardText( const Gwen::UnicodeString& str )
|
||||
|
||||
// Copy the string into the buffer
|
||||
wchar_t* buffer = (wchar_t*) GlobalLock( clipbuffer );
|
||||
wcscpy_s( buffer, iDataSize, str.c_str() );
|
||||
//wcscpy_s( buffer, iDataSize, str.c_str() );
|
||||
memcpy( buffer, str.c_str() ,iDataSize);
|
||||
GlobalUnlock(clipbuffer);
|
||||
|
||||
// Place it on the clipboard
|
||||
|
||||
@@ -19,6 +19,11 @@ public:
|
||||
|
||||
// Constructor
|
||||
b3CommandLineArgs(int argc, char **argv)
|
||||
{
|
||||
addArgs(argc,argv);
|
||||
}
|
||||
|
||||
void addArgs(int argc, char**argv)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
@@ -39,7 +44,12 @@ public:
|
||||
key = string(arg, 2, pos - 2);
|
||||
val = string(arg, pos + 1, arg.length() - 1);
|
||||
}
|
||||
pairs[key] = val;
|
||||
|
||||
//only add new keys, don't replace existing
|
||||
if(pairs.find(key) == pairs.end())
|
||||
{
|
||||
pairs[key] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +64,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void GetCmdLineArgument(const char *arg_name, T &val);
|
||||
bool GetCmdLineArgument(const char *arg_name, T &val);
|
||||
|
||||
int ParsedArgc()
|
||||
{
|
||||
@@ -63,18 +73,20 @@ public:
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
|
||||
inline bool b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
|
||||
{
|
||||
using namespace std;
|
||||
map<string, string>::iterator itr;
|
||||
if ((itr = pairs.find(arg_name)) != pairs.end()) {
|
||||
istringstream strstream(itr->second);
|
||||
strstream >> val;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
|
||||
inline bool b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
|
||||
{
|
||||
using namespace std;
|
||||
map<string, string>::iterator itr;
|
||||
@@ -83,10 +95,11 @@ inline void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, c
|
||||
string s = itr->second;
|
||||
val = (char*) malloc(sizeof(char) * (s.length() + 1));
|
||||
std::strcpy(val, s.c_str());
|
||||
|
||||
return true;
|
||||
} else {
|
||||
val = NULL;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1427,84 +1427,91 @@ void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const
|
||||
|
||||
void btCollisionWorld::debugDrawWorld()
|
||||
{
|
||||
if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
|
||||
if (getDebugDrawer())
|
||||
{
|
||||
if (getDispatcher())
|
||||
{
|
||||
int numManifolds = getDispatcher()->getNumManifolds();
|
||||
btVector3 color(1,1,0);
|
||||
for (int i=0;i<numManifolds;i++)
|
||||
{
|
||||
btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i);
|
||||
//btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
|
||||
//btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
|
||||
btIDebugDraw::DefaultColors defaultColors = getDebugDrawer()->getDefaultColors();
|
||||
|
||||
int numContacts = contactManifold->getNumContacts();
|
||||
for (int j=0;j<numContacts;j++)
|
||||
if ( getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
|
||||
{
|
||||
|
||||
|
||||
if (getDispatcher())
|
||||
{
|
||||
int numManifolds = getDispatcher()->getNumManifolds();
|
||||
|
||||
for (int i=0;i<numManifolds;i++)
|
||||
{
|
||||
btManifoldPoint& cp = contactManifold->getContactPoint(j);
|
||||
getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),color);
|
||||
btPersistentManifold* contactManifold = 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& cp = contactManifold->getContactPoint(j);
|
||||
getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),defaultColors.m_contactPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)))
|
||||
{
|
||||
int i;
|
||||
|
||||
for ( i=0;i<m_collisionObjects.size();i++)
|
||||
if ((getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)))
|
||||
{
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0)
|
||||
int i;
|
||||
|
||||
for ( i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe))
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0)
|
||||
{
|
||||
btVector3 color(btScalar(1.),btScalar(1.),btScalar(1.));
|
||||
switch(colObj->getActivationState())
|
||||
if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe))
|
||||
{
|
||||
case ACTIVE_TAG:
|
||||
color = btVector3(btScalar(1.),btScalar(1.),btScalar(1.)); break;
|
||||
case ISLAND_SLEEPING:
|
||||
color = btVector3(btScalar(0.),btScalar(1.),btScalar(0.));break;
|
||||
case WANTS_DEACTIVATION:
|
||||
color = btVector3(btScalar(0.),btScalar(1.),btScalar(1.));break;
|
||||
case DISABLE_DEACTIVATION:
|
||||
color = btVector3(btScalar(1.),btScalar(0.),btScalar(0.));break;
|
||||
case DISABLE_SIMULATION:
|
||||
color = btVector3(btScalar(1.),btScalar(1.),btScalar(0.));break;
|
||||
default:
|
||||
btVector3 color(btScalar(0.4),btScalar(0.4),btScalar(0.4));
|
||||
|
||||
switch(colObj->getActivationState())
|
||||
{
|
||||
color = btVector3(btScalar(1),btScalar(0.),btScalar(0.));
|
||||
}
|
||||
};
|
||||
case ACTIVE_TAG:
|
||||
color = defaultColors.m_activeObject; break;
|
||||
case ISLAND_SLEEPING:
|
||||
color = defaultColors.m_deactivatedObject;break;
|
||||
case WANTS_DEACTIVATION:
|
||||
color = defaultColors.m_wantsDeactivationObject;break;
|
||||
case DISABLE_DEACTIVATION:
|
||||
color = defaultColors.m_disabledDeactivationObject;break;
|
||||
case DISABLE_SIMULATION:
|
||||
color = defaultColors.m_disabledSimulationObject;break;
|
||||
default:
|
||||
{
|
||||
color = btVector3(btScalar(.3),btScalar(0.3),btScalar(0.3));
|
||||
}
|
||||
};
|
||||
|
||||
debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);
|
||||
}
|
||||
if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
|
||||
{
|
||||
btVector3 minAabb,maxAabb;
|
||||
btVector3 colorvec(1,0,0);
|
||||
colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
|
||||
btVector3 contactThreshold(gContactBreakingThreshold,gContactBreakingThreshold,gContactBreakingThreshold);
|
||||
minAabb -= contactThreshold;
|
||||
maxAabb += contactThreshold;
|
||||
|
||||
btVector3 minAabb2,maxAabb2;
|
||||
|
||||
if(getDispatchInfo().m_useContinuous && colObj->getInternalType()==btCollisionObject::CO_RIGID_BODY && !colObj->isStaticOrKinematicObject())
|
||||
{
|
||||
colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2);
|
||||
minAabb2 -= contactThreshold;
|
||||
maxAabb2 += contactThreshold;
|
||||
minAabb.setMin(minAabb2);
|
||||
maxAabb.setMax(maxAabb2);
|
||||
debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);
|
||||
}
|
||||
if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
|
||||
{
|
||||
btVector3 minAabb,maxAabb;
|
||||
btVector3 colorvec = defaultColors.m_aabb;
|
||||
colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
|
||||
btVector3 contactThreshold(gContactBreakingThreshold,gContactBreakingThreshold,gContactBreakingThreshold);
|
||||
minAabb -= contactThreshold;
|
||||
maxAabb += contactThreshold;
|
||||
|
||||
m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec);
|
||||
btVector3 minAabb2,maxAabb2;
|
||||
|
||||
if(getDispatchInfo().m_useContinuous && colObj->getInternalType()==btCollisionObject::CO_RIGID_BODY && !colObj->isStaticOrKinematicObject())
|
||||
{
|
||||
colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2);
|
||||
minAabb2 -= contactThreshold;
|
||||
maxAabb2 += contactThreshold;
|
||||
minAabb.setMin(minAabb2);
|
||||
maxAabb.setMax(maxAabb2);
|
||||
}
|
||||
|
||||
m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ subject to the following restrictions:
|
||||
#include "btTransform.h"
|
||||
|
||||
|
||||
|
||||
///The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
|
||||
///Typical use case: create a debug drawer object, and assign it to a btCollisionWorld or btDynamicsWorld using setDebugDrawer and call debugDrawWorld.
|
||||
///A class that implements the btIDebugDraw interface has to implement the drawLine method at a minimum.
|
||||
@@ -29,6 +30,29 @@ class btIDebugDraw
|
||||
{
|
||||
public:
|
||||
|
||||
ATTRIBUTE_ALIGNED16(struct) DefaultColors
|
||||
{
|
||||
btVector3 m_activeObject;
|
||||
btVector3 m_deactivatedObject;
|
||||
btVector3 m_wantsDeactivationObject;
|
||||
btVector3 m_disabledDeactivationObject;
|
||||
btVector3 m_disabledSimulationObject;
|
||||
btVector3 m_aabb;
|
||||
btVector3 m_contactPoint;
|
||||
|
||||
DefaultColors()
|
||||
: m_activeObject(1,1,1),
|
||||
m_deactivatedObject(0,1,0),
|
||||
m_wantsDeactivationObject(0,1,1),
|
||||
m_disabledDeactivationObject(1,0,0),
|
||||
m_disabledSimulationObject(1,1,0),
|
||||
m_aabb(1,0,0),
|
||||
m_contactPoint(1,1,0)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
enum DebugDrawModes
|
||||
{
|
||||
DBG_NoDebug=0,
|
||||
@@ -53,6 +77,11 @@ class btIDebugDraw
|
||||
|
||||
virtual ~btIDebugDraw() {};
|
||||
|
||||
|
||||
virtual DefaultColors getDefaultColors() const { DefaultColors colors; return colors; }
|
||||
///the default implementation for setDefaultColors has no effect. A derived class can implement it and store the colors.
|
||||
virtual void setDefaultColors(const DefaultColors& /*colors*/) {}
|
||||
|
||||
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)=0;
|
||||
|
||||
virtual void drawLine(const btVector3& from,const btVector3& to, const btVector3& fromColor, const btVector3& toColor)
|
||||
|
||||
Reference in New Issue
Block a user