public static void Arrow(Vector3 start, Vector3 end, float arrowSize, Color color) { if (mSingleton == null || !mSingleton.IsEnabled) { return; } Primitive p = new Primitive(color); p.AddVertex(start); p.AddVertex(end); Vector3 dir = Vector3.Normalize(end - start); Vector3 right; float dot = Vector3.Dot(dir, Vector3.UnitY); if (dot > .99f || dot < -.99f) { right = Vector3.Cross(dir, Vector3.UnitX); } else { right = Vector3.Cross(dir, Vector3.UnitY); } Vector3 top = Vector3.Cross(right, dir); dir *= arrowSize; right *= arrowSize; top *= arrowSize; // Right slant. p.AddVertex(end); p.AddVertex(end + right - dir); // Left slant. p.AddVertex(end); p.AddVertex(end - right - dir); // Top slant. p.AddVertex(end); p.AddVertex(end + top - dir); // Bottom slant. p.AddVertex(end); p.AddVertex(end - top - dir); mSingleton.mLinePrimitives.Add(p); }
public static void Arrow(Vector3 start, Vector3 end, float arrowSize, Color color) { if (mSingleton == null || !mSingleton.IsEnabled) { return; } Primitive p = new Primitive(color); p.AddVertex(start); p.AddVertex(end); Vector3 dir = Vector3.Normalize(end - start); Vector3 right; float dot = Vector3.Dot(dir, Vector3.UnitY); if (dot > .99f || dot < -.99f) right = Vector3.Cross(dir, Vector3.UnitX); else right = Vector3.Cross(dir, Vector3.UnitY); Vector3 top = Vector3.Cross(right, dir); dir *= arrowSize; right *= arrowSize; top *= arrowSize; // added by pentium @13/5/25 float slantSize = 50; dir *= slantSize; right *= slantSize; top *= slantSize; // Right slant. p.AddVertex(end); p.AddVertex(end + right - dir); // Left slant. p.AddVertex(end); p.AddVertex(end - right - dir); // Top slant. p.AddVertex(end); p.AddVertex(end + top - dir); // Bottom slant. p.AddVertex(end); p.AddVertex(end - top - dir); mSingleton.mLinePrimitives.Add(p); }
public static void Line(Vector3 start, Vector3 end, Color color) { if (mSingleton == null || !mSingleton.IsEnabled) { return; } Primitive p = new Primitive(color); p.AddVertex(start); p.AddVertex(end); mSingleton.mLinePrimitives.Add(p); }
public static void BoundingBox(BoundingBox boundingBox, Color color) { if (mSingleton == null || !mSingleton.IsEnabled) { return; } Vector3 halfExtents = (boundingBox.Max - boundingBox.Min) * 0.5f; Vector3 center = (boundingBox.Max + boundingBox.Min) * 0.5f; Vector3 edgecoord = Vector3.One, pa, pb; Primitive primitive = new Primitive(color); for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { pa = new Vector3(edgecoord.X * halfExtents.X, edgecoord.Y * halfExtents.Y, edgecoord.Z * halfExtents.Z); pa += center; int othercoord = j % 3; SetElement(ref edgecoord, othercoord, GetElement(edgecoord, othercoord) * -1f); pb = new Vector3(edgecoord.X * halfExtents.X, edgecoord.Y * halfExtents.Y, edgecoord.Z * halfExtents.Z); pb += center; primitive.AddVertex(pa); primitive.AddVertex(pb); } edgecoord = new Vector3(-1f, -1f, -1f); if (i < 3) { SetElement(ref edgecoord, i, GetElement(edgecoord, i) * -1f); } } mSingleton.mLinePrimitives.Add(primitive); }
public static void Sphere(Vector3 pos, float radius, Color color) { if (mSingleton == null || !mSingleton.IsEnabled) { return; } Primitive p = new Primitive(color); // Decrease these angles to increase the complexity of the sphere. int dtheta = 35, dphi = 35; int theta, phi; const double DegToRads = System.Math.PI / 180; for (theta = -90; theta <= 90 - dtheta; theta += dtheta) { for (phi = 0; phi <= 360 - dphi; phi += dphi) { p.AddVertex((pos + radius * new Vector3((float)(Math.Cos(theta * DegToRads) * Math.Cos(phi * DegToRads)), (float)(Math.Cos(theta * DegToRads) * Math.Sin(phi * DegToRads)), (float)(Math.Sin(theta * DegToRads))))); p.AddVertex((pos + radius * new Vector3((float)(Math.Cos((theta + dtheta) * DegToRads) * Math.Cos(phi * DegToRads)), (float)(Math.Cos((theta + dtheta) * DegToRads) * Math.Sin(phi * DegToRads)), (float)(Math.Sin((theta + dtheta) * DegToRads))))); p.AddVertex((pos + radius * new Vector3((float)(Math.Cos((theta + dtheta) * DegToRads) * Math.Cos((phi + dphi) * DegToRads)), (float)(Math.Cos((theta + dtheta) * DegToRads) * Math.Sin((phi + dphi) * DegToRads)), (float)(Math.Sin((theta + dtheta) * DegToRads))))); if (theta > -90 && theta < 90) { p.AddVertex((pos + radius * new Vector3((float)(Math.Cos(theta * DegToRads) * Math.Cos((phi + dphi) * DegToRads)), (float)(Math.Cos(theta * DegToRads) * Math.Sin((phi + dphi) * DegToRads)), (float)(Math.Sin(theta * DegToRads))))); } } } mSingleton.mLinePrimitives.Add(p); }
public static void Point(Vector3 pos, Color color) { if (mSingleton == null || !mSingleton.IsEnabled) { return; } foreach (Primitive p in mSingleton.mPointPrimitives) { // Re-use existing primitive w/ same color for batch rendering. if (p.mColor == color) { p.AddVertex(pos); return; } } Primitive primitive = new Primitive(color); primitive.AddVertex(pos); mSingleton.mPointPrimitives.Add(primitive); }
public static void BoundingBox(BoundingBox boundingBox, Color color) { if (mSingleton == null || !mSingleton.IsEnabled) { return; } Vector3 halfExtents = (boundingBox.Max - boundingBox.Min) * 0.5f; Vector3 center = (boundingBox.Max + boundingBox.Min) * 0.5f; Vector3 edgecoord = Vector3.One, pa, pb; Primitive primitive = new Primitive(color); for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { pa = new Vector3(edgecoord.X * halfExtents.X, edgecoord.Y * halfExtents.Y, edgecoord.Z * halfExtents.Z); pa += center; int othercoord = j % 3; SetElement(ref edgecoord, othercoord, GetElement(edgecoord, othercoord) * -1f); pb = new Vector3(edgecoord.X * halfExtents.X, edgecoord.Y * halfExtents.Y, edgecoord.Z * halfExtents.Z); pb += center; primitive.AddVertex(pa); primitive.AddVertex(pb); } edgecoord = new Vector3(-1f, -1f, -1f); if (i < 3) SetElement(ref edgecoord, i, GetElement(edgecoord, i) * -1f); } mSingleton.mLinePrimitives.Add(primitive); }