1 / 16

OGRE Programming Intermediate Tutorial: Volume Selection

OGRE Programming Intermediate Tutorial: Volume Selection. Contents. Perform volume selection. - Click and drag the mouse across the screen to define a rectangle - Release the mouse button to select all the objects within the selection area - Highlight the selected objects

glynise
Download Presentation

OGRE Programming Intermediate Tutorial: Volume Selection

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OGRE Programming Intermediate Tutorial: Volume Selection

  2. Contents • Perform volume selection. • - Click and drag the mouse across the screen to define a rectangle • - Release the mouse button to select all the objects within the selection area • - Highlight the selected objects • Introduce to graphics hardware buffers • Use two objects: • ManualObject (to create the rectangle) • PlaneBoundedVolumeListSceneQuery 2

  3. Graphics Buffers - Vertex buffers: define points in 3D space. - Index buffers: connect the points from the vertex buffer to form triangles. - Though all meshes have a vertex buffer, not all meshes will have an index buffer. - Vertex and index buffers: usually stored in the video card's own memory.

  4. Vertex Buffers - Define points in 3D space. - Each element in the vertex buffer is defined by several attributes: - Position: The only attribute must be set. - Optional properties: color, texture coordinates and so on. 4

  5. Index Buffers • Connect the points from the vertex buffer. • Every three indexes specified in the index buffer defines a single triangle to be drawn by the GPU. • The order of the vertices in the index buffer tells the graphics card which way the triangle faces. • A triangle drawn counter-clockwise is facing to the camera. • A triangle drawn clockwise is facing away from the camera. • - Normally only the front of a triangle is rendered 5 5

  6. The Selection Rectangle • Define in 2D • Be rendered and on top of all other objects on the screen in the overlay layer. • In the SelectionRectangle's constructor: • setRenderQueueGroup(RENDER_QUEUE_OVERLAY); • setUseIdentityProjection(true); • setUseIdentityView(true); • setQueryFlags(0);

  7. The Selection Rectangle: Coordinate System • A new coordinate system with X and Y running from -1 to 1 inclusive • Have to transform the coordinate system (CEGUI) with [0, 1] x [0, 1] to [-1, 1] x [-1, 1]. 7

  8. Definition of the Selection Rectangle • The line strip draws a line to each vertex from the previous vertex. • To create the rectangle, define 5 points (the first and the last point are the same to connect the entire rectangle): • clear(); • begin("", RenderOperation::OT_LINE_STRIP); • position(left, top, -1); • position(right, top, -1); • position(right, bottom, -1); • position(left, bottom, -1); • position(left, top, -1); • end(); 8

  9. Definition of the Selection Rectangle class SelectionRectangle : public ManualObject { public: SelectionRectangle(const String &name) : ManualObject(name) { setUseIdentityProjection(true); setUseIdentityView(true); setRenderQueueGroup(RENDER_QUEUE_OVERLAY); setQueryFlags(0); } };

  10. Definition of the Selection Rectangle class SelectionRectangle : public ManualObject { void setCorners(float left, float top, float right, float bottom) { //mapping to ogre3D projection plane left = left * 2 - 1; right = right * 2 - 1; top = 1 - top * 2; bottom = 1 - bottom * 2; clear(); begin("", RenderOperation::OT_LINE_STRIP); position(left, top, -1); position(right, top, -1); position(right, bottom, -1); position(left, bottom, -1); position(left, top, -1); end(); AxisAlignedBox box; box.setInfinite(); setBoundingBox(box); } }; 10

  11. //Mapping to Ogre3D Projection Plane Space //BEGIN Using CEGUI //left = left * 2 - 1; //right = right * 2 - 1; //top = 1 - top * 2; //bottom = 1 - bottom * 2; //End USING CEGUI //BEGIN Using TrayMgr left = left * 2 - 1; right = right * 2 - 1; top = -1 - top * 2; bottom = -1 -bottom * 2; //End USING TrayMgr

  12. Volume selection process • Define a volume selection query: • PlaneBoundedVolumeListSceneQuery *mVolQuery; • Obtain the four rays at the four corners of the selection rectangle • Define the selection volume using the four rays • define the five planes which enclosing a selection volume; volList stores the list of the planes • set the selection volume: mVolQuery->setVolumes(volList); • execute the query; perform tasks on the results

  13. Volume selection : code • { • … • Ray topLeft = mCamera->getCameraToViewportRay(left, top); • Ray topRight = mCamera->getCameraToViewportRay(right, top); • Ray bottomLeft = mCamera->getCameraToViewportRay(left, bottom); • Ray bottomRight = mCamera->getCameraToViewportRay(right, bottom); • // The plane faces the counter clockwise position. • PlaneBoundedVolume vol; • int np = 100; • vol.planes.push_back(Plane(topLeft.getPoint(3), topRight.getPoint(3), bottomRight.getPoint(3))); // front plane • vol.planes.push_back(Plane(topLeft.getOrigin(), topLeft.getPoint(np), topRight.getPoint(np))); // top plane • vol.planes.push_back(Plane(topLeft.getOrigin(), bottomLeft.getPoint(np), topLeft.getPoint(np))); // left plane • vol.planes.push_back(Plane(bottomLeft.getOrigin(), bottomRight.getPoint(np), bottomLeft.getPoint(np))); // bottom plane • vol.planes.push_back(Plane(bottomRight.getOrigin(), topRight.getPoint(np), bottomRight.getPoint(np))); // right plane • PlaneBoundedVolumeList volList; • volList.push_back(vol); • mVolQuery->setVolumes(volList); • SceneQueryResult result = mVolQuery->execute(); • … … • } 13

  14. How to define mVolQuery ? PlaneBoundedVolumeList volList; mVolQuery = mSceneMgr ->createPlaneBoundedVolumeQuery(volList);

  15. Mapping to screen coordinates: mTrayMgr Ray mRay =mTrayMgr->getCursorRay(mCamera); Vector2 scn = mTrayMgr ->sceneToScreen( mCamera, mRay.getOrigin());

  16. References: http://www.ogre3d.org/wiki/index.php/Intermediate_Tutorial_3 Note: The selection volume is not correct in the original code. Last visit 1st April, 2008

More Related