OgreBullet 的使用
2016-06-16 20:15
260 查看
最近做实训,用到Ogre 的引擎。
在渲染方面,Ogre 的性能杠杠的,不用多解释,但是除了渲染,别的模块很多都是空缺的。
so,当我尝试去做物理引擎的时候,发现就像来到了一篇荒原,对,就是荒原。
所幸,前人做了很多的物理引擎与Ogre 的匹配。OgreBullet 就是与Bullet 匹配的东西。
但是这玩意有点历史,项目还是08年的,我使用的是Ogre的1.9 版本了。
简单尝试了一下,OgreBullet 的使用大概如下。
头文件包含和命名空间的声明:
关键的变量:
然后初始化一下变量:
刚体碰撞基本遵循两个步骤:建立CollisionShape 、建立RigidBody
以两个函数,记录如下:
然后在frameStarted 和 frameEnded 中启用模拟:
我比较不明白的是,析构对象的时候,它会莫名奇妙地崩溃。。。先不管了,真正用的时候,再fixed 一下。
在渲染方面,Ogre 的性能杠杠的,不用多解释,但是除了渲染,别的模块很多都是空缺的。
so,当我尝试去做物理引擎的时候,发现就像来到了一篇荒原,对,就是荒原。
所幸,前人做了很多的物理引擎与Ogre 的匹配。OgreBullet 就是与Bullet 匹配的东西。
但是这玩意有点历史,项目还是08年的,我使用的是Ogre的1.9 版本了。
简单尝试了一下,OgreBullet 的使用大概如下。
头文件包含和命名空间的声明:
#include <OgreBulletDynamicsRigidBody.h> #include <Shapes/OgreBulletCollisionsStaticPlaneShape.h> #include <Shapes/OgreBulletCollisionsBoxShape.h> using namespace OgreBulletDynamics; using namespace OgreBulletCollisions;
关键的变量:
DynamicsWorld* world; std::deque<RigidBody*> bodies; //deque for rigid body std::deque<CollisionShape*> shapes;
然后初始化一下变量:
world = new DynamicsWorld(scene_mgr, bound, gravity_vector);
刚体碰撞基本遵循两个步骤:建立CollisionShape 、建立RigidBody
以两个函数,记录如下:
void add_shape(const Plane _g,const String& name = StringUtil::BLANK) { CollisionShape* shape = new StaticPlaneCollisionShape(_g.normal, -50 ); //CollisionShape* shape = new StaticPlaneCollisionShape(Ogre::Vector3(0,1,0), 0); RigidBody* body = new RigidBody(name ,world); body->setStaticShape(shape, 0.1 ,0.8); _add_shape(shape, body); } void add_shape(SceneNode* node, ogre_vec3 size) { //ToDo ogre_vec3 position = (_camera->getDerivedPosition() + _camera->getDerivedDirection().normalisedCopy() * 10); BoxCollisionShape* box_shape = new BoxCollisionShape(size); RigidBody* rigid_body = new RigidBody("defaultBoxRigid" + StringConverter::toString(box_nums), world); rigid_body->setShape( node, box_shape, 0.6f, // dynamic body restitution 0.6f, // dynamic body friction 1.0f, // dynamic bodymass position, // starting position of the box Quaternion(0,0,0,1)); // orientation of the box rigid_body->setLinearVelocity( _camera->getDerivedDirection().normalisedCopy() * 7.0f); // shoot speed _add_shape(box_shape, rigid_body); ++box_nums; }
然后在frameStarted 和 frameEnded 中启用模拟:
bool Game_controller::frameStarted(const FrameEvent& fe) { ogrebullet.frame_simulation(fe); return true; } bool Game_controller::frameEnded(const FrameEvent& fe) { ogrebullet.frame_simulation(fe); return true; } void frame_simulation(const FrameEvent& fe) { world->stepSimulation(fe.timeSinceLastFrame); }
我比较不明白的是,析构对象的时候,它会莫名奇妙地崩溃。。。先不管了,真正用的时候,再fixed 一下。
相关文章推荐
- Ecliplse 使用中遇到的问题
- c++中函数中变量内存分配以及返回指针、引用类型的思考
- 查看Linux版本系统信息方法汇总
- ALGOL语言
- VIM命令整理
- Codeforces Round #357 (Div. 2) Heap Operations
- javaweb—JDBC连接数据库
- bootstrap精简教程
- ES6 Generator Function 解救异步编程深度嵌套问题
- 判断操作系统代码
- Linux上安装和配置Hadoop
- PLSQL 循环游标 cursor loop fetch into
- C2C的道德边界:沦为从假运单到假病条的供假渠道
- 统计二进制树1的数目
- Eclipse Find/Replace
- HDU 1863 畅通工程 (最小生成树Kruskal)
- linux yum命令详解
- BZOJ 1304 叶子的染色 树形DP
- 关于百度地图API调用
- HDU 2243 (AC自动机 矩阵快速幂)