查看: 1502|回复: 4

关于osg3.0.0的dragger和bullet引擎及osgbullet

[复制链接]

该用户从未签到

发表于 2013-3-14 21:14:37 | 显示全部楼层 |阅读模式
  最近一直在做一个虚拟装配的系统,原来是做windows底层,第一次弄图形的感觉压力山大。不过在看了许多代码后,利用osgbullet把我从solidworks导出的模型成功显示出来,并检测到了碰撞。
  然后,我打算加上dragger,在看了 magicstone&simbaforrest 写的dragger分析后,我打算从selection类继承出一个自己的类,并在里面存放bullet的btCollisionObject指针,用于拖拽的时候实时更新bullet世界的模型坐标。但是,在实际看到osg3.0.0的代码后,发现这个结构已经改变了,所以,我从dragger和DraggerTransformCallback分别继承出一个类来,并增加了新的变量指针指向btCollisionObject。
但是,我虽然是这么想的,但是结果使用的时候总是出现错误,编译是通过的,但是执行的时候总是发生错误被中断 QQ截图20130314210845.png
  下面是我的那两个类
class OBDraggerTransformCallback: public osgManipulator:raggerTransformCallback{

        public:
                基本代码都没有变,就是增加了更新bullet世界的功能。
                OBDraggerTransformCallback(osg::MatrixTransform* obtransform,btCollisionObject* co):DraggerTransformCallback(obtransform){
                        _co=co;
                }


                void ChangeBulletTransform(){

                        osg::Matrix trans =_transform->getMatrix();
                        _co->setWorldTransform(osgbCollision::asBtTransform( trans ) );

                }

                virtual bool receive(const osgManipulator::MotionCommand& command){

                        if (!_transform) return false;

                        switch (command.getStage())
                        {
                        case osgManipulator::MotionCommand::START:
                                {
                                        // Save the current matrix
                                        _startMotionMatrix = _transform->getMatrix();

                                        // Get the LocalToWorld and WorldToLocal matrix for this node.
                                        osg::NodePath nodePathToRoot;
                                        osgManipulator::computeNodePathToRoot(*_transform,nodePathToRoot);
                                        _localToWorld = osg::computeLocalToWorld(nodePathToRoot);
                                        _worldToLocal = osg::Matrix::inverse(_localToWorld);

                                        return true;
                                }
                        case osgManipulator::MotionCommand::MOVE:
                                {
                                        // Transform the command's motion matrix into local motion matrix.
                                        osg::Matrix localMotionMatrix = _localToWorld * command.getWorldToLocal()
                                                * command.getMotionMatrix()
                                                * command.getLocalToWorld() * _worldToLocal;

                                        // Transform by the localMotionMatrix
                                        _transform->setMatrix(localMotionMatrix * _startMotionMatrix);

                                        ChangeBulletTransform();

                                        return true;
                                }
                        case osgManipulator::MotionCommand::FINISH:
                                {
                                        return true;
                                }
                        case osgManipulator::MotionCommand::NONE:
                        default:
                                return false;
                        }
                }

        protected:
                btCollisionObject* _co;
                osg::MatrixTransform* _mt;
               

        };



        class OBTranslateAxisDragger : public osgManipulator::TranslateAxisDragger{


        public:

                OBTranslateAxisDragger(){}
                virtual ~OBTranslateAxisDragger(){}

                void addTransformUpdating(osg::MatrixTransform* transform)
                {
                        addDraggerCallback(new OBDraggerTransformCallback(transform,_co));
                }

                void setbtCollisionObject(btCollisionObject *co){_co=co;}
                btCollisionObject* getbtCollisionObject(){return _co;}


        protected:
                btCollisionObject* _co;
        };


我这样的方法是正确的吗?这么使用是可行的吗?

该用户从未签到

发表于 2013-3-15 07:58:39 | 显示全部楼层
可行不可行主要是看您的功能要求。3.0之后结构变了基本也没怎么变,也就是全部封装到了一个EventUpdateCallback中。至于错误,还需要您自己调试,给出一个截图说明不了什么问题

该用户从未签到

发表于 2013-3-15 12:17:29 | 显示全部楼层
程序出Bug了得自己调试呀....

该用户从未签到

 楼主| 发表于 2013-3-15 14:23:46 | 显示全部楼层
liuzhiyu123 发表于 2013-3-15 07:58
可行不可行主要是看您的功能要求。3.0之后结构变了基本也没怎么变,也就是全部封装到了一个EventUpdateCall ...

我不是寻求解决bug的途径,只是想知道我这个思路是否是正确的。我想实现在dragger更新坐标的时候能够自动更新bullet的碰撞对象坐标,所以继承了dragger类并添加了一些方法来实现。如果这种思路大家觉得不合适,我就不再去修改这个bug,而使用别的方法了。
可能我问的不明确,我的核心问题是这样实现与bullet的交互是好的主意还是坏主意?(不是bug如何解决)

该用户从未签到

发表于 2013-3-15 15:25:35 | 显示全部楼层
我就是这样做的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表