90 likes | 218 Vues
This tutorial covers essential intermediate techniques in Ogre programming. Learn how to select objects on the screen using the mouse, restrict selectable entities, and show the selected object's bounding box. Understand the process of ray scene queries, including how to set up rays, execute queries, and retrieve intersection results. Discover the use of query masks to restrict selectable objects and how to utilize various query type masks. This guide provides practical examples and detailed explanation to enhance your skills in 3D scene management.
E N D
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.
Process of Ray Scene Query • Setup the ray for the ray scene query • Set the sorting type for the results • Execute the ray scene query • Retrieve intersection results • Based on the results, perform the specific task
Process of Ray Scene Query 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) { …… } } 5
Query Masks • Mask: 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 flag is QMASK • mRaySceneQuery->setQueryMask(QMASK); • //now, if ROBOT_MASK & QMASK is non-zero, then the corresponding entities are returned in the query results. 6
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);
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
References: http://www.ogre3d.org/wiki/index.php/Intermediate_Tutorial_3