Welcome to the new Ogre Wiki!
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
Sometimes its useful to have a 3D grid placed on the XZ plane as base of reference for your scene. This short code would show you how to construct the 3D grid using a ManualObject centered at the origin.
private void CreateGrid(int numcols, int numrows, float unitsize) { ManualObject grid = mSceneMgr.CreateManualObject("grid"); grid.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_LINE_LIST); float width = (float)numcols * unitsize; float depth = (float)numrows * unitsize; Vector3 center = new Vector3(-width / 2.0f, 0, -depth / 2.0f); for (int i = 0; i < numrows; ++i) { Vector3 s, e; s.x = 0.0f; s.z = i * unitsize; s.y = 0.0f; e.x = width; e.z = i * unitsize; e.y = 0.0f; grid.Position(s + center); grid.Position(e + center); } grid.Position(new Vector3(0.0f, 0.0f, numrows * unitsize) + center); grid.Position(new Vector3(width, 0.0f, numrows * unitsize) + center); for (int i = 0; i < numcols; ++i) { Vector3 s, e; s.x = i * unitsize; s.z = depth; s.y = 0.0f; e.x = i * unitsize; e.z = 0.0f; e.y = 0.0f; grid.Position(s + center); grid.Position(e + center); } grid.Position(new Vector3(numcols * unitsize, 0.0f, 0.0f) + center); grid.Position(new Vector3(numcols * unitsize, 0.0f, depth) + center); grid.End(); mSceneMgr.RootSceneNode.AttachObject(grid); }
The grid resolution depends on the parameter numrows and numcols. The unitsize parameter tells how big each cell is in world units.
This also constructs the grid with the predefined / hard coded "BaseWhiteNoLighting" material.
Contributors to this page: jacmoe
and
Beauty
.
Page last modified on Sunday 27 of December, 2009 23:19:04 UTC by jacmoe
.
The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.
Sidebar
Search box
Online users
41
online users

