mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-14 13:50:04 +00:00
improve BasicDemo, better mouse handling, add colors to drawing
This commit is contained in:
parent
7f300a877f
commit
28f19f1bab
@ -39,7 +39,7 @@ void BasicDemoPhysicsSetup::initPhysics()
|
||||
|
||||
{
|
||||
btScalar mass(0.);
|
||||
createRigidBody(mass,groundTransform,groundShape);
|
||||
createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1));
|
||||
}
|
||||
|
||||
|
||||
@ -99,7 +99,7 @@ btBoxShape* BasicDemoPhysicsSetup::createBoxShape(const btVector3& halfExtents)
|
||||
return box;
|
||||
}
|
||||
|
||||
btRigidBody* BasicDemoPhysicsSetup::createRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape)
|
||||
btRigidBody* BasicDemoPhysicsSetup::createRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape, const btVector4& color)
|
||||
{
|
||||
btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE));
|
||||
|
||||
|
@ -11,6 +11,7 @@ class btDiscreteDynamicsWorld;
|
||||
class btTransform;
|
||||
class btVector3;
|
||||
class btBoxShape;
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
@ -31,7 +32,7 @@ struct BasicDemoPhysicsSetup
|
||||
|
||||
virtual void stepSimulation(float deltaTime);
|
||||
|
||||
virtual btRigidBody* createRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape);
|
||||
virtual btRigidBody* createRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape, const btVector4& color=btVector4(1,0,0,1));
|
||||
|
||||
virtual btBoxShape* createBoxShape(const btVector3& halfExtents);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user