BulletPhysics-明确设置铰链角度?

时间:2018-08-04 17:09:03

标签: c# bulletphysics

铰链的hingeAngle可以作为单个浮点数进行检索,但不能显式设置。我正在用铰链模拟门,需要能够立即将角度随意设置为打开或关闭。如何做到这一点?

铰链的创建方式为:

const float mass = 10.0f;
BoxShape boxShape = new BoxShape(Door.CollisionShape);
Vector3 pivotA = new Vector3(-Door.CollisionShape.X, Door.CollisionShape.Y, Door.CollisionShape.Z);

door.rigidBody = physics.LocalCreateRigidBody(mass, door.getRotationMatrix() * Matrix4.CreateTranslation(position), boxShape);
door.rigidBody.ActivationState = ActivationState.DisableDeactivation;
door.rigidBody.UserObject = "Door";

var axisA = Vector3.UnitY; // pointing upwards, aka Y-axis
var hinge = new HingeConstraint(door.rigidBody, pivotA, axisA);
hinge.SetLimit(-(float)Math.PI * 0.25f, 0);

physics.World.AddConstraint(hinge);

我将其移至:

float targetVelocity = Door.OpenSpeed;
float maxMotorImpulse = 1.0f;
door.hinge.EnableAngularMotor(true, targetVelocity, maxMotorImpulse);

BulletPhysics在每个步骤的基础上,根据hingeangle增加targetVelocity。我希望直接设置此值,而不是通过施加力来间接设置。

1 个答案:

答案 0 :(得分:0)

您尝试过setMotorTarget()函数吗?

void btHingeConstraint::setMotorTarget
(
    btScalar    targetAngle,
    btScalar    dt 
);

您是否希望在单个模拟步骤中将门从打开更改为关闭?

如果是这样,那似乎是一件危险的事情,因为可能有东西挡住了门,并且通过硬设置门刚体,它可能会与其他形状相交。