Пример #1
0
void CShadowController::MaxSpeed(float maxSpeed, float maxAngularSpeed) {
	btRigidBody* body = btRigidBody::upcast(m_pObject->GetObject());

	btVector3 bullSpeed;
	ConvertPosToBull(maxSpeed, bullSpeed);
	btVector3 available = bullSpeed;

	m_currentSpeed = bullSpeed;

	float length = bullSpeed.length();
	bullSpeed.normalize();

	float dot = bullSpeed.dot(body->getLinearVelocity());
	if (dot > 0) {
		bullSpeed *= dot * length;
		available -= bullSpeed;
	}
	m_shadow.maxSpeed = available.absolute();

	btVector3 bullAngular;
	ConvertAngularImpulseToBull(maxAngularSpeed, bullAngular);
	btVector3 availableAngular;

	float lengthAngular = bullAngular.length();
	bullAngular.normalize();

	float dotAngular = bullAngular.dot(body->getAngularVelocity());
	if (dotAngular > 0) {
		bullAngular *= dotAngular * lengthAngular;
		availableAngular -= bullAngular;
	}
	m_shadow.maxAngular = availableAngular.absolute();
}
Пример #2
0
void CPhysicsObject::ApplyTorqueCenter(const AngularImpulse &torque) {
	if (!IsMoveable() || !IsMotionEnabled()) {
		return;
	}
	Wake();

	btVector3 bullTorque;
	ConvertAngularImpulseToBull(torque, bullTorque);
	m_pObject->applyTorqueImpulse(bullTorque);
}
Пример #3
0
void CPhysicsObject::AddVelocity(const Vector* velocity, const AngularImpulse* angularVelocity) {
	btVector3 btvelocity, btangular;
	if (velocity) {
		ConvertPosToBull(*velocity, btvelocity);
		m_pObject->setLinearVelocity(m_pObject->getLinearVelocity() + btvelocity);
	}
	if (angularVelocity) {
		ConvertAngularImpulseToBull(*angularVelocity, btangular);
		m_pObject->setAngularVelocity(m_pObject->getAngularVelocity() + btangular);
	}
}
Пример #4
0
void CPhysicsObject::SetVelocity(const Vector* velocity, const AngularImpulse* angularVelocity) {
	btVector3 vel, angvel;
	if (velocity) {
		ConvertPosToBull(*velocity, vel);
		m_pObject->setLinearVelocity(vel);
	}
	if (angularVelocity) {
		ConvertAngularImpulseToBull(*angularVelocity, angvel);
		m_pObject->setAngularVelocity(angvel);
	}
}
Пример #5
0
void ConvertShadowControllerToBull(const hlshadowcontrol_params_t &in, shadowcontrol_params_t &out) {
	ConvertPosToBull(in.targetPosition, out.targetPosition);
	ConvertRotationToBull(in.targetRotation, out.targetRotation);
	out.teleportDistance = ConvertDistanceToBull(in.teleportDistance);

	ConvertForceImpulseToBull(in.maxSpeed, out.maxSpeed);
	out.maxSpeed = out.maxSpeed.absolute();
	ConvertAngularImpulseToBull(in.maxAngular, out.maxAngular);
	out.maxAngular = out.maxAngular.absolute();
	out.dampFactor = in.dampFactor;
}
void CShadowController::MaxSpeed(float maxSpeed, float maxAngularSpeed) {
	btRigidBody *body = m_pObject->GetObject();

	//----------------
	// Linear
	//----------------

	btVector3 bullSpeed;
	ConvertPosToBull(Vector(maxSpeed), bullSpeed);
	btVector3 available = bullSpeed;

	// m_currentSpeed = bullSpeed;

	float length = bullSpeed.length();
	bullSpeed.normalize();

	float dot = bullSpeed.dot(body->getLinearVelocity());
	if (dot > 0) {
		bullSpeed *= dot * length;
		available -= bullSpeed;
	}

	// FIXME: This is wrong. Rewrite this later.
	m_shadow.maxSpeed = available.length();

	//----------------
	// Angular
	//----------------

	btVector3 bullAngular;
	ConvertAngularImpulseToBull(Vector(maxAngularSpeed), bullAngular);
	btVector3 availableAngular;

	float lengthAngular = bullAngular.length();
	bullAngular.normalize();

	float dotAngular = bullAngular.dot(body->getAngularVelocity());
	if (dotAngular > 0) {
		bullAngular *= dotAngular * lengthAngular;
		availableAngular -= bullAngular;
	}

	// FIXME: This is wrong. Rewrite this later.
	m_shadow.maxAngular = availableAngular.length();
}
void CPhysicsDragController::Tick(btScalar dt)
{
    for(int i = 0; i < m_ents.Size(); i++)
    {
        CPhysicsObject * object = (CPhysicsObject *)m_ents[i];

        Vector dragLinearFinal(0,0,0);
        AngularImpulse dragAngularFinal(0,0,0);

        Vector vel;
        AngularImpulse ang;
        object->GetVelocity(&vel, &ang);

        btVector3 bull_vel;

        ConvertPosToBull(vel, bull_vel);

        float dragForce = -0.5 * object->GetDragInDirection( &bull_vel ) * m_airDensity * dt;
        if ( dragForce < -1.0f )
        {
            dragForce = -1.0f;
        }
        if ( dragForce < 0 )
        {
            Vector dragLinearFinal = vel * dragForce;
        }
        btVector3 bull_angimpulse;
        ConvertAngularImpulseToBull(ang, bull_angimpulse);

        float angDragForce = -object->GetAngularDragInDirection(&bull_angimpulse) * m_airDensity * dt;
        if ( angDragForce < -1.0f )
        {
            angDragForce = -1.0f;
        }
        if( angDragForce < 0)
        {
            dragAngularFinal = ang * angDragForce;
        }
        object->AddVelocity(&dragLinearFinal, &dragAngularFinal);
    }
}
Пример #8
0
void CPhysicsObject::AddVelocity(const Vector *velocity, const AngularImpulse *angularVelocity) {
	if (!velocity && !angularVelocity) return;

	if (!IsMoveable() || !IsMotionEnabled()) {
		return;
	}
	Wake();

	btVector3 bullvelocity, bullangular;
	if (velocity) {
		ConvertPosToBull(*velocity, bullvelocity);
		m_pObject->setLinearVelocity(m_pObject->getLinearVelocity() + bullvelocity);
	}

	// Angular velocity is supplied in local space.
	if (angularVelocity) {
		ConvertAngularImpulseToBull(*angularVelocity, bullangular);
		bullangular = m_pObject->getWorldTransform().getBasis() * bullangular;

		m_pObject->setAngularVelocity(m_pObject->getAngularVelocity() + bullangular);
	}
}
Пример #9
0
void CPhysicsObject::ApplyTorqueCenter(const AngularImpulse& torque) {
	btVector3 bullTorque;
	ConvertAngularImpulseToBull(torque, bullTorque);
	m_pObject->applyTorque(bullTorque);
}