1 ogre programming intermediate tutorial: volume selection

16
1 OGRE Programming OGRE Programming Intermediate Intermediate Tutorial: Volume Tutorial: Volume Selection Selection

Upload: silvester-lang

Post on 18-Jan-2016

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 OGRE Programming Intermediate Tutorial: Volume Selection

1

OGRE ProgrammingOGRE Programming

Intermediate Tutorial: Intermediate Tutorial: Volume SelectionVolume Selection

Page 2: 1 OGRE Programming Intermediate Tutorial: Volume Selection

2

ContentsContents

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 buffers3. Use two objects:

ManualObject (to create the rectangle) PlaneBoundedVolumeListSceneQuery

Page 3: 1 OGRE Programming Intermediate Tutorial: Volume Selection

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 BuffersGraphics Buffers

Page 4: 1 OGRE Programming Intermediate Tutorial: Volume Selection

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 BuffersVertex Buffers

Page 5: 1 OGRE Programming Intermediate Tutorial: Volume Selection

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 BuffersIndex Buffers

Page 6: 1 OGRE Programming Intermediate Tutorial: Volume Selection

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 RectangleThe Selection Rectangle

Page 7: 1 OGRE Programming Intermediate Tutorial: Volume Selection

77

The Selection Rectangle: The Selection Rectangle: Coordinate SystemCoordinate 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].

Page 8: 1 OGRE Programming Intermediate Tutorial: Volume Selection

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

Page 9: 1 OGRE Programming Intermediate Tutorial: Volume Selection

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

Page 10: 1 OGRE Programming Intermediate Tutorial: Volume Selection

1010

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

Page 11: 1 OGRE Programming Intermediate Tutorial: Volume Selection

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 TrayMgrleft = left * 2 - 1;right = right * 2 - 1;top = -1 - top * 2;bottom = -1 -bottom * 2;//End USING TrayMgr

Page 12: 1 OGRE Programming Intermediate Tutorial: Volume Selection

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

Page 13: 1 OGRE Programming Intermediate Tutorial: Volume Selection

1313

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 planevol.planes.push_back(Plane(topLeft.getOrigin(), topLeft.getPoint(np), topRight.getPoint(np))); // top planevol.planes.push_back(Plane(topLeft.getOrigin(), bottomLeft.getPoint(np),

topLeft.getPoint(np))); // left planevol.planes.push_back(Plane(bottomLeft.getOrigin(), bottomRight.getPoint(np),

bottomLeft.getPoint(np))); // bottom planevol.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();

… …}

Page 14: 1 OGRE Programming Intermediate Tutorial: Volume Selection

14

PlaneBoundedVolumeList volList;

mVolQuery = mSceneMgr-

>createPlaneBoundedVolumeQuery(volList);

How to define mVolQuery ?

Page 15: 1 OGRE Programming Intermediate Tutorial: Volume Selection

15

Ray mRay =mTrayMgr->getCursorRay(mCamera);

Vector2 scn = mTrayMgr ->sceneToScreen( mCamera, mRay.getOrigin());

Mapping to screen coordinates:mTrayMgr

Page 16: 1 OGRE Programming Intermediate Tutorial: Volume Selection

16

References: References:

http://www.ogre3d.org/wiki/index.php/Intermediate_Tutorial_3http://www.ogre3d.org/wiki/index.php/Intermediate_Tutorial_3

Note: The selection volume is not correct in the original code. Note: The selection volume is not correct in the original code. Last visit 1st April, 2008Last visit 1st April, 2008