created new Bullet 2 CPU BasicDemo, using the OpenGL 3 rendering. I will add picking soon. Hold ctrl/alt + mouse to move/zoom camera

remove reference to btGImpact (it is removed now)
This commit is contained in:
erwincoumans
2013-12-06 17:48:58 -08:00
parent bbb2c8a6f1
commit fca6d11381
16 changed files with 301 additions and 1671 deletions

View File

@@ -15,59 +15,15 @@
initOpenGL() initOpenGL()
initGlew() initGlew()
--links{"gwen"} links{"gwen", "OpenGL_Window","OpenGL_TrueTypeFont"}
files { files {
"**.cpp", "**.cpp",
"**.h", "**.h",
"../../src/Bullet3Common/**.cpp", "../../src/Bullet3Common/**.cpp",
"../../src/Bullet3Common/**.h", "../../src/Bullet3Common/**.h",
"../../btgui/OpenGLWindow/SimpleOpenGL3App.cpp",
"../../btgui/OpenGLWindow/SimpleOpenGL3App.h",
"../../btgui/OpenGLWindow/TwFonts.cpp",
"../../btgui/OpenGLWindow/TwFonts.h",
"../../btgui/OpenGLWindow/LoadShader.cpp",
"../../btgui/OpenGLWindow/LoadShader.h",
"../../btgui/OpenGLWindow/GLPrimitiveRenderer.cpp",
"../../btgui/OpenGLWindow/GLPrimitiveRenderer.h",
"../../btgui/OpenGLWindow/GwenOpenGL3CoreRenderer.h",
"../../btgui/OpenGLWindow/GLInstancingRenderer.cpp",
"../../btgui/OpenGLWindow/GLInstancingRenderer.h",
"../../btgui/OpenGLWindow/GLRenderToTexture.cpp",
"../../btgui/OpenGLWindow/GLRenderToTexture.h",
"../../btgui/OpenGLWindow/TwFonts.cpp",
"../../btgui/OpenGLWindow/TwFonts.h",
"../../btgui/FontFiles/OpenSans.cpp",
"../../btgui/OpenGLTrueTypeFont/fontstash.cpp",
"../../btgui/OpenGLTrueTypeFont/fontstash.h",
"../../btgui/OpenGLTrueTypeFont/opengl_fontstashcallbacks.cpp",
"../../btgui/OpenGLTrueTypeFont/opengl_fontstashcallbacks.h",
"../../btgui/Bullet3Common/**.cpp",
"../../btgui/Bullet3Common/**.h",
"../../btgui/Timing/b3Clock.cpp", "../../btgui/Timing/b3Clock.cpp",
"../../btgui/Timing/b3Clock.h" "../../btgui/Timing/b3Clock.h"
} }
if os.is("Windows") then
files {
"../../btgui/OpenGLWindow/Win32OpenGLWindow.cpp",
"../../btgui/OpenGLWindow/Win32OpenGLWindow.h",
"../../btgui/OpenGLWindow/Win32Window.cpp",
"../../btgui/OpenGLWindow/Win32Window.h",
}
end
if os.is("Linux") then
links ("X11")
files{
"../../btgui/OpenGLWindow/X11OpenGLWindow.h",
"../../btgui/OpenGLWindow/X11OpenGLWindow.cpp"
}
end
if os.is("MacOSX") then
links{"Cocoa.framework"}
files{
"../../btgui/OpenGLWindow/MacOpenGLWindow.mm",
"../../btgui/OpenGLWindow/MacOpenGLWindow.h",
}
end

View File

@@ -0,0 +1,217 @@
#define ARRAY_SIZE_X 5
#define ARRAY_SIZE_Y 5
#define ARRAY_SIZE_Z 5
#include "OpenGLWindow/SimpleOpenGL3App.h"
#include "Bullet3Common/b3Vector3.h"
#include "assert.h"
#include <stdio.h>
#include "btBulletDynamicsCommon.h"
class Bullet2RigidBodyDemo
{
protected:
btDiscreteDynamicsWorld* m_dynamicsWorld;
btCollisionDispatcher* m_dispatcher;
btBroadphaseInterface* m_bp;
btCollisionConfiguration* m_config;
btConstraintSolver* m_solver;
public:
Bullet2RigidBodyDemo()
{
m_config = 0;
m_dispatcher = 0;
m_bp = 0;
m_solver = 0;
m_dynamicsWorld = 0;
}
virtual void initPhysics()
{
m_config = new btDefaultCollisionConfiguration;
m_dispatcher = new btCollisionDispatcher(m_config);
m_bp = new btDbvtBroadphase();
m_solver = new btSequentialImpulseConstraintSolver();
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_bp,m_solver,m_config);
}
virtual void exitPhysics()
{
delete m_dynamicsWorld;
m_dynamicsWorld=0;
delete m_solver;
m_solver=0;
delete m_bp;
m_bp=0;
delete m_dispatcher;
m_dispatcher=0;
delete m_config;
m_config=0;
}
virtual ~Bullet2RigidBodyDemo()
{
btAssert(m_config == 0);
btAssert(m_dispatcher == 0);
btAssert(m_bp == 0);
btAssert(m_solver == 0);
btAssert(m_dynamicsWorld == 0);
}
};
class BasicDemo : public Bullet2RigidBodyDemo
{
SimpleOpenGL3App* m_glApp;
public:
BasicDemo(SimpleOpenGL3App* app)
:m_glApp(app)
{
}
virtual ~BasicDemo()
{
}
void initPhysics()
{
Bullet2RigidBodyDemo::initPhysics();
//create ground
int cubeShapeId = m_glApp->registerCubeShape();
float pos[]={0,0,0};
float orn[]={0,0,0,1};
{
float color[]={0.3,0.3,1,1};
float halfExtents[]={50,50,50,1};
btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,-50,0));
m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,groundTransform.getOrigin(),groundTransform.getRotation(),color,halfExtents);
btBoxShape* groundShape = new btBoxShape(btVector3(btScalar(halfExtents[0]),btScalar(halfExtents[1]),btScalar(halfExtents[2])));
//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
{
btScalar mass(0.);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia);
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
//add the body to the dynamics world
m_dynamicsWorld->addRigidBody(body);
}
}
{
float halfExtents[]={1,1,1,1};
float color[]={0,1,0,1};
btTransform startTransform;
startTransform.setIdentity();
btScalar mass = 1.f;
btVector3 localInertia;
btBoxShape* colShape = new btBoxShape(btVector3(halfExtents[0],halfExtents[1],halfExtents[2]));
colShape ->calculateLocalInertia(mass,localInertia);
for (int k=0;k<ARRAY_SIZE_Y;k++)
{
for (int i=0;i<ARRAY_SIZE_X;i++)
{
for(int j = 0;j<ARRAY_SIZE_Z;j++)
{
startTransform.setOrigin(btVector3(
btScalar(2.0*i),
btScalar(20+2.0*k),
btScalar(2.0*j)));
m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,startTransform.getOrigin(),startTransform.getRotation(),color,halfExtents);
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
m_dynamicsWorld->addRigidBody(body);
}
}
}
}
m_glApp->m_instancingRenderer->writeTransforms();
}
void exitPhysics()
{
Bullet2RigidBodyDemo::exitPhysics();
}
void drawObjects()
{
//sync graphics -> physics world transforms
{
for (int i=0;i<m_dynamicsWorld->getNumCollisionObjects();i++)
{
btVector3 pos = m_dynamicsWorld->getCollisionObjectArray()[i]->getWorldTransform().getOrigin();
btQuaternion orn = m_dynamicsWorld->getCollisionObjectArray()[i]->getWorldTransform().getRotation();
m_glApp->m_instancingRenderer->writeSingleInstanceTransformToCPU(pos,orn,i);
}
m_glApp->m_instancingRenderer->writeTransforms();
}
m_glApp->m_instancingRenderer->renderScene();
}
void stepSimulation()
{
m_dynamicsWorld->stepSimulation(1./60,0);
}
};
int main(int argc, char* argv[])
{
float dt = 1./120.f;
SimpleOpenGL3App* app = new SimpleOpenGL3App("Bullet 2 CPU BasicDemo",1024,768);
app->m_instancingRenderer->setCameraDistance(40);
app->m_instancingRenderer->setCameraPitch(0);
app->m_instancingRenderer->setCameraTargetPosition(b3MakeVector3(0,0,0));
BasicDemo* demo = new BasicDemo(app);
demo->initPhysics();
GLint err = glGetError();
assert(err==GL_NO_ERROR);
do
{
GLint err = glGetError();
assert(err==GL_NO_ERROR);
app->m_instancingRenderer->init();
app->m_instancingRenderer->updateCamera();
demo->stepSimulation();
demo->drawObjects();
app->drawGrid(10,0.01);
char bla[1024];
static int frameCount = 0;
frameCount++;
sprintf(bla,"Simulation frame %d", frameCount);
app->drawText(bla,10,10);
app->swapBuffer();
} while (!app->m_window->requestedExit());
demo->exitPhysics();
delete demo;
delete app;
return 0;
}

View File

@@ -0,0 +1,38 @@
project "App2_BasicDemo"
language "C++"
kind "ConsoleApp"
targetdir "../../../bin"
includedirs {
".",
"../../../src",
"../../../btgui"
}
initOpenGL()
initGlew()
links{"gwen", "BulletDynamics", "BulletCollision","LinearMath",
"OpenGL_Window", "OpenGL_TrueTypeFont"
}
files {
"**.cpp",
"**.h",
"../../../src/Bullet3Common/**.cpp",
"../../../src/Bullet3Common/**.h",
"../../../btgui/Timing/b3Clock.cpp",
"../../../btgui/Timing/b3Clock.h"
}
if os.is("Linux") then
links ("X11")
end
if os.is("MacOSX") then
links{"Cocoa.framework"}
end

View File

@@ -4,8 +4,7 @@
language "C++" language "C++"
kind "ConsoleApp" kind "StaticLib"
targetdir "../../bin"
initOpenGL() initOpenGL()
@@ -16,49 +15,14 @@
".." ".."
} }
files
{
files {
"main.cpp",
"../FontFiles/OpenSans.cpp", "../FontFiles/OpenSans.cpp",
"../OpenGLWindow/LoadShader.cpp",
"../OpenGLWindow/LoadShader.h",
"../../src/Bullet3Common/b3AlignedAllocator.cpp",
"../../src/Bullet3Common/b3Logging.cpp",
"../Timing/b3Quickprof.cpp",
"../Timing/b3Quickprof.h" ,
"../Timing/b3Clock.cpp",
"../Timing/b3Clock.h" ,
"fontstash.cpp", "fontstash.cpp",
"fontstash.h", "fontstash.h",
"opengl_fontstashcallbacks.cpp", "opengl_fontstashcallbacks.cpp",
"opengl_fontstashcallbacks.h", "opengl_fontstashcallbacks.h",
"stb_image_write.h", "stb_image_write.h",
"stb_truetype.h", "stb_truetype.h",
} }
if os.is("Windows") then
files{
"../OpenGLWindow/Win32OpenGLWindow.cpp",
"../OpenGLWindow/Win32OpenGLWindow.h",
"../OpenGLWindow/Win32Window.cpp",
"../OpenGLWindow/Win32Window.h",
}
end
if os.is("Linux") then
links{"X11"}
files{
"../OpenGLWindow/X11OpenGLWindow.h",
"../OpenGLWindow/X11OpenGLWindow.cpp"
}
end
if os.is("MacOSX") then
links { "Cocoa.framework" }
files{
"../OpenGLWindow/MacOpenGLWindow.h",
"../OpenGLWindow/MacOpenGLWindow.mm",
}
end

View File

@@ -1,5 +1,5 @@
#include "SimpleOpenGL3App.h" #include "SimpleOpenGL3App.h"
#include "ShapeData.h"
#ifdef __APPLE__ #ifdef __APPLE__
#include "OpenGLWindow/MacOpenGLWindow.h" #include "OpenGLWindow/MacOpenGLWindow.h"
@@ -171,8 +171,15 @@ void SimpleOpenGL3App::drawText( const char* txt, int posX, int posY)
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
int SimpleOpenGL3App::registerCubeShape()
void SimpleOpenGL3App::drawGrid(int gridSize) {
int strideInBytes = 9*sizeof(float);
int numVertices = sizeof(cube_vertices)/strideInBytes;
int numIndices = sizeof(cube_indices)/sizeof(int);
int shapeId = m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
return shapeId;
}
void SimpleOpenGL3App::drawGrid(int gridSize, float yOffset)
{ {
b3Vector3 gridColor = b3MakeVector3(0.5,0.5,0.5); b3Vector3 gridColor = b3MakeVector3(0.5,0.5,0.5);
@@ -182,12 +189,12 @@ void SimpleOpenGL3App::drawGrid(int gridSize)
GLint err = glGetError(); GLint err = glGetError();
b3Assert(err==GL_NO_ERROR); b3Assert(err==GL_NO_ERROR);
m_instancingRenderer->drawLine(b3MakeVector3(float(i),0,float(-gridSize)),b3MakeVector3(float(i),0,float(gridSize)),gridColor); m_instancingRenderer->drawLine(b3MakeVector3(float(i),yOffset,float(-gridSize)),b3MakeVector3(float(i),yOffset,float(gridSize)),gridColor);
err = glGetError(); err = glGetError();
b3Assert(err==GL_NO_ERROR); b3Assert(err==GL_NO_ERROR);
m_instancingRenderer->drawLine(b3MakeVector3(float(-gridSize),0,float(i)),b3MakeVector3(float(gridSize),0,float(i)),gridColor); m_instancingRenderer->drawLine(b3MakeVector3(float(-gridSize),yOffset,float(i)),b3MakeVector3(float(gridSize),yOffset,float(i)),gridColor);
} }
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(1,0,0),b3MakeVector3(1,0,0),3); m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(1,0,0),b3MakeVector3(1,0,0),3);

View File

@@ -16,7 +16,9 @@ struct SimpleOpenGL3App
SimpleOpenGL3App(const char* title, int width,int height); SimpleOpenGL3App(const char* title, int width,int height);
virtual ~SimpleOpenGL3App(); virtual ~SimpleOpenGL3App();
void drawGrid(int gridSize=10); int registerCubeShape();
void drawGrid(int gridSize=10, float yOffset=0.001);
void swapBuffer(); void swapBuffer();
void drawText( const char* txt, int posX, int posY); void drawText( const char* txt, int posX, int posY);

View File

@@ -1,375 +0,0 @@
#include "gwenWindow.h"
#include "Gwen/Platform.h"
#include "Gwen/Controls/TreeControl.h"
#include "Gwen/Controls/RadioButtonController.h"
#include "Gwen/Controls/VerticalSlider.h"
#include "Gwen/Controls/HorizontalSlider.h"
#include "Gwen/Controls/GroupBox.h"
#include "Gwen/Controls/CheckBox.h"
#include "Gwen/Controls/MenuStrip.h"
#include "Gwen/Gwen.h"
#include "Gwen/Align.h"
#include "Gwen/Utility.h"
#include "Gwen/Controls/WindowControl.h"
#include "Gwen/Controls/TabControl.h"
#include "Gwen/Controls/ListBox.h"
#include "Bullet3Common/b3Quickprof.h"
#include "GwenOpenGL3CoreRenderer.h"
#include "GLPrimitiveRenderer.h"
GLPrimitiveRenderer* primRenderer=0;
GwenOpenGL3CoreRenderer* pRenderer = 0;
//Gwen::Renderer::OpenGL_DebugFont * pRenderer =0;
Gwen::Skin::Simple skin;
Gwen::Controls::Canvas* pCanvas =0;
class MyProfileWindow* profWindow = 0;
/*struct MyHander :public Gwen::Event::Handler
{
MyHander (Application* app)
:m_app(app)
{
}
void onButtonA( Gwen::Controls::Base* pControl )
{
OpenTissue::glut::toggleIdle();
}
void SliderMoved(Gwen::Controls::Base* pControl )
{
Gwen::Controls::Slider* pSlider = (Gwen::Controls::Slider*)pControl;
this->m_app->scaleYoungModulus(pSlider->GetValue());
// printf("Slider Value: %.2f", pSlider->GetValue() );
}
void OnCheckChangedStiffnessWarping (Gwen::Controls::Base* pControl)
{
Gwen::Controls::CheckBox* labeled = (Gwen::Controls::CheckBox* )pControl;
bool checked = labeled->IsChecked();
m_app->m_stiffness_warp_on = checked;
}
};
*/
class MyProfileWindow : public Gwen::Controls::WindowControl
{
// Gwen::Controls::TabControl* m_TabControl;
//Gwen::Controls::ListBox* m_TextOutput;
unsigned int m_iFrames;
float m_fLastSecond;
Gwen::Controls::TreeNode* m_node;
Gwen::Controls::TreeControl* m_ctrl;
protected:
void onButtonA( Gwen::Controls::Base* pControl )
{
// OpenTissue::glut::toggleIdle();
}
void SliderMoved(Gwen::Controls::Base* pControl )
{
Gwen::Controls::Slider* pSlider = (Gwen::Controls::Slider*)pControl;
//this->m_app->scaleYoungModulus(pSlider->GetValue());
// printf("Slider Value: %.2f", pSlider->GetValue() );
}
void OnCheckChangedStiffnessWarping (Gwen::Controls::Base* pControl)
{
Gwen::Controls::CheckBox* labeled = (Gwen::Controls::CheckBox* )pControl;
bool checked = labeled->IsChecked();
//m_app->m_stiffness_warp_on = checked;
}
public:
void MenuItemSelect(Gwen::Controls::Base* pControl)
{
if (Hidden())
{
SetHidden(false);
} else
{
SetHidden(true);
}
}
MyProfileWindow ( Gwen::Controls::Base* pParent)
: Gwen::Controls::WindowControl( pParent )
{
SetTitle( L"FEM Settings" );
SetSize( 450, 150 );
this->SetPos(10,40);
// this->Dock( Gwen::Pos::Bottom);
{
m_ctrl = new Gwen::Controls::TreeControl( this );
m_node = m_ctrl->AddNode( L"Total Parent Time" );
//Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
//pNode->AddNode( L"Node Two Inside" );
//pNode->AddNode( L"Eyes" );
//pNode->AddNode( L"Brown" )->AddNode( L"Node Two Inside" )->AddNode( L"Eyes" )->AddNode( L"Brown" );
//Gwen::Controls::TreeNode* node = ctrl->AddNode( L"Node Three" );
//m_ctrl->Dock(Gwen::Pos::Bottom);
m_ctrl->ExpandAll();
m_ctrl->SetBounds( this->GetInnerBounds().x,this->GetInnerBounds().y,this->GetInnerBounds().w,this->GetInnerBounds().h);
}
}
float dumpRecursive(b3ProfileIterator* profileIterator, Gwen::Controls::TreeNode* parentNode)
{
profileIterator->First();
if (profileIterator->Is_Done())
return 0.f;
float accumulated_time=0,parent_time = profileIterator->Is_Root() ? b3ProfileManager::Get_Time_Since_Reset() : profileIterator->Get_Current_Parent_Total_Time();
int i;
int frames_since_reset = b3ProfileManager::Get_Frame_Count_Since_Reset();
//printf("Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time );
float totalTime = 0.f;
int numChildren = 0;
Gwen::UnicodeString txt;
std::vector<Gwen::Controls::TreeNode*> nodes;
for (i = 0; !profileIterator->Is_Done(); i++,profileIterator->Next())
{
numChildren++;
float current_total_time = profileIterator->Get_Current_Total_Time();
accumulated_time += current_total_time;
double fraction = parent_time > B3_EPSILON ? (current_total_time / parent_time) * 100 : 0.f;
Gwen::String name(profileIterator->Get_Current_Name());
#ifdef _WIN32
Gwen::UnicodeString uname = Gwen::Utility::StringToUnicode(name);
txt = Gwen::Utility::Format(L"%s (%.2f %%) :: %.3f ms / frame (%d calls)",uname.c_str(), fraction,(current_total_time / (double)frames_since_reset),profileIterator->Get_Current_Total_Calls());
#else
txt = Gwen::Utility::Format(L"%s (%.2f %%) :: %.3f ms / frame (%d calls)",name.c_str(), fraction,(current_total_time / (double)frames_since_reset),profileIterator->Get_Current_Total_Calls());
#endif
Gwen::Controls::TreeNode* childNode = (Gwen::Controls::TreeNode*)profileIterator->Get_Current_UserPointer();
if (!childNode)
{
childNode = parentNode->AddNode(L"");
profileIterator->Set_Current_UserPointer(childNode);
}
childNode->SetText(txt);
nodes.push_back(childNode);
totalTime += current_total_time;
//recurse into children
}
for (i=0;i<numChildren;i++)
{
profileIterator->Enter_Child(i);
Gwen::Controls::TreeNode* curNode = nodes[i];
dumpRecursive(profileIterator, curNode);
profileIterator->Enter_Parent();
}
return accumulated_time;
}
void UpdateText(b3ProfileIterator* profileIterator, bool idle)
{
static bool update=true;
m_ctrl->SetBounds(0,0,this->GetInnerBounds().w,this->GetInnerBounds().h);
// if (!update)
// return;
update=false;
static int test = 1;
test++;
static double time_since_reset = 0.f;
if (!idle)
{
time_since_reset = b3ProfileManager::Get_Time_Since_Reset();
}
//Gwen::UnicodeString txt = Gwen::Utility::Format( L"FEM Settings %i fps", test );
{
//recompute profiling data, and store profile strings
char blockTime[128];
double totalTime = 0;
int frames_since_reset = b3ProfileManager::Get_Frame_Count_Since_Reset();
profileIterator->First();
double parent_time = profileIterator->Is_Root() ? time_since_reset : profileIterator->Get_Current_Parent_Total_Time();
Gwen::Controls::TreeNode* curParent = m_node;
double accumulated_time = dumpRecursive(profileIterator,m_node);
const char* name = profileIterator->Get_Current_Parent_Name();
#ifdef _WIN32
Gwen::UnicodeString uname = Gwen::Utility::StringToUnicode(name);
Gwen::UnicodeString txt = Gwen::Utility::Format( L"Profiling: %s total time: %.3f ms, unaccounted %.3f %% :: %.3f ms", uname.c_str(), parent_time ,
parent_time > B3_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
#else
Gwen::UnicodeString txt = Gwen::Utility::Format( L"Profiling: %s total time: %.3f ms, unaccounted %.3f %% :: %.3f ms", name, parent_time ,
parent_time > B3_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
#endif
//sprintf(blockTime,"--- Profiling: %s (total running time: %.3f ms) ---", profileIterator->Get_Current_Parent_Name(), parent_time );
//displayProfileString(xOffset,yStart,blockTime);
m_node->SetText(txt);
//printf("%s (%.3f %%) :: %.3f ms\n", "Unaccounted:",);
}
static bool once1 = true;
if (once1)
{
once1 = false;
m_ctrl->ExpandAll();
}
}
void PrintText( const Gwen::UnicodeString& str )
{
}
void Render( Gwen::Skin::Base* skin )
{
m_iFrames++;
if ( m_fLastSecond < Gwen::Platform::GetTimeInSeconds() )
{
SetTitle( Gwen::Utility::Format( L"Profiler %i fps", m_iFrames ) );
m_fLastSecond = Gwen::Platform::GetTimeInSeconds() + 1.0f;
m_iFrames = 0;
}
Gwen::Controls::WindowControl::Render( skin );
}
};
struct MyTestMenuBar : public Gwen::Controls::MenuStrip
{
MyProfileWindow* m_profileWindow;
MyTestMenuBar(Gwen::Controls::Base* pParent, MyProfileWindow* profileWindow)
:Gwen::Controls::MenuStrip(pParent),
m_profileWindow(profileWindow)
{
// Gwen::Controls::MenuStrip* menu = new Gwen::Controls::MenuStrip( pParent );
{
Gwen::Controls::MenuItem* pRoot = AddItem( L"File" );
pRoot = AddItem( L"View" );
// Gwen::Event::Handler* handler = GWEN_MCALL(&MyTestMenuBar::MenuItemSelect );
pRoot->GetMenu()->AddItem( L"Profiler",m_profileWindow,(Gwen::Event::Handler::Function)&MyProfileWindow::MenuItemSelect);
/* pRoot->GetMenu()->AddItem( L"New", L"test16.png", GWEN_MCALL( ThisClass::MenuItemSelect ) );
pRoot->GetMenu()->AddItem( L"Load", L"test16.png", GWEN_MCALL( ThisClass::MenuItemSelect ) );
pRoot->GetMenu()->AddItem( L"Save", GWEN_MCALL( ThisClass::MenuItemSelect ) );
pRoot->GetMenu()->AddItem( L"Save As..", GWEN_MCALL( ThisClass::MenuItemSelect ) );
pRoot->GetMenu()->AddItem( L"Quit", GWEN_MCALL( ThisClass::MenuItemSelect ) );
*/
}
}
};
void setupGUI(int width, int height, sth_stash* font, float retinaScale,GLPrimitiveRenderer* primRender)
{
primRenderer = primRender;
pRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,width,height, retinaScale);
if (primRenderer)
primRenderer->setScreenSize(width,height);
// pRenderer = new Gwen::Renderer::OpenGL_DebugFont();
skin.SetRender( pRenderer );
pCanvas = new Gwen::Controls::Canvas( &skin );
pCanvas->SetSize( width,height);
pCanvas->SetDrawBackground( false);
pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
// pCanvas->SetScale(.5);
//MyWindow* window = new MyWindow(pCanvas);
profWindow = new MyProfileWindow(pCanvas);
MyTestMenuBar* menubar = new MyTestMenuBar(pCanvas, profWindow);
}
void resizeGUI(int width, int height)
{
pCanvas->SetSize(width,height);
pRenderer->resize(width,height);
primRenderer->setScreenSize(width,height);
}
void processProfileData(b3ProfileIterator* iterator, bool idle)
{
if (profWindow)
{
profWindow->UpdateText(iterator, idle);
}
}

View File

@@ -1,24 +0,0 @@
#ifndef MY_GWEN_WINDOW_H
#define MY_GWEN_WINDOW_H
#include "Gwen/Gwen.h"
#include "Gwen/Controls/Button.h"
#include "Gwen/Skins/Simple.h"
#include "Gwen/Renderers/OpenGL_DebugFont.h"
struct sth_stash;
extern class GwenOpenGL3CoreRenderer* pRenderer;
//extern Gwen::Renderer::OpenGL_DebugFont * pRenderer;
extern Gwen::Skin::Simple skin;
extern Gwen::Controls::Canvas* pCanvas;
class GLPrimitiveRenderer;
void setupGUI(int width, int height, sth_stash* font, float retinaScale,GLPrimitiveRenderer* primRender);
void processProfileData(class b3ProfileIterator* iterator, bool idle);
void resizeGUI(int width, int height);
#endif //MY_GWEN_WINDOW_H

View File

@@ -1,516 +0,0 @@
/*
Copyright (c) 2012 Advanced Micro Devices, Inc.
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
//Originally written by Erwin Coumans
//
//#include "vld.h"
#ifndef __APPLE__
#include <GL/glew.h>
#endif
#include <assert.h>
#include "GLInstancingRenderer.h"
#ifdef __APPLE__
#include "MacOpenGLWindow.h"
#elif _WIN32
#include "Win32OpenGLWindow.h"
#elif __linux
#include "X11OpenGLWindow.h"
#endif
#include "GLPrimitiveRenderer.h"
extern char OpenSansData[];
#include "renderscene.h"
#include "Bullet3Common/b3Quickprof.h"
#include "Bullet3Common/b3Quaternion.h"
#include "Bullet3Common/b3CommandLineArgs.h"
#include "../OpenGLTrueTypeFont/fontstash.h"
#include "../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h"
bool printStats = false;
bool pauseSimulation = false;
bool shootObject = false;
bool useInterop = false;
extern int NUM_OBJECTS_X;
extern int NUM_OBJECTS_Y;
extern int NUM_OBJECTS_Z;
extern bool keepStaticObjects;
extern float X_GAP;
extern float Y_GAP;
extern float Z_GAP;
const char* fileName="../../bin/1000 stack.bullet";
void Usage()
{
printf("\nprogram.exe [--pause_simulation=<0 or 1>] [--load_bulletfile=test.bullet] [--enable_interop=<0 or 1>] [--enable_gpusap=<0 or 1>] [--enable_convexheightfield=<0 or 1>] [--enable_static=<0 or 1>] [--x_dim=<int>] [--y_dim=<num>] [--z_dim=<int>] [--x_gap=<float>] [--y_gap=<float>] [--z_gap=<float>]\n");
};
#include "gwenWindow.h"
void MyMouseButtonCallback(int button, int state, float x, float y)
{
//b3DefaultMouseCallback(button,state,x,y);
if (pCanvas)
{
bool handled = pCanvas->InputMouseMoved(x,y,x, y);
if (button>=0)
{
handled = pCanvas->InputMouseButton(button,state);
if (handled)
{
if (!state)
return;
}
}
}
}
int g_OpenGLWidth = 1024;//650;
int g_OpenGLHeight =800;
void MyResizeCallback(float width, float height)
{
g_OpenGLWidth = width;
g_OpenGLHeight = height;
if (pCanvas)
{
pCanvas->SetSize(width,height);
resizeGUI(width,height);
}
}
void MyMouseMoveCallback( float x, float y)
{
//b3DefaultMouseCallback(button,state,x,y);
static int m_lastmousepos[2] = {0,0};
static bool isInitialized = false;
if (pCanvas)
{
if (!isInitialized)
{
isInitialized = true;
m_lastmousepos[0] = x+1;
m_lastmousepos[1] = y+1;
}
bool handled = pCanvas->InputMouseMoved(x,y,m_lastmousepos[0],m_lastmousepos[1]);
}
}
int droidRegular;//, droidItalic, droidBold, droidJapanese, dejavu;
sth_stash* initFont(GLPrimitiveRenderer* primRender)
{
GLint err;
struct sth_stash* stash = 0;
int datasize;
float sx,sy,dx,dy,lh;
GLuint texture;
OpenGL2RenderCallbacks* renderCallbacks = new OpenGL2RenderCallbacks(primRender);
stash = sth_create(512,512,renderCallbacks);//256,256);//,1024);//512,512);
err = glGetError();
assert(err==GL_NO_ERROR);
if (!stash)
{
fprintf(stderr, "Could not create stash.\n");
return 0;
}
#ifdef LOAD_FONT_FROM_FILE
unsigned char* data;
const char* fontPaths[]={
"./",
"../../bin/",
"../bin/",
"bin/"
};
int numPaths=sizeof(fontPaths)/sizeof(char*);
// Load the first truetype font from memory (just because we can).
FILE* fp = 0;
const char* fontPath ="./";
char fullFontFileName[1024];
for (int i=0;i<numPaths;i++)
{
fontPath = fontPaths[i];
//sprintf(fullFontFileName,"%s%s",fontPath,"OpenSans.ttf");//"DroidSerif-Regular.ttf");
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Regular.ttf");//OpenSans.ttf");//"DroidSerif-Regular.ttf");
fp = fopen(fullFontFileName, "rb");
if (fp)
break;
}
err = glGetError();
assert(err==GL_NO_ERROR);
assert(fp);
if (fp)
{
fseek(fp, 0, SEEK_END);
datasize = (int)ftell(fp);
fseek(fp, 0, SEEK_SET);
data = (unsigned char*)malloc(datasize);
if (data == NULL)
{
assert(0);
return 0;
}
else
fread(data, 1, datasize, fp);
fclose(fp);
fp = 0;
}
if (!(droidRegular = sth_add_font_from_memory(stash, data)))
{
assert(0);
return 0;
}
err = glGetError();
assert(err==GL_NO_ERROR);
// Load the remaining truetype fonts directly.
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Italic.ttf");
if (!(droidItalic = sth_add_font(stash,fullFontFileName)))
{
assert(0);
return 0;
}
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Bold.ttf");
if (!(droidBold = sth_add_font(stash,fullFontFileName)))
{
assert(0);
return 0;
}
err = glGetError();
assert(err==GL_NO_ERROR);
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSansJapanese.ttf");
if (!(droidJapanese = sth_add_font(stash,fullFontFileName)))
{
assert(0);
return 0;
}
#else//LOAD_FONT_FROM_FILE
char* data2 = OpenSansData;
unsigned char* data = (unsigned char*) data2;
if (!(droidRegular = sth_add_font_from_memory(stash, data)))
{
printf("error!\n");
}
#endif//LOAD_FONT_FROM_FILE
err = glGetError();
assert(err==GL_NO_ERROR);
return stash;
}
int main(int argc, char* argv[])
{
b3CommandLineArgs args(argc,argv);
if (args.CheckCmdLineFlag("help"))
{
Usage();
return 0;
}
args.GetCmdLineArgument("enable_interop", useInterop);
printf("useInterop=%d\n",useInterop);
args.GetCmdLineArgument("pause_simulation", pauseSimulation);
printf("pause_simulation=%d\n",pauseSimulation);
args.GetCmdLineArgument("x_dim", NUM_OBJECTS_X);
args.GetCmdLineArgument("y_dim", NUM_OBJECTS_Y);
args.GetCmdLineArgument("z_dim", NUM_OBJECTS_Z);
args.GetCmdLineArgument("x_gap", X_GAP);
args.GetCmdLineArgument("y_gap", Y_GAP);
args.GetCmdLineArgument("z_gap", Z_GAP);
printf("x_dim=%d, y_dim=%d, z_dim=%d\n",NUM_OBJECTS_X,NUM_OBJECTS_Y,NUM_OBJECTS_Z);
printf("x_gap=%f, y_gap=%f, z_gap=%f\n",X_GAP,Y_GAP,Z_GAP);
args.GetCmdLineArgument("enable_static", keepStaticObjects);
printf("enable_static=%d\n",keepStaticObjects);
char* tmpfile = 0;
args.GetCmdLineArgument("load_bulletfile", tmpfile );
if (tmpfile)
fileName = tmpfile;
printf("load_bulletfile=%s\n",fileName);
printf("\n");
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
b3gWindowConstructionInfo wci;
wci.m_width = g_OpenGLWidth;
wci.m_height = g_OpenGLHeight;
window->createWindow(wci);
window->setWindowTitle("render test");
float retinaScale = 1;
#ifndef __APPLE__
GLenum err = glewInit();
#else
retinaScale = window->getRetinaScale();
#endif
window->runMainLoop();
window->startRendering();
window->endRendering();
int maxObjectCapacity=128*1024;
GLInstancingRenderer render(maxObjectCapacity);
GLPrimitiveRenderer* primRenderer = new GLPrimitiveRenderer(g_OpenGLWidth,g_OpenGLHeight);
sth_stash* stash = initFont(primRenderer);
render.InitShaders();
createSceneProgrammatically(render);
render.writeTransforms();
window->runMainLoop();
window->setMouseButtonCallback(MyMouseButtonCallback);
window->setMouseMoveCallback(MyMouseMoveCallback);
window->setResizeCallback(MyResizeCallback);
window->setKeyboardCallback(b3DefaultKeyboardCallback);
window->setWheelCallback(b3DefaultWheelCallback);
//GLPrimitiveRenderer* pprender = new GLPrimitiveRenderer(g_OpenGLWidth,g_OpenGLHeight);
glUseProgram(0);
////////////////////////////////
/////////////////////////////////////
if (pCanvas)
{
pCanvas->SetSize(g_OpenGLWidth,g_OpenGLHeight);
}
setupGUI(g_OpenGLWidth,g_OpenGLHeight,stash,retinaScale,primRenderer);
class b3ProfileIterator* m_profileIterator;
m_profileIterator = b3ProfileManager::Get_Iterator();
glClearColor(1,1,1,1);
while (!window->requestedExit())
{
b3ProfileManager::Reset();
{
B3_PROFILE("loop");
{
B3_PROFILE("startRendering");
window->startRendering();
}
render.RenderScene();
glFinish();
float col[4]={0,1,0,1};
// pprender->drawRect(10,50,120,60,col);
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_TEXTURE_2D);
float x = 10;
float y=220;
float dx=0;
if (1)
{
B3_PROFILE("font sth_draw_text");
glEnable(GL_BLEND);
GLint err = glGetError();
assert(err==GL_NO_ERROR);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
err = glGetError();
assert(err==GL_NO_ERROR);
glDisable(GL_DEPTH_TEST);
err = glGetError();
assert(err==GL_NO_ERROR);
glDisable(GL_CULL_FACE);
sth_begin_draw(stash);
sth_flush_draw(stash);
sth_draw_text(stash, droidRegular,20.f, x, y, "Non-retina font rendering !@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,1);//retinaScale);
if (retinaScale!=1.f)
sth_draw_text(stash, droidRegular,20.f*retinaScale, x, y+20, "Retina font rendering!@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,retinaScale);
sth_flush_draw(stash);
sth_end_draw(stash);
}
if (1)
{
B3_PROFILE("gwen RenderCanvas");
if (pCanvas)
{
glEnable(GL_BLEND);
GLint err = glGetError();
assert(err==GL_NO_ERROR);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
err = glGetError();
assert(err==GL_NO_ERROR);
err = glGetError();
assert(err==GL_NO_ERROR);
glDisable(GL_DEPTH_TEST);
err = glGetError();
assert(err==GL_NO_ERROR);
//glColor4ub(255,0,0,255);
err = glGetError();
assert(err==GL_NO_ERROR);
err = glGetError();
assert(err==GL_NO_ERROR);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
// saveOpenGLState(width,height);//m_glutScreenWidth,m_glutScreenHeight);
err = glGetError();
assert(err==GL_NO_ERROR);
err = glGetError();
assert(err==GL_NO_ERROR);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
err = glGetError();
assert(err==GL_NO_ERROR);
err = glGetError();
assert(err==GL_NO_ERROR);
glEnable(GL_BLEND);
err = glGetError();
assert(err==GL_NO_ERROR);
pCanvas->RenderCanvas();
//restoreOpenGLState();
}
}
window->endRendering();
}
b3ProfileManager::Increment_Frame_Counter();
static bool printStats = true;
if (printStats && !pauseSimulation)
{
static int count = 0;
count--;
if (count<0)
{
count = 100;
{
//B3_PROFILE("processProfileData");
processProfileData(m_profileIterator,false);
}
//b3ProfileManager::dumpAll();
//printStats = false;
} else
{
// printf(".");
}
}
}
//delete pprender;
// render.CleanupShaders();
window->closeWindow();
delete window;
return 0;
}

View File

@@ -1,14 +1,11 @@
project "OpenGL_Window"
project "OpenGL_rendertest"
language "C++" language "C++"
kind "ConsoleApp" kind "StaticLib"
targetdir "../../bin" targetdir "../../bin"
initOpenGL() initOpenGL()
initGlew() initGlew()
@@ -17,61 +14,36 @@
"../../src", "../../src",
} }
links { --links {
"gwen" --}
}
files { files {
"main.cpp", "**.cpp",
"renderscene.cpp", "**.h",
"renderscene.h", "**.c"
"GLInstancingRenderer.cpp",
"GLInstancingRenderer.h",
"GLPrimitiveRenderer.h",
"GLPrimitiveRenderer.cpp",
"SimpleOpenGL3App.cpp",
"SimpleOpenGL3App.h",
"LoadShader.cpp",
"LoadShader.h",
"gwenWindow.cpp",
"gwenWindow.h",
"TwFonts.cpp",
"TwFonts.h",
"GwenOpenGL3CoreRenderer.h",
"../FontFiles/OpenSans.cpp",
"../OpenGLTrueTypeFont/fontstash.cpp",
"../OpenGLTrueTypeFont/fontstash.h",
"../OpenGLTrueTypeFont/opengl_fontstashcallbacks.cpp",
"../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h",
"../../src/Bullet3Geometry/b3ConvexHullComputer.cpp",
"../../src/Bullet3Geometry/b3ConvexHullComputer.h",
"../../src/Bullet3Common/b3AlignedAllocator.cpp",
"../Timing/b3Quickprof.cpp",
"../Timing/b3Quickprof.h",
"../Timing/b3Clock.cpp",
"../Timing/b3Clock.h",
} }
if os.is("Windows") then if not os.is("Windows") then
files{ excludes {
"Win32OpenGLWindow.cpp", "Win32OpenGLWindow.cpp",
"Win32OpenGLWindow.h", "Win32OpenGLWindow.h",
"Win32Window.cpp", "Win32Window.cpp",
"Win32Window.h", "Win32Window.h",
} }
end end
if os.is("Linux") then if not os.is("Linux") then
files { excludes {
"X11OpenGLWindow.cpp", "X11OpenGLWindow.cpp",
"X11OpenGLWindows.h" "X11OpenGLWindows.h"
} }
end end
if os.is("MacOSX") then if os.is("MacOSX") then
links{"Cocoa.framework"} links{"Cocoa.framework"}
files else
excludes
{ {
"../OpenGLWindow/MacOpenGLWindow.h", "../OpenGLWindow/MacOpenGLWindow.h",
"../OpenGLWindow/MacOpenGLWindow.mm", "../OpenGLWindow/MacOpenGLWindow.mm",
} }
end end

View File

@@ -1,199 +0,0 @@
int NUM_OBJECTS_X = 35;
int NUM_OBJECTS_Y = 35;
int NUM_OBJECTS_Z = 35;
float X_GAP = 2.3f;
float Y_GAP = 2.f;
float Z_GAP = 2.3f;
bool keepStaticObjects = false;
#include <stdio.h>
#include "OpenGLInclude.h"
#include "renderscene.h"
#include "GLInstancingRenderer.h"
//#include "LinearMath/b3Quickprof.h"
#include "Bullet3Common/b3Quaternion.h"
#include "Bullet3Common/b3Matrix3x3.h"
//#include "../opencl/gpu_rigidbody_pipeline/b3ConvexUtility.h"
#include "ShapeData.h"
///work-in-progress
///This ReadBulletSample is kept as simple as possible without dependencies to the Bullet SDK.
///It can be used to load .bullet data for other physics SDKs
///For a more complete example how to load and convert Bullet data using the Bullet SDK check out
///the Bullet/Demos/SerializeDemo and Bullet/Serialize/BulletWorldImporter
//using namespace Bullet;
struct GraphicsVertex
{
float xyzw[4];
float normal[3];
float uv[2];
};
struct GraphicsShape
{
const float* m_vertices;
int m_numvertices;
const int* m_indices;
int m_numIndices;
float m_scaling[4];
};
struct InstanceGroup
{
// Bullet::b3CollisionShapeData* m_shape;
int m_collisionShapeIndex;
// b3AlignedObjectArray<bParse::bStructHandle*> m_rigidBodies;
};
#define MY_UNITSPHERE_POINTS 42
static b3Vector3 sUnitSpherePoints[MY_UNITSPHERE_POINTS] =
{
b3Vector3(b3Scalar(0.000000) , b3Scalar(-0.000000),b3Scalar(-1.000000)),
b3Vector3(b3Scalar(0.723608) , b3Scalar(-0.525725),b3Scalar(-0.447219)),
b3Vector3(b3Scalar(-0.276388) , b3Scalar(-0.850649),b3Scalar(-0.447219)),
b3Vector3(b3Scalar(-0.894426) , b3Scalar(-0.000000),b3Scalar(-0.447216)),
b3Vector3(b3Scalar(-0.276388) , b3Scalar(0.850649),b3Scalar(-0.447220)),
b3Vector3(b3Scalar(0.723608) , b3Scalar(0.525725),b3Scalar(-0.447219)),
b3Vector3(b3Scalar(0.276388) , b3Scalar(-0.850649),b3Scalar(0.447220)),
b3Vector3(b3Scalar(-0.723608) , b3Scalar(-0.525725),b3Scalar(0.447219)),
b3Vector3(b3Scalar(-0.723608) , b3Scalar(0.525725),b3Scalar(0.447219)),
b3Vector3(b3Scalar(0.276388) , b3Scalar(0.850649),b3Scalar(0.447219)),
b3Vector3(b3Scalar(0.894426) , b3Scalar(0.000000),b3Scalar(0.447216)),
b3Vector3(b3Scalar(-0.000000) , b3Scalar(0.000000),b3Scalar(1.000000)),
b3Vector3(b3Scalar(0.425323) , b3Scalar(-0.309011),b3Scalar(-0.850654)),
b3Vector3(b3Scalar(-0.162456) , b3Scalar(-0.499995),b3Scalar(-0.850654)),
b3Vector3(b3Scalar(0.262869) , b3Scalar(-0.809012),b3Scalar(-0.525738)),
b3Vector3(b3Scalar(0.425323) , b3Scalar(0.309011),b3Scalar(-0.850654)),
b3Vector3(b3Scalar(0.850648) , b3Scalar(-0.000000),b3Scalar(-0.525736)),
b3Vector3(b3Scalar(-0.525730) , b3Scalar(-0.000000),b3Scalar(-0.850652)),
b3Vector3(b3Scalar(-0.688190) , b3Scalar(-0.499997),b3Scalar(-0.525736)),
b3Vector3(b3Scalar(-0.162456) , b3Scalar(0.499995),b3Scalar(-0.850654)),
b3Vector3(b3Scalar(-0.688190) , b3Scalar(0.499997),b3Scalar(-0.525736)),
b3Vector3(b3Scalar(0.262869) , b3Scalar(0.809012),b3Scalar(-0.525738)),
b3Vector3(b3Scalar(0.951058) , b3Scalar(0.309013),b3Scalar(0.000000)),
b3Vector3(b3Scalar(0.951058) , b3Scalar(-0.309013),b3Scalar(0.000000)),
b3Vector3(b3Scalar(0.587786) , b3Scalar(-0.809017),b3Scalar(0.000000)),
b3Vector3(b3Scalar(0.000000) , b3Scalar(-1.000000),b3Scalar(0.000000)),
b3Vector3(b3Scalar(-0.587786) , b3Scalar(-0.809017),b3Scalar(0.000000)),
b3Vector3(b3Scalar(-0.951058) , b3Scalar(-0.309013),b3Scalar(-0.000000)),
b3Vector3(b3Scalar(-0.951058) , b3Scalar(0.309013),b3Scalar(-0.000000)),
b3Vector3(b3Scalar(-0.587786) , b3Scalar(0.809017),b3Scalar(-0.000000)),
b3Vector3(b3Scalar(-0.000000) , b3Scalar(1.000000),b3Scalar(-0.000000)),
b3Vector3(b3Scalar(0.587786) , b3Scalar(0.809017),b3Scalar(-0.000000)),
b3Vector3(b3Scalar(0.688190) , b3Scalar(-0.499997),b3Scalar(0.525736)),
b3Vector3(b3Scalar(-0.262869) , b3Scalar(-0.809012),b3Scalar(0.525738)),
b3Vector3(b3Scalar(-0.850648) , b3Scalar(0.000000),b3Scalar(0.525736)),
b3Vector3(b3Scalar(-0.262869) , b3Scalar(0.809012),b3Scalar(0.525738)),
b3Vector3(b3Scalar(0.688190) , b3Scalar(0.499997),b3Scalar(0.525736)),
b3Vector3(b3Scalar(0.525730) , b3Scalar(0.000000),b3Scalar(0.850652)),
b3Vector3(b3Scalar(0.162456) , b3Scalar(-0.499995),b3Scalar(0.850654)),
b3Vector3(b3Scalar(-0.425323) , b3Scalar(-0.309011),b3Scalar(0.850654)),
b3Vector3(b3Scalar(-0.425323) , b3Scalar(0.309011),b3Scalar(0.850654)),
b3Vector3(b3Scalar(0.162456) , b3Scalar(0.499995),b3Scalar(0.850654))
};
void createSceneProgrammatically(GLInstancingRenderer& renderer)
{
int strideInBytes = sizeof(float)*9;
bool noHeightField = false;
int barrelShapeIndex = -1;
int cubeShapeIndex = -1;
int tetraShapeIndex = -1;
float position[4]={0,0,0,0};
b3Quaternion born(b3Vector3(1,0,0),B3_PI*0.25*0.5);
float orn[4] = {0,0,0,1};
// float rotOrn[4] = {born.getX(),born.getY(),born.getZ(),born.getW()};//
float rotOrn[4] ={0,0,0,1};
float color[4] = {1,1,1,1};
int index=0;
float cubeScaling[4] = {1,1,1,1};
{
int numVertices = sizeof(cube_vertices)/strideInBytes;
int numIndices = sizeof(cube_indices)/sizeof(int);
cubeShapeIndex = renderer.registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
}
if (1)
for (int i=0;i<NUM_OBJECTS_X;i++)
{
for (int j=0;j<NUM_OBJECTS_Y;j++)
{
int k=0;
for (;k<NUM_OBJECTS_Z;k++)
{
float mass = 1.f;//j? 1.f : 0.f;
position[0]=(i*X_GAP-NUM_OBJECTS_X/2)+(j&1);
position[1]=1+(j*Y_GAP);//-NUM_OBJECTS_Y/2);
position[2]=(k*Z_GAP-NUM_OBJECTS_Z/2)+(j&1);
position[3] = 0.f;
renderer.registerGraphicsInstance(cubeShapeIndex,position,rotOrn,color,cubeScaling);
index++;
}
}
}
{
{
int numVertices = sizeof(tetra_vertices)/strideInBytes;
int numIndices = sizeof(tetra_indices)/sizeof(int);
tetraShapeIndex = renderer.registerShape(&tetra_vertices[0],numVertices,tetra_indices,numIndices);
}
{
float groundScaling[4] = {2.5,2,2.5,1};
for (int i=0;i<50;i++)
for (int j=0;j<50;j++)
if (1)
{
void* ptr = (void*) index;
float posnew[4];
posnew[0] = i*5.0-120;
posnew[1] = 0;
posnew[2] = j*5.0-120;
posnew[3] = 1.f;
color[0] = 1.f;
color[1] = 0.f;
color[2] = 0.f;
renderer.registerGraphicsInstance(tetraShapeIndex,posnew,orn,color,groundScaling);
}
}
}
}

View File

@@ -1,7 +0,0 @@
#ifndef RENDER_SCENE_H
#define RENDER_SCENE_H
void createSceneProgrammatically(class GLInstancingRenderer& renderer);
#endif//

View File

@@ -88,6 +88,8 @@
include "../Demos3/Wavefront" include "../Demos3/Wavefront"
include "../btgui/MultiThreading" include "../btgui/MultiThreading"
include "../btgui/OpenGLWindow"
include "../Demos3/ImplicitCloth" include "../Demos3/ImplicitCloth"
include "../Demos3/SimpleOpenGL3" include "../Demos3/SimpleOpenGL3"
@@ -109,6 +111,11 @@ include "../Demos3/SimpleOpenGL3"
include "../test/OpenCL/RadixSortBenchmark" include "../test/OpenCL/RadixSortBenchmark"
include "../src/BulletDynamics"
include "../src/BulletCollision"
include "../src/LinearMath"
include "../Demos3/bullet2/BasicDemo"
include "../src/Bullet3Dynamics" include "../src/Bullet3Dynamics"
include "../src/Bullet3Common" include "../src/Bullet3Common"
include "../src/Bullet3Geometry" include "../src/Bullet3Geometry"

View File

@@ -34,7 +34,7 @@ subject to the following restrictions:
#include "LinearMath/btSerializer.h" #include "LinearMath/btSerializer.h"
#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h" #include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h" #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
#include "BulletCollision/Gimpact/btGImpactShape.h"
//#define DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION //#define DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
@@ -387,14 +387,7 @@ void btCollisionWorld::rayTestSingleInternal(const btTransform& rayFromTrans,con
rcb.m_hitFraction = resultCallback.m_closestHitFraction; rcb.m_hitFraction = resultCallback.m_closestHitFraction;
triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal); triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal);
} }
else if(collisionShape->getShapeType()==GIMPACT_SHAPE_PROXYTYPE) else
{
btGImpactMeshShape* concaveShape = (btGImpactMeshShape*)collisionShape;
BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObjectWrap->getCollisionObject(),concaveShape, colObjWorldTransform);
rcb.m_hitFraction = resultCallback.m_closestHitFraction;
concaveShape->processAllTrianglesRay(&rcb,rayFromLocal,rayToLocal);
}else
{ {
//generic (slower) case //generic (slower) case
btConcaveShape* concaveShape = (btConcaveShape*)collisionShape; btConcaveShape* concaveShape = (btConcaveShape*)collisionShape;

View File

@@ -1,405 +0,0 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
Draft high-level generic physics C-API. For low-level access, use the physics SDK native API's.
Work in progress, functionality will be added on demand.
If possible, use the richer Bullet C++ API, by including <src/btBulletDynamicsCommon.h>
*/
#include "Bullet-C-Api.h"
#include "btBulletDynamicsCommon.h"
#include "LinearMath/btAlignedAllocator.h"
#include "LinearMath/btVector3.h"
#include "LinearMath/btScalar.h"
#include "LinearMath/btMatrix3x3.h"
#include "LinearMath/btTransform.h"
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
#include "BulletCollision/CollisionShapes/btTriangleShape.h"
#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
#include "BulletCollision/NarrowPhaseCollision/btPointCollector.h"
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
#include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
#include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h"
#include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h"
#include "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h"
/*
Create and Delete a Physics SDK
*/
struct btPhysicsSdk
{
// btDispatcher* m_dispatcher;
// btOverlappingPairCache* m_pairCache;
// btConstraintSolver* m_constraintSolver
btVector3 m_worldAabbMin;
btVector3 m_worldAabbMax;
//todo: version, hardware/optimization settings etc?
btPhysicsSdk()
:m_worldAabbMin(-1000,-1000,-1000),
m_worldAabbMax(1000,1000,1000)
{
}
};
plPhysicsSdkHandle plNewBulletSdk()
{
void* mem = btAlignedAlloc(sizeof(btPhysicsSdk),16);
return (plPhysicsSdkHandle)new (mem)btPhysicsSdk;
}
void plDeletePhysicsSdk(plPhysicsSdkHandle physicsSdk)
{
btPhysicsSdk* phys = reinterpret_cast<btPhysicsSdk*>(physicsSdk);
btAlignedFree(phys);
}
/* Dynamics World */
plDynamicsWorldHandle plCreateDynamicsWorld(plPhysicsSdkHandle physicsSdkHandle)
{
btPhysicsSdk* physicsSdk = reinterpret_cast<btPhysicsSdk*>(physicsSdkHandle);
void* mem = btAlignedAlloc(sizeof(btDefaultCollisionConfiguration),16);
btDefaultCollisionConfiguration* collisionConfiguration = new (mem)btDefaultCollisionConfiguration();
mem = btAlignedAlloc(sizeof(btCollisionDispatcher),16);
btDispatcher* dispatcher = new (mem)btCollisionDispatcher(collisionConfiguration);
mem = btAlignedAlloc(sizeof(btAxisSweep3),16);
btBroadphaseInterface* pairCache = new (mem)btAxisSweep3(physicsSdk->m_worldAabbMin,physicsSdk->m_worldAabbMax);
mem = btAlignedAlloc(sizeof(btSequentialImpulseConstraintSolver),16);
btConstraintSolver* constraintSolver = new(mem) btSequentialImpulseConstraintSolver();
mem = btAlignedAlloc(sizeof(btDiscreteDynamicsWorld),16);
return (plDynamicsWorldHandle) new (mem)btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration);
}
void plDeleteDynamicsWorld(plDynamicsWorldHandle world)
{
//todo: also clean up the other allocations, axisSweep, pairCache,dispatcher,constraintSolver,collisionConfiguration
btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
btAlignedFree(dynamicsWorld);
}
void plStepSimulation(plDynamicsWorldHandle world, plReal timeStep)
{
btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
btAssert(dynamicsWorld);
dynamicsWorld->stepSimulation(timeStep);
}
void plAddRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object)
{
btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
btAssert(dynamicsWorld);
btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
btAssert(body);
dynamicsWorld->addRigidBody(body);
}
void plRemoveRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object)
{
btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
btAssert(dynamicsWorld);
btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
btAssert(body);
dynamicsWorld->removeRigidBody(body);
}
/* Rigid Body */
plRigidBodyHandle plCreateRigidBody( void* user_data, float mass, plCollisionShapeHandle cshape )
{
btTransform trans;
trans.setIdentity();
btVector3 localInertia(0,0,0);
btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
btAssert(shape);
if (mass)
{
shape->calculateLocalInertia(mass,localInertia);
}
void* mem = btAlignedAlloc(sizeof(btRigidBody),16);
btRigidBody::btRigidBodyConstructionInfo rbci(mass, 0,shape,localInertia);
btRigidBody* body = new (mem)btRigidBody(rbci);
body->setWorldTransform(trans);
body->setUserPointer(user_data);
return (plRigidBodyHandle) body;
}
void plDeleteRigidBody(plRigidBodyHandle cbody)
{
btRigidBody* body = reinterpret_cast< btRigidBody* >(cbody);
btAssert(body);
btAlignedFree( body);
}
/* Collision Shape definition */
plCollisionShapeHandle plNewSphereShape(plReal radius)
{
void* mem = btAlignedAlloc(sizeof(btSphereShape),16);
return (plCollisionShapeHandle) new (mem)btSphereShape(radius);
}
plCollisionShapeHandle plNewBoxShape(plReal x, plReal y, plReal z)
{
void* mem = btAlignedAlloc(sizeof(btBoxShape),16);
return (plCollisionShapeHandle) new (mem)btBoxShape(btVector3(x,y,z));
}
plCollisionShapeHandle plNewCapsuleShape(plReal radius, plReal height)
{
//capsule is convex hull of 2 spheres, so use btMultiSphereShape
const int numSpheres = 2;
btVector3 positions[numSpheres] = {btVector3(0,height,0),btVector3(0,-height,0)};
btScalar radi[numSpheres] = {radius,radius};
void* mem = btAlignedAlloc(sizeof(btMultiSphereShape),16);
return (plCollisionShapeHandle) new (mem)btMultiSphereShape(positions,radi,numSpheres);
}
plCollisionShapeHandle plNewConeShape(plReal radius, plReal height)
{
void* mem = btAlignedAlloc(sizeof(btConeShape),16);
return (plCollisionShapeHandle) new (mem)btConeShape(radius,height);
}
plCollisionShapeHandle plNewCylinderShape(plReal radius, plReal height)
{
void* mem = btAlignedAlloc(sizeof(btCylinderShape),16);
return (plCollisionShapeHandle) new (mem)btCylinderShape(btVector3(radius,height,radius));
}
/* Convex Meshes */
plCollisionShapeHandle plNewConvexHullShape()
{
void* mem = btAlignedAlloc(sizeof(btConvexHullShape),16);
return (plCollisionShapeHandle) new (mem)btConvexHullShape();
}
/* Concave static triangle meshes */
plMeshInterfaceHandle plNewMeshInterface()
{
return 0;
}
plCollisionShapeHandle plNewCompoundShape()
{
void* mem = btAlignedAlloc(sizeof(btCompoundShape),16);
return (plCollisionShapeHandle) new (mem)btCompoundShape();
}
void plAddChildShape(plCollisionShapeHandle compoundShapeHandle,plCollisionShapeHandle childShapeHandle, plVector3 childPos,plQuaternion childOrn)
{
btCollisionShape* colShape = reinterpret_cast<btCollisionShape*>(compoundShapeHandle);
btAssert(colShape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE);
btCompoundShape* compoundShape = reinterpret_cast<btCompoundShape*>(colShape);
btCollisionShape* childShape = reinterpret_cast<btCollisionShape*>(childShapeHandle);
btTransform localTrans;
localTrans.setIdentity();
localTrans.setOrigin(btVector3(childPos[0],childPos[1],childPos[2]));
localTrans.setRotation(btQuaternion(childOrn[0],childOrn[1],childOrn[2],childOrn[3]));
compoundShape->addChildShape(localTrans,childShape);
}
void plSetEuler(plReal yaw,plReal pitch,plReal roll, plQuaternion orient)
{
btQuaternion orn;
orn.setEuler(yaw,pitch,roll);
orient[0] = orn.getX();
orient[1] = orn.getY();
orient[2] = orn.getZ();
orient[3] = orn.getW();
}
// extern void plAddTriangle(plMeshInterfaceHandle meshHandle, plVector3 v0,plVector3 v1,plVector3 v2);
// extern plCollisionShapeHandle plNewStaticTriangleMeshShape(plMeshInterfaceHandle);
void plAddVertex(plCollisionShapeHandle cshape, plReal x,plReal y,plReal z)
{
btCollisionShape* colShape = reinterpret_cast<btCollisionShape*>( cshape);
(void)colShape;
btAssert(colShape->getShapeType()==CONVEX_HULL_SHAPE_PROXYTYPE);
btConvexHullShape* convexHullShape = reinterpret_cast<btConvexHullShape*>( cshape);
convexHullShape->addPoint(btVector3(x,y,z));
}
void plDeleteShape(plCollisionShapeHandle cshape)
{
btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
btAssert(shape);
btAlignedFree(shape);
}
void plSetScaling(plCollisionShapeHandle cshape, plVector3 cscaling)
{
btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
btAssert(shape);
btVector3 scaling(cscaling[0],cscaling[1],cscaling[2]);
shape->setLocalScaling(scaling);
}
void plSetPosition(plRigidBodyHandle object, const plVector3 position)
{
btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
btAssert(body);
btVector3 pos(position[0],position[1],position[2]);
btTransform worldTrans = body->getWorldTransform();
worldTrans.setOrigin(pos);
body->setWorldTransform(worldTrans);
}
void plSetOrientation(plRigidBodyHandle object, const plQuaternion orientation)
{
btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
btAssert(body);
btQuaternion orn(orientation[0],orientation[1],orientation[2],orientation[3]);
btTransform worldTrans = body->getWorldTransform();
worldTrans.setRotation(orn);
body->setWorldTransform(worldTrans);
}
void plSetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix)
{
btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
btAssert(body);
btTransform& worldTrans = body->getWorldTransform();
worldTrans.setFromOpenGLMatrix(matrix);
}
void plGetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix)
{
btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
btAssert(body);
body->getWorldTransform().getOpenGLMatrix(matrix);
}
void plGetPosition(plRigidBodyHandle object,plVector3 position)
{
btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
btAssert(body);
const btVector3& pos = body->getWorldTransform().getOrigin();
position[0] = pos.getX();
position[1] = pos.getY();
position[2] = pos.getZ();
}
void plGetOrientation(plRigidBodyHandle object,plQuaternion orientation)
{
btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
btAssert(body);
const btQuaternion& orn = body->getWorldTransform().getRotation();
orientation[0] = orn.getX();
orientation[1] = orn.getY();
orientation[2] = orn.getZ();
orientation[3] = orn.getW();
}
//plRigidBodyHandle plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal);
// extern plRigidBodyHandle plObjectCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal);
double plNearestPoints(float p1[3], float p2[3], float p3[3], float q1[3], float q2[3], float q3[3], float *pa, float *pb, float normal[3])
{
btVector3 vp(p1[0], p1[1], p1[2]);
btTriangleShape trishapeA(vp,
btVector3(p2[0], p2[1], p2[2]),
btVector3(p3[0], p3[1], p3[2]));
trishapeA.setMargin(0.000001f);
btVector3 vq(q1[0], q1[1], q1[2]);
btTriangleShape trishapeB(vq,
btVector3(q2[0], q2[1], q2[2]),
btVector3(q3[0], q3[1], q3[2]));
trishapeB.setMargin(0.000001f);
// btVoronoiSimplexSolver sGjkSimplexSolver;
// btGjkEpaPenetrationDepthSolver penSolverPtr;
static btSimplexSolverInterface sGjkSimplexSolver;
sGjkSimplexSolver.reset();
static btGjkEpaPenetrationDepthSolver Solver0;
static btMinkowskiPenetrationDepthSolver Solver1;
btConvexPenetrationDepthSolver* Solver = NULL;
Solver = &Solver1;
btGjkPairDetector convexConvex(&trishapeA ,&trishapeB,&sGjkSimplexSolver,Solver);
convexConvex.m_catchDegeneracies = 1;
// btGjkPairDetector convexConvex(&trishapeA ,&trishapeB,&sGjkSimplexSolver,0);
btPointCollector gjkOutput;
btGjkPairDetector::ClosestPointInput input;
btTransform tr;
tr.setIdentity();
input.m_transformA = tr;
input.m_transformB = tr;
convexConvex.getClosestPoints(input, gjkOutput, 0);
if (gjkOutput.m_hasResult)
{
pb[0] = pa[0] = gjkOutput.m_pointInWorld[0];
pb[1] = pa[1] = gjkOutput.m_pointInWorld[1];
pb[2] = pa[2] = gjkOutput.m_pointInWorld[2];
pb[0]+= gjkOutput.m_normalOnBInWorld[0] * gjkOutput.m_distance;
pb[1]+= gjkOutput.m_normalOnBInWorld[1] * gjkOutput.m_distance;
pb[2]+= gjkOutput.m_normalOnBInWorld[2] * gjkOutput.m_distance;
normal[0] = gjkOutput.m_normalOnBInWorld[0];
normal[1] = gjkOutput.m_normalOnBInWorld[1];
normal[2] = gjkOutput.m_normalOnBInWorld[2];
return gjkOutput.m_distance;
}
return -1.0f;
}