【问题标题】:BulletPhysics - Set hinge angle explicitly?BulletPhysics - 明确设置铰链角度?
【发布时间】:2018-08-04 17:09:02
【问题描述】:

铰链的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 都会在 targetVelocity 的基础上增加 hingeangle。我希望直接设置此值,而不是通过施加力间接设置。

【问题讨论】:

  • 你写了什么代码来解决这个问题?
  • @DanielA.White 你想看什么?

标签: c# bulletphysics


【解决方案1】:

你试过 setMotorTarget() 函数吗?

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

在单个模拟步骤中门从打开变为关闭是您想要的行为吗?

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

【讨论】:

  • 我通过将铰链 MotorTargetVelocity 乘以 -1 来打开和关闭门,并使用 SetLimit() 函数锁定最大和最小角度。它有效,但并不完美。你能推荐一个替代方案吗?
猜你喜欢
  • 1970-01-01
  • 2019-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-08
  • 1970-01-01
  • 2019-04-14
相关资源
最近更新 更多