private static void DrawTransparentCone(Vector3D apexPosition, Vector3 directionVector, Vector3 baseVector, Color color, int wireDivideRatio, MyStringId material, int customViewProjectionMatrix = -1, BlendType blendType = BlendType.Standard) { Vector3 axis = directionVector; axis.Normalize(); float num = (float)(MathHelperD.TwoPi / (double)wireDivideRatio); for (int i = 0; i < wireDivideRatio; i++) { float angle = (float)i * num; float angle2 = (float)(i + 1) * num; Vector3D point = apexPosition + directionVector + Vector3.Transform(baseVector, Matrix.CreateFromAxisAngle(axis, angle)); Vector3D point2 = apexPosition + directionVector + Vector3.Transform(baseVector, Matrix.CreateFromAxisAngle(axis, angle2)); MyQuadD myQuadD; myQuadD.Point0 = point; myQuadD.Point1 = point2; myQuadD.Point2 = apexPosition; myQuadD.Point3 = apexPosition; MyTransparentGeometry.AddQuad(material, ref myQuadD, color, ref Vector3D.Zero, -1, blendType, null); } }
public static void DrawHighlightBox(MatrixD matrix, float scale, float lineWidth, MyStringId material, Color colorFace, Color colorWire, BlendTypeEnum blendType) { // optimized box draw compared to MySimpleObjectDraw.DrawTransparentBox; also allows consistent edge thickness MyQuadD quad; Vector3D p; MatrixD m; var halfScale = (scale * 0.5f); float lineLength = scale; const float ROTATE_90_RAD = (90f / 180f * MathHelper.Pi); // 90deg in radians p = matrix.Translation + matrix.Forward * halfScale; if (IsFaceVisible(p, matrix.Forward)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref matrix); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } p = matrix.Translation + matrix.Backward * halfScale; if (IsFaceVisible(p, matrix.Backward)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref matrix); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } p = matrix.Translation + matrix.Left * halfScale; m = matrix * MatrixD.CreateFromAxisAngle(matrix.Up, ROTATE_90_RAD); if (IsFaceVisible(p, matrix.Left)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } p = matrix.Translation + matrix.Right * halfScale; if (IsFaceVisible(p, matrix.Right)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } m = matrix * MatrixD.CreateFromAxisAngle(matrix.Left, ROTATE_90_RAD); p = matrix.Translation + matrix.Up * halfScale; if (IsFaceVisible(p, matrix.Up)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } p = matrix.Translation + matrix.Down * halfScale; if (IsFaceVisible(p, matrix.Down)) { MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m); MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType); } var upHalf = (matrix.Up * halfScale); var rightHalf = (matrix.Right * halfScale); var forwardHalf = (matrix.Forward * halfScale); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + upHalf + -rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + upHalf + rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -upHalf + -rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -upHalf + rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + -rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + -rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + -upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + -upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType); MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType); }
public static void DrawTransparentCylinder(ref MatrixD worldMatrix, float radius1, float radius2, float length, Vector4 lineColor, Vector4 faceColor, int wireDivideRatio, float thickness, MyStringId?lineMaterial = null, MyStringId?faceMaterial = null) { Vector3D centerTop = Vector3D.Transform(new Vector3D(0, length / 2f, 0), ref worldMatrix); Vector3D centerBottom = Vector3D.Transform(new Vector3D(0, -length / 2f, 0), ref worldMatrix); Vector3D upDir = Vector3D.TransformNormal(new Vector3D(0, 1, 0), ref worldMatrix); upDir.Normalize(); Vector3D currTop = Vector3D.Zero; Vector3D currBottom = Vector3D.Zero; Vector3D prevTop = Vector3D.Zero; Vector3D prevBottom = Vector3D.Zero; float num = 360f / wireDivideRatio; for (int i = 0; i <= wireDivideRatio; i++) { float degrees = i * num; currTop.X = (float)(radius1 * Math.Cos(MathHelper.ToRadians(degrees))); currTop.Y = length / 2f; currTop.Z = (float)(radius1 * Math.Sin(MathHelper.ToRadians(degrees))); currBottom.X = (float)(radius2 * Math.Cos(MathHelper.ToRadians(degrees))); currBottom.Y = -length / 2f; currBottom.Z = (float)(radius2 * Math.Sin(MathHelper.ToRadians(degrees))); currTop = Vector3D.Transform(currTop, worldMatrix); currBottom = Vector3D.Transform(currBottom, worldMatrix); if (lineMaterial.HasValue) { MySimpleObjectDraw.DrawLine(currBottom, currTop, lineMaterial, ref lineColor, thickness); } if (i > 0) { if (lineMaterial.HasValue) { MySimpleObjectDraw.DrawLine(prevBottom, currBottom, lineMaterial, ref lineColor, thickness); MySimpleObjectDraw.DrawLine(prevTop, currTop, lineMaterial, ref lineColor, thickness); } if (faceMaterial.HasValue) { var quad = new MyQuadD() { Point0 = prevTop, Point1 = currTop, Point2 = currBottom, Point3 = prevBottom }; MyTransparentGeometry.AddQuad(faceMaterial.Value, ref quad, faceColor, ref currTop); MyTransparentGeometry.AddTriangleBillboard(centerTop, currTop, prevTop, upDir, upDir, upDir, Vector2.Zero, Vector2.Zero, Vector2.Zero, faceMaterial.Value, 0, currTop, faceColor); MyTransparentGeometry.AddTriangleBillboard(centerBottom, currBottom, prevBottom, -upDir, -upDir, -upDir, Vector2.Zero, Vector2.Zero, Vector2.Zero, faceMaterial.Value, 0, currBottom, faceColor); } } prevBottom = currBottom; prevTop = currTop; } }
void DrawInfluenceCone(Vector3D conePos) { Vector4 color = Color.Cyan.ToVector4() * 10; Vector4 planeColor = (Color.White * 0.1f).ToVector4(); const float LINE_THICK = 0.02f; const int WIRE_DIV_RATIO = 16; var coneMatrix = block.WorldMatrix; coneMatrix.Translation = conePos; //MyTransparentGeometry.AddPointBillboard(Mod.MATERIAL_DOT, Color.Lime, collectPos, 0.05f, 0); float rangeOffset = Range + (offset * 2); // because range check starts from collectPos but cone starts from conePos float baseRadius = rangeOffset * (float)Math.Tan(coneAngle); //MySimpleObjectDraw.DrawTransparentCone(ref coneMatrix, baseRadius, rangeWithOffset, ref color, 16, Mod.MATERIAL_SQUARE); var apexPosition = coneMatrix.Translation; var directionVector = coneMatrix.Forward * rangeOffset; var maxPosCenter = conePos + coneMatrix.Forward * rangeOffset; var baseVector = coneMatrix.Up * baseRadius; Vector3 axis = directionVector; axis.Normalize(); float stepAngle = (float)(Math.PI * 2.0 / (double)WIRE_DIV_RATIO); var prevConePoint = apexPosition + directionVector + Vector3.Transform(baseVector, Matrix.CreateFromAxisAngle(axis, (-1 * stepAngle))); prevConePoint = (apexPosition + Vector3D.Normalize((prevConePoint - apexPosition)) * rangeOffset); var quad = default(MyQuadD); for (int step = 0; step < WIRE_DIV_RATIO; step++) { var conePoint = apexPosition + directionVector + Vector3.Transform(baseVector, Matrix.CreateFromAxisAngle(axis, (step * stepAngle))); var lineDir = (conePoint - apexPosition); lineDir.Normalize(); conePoint = (apexPosition + lineDir * rangeOffset); MyTransparentGeometry.AddLineBillboard(Mod.MATERIAL_SQUARE, color, conePoint, (prevConePoint - conePoint), 1f, LINE_THICK); MyTransparentGeometry.AddLineBillboard(Mod.MATERIAL_SQUARE, color, apexPosition, lineDir, rangeOffset, LINE_THICK); MyTransparentGeometry.AddLineBillboard(Mod.MATERIAL_SQUARE, color, conePoint, (maxPosCenter - conePoint), 1f, LINE_THICK); // Unusable because SQUARE has reflectivity and this method uses materials' reflectivity... making it unable to be made transparent, also reflective xD //var normal = Vector3.Up; //MyTransparentGeometry.AddTriangleBillboard( // apexPosition, prevConePoint, conePoint, // normal, normal, normal, // new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), // Mod.MATERIAL_SQUARE, uint.MaxValue, conePoint, planeColor); // also NOTE: if triangle is used, color needs .ToLinearRGB(). quad.Point0 = prevConePoint; quad.Point1 = conePoint; quad.Point2 = apexPosition; quad.Point3 = apexPosition; MyTransparentGeometry.AddQuad(Mod.MATERIAL_SQUARE, ref quad, planeColor, ref Vector3D.Zero); quad.Point0 = prevConePoint; quad.Point1 = conePoint; quad.Point2 = maxPosCenter; quad.Point3 = maxPosCenter; MyTransparentGeometry.AddQuad(Mod.MATERIAL_SQUARE, ref quad, planeColor, ref Vector3D.Zero); prevConePoint = conePoint; } }
/// <summary> /// DrawTransparentSphere /// </summary> /// <param name="vctPos"></param> /// <param name="radius"></param> /// <param name="vctColor"></param> /// <param name="bWireFramed"></param> /// <param name="wireDivideRatio"></param> public static void DrawTransparentSphere(ref Matrix worldMatrix, float radius, ref Vector4 vctColor, bool bWireFramed, int wireDivideRatio, MyTransparentMaterialEnum?faceMaterial = null, MyTransparentMaterialEnum?lineMaterial = null) { if (!lineMaterial.HasValue) { lineMaterial = MyTransparentMaterialEnum.ProjectileTrailLine; } m_verticesBuffer.Clear(); MyMeshHelper.GenerateSphere(ref worldMatrix, radius, wireDivideRatio, m_verticesBuffer); Vector3 vctZero = Vector3.Zero; float thickness = radius * 0.01f; int i = 0; for (i = 0; i < m_verticesBuffer.Count; i += 4) { MyQuad quad; quad.Point0 = m_verticesBuffer[i + 1]; quad.Point1 = m_verticesBuffer[i + 3]; quad.Point2 = m_verticesBuffer[i + 2]; quad.Point3 = m_verticesBuffer[i]; MyTransparentGeometry.AddQuad(faceMaterial ?? MyTransparentMaterialEnum.ContainerBorder, ref quad, ref vctColor, ref vctZero); if (bWireFramed) { //@ 20 - lifespan for 1 update in 60FPPS Vector3 start = quad.Point0; Vector3 dir = quad.Point1 - start; float len = dir.Length(); if (len > 0.1f) { dir = MyMwcUtils.Normalize(dir); MyTransparentGeometry.AddLineBillboard(lineMaterial.Value, vctColor, start, dir, len, thickness); } start = quad.Point1; dir = quad.Point2 - start; len = dir.Length(); if (len > 0.1f) { dir = MyMwcUtils.Normalize(dir); MyTransparentGeometry.AddLineBillboard(lineMaterial.Value, vctColor, start, dir, len, thickness); } /*start = quad.Point2; * dir = quad.Point3 - start; * len = dir.Length(); * if (len > 0.1f) * { * dir = MyMwcUtils.Normalize(dir); * newParticle3.StartLineParticle(lineMaterial.Value, false, 20, start, Vector3.Zero, vctColor, vctColor, dir, thickness, len, len, false, MyParticlesConstants.SOFT_PARTICLE_DISTANCE_SCALE_FOR_HARD_PARTICLES); * } * * start = quad.Point3; * dir = quad.Point1 - start; * len = dir.Length(); * if (len > 0.1f) * { * dir = MyMwcUtils.Normalize(dir); * newParticle4.StartLineParticle(lineMaterial.Value, false, 20, start, Vector3.Zero, vctColor, vctColor, dir, thickness, len, len, false, MyParticlesConstants.SOFT_PARTICLE_DISTANCE_SCALE_FOR_HARD_PARTICLES); * }*/ } } }
/// <summary> /// DrawTransparentBox /// </summary> public static void DrawTransparentBox(ref Matrix worldMatrix, ref BoundingBox localbox, ref Vector4 vctColor, bool bWireFramed, int wireDivideRatio, MyTransparentMaterialEnum?faceMaterial = null, MyTransparentMaterialEnum?lineMaterial = null) { if (!faceMaterial.HasValue) { faceMaterial = MyTransparentMaterialEnum.ContainerBorder; } Vector3 vctMin = localbox.Min; Vector3 vctMax = localbox.Max; //@ CreateQuads Vector3 translation = worldMatrix.Translation; MyQuad quad; Matrix orientation = Matrix.Identity; orientation.Forward = worldMatrix.Forward; orientation.Up = worldMatrix.Up; orientation.Right = worldMatrix.Right; float halfWidth = (localbox.Max.X - localbox.Min.X) / 2f; float halfHeight = (localbox.Max.Y - localbox.Min.Y) / 2f; float halfDeep = (localbox.Max.Z - localbox.Min.Z) / 2f; //@ Front side Vector3 faceNorm = Vector3.Transform(Vector3.Forward, orientation); faceNorm *= halfDeep; Vector3 vctPos = translation + faceNorm; MyUtils.GenerateQuad(out quad, ref vctPos, halfWidth, halfHeight, ref worldMatrix); MyTransparentGeometry.AddQuad(faceMaterial.Value, ref quad, ref vctColor, ref translation); //@ Back side vctPos = translation - faceNorm; MyUtils.GenerateQuad(out quad, ref vctPos, halfWidth, halfHeight, ref worldMatrix); MyTransparentGeometry.AddQuad(faceMaterial.Value, ref quad, ref vctColor, ref translation); //@ Left side Matrix rotMat = Matrix.CreateRotationY(MathHelper.ToRadians(90f)); Matrix rotated = rotMat * worldMatrix; faceNorm = Vector3.Transform(Vector3.Left, orientation); faceNorm *= halfWidth; vctPos = translation + faceNorm; MyUtils.GenerateQuad(out quad, ref vctPos, halfDeep, halfHeight, ref rotated); MyTransparentGeometry.AddQuad(faceMaterial.Value, ref quad, ref vctColor, ref translation); //@ Right side vctPos = translation - faceNorm; MyUtils.GenerateQuad(out quad, ref vctPos, halfDeep, halfHeight, ref rotated); MyTransparentGeometry.AddQuad(faceMaterial.Value, ref quad, ref vctColor, ref translation); //@ Top side rotMat = Matrix.CreateRotationX(MathHelper.ToRadians(90f)); rotated = rotMat * worldMatrix; faceNorm = Vector3.Transform(Vector3.Up, orientation); faceNorm *= ((localbox.Max.Y - localbox.Min.Y) / 2f); vctPos = translation + faceNorm; MyUtils.GenerateQuad(out quad, ref vctPos, halfWidth, halfDeep, ref rotated); MyTransparentGeometry.AddQuad(faceMaterial.Value, ref quad, ref vctColor, ref translation); //@ Bottom side vctPos = translation - faceNorm; MyUtils.GenerateQuad(out quad, ref vctPos, halfWidth, halfDeep, ref rotated); MyTransparentGeometry.AddQuad(faceMaterial.Value, ref quad, ref vctColor, ref translation); if (bWireFramed) { Vector4 vctWireColor = vctColor; vctWireColor *= 1.3f; DrawWireFramedBox(ref worldMatrix, ref localbox, ref vctWireColor, 0.02f, wireDivideRatio, lineMaterial); } }
void DrawSymmetry() { if (!Main.LocalToolHandler.SymmetryInputAvailable || !MyAPIGateway.CubeBuilder.UseSymmetry || Main.LocalToolHandler.AimedBlock == null) { return; } IMyCubeGrid selectedGrid = Main.LocalToolHandler.AimedBlock.CubeGrid; if (!selectedGrid.XSymmetryPlane.HasValue && !selectedGrid.YSymmetryPlane.HasValue && !selectedGrid.ZSymmetryPlane.HasValue) { return; } MatrixD matrix = selectedGrid.WorldMatrix; MyQuadD quad = new MyQuadD(); float gridSizeHalf = selectedGrid.GridSize * 0.5f; Vector3D gridSize = (Vector3I.One + (selectedGrid.Max - selectedGrid.Min)) * gridSizeHalf; if (selectedGrid.XSymmetryPlane.HasValue) { Vector3D center = matrix.Translation + matrix.Right * ((selectedGrid.XSymmetryPlane.Value.X * selectedGrid.GridSize) - (selectedGrid.XSymmetryOdd ? gridSizeHalf : 0)); Vector3D minY = matrix.Up * ((selectedGrid.Min.Y - 1.5f) * selectedGrid.GridSize); Vector3D maxY = matrix.Up * ((selectedGrid.Max.Y + 1.5f) * selectedGrid.GridSize); Vector3D minZ = matrix.Backward * ((selectedGrid.Min.Z - 1.5f) * selectedGrid.GridSize); Vector3D maxZ = matrix.Backward * ((selectedGrid.Max.Z + 1.5f) * selectedGrid.GridSize); quad.Point0 = center + maxY + maxZ; quad.Point1 = center + maxY + minZ; quad.Point2 = center + minY + minZ; quad.Point3 = center + minY + maxZ; MyTransparentGeometry.AddQuad(SYMMETRY_PLANES_MATERIAL, ref quad, Color.Red * SYMMETRY_PLANES_ALPHA, ref center, blendType: SYMMETRY_PLANES_BLENDTYPE); } if (selectedGrid.YSymmetryPlane.HasValue) { Vector3D center = matrix.Translation + matrix.Up * ((selectedGrid.YSymmetryPlane.Value.Y * selectedGrid.GridSize) - (selectedGrid.YSymmetryOdd ? gridSizeHalf : 0)); Vector3D minZ = matrix.Backward * ((selectedGrid.Min.Z - 1.5f) * selectedGrid.GridSize); Vector3D maxZ = matrix.Backward * ((selectedGrid.Max.Z + 1.5f) * selectedGrid.GridSize); Vector3D minX = matrix.Right * ((selectedGrid.Min.X - 1.5f) * selectedGrid.GridSize); Vector3D maxX = matrix.Right * ((selectedGrid.Max.X + 1.5f) * selectedGrid.GridSize); quad.Point0 = center + maxZ + maxX; quad.Point1 = center + maxZ + minX; quad.Point2 = center + minZ + minX; quad.Point3 = center + minZ + maxX; MyTransparentGeometry.AddQuad(SYMMETRY_PLANES_MATERIAL, ref quad, Color.Green * SYMMETRY_PLANES_ALPHA, ref center, blendType: SYMMETRY_PLANES_BLENDTYPE); } if (selectedGrid.ZSymmetryPlane.HasValue) { Vector3D center = matrix.Translation + matrix.Backward * ((selectedGrid.ZSymmetryPlane.Value.Z * selectedGrid.GridSize) + (selectedGrid.ZSymmetryOdd ? gridSizeHalf : 0)); Vector3D minY = matrix.Up * ((selectedGrid.Min.Y - 1.5f) * selectedGrid.GridSize); Vector3D maxY = matrix.Up * ((selectedGrid.Max.Y + 1.5f) * selectedGrid.GridSize); Vector3D minX = matrix.Right * ((selectedGrid.Min.X - 1.5f) * selectedGrid.GridSize); Vector3D maxX = matrix.Right * ((selectedGrid.Max.X + 1.5f) * selectedGrid.GridSize); quad.Point0 = center + maxY + maxX; quad.Point1 = center + maxY + minX; quad.Point2 = center + minY + minX; quad.Point3 = center + minY + maxX; MyTransparentGeometry.AddQuad(SYMMETRY_PLANES_MATERIAL, ref quad, Color.Blue * SYMMETRY_PLANES_ALPHA, ref center, blendType: SYMMETRY_PLANES_BLENDTYPE); } }
public static void DrawTransparentCylinder(ref MatrixD worldMatrix, float radiusBase, float radiusTop, float length, int wireDivideRatio, Vector4 faceColor, Vector4 lineColor, MyStringId?faceMaterial = null, MyStringId?lineMaterial = null, float lineThickness = 0.01f, BlendTypeEnum lineBlendType = BlendTypeEnum.Standard, BlendTypeEnum faceBlendType = BlendTypeEnum.Standard, bool capEnds = true) { Vector3D dir = worldMatrix.Forward; Vector3D centerBottom = worldMatrix.Translation; Vector3D centerTop = worldMatrix.Translation + dir * length; Vector3D currBottom = Vector3D.Zero; Vector3D currTop = Vector3D.Zero; Vector3D prevBottom = Vector3D.Zero; Vector3D prevTop = Vector3D.Zero; float stepDeg = 360f / wireDivideRatio; for (int i = 0; i <= wireDivideRatio; i++) { float angle = MathHelper.ToRadians(i * stepDeg); currBottom.X = radiusBase * Math.Cos(angle); currBottom.Y = radiusBase * Math.Sin(angle); currBottom.Z = 0; currBottom = Vector3D.Transform(currBottom, worldMatrix); currTop.X = radiusTop * Math.Cos(angle); currTop.Y = radiusTop * Math.Sin(angle); currTop.Z = -length; currTop = Vector3D.Transform(currTop, worldMatrix); if (lineMaterial.HasValue) { MyTransparentGeometry.AddLineBillboard(lineMaterial.Value, lineColor, currBottom, (currTop - currBottom), 1f, lineThickness, lineBlendType); } if (i > 0) { if (lineMaterial.HasValue) { MyTransparentGeometry.AddLineBillboard(lineMaterial.Value, lineColor, prevBottom, (currBottom - prevBottom), 1f, lineThickness, lineBlendType); MyTransparentGeometry.AddLineBillboard(lineMaterial.Value, lineColor, prevTop, (currTop - prevTop), 1f, lineThickness, lineBlendType); } if (faceMaterial.HasValue) { var quad = new MyQuadD() { Point0 = prevTop, Point1 = currTop, Point2 = currBottom, Point3 = prevBottom }; MyTransparentGeometry.AddQuad(faceMaterial.Value, ref quad, faceColor, ref currTop, blendType: faceBlendType); if (capEnds) { var color = faceColor.ToLinearRGB(); // HACK keeping color consistent with AddQuad() and AddLineBillboard() MyTransparentGeometry.AddTriangleBillboard(centerTop, currTop, prevTop, dir, dir, dir, Vector2.Zero, Vector2.Zero, Vector2.Zero, faceMaterial.Value, 0, currTop, color, faceBlendType); MyTransparentGeometry.AddTriangleBillboard(centerBottom, currBottom, prevBottom, -dir, -dir, -dir, Vector2.Zero, Vector2.Zero, Vector2.Zero, faceMaterial.Value, 0, currBottom, color, faceBlendType); } } } prevBottom = currBottom; prevTop = currTop; } }
public override bool Draw(MyRenderObject renderObject) { if (Render.MyRender.GetCurrentLodDrawPass() == MyLodTypeEnum.LOD0) { if (IsDummyVisible()) { base.Draw(renderObject); Vector4 color; switch (DummyFlags) { case MyDummyPointFlags.NONE: color = new Vector4(0.5f, 0.7f, 0.1f, 0.3f); break; case MyDummyPointFlags.SAFE_AREA: color = new Vector4(0.2f, 0.3f, 0.22f, 0.1f); break; case MyDummyPointFlags.DETECTOR: color = new Vector4(0.12f, 0.1f, 0.7f, 0.3f); break; case MyDummyPointFlags.PARTICLE: color = new Vector4(0.6f, 0.05f, 0.1f, 0.3f); break; default: color = new Vector4(0.6f, 0.6f, 0.7f, 0.3f); break; } if ((DummyFlags & MyDummyPointFlags.COLOR_AREA) != 0) { color = Color; // color Color areas with their area color (overriding the default color). I like to write "color". } Matrix worldMatrix = WorldMatrix; if ((int)(DummyFlags & MyDummyPointFlags.TEXTURE_QUAD) > 0) { BoundingBox localAABB = LocalAABB; MySimpleObjectDraw.DrawWireFramedBox(ref worldMatrix, ref localAABB, ref color, 0.01f, 1, LineMaterial); if (!string.IsNullOrEmpty(Name)) { //var tex = MinerWars.AppCode.Game.Textures.MyTextureManager.GetTexture<MinerWars.AppCode.Game.Textures.MyTexture2D>(Name); int i = 0; foreach (MyTransparentMaterialEnum trEnum in Enum.GetValues(typeof(MyTransparentMaterialEnum))) { if (MyTransparentMaterialConstants.MyTransparentMaterialStrings[i] == Name) { Vector4 quadColor = Vector4.One; MyQuad quad; Vector3 position = GetPosition(); Vector3 zeroPosition = Vector3.Zero; var texture = MyTransparentGeometry.GetTexture(trEnum); float ratio = texture.Height / (float)texture.Width; MyUtils.GenerateQuad(out quad, ref position, WorldAABB.Size().X *ratio, WorldAABB.Size().X, ref worldMatrix); MyTransparentGeometry.AddQuad(trEnum, ref quad, ref quadColor, ref position); } i++; } } } else { if (Type == MyDummyPointType.Box) { BoundingBox localAABB = LocalAABB; MySimpleObjectDraw.DrawTransparentBox(ref worldMatrix, ref localAABB, ref color, true, 1, FaceMaterial, LineMaterial); } else { BoundingSphere localSphere = new BoundingSphere(worldMatrix.Translation, Radius); MySimpleObjectDraw.DrawTransparentSphere(ref worldMatrix, localSphere.Radius, ref color, true, 12, FaceMaterial, LineMaterial); } } } if (ParticleEffect != null && IsVisible() && Enabled) { Vector4 particleColor = Color == Vector4.Zero ? Vector4.One : Color; ParticleEffect.UserColorMultiplier = particleColor; ParticleEffect.UserScale = UserScale; UpdateWorldVolume(); MyParticlesManager.CustomDraw(ParticleEffect); } } return(false); }