Start re-organizing demos so the physics setup can be shared easier (explicit create graphics objects, init/exit physics etc)
Add B3G_RETURN key code, only implemented in Windows so far (todo: Mac, Linux) Fix Windows key management (use WM_CHAR event instead of WM_KEYUP Add Return (OnKeyReturn) key support TreeNode, so we can select an item using the return key.
This commit is contained in:
@@ -11,9 +11,23 @@
|
||||
#include "../bullet2/RagdollDemo/RagdollDemo.h"
|
||||
#include "../bullet2/LuaDemo/LuaDemo.h"
|
||||
#include "../bullet2/ChainDemo/ChainDemo.h"
|
||||
#include "../../Demos/CcdPhysicsDemo/CcdPhysicsSetup.h"
|
||||
|
||||
static BulletDemoInterface* MyCcdPhysicsDemoCreateFunc(SimpleOpenGL3App* app)
|
||||
{
|
||||
CommonPhysicsSetup* physicsSetup = new CcdPhysicsSetup();
|
||||
return new BasicDemo(app, physicsSetup);
|
||||
}
|
||||
|
||||
static BulletDemoInterface* MyKinematicObjectCreateFunc(SimpleOpenGL3App* app)
|
||||
{
|
||||
CommonPhysicsSetup* physicsSetup = new KinematicObjectSetup();
|
||||
return new BasicDemo(app, physicsSetup);
|
||||
}
|
||||
|
||||
struct BulletDemoEntry
|
||||
{
|
||||
int m_menuLevel;
|
||||
const char* m_name;
|
||||
BulletDemoInterface::CreateFunc* m_createFunc;
|
||||
};
|
||||
@@ -23,23 +37,28 @@ static BulletDemoEntry allDemos[]=
|
||||
{
|
||||
|
||||
//{"emptydemo",EmptyBulletDemo::MyCreateFunc},
|
||||
{"BasicDemo",BasicDemo::MyCreateFunc},
|
||||
|
||||
|
||||
{"ChainDemo",ChainDemo::MyCreateFunc},
|
||||
{"SIHingeDemo",HingeDemo::SICreateFunc},
|
||||
{"PGSHingeDemo",HingeDemo::PGSCreateFunc},
|
||||
{"DantzigHingeDemo",HingeDemo::DantzigCreateFunc},
|
||||
{"LemkeHingeDemo",HingeDemo::LemkeCreateFunc},
|
||||
{"InertiaHingeDemo",HingeDemo::InertiaCreateFunc},
|
||||
{"ABMHingeDemo",HingeDemo::FeatherstoneCreateFunc},
|
||||
|
||||
|
||||
{"Ragdoll",RagDollDemo::MyCreateFunc},
|
||||
{"MultiBody1",FeatherstoneDemo1::MyCreateFunc},
|
||||
// {"MultiBody2",FeatherstoneDemo2::MyCreateFunc},
|
||||
{0,"API Demos", 0},
|
||||
|
||||
{"MultiDofDemo",MultiDofDemo::MyCreateFunc},
|
||||
{1,"BasicDemo",BasicDemo::MyCreateFunc},
|
||||
{ 1, "CcdDemo", MyCcdPhysicsDemoCreateFunc },
|
||||
{ 1, "Kinematic", MyKinematicObjectCreateFunc },
|
||||
|
||||
/* {1,"ChainDemo",ChainDemo::MyCreateFunc},
|
||||
// {0, "Stress tests", 0 },
|
||||
|
||||
{1,"SIHingeDemo",HingeDemo::SICreateFunc},
|
||||
{1,"PGSHingeDemo",HingeDemo::PGSCreateFunc},
|
||||
{1,"DantzigHingeDemo",HingeDemo::DantzigCreateFunc},
|
||||
{1,"LemkeHingeDemo",HingeDemo::LemkeCreateFunc},
|
||||
{1,"InertiaHingeDemo",HingeDemo::InertiaCreateFunc},
|
||||
{1,"ABMHingeDemo",HingeDemo::FeatherstoneCreateFunc},
|
||||
|
||||
{1,"Ragdoll",RagDollDemo::MyCreateFunc},
|
||||
*/
|
||||
{ 0, "Multibody" ,0},
|
||||
{1,"MultiBody1",FeatherstoneDemo1::MyCreateFunc},
|
||||
// {"MultiBody2",FeatherstoneDemo2::MyCreateFunc},
|
||||
{1,"MultiDofDemo",MultiDofDemo::MyCreateFunc},
|
||||
// {"LuaDemo",LuaDemo::MyCreateFunc}
|
||||
|
||||
};
|
||||
|
||||
@@ -14,18 +14,22 @@ SET(App_AllBullet2Demos_SRCS
|
||||
../bullet2/BasicDemo/Bullet2RigidBodyDemo.h
|
||||
../../Demos/BasicDemo/BasicDemoPhysicsSetup.cpp
|
||||
../../Demos/BasicDemo/BasicDemoPhysicsSetup.h
|
||||
../../Demos/CcdPhysicsDemo/CcdPhysicsSetup.cpp
|
||||
../../Demos/CcdPhysicsDemo/CcdPhysicsSetup.h
|
||||
../bullet2/FeatherstoneMultiBodyDemo/BulletMultiBodyDemos.cpp
|
||||
../bullet2/FeatherstoneMultiBodyDemo/BulletMultiBodyDemos.h
|
||||
../bullet2/FeatherstoneMultiBodyDemo/MultiDofDemo.cpp
|
||||
../bullet2/FeatherstoneMultiBodyDemo/MultiDofDemo.h
|
||||
../bullet2/BasicDemo/BasicDemo.cpp
|
||||
../bullet2/BasicDemo/BasicDemo.h
|
||||
../bullet2/BasicDemo/HingeDemo.cpp
|
||||
../bullet2/BasicDemo/HingeDemo.h
|
||||
../bullet2/ChainDemo/ChainDemo.cpp
|
||||
../bullet2/ChainDemo/ChainDemo.h
|
||||
../bullet2/RagdollDemo/RagdollDemo.cpp
|
||||
../bullet2/RagdollDemo/RagdollDemo.h
|
||||
# the next few demos are not converted to 'newer' structure yet
|
||||
# target is to convert all Bullet 2 demos in new structure, but need to settle down on features
|
||||
# ../bullet2/BasicDemo/HingeDemo.cpp
|
||||
# ../bullet2/BasicDemo/HingeDemo.h
|
||||
# ../bullet2/ChainDemo/ChainDemo.cpp
|
||||
# ../bullet2/ChainDemo/ChainDemo.h
|
||||
# ../bullet2/RagdollDemo/RagdollDemo.cpp
|
||||
# ../bullet2/RagdollDemo/RagdollDemo.h
|
||||
# ../bullet2/LuaDemo/LuaDemo.cpp
|
||||
# ../bullet2/LuaDemo/LuaDemo.h
|
||||
../GpuDemos/gwenUserInterface.cpp
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "Bullet3Common/b3Vector3.h"
|
||||
#include "assert.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../GpuDemos/gwenInternalData.h"
|
||||
#include "../GpuDemos/gwenUserInterface.h"
|
||||
#include "BulletDemoEntries.h"
|
||||
#include "../../btgui/Timing/b3Clock.h"
|
||||
@@ -11,6 +11,7 @@ const char* startFileName = "bulletDemo.txt";
|
||||
static SimpleOpenGL3App* app=0;
|
||||
static GwenUserInterface* gui = 0;
|
||||
static int sCurrentDemoIndex = 0;
|
||||
static int sCurrentHightlighted = 0;
|
||||
static BulletDemoInterface* sCurrentDemo = 0;
|
||||
static b3AlignedObjectArray<const char*> allNames;
|
||||
|
||||
@@ -22,11 +23,18 @@ static bool pauseSimulation=false;
|
||||
void MyKeyboardCallback(int key, int state)
|
||||
{
|
||||
|
||||
//printf("key=%d, state=%d\n", key, state);
|
||||
bool handled = false;
|
||||
if (sCurrentDemo)
|
||||
if (gui)
|
||||
{
|
||||
|
||||
handled = gui->keyboardCallback(key, state);
|
||||
}
|
||||
if (!handled && sCurrentDemo)
|
||||
{
|
||||
handled = sCurrentDemo->keyboardCallback(key,state);
|
||||
}
|
||||
|
||||
//checkout: is it desired to ignore keys, if the demo already handles them?
|
||||
//if (handled)
|
||||
// return;
|
||||
@@ -130,6 +138,88 @@ void MyComboBoxCallback(int comboId, const char* item)
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct MyMenuItemHander :public Gwen::Event::Handler
|
||||
{
|
||||
int m_buttonId;
|
||||
|
||||
MyMenuItemHander( int buttonId)
|
||||
:m_buttonId(buttonId)
|
||||
{
|
||||
}
|
||||
|
||||
void onButtonA(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
const Gwen::String& name = pControl->GetName();
|
||||
Gwen::Controls::TreeNode* node = (Gwen::Controls::TreeNode*)pControl;
|
||||
Gwen::Controls::Label* l = node->GetButton();
|
||||
|
||||
Gwen::UnicodeString la = node->GetButton()->GetText();// node->GetButton()->GetName();// GetText();
|
||||
Gwen::String laa = Gwen::Utility::UnicodeToString(la);
|
||||
const char* ha = laa.c_str();
|
||||
|
||||
//printf("selected %s\n", ha);
|
||||
//int dep = but->IsDepressed();
|
||||
//int tog = but->GetToggleState();
|
||||
// if (m_data->m_toggleButtonCallback)
|
||||
// (*m_data->m_toggleButtonCallback)(m_buttonId, tog);
|
||||
}
|
||||
void onButtonB(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
Gwen::Controls::Label* label = (Gwen::Controls::Label*) pControl;
|
||||
Gwen::UnicodeString la = label->GetText();// node->GetButton()->GetName();// GetText();
|
||||
Gwen::String laa = Gwen::Utility::UnicodeToString(la);
|
||||
const char* ha = laa.c_str();
|
||||
|
||||
|
||||
selectDemo(sCurrentHightlighted);
|
||||
saveCurrentDemoEntry(sCurrentDemoIndex, startFileName);
|
||||
}
|
||||
void onButtonC(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
Gwen::Controls::Label* label = (Gwen::Controls::Label*) pControl;
|
||||
Gwen::UnicodeString la = label->GetText();// node->GetButton()->GetName();// GetText();
|
||||
Gwen::String laa = Gwen::Utility::UnicodeToString(la);
|
||||
const char* ha = laa.c_str();
|
||||
|
||||
|
||||
// printf("onButtonC ! %s\n", ha);
|
||||
}
|
||||
void onButtonD(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
/* Gwen::Controls::Label* label = (Gwen::Controls::Label*) pControl;
|
||||
Gwen::UnicodeString la = label->GetText();// node->GetButton()->GetName();// GetText();
|
||||
Gwen::String laa = Gwen::Utility::UnicodeToString(la);
|
||||
const char* ha = laa.c_str();
|
||||
*/
|
||||
|
||||
// printf("onKeyReturn ! \n");
|
||||
selectDemo(sCurrentHightlighted);
|
||||
saveCurrentDemoEntry(sCurrentDemoIndex, startFileName);
|
||||
|
||||
}
|
||||
|
||||
void onButtonE(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
// printf("select %d\n",m_buttonId);
|
||||
sCurrentHightlighted = m_buttonId;
|
||||
}
|
||||
|
||||
void onButtonF(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
//printf("selection changed!\n");
|
||||
}
|
||||
|
||||
void onButtonG(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
//printf("onButtonG !\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
b3Clock clock;
|
||||
@@ -152,22 +242,66 @@ int main(int argc, char* argv[])
|
||||
sth_stash* fontstash=app->getFontStash();
|
||||
gui = new GwenUserInterface;
|
||||
gui->init(width,height,fontstash,app->m_window->getRetinaScale());
|
||||
|
||||
// gui->getInternalData()->m_explorerPage
|
||||
Gwen::Controls::TreeControl* tree = gui->getInternalData()->m_explorerTreeCtrl;
|
||||
int numDemos = sizeof(allDemos)/sizeof(BulletDemoEntry);
|
||||
|
||||
for (int i=0;i<numDemos;i++)
|
||||
char nodeText[1024];
|
||||
int curDemo = 0;
|
||||
int selectedDemo = loadCurrentDemoEntry(startFileName);
|
||||
Gwen::Controls::TreeNode* curNode = tree;
|
||||
MyMenuItemHander* handler2 = new MyMenuItemHander(-1);
|
||||
|
||||
tree->onReturnKeyDown.Add(handler2, &MyMenuItemHander::onButtonD);
|
||||
|
||||
for (int d = 0; d<numDemos; d++)
|
||||
{
|
||||
// sprintf(nodeText, "Node %d", i);
|
||||
Gwen::UnicodeString nodeUText = Gwen::Utility::StringToUnicode(allDemos[d].m_name);
|
||||
if (allDemos[d].m_menuLevel==1)
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = curNode->AddNode(nodeUText);
|
||||
if (d == selectedDemo)
|
||||
{
|
||||
pNode->SetSelected(true);
|
||||
tree->ExpandAll();
|
||||
selectDemo(d);
|
||||
|
||||
|
||||
}
|
||||
MyMenuItemHander* handler = new MyMenuItemHander(d);
|
||||
pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonA);
|
||||
pNode->GetButton()->onDoubleClick.Add(handler, &MyMenuItemHander::onButtonB);
|
||||
pNode->GetButton()->onDown.Add(handler, &MyMenuItemHander::onButtonC);
|
||||
pNode->onSelect.Add(handler, &MyMenuItemHander::onButtonE);
|
||||
pNode->onReturnKeyDown.Add(handler, &MyMenuItemHander::onButtonG);
|
||||
pNode->onSelectChange.Add(handler, &MyMenuItemHander::onButtonF);
|
||||
// pNode->onKeyReturn.Add(handler, &MyMenuItemHander::onButtonD);
|
||||
// pNode->GetButton()->onKeyboardReturn.Add(handler, &MyMenuItemHander::onButtonD);
|
||||
// pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonD);
|
||||
// pNode->onKeyboardPressed.Add(handler, &MyMenuItemHander::onButtonD);
|
||||
// pNode->OnKeyPress
|
||||
}
|
||||
else
|
||||
{
|
||||
curNode = tree->AddNode(nodeUText);
|
||||
}
|
||||
}
|
||||
|
||||
/* for (int i=0;i<numDemos;i++)
|
||||
{
|
||||
allNames.push_back(allDemos[i].m_name);
|
||||
}
|
||||
|
||||
selectDemo(loadCurrentDemoEntry(startFileName));
|
||||
*/
|
||||
//selectDemo(loadCurrentDemoEntry(startFileName));
|
||||
/*
|
||||
gui->registerComboBox(DEMO_SELECTION_COMBOBOX,allNames.size(),&allNames[0],sCurrentDemoIndex);
|
||||
|
||||
//const char* names2[] = {"comboF", "comboG","comboH"};
|
||||
//gui->registerComboBox(2,3,&names2[0],0);
|
||||
|
||||
gui->setComboBoxCallback(MyComboBoxCallback);
|
||||
|
||||
*/
|
||||
unsigned long int prevTimeInMicroseconds = clock.getTimeMicroseconds();
|
||||
|
||||
do
|
||||
|
||||
@@ -25,21 +25,23 @@
|
||||
"../bullet2/BasicDemo/Bullet2RigidBodyDemo.h",
|
||||
"../../Demos/BasicDemo/BasicDemoPhysicsSetup.cpp",
|
||||
"../../Demos/BasicDemo/BasicDemoPhysicsSetup.h",
|
||||
"../../Demos/CcdPhysicsDemo/CcdPhysicsSetup.cpp",
|
||||
"../../Demos/CcdPhysicsDemo/CcdPhysicsSetup.h",
|
||||
"../bullet2/FeatherstoneMultiBodyDemo/BulletMultiBodyDemos.cpp",
|
||||
"../bullet2/FeatherstoneMultiBodyDemo/BulletMultiBodyDemos.h",
|
||||
"../bullet2/FeatherstoneMultiBodyDemo/MultiDofDemo.cpp",
|
||||
"../bullet2/FeatherstoneMultiBodyDemo/MultiDofDemo.h",
|
||||
"../bullet2/BasicDemo/BasicDemo.cpp",
|
||||
"../bullet2/BasicDemo/BasicDemo.h",
|
||||
"../bullet2/BasicDemo/HingeDemo.cpp",
|
||||
"../bullet2/BasicDemo/HingeDemo.h",
|
||||
"../bullet2/ChainDemo/ChainDemo.cpp",
|
||||
"../bullet2/ChainDemo/ChainDemo.h",
|
||||
-- "../bullet2/BasicDemo/HingeDemo.cpp",
|
||||
-- "../bullet2/BasicDemo/HingeDemo.h",
|
||||
-- "../bullet2/ChainDemo/ChainDemo.cpp",
|
||||
-- "../bullet2/ChainDemo/ChainDemo.h",
|
||||
|
||||
"../bullet2/RagdollDemo/RagdollDemo.cpp",
|
||||
"../bullet2/RagdollDemo/RagdollDemo.h",
|
||||
"../bullet2/LuaDemo/LuaDemo.cpp",
|
||||
"../bullet2/LuaDemo/LuaDemo.h",
|
||||
-- "../bullet2/RagdollDemo/RagdollDemo.cpp",
|
||||
-- "../bullet2/RagdollDemo/RagdollDemo.h",
|
||||
-- "../bullet2/LuaDemo/LuaDemo.cpp",
|
||||
-- "../bullet2/LuaDemo/LuaDemo.h",
|
||||
|
||||
|
||||
"../../src/Bullet3Common/**.cpp",
|
||||
|
||||
Reference in New Issue
Block a user