ogre programming intermediate tutorial
DESCRIPTION
OGRE Programming Intermediate Tutorial. Contents. Select any object on the screen using the mouse Restrict what is selectable. 2. Showing the selected object. Show the bounding box of a scene node: mCurrentObject->showBoundingBox(true); //mCurrentObject is a SceneNode. - PowerPoint PPT PresentationTRANSCRIPT
1
OGRE ProgrammingOGRE Programming
Intermediate TutorialIntermediate Tutorial
2
ContentsContents
2
1. Select any object on the screen using the mouse
2. Restrict what is selectable
3
Show the bounding box of a scene node:
mCurrentObject->showBoundingBox(true);
//mCurrentObject is a SceneNode.
Showing the selected object
4
1. Setup the ray for the ray scene query
2. Set the sorting type for the results
3. Execute the ray scene query
4. Retrieve intersection results
5. Based on the results, perform the specific task
Process of Ray Scene QueryProcess of Ray Scene Query
55
CEGUI::Point mousePos = CEGUI::MouseCursor::getSingleton().getPosition(); Ray mouseRay = mCamera->getCameraToViewportRay(
mousePos.d_x /float( arg.state.width ) , mousePos.d_y /float( arg.state.height ));
mRaySceneQuery->setRay(mouseRay); mRaySceneQuery->setSortByDistance(true); // Perform the scene query
RaySceneQueryResult &result = mRaySceneQuery->execute();RaySceneQueryResult::iterator itr = result.begin();
for (itr = result.begin(); itr != result.end(); itr++) { if (itr->movable && itr->movable->getName().substr(0, 5) !
= "tile[") { mCurrentObject = itr->movable->getParentSceneNode(); break; } // if
else if (itr->worldFragment) {……
} }
Process of Ray Scene QueryProcess of Ray Scene Query
66
Query MasksMask: bitwise value.The mask can be used to restrict the objects which are selectable.
Set the mask for an entity:ent->setQueryFlags(ROBOT_MASK);
Set the ray scene query for the entity whose query Set the ray scene query for the entity whose query flag is QMASKflag is QMASK
mRaySceneQuery->setQueryMask(QMASK);//now, if //now, if ROBOT_MASK & QMASK ROBOT_MASK & QMASK is is non-zeronon-zero, then the , then the corresponding entities are returned in the query results.corresponding entities are returned in the query results.
7
Query Type Masks
The query never returns the billboardset normally. Why?
The SceneQuery has another mask: QueryTypeMask.
It limits the selection type specified as the flag.
By default, it returns only objects of entity type.
To return BillboardSets or ParticleSystems:
mRaySceneQuery->setQueryTypeMask(SceneManager::FX_TYPE_MASK);
8
QueryTypeMask
Six types of QueryTypeMask defined in the SceneManager class as static members:
WORLD_GEOMETRY_TYPE_MASK //Returns world geometry.
ENTITY_TYPE_MASK //Returns entities.
FX_TYPE_MASK //Returns billboardsets / particle systems.
STATICGEOMETRY_TYPE_MASK //Returns static geometry.
LIGHT_TYPE_MASK //Returns lights.
USER_TYPE_MASK_LIMIT //User type mask limit.
The default QueryTypeMask : ENTITY_TYPE_MASK
9
References: References:
http://www.ogre3d.org/wiki/index.php/Intermediate_Tutorial_3