转自: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、初始化
2、碰撞检测
3、鼠标拾取,射线查询
4、清理
delete mCollisionTools;
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

3

4

5

6

7

8

9

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
}

2

3

4

5

6

7

8

9

10

11

12

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
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

4、清理

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