Ogre Moc笔记

转自:http://www.cppblog.com/flyindark/archive/2011/06/08/148281.html


MOC的资料不多,目前仅限于以下几处:
http://www.ogre3d.org/tikiwiki/Minimal+Ogre+Collision&structure=Libraries
http://www.ogre3d.org/forums/viewtopic.php?t=45267
http://sourceforge.net/projects/moc-collision/
http://www.ogre3d.org/forums/viewtopic.php?t=23440
http://code.google.com/p/minimal-ogre-collision-toolkit/

moc代码只有一个h和一个cpp文件,还算简洁的。也是很多年没有维护了,简单用用也算够了。

使用步骤
1、初始化
1 MOC::CollisionTools* mCollisionTools;
2 //  init the collision handler
3 mCollisionTools =  new CollisionTools(mSceneMgr, mArtifexLoader->mTerrainInfo);
4
5 //  set how far we want the camera to be above ground
6 mCollisionTools->setHeightAdjust(4.5f);
7
8 //  place the camera node on the ground
9 mCollisionTools->calculateY(mCamNode);

2、碰撞检测
 1 //  calculate the new Y position: check vs. terrain & all objects flagged with ENTITY_MASK
 2 //  multiple masks possible like e.g. ENTITY_MASK|MY_MASK|ETC_MASK
 3 //  doGridCheck casts a 2nd ray, gridWidth=2.0f ogre units away from the exact camera position to 
 4 //  avoid falling through small wholes or gaps in hangbridges for example.
 5 mCollisionTools->calculateY(mCamNode, true, true,2.0f,ENTITY_MASK);
 6
 7 //  check if we are colliding with anything with a collision radius of 2.5 ogre units and we 
 8 //  set the ray origin -1.0 lower towards the ground to get smaller obstacles too
 9 if (mCollisionTools->collidesWithEntity(oldPos, mCamNode->getPosition(), 2.5f, -1.0f, ENTITY_MASK))
10 {
11    // undo move
12    mCamNode->setPosition(oldPos);
13}

3、鼠标拾取,射线查询
 1 void SampleApp::pickEntity( const OIS::MouseEvent &arg,  const Ogre::uint32 queryMask)
 2 {
 3    Entity *tmpE = NULL;
 4    Vector3 result = Vector3::ZERO;
 5    float distToColl;
 6    if (mCollisionTools->raycastFromCamera(mRenderWin, mCamera, arg, result, (ulong&)tmpE, distToColl, queryMask))
 7    {
 8        SceneNode* node = tmpE->getParentSceneNode();
 9        if (node->getShowBoundingBox()) 
10        {
11            node->showBoundingBox(false);
12        }
 else 
13        {
14            node->showBoundingBox(true);
15        }

16    }

17}

18
19 bool SampleApp::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id)
20 {
21    if ( id == OIS::MB_Left )
22    {
23        mLMouseDown = true;
24        pickEntity(arg, ENTITY_MASK);
25    }

26}

4、清理
delete mCollisionTools;

5、中文资料
http://archive.cnblogs.com/a/1914145/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值