History: Peter's Grid System
Source of version: 15
Copy to clipboard
{DIV(type="div",bg="#FFC",align="center")}__Warning__: Article under construction...{DIV}
!! Introduction
After some digging around about grid systems and trying ((EditorGridSystem|Jeroen Dierckx's EditorGridSystem)), We decided to write our own grid system with different feature set and release it to the community, because Ogre is si cool.
{maketoc}
!! Screenshots
||{img fileId="2182" thumb="y" rel="box[g]"}|{img fileId="2183" thumb="y" rel="box[g]"}
{img fileId="2185" thumb="y" rel="box[g]"}|{img fileId="2184" thumb="y" rel="box[g]"}||
!! Features
Following features are supported by Peter's Grid System:
* This grid have three planes support - XY, XZ, YZ that can be visible/hidden
* Grid is generated/updated by request, uses ManualObject
* Limitations in each dimension
* Cell size per dimension
* Grid Offset
* Colors for offset, master and division axis,
* Does NOT depend from the camera type used,
* Not limited to one instance (no named items used!)
!! Usage
To create a grid, just create an instance of the class and set the properties you want to, then call {MONO()}update(){MONO}
{FADE(label="View C++ code")}
{CODE(wrap="1", colors="c++")}
/*OgreGrid*/ grid = new OgreGrid(/*Ogre::SceneManager*/ui->TheScene->scene, /*Material name*/"BaseWhiteAlphaBlended");
//Where to draw the grid?
grid->drawQueue = Ogre::RENDER_QUEUE_OVERLAY;
//Attach it to some SceneNode
grid->attachToNode(scene->getRootSceneNode());
//Some grid settings
grid->setCellSize(0.5);
grid->ymin = -9;
grid->ymax = 2;
grid->ofY = 2;
grid->zmin = -2;
grid->zmax = 1;
grid->showXZ = true;
grid->showXY = true;
grid->showYZ = true;
grid->setDivisions(10);
grid->colorDivision = Ogre::ColourValue(0,1,0,0.3);
grid->colorOffset = Ogre::ColourValue(0,0,1,1);
grid->colorMaster = Ogre::ColourValue(1,0,0,0.7);
//Regenerate the grid
grid->update();
{CODE}
{FADE}
!! Options
After creating an instance to the grid class, you can set the options of the grid you want to. After you change option, you must call {MONO()}update(){MONO} to update the grid manually. All options are public data members with the exception of some convenience setters.
!!!!Cell sizes
{MONO()}float csX, csY, csZ{MONO} are used to control the master grid axes distance, per dimaneion. You may have a grid with cell size 2x1 in the X/Y dimension. You can use grid sizes such as 0.5x0.5. You can also use {MONO()}setCellSize(float size){MONO} and {MONO()}setCellSize(float x, float y, float z){MONO} for this purpose.
!!!!Zero offset
{MONO()}float ofX, ofY, ofZ{MONO} are used to move the center of the grid in each dimension. You can also use {MONO()}setOffset(float x, float y, float z){MONO}
!!!!Division count
{MONO()}int divX, divY, divZ{MONO} are used to set the number of subdivisions in each dimension. You can also use {MONO()}setDivisions(int n){MONO} and {MONO()}setDivisions(int x,int y,int z){MONO} for this purpose. To show or hide the divisions and use only the master axes, set {MONO()}bool showDivisions{MONO}
!!!!Grid range limitations
Our grid is limited to certain values in each division. If axis is limited from -5 to +5, only these cells that are in this range will be drawn for the given dimension. Limitations are set via {MONO()}int xmin, xmax, ymin, ymax, zmin, zmax{MONO}. Note that the default limitations are from -5 to +5, and the system does not support infinite grids still. In the future, I may decide to implement infinite planes. Also, setting huge limitations will generate too much lines and may affect performance, especially if there are too much divisions, as well. If you want infinite 2D grid, you should consider ((EditorGridSystem|Jeroen Dierckx's EditorGridSystem)) instead.
!!!!Shown planes
You can set which grid plane is drawn by setting {MONO()}bool showXY, showXZ, showYZ{MONO} as you like. By default, only the XY plane is shown. You can also use {MONO()}showPlanes(bool xy, bool xz, bool yz){MONO} for this purpose.
!!!!Colors:
* {MONO()}colorMaster{MONO} - The color of master lines. Master lines are drawn each cell size units.
* {MONO()}colorOffset{MONO} - The color of the offset lines, e.g. these that pass thru (0,0,0)+Grid's offset
* {MONO()}colorDivision{MONO} - The color of the division lines. You usually want to set lighter color for these.
Please note that the default material, "BaseWhiteNoLighting", does not support alpha from the vertex colors. Peter's Grid System uses vertex colors for grid lines color, and all this is within 1 section in 1 ManualObject. If you want alpha, you can use the following material:
{FADE(label="View material")}
{CODE(wrap="1", colors="C++")}
material "BaseWhiteAlphaBlended"
{
receive_shadows on
transparency_casts_shadows off
technique
{
lod_index 0
scheme Default
pass
{
lighting off
max_lights 8
start_light 0
iteration once
point_size 4
point_sprites off
point_size_attenuation off
point_size_min 0
point_size_max 0
scene_blend alpha_blend
depth_check on
alpha_rejection always_pass 0
alpha_to_coverage off
transparent_sorting on
depth_write on
depth_func less_equal
depth_bias 0 0
iteration_depth_bias 0
light_scissor off
light_clip_planes off
cull_hardware clockwise
cull_software back
shading gouraud
polygon_mode solid
polygon_mode_overrideable on
normalise_normals off
fog_override false
}
}
}
{CODE}
{FADE}