some refactoring and a bug fix -- grab script can throw things again

This commit is contained in:
Seth Alves 2015-10-30 16:35:50 -07:00
parent cf83ca22bb
commit 944f0965c0
3 changed files with 9 additions and 14 deletions

View file

@ -15,13 +15,11 @@
Script.include("../libraries/utils.js");
////////////////////////////////////////////////////////////
//
// add lines where the hand ray picking is happening
//
var WANT_DEBUG = false;
/////////////////////////////////////////////////////////////////
//
// these tune time-averaging and "on" value for analog trigger
//
@ -30,7 +28,6 @@ var TRIGGER_SMOOTH_RATIO = 0.1; // 0.0 disables smoothing of trigger value
var TRIGGER_ON_VALUE = 0.4;
var TRIGGER_OFF_VALUE = 0.15;
/////////////////////////////////////////////////////////////////
//
// distant manipulation
//
@ -44,7 +41,6 @@ var LINE_ENTITY_DIMENSIONS = { x: 1000, y: 1000,z: 1000};
var LINE_LENGTH = 500;
var PICK_MAX_DISTANCE = 500; // max length of pick-ray
/////////////////////////////////////////////////////////////////
//
// near grabbing
//
@ -57,7 +53,6 @@ var RELEASE_VELOCITY_MULTIPLIER = 1.5; // affects throwing things
var PICK_BACKOFF_DISTANCE = 0.2; // helps when hand is intersecting the grabble object
var NEAR_GRABBING_KINEMATIC = true; // force objects to be kinematic when near-grabbed
/////////////////////////////////////////////////////////////////
//
// other constants
//
@ -228,7 +223,7 @@ function MyController(hand, triggerAction) {
this.setState = function(newState) {
if (WANT_DEBUG) {
print("STATE: " + stateToName(this.state) + " --> " + newState + ", hand: " + this.hand);
print("STATE: " + stateToName(this.state) + " --> " + stateToName(newState) + ", hand: " + this.hand);
}
this.state = newState;
}
@ -849,7 +844,6 @@ function MyController(hand, triggerAction) {
// the action will tend to quickly bring an object's velocity to zero. now that
// the action is gone, set the objects velocity to something the holder might expect.
print("release velocity is " + vec3toStr(this.grabbedVelocity));
Entities.editEntity(this.grabbedEntity, {
velocity: this.grabbedVelocity
});

View file

@ -82,12 +82,12 @@ void PhysicsEngine::addObject(ObjectMotionState* motionState) {
btCollisionShape* shape = motionState->getShape();
assert(shape);
body = new btRigidBody(mass, motionState, shape, inertia);
motionState->setRigidBody(body);
} else {
body->setMassProps(mass, inertia);
}
body->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
body->updateInertiaTensor();
motionState->setRigidBody(body);
motionState->updateBodyVelocities();
const float KINEMATIC_LINEAR_VELOCITY_THRESHOLD = 0.01f; // 1 cm/sec
const float KINEMATIC_ANGULAR_VELOCITY_THRESHOLD = 0.01f; // ~1 deg/sec
@ -101,12 +101,15 @@ void PhysicsEngine::addObject(ObjectMotionState* motionState) {
shape->calculateLocalInertia(mass, inertia);
if (!body) {
body = new btRigidBody(mass, motionState, shape, inertia);
motionState->setRigidBody(body);
} else {
body->setMassProps(mass, inertia);
}
body->setCollisionFlags(body->getCollisionFlags() & ~(btCollisionObject::CF_KINEMATIC_OBJECT |
btCollisionObject::CF_STATIC_OBJECT));
body->updateInertiaTensor();
motionState->setRigidBody(body);
motionState->updateBodyVelocities();
// NOTE: Bullet will deactivate any object whose velocity is below these thresholds for longer than 2 seconds.
// (the 2 seconds is determined by: static btRigidBody::gDeactivationTime
const float DYNAMIC_LINEAR_VELOCITY_THRESHOLD = 0.05f; // 5 cm/sec
@ -123,12 +126,12 @@ void PhysicsEngine::addObject(ObjectMotionState* motionState) {
if (!body) {
assert(motionState->getShape());
body = new btRigidBody(mass, motionState, motionState->getShape(), inertia);
motionState->setRigidBody(body);
} else {
body->setMassProps(mass, inertia);
}
body->setCollisionFlags(btCollisionObject::CF_STATIC_OBJECT);
body->updateInertiaTensor();
motionState->setRigidBody(body);
break;
}
}

View file

@ -98,13 +98,11 @@ void ThreadSafeDynamicsWorld::synchronizeMotionState(btRigidBody* body) {
{
if (body->isKinematicObject()) {
ObjectMotionState* objectMotionState = static_cast<ObjectMotionState*>(body->getMotionState());
if (!objectMotionState->hasInternalKinematicChanges()) {
return;
} else {
if (objectMotionState->hasInternalKinematicChanges()) {
objectMotionState->clearInternalKinematicChanges();
body->getMotionState()->setWorldTransform(body->getWorldTransform());
return;
}
return;
}
btTransform interpolatedTransform;
btTransformUtil::integrateTransform(body->getInterpolationWorldTransform(),