游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3319|回复: 3

关于Bullet物理引擎中的btGeneric6DofConstraint

[复制链接]

2

主题

18

帖子

18

积分

新手上路

Rank: 1

积分
18
发表于 2011-3-10 00:06:00 | 显示全部楼层 |阅读模式
我创建了3个 btGeneric6DofConstraint分别显示3个刚体的旋转,代码如下

{ //Allowed rotation around the x-axis only
trans.setOrigin(btVector3(-10,0,0));
d6body0 = localCreateRigidBody( mass,trans,shape);
d6body0->setActivationState(DISABLE_DEACTIVATION);

spSlider6Dof = new btGeneric6DofConstraint(*d6body0,btTransform::getIdentity(),true);
spSlider6Dof->setAngularLowerLimit(btVector3(1.0, 0, 0));
spSlider6Dof->setAngularUpperLimit(btVector3(-1.0,0, 0));

m_dynamicsWorld->addConstraint(spSlider6Dof);
spSlider6Dof->setDbgDrawSize(btScalar(5.f));
}
{ //Allowed rotation around the y-axis only
trans.setOrigin(btVector3(0,0,0));
d6body0 = localCreateRigidBody( mass,trans,shape);
d6body0->setActivationState(DISABLE_DEACTIVATION);

spSlider6Dof = new btGeneric6DofConstraint(*d6body0,btTransform::getIdentity(),true);
spSlider6Dof->setAngularLowerLimit(btVector3(0,1.0,0));
spSlider6Dof->setAngularUpperLimit(btVector3(0,-1.0,0));

m_dynamicsWorld->addConstraint(spSlider6Dof);
spSlider6Dof->setDbgDrawSize(btScalar(5.f));
}
{ //Allowed rotation around the z-axis only
trans.setOrigin(btVector3(10,0,0));
d6body0 = localCreateRigidBody( mass,trans,shape);
d6body0->setActivationState(DISABLE_DEACTIVATION);

spSlider6Dof = new btGeneric6DofConstraint(*d6body0,btTransform::getIdentity(),true);
spSlider6Dof->setAngularLowerLimit(btVector3(0, 0, 1.0));
spSlider6Dof->setAngularUpperLimit(btVector3(0, 0,-1.0));

m_dynamicsWorld->addConstraint(spSlider6Dof);
spSlider6Dof->setDbgDrawSize(btScalar(5.f));
}

但是你可以看到第二个约束是怪异的,为什么呢?
你可以下载附件中的代码替换ConstraintDemo中的同名文件来观看上面代码的效果。

另外,我其实是想创建一辆不会翻的车,应该如何实现?

0

主题

4

帖子

5

积分

新手上路

Rank: 1

积分
5
发表于 2011-3-11 13:54:00 | 显示全部楼层

Re:关于Bullet物理引擎中的btGeneric6DofConstraint

...................................

1

主题

102

帖子

108

积分

注册会员

Rank: 2

积分
108
QQ
发表于 2011-3-17 01:35:00 | 显示全部楼层

Re:关于Bullet物理引擎中的btGeneric6DofConstraint

我记得好像Y轴比较麻烦。因为它有角度限制,解决办法就是,如果一个joint你只限制一个或者两个轴的话,那可以通过旋转避开这个轴,转换成别的轴的约束。
不敢确定,已经半年没弄过了

2

主题

18

帖子

18

积分

新手上路

Rank: 1

积分
18
 楼主| 发表于 2011-3-17 23:39:00 | 显示全部楼层

Re: 关于Bullet物理引擎中的btGeneric6DofConstraint

问题已解决
    {
        trans.setOrigin(btVector3(0,0,0));
        d6body0 = localCreateRigidBody( mass,trans,shape);
        d6body0->setActivationState(DISABLE_DEACTIVATION);

        btRigidBody* _bt_balancer_body = new btRigidBody(
            btRigidBody::btRigidBodyConstructionInfo(
            0, 0, 0 ) );
        // must use X axis as Y axis because 6dof wont spin freely on Y
        btTransform frameina( btTransform::getIdentity() );
        btTransform frameinb( btTransform::getIdentity() );
        frameina.getBasis().setEulerZYX( 0, 0, SIMD_HALF_PI );
        _bt_balancer_body->getWorldTransform().getBasis().setEulerZYX( 0, 0, SIMD_HALF_PI );
        m_dynamicsWorld->addRigidBody(_bt_balancer_body);

        spSlider6Dof = new btGeneric6DofConstraint(*d6body0, *_bt_balancer_body, frameina, frameinb,true);

        spSlider6Dof->setAngularLowerLimit(btVector3(1.0, 0, 0));
        spSlider6Dof->setAngularUpperLimit(btVector3(-1.0, 0,  0));

        m_dynamicsWorld->addConstraint(spSlider6Dof);
        spSlider6Dof->setDbgDrawSize(btScalar(5.f));
    }
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-8-14 08:08

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表