public static void DrawBox2(BoundingBoxD box, MatrixD wm, Color color, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Wireframe, float thickness = 0.01f) { wm.Translation = box.Center; var lbox = box.TransformSlow(Matrix.Identity); MySimpleObjectDraw.DrawTransparentBox(ref wm, ref lbox, ref color, raster, 1, thickness, MyStringId.GetOrCompute("Square"), MyStringId.GetOrCompute("Square")); }
public static void Draw(this MyOrientedBoundingBoxD obb, Color color, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Solid, float thickness = 0.5f, MyStringId?material = null) { var box = new BoundingBoxD(-obb.HalfExtent, obb.HalfExtent); var wm = MatrixD.CreateFromTransformScale(obb.Orientation, obb.Center, Vector3D.One); MySimpleObjectDraw.DrawTransparentBox(ref wm, ref box, ref color, raster, 1, thickness, material ?? Square, material ?? Square); }
public static void Draw(this BoundingBoxD aabb, Color color, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Solid, float thickness = 0.5f, MyStringId?material = null) { var box = new BoundingBoxD(-aabb.HalfExtents, aabb.HalfExtents); var wm = MatrixD.CreateWorld(aabb.Center); MySimpleObjectDraw.DrawTransparentBox(ref wm, ref box, ref color, raster, 1, thickness, material ?? Square, material ?? Square); }
public static void DrawSphere(MatrixD worldMatrix, double radius, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Wireframe) { var color = Color.White; var material = MyStringId.GetOrCompute("Square"); MySimpleObjectDraw.DrawTransparentSphere(ref worldMatrix, (float)radius, ref color, raster, 20, material, material, 0.5f); }
public static void DrawOBB(MyOrientedBoundingBoxD obb, Color color, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Wireframe, float thickness = 0.01f) { var box = new BoundingBoxD(-obb.HalfExtent, obb.HalfExtent); var wm = MatrixD.CreateFromQuaternion(obb.Orientation); wm.Translation = obb.Center; MySimpleObjectDraw.DrawTransparentBox(ref wm, ref box, ref color, MySimpleObjectRasterizer.Solid, 1); }
public static void DrawObb(MyOrientedBoundingBoxD obb, Color color, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Wireframe, float thickness = 0.01f) { BoundingBoxD box = new BoundingBoxD(-obb.HalfExtent, obb.HalfExtent); MatrixD wm = MatrixD.CreateFromQuaternion(obb.Orientation); wm.Translation = obb.Center; MySimpleObjectDraw.DrawTransparentBox(ref wm, ref box, ref color, raster, 1, thickness, MyStringId.GetOrCompute("Square"), MyStringId.GetOrCompute("Square")); }
/// <summary> /// DrawTransparentSphere /// </summary> /// <param name="vctPos"></param> /// <param name="radius"></param> /// <param name="color"></param> /// <param name="bWireFramed"></param> /// <param name="wireDivideRatio"></param> public static void DrawTransparentSphere(ref MatrixD worldMatrix, float radius, ref Color color, MySimpleObjectRasterizer rasterization, int wireDivideRatio, string faceMaterial = null, string lineMaterial = null, float lineThickness = -1, int customViewProjectionMatrix = -1) { if (lineMaterial == null) { lineMaterial = "GizmoDrawLine"; } m_verticesBuffer.Clear(); MyMeshHelper.GenerateSphere(ref worldMatrix, radius, wireDivideRatio, m_verticesBuffer); Vector3D vctZero = Vector3D.Zero; float thickness = radius * 0.01f; if (lineThickness > -1.0f) { thickness = lineThickness; } int i = 0; for (i = 0; i < m_verticesBuffer.Count; i += 4) { MyQuadD quad; quad.Point0 = m_verticesBuffer[i + 1]; quad.Point1 = m_verticesBuffer[i + 3]; quad.Point2 = m_verticesBuffer[i + 2]; quad.Point3 = m_verticesBuffer[i]; if (rasterization == MySimpleObjectRasterizer.Solid || rasterization == MySimpleObjectRasterizer.SolidAndWireframe) { MyTransparentGeometry.AddQuad(faceMaterial ?? "ContainerBorder", ref quad, ref color, ref vctZero, 0, customViewProjectionMatrix); } if (rasterization == MySimpleObjectRasterizer.Wireframe || rasterization == MySimpleObjectRasterizer.SolidAndWireframe) { //@ 20 - lifespan for 1 update in 60FPPS Vector3D start = quad.Point0; Vector3D dir = quad.Point1 - start; float len = (float)dir.Length(); if (len > 0.1f) { dir = MyUtils.Normalize(dir); MyTransparentGeometry.AddLineBillboard(lineMaterial, color, start, dir, len, thickness, 0, false, customViewProjectionMatrix); } start = quad.Point1; dir = quad.Point2 - start; len = (float)dir.Length(); if (len > 0.1f) { dir = MyUtils.Normalize(dir); MyTransparentGeometry.AddLineBillboard(lineMaterial, color, start, dir, len, thickness, 0, false, customViewProjectionMatrix); } } } }
/// <summary> /// DrawTransparentBox /// </summary> public static void DrawTransparentBox(ref MatrixD worldMatrix, ref BoundingBoxD localbox, ref Color color, MySimpleObjectRasterizer rasterization, Vector3I wireDivideRatio, float lineWidth = 1, string faceMaterial = null, string lineMaterial = null, bool onlyFrontFaces = false, int customViewProjection = -1, int priority = 0) { if (faceMaterial == null) { faceMaterial = "ContainerBorder"; } if (rasterization == MySimpleObjectRasterizer.Solid || rasterization == MySimpleObjectRasterizer.SolidAndWireframe) { Vector3 vctMin = localbox.Min; Vector3 vctMax = localbox.Max; //@ CreateQuads MyQuadD quad; MatrixD orientation = MatrixD.Identity; orientation.Forward = worldMatrix.Forward; orientation.Up = worldMatrix.Up; orientation.Right = worldMatrix.Right; Vector3D translation = worldMatrix.Translation + Vector3D.Transform(localbox.Center, orientation);// +(vctMin + vctMax) / 2; float halfWidth = (float)(localbox.Max.X - localbox.Min.X) / 2f; float halfHeight = (float)(localbox.Max.Y - localbox.Min.Y) / 2f; float halfDeep = (float)(localbox.Max.Z - localbox.Min.Z) / 2f; //@ Front side Vector3D faceNorm = Vector3D.TransformNormal(Vector3.Forward, orientation); faceNorm *= halfDeep; Vector3D vctPos = translation + faceNorm; if (!onlyFrontFaces || FaceVisible(vctPos, faceNorm)) { MyUtils.GenerateQuad(out quad, ref vctPos, halfWidth, halfHeight, ref worldMatrix); MyTransparentGeometry.AddQuad(faceMaterial, ref quad, ref color, ref vctPos, priority, customViewProjection); } //@ Back side vctPos = translation - faceNorm; if (!onlyFrontFaces || FaceVisible(vctPos, -faceNorm)) { MyUtils.GenerateQuad(out quad, ref vctPos, halfWidth, halfHeight, ref worldMatrix); MyTransparentGeometry.AddQuad(faceMaterial, ref quad, ref color, ref vctPos, priority, customViewProjection); } //@ Left side MatrixD rotMat = MatrixD.CreateRotationY(MathHelper.ToRadians(90f)); MatrixD rotated = rotMat * worldMatrix; faceNorm = Vector3.TransformNormal(Vector3.Left, worldMatrix); faceNorm *= halfWidth; vctPos = translation + faceNorm; if (!onlyFrontFaces || FaceVisible(vctPos, faceNorm)) { MyUtils.GenerateQuad(out quad, ref vctPos, halfDeep, halfHeight, ref rotated); MyTransparentGeometry.AddQuad(faceMaterial, ref quad, ref color, ref vctPos, priority, customViewProjection); } //@ Right side vctPos = translation - faceNorm; if (!onlyFrontFaces || FaceVisible(vctPos, -faceNorm)) { MyUtils.GenerateQuad(out quad, ref vctPos, halfDeep, halfHeight, ref rotated); MyTransparentGeometry.AddQuad(faceMaterial, ref quad, ref color, ref vctPos, priority, customViewProjection); } //@ Top side rotMat = Matrix.CreateRotationX(MathHelper.ToRadians(90f)); rotated = rotMat * worldMatrix; faceNorm = Vector3.TransformNormal(Vector3.Up, worldMatrix); faceNorm *= ((localbox.Max.Y - localbox.Min.Y) / 2f); vctPos = translation + faceNorm; if (!onlyFrontFaces || FaceVisible(vctPos, faceNorm)) { MyUtils.GenerateQuad(out quad, ref vctPos, halfWidth, halfDeep, ref rotated); MyTransparentGeometry.AddQuad(faceMaterial, ref quad, ref color, ref vctPos, priority, customViewProjection); } //@ Bottom side vctPos = translation - faceNorm; if (!onlyFrontFaces || FaceVisible(vctPos, -faceNorm)) { MyUtils.GenerateQuad(out quad, ref vctPos, halfWidth, halfDeep, ref rotated); MyTransparentGeometry.AddQuad(faceMaterial, ref quad, ref color, ref vctPos, priority, customViewProjection); } } if (rasterization == MySimpleObjectRasterizer.Wireframe || rasterization == MySimpleObjectRasterizer.SolidAndWireframe) { Color wireColor = color; wireColor *= 1.3f; DrawWireFramedBox(ref worldMatrix, ref localbox, ref wireColor, lineWidth, wireDivideRatio, lineMaterial, onlyFrontFaces, customViewProjection, priority); } }
public static void DrawAttachedTransparentBox(ref MatrixD worldMatrix, ref BoundingBoxD localbox, ref Color color, int renderObjectID, ref MatrixD worldToLocal, MySimpleObjectRasterizer rasterization, int wireDivideRatio, float lineWidth = 1, string faceMaterial = null, string lineMaterial = null, bool onlyFrontFaces = false, int priority = 0) { DrawAttachedTransparentBox(ref worldMatrix, ref localbox, ref color, renderObjectID, ref worldToLocal, rasterization, new Vector3I(wireDivideRatio), lineWidth, faceMaterial, lineMaterial, onlyFrontFaces, priority); }
public static void DrawBox3(MatrixD matrix, BoundingBoxD box, Color color, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Wireframe, float thickness = 0.01f) { MySimpleObjectDraw.DrawTransparentBox(ref matrix, ref box, ref color, raster, 1, thickness, MyStringId.GetOrCompute("Square"), MyStringId.GetOrCompute("Square")); }
public static void DrawTransparentBox(ref MatrixD worldMatrix, ref BoundingBoxD localbox, ref Color color, ref Color frontFaceColor, MySimpleObjectRasterizer rasterization, int wireDivideRatio, float lineWidth = 1, string faceMaterial = null, string lineMaterial = null, bool onlyFrontFaces = false, int customViewProjection = -1, int priority = 0) { DrawTransparentBox(ref worldMatrix, ref localbox, ref color, ref frontFaceColor, rasterization, new Vector3I(wireDivideRatio), lineWidth, faceMaterial, lineMaterial, onlyFrontFaces, customViewProjection, priority); }
public static Vector3D DrawAsSphere(this Vector3D vector, float radius, Color color, MySimpleObjectRasterizer rasterizer = MySimpleObjectRasterizer.Solid, int wire = 20, MyStringId?material = null) { var matrix = MatrixD.CreateWorld(vector); MySimpleObjectDraw.DrawTransparentSphere(ref matrix, (float)radius, ref color, rasterizer, wire, material ?? Square, material ?? Square); return(vector); }
public static MatrixD DrawAsSphere(this MatrixD matrix, float radius, Color color, MySimpleObjectRasterizer rasterizer = MySimpleObjectRasterizer.Solid, int wire = 20, MyStringId?material = null) { MySimpleObjectDraw.DrawTransparentSphere(ref matrix, (float)radius, ref color, rasterizer, wire, material ?? Square, material ?? Square); return(matrix); }
public static void Draw(this BoundingSphereD sphere, Color color, MySimpleObjectRasterizer rasterizer = MySimpleObjectRasterizer.Solid, int wire = 20, MyStringId?material = null) { var matrix = MatrixD.CreateWorld(sphere.Center); MySimpleObjectDraw.DrawTransparentSphere(ref matrix, (float)sphere.Radius, ref color, rasterizer, wire, material ?? Square, material ?? Square); }
public static void DrawBB(MatrixD wm, BoundingBoxD bb, Color color, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Wireframe, float thickness = 0.01f) { var material = MyStringId.GetOrCompute("Square"); MySimpleObjectDraw.DrawTransparentBox(ref wm, ref bb, ref color, raster, 1, thickness, material, material); }