Skip to main content

History: Create Tetrahedron with MOGRE

Preview of version: 12

Tetrahedron-turning-120px.gif
Image

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 4 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()

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

Copy to clipboard
// 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));

Copy to clipboard
// remove tetrahedrons if (mScene.Smgr.HasManualObject(tetraName)) mScene.Smgr.GetManualObject(tetraName).Clear();

See also

History

Information Version
Sun 31 of Jul, 2011 23:31 GMT-0000 jacmoe 20
Sat 05 of Mar, 2011 20:53 GMT-0000 Beauty added 2 links + blank lines for better overview 19
Fri 26 of Nov, 2010 19:37 GMT-0000 Beauty corrected wrong URL 18
Fri 26 of Nov, 2010 17:13 GMT-0000 Beauty mistype correction 17
Wed 18 of Aug, 2010 15:38 GMT-0000 Beauty added link 16
Wed 18 of Aug, 2010 15:37 GMT-0000 Beauty mistype correction 15
Mon 26 of Jul, 2010 09:00 GMT-0000 Beauty mistype correction 14
Mon 26 of Jul, 2010 08:59 GMT-0000 Beauty tiny changes 13
Sun 25 of Jul, 2010 02:08 GMT-0000 mstoyke It's 4 triangles, not 3 :) 12
Fri 23 of Jul, 2010 12:18 GMT-0000 Beauty mistype correction 11
Sat 09 of Jan, 2010 14:27 GMT-0000 Beauty corrected link 10
Thu 31 of Dec, 2009 00:10 GMT-0000 jacmoe 9
Thu 31 of Dec, 2009 00:10 GMT-0000 jacmoe 8
Thu 31 of Dec, 2009 00:09 GMT-0000 jacmoe 7
Thu 31 of Dec, 2009 00:06 GMT-0000 jacmoe 6
Sun 27 of Dec, 2009 19:34 GMT-0000 jacmoe 5
Sun 27 of Dec, 2009 19:33 GMT-0000 jacmoe 4
Sun 27 of Dec, 2009 19:33 GMT-0000 jacmoe 3
Sun 27 of Dec, 2009 19:09 GMT-0000 jacmoe 2
Thu 30 of Apr, 2009 13:34 GMT-0000 Beauty added note for particles as alternative 1