OgreBullet 的使用
来源:互联网 发布:刻录软件怎么用 编辑:程序博客网 时间:2024/06/14 22:35
最近做实训,用到Ogre 的引擎。
在渲染方面,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 一下。
1 0
- OgreBullet 的使用
- 关于ogrebullet中如何判断两个物体何时碰撞的问题
- 学习OgreBullet【1】
- GUID使用的使用
- ${}的使用
- 的使用
- @[],@()的使用
- ->的使用
- +、-、*、/、%的使用
- &&的使用
- %:的使用
- Makefile中使用$$的使用
- Makefile中使用$$的使用
- Red5的使用--使用日志
- prefernce的使用具体使用
- 【工具使用】git 的使用
- 关于使用AsyncTaskLoader的使用
- 使用CABasicAnimation的基本使用
- PLSQL 循环游标 cursor loop fetch into
- Android中的内存泄露(一.内存泄漏的认识以及LeakCannry的基本用法)
- UGUI的事件机制
- C/c++几个预定义的宏:__DATE__,__TIME__,__FILE__,__LINE__
- EL表达式
- OgreBullet 的使用
- 利用 BASE64Encoder 对字符串进行加密 BASE64Decoder进行解密
- Coin Change
- Java 面试题汇总 《个人从各种看过的面试宝典里面集合过来的》
- Android RecyclerView 完全解析
- MySQL 基于存储过程 实现数据统计按日、周、月份统计模板
- javaweb—SpringMVC+Spring+MyBatis整合
- 查看Linux版本系统信息方法汇总
- Java合并数组的两个子有序段