improve BasicDemo, better mouse handling, add colors to drawing
This commit is contained in:
@@ -68,13 +68,13 @@ void BasicDemo::exitPhysics()
|
||||
|
||||
//SimpleOpenGL3App* m_glApp;
|
||||
|
||||
btRigidBody* MyBasicDemoPhysicsSetup::createRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape)
|
||||
btRigidBody* MyBasicDemoPhysicsSetup::createRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape, const btVector4& color)
|
||||
{
|
||||
btRigidBody* body = BasicDemoPhysicsSetup::createRigidBody(mass,startTransform,shape);
|
||||
int graphicsShapeId = shape->getUserIndex();
|
||||
btAssert(graphicsShapeId>=0);
|
||||
btVector3 localScaling = shape->getLocalScaling();
|
||||
float color[]={0.3,0.3,1,1};
|
||||
|
||||
int graphicsInstanceId = m_glApp->m_instancingRenderer->registerGraphicsInstance(graphicsShapeId,startTransform.getOrigin(),startTransform.getRotation(),color,localScaling);
|
||||
body->setUserIndex(graphicsInstanceId);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ struct MyBasicDemoPhysicsSetup : public BasicDemoPhysicsSetup
|
||||
{
|
||||
SimpleOpenGL3App* m_glApp;
|
||||
|
||||
virtual btRigidBody* createRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape);
|
||||
virtual btRigidBody* createRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape, const btVector4& color);
|
||||
|
||||
virtual btBoxShape* createBoxShape(const btVector3& halfExtents);
|
||||
};
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
Bullet2RigidBodyDemo::Bullet2RigidBodyDemo(SimpleOpenGL3App* app)
|
||||
:m_glApp(app),
|
||||
m_pickedBody(0),
|
||||
m_pickedConstraint(0)
|
||||
m_pickedConstraint(0),
|
||||
m_controlPressed(false),
|
||||
m_altPressed(false)
|
||||
{
|
||||
m_config = 0;
|
||||
m_dispatcher = 0;
|
||||
@@ -113,8 +115,8 @@ btVector3 Bullet2RigidBodyDemo::getRayTo(int x,int y)
|
||||
|
||||
bool Bullet2RigidBodyDemo::mouseMoveCallback(float x,float y)
|
||||
{
|
||||
// if (m_data->m_altPressed!=0 || m_data->m_controlPressed!=0)
|
||||
// return false;
|
||||
//if (m_data->m_altPressed!=0 || m_data->m_controlPressed!=0)
|
||||
//return false;
|
||||
|
||||
if (m_pickedBody && m_pickedConstraint)
|
||||
{
|
||||
@@ -143,7 +145,7 @@ bool Bullet2RigidBodyDemo::mouseButtonCallback(int button, int state, float x, f
|
||||
|
||||
if (state==1)
|
||||
{
|
||||
if(button==0)// && (m_data->m_altPressed==0 && m_data->m_controlPressed==0))
|
||||
if(button==0 && (!m_altPressed && !m_controlPressed))
|
||||
{
|
||||
btVector3 camPos;
|
||||
m_glApp->m_instancingRenderer->getCameraPosition(camPos);
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "../../AllBullet2Demos/BulletDemoInterface.h"
|
||||
|
||||
#include "OpenGLWindow/b3gWindowInterface.h"
|
||||
|
||||
class Bullet2RigidBodyDemo : public BulletDemoInterface
|
||||
{
|
||||
public:
|
||||
@@ -19,7 +21,8 @@ public:
|
||||
btVector3 m_oldPickingPos;
|
||||
btVector3 m_hitPos;
|
||||
btScalar m_oldPickingDist;
|
||||
|
||||
bool m_controlPressed;
|
||||
bool m_altPressed;
|
||||
|
||||
public:
|
||||
|
||||
@@ -35,6 +38,14 @@ public:
|
||||
virtual bool mouseButtonCallback(int button, int state, float x, float y);
|
||||
virtual bool keyboardCallback(int key, int state)
|
||||
{
|
||||
if (key==B3G_CONTROL)
|
||||
{
|
||||
m_controlPressed = (state==1);
|
||||
}
|
||||
if (key==B3G_ALT)
|
||||
{
|
||||
m_altPressed = (state==1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user