Ejemplo n.º 1
0
void pWheel1::_tick(float dt)
{

	if(!hasGroundContact())
		updateContactPosition();
	
	//################################################################
	//
	// Calculate the wheel rotation around the roll axis
	//
	updateAngularVelocity(dt*0.001f, false);

	float motorTorque=0.0;

	if(getWheelFlag(WF_Accelerated)) 
	{
		/*if (handBrake && getWheelFlag(NX_WF_AFFECTED_BY_HANDBRAKE)) 
		{
			// Handbrake, blocking!
		}*/
		
		if (hasGroundContact()) 
		{
			// Touching, force applies
			NxVec3 steeringDirection;
			getSteeringDirection(steeringDirection);
			steeringDirection.normalize();
			NxReal localTorque = motorTorque;
			NxReal wheelForce = localTorque / _radius;
			steeringDirection *= wheelForce;
			wheelCapsule->getActor().addForceAtPos(steeringDirection, contactInfo->contactPosition);
			if(contactInfo->otherActor->isDynamic())
				contactInfo->otherActor->addForceAtPos(-steeringDirection, contactInfo->contactPosition);
		} 
	}
	
	NxMat34& wheelPose = getWheelCapsule()->getGlobalPose();
	NxMat33 rot, axisRot, rollRot;
	rot.rotY( _angle );
	axisRot.rotY(0);
	rollRot.rotX(_turnAngle);
	wheelPose.M = rot * wheelPose.M * axisRot * rollRot;

	float a = _angle;
	float b = getWheelRollAngle();

	
	setWheelPose(wheelPose);
	//setWheelOrientation(wheelPose.M);


	contactInfo->reset();
}
Ejemplo n.º 2
0
void pWheel1::tick(bool handbrake, float motorTorque, float brakeTorque, float dt)
{

	if(getWheelFlag(WF_Accelerated)) 
	{
		if (handbrake && getWheelFlag(WF_AffectedByHandbrake)) 
		{
			// Handbrake, blocking!
		}
		else if (hasGroundContact()) 
		{
			// Touching, force applies
			NxVec3 steeringDirection;
			getSteeringDirection(steeringDirection);
			steeringDirection.normalize();
			NxReal localTorque = motorTorque;
			NxReal wheelForce = localTorque / _radius;
			steeringDirection *= wheelForce;
			wheelCapsule->getActor().addForceAtPos(steeringDirection, contactInfo->contactPosition);
			if(contactInfo->otherActor->isDynamic())
				contactInfo->otherActor->addForceAtPos(-steeringDirection, contactInfo->contactPosition);
		} 
	}

	NxReal OneMinusBreakPedal = 1-brakeTorque;

	/*
	if(handBrake && getWheelFlag(WF_AffectedByHandbrake)) 
	{
	material->setDynamicFrictionV(1);
	material->setStaticFrictionV(4);
	material->setDynamicFriction(0.4f);
	material->setStaticFriction(1.0f);
	} 
	else 
	{
	NxReal newv = OneMinusBreakPedal * _frictionToFront + brakeTorque;
	NxReal newv4= OneMinusBreakPedal * _frictionToFront + brakeTorque*4;
	material->setDynamicFrictionV(newv);
	material->setDynamicFriction(_frictionToSide);

	material->setStaticFrictionV(newv*4);
	material->setStaticFriction(2);
	}*/

	if(!hasGroundContact())
		updateContactPosition();
	updateAngularVelocity(dt, handbrake);

	contactInfo->reset();
}
Ejemplo n.º 3
0
/**
 * Applies impulse to a body.
 *
 * @param [in] context The context the body is in.
 * @param [in,out] body The body to apply the impulse to.
 * @param [in] pointOfForce The point where the force applied.
 * @param [in] impulseVector The direction and strength of the impulse (in N * time_step)
 *
 */
void applyImpulse(
    DYN_Context *context,
    DYN_Body *body,
    const double *pointOfForce,
    const double *impulseVector
)
{
    double radius[3]; // vector from the mass center to the point where the force applies.
    double angularImpulse[3]; // The angular impulse applied to the body.
    double tmp[3];

    ALG_getPointToPointVector(radius, body->position, pointOfForce);
    ALG_crossProduct(angularImpulse, radius, impulseVector);
    // Apply the change to the linear momentum
    memcpy(tmp, impulseVector, sizeof(tmp));
    ALG_scale(tmp, 1 / body->staticAttributes->mass);
    ALG_translate(body->velocity, tmp);
    if (!ALG_isNullVector(angularImpulse))
    {
        double bodyRotationAxis[3]; // Axis of the angular impulse is in the object space.
        double momentOfInertiaCurrentAxis;
        double angularMomentum[3];

        // Calculate the moment of inertia for the current rotational axis
        assert(ALG_solveSystem3(bodyRotationAxis, body->orientation, body->angularVelocity));
        ALG_normalizeVector(bodyRotationAxis);
        // Calculate Io * o
        ALG_transform(tmp, bodyRotationAxis, body->staticAttributes->intertiaTensor);
        momentOfInertiaCurrentAxis = ALG_dotProduct(tmp, bodyRotationAxis);
        assert(momentOfInertiaCurrentAxis >= 0);
        // Calculate the current angular momentum of the body
        memcpy(angularMomentum, body->angularVelocity, sizeof(tmp));
        ALG_scale(angularMomentum, momentOfInertiaCurrentAxis); // current angular momentum
        ALG_translate(angularMomentum, angularImpulse); // new angular momentum.
        // Update angular velocity and rotation.
        updateAngularVelocity(body, angularMomentum);
    }
    //fprintf(f, "\n");

}