/// <summary> /// Large vertex displacements such as are possible with C3E4v_twist /// require a high degree of tessellation. This routine draws a /// triangle recursively subdivided to provide sufficient tessellation. */ /// </summary> static void DrawSubDividedTriangle(ManualObject obj, int subdivisions) { float[] a = new float[2] { -0.8f, 0.8f }; float[] b = new float[2] { 0.8f, 0.8f }; float[] c = new float[2] { 0.0f, -0.8f }; float[] ca = new float[3] { 0, 0, 1 }; float[] cb = new float[3] { 0, 0, 1 }; float[] cc = new float[3] { 0.7f, 0.7f, 1 }; RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST; obj.Begin("CgTutorials/C3E4_Material", operation); TriangleDivide(obj, subdivisions, a, b, c, ca, cb, cc); obj.End(); }
private void CreateLine(ManualObject mo, Vector3 origin, Vector3 final, int useMaterial, Vector4 color) { float lineWidth = 0.1f; RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_FAN; switch (useMaterial) { case 1: mo.Begin("SharpMap/Line3D_v1", operation); break; default: MaterialPtr material = MaterialManager.Singleton.CreateOrRetrieve("Test/ColourLines3d", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME).first; material.GetTechnique(0).GetPass(0).VertexColourTracking = (int)TrackVertexColourEnum.TVC_AMBIENT; mo.Begin("Test/ColourLines3d", operation); break; } Vector3 delta = final - origin; delta = new Vector3(-delta.y, delta.x, delta.z).NormalisedCopy *lineWidth; mo.Position(origin); mo.Position(final); mo.Position(final + delta); mo.Position(origin + delta); //lines3d.TextureCoord((float)i / (float)pointsList.Count); ManualObject.ManualObjectSection section = lines3d.End(); section.SetCustomParameter(constantColor, color); }
private bool CheckSubMeshOpType(MeshPtr mesh, RenderOperation.OperationTypes opType) { for (ushort i = 0; i < mesh.NumSubMeshes; i++) { if (mesh.GetSubMesh(i).operationType != opType) { return(false); } } return(true); }
public void BeginBlock() { Console.WriteLine("BeginBlock"); pointsList = new List <Point>(); if (rendererObj == null) { rendererObj = sceneManager.CreateManualObject("Element" + count); count++; } RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST; MaterialPtr material = MaterialManager.Singleton.CreateOrRetrieve("Test/ColourLines3d", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME).first; material.GetTechnique(0).GetPass(0).VertexColourTracking = (int)TrackVertexColourEnum.TVC_AMBIENT; rendererObj.Begin("Test/ColourLines3d", operation); }
static ManualObject DrawTriangle(ManualObject obj) { RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST; obj.Begin("CgTutorials/C3E2_Material", operation); obj.Position(0.0f, -0.8f, 0.0f); obj.Colour(0, 0, 1); /* Blue */ obj.Position(0.8f, 0.8f, 0.0f); obj.Colour(0, 1, 0); /* Green */ obj.Position(-0.8f, 0.8f, 0.0f); obj.Colour(1, 0, 0); /* Red */ obj.End(); return(obj); }
static ManualObject DrawTriangle(ManualObject obj) { RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST; obj.Begin("CgTutorials/C3E5_Material", operation); obj.Position(0.0f, -0.8f, 0.0f); obj.TextureCoord(0, 0); obj.Position(0.8f, 0.8f, 0.0f); obj.TextureCoord(1, 0); obj.Position(-0.8f, 0.8f, 0.0f); obj.TextureCoord(0.5f, 1); obj.End(); return(obj); }
1, 2, 3 }; // back face /* * static public void CreateBoidMesh(string name, string color) * { * Vector3[] colors = baseColors; * if (color.Equals("green")) * { * colors[0] = colors[1] = colors[2] = new Vector3(0.0f, 1.0f, 0.0f); * } * else if (color.Equals("red")) * { * colors[0] = colors[1] = colors[2] = new Vector3(1.0f, 0.0f, 0.0f); * } * * // Return now if already exists * if (MeshManager.Singleton.ResourceExists(name)) * return; * * MeshBuilderHelper mbh = new MeshBuilderHelper(name, "Flocking", false, 0, (uint)pts.Length); * * UInt32 offPos = mbh.AddElement(VertexElementType.VET_FLOAT3, VertexElementSemantic.VES_POSITION).Offset; * UInt32 offDiff = mbh.AddElement(VertexElementType.VET_FLOAT3, VertexElementSemantic.VES_DIFFUSE).Offset; * * mbh.CreateVertexBuffer(HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY); * for (int count = 0; count < pts.Length; count++) * { * mbh.SetVertFloat((uint)count, offPos, pts[count].x, pts[count].y, pts[count].z); //position * mbh.SetVertFloat((uint)count, offDiff, colors[count].x, colors[count].y, colors[count].z); //color * } * * mbh.CreateIndexBuffer((uint)(indices.Length / 3), HardwareIndexBuffer.IndexType.IT_16BIT, HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY); * for (uint index = 0; index < indices.Length / 3; index++) * { * mbh.SetIndex16bit(index, (UInt16)(indices[index * 3]), * (UInt16)(indices[index * 3 + 1]), * (UInt16)(indices[index * 3 + 2])); * } * * MaterialPtr material = MaterialManager.Singleton.CreateOrRetrieve("Test/ColourTest", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME).first; * material.GetTechnique(0).GetPass(0).VertexColourTracking = (int)TrackVertexColourEnum.TVC_AMBIENT; * MeshPtr m = mbh.Load("Test/ColourTest"); * m._setBounds(new AxisAlignedBox(-1.0f, -1.0f, -1.0f, * 1.0f, 1.0f, 1.0f), false); * m._setBoundingSphereRadius((float)System.Math.Sqrt(1.0f * 1.0f + 1.0f * 1.0f)); * } */ public static ManualObject CreateBoidObject(string name, SceneManager sceneMgr, string color) { Vector3[] colors = baseColors; if (color.Equals("green")) { colors[0] = colors[1] = colors[2] = new Vector3(0.0f, 1.0f, 0.0f); } else if (color.Equals("red")) { colors[0] = colors[1] = colors[2] = new Vector3(1.0f, 0.0f, 0.0f); } // Return now if already exists if (MeshManager.Singleton.ResourceExists(name)) { return(null); } ManualObject boidObj = sceneMgr.CreateManualObject(name); RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST; MaterialPtr material = MaterialManager.Singleton.CreateOrRetrieve("Test/Boid", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME).first; material.GetTechnique(0).GetPass(0).VertexColourTracking = (int)TrackVertexColourEnum.TVC_AMBIENT; boidObj.Begin("Test/Boid", operation); for (int count = 0; count < pts.Length; count++) { boidObj.Position(pts[count]); //position boidObj.Colour(colors[count].x, colors[count].y, colors[count].z); //color } for (uint index = 0; index < indices.Length / 3; index++) { boidObj.Index((ushort)(indices[index * 3])); boidObj.Index((ushort)(indices[index * 3 + 1])); boidObj.Index((ushort)(indices[index * 3 + 2])); } boidObj.End(); return(boidObj); }
public ManualObject CreateNode(string name, SceneManager sceneMgr) { ManualObject manualObj = sceneMgr.CreateManualObject(name); RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST; MaterialPtr material = MaterialManager.Singleton.Create("Test/Tutorial00", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); material.GetTechnique(0).GetPass(0).VertexColourTracking = (int)TrackVertexColourEnum.TVC_AMBIENT; manualObj.Begin("Test/Tutorial00", operation); manualObj.Position(-5.0f, 0.0f, 0.0f); manualObj.Position(5.0f, 0.0f, 0.0f); manualObj.Position(0.0f, 5.0f, 0.0f); manualObj.End(); return(manualObj); }
static void DrawStar(ManualObject obj, float x, float y, int starPoints, float R, float r) { int i; float piOverStarPoints = 3.14159f / starPoints, angle = 0.0f; RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_FAN; obj.Begin("CgTutorials/C2E2_green_Material", operation); obj.Position(x, y, 0.0f); /* Center of star */ /* Emit exterior vertices for star's points. */ for (i = 0; i < starPoints; i++) { obj.Position(x + R * Math.Cos(angle), y + R * Math.Sin(angle), 0.0f); angle += piOverStarPoints; obj.Position(x + r * Math.Cos(angle), y + r * Math.Sin(angle), 0.0f); angle += piOverStarPoints; } /* End by repeating first exterior vertex of star. */ angle = 0; obj.Position(x + R * Math.Cos(angle), y + R * Math.Sin(angle), 0.0f); obj.End(); }
public ManualObject CreateNode(string name, SceneManager sceneMgr, bool useScreenPos) { ManualObject manualObj = sceneMgr.CreateManualObject(name); RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST; if (useScreenPos) { manualObj.Begin("CgTutorials/C2E1v_green_Material", operation); } else { manualObj.Begin("CgTutorials/C2E1v_green_Material_2", operation); } manualObj.Position(-0.5f, 0.0f, 0.0f); manualObj.Position(0.5f, 0.0f, 0.0f); manualObj.Position(0.0f, 0.5f, 0.0f); manualObj.End(); return(manualObj); }
static ManualObject.ManualObjectSection BuildTerrainBlock(ManualObject obj, ushort pointsX, ushort pointsY, Vector4 translationScale, Vector4 color) { RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_STRIP; obj.Begin("Terrain/Terrain_Material", operation); /* * This function uses one big zigzag triangle strip for the whole grid. * And insert degenerated (invisible) triangles to join 2 rows. For instance: * 0 1 2 3 * 4 5 6 7 * 8 9 10 11 * 12 13 14 15 * * The index buffer would look like : * 0, 4, 1, 5, 2, 6, 3, 7, 7, 7, 11, 6, 10, 5, 9, 4, 8, 8, 8, 12, 9, 13, 10, 14, 11, 15 */ for (int y = pointsY - 1; y >= 0; y--) { for (int x = 0; x <= pointsX - 1; x++) { obj.Position(x, y, 0.0f); obj.TextureCoord((float)x / (float)(pointsX), (float)y / (float)(pointsY)); } } //Console.Write("\n Index:"); // We have pointsX -1 lines for (ushort y = 0; y < pointsY - 1; y++) { if (y % 2 == 0) { for (int x = 0; x < pointsX; x++) { obj.Index((ushort)(y * pointsX + x)); //(x, y + 1, 0.0f); //Console.Write("," + (y * pointsX + x)); obj.Index((ushort)(y * pointsX + x + pointsX)); //(x, y, 0.0f); //Console.Write("," + (y * pointsX + x + pointsX)); } if (y != pointsY - 2) { obj.Index((ushort)(y * pointsX + pointsX - 1)); //(0, y+1, 0.0f); //Console.Write("," + (y * pointsX + 2 * pointsX - 1)); } } else { for (int x = pointsX - 1; x >= 0; x--) { obj.Index((ushort)(y * pointsX + x)); //(x, y + 1, 0.0f); //Console.Write(", " + (y * pointsX + x)); obj.Index((ushort)(y * pointsX + x + pointsX)); //(x, y, 0.0f); //Console.Write(", " + (y * pointsX + x + pointsX)); } if (y != pointsY - 2) { obj.Index((ushort)(y * pointsX + pointsX)); //(0, y+1, 0.0f); //Console.Write(", " + (y * pointsX + pointsX)); } } } //Console.WriteLine(";"); ManualObject.ManualObjectSection manualObjSec1 = obj.End(); obj.BoundingBox = new AxisAlignedBox(translationScale.x, translationScale.y, -1, (pointsX * translationScale.z + translationScale.x), (pointsY * translationScale.w + translationScale.y), 1); manualObjSec1.SetCustomParameter(TransXYscaleXY, translationScale); manualObjSec1.SetCustomParameter(ColorAndHeightScale, color); return(manualObjSec1); }