public static void DrawWireframe(PrimitiveDrawer primitiveDrawer, Vector3 cameraPosition, Matrix cameraView, Matrix cameraProjection, Vector3 center, Vector3 size, Quaternion rotation, Color color) { var world = Matrix.CreateScale(size) * Matrix.CreateFromQuaternion(rotation) * Matrix.CreateTranslation(center); var vertices = new VertexPositionColor[WireframeLines.Length * 2]; for (int i = 0; i < WireframeLines.Length; i++) { var transformedLine = WireframeLine.Transform(WireframeLines[i], world); Vector3 cameraToLine = Vector3.Normalize(((transformedLine.Point1 + transformedLine.Point2) / 2) - cameraPosition); Color lineColor = color; if (!IsCameraFacing(cameraToLine, transformedLine.FaceNormal1) && !IsCameraFacing(cameraToLine, transformedLine.FaceNormal2)) { lineColor = Color.FromNonPremultiplied(color.R, color.G, color.B, 25); } vertices[i * 2] = new VertexPositionColor(transformedLine.Point1, lineColor); vertices[(i * 2) + 1] = new VertexPositionColor(transformedLine.Point2, lineColor); } primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection, Color.White, null, PrimitiveType.LineList, vertices, false); }
public static WireframeLine Transform(WireframeLine line, Matrix matrix) { return(new WireframeLine( Vector3.Transform(line.Point1, matrix), Vector3.Transform(line.Point2, matrix), Vector3.Normalize(Vector3.TransformNormal(line.FaceNormal1, matrix)), Vector3.Normalize(Vector3.TransformNormal(line.FaceNormal2, matrix)))); }
public static WireframeLine Transform(WireframeLine line, Matrix matrix) { return new WireframeLine( Vector3.Transform(line.Point1, matrix), Vector3.Transform(line.Point2, matrix), Vector3.Normalize(Vector3.TransformNormal(line.FaceNormal1, matrix)), Vector3.Normalize(Vector3.TransformNormal(line.FaceNormal2, matrix))); }