Create Tetrahedron with MOGRE
From Ogre Wiki
|
This is a method to create a tetrahedron as ManualObject.
For Ogre users it should be easy to port.
If somebody do so, please publish the code (or send it to user Beauty.
It's going easy on resources (just 4 vertices and 3 triangles) and usefull if you need many objects in your scene. For example to add marks at different positions where an airplane was flying along.
If there are problems with the code ask user Beauty.
Alternatively you can use Particles. They can have nice visual effects and maybe they need less performance(?).
CreateTetrahedron()
/// <summary>
/// Create a tetrahedron with point of origin in middle of volume.
/// It will be added to the SceneManager as ManualObject. The material must still exists.
/// </summary>
/// <param name="position">Position in scene</param>
/// <param name="scale">Size of the tetrahedron</param>
/// <param name="name">Name of the ManualObject that will be created</param>
/// <param name="materialName">Name of the used material</param>
///
void CreateTetrahedron(String name, Vector3 position, Single scale, String materialName)
{
ManualObject manObTetra = new ManualObject(name);
manObTetra.CastShadows = false;
// render just before overlays (so all objects behind the transparen tetrahedron are visible)
manObTetra.RenderQueueGroup = (byte)RenderQueueGroupID.RENDER_QUEUE_OVERLAY - 1; // = 99
Vector3[] c = new Vector3[4]; // corners
// calculate corners of tetrahedron (with point of origin in middle of volume)
Single mbot = scale * 0.2f; // distance middle to bottom
Single mtop = scale * 0.62f; // distance middle to top
Single mf = scale * 0.289f; // distance middle to front
Single mb = scale * 0.577f; // distance middle to back
Single mlr = scale * 0.5f; // distance middle to left right
// width / hight / depth
c[0] = new Vector3(-mlr, -mbot, mf); // left bottom front
c[1] = new Vector3( mlr, -mbot, mf); // right bottom front
c[2] = new Vector3( 0, -mbot, -mb); // (middle) bottom back
c[3] = new Vector3( 0, mtop, 0); // (middle) top (middle)
// add position offset for all corners (move tetrahedron)
for (Int16 i = 0; i <= 3; i++)
c[i] += position;
// create bottom
manObTetra.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
manObTetra.Position(c[2]);
manObTetra.Position(c[1]);
manObTetra.Position(c[0]);
manObTetra.Triangle(0, 1, 2);
manObTetra.End();
// create right back side
manObTetra.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
manObTetra.Position(c[1]);
manObTetra.Position(c[2]);
manObTetra.Position(c[3]);
manObTetra.Triangle(0, 1, 2);
manObTetra.End();
// create left back side
manObTetra.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
manObTetra.Position(c[3]);
manObTetra.Position(c[2]);
manObTetra.Position(c[0]);
manObTetra.Triangle(0, 1, 2);
manObTetra.End();
// create front side
manObTetra.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
manObTetra.Position(c[0]);
manObTetra.Position(c[1]);
manObTetra.Position(c[3]);
manObTetra.Triangle(0, 1, 2);
manObTetra.End();
} // CreateTetrahedron
Using example
// a material with the name materialName must be created or loaded! Vector3 position = new Vector3(1, 1, -1); Single size = 1; String tetraName = "terta"; // create manual object CreateTetrahedron(tetraName, position, size, materialName); // attach to scene mScene.Smgr.RootSceneNode.AttachObject(mScene.Smgr.GetManualObject(tetraName));
// remove tetrahedrons
if (mScene.Smgr.HasManualObject(tetraName))
mScene.Smgr.GetManualObject(tetraName).Clear();
See also
- MOGRE Line 3D - includes some code how to create a material on the fly
- ManualObject
- ManualObject - API class reference with description
- CodeSnippets for ManualObject
- Particle



