MOGRE Line 3D        
Print

This is a fine code snippet to create a line in 3D space. Independent of distance to the camera it's always to see with one pixel width (unless there is no object between).

Regard that you call this code only once and not every frame. If you need moving a line adapt the snippet.

The material can be reused. Also the ManualObject can be reused (for that call manOb.Clear()).

For this you have to declare the objects in the class and assign/update them in a method.

If you need more than one line, regard to create ManualObjects and SceneNodes with different name.

The code is a port of Line 3D, what was created by DWORD and jacmoe.

// create material (colour)
MaterialPtr moMaterial = MaterialManager.Singleton.Create("line_material", "debugger");
moMaterial.ReceiveShadows = false;
moMaterial.GetTechnique(0).SetLightingEnabled(true);
moMaterial.GetTechnique(0).GetPass(0).SetDiffuse(0, 0, 1, 0);
moMaterial.GetTechnique(0).GetPass(0).SetAmbient(0, 0, 1);
moMaterial.GetTechnique(0).GetPass(0).SetSelfIllumination(0, 0, 1);
moMaterial.Dispose();  // dispose pointer, not the material
 
// create line object
ManualObject manOb = Smgr.CreateManualObject("line");
manOb.Begin("line_material", RenderOperation.OperationTypes.OT_LINE_LIST);
manOb.Position(30, 20, 10);
manOb.Position(40, 10, 0);
// ... maybe more points
manOb.End();
 
// create SceneNode and attach the line
SceneNode moNode = Smgr.RootSceneNode.CreateChildSceneNode("line_node");
moNode.SetPosition(Vector3.ZERO);
moNode.AttachObject(manOb);

 
If you want to remove the line you can do it like this:

// destroy the line
Smgr.DestroyManualObject("line"); 
 
// destroy the SceneNode (or keep it to add other manual objects)
Smgr.DestroySceneNode("line_node");                
 
// alternatively just hide, if you want to use the line same again
Smgr.GetSceneNode("line_node").SetVisible(false);

 

See also

 

 
Note: If somebody ports some C++ code to C#, please publish it. (Just make a quick paste to the Mogre forum and we will add it to the wiki.)


Contributors to this page: jacmoe111451 points  , Spacegaier3733 points  and Beauty5965 points  .
Page last modified on Sunday 31 of July, 2011 23:30:29 GMT by jacmoe111451 points .


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.