Merge pull request #271 from erwincoumans/master

btHingeConstraint to set/get ERP, refactor gfx backends (work-in-progress)
This commit is contained in:
erwincoumans
2014-10-17 13:48:02 -07:00
55 changed files with 1440 additions and 348 deletions

View File

@@ -9,7 +9,8 @@
void BasicDemoPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge) void BasicDemoPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
{ {
createEmptyDynamicsWorld(); createEmptyDynamicsWorld();
gfxBridge.createPhysicsDebugDrawer(m_dynamicsWorld);
m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints);
///create a few basic rigid bodies ///create a few basic rigid bodies
btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));

View File

@@ -20,58 +20,61 @@
#include "../ImportSTLDemo/ImportSTLSetup.h" #include "../ImportSTLDemo/ImportSTLSetup.h"
#include "../../Demos/SerializeDemo/SerializeSetup.h" #include "../../Demos/SerializeDemo/SerializeSetup.h"
#include "../bullet2/MultiBodyDemo/TestJointTorqueSetup.h" #include "../bullet2/MultiBodyDemo/TestJointTorqueSetup.h"
#include "../bullet2/CollisionDetection/SupportFuncDemo.h"
static BulletDemoInterface* TestJointTorqueCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* TestJointTorqueCreateFunc(CommonGraphicsApp* app)
{ {
CommonPhysicsSetup* physicsSetup = new TestJointTorqueSetup(); CommonPhysicsSetup* physicsSetup = new TestJointTorqueSetup();
return new BasicDemo(app, physicsSetup); return new BasicDemo(app, physicsSetup);
} }
static BulletDemoInterface* LuaDemoCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* LuaDemoCreateFunc(CommonGraphicsApp* app)
{ {
CommonPhysicsSetup* physicsSetup = new LuaPhysicsSetup(app); CommonPhysicsSetup* physicsSetup = new LuaPhysicsSetup(app);
return new BasicDemo(app, physicsSetup); return new BasicDemo(app, physicsSetup);
} }
static BulletDemoInterface* MyCcdPhysicsDemoCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* MyCcdPhysicsDemoCreateFunc(CommonGraphicsApp* app)
{ {
CommonPhysicsSetup* physicsSetup = new CcdPhysicsSetup(); CommonPhysicsSetup* physicsSetup = new CcdPhysicsSetup();
return new BasicDemo(app, physicsSetup); return new BasicDemo(app, physicsSetup);
} }
static BulletDemoInterface* MyKinematicObjectCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* MyKinematicObjectCreateFunc(CommonGraphicsApp* app)
{ {
CommonPhysicsSetup* physicsSetup = new KinematicObjectSetup(); CommonPhysicsSetup* physicsSetup = new KinematicObjectSetup();
return new BasicDemo(app, physicsSetup); return new BasicDemo(app, physicsSetup);
} }
static BulletDemoInterface* MySerializeCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* MySerializeCreateFunc(CommonGraphicsApp* app)
{ {
CommonPhysicsSetup* physicsSetup = new SerializeSetup(); CommonPhysicsSetup* physicsSetup = new SerializeSetup();
return new BasicDemo(app, physicsSetup); return new BasicDemo(app, physicsSetup);
} }
static BulletDemoInterface* MyConstraintCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* MyConstraintCreateFunc(CommonGraphicsApp* app)
{ {
CommonPhysicsSetup* physicsSetup = new ConstraintPhysicsSetup(); CommonPhysicsSetup* physicsSetup = new ConstraintPhysicsSetup();
return new BasicDemo(app, physicsSetup); return new BasicDemo(app, physicsSetup);
} }
static BulletDemoInterface* MyImportUrdfCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* MyImportUrdfCreateFunc(CommonGraphicsApp* app)
{ {
CommonPhysicsSetup* physicsSetup = new ImportUrdfDemo(); CommonPhysicsSetup* physicsSetup = new ImportUrdfDemo();
return new BasicDemo(app, physicsSetup); return new BasicDemo(app, physicsSetup);
} }
static BulletDemoInterface* MyImportObjCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* MyImportObjCreateFunc(CommonGraphicsApp* app)
{ {
CommonPhysicsSetup* physicsSetup = new ImportObjDemo(app); CommonPhysicsSetup* physicsSetup = new ImportObjDemo(app);
return new BasicDemo(app, physicsSetup); return new BasicDemo(app, physicsSetup);
} }
static BulletDemoInterface* MyImportSTLCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* MyImportSTLCreateFunc(CommonGraphicsApp* app)
{ {
CommonPhysicsSetup* physicsSetup = new ImportSTLDemo(app); CommonPhysicsSetup* physicsSetup = new ImportSTLDemo(app);
return new BasicDemo(app, physicsSetup); return new BasicDemo(app, physicsSetup);
} }
struct BulletDemoEntry struct BulletDemoEntry
{ {
int m_menuLevel; int m_menuLevel;
@@ -83,9 +86,13 @@ struct BulletDemoEntry
static BulletDemoEntry allDemos[]= static BulletDemoEntry allDemos[]=
{ {
{0,"LowLevel",0},
{1,"SupportFunc", &MySupportFuncDemo::CreateFunc},
//{"emptydemo",EmptyBulletDemo::MyCreateFunc}, //{"emptydemo",EmptyBulletDemo::MyCreateFunc},
{0,"API Demos", 0}, {0,"API Demos", 0},
{1,"BasicDemo",BasicDemo::MyCreateFunc}, {1,"BasicDemo",BasicDemo::MyCreateFunc},
{ 1, "CcdDemo", MyCcdPhysicsDemoCreateFunc }, { 1, "CcdDemo", MyCcdPhysicsDemoCreateFunc },
{ 1, "Kinematic", MyKinematicObjectCreateFunc }, { 1, "Kinematic", MyKinematicObjectCreateFunc },

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" #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 "Bullet3Common/b3Vector3.h"
#include "assert.h" #include "assert.h"
#include <stdio.h> #include <stdio.h>
@@ -11,11 +34,172 @@
#include "Bullet3AppSupport/GwenProfileWindow.h" #include "Bullet3AppSupport/GwenProfileWindow.h"
#include "Bullet3AppSupport/GwenTextureWindow.h" #include "Bullet3AppSupport/GwenTextureWindow.h"
#include "Bullet3AppSupport/GraphingTexture.h" #include "Bullet3AppSupport/GraphingTexture.h"
#include "OpenGLWindow/CommonRenderInterface.h"
#include "OpenGLWindow/SimpleCamera.h"
CommonGraphicsApp* app=0;
#ifdef USE_OPENGL2
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()
{
}
};
#endif //USE_OPENGL2
b3gWindowInterface* s_window = 0;
CommonParameterInterface* s_parameterInterface=0;
CommonRenderInterface* s_instancingRenderer=0;
#define DEMO_SELECTION_COMBOBOX 13 #define DEMO_SELECTION_COMBOBOX 13
const char* startFileName = "bulletDemo.txt"; const char* startFileName = "bulletDemo.txt";
static SimpleOpenGL3App* app=0;
static GwenUserInterface* gui = 0; static GwenUserInterface* gui = 0;
static int sCurrentDemoIndex = 0; static int sCurrentDemoIndex = 0;
static int sCurrentHightlighted = 0; static int sCurrentHightlighted = 0;
@@ -30,82 +214,14 @@ int midiBaseIndex = 176;
//#include <float.h> //#include <float.h>
//unsigned int fp_control_state = _controlfp(_EM_INEXACT, _MCW_EM); //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) void MyKeyboardCallback(int key, int state)
{ {
@@ -146,15 +262,16 @@ void MyKeyboardCallback(int key, int state)
useShadowMap=!useShadowMap; 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) static void MyMouseMoveCallback( float x, float y)
{ {
bool handled = false; bool handled = false;
@@ -163,8 +280,14 @@ static void MyMouseMoveCallback( float x, float y)
if (!handled && gui) if (!handled && gui)
handled = gui->mouseMoveCallback(x,y); handled = gui->mouseMoveCallback(x,y);
if (!handled) if (!handled)
b3DefaultMouseMoveCallback(x,y); {
if (prevMouseMoveCallback)
prevMouseMoveCallback(x,y);
}
} }
b3MouseButtonCallback prevMouseButtonCallback = 0;
static void MyMouseButtonCallback(int button, int state, float x, float y) static void MyMouseButtonCallback(int button, int state, float x, float y)
{ {
bool handled = false; 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); handled = gui->mouseButtonCallback(button,state,x,y);
if (!handled) if (!handled)
b3DefaultMouseButtonCallback(button,state,x,y); {
if (prevMouseButtonCallback )
prevMouseButtonCallback (button,state,x,y);
}
// b3DefaultMouseButtonCallback(button,state,x,y);
} }
#include <string.h> #include <string.h>
@@ -187,17 +314,17 @@ void openURDFDemo(const char* filename)
if (sCurrentDemo) if (sCurrentDemo)
{ {
sCurrentDemo->exitPhysics(); sCurrentDemo->exitPhysics();
app->m_instancingRenderer->removeAllInstances(); s_instancingRenderer->removeAllInstances();
delete sCurrentDemo; delete sCurrentDemo;
sCurrentDemo=0; sCurrentDemo=0;
} }
app->m_parameterInterface->removeAllParameters(); s_parameterInterface->removeAllParameters();
ImportUrdfDemo* physicsSetup = new ImportUrdfDemo(); ImportUrdfDemo* physicsSetup = new ImportUrdfDemo();
physicsSetup->setFileName(filename); physicsSetup->setFileName(filename);
sCurrentDemo = new BasicDemo(app, physicsSetup); sCurrentDemo = new BasicDemo(0, physicsSetup);
if (sCurrentDemo) if (sCurrentDemo)
{ {
@@ -219,16 +346,21 @@ void selectDemo(int demoIndex)
if (sCurrentDemo) if (sCurrentDemo)
{ {
sCurrentDemo->exitPhysics(); sCurrentDemo->exitPhysics();
app->m_instancingRenderer->removeAllInstances(); s_instancingRenderer->removeAllInstances();
delete sCurrentDemo; delete sCurrentDemo;
sCurrentDemo=0; 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); sCurrentDemo = (*allDemos[demoIndex].m_createFunc)(app);
if (sCurrentDemo) if (sCurrentDemo)
{ {
if (gui)
{
bool isLeft = true;
gui->setStatusBarMessage("Status: OK", false);
}
sCurrentDemo->initPhysics(); sCurrentDemo->initPhysics();
} }
} }
@@ -255,6 +387,28 @@ void MyComboBoxCallback(int comboId, const char* item)
} }
void MyStatusBarPrintf(const char* msg)
{
printf("b3Printf: %s\n", msg);
if (gui)
{
bool isLeft = true;
gui->setStatusBarMessage(msg,isLeft);
}
}
void MyStatusBarWarning(const char* msg)
{
printf("Warning: %s\n", msg);
if (gui)
{
bool isLeft = false;
gui->setStatusBarMessage(msg,isLeft);
}
}
struct MyMenuItemHander :public Gwen::Event::Handler struct MyMenuItemHander :public Gwen::Event::Handler
{ {
int m_buttonId; int m_buttonId;
@@ -359,7 +513,7 @@ void fileOpenCallback()
{ {
char filename[1024]; char filename[1024];
int len = app->m_window->fileOpenDialog(filename,1024); int len = s_window->fileOpenDialog(filename,1024);
if (len) if (len)
{ {
//todo(erwincoumans) check if it is actually URDF //todo(erwincoumans) check if it is actually URDF
@@ -379,31 +533,70 @@ int main(int argc, char* argv[])
int width = 1024; int width = 1024;
int height=768; int height=768;
// wci.m_resizeCallback = MyResizeCallback;
app = new SimpleOpenGL3App("AllBullet2Demos",width,height); #ifdef USE_OPENGL2
app->m_instancingRenderer->setCameraDistance(13); app = new SimpleOpenGL2App("AllBullet2Demos",width,height);
app->m_instancingRenderer->setCameraPitch(0); app->m_renderer = new TestRenderer(width,height);
app->m_instancingRenderer->setCameraTargetPosition(b3MakeVector3(0,0,0)); #else
app->m_window->setMouseMoveCallback(MyMouseMoveCallback); SimpleOpenGL3App* simpleApp = new SimpleOpenGL3App("AllBullet2Demos",width,height);
app->m_window->setMouseButtonCallback(MyMouseButtonCallback); app = simpleApp;
app->m_window->setKeyboardCallback(MyKeyboardCallback); #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);
b3SetCustomWarningMessageFunc(MyStatusBarWarning);
b3SetCustomPrintfFunc(MyStatusBarPrintf);
/*
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); assert(glGetError()==GL_NO_ERROR);
sth_stash* fontstash=app->getFontStash();
gui = new GwenUserInterface; 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 // gui->getInternalData()->m_explorerPage
Gwen::Controls::TreeControl* tree = gui->getInternalData()->m_explorerTreeCtrl; 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()); MyProfileWindow* profWindow = setupProfileWindow(gui->getInternalData());
profileWindowSetVisible(profWindow,false); profileWindowSetVisible(profWindow,false);
#if 0
{ {
MyGraphInput input(gui->getInternalData()); MyGraphInput input(gui->getInternalData());
input.m_width=300; input.m_width=300;
@@ -448,10 +641,9 @@ int main(int argc, char* argv[])
setupTextureWindow(input); setupTextureWindow(input);
} }
//destroyTextureWindow(gw); //destroyTextureWindow(gw);
#endif
s_parameterInterface = app->m_parameterInterface = new GwenParameterInterface(gui->getInternalData());
app->m_parameterInterface = new GwenParameterInterface(gui->getInternalData());
//gui->getInternalData()->m_demoPage; //gui->getInternalData()->m_demoPage;
int numDemos = sizeof(allDemos)/sizeof(BulletDemoEntry); int numDemos = sizeof(allDemos)/sizeof(BulletDemoEntry);
@@ -520,13 +712,13 @@ int main(int argc, char* argv[])
{ {
assert(glGetError()==GL_NO_ERROR); assert(glGetError()==GL_NO_ERROR);
app->m_instancingRenderer->init(); s_instancingRenderer->init();
DrawGridData dg; DrawGridData dg;
dg.upAxis = app->getUpAxis(); dg.upAxis = app->getUpAxis();
{ {
BT_PROFILE("Update Camera"); BT_PROFILE("Update Camera");
app->m_instancingRenderer->updateCamera(dg.upAxis); s_instancingRenderer->updateCamera(dg.upAxis);
} }
{ {
BT_PROFILE("Draw Grid"); BT_PROFILE("Draw Grid");
@@ -571,20 +763,30 @@ int main(int argc, char* argv[])
if (!pauseSimulation) if (!pauseSimulation)
processProfileData(profWindow,false); processProfileData(profWindow,false);
{ {
#ifdef USE_OPENGL2
{
saveOpenGLState(width,height);
}
#endif
BT_PROFILE("Draw Gwen GUI"); 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; toggle=1-toggle;
{ {
BT_PROFILE("Sync Parameters"); BT_PROFILE("Sync Parameters");
app->m_parameterInterface->syncParameters(); s_parameterInterface->syncParameters();
} }
{ {
BT_PROFILE("Swap Buffers"); BT_PROFILE("Swap Buffers");
app->swapBuffer(); app->swapBuffer();
} }
} while (!app->m_window->requestedExit());
} while (!s_window->requestedExit());
// selectDemo(0); // selectDemo(0);
delete gui; delete gui;

View File

@@ -20,7 +20,7 @@
#include "OpenGLWindow/GLPrimitiveRenderer.h" #include "OpenGLWindow/GLPrimitiveRenderer.h"
#include "OpenGLWindow/GLInstancingRenderer.h" #include "OpenGLWindow/GLInstancingRenderer.h"
//#include "OpenGL3CoreRenderer.h" #include "OpenGLWindow/GwenOpenGL3CoreRenderer.h"
//#include "b3GpuDynamicsWorld.h" //#include "b3GpuDynamicsWorld.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
@@ -739,7 +739,10 @@ int main(int argc, char* argv[])
if (gui) 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"); printf("init fonts");

View File

@@ -7,7 +7,7 @@
#include "OpenGLWindow/SimpleOpenGL3App.h" #include "OpenGLWindow/SimpleOpenGL3App.h"
#include "Wavefront2GLInstanceGraphicsShape.h" #include "Wavefront2GLInstanceGraphicsShape.h"
ImportObjDemo::ImportObjDemo(SimpleOpenGL3App* app) ImportObjDemo::ImportObjDemo(CommonGraphicsApp* app)
:m_app(app) :m_app(app)
{ {
@@ -75,11 +75,11 @@ void ImportObjDemo::initPhysics(GraphicsPhysicsBridge& gfxBridge)
btVector3 color(0,0,1); 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 = //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 class ImportObjDemo : public CommonRigidBodySetup
{ {
struct SimpleOpenGL3App* m_app; struct CommonGraphicsApp* m_app;
public: public:
ImportObjDemo(SimpleOpenGL3App* app); ImportObjDemo(CommonGraphicsApp* app);
virtual ~ImportObjDemo(); virtual ~ImportObjDemo();
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge); virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);

View File

@@ -6,7 +6,7 @@
#include "OpenGLWindow/SimpleOpenGL3App.h" #include "OpenGLWindow/SimpleOpenGL3App.h"
#include "LoadMeshFromSTL.h" #include "LoadMeshFromSTL.h"
ImportSTLDemo::ImportSTLDemo(SimpleOpenGL3App* app) ImportSTLDemo::ImportSTLDemo(CommonGraphicsApp* app)
:m_app(app) :m_app(app)
{ {
@@ -68,11 +68,11 @@ void ImportSTLDemo::initPhysics(GraphicsPhysicsBridge& gfxBridge)
btVector3 color(0,0,1); 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 = // 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 class ImportSTLDemo : public CommonRigidBodySetup
{ {
struct SimpleOpenGL3App* m_app; struct CommonGraphicsApp* m_app;
public: public:
ImportSTLDemo(SimpleOpenGL3App* app); ImportSTLDemo(CommonGraphicsApp* app);
virtual ~ImportSTLDemo(); virtual ~ImportSTLDemo();
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge); virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,114 @@
#ifndef SUPPORT_FUNC_DEMO_H
#define SUPPORT_FUNC_DEMO_H
#include "Bullet3AppSupport/BulletDemoInterface.h"
#include "OpenGLWindow/CommonGraphicsApp.h"
#include "BulletCollision/CollisionShapes/btSphereShape.h"
///quick demo showing the support map function (localGetSupportingVertex)
class MySupportFuncDemo : public BulletDemoInterface
{
CommonGraphicsApp* m_app;
btSphereShape* m_sphere;
float m_x;
float m_y;
public:
MySupportFuncDemo(CommonGraphicsApp* app)
:m_app(app),
m_x(0),
m_y(0)
{
m_sphere = new btSphereShape(1);
{
int boxId = m_app->registerCubeShape(10,0.1,10);
btVector3 pos(0,-2,0);
btQuaternion orn(0,0,0,1);
btVector4 color(0.3,0.3,0.3,1);
btVector3 scaling(1,1,1);
m_app->m_renderer->registerGraphicsInstance(boxId,pos,orn,color,scaling);
}
{
int sphereId = m_app->registerGraphicsSphereShape(1,false,0,0);
btVector3 pos(0,0,0);
btQuaternion orn(0,0,0,1);
btVector4 color(0,1,0,0.6);
btVector3 scaling(1,1,1);
m_app->m_renderer->registerGraphicsInstance(sphereId,pos,orn,color,scaling);
}
m_app->m_renderer->writeTransforms();
m_app->m_renderer->enableBlend(true);
}
virtual ~MySupportFuncDemo()
{
m_app->m_renderer->enableBlend(false);
delete m_sphere;
}
static BulletDemoInterface* CreateFunc(CommonGraphicsApp* app)
{
return new MySupportFuncDemo(app);
}
virtual void initPhysics()
{
}
virtual void exitPhysics()
{
}
virtual void stepSimulation(float deltaTime)
{
m_x+=0.01f;
m_y+=0.02f;
}
virtual void renderScene()
{
m_app->m_renderer->renderScene();
}
virtual void physicsDebugDraw()
{
int width=3;
btVector3 from(0,0,0);
btVector3 to(10.*btSin(m_x),10.*btCos(m_x),10.*btSin(m_y));
{
btVector3 color(1,0,0);
m_app->m_renderer->drawLine(from,to,color,width);
}
btVector3 dir(to-from);
btVector3 sup = m_sphere->btConvexInternalShape::localGetSupportingVertex(dir);
btVector3 orth0,orth1;
btPlaneSpace1(dir,orth0,orth1);
btVector3 color(0,0,1);
orth0.normalize();
orth1.normalize();
m_app->m_renderer->drawLine(sup,sup+orth0*0.4,color,3);
m_app->m_renderer->drawLine(sup,sup+orth1*0.4,color,3);
}
virtual bool mouseMoveCallback(float x,float y)
{
return false;
}
virtual bool mouseButtonCallback(int button, int state, float x, float y)
{
return false;
}
virtual bool keyboardCallback(int key, int state)
{
return false;
}
};
#endif //SUPPORT_FUNC_DEMO

View File

@@ -19,9 +19,12 @@ void ConstraintPhysicsSetup::stepSimulation(float deltaTime)
} }
#include "Bullet3Common/b3Logging.h"
void ConstraintPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge) void ConstraintPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
{ {
b3Printf(__FILE__);
gfxBridge.setUpAxis(1); gfxBridge.setUpAxis(1);
createEmptyDynamicsWorld(); createEmptyDynamicsWorld();
@@ -51,6 +54,8 @@ slider.m_maxVal=720;
btVector3 btAxisA( 0.0f, 1.0f, 0.0f ); // pointing upwards, aka Y-axis btVector3 btAxisA( 0.0f, 1.0f, 0.0f ); // pointing upwards, aka Y-axis
spDoorHinge = new btHingeAccumulatedAngleConstraint( *pDoorBody, btPivotA, btAxisA ); spDoorHinge = new btHingeAccumulatedAngleConstraint( *pDoorBody, btPivotA, btAxisA );
spDoorHinge->setParam(BT_CONSTRAINT_ERP,0.5);
btScalar erp = spDoorHinge->getParam(BT_CONSTRAINT_ERP);
// spDoorHinge->setLimit( 0.0f, SIMD_PI_2 ); // spDoorHinge->setLimit( 0.0f, SIMD_PI_2 );
// test problem values // test problem values

View File

@@ -48,7 +48,7 @@ static btVector4 colors[4] =
Bullet2MultiBodyDemo::Bullet2MultiBodyDemo(SimpleOpenGL3App* app) Bullet2MultiBodyDemo::Bullet2MultiBodyDemo(CommonGraphicsApp* app)
:m_glApp(app), :m_glApp(app),
m_pickedBody(0), m_pickedBody(0),
m_pickedConstraint(0), m_pickedConstraint(0),
@@ -97,7 +97,7 @@ Bullet2MultiBodyDemo::~Bullet2MultiBodyDemo()
btVector3 Bullet2MultiBodyDemo::getRayTo(int x,int y) btVector3 Bullet2MultiBodyDemo::getRayTo(int x,int y)
{ {
if (!m_glApp->m_instancingRenderer) if (!m_glApp->m_renderer)
{ {
btAssert(0); btAssert(0);
return btVector3(0,0,0); return btVector3(0,0,0);
@@ -110,8 +110,8 @@ btVector3 Bullet2MultiBodyDemo::getRayTo(int x,int y)
float fov = b3Scalar(2.0) * b3Atan(tanFov); float fov = b3Scalar(2.0) * b3Atan(tanFov);
btVector3 camPos,camTarget; btVector3 camPos,camTarget;
m_glApp->m_instancingRenderer->getCameraPosition(camPos); m_glApp->m_renderer->getCameraPosition(camPos);
m_glApp->m_instancingRenderer->getCameraTargetPosition(camTarget); m_glApp->m_renderer->getCameraTargetPosition(camTarget);
btVector3 rayFrom = camPos; btVector3 rayFrom = camPos;
btVector3 rayForward = (camTarget-camPos); btVector3 rayForward = (camTarget-camPos);
@@ -136,8 +136,8 @@ btVector3 Bullet2MultiBodyDemo::getRayTo(int x,int y)
vertical *= 2.f * farPlane * tanfov; vertical *= 2.f * farPlane * tanfov;
b3Scalar aspect; b3Scalar aspect;
float width = m_glApp->m_instancingRenderer->getScreenWidth(); float width = m_glApp->m_renderer->getScreenWidth();
float height = m_glApp->m_instancingRenderer->getScreenHeight(); float height = m_glApp->m_renderer->getScreenHeight();
aspect = width / height; aspect = width / height;
@@ -171,7 +171,7 @@ bool Bullet2MultiBodyDemo::mouseMoveCallback(float x,float y)
btVector3 rayFrom; btVector3 rayFrom;
// btVector3 oldPivotInB = pickCon->getPivotInB(); // btVector3 oldPivotInB = pickCon->getPivotInB();
btVector3 newPivotB; btVector3 newPivotB;
m_glApp->m_instancingRenderer->getCameraPosition(rayFrom); m_glApp->m_renderer->getCameraPosition(rayFrom);
btVector3 dir = newRayTo-rayFrom; btVector3 dir = newRayTo-rayFrom;
dir.normalize(); dir.normalize();
dir *= m_oldPickingDist; dir *= m_oldPickingDist;
@@ -189,7 +189,7 @@ bool Bullet2MultiBodyDemo::mouseMoveCallback(float x,float y)
// btVector3 oldPivotInB = m_pickingMultiBodyPoint2Point->getPivotInB(); // btVector3 oldPivotInB = m_pickingMultiBodyPoint2Point->getPivotInB();
btVector3 newPivotB; btVector3 newPivotB;
btVector3 camPos; btVector3 camPos;
m_glApp->m_instancingRenderer->getCameraPosition(camPos); m_glApp->m_renderer->getCameraPosition(camPos);
rayFrom = camPos; rayFrom = camPos;
btVector3 dir = newRayTo-rayFrom; btVector3 dir = newRayTo-rayFrom;
dir.normalize(); 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)) if(button==0)// && (m_data->m_altPressed==0 && m_data->m_controlPressed==0))
{ {
btVector3 camPos; btVector3 camPos;
m_glApp->m_instancingRenderer->getCameraPosition(camPos); m_glApp->m_renderer->getCameraPosition(camPos);
btVector3 rayFrom = camPos; btVector3 rayFrom = camPos;
btVector3 rayTo = getRayTo(x,y); 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) :Bullet2MultiBodyDemo(app)
{ {
} }
@@ -329,7 +329,7 @@ btMultiBody* FeatherstoneDemo1::createFeatherstoneMultiBody(class btMultiBodyDyn
int curColor=0; int curColor=0;
int cubeShapeId = m_glApp->registerCubeShape(); int cubeShapeId = m_glApp->registerCubeShape(1,1,1);
int n_links = settings.m_numLinks; int n_links = settings.m_numLinks;
float mass = 13.5*scaling; float mass = 13.5*scaling;
@@ -458,7 +458,7 @@ btMultiBody* FeatherstoneDemo1::createFeatherstoneMultiBody(class btMultiBodyDyn
btVector4 color = colors[curColor++]; btVector4 color = colors[curColor++];
curColor&=3; 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); col->setUserIndex(index);
@@ -503,7 +503,7 @@ btMultiBody* FeatherstoneDemo1::createFeatherstoneMultiBody(class btMultiBodyDyn
btVector4 color = colors[curColor++]; btVector4 color = colors[curColor++];
curColor&=3; 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); col->setUserIndex(index);
@@ -530,7 +530,7 @@ void FeatherstoneDemo1::addBoxes_testMultiDof()
void FeatherstoneDemo1::createGround() void FeatherstoneDemo1::createGround()
{ {
//create ground //create ground
int cubeShapeId = m_glApp->registerCubeShape(); int cubeShapeId = m_glApp->registerCubeShape(1,1,1);
//float pos[]={0,0,0}; //float pos[]={0,0,0};
//float orn[]={0,0,0,1}; //float orn[]={0,0,0,1};
@@ -555,7 +555,7 @@ void FeatherstoneDemo1::createGround()
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo); 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); body ->setUserIndex(index);
//add the body to the dynamics world //add the body to the dynamics world
@@ -579,7 +579,7 @@ void FeatherstoneDemo1::initPhysics()
createFeatherstoneMultiBody(m_dynamicsWorld,settings); 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(); int index = col->getUserIndex();
if (index>=0) 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() void FeatherstoneDemo1::physicsDebugDraw()
@@ -646,7 +646,7 @@ void FeatherstoneDemo1::stepSimulation(float deltaTime)
FeatherstoneDemo2::FeatherstoneDemo2(SimpleOpenGL3App* app) FeatherstoneDemo2::FeatherstoneDemo2(CommonGraphicsApp* app)
:FeatherstoneDemo1(app) :FeatherstoneDemo1(app)
{ {
} }
@@ -1032,7 +1032,7 @@ void FeatherstoneDemo2::initPhysics()
//RagDoll2* doll = new RagDoll2(m_dynamicsWorld,offset,m_glApp); //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: protected:
SimpleOpenGL3App* m_glApp; CommonGraphicsApp* m_glApp;
class btRigidBody* m_pickedBody; class btRigidBody* m_pickedBody;
class btTypedConstraint* m_pickedConstraint; class btTypedConstraint* m_pickedConstraint;
@@ -53,7 +53,7 @@ protected:
//btAlignedObjectArray<btMultiBodyLinkCollider*> m_linkColliders; //btAlignedObjectArray<btMultiBodyLinkCollider*> m_linkColliders;
public: public:
Bullet2MultiBodyDemo(SimpleOpenGL3App* app); Bullet2MultiBodyDemo(CommonGraphicsApp* app);
virtual void initPhysics(); virtual void initPhysics();
virtual void exitPhysics(); virtual void exitPhysics();
virtual ~Bullet2MultiBodyDemo(); virtual ~Bullet2MultiBodyDemo();
@@ -71,11 +71,11 @@ class FeatherstoneDemo1 : public Bullet2MultiBodyDemo
public: public:
FeatherstoneDemo1(SimpleOpenGL3App* app); FeatherstoneDemo1(CommonGraphicsApp* app);
virtual ~FeatherstoneDemo1(); virtual ~FeatherstoneDemo1();
static BulletDemoInterface* MyCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* MyCreateFunc(CommonGraphicsApp* app)
{ {
return new FeatherstoneDemo1(app); return new FeatherstoneDemo1(app);
} }
@@ -100,11 +100,11 @@ class FeatherstoneDemo2 : public FeatherstoneDemo1
public: public:
FeatherstoneDemo2(SimpleOpenGL3App* app); FeatherstoneDemo2(CommonGraphicsApp* app);
virtual ~FeatherstoneDemo2(); virtual ~FeatherstoneDemo2();
static BulletDemoInterface* MyCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* MyCreateFunc(CommonGraphicsApp* app)
{ {
return new FeatherstoneDemo2(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) :FeatherstoneDemo1(app)
{ {
} }
@@ -75,8 +75,8 @@ void MultiDofDemo::initPhysics()
if(g_firstInit) if(g_firstInit)
{ {
this->m_glApp->m_instancingRenderer->setCameraDistance(btScalar(10.*scaling)); this->m_glApp->m_renderer->setCameraDistance(btScalar(10.*scaling));
this->m_glApp->m_instancingRenderer->setCameraPitch(50); this->m_glApp->m_renderer->setCameraPitch(50);
g_firstInit = false; g_firstInit = false;
} }
///collision configuration contains default setup for memory, collision setup ///collision configuration contains default setup for memory, collision setup
@@ -159,7 +159,7 @@ void MultiDofDemo::initPhysics()
/// ///
addColliders_testMultiDof(mbC, world, baseHalfExtents, linkHalfExtents); addColliders_testMultiDof(mbC, world, baseHalfExtents, linkHalfExtents);
int cubeShapeId = m_glApp->registerCubeShape(); int cubeShapeId = m_glApp->registerCubeShape(1,1,1);
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
btScalar groundHeight = -51.55; btScalar groundHeight = -51.55;
if (!multibodyOnly) if (!multibodyOnly)
@@ -183,7 +183,7 @@ void MultiDofDemo::initPhysics()
//add the body to the dynamics world //add the body to the dynamics world
m_dynamicsWorld->addRigidBody(body,1,1+2);//,1,1+2); 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); body->setUserIndex(index);
@@ -223,12 +223,12 @@ void MultiDofDemo::initPhysics()
m_dynamicsWorld->addRigidBody(body);//,1,1+2); 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); 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) 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; btAlignedObjectArray<btQuaternion> world_to_local;
world_to_local.resize(pMultiBody->getNumLinks() + 1); world_to_local.resize(pMultiBody->getNumLinks() + 1);
@@ -325,7 +325,7 @@ void MultiDofDemo::addColliders_testMultiDof(btMultiBody *pMultiBody, btMultiBod
pWorld->addCollisionObject(col, 2,1+2); 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); col->setUserIndex(index);
@@ -363,7 +363,7 @@ void MultiDofDemo::addColliders_testMultiDof(btMultiBody *pMultiBody, btMultiBod
col->setWorldTransform(tr); col->setWorldTransform(tr);
col->setFriction(friction); col->setFriction(friction);
pWorld->addCollisionObject(col,2,1+2); 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); col->setUserIndex(index);

View File

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

View File

@@ -27,7 +27,7 @@ static btVector4 colors[4] =
btVector4(1,1,0,1), btVector4(1,1,0,1),
}; };
LuaPhysicsSetup::LuaPhysicsSetup(class SimpleOpenGL3App* app) LuaPhysicsSetup::LuaPhysicsSetup(struct CommonGraphicsApp* app)
:m_glApp(app), :m_glApp(app),
m_config(0), m_config(0),
m_dispatcher(0), m_dispatcher(0),
@@ -93,7 +93,7 @@ static int gCreateCubeShape(lua_State *L)
btCollisionShape* colShape = new btBoxShape(halfExtents); btCollisionShape* colShape = new btBoxShape(halfExtents);
CustomShapeData* shapeData = new CustomShapeData(); 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; shapeData->m_localScaling = halfExtents;
colShape->setUserPointer(shapeData); colShape->setUserPointer(shapeData);
@@ -252,7 +252,7 @@ static int gCreateRigidBody (lua_State *L)
if (shapeData) 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); body->setUserIndex(rbd->m_graphicsInstanceIndex);
} }
} }
@@ -389,7 +389,7 @@ void LuaPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
b3Error("Cannot find Lua file%s\n",sLuaFileName); 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(); int index = colObj->getUserIndex();
if (index >= 0) 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) btRigidBody* LuaPhysicsSetup::createRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape, const btVector4& color)

View File

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

View File

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

View File

@@ -1,6 +1,10 @@
#include "Bullet2RigidBodyDemo.h" #include "Bullet2RigidBodyDemo.h"
#include "btBulletDynamicsCommon.h" #include "btBulletDynamicsCommon.h"
#include "OpenGLWindow/SimpleOpenGL3App.h"
#include "OpenGLWindow/CommonGraphicsApp.h"
#include "OpenGLWindow/CommonRenderInterface.h"
#include "Bullet3Common/b3Scalar.h"
#include "BulletCollision/CollisionShapes/btShapeHull.h"//to create a tesselation of a generic btConvexShape #include "BulletCollision/CollisionShapes/btShapeHull.h"//to create a tesselation of a generic btConvexShape
#include "MyDebugDrawer.h" #include "MyDebugDrawer.h"
struct GraphicsVertex struct GraphicsVertex
@@ -13,10 +17,10 @@ struct GraphicsVertex
struct MyGraphicsPhysicsBridge : public GraphicsPhysicsBridge struct MyGraphicsPhysicsBridge : public GraphicsPhysicsBridge
{ {
SimpleOpenGL3App* m_glApp; CommonGraphicsApp* m_glApp;
MyDebugDrawer* m_debugDraw; MyDebugDrawer* m_debugDraw;
MyGraphicsPhysicsBridge(SimpleOpenGL3App* glApp) MyGraphicsPhysicsBridge(CommonGraphicsApp* glApp)
:m_glApp(glApp), m_debugDraw(0) :m_glApp(glApp), m_debugDraw(0)
{ {
} }
@@ -31,7 +35,7 @@ struct MyGraphicsPhysicsBridge : public GraphicsPhysicsBridge
int graphicsShapeId = shape->getUserIndex(); int graphicsShapeId = shape->getUserIndex();
btAssert(graphicsShapeId >= 0); btAssert(graphicsShapeId >= 0);
btVector3 localScaling = shape->getLocalScaling(); btVector3 localScaling = shape->getLocalScaling();
int graphicsInstanceId = m_glApp->m_instancingRenderer->registerGraphicsInstance(graphicsShapeId, startTransform.getOrigin(), startTransform.getRotation(), color, localScaling); int graphicsInstanceId = m_glApp->m_renderer->registerGraphicsInstance(graphicsShapeId, startTransform.getOrigin(), startTransform.getRotation(), color, localScaling);
body->setUserIndex(graphicsInstanceId); body->setUserIndex(graphicsInstanceId);
} }
virtual void createCollisionShapeGraphicsObject(btCollisionShape* collisionShape) virtual void createCollisionShapeGraphicsObject(btCollisionShape* collisionShape)
@@ -110,7 +114,7 @@ struct MyGraphicsPhysicsBridge : public GraphicsPhysicsBridge
} }
int shapeId = m_glApp->m_instancingRenderer->registerShape(&gvertices[0].pos[0],gvertices.size(),&indices[0],indices.size()); int shapeId = m_glApp->m_renderer->registerShape(&gvertices[0].pos[0],gvertices.size(),&indices[0],indices.size());
convex->setUserIndex(shapeId); convex->setUserIndex(shapeId);
} }
} }
@@ -132,10 +136,10 @@ struct MyGraphicsPhysicsBridge : public GraphicsPhysicsBridge
int index = colObj->getUserIndex(); int index = colObj->getUserIndex();
if (index >= 0) 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();
} }
virtual void createPhysicsDebugDrawer(btDiscreteDynamicsWorld* rbWorld) virtual void createPhysicsDebugDrawer(btDiscreteDynamicsWorld* rbWorld)
@@ -164,7 +168,7 @@ struct MyGraphicsPhysicsBridge : public GraphicsPhysicsBridge
} }
}; };
Bullet2RigidBodyDemo::Bullet2RigidBodyDemo(SimpleOpenGL3App* app, CommonPhysicsSetup* physicsSetup) Bullet2RigidBodyDemo::Bullet2RigidBodyDemo(CommonGraphicsApp* app, CommonPhysicsSetup* physicsSetup)
: m_physicsSetup(physicsSetup), : m_physicsSetup(physicsSetup),
m_controlPressed(false), m_controlPressed(false),
m_altPressed(false), m_altPressed(false),
@@ -177,7 +181,7 @@ void Bullet2RigidBodyDemo::initPhysics()
MyGraphicsPhysicsBridge glBridge(m_glApp); MyGraphicsPhysicsBridge glBridge(m_glApp);
glBridge.setUpAxis(1); glBridge.setUpAxis(1);
m_physicsSetup->initPhysics(glBridge); m_physicsSetup->initPhysics(glBridge);
m_glApp->m_instancingRenderer->writeTransforms(); m_glApp->m_renderer->writeTransforms();
} }
@@ -201,7 +205,7 @@ void Bullet2RigidBodyDemo::renderScene()
MyGraphicsPhysicsBridge glBridge(m_glApp); MyGraphicsPhysicsBridge glBridge(m_glApp);
m_physicsSetup->syncPhysicsToGraphics(glBridge); m_physicsSetup->syncPhysicsToGraphics(glBridge);
m_glApp->m_instancingRenderer->renderScene(); m_glApp->m_renderer->renderScene();
} }
@@ -216,7 +220,7 @@ Bullet2RigidBodyDemo::~Bullet2RigidBodyDemo()
btVector3 Bullet2RigidBodyDemo::getRayTo(int x,int y) btVector3 Bullet2RigidBodyDemo::getRayTo(int x,int y)
{ {
if (!m_glApp->m_instancingRenderer) if (!m_glApp->m_renderer)
{ {
btAssert(0); btAssert(0);
return btVector3(0,0,0); return btVector3(0,0,0);
@@ -229,8 +233,8 @@ btVector3 Bullet2RigidBodyDemo::getRayTo(int x,int y)
float fov = b3Scalar(2.0) * b3Atan(tanFov); float fov = b3Scalar(2.0) * b3Atan(tanFov);
btVector3 camPos,camTarget; btVector3 camPos,camTarget;
m_glApp->m_instancingRenderer->getCameraPosition(camPos); m_glApp->m_renderer->getCameraPosition(camPos);
m_glApp->m_instancingRenderer->getCameraTargetPosition(camTarget); m_glApp->m_renderer->getCameraTargetPosition(camTarget);
btVector3 rayFrom = camPos; btVector3 rayFrom = camPos;
btVector3 rayForward = (camTarget-camPos); btVector3 rayForward = (camTarget-camPos);
@@ -257,8 +261,8 @@ btVector3 Bullet2RigidBodyDemo::getRayTo(int x,int y)
vertical *= 2.f * farPlane * tanfov; vertical *= 2.f * farPlane * tanfov;
b3Scalar aspect; b3Scalar aspect;
float width = m_glApp->m_instancingRenderer->getScreenWidth(); float width = m_glApp->m_renderer->getScreenWidth();
float height = m_glApp->m_instancingRenderer->getScreenHeight(); float height = m_glApp->m_renderer->getScreenHeight();
aspect = width / height; aspect = width / height;
@@ -281,7 +285,7 @@ bool Bullet2RigidBodyDemo::mouseMoveCallback(float x,float y)
{ {
btVector3 rayTo = getRayTo(x, y); btVector3 rayTo = getRayTo(x, y);
btVector3 rayFrom; btVector3 rayFrom;
m_glApp->m_instancingRenderer->getCameraPosition(rayFrom); m_glApp->m_renderer->getCameraPosition(rayFrom);
m_physicsSetup->movePickedBody(rayFrom,rayTo); m_physicsSetup->movePickedBody(rayFrom,rayTo);
return false; return false;
@@ -295,7 +299,7 @@ bool Bullet2RigidBodyDemo::mouseButtonCallback(int button, int state, float x, f
if(button==0 && (!m_altPressed && !m_controlPressed)) if(button==0 && (!m_altPressed && !m_controlPressed))
{ {
btVector3 camPos; btVector3 camPos;
m_glApp->m_instancingRenderer->getCameraPosition(camPos); m_glApp->m_renderer->getCameraPosition(camPos);
btVector3 rayFrom = camPos; btVector3 rayFrom = camPos;
btVector3 rayTo = getRayTo(x,y); btVector3 rayTo = getRayTo(x,y);

View File

@@ -19,9 +19,9 @@ public:
public: public:
struct SimpleOpenGL3App* m_glApp; struct CommonGraphicsApp* m_glApp;
Bullet2RigidBodyDemo(SimpleOpenGL3App* app, CommonPhysicsSetup* physicsSetup); Bullet2RigidBodyDemo(CommonGraphicsApp* app, CommonPhysicsSetup* physicsSetup);
virtual void initPhysics(); virtual void initPhysics();
virtual void exitPhysics(); virtual void exitPhysics();
virtual void renderScene(); virtual void renderScene();

View File

@@ -1,13 +1,13 @@
#ifndef DEMO_INTERFACE_H #ifndef DEMO_INTERFACE_H
#define DEMO_INTERFACE_H #define DEMO_INTERFACE_H
struct SimpleOpenGL3App; struct CommonGraphicsApp;
class BulletDemoInterface class BulletDemoInterface
{ {
public: public:
typedef class BulletDemoInterface* (CreateFunc)(SimpleOpenGL3App* app); typedef class BulletDemoInterface* (CreateFunc)(CommonGraphicsApp* app);
virtual ~BulletDemoInterface() virtual ~BulletDemoInterface()
{ {
@@ -27,7 +27,7 @@ public:
class EmptyBulletDemo : public BulletDemoInterface class EmptyBulletDemo : public BulletDemoInterface
{ {
public: public:
static BulletDemoInterface* MyCreateFunc(SimpleOpenGL3App* app) static BulletDemoInterface* MyCreateFunc(CommonGraphicsApp* app)
{ {
return new EmptyBulletDemo(); return new EmptyBulletDemo();
} }

View File

@@ -3,6 +3,8 @@
#include "LinearMath/btIDebugDraw.h" #include "LinearMath/btIDebugDraw.h"
#include "LinearMath/btAlignedObjectArray.h" #include "LinearMath/btAlignedObjectArray.h"
#include "OpenGLWindow/CommonGraphicsApp.h"
#define BT_LINE_BATCH_SIZE 512 #define BT_LINE_BATCH_SIZE 512
struct MyDebugVec3 struct MyDebugVec3
@@ -20,7 +22,7 @@ struct MyDebugVec3
}; };
class MyDebugDrawer : public btIDebugDraw class MyDebugDrawer : public btIDebugDraw
{ {
SimpleOpenGL3App* m_glApp; CommonGraphicsApp* m_glApp;
int m_debugMode; int m_debugMode;
btAlignedObjectArray<MyDebugVec3> m_linePoints; btAlignedObjectArray<MyDebugVec3> m_linePoints;
@@ -29,7 +31,7 @@ class MyDebugDrawer : public btIDebugDraw
public: public:
MyDebugDrawer(SimpleOpenGL3App* app) MyDebugDrawer(CommonGraphicsApp* app)
: m_glApp(app) : m_glApp(app)
,m_debugMode(btIDebugDraw::DBG_DrawWireframe|btIDebugDraw::DBG_DrawAabb), ,m_debugMode(btIDebugDraw::DBG_DrawWireframe|btIDebugDraw::DBG_DrawAabb),
m_currentLineColor(-1,-1,-1) m_currentLineColor(-1,-1,-1)
@@ -92,7 +94,7 @@ public:
debugColor[1] = m_currentLineColor.y(); debugColor[1] = m_currentLineColor.y();
debugColor[2] = m_currentLineColor.z(); debugColor[2] = m_currentLineColor.z();
debugColor[3] = 1.f; debugColor[3] = 1.f;
m_glApp->m_instancingRenderer->drawLines(&m_linePoints[0].x,debugColor, m_glApp->m_renderer->drawLines(&m_linePoints[0].x,debugColor,
m_linePoints.size(),sizeof(MyDebugVec3), m_linePoints.size(),sizeof(MyDebugVec3),
&m_lineIndices[0], &m_lineIndices[0],
m_lineIndices.size(), m_lineIndices.size(),

View File

@@ -31,11 +31,12 @@
struct GwenInternalData struct GwenInternalData
{ {
struct sth_stash; //struct sth_stash;
class GwenOpenGL3CoreRenderer* pRenderer; //class GwenOpenGL3CoreRenderer* pRenderer;
Gwen::Renderer::Base* pRenderer;
Gwen::Skin::Simple skin; Gwen::Skin::Simple skin;
Gwen::Controls::Canvas* pCanvas; Gwen::Controls::Canvas* pCanvas;
GLPrimitiveRenderer* m_primRenderer; //GLPrimitiveRenderer* m_primRenderer;
Gwen::Controls::TabButton* m_demoPage; Gwen::Controls::TabButton* m_demoPage;
Gwen::Controls::TabButton* m_explorerPage; Gwen::Controls::TabButton* m_explorerPage;
Gwen::Controls::TreeControl* m_explorerTreeCtrl; Gwen::Controls::TreeControl* m_explorerTreeCtrl;

View File

@@ -27,13 +27,10 @@ GwenUserInterface::~GwenUserInterface()
delete m_data->pCanvas; delete m_data->pCanvas;
GLPrimitiveRenderer* prim = m_data->m_primRenderer;
GwenOpenGL3CoreRenderer* coreRend = m_data->pRenderer;
delete m_data; delete m_data;
delete prim;
delete coreRend;
} }
@@ -161,11 +158,11 @@ void GwenUserInterface::registerFileOpenCallback(b3FileOpenCallback callback)
m_data->m_menuItems->m_fileOpenCallback = callback; m_data->m_menuItems->m_fileOpenCallback = callback;
} }
void GwenUserInterface::init(int width, int height,struct sth_stash* stash,float retinaScale) void GwenUserInterface::init(int width, int height,Gwen::Renderer::Base* renderer,float retinaScale)
{ {
m_data->m_curYposition = 20; m_data->m_curYposition = 20;
m_data->m_primRenderer = new GLPrimitiveRenderer(width,height); //m_data->m_primRenderer = new GLPrimitiveRenderer(width,height);
m_data->pRenderer = new GwenOpenGL3CoreRenderer(m_data->m_primRenderer,stash,width,height,retinaScale); m_data->pRenderer = renderer;//new GwenOpenGL3CoreRenderer(m_data->m_primRenderer,stash,width,height,retinaScale);
m_data->skin.SetRender( m_data->pRenderer ); m_data->skin.SetRender( m_data->pRenderer );
@@ -357,7 +354,7 @@ void GwenUserInterface::draw(int width, int height)
if (m_data->pCanvas) if (m_data->pCanvas)
{ {
m_data->pCanvas->SetSize(width,height); m_data->pCanvas->SetSize(width,height);
m_data->m_primRenderer->setScreenSize(width,height); //m_data->m_primRenderer->setScreenSize(width,height);
m_data->pRenderer->Resize(width,height); m_data->pRenderer->Resize(width,height);
m_data->pCanvas->RenderCanvas(); m_data->pCanvas->RenderCanvas();
//restoreOpenGLState(); //restoreOpenGLState();

View File

@@ -7,7 +7,13 @@ typedef void (*b3ComboBoxCallback) (int combobox, const char* item);
typedef void (*b3ToggleButtonCallback)(int button, int state); typedef void (*b3ToggleButtonCallback)(int button, int state);
typedef void (*b3FileOpenCallback)(); typedef void (*b3FileOpenCallback)();
namespace Gwen
{
namespace Renderer
{
class Base;
};
};
class GwenUserInterface class GwenUserInterface
{ {
GwenInternalData* m_data; GwenInternalData* m_data;
@@ -18,7 +24,7 @@ class GwenUserInterface
virtual ~GwenUserInterface(); virtual ~GwenUserInterface();
void init(int width, int height,struct sth_stash* stash,float retinaScale); void init(int width, int height,Gwen::Renderer::Base* gwenRenderer,float retinaScale);
void draw(int width, int height); void draw(int width, int height);

View File

@@ -308,14 +308,14 @@ int main()
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow(); b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
window->setKeyboardCallback(keyCallback); window->setKeyboardCallback(keyCallback);
b3gWindowConstructionInfo wci; b3gWindowConstructionInfo wci;
wci.m_openglVersion = 3; wci.m_openglVersion = 2;
wci.m_width = sWidth; wci.m_width = sWidth;
wci.m_height = sHeight; wci.m_height = sHeight;
// wci.m_resizeCallback = MyResizeCallback; // wci.m_resizeCallback = MyResizeCallback;
window->createWindow(wci); window->createWindow(wci);
window->setResizeCallback(MyResizeCallback); window->setResizeCallback(MyResizeCallback);
window->setWindowTitle("render test");
int majorGlVersion, minorGlVersion; int majorGlVersion, minorGlVersion;
@@ -324,10 +324,20 @@ int main()
printf("Exit: Error cannot extract OpenGL version from GL_VERSION string\n"); printf("Exit: Error cannot extract OpenGL version from GL_VERSION string\n");
exit(0); exit(0);
} }
char title[1024];
if (wci.m_openglVersion>2)
{
sprintf(title,"Gwen with OpenGL %d.%d\n",majorGlVersion,minorGlVersion);
} else
{
sprintf(title,"Gwen with OpenGL %d\n",wci.m_openglVersion);
}
window->setWindowTitle(title);
if (majorGlVersion>=3 && wci.m_openglVersion>=3) if (majorGlVersion>=3 && wci.m_openglVersion>=3)
{ {
float retinaScale = 1.f; float retinaScale = 1.f;
#ifndef __APPLE__ #ifndef __APPLE__
#ifndef _WIN32 #ifndef _WIN32
//we need glewExperimental on Linux //we need glewExperimental on Linux
@@ -360,10 +370,7 @@ int main()
skin.SetRender( gwenRenderer ); skin.SetRender( gwenRenderer );
pCanvas = new Gwen::Controls::Canvas( &skin );
pCanvas->SetSize( sWidth, sHeight);
pCanvas->SetDrawBackground( true );
pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
glClearColor(1,0,0,1); glClearColor(1,0,0,1);

View File

@@ -0,0 +1,51 @@
#ifndef COMMON_GRAPHICS_APP_H
#define COMMON_GRAPHICS_APP_H
struct DrawGridData
{
int gridSize;
float upOffset;
int upAxis;
float gridColor[4];
DrawGridData()
:gridSize(10),
upOffset(0.001f),
upAxis(1)
{
gridColor[0] = 0.6f;
gridColor[1] = 0.6f;
gridColor[2] = 0.6f;
gridColor[3] = 1.f;
}
};
struct CommonGraphicsApp
{
CommonGraphicsApp()
:m_window(0),
m_renderer(0),
m_parameterInterface(0)
{
}
virtual ~CommonGraphicsApp()
{
}
class b3gWindowInterface* m_window;
struct CommonRenderInterface* m_renderer;
struct CommonParameterInterface* m_parameterInterface;
virtual void drawGrid(DrawGridData data=DrawGridData()) = 0;
virtual void setUpAxis(int axis) = 0;
virtual int getUpAxis() const = 0;
virtual void swapBuffer() = 0;
virtual void drawText( const char* txt, int posX, int posY) = 0;
virtual int registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ)=0;
virtual int registerGraphicsSphereShape(float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10)=0;
};
#endif //COMMON_GRAPHICS_APP_H

View File

@@ -0,0 +1,53 @@
#ifndef COMMON_RENDER_INTERFACE_H
#define COMMON_RENDER_INTERFACE_H
enum
{
B3_GL_TRIANGLES = 1,
B3_GL_POINTS
};
enum
{
B3_DEFAULT_RENDERMODE=1,
//B3_WIREFRAME_RENDERMODE,
B3_CREATE_SHADOWMAP_RENDERMODE,
B3_USE_SHADOWMAP_RENDERMODE,
};
struct CommonRenderInterface
{
virtual void init()=0;
virtual void updateCamera(int upAxis)=0;
virtual void removeAllInstances() = 0;
virtual void setCameraDistance(float dist) = 0;
virtual void setCameraPitch(float pitch) = 0;
virtual void setCameraTargetPosition(float x, float y, float z)=0;
virtual void getCameraPosition(float cameraPos[4])=0;
virtual void getCameraPosition(double cameraPos[4])=0;
virtual void setCameraTargetPosition(float cameraPos[4])=0;
virtual void getCameraTargetPosition(float cameraPos[4]) const=0;
virtual void getCameraTargetPosition(double cameraPos[4]) const=0;
virtual void renderScene()=0;
virtual int getScreenWidth() = 0;
virtual int getScreenHeight() = 0;
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)=0;
virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling)=0;
virtual void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize)=0;
virtual void drawLine(const float from[4], const float to[4], const float color[4], float lineWidth) = 0;
virtual void drawLine(const double from[4], const double to[4], const double color[4], double lineWidth) = 0;
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1)=0;
virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)=0;
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)=0;
virtual void writeTransforms()=0;
virtual void enableBlend(bool blend)=0;
};
#endif//COMMON_RENDER_INTERFACE_H

View File

@@ -380,7 +380,8 @@ GLInstancingRenderer::GLInstancingRenderer(int maxNumObjectCapacity, int maxShap
m_textureinitialized(false), m_textureinitialized(false),
m_screenWidth(0), m_screenWidth(0),
m_screenHeight(0), m_screenHeight(0),
m_upAxis(1) m_upAxis(1),
m_enableBlend(false)
{ {
m_data = new InternalDataRenderer; m_data = new InternalDataRenderer;
@@ -951,7 +952,7 @@ void GLInstancingRenderer::init()
} }
void b3CreateFrustum( static void b3CreateFrustum(
float left, float left,
float right, float right,
float bottom, float bottom,
@@ -984,14 +985,14 @@ void b3CreateFrustum(
} }
void b3Matrix4x4Mul(GLfloat aIn[4][4], GLfloat bIn[4][4], GLfloat result[4][4]) static void b3Matrix4x4Mul(GLfloat aIn[4][4], GLfloat bIn[4][4], GLfloat result[4][4])
{ {
for (int j=0;j<4;j++) for (int j=0;j<4;j++)
for (int i=0;i<4;i++) for (int i=0;i<4;i++)
result[j][i] = aIn[0][i] * bIn[j][0] + aIn[1][i] * bIn[j][1] + aIn[2][i] * bIn[j][2] + aIn[3][i] * bIn[j][3]; result[j][i] = aIn[0][i] * bIn[j][0] + aIn[1][i] * bIn[j][1] + aIn[2][i] * bIn[j][2] + aIn[3][i] * bIn[j][3];
} }
void b3Matrix4x4Mul16(GLfloat aIn[16], GLfloat bIn[16], GLfloat result[16]) static void b3Matrix4x4Mul16(GLfloat aIn[16], GLfloat bIn[16], GLfloat result[16])
{ {
for (int j=0;j<4;j++) for (int j=0;j<4;j++)
for (int i=0;i<4;i++) for (int i=0;i<4;i++)
@@ -999,7 +1000,7 @@ void b3Matrix4x4Mul16(GLfloat aIn[16], GLfloat bIn[16], GLfloat result[16])
} }
void b3CreateDiagonalMatrix(GLfloat value, GLfloat result[4][4]) static void b3CreateDiagonalMatrix(GLfloat value, GLfloat result[4][4])
{ {
for (int i=0;i<4;i++) for (int i=0;i<4;i++)
{ {
@@ -1016,7 +1017,7 @@ void b3CreateDiagonalMatrix(GLfloat value, GLfloat result[4][4])
} }
} }
void b3CreateOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar, GLfloat result[4][4]) static void b3CreateOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar, GLfloat result[4][4])
{ {
b3CreateDiagonalMatrix(1.f,result); b3CreateDiagonalMatrix(1.f,result);
@@ -1028,7 +1029,7 @@ void b3CreateOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLf
result[3][2] = - (zFar + zNear) / (zFar - zNear); result[3][2] = - (zFar + zNear) / (zFar - zNear);
} }
void b3CreateLookAt(const b3Vector3& eye, const b3Vector3& center,const b3Vector3& up, GLfloat result[16]) static void b3CreateLookAt(const b3Vector3& eye, const b3Vector3& center,const b3Vector3& up, GLfloat result[16])
{ {
b3Vector3 f = (center - eye).normalized(); b3Vector3 f = (center - eye).normalized();
b3Vector3 u = up.normalized(); b3Vector3 u = up.normalized();
@@ -1172,9 +1173,13 @@ float GLInstancingRenderer::getCameraPitch() const
return m_data->m_azi; return m_data->m_azi;
} }
void GLInstancingRenderer::setCameraTargetPosition(float x, float y, float z)
{
m_data->m_cameraTargetPosition = b3MakeVector3(x,y,z);
}
void GLInstancingRenderer::setCameraTargetPosition(float cameraPos[4]) void GLInstancingRenderer::setCameraTargetPosition(float cameraPos[4])
{ {
m_data->m_cameraTargetPosition = b3MakeVector3(cameraPos[0],cameraPos[1],cameraPos[2]); setCameraTargetPosition(cameraPos[0],cameraPos[1],cameraPos[2]);
} }
void GLInstancingRenderer::getCameraTargetPosition(float cameraPos[4]) const void GLInstancingRenderer::getCameraTargetPosition(float cameraPos[4]) const
@@ -1437,6 +1442,14 @@ void GLInstancingRenderer::drawLines(const float* positions, const float color[4
} }
void GLInstancingRenderer::drawLine(const double fromIn[4], const double toIn[4], const double colorIn[4], double lineWidthIn)
{
float from[4]={float(fromIn[0]),float(fromIn[1]),float(fromIn[2]),float(fromIn[3])};
float to[4]={float(toIn[0]),float(toIn[1]),float(toIn[2]),float(toIn[3])};
float color[4]={float(colorIn[0]),float(colorIn[1]),float(colorIn[2]),float(colorIn[3])};
float lineWidth=float(lineWidthIn);
drawLine(from,to,color,lineWidth);
}
void GLInstancingRenderer::drawLine(const float from[4], const float to[4], const float color[4], float lineWidth) void GLInstancingRenderer::drawLine(const float from[4], const float to[4], const float color[4], float lineWidth)
{ {
b3Assert(glGetError() ==GL_NO_ERROR); b3Assert(glGetError() ==GL_NO_ERROR);
@@ -1589,14 +1602,14 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
// m_data->m_shadowMap->disable(); // m_data->m_shadowMap->disable();
// return; // return;
// glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
// glCullFace(GL_BACK); // Cull back-facing triangles -> draw only front-facing triangles glCullFace(GL_BACK); // Cull back-facing triangles -> draw only front-facing triangles
b3Assert(glGetError() ==GL_NO_ERROR); b3Assert(glGetError() ==GL_NO_ERROR);
} else } else
{ {
glDisable(GL_CULL_FACE); //glDisable(GL_CULL_FACE);
//glCullFace(GL_BACK); glCullFace(GL_BACK);
} }
@@ -1747,7 +1760,7 @@ b3Assert(glGetError() ==GL_NO_ERROR);
glUseProgram(instancingShaderPointSprite); glUseProgram(instancingShaderPointSprite);
glUniformMatrix4fv(ProjectionMatrixPointSprite, 1, false, &projectionMatrix[0]); glUniformMatrix4fv(ProjectionMatrixPointSprite, 1, false, &projectionMatrix[0]);
glUniformMatrix4fv(ModelViewMatrixPointSprite, 1, false, &modelviewMatrix[0]); glUniformMatrix4fv(ModelViewMatrixPointSprite, 1, false, &modelviewMatrix[0]);
glUniform1f(screenWidthPointSprite,m_screenWidth); glUniform1f(screenWidthPointSprite,float(m_screenWidth));
//glUniform1i(uniform_texture_diffusePointSprite, 0); //glUniform1i(uniform_texture_diffusePointSprite, 0);
b3Assert(glGetError() ==GL_NO_ERROR); b3Assert(glGetError() ==GL_NO_ERROR);
@@ -1790,6 +1803,12 @@ b3Assert(glGetError() ==GL_NO_ERROR);
case B3_USE_SHADOWMAP_RENDERMODE: case B3_USE_SHADOWMAP_RENDERMODE:
{ {
if (m_enableBlend)
{
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
glUseProgram(useShadowMapInstancingShader); glUseProgram(useShadowMapInstancingShader);
glUniformMatrix4fv(useShadow_ProjectionMatrix, 1, false, &projectionMatrix[0]); glUniformMatrix4fv(useShadow_ProjectionMatrix, 1, false, &projectionMatrix[0]);
glUniformMatrix4fv(useShadow_ModelViewMatrix, 1, false, &modelviewMatrix[0]); glUniformMatrix4fv(useShadow_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
@@ -1804,7 +1823,12 @@ b3Assert(glGetError() ==GL_NO_ERROR);
glBindTexture(GL_TEXTURE_2D, m_data->m_shadowTexture); glBindTexture(GL_TEXTURE_2D, m_data->m_shadowTexture);
glUniform1i(useShadow_shadowMap,1); glUniform1i(useShadow_shadowMap,1);
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances); glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
break; if (m_enableBlend)
{
glDisable (GL_BLEND);
}
break;
} }
default: default:
{ {

View File

@@ -17,6 +17,7 @@ subject to the following restrictions:
#define GL_INSTANCING_RENDERER_H #define GL_INSTANCING_RENDERER_H
#include "Bullet3Common/b3AlignedObjectArray.h" #include "Bullet3Common/b3AlignedObjectArray.h"
#include "OpenGLWindow/CommonRenderInterface.h"
void b3DefaultMouseButtonCallback( int button, int state, float x, float y); void b3DefaultMouseButtonCallback( int button, int state, float x, float y);
@@ -24,21 +25,9 @@ void b3DefaultMouseMoveCallback( float x, float y);
void b3DefaultKeyboardCallback(int key, int state); void b3DefaultKeyboardCallback(int key, int state);
void b3DefaultWheelCallback( float deltax, float deltay); void b3DefaultWheelCallback( float deltax, float deltay);
enum
{
B3_GL_TRIANGLES = 1,
B3_GL_POINTS
};
enum
{
B3_DEFAULT_RENDERMODE=1,
//B3_WIREFRAME_RENDERMODE,
B3_CREATE_SHADOWMAP_RENDERMODE,
B3_USE_SHADOWMAP_RENDERMODE,
};
class GLInstancingRenderer class GLInstancingRenderer : public CommonRenderInterface
{ {
b3AlignedObjectArray<struct b3GraphicsInstance*> m_graphicsInstances; b3AlignedObjectArray<struct b3GraphicsInstance*> m_graphicsInstances;
@@ -54,7 +43,8 @@ class GLInstancingRenderer
int m_screenHeight; int m_screenHeight;
int m_upAxis; int m_upAxis;
bool m_enableBlend;
void renderSceneInternal(int renderMode=B3_DEFAULT_RENDERMODE); void renderSceneInternal(int renderMode=B3_DEFAULT_RENDERMODE);
@@ -62,29 +52,29 @@ public:
GLInstancingRenderer(int m_maxObjectCapacity, int maxShapeCapacityInBytes = 56*1024*1024); GLInstancingRenderer(int m_maxObjectCapacity, int maxShapeCapacityInBytes = 56*1024*1024);
virtual ~GLInstancingRenderer(); virtual ~GLInstancingRenderer();
void init(); virtual void init();
void renderScene(); virtual void renderScene();
void InitShaders(); void InitShaders();
void CleanupShaders(); void CleanupShaders();
void removeAllInstances(); void removeAllInstances();
void updateShape(int shapeIndex, const float* vertices); virtual void updateShape(int shapeIndex, const float* vertices);
///vertices must be in the format x,y,z, nx,ny,nz, u,v ///vertices must be in the format x,y,z, nx,ny,nz, u,v
int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1); virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1);
int registerTexture(const unsigned char* texels, int width, int height); virtual int registerTexture(const unsigned char* texels, int width, int height);
///position x,y,z, quaternion x,y,z,w, color r,g,b,a, scaling x,y,z ///position x,y,z, quaternion x,y,z,w, color r,g,b,a, scaling x,y,z
int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling); virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);
int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling); virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling);
void writeTransforms(); void writeTransforms();
void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex); virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex);
void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex) virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)
{ {
float pos[4]; float pos[4];
float orn[4]; float orn[4];
@@ -100,22 +90,23 @@ public:
} }
void writeSingleInstanceTransformToGPU(float* position, float* orientation, int srcIndex); virtual void writeSingleInstanceTransformToGPU(float* position, float* orientation, int srcIndex);
void writeSingleInstanceColorToCPU(float* color, int srcIndex); virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex);
void getMouseDirection(float* dir, int mouseX, int mouseY); virtual void getMouseDirection(float* dir, int mouseX, int mouseY);
struct GLInstanceRendererInternalData* getInternalData(); struct GLInstanceRendererInternalData* getInternalData();
void drawLine(const float from[4], const float to[4], const float color[4], float lineWidth=1); virtual void drawLine(const float from[4], const float to[4], const float color[4], float lineWidth=1);
void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize); virtual void drawLine(const double from[4], const double to[4], const double color[4], double lineWidth=1);
void drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize); virtual void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize);
void drawPoint(const float* position, const float color[4], float pointSize=1); virtual void drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize);
void updateCamera(int upAxis=1); virtual void drawPoint(const float* position, const float color[4], float pointSize=1);
virtual void updateCamera(int upAxis=1);
void getCameraPosition(float cameraPos[4]); virtual void getCameraPosition(float cameraPos[4]);
void getCameraPosition(double cameraPos[4]) virtual void getCameraPosition(double cameraPos[4])
{ {
float campos[4]; float campos[4];
getCameraPosition(campos); getCameraPosition(campos);
@@ -125,13 +116,14 @@ public:
cameraPos[3] = campos[3]; cameraPos[3] = campos[3];
} }
void setCameraDistance(float dist); virtual void setCameraDistance(float dist);
float getCameraDistance() const; virtual float getCameraDistance() const;
//set the camera 'target' //set the camera 'target'
void setCameraTargetPosition(float cameraPos[4]); virtual void setCameraTargetPosition(float x, float y, float z);
void getCameraTargetPosition(float cameraPos[4]) const; virtual void setCameraTargetPosition(float cameraPos[4]);
void getCameraTargetPosition(double cameraPos[4]) const virtual void getCameraTargetPosition(float cameraPos[4]) const;
virtual void getCameraTargetPosition(double cameraPos[4]) const
{ {
float campos[4]; float campos[4];
getCameraTargetPosition(campos); getCameraTargetPosition(campos);
@@ -142,30 +134,34 @@ public:
} }
void setCameraYaw(float yaw); virtual void setCameraYaw(float yaw);
void setCameraPitch(float pitch); virtual void setCameraPitch(float pitch);
float getCameraYaw() const; virtual float getCameraYaw() const;
float getCameraPitch() const; virtual float getCameraPitch() const;
void resize(int width, int height); virtual void resize(int width, int height);
int getScreenWidth() virtual int getScreenWidth()
{ {
return m_screenWidth; return m_screenWidth;
} }
int getScreenHeight() virtual int getScreenHeight()
{ {
return m_screenHeight; return m_screenHeight;
} }
int getMaxShapeCapacity() const virtual int getMaxShapeCapacity() const
{ {
return m_maxShapeCapacityInBytes; return m_maxShapeCapacityInBytes;
} }
int getInstanceCapacity() const virtual int getInstanceCapacity() const
{ {
return m_maxNumObjectCapacity; return m_maxNumObjectCapacity;
} }
void enableShadowMap(); virtual void enableShadowMap();
virtual void enableBlend(bool blend)
{
m_enableBlend = blend;
}
}; };

View File

@@ -1,7 +1,7 @@
#ifndef _GL_PRIMITIVE_RENDERER_H #ifndef _GL_PRIMITIVE_RENDERER_H
#define _GL_PRIMITIVE_RENDERER_H #define _GL_PRIMITIVE_RENDERER_H
#include "OpenGLInclude.h" //#include "OpenGLInclude.h"
class GLPrimitiveRenderer class GLPrimitiveRenderer
{ {

View File

@@ -5,6 +5,8 @@
#include "Gwen/Gwen.h" #include "Gwen/Gwen.h"
#include "Gwen/BaseRender.h" #include "Gwen/BaseRender.h"
#include "GLPrimitiveRenderer.h" #include "GLPrimitiveRenderer.h"
#include "OpenGLWindow/OpenGLInclude.h"
struct sth_stash; struct sth_stash;
#include "fontstash.h" #include "fontstash.h"
#include "Gwen/Texture.h" #include "Gwen/Texture.h"
@@ -74,14 +76,14 @@ class GwenOpenGL3CoreRenderer : public Gwen::Renderer::Base
GLuint m_fontTextureId; GLuint m_fontTextureId;
MyTextureLoader* m_textureLoader; MyTextureLoader* m_textureLoader;
public: public:
GwenOpenGL3CoreRenderer (GLPrimitiveRenderer* primRender, sth_stash* font,float screenWidth, float screenHeight, float retinaScale) GwenOpenGL3CoreRenderer (GLPrimitiveRenderer* primRender, sth_stash* font,float screenWidth, float screenHeight, float retinaScale, MyTextureLoader* loader=0)
:m_primitiveRenderer(primRender), :m_primitiveRenderer(primRender),
m_font(font), m_font(font),
m_screenWidth(screenWidth), m_screenWidth(screenWidth),
m_screenHeight(screenHeight), m_screenHeight(screenHeight),
m_retinaScale(retinaScale), m_retinaScale(retinaScale),
m_useTrueTypeFont(false), m_useTrueTypeFont(false),
m_textureLoader(0) m_textureLoader(loader)
{ {
///only enable true type fonts on Macbook Retina, it looks gorgeous ///only enable true type fonts on Macbook Retina, it looks gorgeous
if (retinaScale==2.0f) if (retinaScale==2.0f)
@@ -323,10 +325,6 @@ public:
return Gwen::Renderer::Base::MeasureText(pFont,text); return Gwen::Renderer::Base::MeasureText(pFont,text);
} }
void setTextureLoader(MyTextureLoader* loader)
{
m_textureLoader = loader;
}
virtual void LoadTexture( Gwen::Texture* pTexture ) virtual void LoadTexture( Gwen::Texture* pTexture )
{ {

View File

@@ -56,10 +56,25 @@ public:
{ {
m_keyboardCallback = keyboardCallback; m_keyboardCallback = keyboardCallback;
} }
virtual b3MouseMoveCallback getMouseMoveCallback()
{
return m_mouseMoveCallback;
}
virtual b3MouseButtonCallback getMouseButtonCallback()
{
return m_mouseButtonCallback;
}
virtual b3ResizeCallback getResizeCallback();
virtual b3WheelCallback getWheelCallback()
{
return m_wheelCallback;
}
b3KeyboardCallback getKeyboardCallback() b3KeyboardCallback getKeyboardCallback()
{ {
return m_keyboardCallback; return m_keyboardCallback;
} }
void setWheelCallback (b3WheelCallback wheelCallback) void setWheelCallback (b3WheelCallback wheelCallback)
{ {

View File

@@ -53,6 +53,7 @@ void dumpInfo(void)
-(float) GetWindowWidth; -(float) GetWindowWidth;
-(float) GetWindowHeight; -(float) GetWindowHeight;
-(void) setResizeCallback:(b3ResizeCallback) callback; -(void) setResizeCallback:(b3ResizeCallback) callback;
-(b3ResizeCallback) getResizeCallback;
@end @end
float loop; float loop;
@@ -70,6 +71,11 @@ float loop;
return m_lastHeight; return m_lastHeight;
} }
-(b3ResizeCallback) getResizeCallback
{
return m_resizeCallback;
}
-(void)setResizeCallback:(b3ResizeCallback)callback -(void)setResizeCallback:(b3ResizeCallback)callback
{ {
m_resizeCallback = callback; m_resizeCallback = callback;
@@ -1057,4 +1063,7 @@ void MacOpenGLWindow::setResizeCallback(b3ResizeCallback resizeCallback)
} }
} }
b3ResizeCallback MacOpenGLWindow::getResizeCallback()
{
return [m_internalData->m_myview getResizeCallback];
}

View File

@@ -52,5 +52,5 @@ void main(void)
if (visibility<0.6) if (visibility<0.6)
visibility=0.6f; visibility=0.6f;
color = vec4(ct * visibility, 1.f);//at * af); color = vec4(ct * visibility, fragment.color.w);
} }

View File

@@ -44,6 +44,6 @@ static const char* useShadowMapInstancingFragmentShader= \
" if (visibility<0.6)\n" " if (visibility<0.6)\n"
" visibility=0.6f;\n" " visibility=0.6f;\n"
" \n" " \n"
" color = vec4(ct * visibility, 1.f);//at * af); \n" " color = vec4(ct * visibility, fragment.color.w);\n"
"}\n" "}\n"
; ;

View File

@@ -0,0 +1,260 @@
#include "OpenGLWindow/SimpleCamera.h"
#include "Bullet3Common/b3Vector3.h"
#include "Bullet3Common/b3Quaternion.h"
#include "Bullet3Common/b3Matrix3x3.h"
struct SimpleCameraInternalData
{
SimpleCameraInternalData()
:m_cameraTargetPosition(b3MakeVector3(0,0,0)),
m_cameraDistance(20),
m_cameraUp(b3MakeVector3(0,1,0)),
m_cameraUpAxis(1),
m_cameraForward(b3MakeVector3(1,0,0)),
m_frustumZNear(1),
m_frustumZFar(10000),
m_yaw(20),
m_pitch(0),
m_aspect(1)
{
}
b3Vector3 m_cameraTargetPosition;
float m_cameraDistance;
b3Vector3 m_cameraUp;
b3Vector3 m_cameraForward;
int m_cameraUpAxis;
//the m_cameraPosition is a cached value, recomputed from other values
b3Vector3 m_cameraPosition;
float m_yaw;
float m_pitch;
float m_aspect;
float m_frustumZNear;
float m_frustumZFar;
};
SimpleCamera::SimpleCamera()
{
m_data = new SimpleCameraInternalData;
}
SimpleCamera::~SimpleCamera()
{
delete m_data;
}
static void b3CreateFrustum(
float left,
float right,
float bottom,
float top,
float nearVal,
float farVal,
float frustum[16])
{
frustum[0*4+0] = (float(2) * nearVal) / (right - left);
frustum[0*4+1] = float(0);
frustum[0*4+2] = float(0);
frustum[0*4+3] = float(0);
frustum[1*4+0] = float(0);
frustum[1*4+1] = (float(2) * nearVal) / (top - bottom);
frustum[1*4+2] = float(0);
frustum[1*4+3] = float(0);
frustum[2*4+0] = (right + left) / (right - left);
frustum[2*4+1] = (top + bottom) / (top - bottom);
frustum[2*4+2] = -(farVal + nearVal) / (farVal - nearVal);
frustum[2*4+3] = float(-1);
frustum[3*4+0] = float(0);
frustum[3*4+1] = float(0);
frustum[3*4+2] = -(float(2) * farVal * nearVal) / (farVal - nearVal);
frustum[3*4+3] = float(0);
}
static void b3CreateDiagonalMatrix(float value, float result[4][4])
{
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
{
if (i==j)
{
result[i][j] = value;
} else
{
result[i][j] = 0.f;
}
}
}
}
static void b3CreateOrtho(float left, float right, float bottom, float top, float zNear, float zFar, float result[4][4])
{
b3CreateDiagonalMatrix(1.f,result);
result[0][0] = 2.f / (right - left);
result[1][1] = 2.f / (top - bottom);
result[2][2] = - 2.f / (zFar - zNear);
result[3][0] = - (right + left) / (right - left);
result[3][1] = - (top + bottom) / (top - bottom);
result[3][2] = - (zFar + zNear) / (zFar - zNear);
}
static void b3CreateLookAt(const b3Vector3& eye, const b3Vector3& center,const b3Vector3& up, float result[16])
{
b3Vector3 f = (center - eye).normalized();
b3Vector3 u = up.normalized();
b3Vector3 s = (f.cross(u)).normalized();
u = s.cross(f);
result[0*4+0] = s.x;
result[1*4+0] = s.y;
result[2*4+0] = s.z;
result[0*4+1] = u.x;
result[1*4+1] = u.y;
result[2*4+1] = u.z;
result[0*4+2] =-f.x;
result[1*4+2] =-f.y;
result[2*4+2] =-f.z;
result[0*4+3] = 0.f;
result[1*4+3] = 0.f;
result[2*4+3] = 0.f;
result[3*4+0] = -s.dot(eye);
result[3*4+1] = -u.dot(eye);
result[3*4+2] = f.dot(eye);
result[3*4+3] = 1.f;
}
void SimpleCamera::setCameraUpAxis(int upAxis)
{
m_data->m_cameraUpAxis = upAxis;
update();
}
void SimpleCamera::update()
{
int forwardAxis(-1);
switch (m_data->m_cameraUpAxis)
{
case 1:
forwardAxis = 2;
m_data->m_cameraUp = b3MakeVector3(0,1,0);
//gLightPos = b3MakeVector3(-50.f,100,30);
break;
case 2:
forwardAxis = 1;
m_data->m_cameraUp = b3MakeVector3(0,0,1);
//gLightPos = b3MakeVector3(-50.f,30,100);
break;
default:
{
b3Assert(0);
return;
}
};
b3Vector3 eyePos = b3MakeVector3(0,0,0);
eyePos[forwardAxis] = -m_data->m_cameraDistance;
m_data->m_cameraForward = b3MakeVector3(eyePos[0],eyePos[1],eyePos[2]);
if (m_data->m_cameraForward.length2() < B3_EPSILON)
{
m_data->m_cameraForward.setValue(1.f,0.f,0.f);
} else
{
m_data->m_cameraForward.normalize();
}
// m_azi=m_azi+0.01;
b3Scalar rele = m_data->m_yaw * b3Scalar(0.01745329251994329547);// rads per deg
b3Scalar razi = m_data->m_pitch * b3Scalar(0.01745329251994329547);// rads per deg
b3Quaternion rot(m_data->m_cameraUp,razi);
b3Vector3 right = m_data->m_cameraUp.cross(m_data->m_cameraForward);
b3Quaternion roll(right,-rele);
eyePos = b3Matrix3x3(rot) * b3Matrix3x3(roll) * eyePos;
m_data->m_cameraPosition = eyePos;
m_data->m_cameraPosition+= m_data->m_cameraTargetPosition;
}
void SimpleCamera::getCameraProjectionMatrix(float projectionMatrix[16]) const
{
b3CreateFrustum(-m_data->m_aspect * m_data->m_frustumZNear, m_data->m_aspect * m_data->m_frustumZNear, -m_data->m_frustumZNear,m_data->m_frustumZNear, m_data->m_frustumZNear, m_data->m_frustumZFar,projectionMatrix);
}
void SimpleCamera::getCameraViewMatrix(float viewMatrix[16]) const
{
b3CreateLookAt(m_data->m_cameraPosition,m_data->m_cameraTargetPosition,m_data->m_cameraUp,viewMatrix);
}
void SimpleCamera::getCameraTargetPosition(float pos[3]) const
{
pos[0] =m_data->m_cameraTargetPosition[0];
pos[1] =m_data->m_cameraTargetPosition[1];
pos[2] =m_data->m_cameraTargetPosition[2];
}
void SimpleCamera::getCameraPosition(float pos[3]) const
{
pos[0] =m_data->m_cameraPosition[0];
pos[1] =m_data->m_cameraPosition[1];
pos[2] =m_data->m_cameraPosition[2];
}
void SimpleCamera::setCameraTargetPosition(float x,float y,float z)
{
m_data->m_cameraTargetPosition.setValue(x,y,z);
update();
}
void SimpleCamera::setCameraDistance(float dist)
{
m_data->m_cameraDistance = dist;
update();
}
void SimpleCamera::setCameraUpVector(float x,float y ,float z)
{
m_data->m_cameraUp.setValue(x,y,z);
update();
}
void SimpleCamera::setCameraYaw(float yaw)
{
m_data->m_yaw = yaw;
update();
}
void SimpleCamera::setCameraPitch(float pitch)
{
m_data->m_pitch = pitch;
update();
}
void SimpleCamera::setAspectRatio(float ratio)
{
m_data->m_aspect = ratio;
update();
}

View File

@@ -0,0 +1,36 @@
#ifndef SIMPLE_CAMERA_H
#define SIMPLE_CAMERA_H
struct CommonCameraInterface
{
virtual void getCameraProjectionMatrix(float m[16])const = 0;
virtual void getCameraViewMatrix(float m[16]) const = 0;
};
struct SimpleCamera : public CommonCameraInterface
{
struct SimpleCameraInternalData* m_data;
SimpleCamera();
virtual ~SimpleCamera();
void update();
virtual void getCameraProjectionMatrix(float m[16]) const;
virtual void getCameraViewMatrix(float m[16]) const;
virtual void getCameraTargetPosition(float pos[3]) const;
virtual void getCameraPosition(float pos[3]) const;
virtual void setCameraTargetPosition(float x,float y,float z);
virtual void setCameraDistance(float dist);
virtual void setCameraUpVector(float x,float y, float z);
///the setCameraUpAxis will call the 'setCameraUpVector' and 'setCameraForwardVector'
virtual void setCameraUpAxis(int axis);
virtual void setCameraYaw(float yaw);
virtual void setCameraPitch(float pitch);
virtual void setAspectRatio(float ratio);
};
#endif //SIMPLE_CAMERA_H

View File

@@ -0,0 +1,196 @@
#include "OpenGLWindow/SimpleOpenGL2App.h"
#include "OpenGLWindow/OpenGLInclude.h"
#include "Bullet3Common/b3Logging.h"//b3Assert?
#include "Bullet3Common/b3Scalar.h"
#include "Bullet3Common/b3AlignedObjectArray.h"
#include "Bullet3Common/b3Vector3.h"
#include "stdlib.h"
#ifdef __APPLE__
#include "OpenGLWindow/MacOpenGLWindow.h"
#else
#include "OpenGLWindow/GlewWindows/GL/glew.h"
//#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 <stdio.h>
#include "OpenGLWindow/CommonRenderInterface.h"
struct SimpleOpenGL2AppInternalData
{
};
SimpleOpenGL2App::SimpleOpenGL2App(const char* title, int width, int height)
{
m_data = new SimpleOpenGL2AppInternalData;
m_window = new b3gDefaultOpenGLWindow();
b3gWindowConstructionInfo ci;
ci.m_title = title;
ci.m_openglVersion = 2;
ci.m_width = width;
ci.m_height = height;
m_window->createWindow(ci);
m_window->setWindowTitle(title);
#ifndef __APPLE__
#ifndef _WIN32
//some Linux implementations need the 'glewExperimental' to be true
glewExperimental = GL_TRUE;
#endif
if (glewInit() != GLEW_OK)
{
b3Error("glewInit failed");
exit(1);
}
if (!GLEW_VERSION_2_1) // check that the machine supports the 2.1 API.
{
b3Error("GLEW_VERSION_2_1 needs to support 2_1");
exit(1); // or handle the error in a nicer way
}
#endif
glGetError();//don't remove this call, it is needed for Ubuntu
glClearColor(0.9,0.9,1,1);
b3Assert(glGetError() ==GL_NO_ERROR);
//m_primRenderer = new GLPrimitiveRenderer(width,height);
m_parameterInterface = 0;
b3Assert(glGetError() ==GL_NO_ERROR);
//m_instancingRenderer = new GLInstancingRenderer(128*1024,32*1024*1024);
//m_instancingRenderer->init();
//m_instancingRenderer->resize(width,height);
b3Assert(glGetError() ==GL_NO_ERROR);
//m_instancingRenderer->InitShaders();
}
SimpleOpenGL2App::~SimpleOpenGL2App()
{
delete m_data;
}
void SimpleOpenGL2App::drawGrid(DrawGridData data)
{
int gridSize = data.gridSize;
float upOffset = data.upOffset;
int upAxis = data.upAxis;
float gridColor[4];
gridColor[0] = data.gridColor[0];
gridColor[1] = data.gridColor[1];
gridColor[2] = data.gridColor[2];
gridColor[3] = data.gridColor[3];
int sideAxis=-1;
int forwardAxis=-1;
switch (upAxis)
{
case 1:
forwardAxis=2;
sideAxis=0;
break;
case 2:
forwardAxis=1;
sideAxis=0;
break;
default:
b3Assert(0);
};
//b3Vector3 gridColor = b3MakeVector3(0.5,0.5,0.5);
b3AlignedObjectArray<unsigned int> indices;
b3AlignedObjectArray<b3Vector3> vertices;
int lineIndex=0;
for(int i=-gridSize;i<=gridSize;i++)
{
{
b3Assert(glGetError() ==GL_NO_ERROR);
b3Vector3 from = b3MakeVector3(0,0,0);
from[sideAxis] = float(i);
from[upAxis] = upOffset;
from[forwardAxis] = float(-gridSize);
b3Vector3 to=b3MakeVector3(0,0,0);
to[sideAxis] = float(i);
to[upAxis] = upOffset;
to[forwardAxis] = float(gridSize);
vertices.push_back(from);
indices.push_back(lineIndex++);
vertices.push_back(to);
indices.push_back(lineIndex++);
// m_renderer->drawLine(from,to,gridColor);
}
b3Assert(glGetError() ==GL_NO_ERROR);
{
b3Assert(glGetError() ==GL_NO_ERROR);
b3Vector3 from=b3MakeVector3(0,0,0);
from[sideAxis] = float(-gridSize);
from[upAxis] = upOffset;
from[forwardAxis] = float(i);
b3Vector3 to=b3MakeVector3(0,0,0);
to[sideAxis] = float(gridSize);
to[upAxis] = upOffset;
to[forwardAxis] = float(i);
vertices.push_back(from);
indices.push_back(lineIndex++);
vertices.push_back(to);
indices.push_back(lineIndex++);
// m_renderer->drawLine(from,to,gridColor);
}
}
m_renderer->drawLines(&vertices[0].x,
gridColor,
vertices.size(),sizeof(b3Vector3),&indices[0],indices.size(),1);
m_renderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(1,0,0),b3MakeVector3(1,0,0),3);
m_renderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,1,0),b3MakeVector3(0,1,0),3);
m_renderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,0,1),b3MakeVector3(0,0,1),3);
// void GLInstancingRenderer::drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize)
//we don't use drawPoints because all points would have the same color
// b3Vector3 points[3] = { b3MakeVector3(1, 0, 0), b3MakeVector3(0, 1, 0), b3MakeVector3(0, 0, 1) };
// m_instancingRenderer->drawPoints(&points[0].x, b3MakeVector3(1, 0, 0), 3, sizeof(b3Vector3), 6);
}
void SimpleOpenGL2App::setUpAxis(int axis)
{
}
int SimpleOpenGL2App::getUpAxis() const
{
return 1;
}
void SimpleOpenGL2App::swapBuffer()
{
m_window->endRendering();
m_window->startRendering();
}
void SimpleOpenGL2App::drawText( const char* txt, int posX, int posY)
{
}

View File

@@ -0,0 +1,31 @@
#ifndef SIMPLE_OPENGL2_APP_H
#define SIMPLE_OPENGL2_APP_H
#include "OpenGLWindow/CommonGraphicsApp.h"
class SimpleOpenGL2App : public CommonGraphicsApp
{
protected:
struct SimpleOpenGL2AppInternalData* m_data;
public:
SimpleOpenGL2App(const char* title, int width, int height);
virtual ~SimpleOpenGL2App();
virtual void drawGrid(DrawGridData data=DrawGridData());
virtual void setUpAxis(int axis);
virtual int getUpAxis() const;
virtual void swapBuffer();
virtual void drawText( const char* txt, int posX, int posY);
virtual int registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ)
{
return 0;
}
virtual int registerGraphicsSphereShape(float radius, bool usePointSprites, int largeSphereThreshold, int mediumSphereThreshold)
{
return 0;
}
};
#endif //SIMPLE_OPENGL2_APP_H

View File

@@ -140,6 +140,7 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
b3Assert(glGetError() ==GL_NO_ERROR); b3Assert(glGetError() ==GL_NO_ERROR);
m_instancingRenderer = new GLInstancingRenderer(128*1024,32*1024*1024); m_instancingRenderer = new GLInstancingRenderer(128*1024,32*1024*1024);
m_renderer = m_instancingRenderer ;
m_instancingRenderer->init(); m_instancingRenderer->init();
m_instancingRenderer->resize(width,height); m_instancingRenderer->resize(width,height);

View File

@@ -5,33 +5,16 @@
#include "OpenGLWindow/GLPrimitiveRenderer.h" #include "OpenGLWindow/GLPrimitiveRenderer.h"
#include "OpenGLWindow/b3gWindowInterface.h" #include "OpenGLWindow/b3gWindowInterface.h"
struct DrawGridData #include "OpenGLWindow/CommonGraphicsApp.h"
{
int gridSize;
float upOffset;
int upAxis;
float gridColor[4];
DrawGridData()
:gridSize(10),
upOffset(0.001f),
upAxis(1)
{
gridColor[0] = 0.6f;
gridColor[1] = 0.6f;
gridColor[2] = 0.6f;
gridColor[3] = 1.f;
}
};
struct SimpleOpenGL3App struct SimpleOpenGL3App : public CommonGraphicsApp
{ {
struct SimpleInternalData* m_data; struct SimpleInternalData* m_data;
class b3gWindowInterface* m_window;
class GLPrimitiveRenderer* m_primRenderer; class GLPrimitiveRenderer* m_primRenderer;
class GLInstancingRenderer* m_instancingRenderer; class GLInstancingRenderer* m_instancingRenderer;
struct CommonParameterInterface* m_parameterInterface;
SimpleOpenGL3App(const char* title, int width,int height); SimpleOpenGL3App(const char* title, int width,int height);
virtual ~SimpleOpenGL3App(); virtual ~SimpleOpenGL3App();
@@ -43,11 +26,11 @@ struct SimpleOpenGL3App
void dumpFramesToVideo(const char* mp4Filename); void dumpFramesToVideo(const char* mp4Filename);
void drawGrid(DrawGridData data=DrawGridData()); void drawGrid(DrawGridData data=DrawGridData());
void setUpAxis(int axis); virtual void setUpAxis(int axis);
int getUpAxis() const; virtual int getUpAxis() const;
void swapBuffer(); virtual void swapBuffer();
void drawText( const char* txt, int posX, int posY); virtual void drawText( const char* txt, int posX, int posY);
struct sth_stash* getFontStash(); struct sth_stash* getFontStash();

View File

@@ -46,8 +46,13 @@ void Win32OpenGLWindow::enableOpenGL()
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA; pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32; pfd.cColorBits = 32;
pfd.cDepthBits = 16; pfd.cRedBits = 8;
pfd.cStencilBits = 1; pfd.cGreenBits = 8;
pfd.cBlueBits = 8;
pfd.cAlphaBits = 8;
pfd.cDepthBits = 24;
pfd.cStencilBits = 8;//1;
pfd.iLayerType = PFD_MAIN_PLANE; pfd.iLayerType = PFD_MAIN_PLANE;
format = ChoosePixelFormat( m_data->m_hDC, &pfd ); format = ChoosePixelFormat( m_data->m_hDC, &pfd );
SetPixelFormat( m_data->m_hDC, format, &pfd ); SetPixelFormat( m_data->m_hDC, format, &pfd );
@@ -115,15 +120,15 @@ void Win32OpenGLWindow::closeWindow()
void Win32OpenGLWindow::startRendering() void Win32OpenGLWindow::startRendering()
{ {
pumpMessage(); pumpMessage();
//don't clear all 3 buffers because some AMD drivers are buggy
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //clear buffers //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glCullFace(GL_BACK); //glCullFace(GL_BACK);
//glFrontFace(GL_CCW); //glFrontFace(GL_CCW);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
} }

View File

@@ -709,5 +709,21 @@ b3KeyboardCallback Win32Window::getKeyboardCallback()
return m_data->m_keyboardCallback; return m_data->m_keyboardCallback;
} }
b3MouseMoveCallback Win32Window::getMouseMoveCallback()
{
return m_data->m_mouseMoveCallback;
}
b3MouseButtonCallback Win32Window::getMouseButtonCallback()
{
return m_data->m_mouseButtonCallback;
}
b3ResizeCallback Win32Window::getResizeCallback()
{
return m_data->m_resizeCallback;
}
b3WheelCallback Win32Window::getWheelCallback()
{
return m_data->m_wheelCallback;
}

View File

@@ -69,7 +69,11 @@ public:
virtual void setResizeCallback(b3ResizeCallback resizeCallback); virtual void setResizeCallback(b3ResizeCallback resizeCallback);
virtual void setWheelCallback(b3WheelCallback wheelCallback); virtual void setWheelCallback(b3WheelCallback wheelCallback);
virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback); virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback);
virtual b3MouseMoveCallback getMouseMoveCallback();
virtual b3MouseButtonCallback getMouseButtonCallback();
virtual b3ResizeCallback getResizeCallback();
virtual b3WheelCallback getWheelCallback();
virtual b3KeyboardCallback getKeyboardCallback(); virtual b3KeyboardCallback getKeyboardCallback();
virtual void setRenderCallback( b3RenderCallback renderCallback); virtual void setRenderCallback( b3RenderCallback renderCallback);

View File

@@ -964,10 +964,29 @@ void X11OpenGLWindow::setKeyboardCallback( b3KeyboardCallback keyboardCallback)
} }
b3MouseMoveCallback X11OpenGLWindow::getMouseMoveCallback()
{
return m_data->m_mouseMoveCallback;
}
b3MouseButtonCallback X11OpenGLWindow::getMouseButtonCallback()
{
return m_data->m_mouseButtonCallback;
}
b3ResizeCallback X11OpenGLWindow::getResizeCallback()
{
return m_data->m_resizeCallback;
}
b3WheelCallback X11OpenGLWindow::getWheelCallback()
{
return m_data->m_wheelCallback;
}
b3KeyboardCallback X11OpenGLWindow::getKeyboardCallback() b3KeyboardCallback X11OpenGLWindow::getKeyboardCallback()
{ {
return m_data->m_keyboardCallback; return m_data->m_keyboardCallback;
} }
#include <stdio.h> #include <stdio.h>
int X11OpenGLWindow::fileOpenDialog(char* filename, int maxNameLength) int X11OpenGLWindow::fileOpenDialog(char* filename, int maxNameLength)

View File

@@ -53,7 +53,12 @@ public:
virtual void setResizeCallback(b3ResizeCallback resizeCallback); virtual void setResizeCallback(b3ResizeCallback resizeCallback);
virtual void setWheelCallback(b3WheelCallback wheelCallback); virtual void setWheelCallback(b3WheelCallback wheelCallback);
virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback); virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback);
virtual b3KeyboardCallback getKeyboardCallback();
virtual b3MouseMoveCallback getMouseMoveCallback();
virtual b3MouseButtonCallback getMouseButtonCallback();
virtual b3ResizeCallback getResizeCallback();
virtual b3WheelCallback getWheelCallback();
virtual b3KeyboardCallback getKeyboardCallback();
virtual void setRenderCallback( b3RenderCallback renderCallback); virtual void setRenderCallback( b3RenderCallback renderCallback);

View File

@@ -98,9 +98,17 @@ class b3gWindowInterface
virtual void setMouseMoveCallback(b3MouseMoveCallback mouseCallback)=0; virtual void setMouseMoveCallback(b3MouseMoveCallback mouseCallback)=0;
virtual b3MouseMoveCallback getMouseMoveCallback()=0;
virtual void setMouseButtonCallback(b3MouseButtonCallback mouseCallback)=0; virtual void setMouseButtonCallback(b3MouseButtonCallback mouseCallback)=0;
virtual b3MouseButtonCallback getMouseButtonCallback()=0;
virtual void setResizeCallback(b3ResizeCallback resizeCallback)=0; virtual void setResizeCallback(b3ResizeCallback resizeCallback)=0;
virtual b3ResizeCallback getResizeCallback()=0;
virtual void setWheelCallback(b3WheelCallback wheelCallback)=0; virtual void setWheelCallback(b3WheelCallback wheelCallback)=0;
virtual b3WheelCallback getWheelCallback()=0;
virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback)=0; virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback)=0;
virtual b3KeyboardCallback getKeyboardCallback()=0; virtual b3KeyboardCallback getKeyboardCallback()=0;

View File

@@ -1,6 +1,7 @@
rem premake4 --with-pe vs2010 rem premake4 --with-pe vs2010
premake4 vs2010 rem premake4 --bullet2demos vs2010
premake4 vs2010
mkdir vs2010\cache mkdir vs2010\cache
pause pause

View File

@@ -45,7 +45,11 @@ btHingeConstraint::btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const bt
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
m_useReferenceFrameA(useReferenceFrameA), m_useReferenceFrameA(useReferenceFrameA),
m_flags(0) m_flags(0),
m_normalCFM(0),
m_normalERP(0),
m_stopCFM(0),
m_stopERP(0)
{ {
m_rbAFrame.getOrigin() = pivotInA; m_rbAFrame.getOrigin() = pivotInA;
@@ -101,7 +105,11 @@ m_angularOnly(false), m_enableAngularMotor(false),
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
m_useReferenceFrameA(useReferenceFrameA), m_useReferenceFrameA(useReferenceFrameA),
m_flags(0) m_flags(0),
m_normalCFM(0),
m_normalERP(0),
m_stopCFM(0),
m_stopERP(0)
{ {
// since no frame is given, assume this to be zero angle and just pick rb transform axis // since no frame is given, assume this to be zero angle and just pick rb transform axis
@@ -151,7 +159,11 @@ m_enableAngularMotor(false),
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
m_useReferenceFrameA(useReferenceFrameA), m_useReferenceFrameA(useReferenceFrameA),
m_flags(0) m_flags(0),
m_normalCFM(0),
m_normalERP(0),
m_stopCFM(0),
m_stopERP(0)
{ {
#ifndef _BT_USE_CENTER_LIMIT_ #ifndef _BT_USE_CENTER_LIMIT_
//start with free //start with free
@@ -177,7 +189,11 @@ m_enableAngularMotor(false),
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
m_useReferenceFrameA(useReferenceFrameA), m_useReferenceFrameA(useReferenceFrameA),
m_flags(0) m_flags(0),
m_normalCFM(0),
m_normalERP(0),
m_stopCFM(0),
m_stopERP(0)
{ {
///not providing rigidbody B means implicitly using worldspace for body B ///not providing rigidbody B means implicitly using worldspace for body B
@@ -331,6 +347,7 @@ void btHingeAccumulatedAngleConstraint::getInfo1(btConstraintInfo1* info)
m_accumulatedAngle = btShortestAngleUpdate(m_accumulatedAngle,curHingeAngle); m_accumulatedAngle = btShortestAngleUpdate(m_accumulatedAngle,curHingeAngle);
btHingeConstraint::getInfo1(info); btHingeConstraint::getInfo1(info);
} }
@@ -464,7 +481,9 @@ void btHingeConstraint::getInfo2Internal(btConstraintInfo2* info, const btTransf
a2.getSkewSymmetricMatrix(angular0,angular1,angular2); a2.getSkewSymmetricMatrix(angular0,angular1,angular2);
} }
// linear RHS // linear RHS
btScalar k = info->fps * info->erp; btScalar normalErp = (m_flags & BT_HINGE_FLAGS_ERP_NORM) ? m_normalERP : info->erp;
btScalar k = info->fps * normalErp;
if (!m_angularOnly) if (!m_angularOnly)
{ {
for(i = 0; i < 3; i++) for(i = 0; i < 3; i++)
@@ -561,7 +580,7 @@ void btHingeConstraint::getInfo2Internal(btConstraintInfo2* info, const btTransf
powered = 0; powered = 0;
} }
info->m_constraintError[srow] = btScalar(0.0f); info->m_constraintError[srow] = btScalar(0.0f);
btScalar currERP = (m_flags & BT_HINGE_FLAGS_ERP_STOP) ? m_stopERP : info->erp; btScalar currERP = (m_flags & BT_HINGE_FLAGS_ERP_STOP) ? m_stopERP : normalErp;
if(powered) if(powered)
{ {
if(m_flags & BT_HINGE_FLAGS_CFM_NORM) if(m_flags & BT_HINGE_FLAGS_CFM_NORM)
@@ -851,7 +870,8 @@ void btHingeConstraint::getInfo2InternalUsingFrameOffset(btConstraintInfo2* info
for (i=0; i<3; i++) info->m_J1angularAxis[s2+i] = tmpA[i]; for (i=0; i<3; i++) info->m_J1angularAxis[s2+i] = tmpA[i];
for (i=0; i<3; i++) info->m_J2angularAxis[s2+i] = -tmpB[i]; for (i=0; i<3; i++) info->m_J2angularAxis[s2+i] = -tmpB[i];
btScalar k = info->fps * info->erp; btScalar normalErp = (m_flags & BT_HINGE_FLAGS_ERP_NORM)? m_normalERP : info->erp;
btScalar k = info->fps * normalErp;
if (!m_angularOnly) if (!m_angularOnly)
{ {
@@ -909,7 +929,8 @@ void btHingeConstraint::getInfo2InternalUsingFrameOffset(btConstraintInfo2* info
// angular_velocity = (erp*fps) * (ax1 x ax2) // angular_velocity = (erp*fps) * (ax1 x ax2)
// ax1 x ax2 is in the plane space of ax1, so we project the angular // ax1 x ax2 is in the plane space of ax1, so we project the angular
// velocity to p and q to find the right hand side. // velocity to p and q to find the right hand side.
k = info->fps * info->erp; k = info->fps * normalErp;//??
btVector3 u = ax1A.cross(ax1B); btVector3 u = ax1A.cross(ax1B);
info->m_constraintError[s3] = k * u.dot(p); info->m_constraintError[s3] = k * u.dot(p);
info->m_constraintError[s4] = k * u.dot(q); info->m_constraintError[s4] = k * u.dot(q);
@@ -954,7 +975,7 @@ void btHingeConstraint::getInfo2InternalUsingFrameOffset(btConstraintInfo2* info
powered = 0; powered = 0;
} }
info->m_constraintError[srow] = btScalar(0.0f); info->m_constraintError[srow] = btScalar(0.0f);
btScalar currERP = (m_flags & BT_HINGE_FLAGS_ERP_STOP) ? m_stopERP : info->erp; btScalar currERP = (m_flags & BT_HINGE_FLAGS_ERP_STOP) ? m_stopERP : normalErp;
if(powered) if(powered)
{ {
if(m_flags & BT_HINGE_FLAGS_CFM_NORM) if(m_flags & BT_HINGE_FLAGS_CFM_NORM)
@@ -1055,6 +1076,10 @@ void btHingeConstraint::setParam(int num, btScalar value, int axis)
m_normalCFM = value; m_normalCFM = value;
m_flags |= BT_HINGE_FLAGS_CFM_NORM; m_flags |= BT_HINGE_FLAGS_CFM_NORM;
break; break;
case BT_CONSTRAINT_ERP:
m_normalERP = value;
m_flags |= BT_HINGE_FLAGS_ERP_NORM;
break;
default : default :
btAssertConstrParams(0); btAssertConstrParams(0);
} }
@@ -1085,6 +1110,10 @@ btScalar btHingeConstraint::getParam(int num, int axis) const
btAssertConstrParams(m_flags & BT_HINGE_FLAGS_CFM_NORM); btAssertConstrParams(m_flags & BT_HINGE_FLAGS_CFM_NORM);
retVal = m_normalCFM; retVal = m_normalCFM;
break; break;
case BT_CONSTRAINT_ERP:
btAssertConstrParams(m_flags & BT_HINGE_FLAGS_ERP_NORM);
retVal = m_normalERP;
break;
default : default :
btAssertConstrParams(0); btAssertConstrParams(0);
} }

View File

@@ -41,7 +41,8 @@ enum btHingeFlags
{ {
BT_HINGE_FLAGS_CFM_STOP = 1, BT_HINGE_FLAGS_CFM_STOP = 1,
BT_HINGE_FLAGS_ERP_STOP = 2, BT_HINGE_FLAGS_ERP_STOP = 2,
BT_HINGE_FLAGS_CFM_NORM = 4 BT_HINGE_FLAGS_CFM_NORM = 4,
BT_HINGE_FLAGS_ERP_NORM = 8
}; };
@@ -94,6 +95,7 @@ public:
int m_flags; int m_flags;
btScalar m_normalCFM; btScalar m_normalCFM;
btScalar m_normalERP;
btScalar m_stopCFM; btScalar m_stopCFM;
btScalar m_stopERP; btScalar m_stopERP;