Move some code from Branches/OpenCL to trunk, related to threading and OpenCL:

Added Demos/ThreadingDemo showing how to use the cross-platform btThreadSupportInterface under Windows.
Added Demos/ParticlesOpenCL showing how to run the NVidia particle demo under OpenCL implementations by AMD, NVidia and MiniCL (CPU)
This commit is contained in:
erwin.coumans
2010-06-24 22:54:00 +00:00
parent b2798eaae5
commit 498da0721b
36 changed files with 4020 additions and 38 deletions

View File

@@ -12,6 +12,7 @@
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Extras/ConvexHull
)

View File

@@ -85,7 +85,9 @@ m_idle(false),
m_enableshadows(false),
m_sundirection(btVector3(1,-2,1)*1000),
m_defaultContactProcessingThreshold(BT_LARGE_FLOAT)
m_defaultContactProcessingThreshold(BT_LARGE_FLOAT),
m_frustumZNear(1.f),
m_frustumZFar(10000.f)
{
#ifndef BT_NO_PROFILE
m_profileIterator = CProfileManager::Get_Iterator();
@@ -245,10 +247,12 @@ void DemoApplication::updateCamera() {
{
if (m_glutScreenWidth > m_glutScreenHeight)
{
glFrustum (-aspect, aspect, -1.0, 1.0, 1.0, 10000.0);
// glFrustum (-aspect, aspect, -1.0, 1.0, 1.0, 10000.0);
glFrustum (-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar);
} else
{
glFrustum (-1.0, 1.0, -aspect, aspect, 1.0, 10000.0);
// glFrustum (-1.0, 1.0, -aspect, aspect, 1.0, 10000.0);
glFrustum (-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

View File

@@ -80,6 +80,9 @@ protected:
int m_glutScreenWidth;
int m_glutScreenHeight;
float m_frustumZNear;
float m_frustumZFar;
int m_ortho;
float m_ShootBoxInitialSpeed;
@@ -178,6 +181,11 @@ public:
return btScalar(16666.);
#endif
}
void setFrustumZPlanes(float zNear, float zFar)
{
m_frustumZNear = zNear;
m_frustumZFar = zFar;
}
///glut callbacks

View File

@@ -195,7 +195,8 @@ GL_DialogWindow* GL_DialogDynamicsWorld::createDialog(int horPos,int vertPos,int
btRigidBody* body = new btRigidBody(rbInfo);
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(btScalar(horPos-m_screenWidth/2+dialogWidth/2), btScalar(vertPos+m_screenHeight/2.+dialogHeight/2),btScalar(0.)));
// trans.setOrigin(btVector3(btScalar(horPos-m_screenWidth/2+dialogWidth/2), btScalar(vertPos+m_screenHeight/2.+dialogHeight/2),btScalar(0.)));
trans.setOrigin(btVector3(btScalar(horPos-m_screenWidth/2+dialogWidth/2), btScalar(vertPos-m_screenHeight/2.+dialogHeight/2),btScalar(0.)));
@@ -215,7 +216,7 @@ GL_DialogWindow* GL_DialogDynamicsWorld::createDialog(int horPos,int vertPos,int
}
GL_SliderControl* GL_DialogDynamicsWorld::createSlider(GL_DialogWindow* dialog, const char* sliderText)
GL_SliderControl* GL_DialogDynamicsWorld::createSlider(GL_DialogWindow* dialog, const char* sliderText, btScalar initialFraction)
{
btBox2dShape* boxShape = new btBox2dShape(btVector3(6.f,6.f,0.4f));
btScalar mass = .1f;
@@ -225,7 +226,10 @@ GL_SliderControl* GL_DialogDynamicsWorld::createSlider(GL_DialogWindow* dialog,
btRigidBody* body = new btRigidBody(rbInfo);
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(dialog->getDialogHorPos()-m_screenWidth/2.f+dialog->getDialogWidth()/2.f, dialog->getDialogVertPos()+m_screenHeight/2.f+dialog->getDialogHeight()/2+dialog->getNumControls()*20.f,-0.2f));
int sliderX = dialog->getDialogHorPos() - m_screenWidth/2 + dialog->getDialogWidth()/2;
// int sliderY = dialog->getDialogVertPos() + m_screenHeight/2 + dialog->getDialogHeight()/2 + dialog->getNumControls()*20;
int sliderY = dialog->getDialogVertPos() - m_screenHeight/2 + dialog->getDialogHeight()/2 + dialog->getNumControls()*20;
trans.setOrigin(btVector3(sliderX, sliderY,-0.2f));
body->setWorldTransform(trans);
//body->setDamping(0.999,0.99);
@@ -245,7 +249,9 @@ GL_SliderControl* GL_DialogDynamicsWorld::createSlider(GL_DialogWindow* dialog,
btTransform frameInA;
frameInA.setIdentity();
btVector3 offset(btVector3(-dialog->getDialogWidth()/2.f+16.f,-dialog->getDialogHeight()/2.f+dialog->getNumControls()*20.f+36.f,0.2f));
int offsX = -dialog->getDialogWidth()/2 + 16;
int offsY = -dialog->getDialogHeight()/2 + dialog->getNumControls()*20 + 36;
btVector3 offset(btVector3(offsX, offsY, 0.2f));
frameInA.setOrigin(offset);
@@ -253,8 +259,13 @@ GL_SliderControl* GL_DialogDynamicsWorld::createSlider(GL_DialogWindow* dialog,
frameInB.setIdentity();
//frameInB.setOrigin(-offset/2);
btScalar lowerLimit = 80.f;
btScalar upperLimit = 170.f;
// btScalar lowerLimit = 80.f;
// btScalar upperLimit = 170.f;
btScalar lowerLimit = 141.f;
btScalar upperLimit = 227.f;
btScalar actualLimit = lowerLimit+initialFraction*(upperLimit-lowerLimit);
#if 0
bool useFrameA = false;
@@ -264,19 +275,24 @@ GL_SliderControl* GL_DialogDynamicsWorld::createSlider(GL_DialogWindow* dialog,
constraint->setLimit(0,lowerLimit,upperLimit);
#else
btSliderConstraint* sliderConstraint = new btSliderConstraint(*dialogBody,*body,frameInA,frameInB,true);//useFrameA);
sliderConstraint->setLowerLinLimit(lowerLimit);
sliderConstraint->setUpperLinLimit(upperLimit);
sliderConstraint->setLowerLinLimit(actualLimit);
sliderConstraint->setUpperLinLimit(actualLimit);
m_dynamicsWorld->addConstraint(sliderConstraint,true);
#endif
GL_SliderControl* slider = new GL_SliderControl(sliderText, body,dialog,lowerLimit,upperLimit, sliderConstraint);
body->setUserPointer(slider);
dialog->addControl(slider);
slider->m_fraction = initialFraction;
return slider;
}
GL_ToggleControl* GL_DialogDynamicsWorld::createToggle(GL_DialogWindow* dialog, const char* toggleText)
{
@@ -289,7 +305,11 @@ GL_ToggleControl* GL_DialogDynamicsWorld::createToggle(GL_DialogWindow* dialog,
btRigidBody* body = new btRigidBody(rbInfo);
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(dialog->getDialogHorPos()-m_screenWidth/2.f+dialog->getDialogWidth()/2.f, dialog->getDialogVertPos()+m_screenHeight/2.f+dialog->getDialogHeight()/2+dialog->getNumControls()*20.f,-0.2f));
int toggleX = dialog->getDialogHorPos() - m_screenWidth/2 + dialog->getDialogWidth()/2;
// int toggleY = dialog->getDialogVertPos() + m_screenHeight/2 + dialog->getDialogHeight()/2 + dialog->getNumControls()*20;
int toggleY = dialog->getDialogVertPos() - m_screenHeight/2 + dialog->getDialogHeight()/2 + dialog->getNumControls()*20;
trans.setOrigin(btVector3(toggleX, toggleY, -0.2f));
body->setWorldTransform(trans);
body->setDamping(0.999f,0.99f);
@@ -737,3 +757,5 @@ void GL_DialogDynamicsWorld::mouseMotionFunc(int x,int y)
}

View File

@@ -78,7 +78,7 @@ public:
GL_ToggleControl* createToggle(GL_DialogWindow* dialog, const char* toggleText);
GL_SliderControl* createSlider(GL_DialogWindow* dialog, const char* sliderText);
GL_SliderControl* createSlider(GL_DialogWindow* dialog, const char* sliderText, btScalar initialFraction = btScalar(0.5f));
virtual void draw(btScalar timeStep);

View File

@@ -20,6 +20,8 @@ subject to the following restrictions:
#include "GLDebugFont.h"
#include "btBulletDynamicsCommon.h"
#include <stdio.h> // for sprintf()
#define USE_ARRAYS 1
@@ -305,7 +307,6 @@ void GL_ToggleControl::draw(int& parentHorPos2,int& parentVertPos2,btScalar delt
}
void GL_SliderControl::draw(int& parentHorPos2,int& parentVertPos2,btScalar deltaTime)
{
@@ -318,7 +319,17 @@ void GL_SliderControl::draw(int& parentHorPos2,int& parentVertPos2,btScalar delt
unsigned int grey = 0xff6f6f6f;
int borderSize = 2;
unsigned int white = 0xffefefef;
drawRect(parentHorPos2+80+borderSize, parentVertPos2+borderSize, parentHorPos2+m_parentWindow->getDialogWidth()-16-borderSize, parentVertPos2+2-borderSize, white,white,white,white);
int sliderPosS = parentHorPos2+150+borderSize;
int sliderPosE = parentHorPos2+m_parentWindow->getDialogWidth()-40-borderSize;
int sliderPos = controlHorPos;
if(sliderPos < sliderPosS) sliderPos = sliderPosS;
if(sliderPos > sliderPosE) sliderPos = sliderPosE;
// drawRect(parentHorPos2+80+borderSize, parentVertPos2+borderSize, parentHorPos2+m_parentWindow->getDialogWidth()-16-borderSize, parentVertPos2+2-borderSize, white,white,white,white);
drawRect( sliderPosS,
parentVertPos2+borderSize,
sliderPosE,
parentVertPos2+2-borderSize,
white,white,white,white);
drawRect(parentHorPos, parentVertPos, parentHorPos+16, parentVertPos+16, grey, grey, grey, grey);
@@ -329,8 +340,19 @@ void GL_SliderControl::draw(int& parentHorPos2,int& parentVertPos2,btScalar delt
btVector3 rgb(1,1,1);
GLDebugDrawStringInternal(parentHorPos2,parentVertPos2+8,m_sliderText,rgb);
btSliderConstraint* pSlider = (btSliderConstraint*)m_constraint;
btScalar currPos = pSlider->getLinearPos();
// if(currPos < pSlider->getLowerLinLimit()) currPos = pSlider->getLowerLinLimit();
// if(currPos > pSlider->getUpperLinLimit()) currPos = pSlider->getUpperLinLimit();
// m_fraction = (currPos - pSlider->getLowerLinLimit()) / (pSlider->getUpperLinLimit() - pSlider->getLowerLinLimit());
m_fraction = (btScalar)(sliderPos - sliderPosS) / (btScalar)(sliderPosE - sliderPosS);
char tmpBuf[256];
sprintf(tmpBuf, "%s %3d%%", m_sliderText, (int)(m_fraction * 100.f));
// GLDebugDrawStringInternal(parentHorPos2,parentVertPos2+8,m_sliderText,rgb);
GLDebugDrawStringInternal(parentHorPos2,parentVertPos2+8, tmpBuf, rgb);
parentVertPos2+=20;
}

View File

@@ -123,6 +123,7 @@ struct GL_SliderControl : public GL_DialogControl
btScalar m_lowerLimit;
btScalar m_upperLimit;
btTypedConstraint* m_constraint;
btScalar m_fraction;
const char* m_sliderText;
public:
@@ -140,7 +141,7 @@ public:
virtual void draw(int& parentHorPos,int& parentVertPos,btScalar deltaTime);
btScalar btGetFraction();
btScalar btGetFraction() { return m_fraction; }
btScalar getLowerLimit()
{