refactor to allow various gfx backends (work-in-progress)

This commit is contained in:
Erwin Coumans
2014-09-23 18:27:16 -07:00
parent 76f4bd9a9d
commit e314f56f9d
49 changed files with 1171 additions and 296 deletions

View File

@@ -21,51 +21,51 @@
#include "../../Demos/SerializeDemo/SerializeSetup.h"
#include "../bullet2/MultiBodyDemo/TestJointTorqueSetup.h"
static BulletDemoInterface* TestJointTorqueCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* TestJointTorqueCreateFunc(CommonGraphicsApp* app)
{
CommonPhysicsSetup* physicsSetup = new TestJointTorqueSetup();
return new BasicDemo(app, physicsSetup);
}
static BulletDemoInterface* LuaDemoCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* LuaDemoCreateFunc(CommonGraphicsApp* app)
{
CommonPhysicsSetup* physicsSetup = new LuaPhysicsSetup(app);
return new BasicDemo(app, physicsSetup);
}
static BulletDemoInterface* MyCcdPhysicsDemoCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyCcdPhysicsDemoCreateFunc(CommonGraphicsApp* app)
{
CommonPhysicsSetup* physicsSetup = new CcdPhysicsSetup();
return new BasicDemo(app, physicsSetup);
}
static BulletDemoInterface* MyKinematicObjectCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyKinematicObjectCreateFunc(CommonGraphicsApp* app)
{
CommonPhysicsSetup* physicsSetup = new KinematicObjectSetup();
return new BasicDemo(app, physicsSetup);
}
static BulletDemoInterface* MySerializeCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MySerializeCreateFunc(CommonGraphicsApp* app)
{
CommonPhysicsSetup* physicsSetup = new SerializeSetup();
return new BasicDemo(app, physicsSetup);
}
static BulletDemoInterface* MyConstraintCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyConstraintCreateFunc(CommonGraphicsApp* app)
{
CommonPhysicsSetup* physicsSetup = new ConstraintPhysicsSetup();
return new BasicDemo(app, physicsSetup);
}
static BulletDemoInterface* MyImportUrdfCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyImportUrdfCreateFunc(CommonGraphicsApp* app)
{
CommonPhysicsSetup* physicsSetup = new ImportUrdfDemo();
return new BasicDemo(app, physicsSetup);
}
static BulletDemoInterface* MyImportObjCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyImportObjCreateFunc(CommonGraphicsApp* app)
{
CommonPhysicsSetup* physicsSetup = new ImportObjDemo(app);
return new BasicDemo(app, physicsSetup);
}
static BulletDemoInterface* MyImportSTLCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyImportSTLCreateFunc(CommonGraphicsApp* app)
{
CommonPhysicsSetup* physicsSetup = new ImportSTLDemo(app);
return new BasicDemo(app, physicsSetup);

View File

@@ -1,5 +1,28 @@
//#include "OpenGLWindow/OpenGLInclude.h"
//#include "OpenGL/gl.h"
#define USE_OPENGL2
#ifdef USE_OPENGL2
#include "OpenGLWindow/SimpleOpenGL2App.h"
#else
#include "OpenGLWindow/SimpleOpenGL3App.h"
#endif
#ifdef __APPLE__
#include "OpenGLWindow/MacOpenGLWindow.h"
#else
#include "GL/glew.h"
#ifdef _WIN32
#include "OpenGLWindow/Win32OpenGLWindow.h"
#else
//let's cross the fingers it is Linux/X11
#include "OpenGLWindow/X11OpenGLWindow.h"
#endif //_WIN32
#endif//__APPLE__
#include "Gwen/Renderers/OpenGL_DebugFont.h"
#include "Bullet3Common/b3Vector3.h"
#include "assert.h"
#include <stdio.h>
@@ -11,11 +34,172 @@
#include "Bullet3AppSupport/GwenProfileWindow.h"
#include "Bullet3AppSupport/GwenTextureWindow.h"
#include "Bullet3AppSupport/GraphingTexture.h"
#include "OpenGLWindow/CommonRenderInterface.h"
#include "OpenGLWindow/SimpleCamera.h"
CommonGraphicsApp* app=0;
struct TestRenderer : public CommonRenderInterface
{
int m_width;
int m_height;
SimpleCamera m_camera;
TestRenderer(int width, int height)
:m_width(width),
m_height(height)
{
}
virtual void init()
{
}
virtual void updateCamera(int upAxis)
{
float projection[16];
float view[16];
m_camera.setAspectRatio((float)m_width/(float)m_height);
m_camera.update();
m_camera.getCameraProjectionMatrix(projection);
m_camera.getCameraViewMatrix(view);
GLfloat projMat[16];
GLfloat viewMat[16];
for (int i=0;i<16;i++)
{
viewMat[i] = view[i];
projMat[i] = projection[i];
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMultMatrixf(projMat);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf(viewMat);
}
virtual void removeAllInstances()
{
}
virtual void setCameraDistance(float dist)
{
m_camera.setCameraDistance(dist);
}
virtual void setCameraPitch(float pitch)
{
m_camera.setCameraPitch(pitch);
}
virtual void setCameraTargetPosition(float x, float y, float z)
{
m_camera.setCameraTargetPosition(x,y,z);
}
virtual void getCameraPosition(float cameraPos[4])
{
float pos[3];
m_camera.getCameraPosition(pos);
cameraPos[0] = pos[0];
cameraPos[1] = pos[1];
cameraPos[2] = pos[2];
}
virtual void getCameraPosition(double cameraPos[4])
{
float pos[3];
m_camera.getCameraPosition(pos);
cameraPos[0] = pos[0];
cameraPos[1] = pos[1];
cameraPos[2] = pos[2];
}
virtual void setCameraTargetPosition(float cameraPos[4])
{
m_camera.setCameraTargetPosition(cameraPos[0],cameraPos[1],cameraPos[2]);
}
virtual void getCameraTargetPosition(float cameraPos[4]) const
{
m_camera.getCameraTargetPosition(cameraPos);
}
virtual void getCameraTargetPosition(double cameraPos[4]) const
{
cameraPos[0] = 1;
cameraPos[1] = 1;
cameraPos[2] = 1;
}
virtual void renderScene()
{
}
virtual int getScreenWidth()
{
return m_width;
}
virtual int getScreenHeight()
{
return m_height;
}
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)
{
return 0;
}
virtual void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize)
{
int pointStrideInFloats = pointStrideInBytes/4;
glLineWidth(pointDrawSize);
for (int i=0;i<numIndices;i+=2)
{
int index0 = indices[i];
int index1 = indices[i+1];
btVector3 fromColor(color[0],color[1],color[2]);
btVector3 toColor(color[0],color[1],color[2]);
btVector3 from(positions[index0*pointStrideInFloats],positions[index0*pointStrideInFloats+1],positions[index0*pointStrideInFloats+2]);
btVector3 to(positions[index1*pointStrideInFloats],positions[index1*pointStrideInFloats+1],positions[index1*pointStrideInFloats+2]);
glBegin(GL_LINES);
glColor3f(fromColor.getX(), fromColor.getY(), fromColor.getZ());
glVertex3d(from.getX(), from.getY(), from.getZ());
glColor3f(toColor.getX(), toColor.getY(), toColor.getZ());
glVertex3d(to.getX(), to.getY(), to.getZ());
glEnd();
}
}
virtual void drawLine(const float from[4], const float to[4], const float color[4], float lineWidth)
{
glLineWidth(lineWidth);
glBegin(GL_LINES);
glColor3f(color[0],color[1],color[2]);
glVertex3d(from[0],from[1],from[2]);
glVertex3d(to[0],to[1],to[2]);
glEnd();
}
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1)
{
return 0;
}
virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)
{
}
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)
{
}
virtual void writeTransforms()
{
}
};
b3gWindowInterface* s_window = 0;
CommonParameterInterface* s_parameterInterface=0;
CommonRenderInterface* s_instancingRenderer=0;
#define DEMO_SELECTION_COMBOBOX 13
const char* startFileName = "bulletDemo.txt";
static SimpleOpenGL3App* app=0;
static GwenUserInterface* gui = 0;
static int sCurrentDemoIndex = 0;
static int sCurrentHightlighted = 0;
@@ -30,82 +214,14 @@ int midiBaseIndex = 176;
//#include <float.h>
//unsigned int fp_control_state = _controlfp(_EM_INEXACT, _MCW_EM);
#ifdef B3_USE_MIDI
#include "../../btgui/MidiTest/RtMidi.h"
bool chooseMidiPort( RtMidiIn *rtmidi )
{
if (!rtmidi)
return false;
std::string portName;
unsigned int i = 0, nPorts = rtmidi->getPortCount();
if ( nPorts == 0 ) {
std::cout << "No input ports available!" << std::endl;
return false;
}
if ( nPorts == 1 ) {
std::cout << "\nOpening " << rtmidi->getPortName() << std::endl;
}
else {
for ( i=0; i<nPorts; i++ ) {
portName = rtmidi->getPortName(i);
std::cout << " Input port #" << i << ": " << portName << '\n';
}
do {
std::cout << "\nChoose a port number: ";
std::cin >> i;
} while ( i >= nPorts );
}
// std::getline( std::cin, keyHit ); // used to clear out stdin
rtmidi->openPort( i );
return true;
}
void PairMidiCallback( double deltatime, std::vector< unsigned char > *message, void *userData )
{
unsigned int nBytes = message->size();
if (nBytes==3)
{
//if ( message->at(1)==16)
{
printf("midi %d at %f = %d\n", message->at(1), deltatime, message->at(2));
//test->SetValue(message->at(2));
#if KORG_MIDI
if (message->at(0)>=midiBaseIndex && message->at(0)<(midiBaseIndex+8))
{
int sliderIndex = message->at(0)-midiBaseIndex;//-16;
printf("sliderIndex = %d\n", sliderIndex);
float sliderValue = message->at(2);
printf("sliderValue = %f\n", sliderValue);
app->m_parameterInterface->setSliderValue(sliderIndex,sliderValue);
}
#else
//ICONTROLS
if (message->at(0)==176)
{
int sliderIndex = message->at(1)-32;//-16;
printf("sliderIndex = %d\n", sliderIndex);
float sliderValue = message->at(2);
printf("sliderValue = %f\n", sliderValue);
app->m_parameterInterface->setSliderValue(sliderIndex,sliderValue);
}
#endif
}
}
}
#endif //B3_USE_MIDI
b3KeyboardCallback prevKeyboardCallback = 0;
void MyKeyboardCallback(int key, int state)
{
@@ -146,15 +262,16 @@ void MyKeyboardCallback(int key, int state)
useShadowMap=!useShadowMap;
}
if (key==B3G_ESCAPE && app && app->m_window)
if (key==B3G_ESCAPE && s_window)
{
app->m_window->setRequestExit();
s_window->setRequestExit();
}
b3DefaultKeyboardCallback(key,state);
if (prevKeyboardCallback)
prevKeyboardCallback(key,state);
}
b3MouseMoveCallback prevMouseMoveCallback = 0;
static void MyMouseMoveCallback( float x, float y)
{
bool handled = false;
@@ -163,8 +280,14 @@ static void MyMouseMoveCallback( float x, float y)
if (!handled && gui)
handled = gui->mouseMoveCallback(x,y);
if (!handled)
b3DefaultMouseMoveCallback(x,y);
{
if (prevMouseMoveCallback)
prevMouseMoveCallback(x,y);
}
}
b3MouseButtonCallback prevMouseButtonCallback = 0;
static void MyMouseButtonCallback(int button, int state, float x, float y)
{
bool handled = false;
@@ -176,7 +299,11 @@ static void MyMouseButtonCallback(int button, int state, float x, float y)
handled = gui->mouseButtonCallback(button,state,x,y);
if (!handled)
b3DefaultMouseButtonCallback(button,state,x,y);
{
if (prevMouseButtonCallback )
prevMouseButtonCallback (button,state,x,y);
}
// b3DefaultMouseButtonCallback(button,state,x,y);
}
#include <string.h>
@@ -187,17 +314,17 @@ void openURDFDemo(const char* filename)
if (sCurrentDemo)
{
sCurrentDemo->exitPhysics();
app->m_instancingRenderer->removeAllInstances();
s_instancingRenderer->removeAllInstances();
delete sCurrentDemo;
sCurrentDemo=0;
}
app->m_parameterInterface->removeAllParameters();
s_parameterInterface->removeAllParameters();
ImportUrdfDemo* physicsSetup = new ImportUrdfDemo();
physicsSetup->setFileName(filename);
sCurrentDemo = new BasicDemo(app, physicsSetup);
sCurrentDemo = new BasicDemo(0, physicsSetup);
if (sCurrentDemo)
{
@@ -219,13 +346,13 @@ void selectDemo(int demoIndex)
if (sCurrentDemo)
{
sCurrentDemo->exitPhysics();
app->m_instancingRenderer->removeAllInstances();
s_instancingRenderer->removeAllInstances();
delete sCurrentDemo;
sCurrentDemo=0;
}
if (allDemos[demoIndex].m_createFunc && app)
if (allDemos[demoIndex].m_createFunc)
{
app->m_parameterInterface->removeAllParameters();
s_parameterInterface->removeAllParameters();
sCurrentDemo = (*allDemos[demoIndex].m_createFunc)(app);
if (sCurrentDemo)
{
@@ -359,7 +486,7 @@ void fileOpenCallback()
{
char filename[1024];
int len = app->m_window->fileOpenDialog(filename,1024);
int len = s_window->fileOpenDialog(filename,1024);
if (len)
{
//todo(erwincoumans) check if it is actually URDF
@@ -379,31 +506,66 @@ int main(int argc, char* argv[])
int width = 1024;
int height=768;
// wci.m_resizeCallback = MyResizeCallback;
app = new SimpleOpenGL3App("AllBullet2Demos",width,height);
app->m_instancingRenderer->setCameraDistance(13);
app->m_instancingRenderer->setCameraPitch(0);
app->m_instancingRenderer->setCameraTargetPosition(b3MakeVector3(0,0,0));
app->m_window->setMouseMoveCallback(MyMouseMoveCallback);
app->m_window->setMouseButtonCallback(MyMouseButtonCallback);
app->m_window->setKeyboardCallback(MyKeyboardCallback);
#ifdef USE_OPENGL2
app = new SimpleOpenGL2App("AllBullet2Demos",width,height);
app->m_renderer = new TestRenderer(width,height);
#else
SimpleOpenGL3App* simpleApp = new SimpleOpenGL3App("AllBullet2Demos",width,height);
app = simpleApp;
#endif
s_instancingRenderer = app->m_renderer;
s_window = app->m_window;
prevMouseMoveCallback = s_window->getMouseMoveCallback();
s_window->setMouseMoveCallback(MyMouseMoveCallback);
prevMouseButtonCallback = s_window->getMouseButtonCallback();
s_window->setMouseButtonCallback(MyMouseButtonCallback);
prevKeyboardCallback = s_window->getKeyboardCallback();
s_window->setKeyboardCallback(MyKeyboardCallback);
app->m_renderer->setCameraDistance(13);
app->m_renderer->setCameraPitch(0);
app->m_renderer->setCameraTargetPosition(0,0,0);
/*
SimpleOpenGL3App* app = new SimpleOpenGL3App("AllBullet2Demos",width,height);
s_instancingRenderer->setCameraDistance(13);
s_instancingRenderer->setCameraPitch(0);
s_instancingRenderer->setCameraTargetPosition(0,0,0);
s_window->setMouseMoveCallback(MyMouseMoveCallback);
s_window->setMouseButtonCallback(MyMouseButtonCallback);
s_window->setKeyboardCallback(MyKeyboardCallback);
*/
assert(glGetError()==GL_NO_ERROR);
sth_stash* fontstash=app->getFontStash();
gui = new GwenUserInterface;
gui->init(width,height,fontstash,app->m_window->getRetinaScale());
GL3TexLoader* myTexLoader = new GL3TexLoader;
#ifdef USE_OPENGL2
Gwen::Renderer::Base* gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
#else
sth_stash* fontstash=simpleApp->getFontStash();
Gwen::Renderer::Base* gwenRenderer = new GwenOpenGL3CoreRenderer(simpleApp->m_primRenderer,fontstash,width,height,s_window->getRetinaScale(),myTexLoader);
#endif
//
gui->init(width,height,gwenRenderer,s_window->getRetinaScale());
// gui->getInternalData()->m_explorerPage
Gwen::Controls::TreeControl* tree = gui->getInternalData()->m_explorerTreeCtrl;
GL3TexLoader* myTexLoader = new GL3TexLoader;
gui->getInternalData()->pRenderer->setTextureLoader(myTexLoader);
//gui->getInternalData()->pRenderer->setTextureLoader(myTexLoader);
MyProfileWindow* profWindow = setupProfileWindow(gui->getInternalData());
profileWindowSetVisible(profWindow,false);
#if 0
{
MyGraphInput input(gui->getInternalData());
input.m_width=300;
@@ -448,10 +610,9 @@ int main(int argc, char* argv[])
setupTextureWindow(input);
}
//destroyTextureWindow(gw);
#endif
s_parameterInterface = app->m_parameterInterface = new GwenParameterInterface(gui->getInternalData());
app->m_parameterInterface = new GwenParameterInterface(gui->getInternalData());
//gui->getInternalData()->m_demoPage;
int numDemos = sizeof(allDemos)/sizeof(BulletDemoEntry);
@@ -520,13 +681,13 @@ int main(int argc, char* argv[])
{
assert(glGetError()==GL_NO_ERROR);
app->m_instancingRenderer->init();
s_instancingRenderer->init();
DrawGridData dg;
dg.upAxis = app->getUpAxis();
{
BT_PROFILE("Update Camera");
app->m_instancingRenderer->updateCamera(dg.upAxis);
s_instancingRenderer->updateCamera(dg.upAxis);
}
{
BT_PROFILE("Draw Grid");
@@ -571,20 +732,30 @@ int main(int argc, char* argv[])
if (!pauseSimulation)
processProfileData(profWindow,false);
{
#ifdef USE_OPENGL2
{
saveOpenGLState(width,height);
}
#endif
BT_PROFILE("Draw Gwen GUI");
gui->draw(app->m_instancingRenderer->getScreenWidth(),app->m_instancingRenderer->getScreenHeight());
gui->draw(s_instancingRenderer->getScreenWidth(),s_instancingRenderer->getScreenHeight());
#ifdef USE_OPENGL2
restoreOpenGLState();
#endif
}
}
toggle=1-toggle;
{
BT_PROFILE("Sync Parameters");
app->m_parameterInterface->syncParameters();
s_parameterInterface->syncParameters();
}
{
BT_PROFILE("Swap Buffers");
app->swapBuffer();
}
} while (!app->m_window->requestedExit());
} while (!s_window->requestedExit());
// selectDemo(0);
delete gui;

View File

@@ -20,7 +20,7 @@
#include "OpenGLWindow/GLPrimitiveRenderer.h"
#include "OpenGLWindow/GLInstancingRenderer.h"
//#include "OpenGL3CoreRenderer.h"
#include "OpenGLWindow/GwenOpenGL3CoreRenderer.h"
//#include "b3GpuDynamicsWorld.h"
#include <assert.h>
#include <string.h>
@@ -739,7 +739,10 @@ int main(int argc, char* argv[])
if (gui)
{
gui->init(g_OpenGLWidth,g_OpenGLHeight,stash,window->getRetinaScale());
Gwen::Renderer::Base* gwenRenderer = new GwenOpenGL3CoreRenderer(&prim,stash, g_OpenGLWidth,g_OpenGLHeight,window->getRetinaScale());
gui->init(g_OpenGLWidth,g_OpenGLHeight,gwenRenderer,window->getRetinaScale());
printf("init fonts");

View File

@@ -7,7 +7,7 @@
#include "OpenGLWindow/SimpleOpenGL3App.h"
#include "Wavefront2GLInstanceGraphicsShape.h"
ImportObjDemo::ImportObjDemo(SimpleOpenGL3App* app)
ImportObjDemo::ImportObjDemo(CommonGraphicsApp* app)
:m_app(app)
{
@@ -75,11 +75,11 @@ void ImportObjDemo::initPhysics(GraphicsPhysicsBridge& gfxBridge)
btVector3 color(0,0,1);
int shapeId = m_app->m_instancingRenderer->registerShape(&gfxShape->m_vertices->at(0).xyzw[0], gfxShape->m_numvertices, &gfxShape->m_indices->at(0), gfxShape->m_numIndices);
int shapeId = m_app->m_renderer->registerShape(&gfxShape->m_vertices->at(0).xyzw[0], gfxShape->m_numvertices, &gfxShape->m_indices->at(0), gfxShape->m_numIndices);
//int id =
m_app->m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
m_app->m_renderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
/*

View File

@@ -6,9 +6,9 @@
class ImportObjDemo : public CommonRigidBodySetup
{
struct SimpleOpenGL3App* m_app;
struct CommonGraphicsApp* m_app;
public:
ImportObjDemo(SimpleOpenGL3App* app);
ImportObjDemo(CommonGraphicsApp* app);
virtual ~ImportObjDemo();
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);

View File

@@ -6,7 +6,7 @@
#include "OpenGLWindow/SimpleOpenGL3App.h"
#include "LoadMeshFromSTL.h"
ImportSTLDemo::ImportSTLDemo(SimpleOpenGL3App* app)
ImportSTLDemo::ImportSTLDemo(CommonGraphicsApp* app)
:m_app(app)
{
@@ -68,11 +68,11 @@ void ImportSTLDemo::initPhysics(GraphicsPhysicsBridge& gfxBridge)
btVector3 color(0,0,1);
int shapeId = m_app->m_instancingRenderer->registerShape(&gfxShape->m_vertices->at(0).xyzw[0], gfxShape->m_numvertices, &gfxShape->m_indices->at(0), gfxShape->m_numIndices);
int shapeId = m_app->m_renderer->registerShape(&gfxShape->m_vertices->at(0).xyzw[0], gfxShape->m_numvertices, &gfxShape->m_indices->at(0), gfxShape->m_numIndices);
// int id =
m_app->m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
m_app->m_renderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
/*

View File

@@ -6,9 +6,9 @@
class ImportSTLDemo : public CommonRigidBodySetup
{
struct SimpleOpenGL3App* m_app;
struct CommonGraphicsApp* m_app;
public:
ImportSTLDemo(SimpleOpenGL3App* app);
ImportSTLDemo(CommonGraphicsApp* app);
virtual ~ImportSTLDemo();
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);

View File

@@ -3,6 +3,7 @@
#include "Bullet3Common/b3CommandLineArgs.h"
#include "assert.h"
#include <stdio.h>
#include "OpenGLWindow/OpenGLInclude.h"
char* gVideoFileName = 0;
char* gPngFileName = 0;

View File

@@ -14,7 +14,7 @@
static const float scaling=0.35f;
BasicDemo::BasicDemo(SimpleOpenGL3App* app, CommonPhysicsSetup* physicsSetup)
BasicDemo::BasicDemo(CommonGraphicsApp* app, CommonPhysicsSetup* physicsSetup)
:Bullet2RigidBodyDemo(app,physicsSetup)
{
}

View File

@@ -16,13 +16,13 @@ class BasicDemo : public Bullet2RigidBodyDemo
public:
static BulletDemoInterface* MyCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyCreateFunc(CommonGraphicsApp* app)
{
CommonPhysicsSetup* physicsSetup = new BasicDemoPhysicsSetup();
return new BasicDemo(app, physicsSetup);
}
BasicDemo(SimpleOpenGL3App* app, CommonPhysicsSetup* physicsSetup);
BasicDemo(CommonGraphicsApp* app, CommonPhysicsSetup* physicsSetup);
virtual ~BasicDemo();
void createGround(int cubeShapeId);

View File

@@ -19,35 +19,35 @@ class HingeDemo : public BasicDemo
int m_hingeMethod;
public:
static BulletDemoInterface* FeatherstoneCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* FeatherstoneCreateFunc(CommonGraphicsApp* app)
{
return new HingeDemo(app, FEATHERSTONE_HINGE);
}
static BulletDemoInterface* DantzigCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* DantzigCreateFunc(CommonGraphicsApp* app)
{
return new HingeDemo(app, DANTZIG_HINGE);
}
static BulletDemoInterface* LemkeCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* LemkeCreateFunc(CommonGraphicsApp* app)
{
return new HingeDemo(app, LEMKE_HINGE);
}
static BulletDemoInterface* PGSCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* PGSCreateFunc(CommonGraphicsApp* app)
{
return new HingeDemo(app, PGS_HINGE);
}
static BulletDemoInterface* SICreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* SICreateFunc(CommonGraphicsApp* app)
{
return new HingeDemo(app, SI_HINGE);
}
static BulletDemoInterface* InertiaCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* InertiaCreateFunc(CommonGraphicsApp* app)
{
return new HingeDemo(app, INERTIA_HINGE);
}
HingeDemo(SimpleOpenGL3App* app, HINGE_CREATION_METHOD hingeMethod);
HingeDemo(CommonGraphicsApp* app, HINGE_CREATION_METHOD hingeMethod);
class btMultiBody* createFeatherstoneHinge(class btMultiBodyDynamicsWorld* world, const struct btMultiBodySettings2& settings);

View File

@@ -11,12 +11,12 @@ class ChainDemo : public Bullet2RigidBodyDemo
public:
static BulletDemoInterface* MyCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyCreateFunc(CommonGraphicsApp* app)
{
return new ChainDemo(app);
}
ChainDemo(SimpleOpenGL3App* app);
ChainDemo(CommonGraphicsApp* app);
virtual ~ChainDemo();
void createGround(int cubeShapeId);

View File

@@ -48,7 +48,7 @@ static btVector4 colors[4] =
Bullet2MultiBodyDemo::Bullet2MultiBodyDemo(SimpleOpenGL3App* app)
Bullet2MultiBodyDemo::Bullet2MultiBodyDemo(CommonGraphicsApp* app)
:m_glApp(app),
m_pickedBody(0),
m_pickedConstraint(0),
@@ -97,7 +97,7 @@ Bullet2MultiBodyDemo::~Bullet2MultiBodyDemo()
btVector3 Bullet2MultiBodyDemo::getRayTo(int x,int y)
{
if (!m_glApp->m_instancingRenderer)
if (!m_glApp->m_renderer)
{
btAssert(0);
return btVector3(0,0,0);
@@ -110,8 +110,8 @@ btVector3 Bullet2MultiBodyDemo::getRayTo(int x,int y)
float fov = b3Scalar(2.0) * b3Atan(tanFov);
btVector3 camPos,camTarget;
m_glApp->m_instancingRenderer->getCameraPosition(camPos);
m_glApp->m_instancingRenderer->getCameraTargetPosition(camTarget);
m_glApp->m_renderer->getCameraPosition(camPos);
m_glApp->m_renderer->getCameraTargetPosition(camTarget);
btVector3 rayFrom = camPos;
btVector3 rayForward = (camTarget-camPos);
@@ -136,8 +136,8 @@ btVector3 Bullet2MultiBodyDemo::getRayTo(int x,int y)
vertical *= 2.f * farPlane * tanfov;
b3Scalar aspect;
float width = m_glApp->m_instancingRenderer->getScreenWidth();
float height = m_glApp->m_instancingRenderer->getScreenHeight();
float width = m_glApp->m_renderer->getScreenWidth();
float height = m_glApp->m_renderer->getScreenHeight();
aspect = width / height;
@@ -171,7 +171,7 @@ bool Bullet2MultiBodyDemo::mouseMoveCallback(float x,float y)
btVector3 rayFrom;
// btVector3 oldPivotInB = pickCon->getPivotInB();
btVector3 newPivotB;
m_glApp->m_instancingRenderer->getCameraPosition(rayFrom);
m_glApp->m_renderer->getCameraPosition(rayFrom);
btVector3 dir = newRayTo-rayFrom;
dir.normalize();
dir *= m_oldPickingDist;
@@ -189,7 +189,7 @@ bool Bullet2MultiBodyDemo::mouseMoveCallback(float x,float y)
// btVector3 oldPivotInB = m_pickingMultiBodyPoint2Point->getPivotInB();
btVector3 newPivotB;
btVector3 camPos;
m_glApp->m_instancingRenderer->getCameraPosition(camPos);
m_glApp->m_renderer->getCameraPosition(camPos);
rayFrom = camPos;
btVector3 dir = newRayTo-rayFrom;
dir.normalize();
@@ -210,7 +210,7 @@ bool Bullet2MultiBodyDemo::mouseButtonCallback(int button, int state, float x, f
if(button==0)// && (m_data->m_altPressed==0 && m_data->m_controlPressed==0))
{
btVector3 camPos;
m_glApp->m_instancingRenderer->getCameraPosition(camPos);
m_glApp->m_renderer->getCameraPosition(camPos);
btVector3 rayFrom = camPos;
btVector3 rayTo = getRayTo(x,y);
@@ -314,7 +314,7 @@ bool Bullet2MultiBodyDemo::mouseButtonCallback(int button, int state, float x, f
FeatherstoneDemo1::FeatherstoneDemo1(SimpleOpenGL3App* app)
FeatherstoneDemo1::FeatherstoneDemo1(CommonGraphicsApp* app)
:Bullet2MultiBodyDemo(app)
{
}
@@ -329,7 +329,7 @@ btMultiBody* FeatherstoneDemo1::createFeatherstoneMultiBody(class btMultiBodyDyn
int curColor=0;
int cubeShapeId = m_glApp->registerCubeShape();
int cubeShapeId = m_glApp->registerCubeShape(1,1,1);
int n_links = settings.m_numLinks;
float mass = 13.5*scaling;
@@ -458,7 +458,7 @@ btMultiBody* FeatherstoneDemo1::createFeatherstoneMultiBody(class btMultiBodyDyn
btVector4 color = colors[curColor++];
curColor&=3;
int index = m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,tr.getOrigin(),tr.getRotation(),color,halfExtents);
int index = m_glApp->m_renderer->registerGraphicsInstance(cubeShapeId,tr.getOrigin(),tr.getRotation(),color,halfExtents);
col->setUserIndex(index);
@@ -503,7 +503,7 @@ btMultiBody* FeatherstoneDemo1::createFeatherstoneMultiBody(class btMultiBodyDyn
btVector4 color = colors[curColor++];
curColor&=3;
int index = m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,tr.getOrigin(),tr.getRotation(),color,halfExtents);
int index = m_glApp->m_renderer->registerGraphicsInstance(cubeShapeId,tr.getOrigin(),tr.getRotation(),color,halfExtents);
col->setUserIndex(index);
@@ -530,7 +530,7 @@ void FeatherstoneDemo1::addBoxes_testMultiDof()
void FeatherstoneDemo1::createGround()
{
//create ground
int cubeShapeId = m_glApp->registerCubeShape();
int cubeShapeId = m_glApp->registerCubeShape(1,1,1);
//float pos[]={0,0,0};
//float orn[]={0,0,0,1};
@@ -555,7 +555,7 @@ void FeatherstoneDemo1::createGround()
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
int index = m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,groundTransform.getOrigin(),groundTransform.getRotation(),color,halfExtents);
int index = m_glApp->m_renderer->registerGraphicsInstance(cubeShapeId,groundTransform.getOrigin(),groundTransform.getRotation(),color,halfExtents);
body ->setUserIndex(index);
//add the body to the dynamics world
@@ -579,7 +579,7 @@ void FeatherstoneDemo1::initPhysics()
createFeatherstoneMultiBody(m_dynamicsWorld,settings);
m_glApp->m_instancingRenderer->writeTransforms();
m_glApp->m_renderer->writeTransforms();
}
@@ -602,13 +602,13 @@ void FeatherstoneDemo1::renderScene()
int index = col->getUserIndex();
if (index>=0)
{
m_glApp->m_instancingRenderer->writeSingleInstanceTransformToCPU(pos,orn,index);
m_glApp->m_renderer->writeSingleInstanceTransformToCPU(pos,orn,index);
}
}
m_glApp->m_instancingRenderer->writeTransforms();
m_glApp->m_renderer->writeTransforms();
}
m_glApp->m_instancingRenderer->renderScene();
m_glApp->m_renderer->renderScene();
}
void FeatherstoneDemo1::physicsDebugDraw()
@@ -646,7 +646,7 @@ void FeatherstoneDemo1::stepSimulation(float deltaTime)
FeatherstoneDemo2::FeatherstoneDemo2(SimpleOpenGL3App* app)
FeatherstoneDemo2::FeatherstoneDemo2(CommonGraphicsApp* app)
:FeatherstoneDemo1(app)
{
}
@@ -1032,7 +1032,7 @@ void FeatherstoneDemo2::initPhysics()
//RagDoll2* doll = new RagDoll2(m_dynamicsWorld,offset,m_glApp);
m_glApp->m_instancingRenderer->writeTransforms();
m_glApp->m_renderer->writeTransforms();
}

View File

@@ -33,7 +33,7 @@ class Bullet2MultiBodyDemo : public BulletDemoInterface
{
protected:
SimpleOpenGL3App* m_glApp;
CommonGraphicsApp* m_glApp;
class btRigidBody* m_pickedBody;
class btTypedConstraint* m_pickedConstraint;
@@ -53,7 +53,7 @@ protected:
//btAlignedObjectArray<btMultiBodyLinkCollider*> m_linkColliders;
public:
Bullet2MultiBodyDemo(SimpleOpenGL3App* app);
Bullet2MultiBodyDemo(CommonGraphicsApp* app);
virtual void initPhysics();
virtual void exitPhysics();
virtual ~Bullet2MultiBodyDemo();
@@ -71,11 +71,11 @@ class FeatherstoneDemo1 : public Bullet2MultiBodyDemo
public:
FeatherstoneDemo1(SimpleOpenGL3App* app);
FeatherstoneDemo1(CommonGraphicsApp* app);
virtual ~FeatherstoneDemo1();
static BulletDemoInterface* MyCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyCreateFunc(CommonGraphicsApp* app)
{
return new FeatherstoneDemo1(app);
}
@@ -100,11 +100,11 @@ class FeatherstoneDemo2 : public FeatherstoneDemo1
public:
FeatherstoneDemo2(SimpleOpenGL3App* app);
FeatherstoneDemo2(CommonGraphicsApp* app);
virtual ~FeatherstoneDemo2();
static BulletDemoInterface* MyCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyCreateFunc(CommonGraphicsApp* app)
{
return new FeatherstoneDemo2(app);
}

View File

@@ -32,7 +32,7 @@ static float friction = 1.;
MultiDofDemo::MultiDofDemo(SimpleOpenGL3App* app)
MultiDofDemo::MultiDofDemo(CommonGraphicsApp* app)
:FeatherstoneDemo1(app)
{
}
@@ -75,8 +75,8 @@ void MultiDofDemo::initPhysics()
if(g_firstInit)
{
this->m_glApp->m_instancingRenderer->setCameraDistance(btScalar(10.*scaling));
this->m_glApp->m_instancingRenderer->setCameraPitch(50);
this->m_glApp->m_renderer->setCameraDistance(btScalar(10.*scaling));
this->m_glApp->m_renderer->setCameraPitch(50);
g_firstInit = false;
}
///collision configuration contains default setup for memory, collision setup
@@ -159,7 +159,7 @@ void MultiDofDemo::initPhysics()
///
addColliders_testMultiDof(mbC, world, baseHalfExtents, linkHalfExtents);
int cubeShapeId = m_glApp->registerCubeShape();
int cubeShapeId = m_glApp->registerCubeShape(1,1,1);
/////////////////////////////////////////////////////////////////
btScalar groundHeight = -51.55;
if (!multibodyOnly)
@@ -183,7 +183,7 @@ void MultiDofDemo::initPhysics()
//add the body to the dynamics world
m_dynamicsWorld->addRigidBody(body,1,1+2);//,1,1+2);
int index = m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,groundTransform.getOrigin(),groundTransform.getRotation(),btVector4(0,1,0,1),groundHalfExtents);
int index = m_glApp->m_renderer->registerGraphicsInstance(cubeShapeId,groundTransform.getOrigin(),groundTransform.getRotation(),btVector4(0,1,0,1),groundHalfExtents);
body->setUserIndex(index);
@@ -223,12 +223,12 @@ void MultiDofDemo::initPhysics()
m_dynamicsWorld->addRigidBody(body);//,1,1+2);
int index = m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,startTransform.getOrigin(),startTransform.getRotation(),btVector4(1,1,0,1),halfExtents);
int index = m_glApp->m_renderer->registerGraphicsInstance(cubeShapeId,startTransform.getOrigin(),startTransform.getRotation(),btVector4(1,1,0,1),halfExtents);
body->setUserIndex(index);
}
m_glApp->m_instancingRenderer->writeTransforms();
m_glApp->m_renderer->writeTransforms();
/////////////////////////////////////////////////////////////////
}
@@ -295,7 +295,7 @@ btMultiBody* MultiDofDemo::createFeatherstoneMultiBody_testMultiDof(btMultiBodyD
void MultiDofDemo::addColliders_testMultiDof(btMultiBody *pMultiBody, btMultiBodyDynamicsWorld *pWorld, const btVector3 &baseHalfExtents, const btVector3 &linkHalfExtents)
{
int cubeShapeId = m_glApp->registerCubeShape();
int cubeShapeId = m_glApp->registerCubeShape(1,1,1);
btAlignedObjectArray<btQuaternion> world_to_local;
world_to_local.resize(pMultiBody->getNumLinks() + 1);
@@ -325,7 +325,7 @@ void MultiDofDemo::addColliders_testMultiDof(btMultiBody *pMultiBody, btMultiBod
pWorld->addCollisionObject(col, 2,1+2);
int index = m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,tr.getOrigin(),tr.getRotation(),btVector4(0,0,1,1),baseHalfExtents);
int index = m_glApp->m_renderer->registerGraphicsInstance(cubeShapeId,tr.getOrigin(),tr.getRotation(),btVector4(0,0,1,1),baseHalfExtents);
col->setUserIndex(index);
@@ -363,7 +363,7 @@ void MultiDofDemo::addColliders_testMultiDof(btMultiBody *pMultiBody, btMultiBod
col->setWorldTransform(tr);
col->setFriction(friction);
pWorld->addCollisionObject(col,2,1+2);
int index = m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,tr.getOrigin(),tr.getRotation(),btVector4(0,0,1,1),linkHalfExtents);
int index = m_glApp->m_renderer->registerGraphicsInstance(cubeShapeId,tr.getOrigin(),tr.getRotation(),btVector4(0,0,1,1),linkHalfExtents);
col->setUserIndex(index);

View File

@@ -9,11 +9,11 @@ class MultiDofDemo : public FeatherstoneDemo1
public:
MultiDofDemo(SimpleOpenGL3App* app);
MultiDofDemo(CommonGraphicsApp* app);
virtual ~MultiDofDemo();
static BulletDemoInterface* MyCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyCreateFunc(CommonGraphicsApp* app)
{
return new MultiDofDemo(app);
}

View File

@@ -27,7 +27,7 @@ static btVector4 colors[4] =
btVector4(1,1,0,1),
};
LuaPhysicsSetup::LuaPhysicsSetup(class SimpleOpenGL3App* app)
LuaPhysicsSetup::LuaPhysicsSetup(struct CommonGraphicsApp* app)
:m_glApp(app),
m_config(0),
m_dispatcher(0),
@@ -93,7 +93,7 @@ static int gCreateCubeShape(lua_State *L)
btCollisionShape* colShape = new btBoxShape(halfExtents);
CustomShapeData* shapeData = new CustomShapeData();
shapeData->m_shapeIndex = sLuaDemo->m_glApp->registerCubeShape();
shapeData->m_shapeIndex = sLuaDemo->m_glApp->registerCubeShape(1,1,1);
shapeData->m_localScaling = halfExtents;
colShape->setUserPointer(shapeData);
@@ -252,7 +252,7 @@ static int gCreateRigidBody (lua_State *L)
if (shapeData)
{
rbd ->m_graphicsInstanceIndex = sLuaDemo->m_glApp->m_instancingRenderer->registerGraphicsInstance(shapeData->m_shapeIndex,startTransform.getOrigin(),startTransform.getRotation(),color,shapeData->m_localScaling);
rbd ->m_graphicsInstanceIndex = sLuaDemo->m_glApp->m_renderer->registerGraphicsInstance(shapeData->m_shapeIndex,startTransform.getOrigin(),startTransform.getRotation(),color,shapeData->m_localScaling);
body->setUserIndex(rbd->m_graphicsInstanceIndex);
}
}
@@ -389,7 +389,7 @@ void LuaPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
b3Error("Cannot find Lua file%s\n",sLuaFileName);
}
m_glApp->m_instancingRenderer->writeTransforms();
m_glApp->m_renderer->writeTransforms();
}
@@ -447,10 +447,10 @@ void LuaPhysicsSetup::syncPhysicsToGraphics(GraphicsPhysicsBridge& gfxBridge)
int index = colObj->getUserIndex();
if (index >= 0)
{
m_glApp->m_instancingRenderer->writeSingleInstanceTransformToCPU(pos, orn, index);
m_glApp->m_renderer->writeSingleInstanceTransformToCPU(pos, orn, index);
}
}
m_glApp->m_instancingRenderer->writeTransforms();
m_glApp->m_renderer->writeTransforms();
}
btRigidBody* LuaPhysicsSetup::createRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape, const btVector4& color)

View File

@@ -9,7 +9,7 @@
struct LuaPhysicsSetup : public CommonPhysicsSetup
{
LuaPhysicsSetup(class SimpleOpenGL3App* app);
LuaPhysicsSetup(struct CommonGraphicsApp* app);
virtual ~LuaPhysicsSetup();
class btDefaultCollisionConfiguration* m_config;
@@ -17,7 +17,7 @@ struct LuaPhysicsSetup : public CommonPhysicsSetup
class btDbvtBroadphase* m_bp;
class btNNCGConstraintSolver* m_solver;
class btDiscreteDynamicsWorld* m_dynamicsWorld;
class SimpleOpenGL3App* m_glApp;
struct CommonGraphicsApp* m_glApp;
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);

View File

@@ -6,13 +6,13 @@
#include "../BasicDemo/BasicDemo.h"
struct BulletDemoInterface;
struct SimpleOpenGL3App;
struct CommonGraphicsApp;
class RagDollSetup : public CommonRigidBodySetup
{
public:
static BulletDemoInterface* MyCreateFunc(SimpleOpenGL3App* app)
static BulletDemoInterface* MyCreateFunc(CommonGraphicsApp* app)
{
CommonPhysicsSetup* physicsSetup = new RagDollSetup();
return new BasicDemo(app, physicsSetup);