Skip to main content

History: MOGRE Line 3D

Source of version: 7

Copy to clipboard
            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|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.

{CODE(wrap="1", colors="c#")}// 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);{CODE}

If you want to remove the line you can do it like this:
{CODE(wrap="1", colors="c#")}// 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);  {CODE}

%%%
!!See also

* ((Line 3D))
* ((ManualObject))
* ((ManualObject 2D))
* ((Circle3D))
* ((Create Tetrahedron with MOGRE))
* ((DynamicLineDrawing)) - create a line by the class ''SimpleRenderable'', which can be modified with better performance
* ((Ogre Line Chart))
* Forum topic: [http://www.ogre3d.org/addonforums/viewtopic.php?f=8&t=11506|Rendering lines with thickness -- using BillboardChain] (Mogre)
* Forum topic: [http://www.ogre3d.org/addonforums/viewtopic.php?f=8&t=11503|DynamicLines - Mogre version]
* ((Debug Drawing Utility Class))
** [http://www.ogre3d.org/addonforums/viewtopic.php?f=8&t=14554|Mogre port] of Debug Drawing Utility Class

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.)

        

History

Information Version
Wed 11 of Apr, 2012 11:47 GMT-0000 Beauty updated the code for usage with Mogre 1.7 and newer 8
Sun 31 of Jul, 2011 23:30 GMT-0000 jacmoe 7
Fri 18 of Feb, 2011 16:45 GMT-0000 Beauty added links 6
Sun 30 of Jan, 2011 12:54 GMT-0000 Beauty 5
Wed 15 of Sep, 2010 09:51 GMT-0000 Beauty added link to ((DynamicLineDrawing)) + added porting note 4
Sat 09 of Jan, 2010 14:07 GMT-0000 Beauty linked word 3
Sun 27 of Dec, 2009 19:06 GMT-0000 jacmoe 2
Tue 16 of Dec, 2008 22:01 GMT-0000 Spacegaier some small layout changes 1