Пример #1
0
/**
*  @brief
*    Static Newton joint user callback function
*/
unsigned JointUniversal::JointUserCallback(const Newton::NewtonJoint *pNewtonJoint, Newton::NewtonHingeSliderUpdateDesc *pDesc)
{
	// Get joint
	const JointUniversal *pJoint = static_cast<JointUniversal*>(NewtonJointGetUserData(pNewtonJoint));
	if (!pJoint)
		return 0;

	// [TODO] Breakable

	// Get min/max angle limits
	const float fAngleMinLimit1 = pJoint->GetLowRange1();
	const float fAngleMaxLimit1 = pJoint->GetHighRange1();
	const float fAngleMinLimit2 = pJoint->GetLowRange2();
	const float fAngleMaxLimit2 = pJoint->GetHighRange2();

	// Check limits
	uint32 nReturn = 0;
	// Limit 1
	float fAngle = NewtonUniversalGetJointAngle0(pNewtonJoint);
	if (fAngle > fAngleMaxLimit1) {
		// If the joint angle is large than the defined value, stop the universal
		pDesc[0].m_accel = NewtonUniversalCalculateStopAlpha0(pNewtonJoint, pDesc, fAngleMaxLimit1);
		nReturn |= 1;
	} else if (fAngle < fAngleMinLimit1) {
		// If the joint angle is smaller than the defined value, stop the universal
		pDesc[0].m_accel = NewtonUniversalCalculateStopAlpha0(pNewtonJoint, pDesc, fAngleMinLimit1);
		nReturn |= 1;
	}
	// Limit 2
	fAngle = NewtonUniversalGetJointAngle1(pNewtonJoint);
	if (fAngle > fAngleMaxLimit2) {
		// If the joint angle is large than the defined value, stop the universal
		pDesc[1].m_accel = NewtonUniversalCalculateStopAlpha1(pNewtonJoint, &pDesc[1], fAngleMaxLimit2);
		nReturn |= 2;
	} else if (fAngle < fAngleMinLimit2) {
		// If the joint angle is smaller than the defined value, stop the universal
		pDesc[1].m_accel = NewtonUniversalCalculateStopAlpha1(pNewtonJoint, &pDesc[1], fAngleMinLimit2);
		nReturn |= 2;
	}

	// No action need it if the joint angle is with the limits
	return nReturn;
}
	dFloat Roket_PhysicsJointUniversal::getAngle1()
	{
		return NewtonUniversalGetJointAngle1(joint);
	}