add alpha blendering option (disabled by default) using w component of color

add low-level support function demo (test)
This commit is contained in:
Erwin Coumans
2014-10-15 18:05:11 -07:00
parent ce0ad64475
commit eda1ff77db
8 changed files with 147 additions and 10 deletions

View File

@@ -20,6 +20,7 @@
#include "../ImportSTLDemo/ImportSTLSetup.h"
#include "../../Demos/SerializeDemo/SerializeSetup.h"
#include "../bullet2/MultiBodyDemo/TestJointTorqueSetup.h"
#include "../bullet2/CollisionDetection/SupportFuncDemo.h"
static BulletDemoInterface* TestJointTorqueCreateFunc(CommonGraphicsApp* app)
{
@@ -72,6 +73,8 @@ static BulletDemoInterface* MyImportSTLCreateFunc(CommonGraphicsApp* app)
}
struct BulletDemoEntry
{
int m_menuLevel;
@@ -83,9 +86,13 @@ struct BulletDemoEntry
static BulletDemoEntry allDemos[]=
{
{0,"LowLevel",0},
{1,"SupportFunc", &MySupportFuncDemo::CreateFunc},
//{"emptydemo",EmptyBulletDemo::MyCreateFunc},
{0,"API Demos", 0},
{1,"BasicDemo",BasicDemo::MyCreateFunc},
{ 1, "CcdDemo", MyCcdPhysicsDemoCreateFunc },
{ 1, "Kinematic", MyKinematicObjectCreateFunc },

View File

@@ -0,0 +1,112 @@
#ifndef SUPPORT_FUNC_DEMO_H
#define SUPPORT_FUNC_DEMO_H
#include "Bullet3AppSupport/BulletDemoInterface.h"
#include "OpenGLWindow/CommonGraphicsApp.h"
#include "BulletCollision/CollisionShapes/btSphereShape.h"
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)
{
}
virtual bool mouseButtonCallback(int button, int state, float x, float y)
{
}
virtual bool keyboardCallback(int key, int state)
{
}
};
#endif //SUPPORT_FUNC_DEMO