Added Height Field Fluid Demo to Bullet. All code stored in the Demos/HeightFieldFluidDemo directory for now.
Please see HfFluidDemo.cpp for examples of how to use the height field fluid along with buoyant collision shapes. The implementation is still lacking in my ways: 1) Need to complete more collision algorithms for buoyant collision shapes 2) Support compound buoyant shapes 3) The buoyancy model isn't that great 4) Fluid volume can be lost over time
This commit is contained in:
@@ -82,7 +82,8 @@ m_sundirection(btVector3(1,-2,1)*1000)
|
||||
m_profileIterator = CProfileManager::Get_Iterator();
|
||||
#endif //BT_NO_PROFILE
|
||||
|
||||
m_shapeDrawer.enableTexture(true);
|
||||
m_shapeDrawer = new GL_ShapeDrawer ();
|
||||
m_shapeDrawer->enableTexture(true);
|
||||
m_enableshadows = false;
|
||||
}
|
||||
|
||||
@@ -97,9 +98,18 @@ DemoApplication::~DemoApplication()
|
||||
if (m_shootBoxShape)
|
||||
delete m_shootBoxShape;
|
||||
|
||||
if (m_shapeDrawer)
|
||||
delete m_shapeDrawer;
|
||||
}
|
||||
|
||||
|
||||
void DemoApplication::overrideGLShapeDrawer (GL_ShapeDrawer* shapeDrawer)
|
||||
{
|
||||
shapeDrawer->enableTexture (m_shapeDrawer->hasTextureEnabled());
|
||||
delete m_shapeDrawer;
|
||||
m_shapeDrawer = shapeDrawer;
|
||||
}
|
||||
|
||||
void DemoApplication::myinit(void)
|
||||
{
|
||||
|
||||
@@ -298,7 +308,7 @@ void DemoApplication::keyboardCallback(unsigned char key, int x, int y)
|
||||
case 'x' : zoomOut(); break;
|
||||
case 'i' : toggleIdle(); break;
|
||||
case 'g' : m_enableshadows=!m_enableshadows;break;
|
||||
case 'u' : m_shapeDrawer.enableTexture(!m_shapeDrawer.enableTexture(false));break;
|
||||
case 'u' : m_shapeDrawer->enableTexture(!m_shapeDrawer->enableTexture(false));break;
|
||||
case 'h':
|
||||
if (m_debugMode & btIDebugDraw::DBG_NoHelpText)
|
||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_NoHelpText);
|
||||
@@ -510,7 +520,19 @@ void DemoApplication::displayCallback()
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DemoApplication::setShootBoxShape ()
|
||||
{
|
||||
if (!m_shootBoxShape)
|
||||
{
|
||||
//#define TEST_UNIFORM_SCALING_SHAPE 1
|
||||
#ifdef TEST_UNIFORM_SCALING_SHAPE
|
||||
btConvexShape* childShape = new btBoxShape(btVector3(1.f,1.f,1.f));
|
||||
m_shootBoxShape = new btUniformScalingShape(childShape,0.5f);
|
||||
#else
|
||||
m_shootBoxShape = new btSphereShape(1.f);//BoxShape(btVector3(1.f,1.f,1.f));
|
||||
#endif//
|
||||
}
|
||||
}
|
||||
|
||||
void DemoApplication::shootBox(const btVector3& destination)
|
||||
{
|
||||
@@ -523,16 +545,7 @@ void DemoApplication::shootBox(const btVector3& destination)
|
||||
btVector3 camPos = getCameraPosition();
|
||||
startTransform.setOrigin(camPos);
|
||||
|
||||
if (!m_shootBoxShape)
|
||||
{
|
||||
//#define TEST_UNIFORM_SCALING_SHAPE 1
|
||||
#ifdef TEST_UNIFORM_SCALING_SHAPE
|
||||
btConvexShape* childShape = new btBoxShape(btVector3(1.f,1.f,1.f));
|
||||
m_shootBoxShape = new btUniformScalingShape(childShape,0.5f);
|
||||
#else
|
||||
m_shootBoxShape = new btSphereShape(1.f);//BoxShape(btVector3(1.f,1.f,1.f));
|
||||
#endif//
|
||||
}
|
||||
setShootBoxShape ();
|
||||
|
||||
btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_shootBoxShape);
|
||||
|
||||
@@ -981,9 +994,9 @@ void DemoApplication::renderscene(int pass)
|
||||
|
||||
switch(pass)
|
||||
{
|
||||
case 0: m_shapeDrawer.drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode(),aabbMin,aabbMax);break;
|
||||
case 1: m_shapeDrawer.drawShadow(m,m_sundirection*rot,colObj->getCollisionShape(),aabbMin,aabbMax);break;
|
||||
case 2: m_shapeDrawer.drawOpenGL(m,colObj->getCollisionShape(),wireColor*0.3,0,aabbMin,aabbMax);break;
|
||||
case 0: m_shapeDrawer->drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode(),aabbMin,aabbMax);break;
|
||||
case 1: m_shapeDrawer->drawShadow(m,m_sundirection*rot,colObj->getCollisionShape(),aabbMin,aabbMax);break;
|
||||
case 2: m_shapeDrawer->drawOpenGL(m,colObj->getCollisionShape(),wireColor*0.3,0,aabbMin,aabbMax);break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class DemoApplication
|
||||
void showProfileInfo(float& xOffset,float& yStart, float yIncr);
|
||||
void renderscene(int pass);
|
||||
|
||||
GL_ShapeDrawer m_shapeDrawer;
|
||||
GL_ShapeDrawer* m_shapeDrawer;
|
||||
bool m_enableshadows;
|
||||
btVector3 m_sundirection;
|
||||
|
||||
@@ -102,15 +102,16 @@ public:
|
||||
|
||||
}
|
||||
|
||||
void overrideGLShapeDrawer (GL_ShapeDrawer* shapeDrawer);
|
||||
|
||||
void setOrthographicProjection();
|
||||
void resetPerspectiveProjection();
|
||||
|
||||
bool setTexturing(bool enable) { return(m_shapeDrawer.enableTexture(enable)); }
|
||||
bool setTexturing(bool enable) { return(m_shapeDrawer->enableTexture(enable)); }
|
||||
bool setShadows(bool enable) { bool p=m_enableshadows;m_enableshadows=enable;return(p); }
|
||||
bool getTexturing() const
|
||||
{
|
||||
return m_shapeDrawer.hasTextureEnabled();
|
||||
return m_shapeDrawer->hasTextureEnabled();
|
||||
}
|
||||
bool getShadows() const
|
||||
{
|
||||
@@ -176,6 +177,7 @@ public:
|
||||
virtual void clientResetScene();
|
||||
|
||||
///Demo functions
|
||||
virtual void setShootBoxShape ();
|
||||
void shootBox(const btVector3& destination);
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,17 @@ GLDebugDrawer::GLDebugDrawer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GLDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& fromColor, const btVector3& toColor)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
void GLDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
|
||||
{
|
||||
// if (m_debugMode > 0)
|
||||
@@ -33,6 +44,30 @@ void GLDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btV
|
||||
}
|
||||
}
|
||||
|
||||
void GLDebugDrawer::drawSphere (const btVector3& p, btScalar radius, const btVector3& color)
|
||||
{
|
||||
glColor4f (color.getX(), color.getY(), color.getZ(), btScalar(1.0f));
|
||||
glPushMatrix ();
|
||||
glTranslatef (p.getX(), p.getY(), p.getZ());
|
||||
glutSolidSphere (radius, 10, 10);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void GLDebugDrawer::drawBox (const btVector3& boxMin, const btVector3& boxMax, const btVector3& color, btScalar alpha)
|
||||
{
|
||||
btVector3 halfExtent = (boxMax - boxMin) * btScalar(0.5f);
|
||||
btVector3 center = (boxMax + boxMin) * btScalar(0.5f);
|
||||
//glEnable(GL_BLEND); // Turn blending On
|
||||
//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glColor4f (color.getX(), color.getY(), color.getZ(), alpha);
|
||||
glPushMatrix ();
|
||||
glTranslatef (center.getX(), center.getY(), center.getZ());
|
||||
glScaled(2*halfExtent[0], 2*halfExtent[1], 2*halfExtent[2]);
|
||||
glutSolidCube(1.0);
|
||||
glPopMatrix ();
|
||||
//glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
void GLDebugDrawer::drawTriangle(const btVector3& a,const btVector3& b,const btVector3& c,const btVector3& color,btScalar alpha)
|
||||
{
|
||||
// if (m_debugMode > 0)
|
||||
|
||||
@@ -14,8 +14,13 @@ public:
|
||||
GLDebugDrawer();
|
||||
|
||||
|
||||
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& fromColor, const btVector3& toColor);
|
||||
|
||||
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color);
|
||||
|
||||
|
||||
virtual void drawSphere (const btVector3& p, btScalar radius, const btVector3& color);
|
||||
virtual void drawBox (const btVector3& boxMin, const btVector3& boxMax, const btVector3& color, btScalar alpha);
|
||||
|
||||
virtual void drawTriangle(const btVector3& a,const btVector3& b,const btVector3& c,const btVector3& color,btScalar alpha);
|
||||
|
||||
virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color);
|
||||
|
||||
@@ -25,6 +25,7 @@ class btShapeHull;
|
||||
/// OpenGL shape drawing
|
||||
class GL_ShapeDrawer
|
||||
{
|
||||
protected:
|
||||
struct ShapeCache
|
||||
{
|
||||
struct Edge { btVector3 n[2];int v[2]; };
|
||||
@@ -38,17 +39,17 @@ class GL_ShapeDrawer
|
||||
bool m_textureenabled;
|
||||
bool m_textureinitialized;
|
||||
|
||||
private:
|
||||
|
||||
ShapeCache* cache(btConvexShape*);
|
||||
|
||||
public:
|
||||
public:
|
||||
GL_ShapeDrawer();
|
||||
|
||||
virtual ~GL_ShapeDrawer();
|
||||
|
||||
///drawOpenGL might allocate temporary memoty, stores pointer in shape userpointer
|
||||
void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode,const btVector3& worldBoundsMin,const btVector3& worldBoundsMax);
|
||||
void drawShadow(btScalar* m, const btVector3& extrusion,const btCollisionShape* shape,const btVector3& worldBoundsMin,const btVector3& worldBoundsMax);
|
||||
virtual void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode,const btVector3& worldBoundsMin,const btVector3& worldBoundsMax);
|
||||
virtual void drawShadow(btScalar* m, const btVector3& extrusion,const btCollisionShape* shape,const btVector3& worldBoundsMin,const btVector3& worldBoundsMax);
|
||||
|
||||
bool enableTexture(bool enable) { bool p=m_textureenabled;m_textureenabled=enable;return(p); }
|
||||
bool hasTextureEnabled() const
|
||||
@@ -64,4 +65,4 @@ class GL_ShapeDrawer
|
||||
void OGL_displaylist_register_shape(btCollisionShape * shape);
|
||||
void OGL_displaylist_clean();
|
||||
|
||||
#endif //GL_SHAPE_DRAWER_H
|
||||
#endif //GL_SHAPE_DRAWER_H
|
||||
Reference in New Issue
Block a user