首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BulletPhysics -显式设置铰链角度?

BulletPhysics -显式设置铰链角度?
EN

Stack Overflow用户
提问于 2018-08-05 01:09:03
回答 1查看 142关注 0票数 0

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

使用以下命令创建铰链:

代码语言:javascript
复制
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);

我将使用以下命令移动它:

代码语言:javascript
复制
float targetVelocity = Door.OpenSpeed;
float maxMotorImpulse = 1.0f;
door.hinge.EnableAngularMotor(true, targetVelocity, maxMotorImpulse);

在每一步,BulletPhysics都会根据hingeangle增加targetVelocity。我希望直接设置此值,而不是通过施加力间接设置。

EN

回答 1

Stack Overflow用户

发布于 2018-12-07 08:27:58

你有没有尝试过setMotorTarget()函数?

代码语言:javascript
复制
void btHingeConstraint::setMotorTarget
(
    btScalar    targetAngle,
    btScalar    dt 
);

您希望门在单个模拟步骤中从打开状态变为关闭状态吗?

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51687855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档