Example #1
0
void ObjectMotionState::handleEasyChanges(uint32_t flags, PhysicsEngine* engine) {
    if (flags & EntityItem::DIRTY_POSITION) {
        btTransform worldTrans;
        if (flags & EntityItem::DIRTY_ROTATION) {
            worldTrans.setRotation(glmToBullet(getObjectRotation()));
        } else {
            worldTrans = _body->getWorldTransform();
        }
        worldTrans.setOrigin(glmToBullet(getObjectPosition()));
        _body->setWorldTransform(worldTrans);
    } else if (flags & EntityItem::DIRTY_ROTATION) {
        btTransform worldTrans = _body->getWorldTransform();
        worldTrans.setRotation(glmToBullet(getObjectRotation()));
        _body->setWorldTransform(worldTrans);
    }

    if (flags & EntityItem::DIRTY_LINEAR_VELOCITY) {
        _body->setLinearVelocity(glmToBullet(getObjectLinearVelocity()));
        _body->setGravity(glmToBullet(getObjectGravity()));
    }
    if (flags & EntityItem::DIRTY_ANGULAR_VELOCITY) {
        _body->setAngularVelocity(glmToBullet(getObjectAngularVelocity()));
    }

    if (flags & EntityItem::DIRTY_MATERIAL) {
        updateBodyMaterialProperties();
    }

    if (flags & EntityItem::DIRTY_MASS) {
        updateBodyMassProperties();
    }
}
Example #2
0
// virtual
void AvatarMotionState::setWorldTransform(const btTransform& worldTrans) {
    const float SPRING_TIMESCALE = 0.5f;
    float tau = PHYSICS_ENGINE_FIXED_SUBSTEP / SPRING_TIMESCALE;
    btVector3 currentPosition = worldTrans.getOrigin();
    btVector3 offsetToTarget = glmToBullet(getObjectPosition()) - currentPosition;
    float distance = offsetToTarget.length();
    if ((1.0f - tau) * distance > _diameter) {
        // the avatar body is far from its target --> slam position
        btTransform newTransform;
        newTransform.setOrigin(currentPosition + offsetToTarget);
        newTransform.setRotation(glmToBullet(getObjectRotation()));
        _body->setWorldTransform(newTransform);
        _body->setLinearVelocity(glmToBullet(getObjectLinearVelocity()));
        _body->setAngularVelocity(glmToBullet(getObjectAngularVelocity()));
    } else {
        // the avatar body is near its target --> slam velocity
        btVector3 velocity = glmToBullet(getObjectLinearVelocity()) + (1.0f / SPRING_TIMESCALE) * offsetToTarget;
        _body->setLinearVelocity(velocity);
        _body->setAngularVelocity(glmToBullet(getObjectAngularVelocity()));
        // slam its rotation
        btTransform newTransform = worldTrans;
        newTransform.setRotation(glmToBullet(getObjectRotation()));
        _body->setWorldTransform(newTransform);
    }
}
Example #3
0
// virtual
void AvatarMotionState::getWorldTransform(btTransform& worldTrans) const {
    worldTrans.setOrigin(glmToBullet(getObjectPosition()));
    worldTrans.setRotation(glmToBullet(getObjectRotation()));
    if (_body) {
        _body->setLinearVelocity(glmToBullet(getObjectLinearVelocity()));
        _body->setAngularVelocity(glmToBullet(getObjectAngularVelocity()));
    }
}
Example #4
0
Matrix4f const *Node::getMatrix(void)
{
	Matrix4f translationM, rotationM, scalingM;
	getObjectScaling(scalingM);
	getObjectTranslation(translationM);
	getObjectRotation(rotationM);
	

	_transformationMatrix = translationM * rotationM * scalingM;
	return &_transformationMatrix;
}
Example #5
0
Matrix4f const *Node::getMatrix(void)
{
	Matrix4f translationM, rotationM, scalingM, projectionM, cameraPos, cameraOrientation;
	getObjectScaling(scalingM);
	getObjectTranslation(translationM);
	getObjectRotation(rotationM);
	getPerspctiveProjection(projectionM);
	getCameraTranslation(cameraPos);
	getCameraOrientation(cameraOrientation);

	_transformationMatrix = projectionM * cameraOrientation * cameraPos * translationM * rotationM * scalingM;
	return &_transformationMatrix;
}
Example #6
0
void ObjectMotionState::handleEasyChanges(uint32_t flags) {
    if (flags & EntityItem::DIRTY_POSITION) {
        btTransform worldTrans;
        if (flags & EntityItem::DIRTY_ROTATION) {
            worldTrans.setRotation(glmToBullet(getObjectRotation()));
        } else {
            worldTrans = _body->getWorldTransform();
        }
        worldTrans.setOrigin(glmToBullet(getObjectPosition()));
        _body->setWorldTransform(worldTrans);
    } else if (flags & EntityItem::DIRTY_ROTATION) {
        btTransform worldTrans = _body->getWorldTransform();
        worldTrans.setRotation(glmToBullet(getObjectRotation()));
        _body->setWorldTransform(worldTrans);
    }

    if (flags & EntityItem::DIRTY_LINEAR_VELOCITY) {
        _body->setLinearVelocity(glmToBullet(getObjectLinearVelocity()));
        _body->setGravity(glmToBullet(getObjectGravity()));
    }
    if (flags & EntityItem::DIRTY_ANGULAR_VELOCITY) {
        _body->setAngularVelocity(glmToBullet(getObjectAngularVelocity()));
    }

    if (flags & EntityItem::DIRTY_MATERIAL) {
        updateBodyMaterialProperties();
    }

    if (flags & EntityItem::DIRTY_MASS) {
        float mass = getMass();
        btVector3 inertia(0.0f, 0.0f, 0.0f);
        _body->getCollisionShape()->calculateLocalInertia(mass, inertia);
        _body->setMassProps(mass, inertia);
        _body->updateInertiaTensor();
    }
}
// virtual
void DetailedMotionState::getWorldTransform(btTransform& worldTrans) const {
    worldTrans.setOrigin(glmToBullet(getObjectPosition()));
    worldTrans.setRotation(glmToBullet(getObjectRotation()));
}