Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 OGRE Programming Intermediate Tutorial: Volume Selection.

Similar presentations


Presentation on theme: "1 OGRE Programming Intermediate Tutorial: Volume Selection."— Presentation transcript:

1 1 OGRE Programming Intermediate Tutorial: Volume Selection

2 2Contents 2 1.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 2.Introduce to graphics hardware buffers 3.Use two objects: ManualObject (to create the rectangle) PlaneBoundedVolumeListSceneQuery

3 3 - 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. Graphics Buffers

4 44 - 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. Vertex Buffers

5 555 - 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 Index Buffers

6 6 -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); The Selection Rectangle

7 77 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].

8 88 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();

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

10 10 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); } }; Definition of the Selection Rectangle

11 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 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 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(); … }

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

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

16 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


Download ppt "1 OGRE Programming Intermediate Tutorial: Volume Selection."

Similar presentations


Ads by Google