public AxisRenderer() { Mesh myMesh = new Mesh(); float smallthingsize = 0.05f; // X Axis MeshUtils.CreateLine(ref myMesh, Vector3.Zero, Vector3.UnitX, Vector3.UnitX); MeshUtils.CreateLine(ref myMesh, Vector3.Zero, Vector3.UnitY, Vector3.UnitY); MeshUtils.CreateLine(ref myMesh, Vector3.Zero, Vector3.UnitZ, Vector3.UnitZ); MeshUtils.CreateArrowCap(ref myMesh, Vector3.UnitX, Vector3.UnitY, Vector3.UnitX, 0.025f, 0.1f, Vector3.UnitX); MeshUtils.CreateArrowCap(ref myMesh, Vector3.UnitZ, Vector3.UnitY, Vector3.UnitZ, 0.025f, 0.1f, Vector3.UnitZ); MeshUtils.CreateArrowCap(ref myMesh, Vector3.UnitY, Vector3.UnitX, Vector3.UnitY, 0.025f, 0.1f, Vector3.UnitY); MeshUtils.CreateLine(ref myMesh, Vector3.UnitX * smallthingsize, Vector3.UnitY * smallthingsize, Vector3.One); MeshUtils.CreateLine(ref myMesh, Vector3.UnitX * smallthingsize, Vector3.UnitZ * smallthingsize, Vector3.One); MeshUtils.CreateLine(ref myMesh, Vector3.UnitY * smallthingsize, Vector3.UnitZ * smallthingsize, Vector3.One); MeshUtils.CreateLine(ref myMesh, Vector3.Zero, Vector3.UnitX * smallthingsize, Vector3.One); MeshUtils.CreateLine(ref myMesh, Vector3.Zero, Vector3.UnitZ * smallthingsize, Vector3.One); MeshUtils.CreateLine(ref myMesh, Vector3.Zero, Vector3.UnitY * smallthingsize, Vector3.One); Mesh = myMesh; Mesh.GenerateVAO(); }
public void GenerateBox(Bounds box) { if (Mesh != null) { Mesh.Clear(); } Mesh myMesh = new Mesh(); /* * MeshUtils.CreateLine(ref myMesh, box.Min, box.Min + Vector3.UnitX, Vector3.UnitX); * MeshUtils.CreateLine(ref myMesh, box.Min, box.Min + Vector3.UnitY, Vector3.UnitX); * MeshUtils.CreateLine(ref myMesh, box.Min, box.Min + Vector3.UnitZ, Vector3.UnitX); * * MeshUtils.CreateLine(ref myMesh, box.Max, box.Max - Vector3.UnitX, Vector3.UnitY); * MeshUtils.CreateLine(ref myMesh, box.Max, box.Max - Vector3.UnitY, Vector3.UnitY); * MeshUtils.CreateLine(ref myMesh, box.Max, box.Max - Vector3.UnitZ, Vector3.UnitY); */ Vector3 frontTL = new Vector3(box.Min.X, box.Min.Y, box.Max.Z); Vector3 frontBL = new Vector3(box.Min.X, box.Max.Y, box.Max.Z); Vector3 frontTR = new Vector3(box.Max.X, box.Min.Y, box.Max.Z); Vector3 frontBR = new Vector3(box.Max.X, box.Max.Y, box.Max.Z); Vector3 backTL = new Vector3(box.Min.X, box.Min.Y, box.Min.Z); Vector3 backBL = new Vector3(box.Min.X, box.Max.Y, box.Min.Z); Vector3 backTR = new Vector3(box.Max.X, box.Min.Y, box.Min.Z); Vector3 backBR = new Vector3(box.Max.X, box.Max.Y, box.Min.Z); // Front rect MeshUtils.CreateLine(ref myMesh, frontTL, frontTR, Vector3.One); MeshUtils.CreateLine(ref myMesh, frontTR, frontBR, Vector3.One); MeshUtils.CreateLine(ref myMesh, frontBR, frontBL, Vector3.One); MeshUtils.CreateLine(ref myMesh, frontBL, frontTL, Vector3.One); MeshUtils.CreateLine(ref myMesh, frontTL, backTL, Vector3.One); MeshUtils.CreateLine(ref myMesh, frontTR, backTR, Vector3.One); MeshUtils.CreateLine(ref myMesh, frontBR, backBR, Vector3.One); MeshUtils.CreateLine(ref myMesh, frontBL, backBL, Vector3.One); MeshUtils.CreateLine(ref myMesh, backTL, backTR, Vector3.One); MeshUtils.CreateLine(ref myMesh, backTR, backBR, Vector3.One); MeshUtils.CreateLine(ref myMesh, backBR, backBL, Vector3.One); MeshUtils.CreateLine(ref myMesh, backBL, backTL, Vector3.One); Mesh = myMesh; Mesh.GenerateVAO(); }
public void GenerateBox(Vector3 position, Vector3 size, Vector3 color) { if (Mesh != null) { Mesh.Clear(); } Mesh myMesh = new Mesh(); Vector3 frontTL = new Vector3(position.X - size.X / 2.0f, position.Y - size.Y / 2.0f, position.Z - size.Z / 2.0f); Vector3 frontBL = new Vector3(position.X - size.X / 2.0f, position.Y + size.Y / 2.0f, position.Z - size.Z / 2.0f); Vector3 frontTR = new Vector3(position.X + size.X / 2.0f, position.Y - size.Y / 2.0f, position.Z - size.Z / 2.0f); Vector3 frontBR = new Vector3(position.X + size.X / 2.0f, position.Y + size.Y / 2.0f, position.Z - size.Z / 2.0f); Vector3 backTL = new Vector3(position.X - size.X / 2.0f, position.Y - size.Y / 2.0f, -position.Z + size.Z / 2.0f); Vector3 backBL = new Vector3(position.X - size.X / 2.0f, position.Y + size.Y / 2.0f, -position.Z + size.Z / 2.0f); Vector3 backTR = new Vector3(position.X + size.X / 2.0f, position.Y - size.Y / 2.0f, -position.Z + size.Z / 2.0f); Vector3 backBR = new Vector3(position.X + size.X / 2.0f, position.Y + size.Y / 2.0f, -position.Z + size.Z / 2.0f); // Front rect Vector3 normal = new Vector3(0, 0, 1); MeshUtils.CreateLine(ref myMesh, frontTL, frontTR, color); MeshUtils.CreateLine(ref myMesh, frontTR, frontBR, color); MeshUtils.CreateLine(ref myMesh, frontBR, frontBL, color); MeshUtils.CreateLine(ref myMesh, frontBL, frontTL, color); MeshUtils.CreateLine(ref myMesh, frontTL, backTL, color); MeshUtils.CreateLine(ref myMesh, frontTR, backTR, color); MeshUtils.CreateLine(ref myMesh, frontBR, backBR, color); MeshUtils.CreateLine(ref myMesh, frontBL, backBL, color); MeshUtils.CreateLine(ref myMesh, backTL, backTR, color); MeshUtils.CreateLine(ref myMesh, backTR, backBR, color); MeshUtils.CreateLine(ref myMesh, backBR, backBL, color); MeshUtils.CreateLine(ref myMesh, backBL, backTL, color); Mesh = myMesh; Mesh.GenerateVAO(); }