public static Vector2 ToVector2(this Vector3 vector, ProjectionPlanes projectionPlane) { if (projectionPlane == ProjectionPlanes.XY) { return(new Vector2(vector.x, vector.y)); } if (projectionPlane == ProjectionPlanes.XZ) { return(new Vector2(vector.x, vector.z)); } return(new Vector2(vector.y, vector.z)); }
public static ProjectionPlanes GetProjectionPlane(this Vector3 vector) { ProjectionPlanes result = ProjectionPlanes.YZ; float num = Mathf.Abs(vector.x); float num2 = Mathf.Abs(vector.y); if (num2 > num) { result = ProjectionPlanes.XZ; num = num2; } num2 = Mathf.Abs(vector.z); if (num2 > num) { result = ProjectionPlanes.XY; } return(result); }
protected void DrawCapsule(ref Capsule3 capsule) { Vector3 axis = capsule.Segment.Direction; ProjectionPlanes projPlane = axis.GetProjectionPlane(); Vector3 side = projPlane == ProjectionPlanes.YZ ? Vector3ex.UnitZ : Vector3ex.UnitX; side = axis.Cross(ref side); Vector3 side1 = side.Cross(ref axis); Vector3 p0 = capsule.Segment.P0; Vector3 p1 = capsule.Segment.P1; Vector3 offset = side * capsule.Radius; DrawSegment(p0 + offset, p1 + offset); DrawSegment(p0 - offset, p1 - offset); offset = side1 * capsule.Radius; DrawSegment(p0 + offset, p1 + offset); DrawSegment(p0 - offset, p1 - offset); Gizmos.DrawWireSphere(p0, capsule.Radius); Gizmos.DrawWireSphere(p1, capsule.Radius); }
public static Polygon2 CreateProjected(Polygon3 polygon, ProjectionPlanes projectionPlane) { Polygon2 polygon2 = new Polygon2(polygon.VertexCount); if (projectionPlane == ProjectionPlanes.XY) { int i = 0; int vertexCount = polygon.VertexCount; while (i < vertexCount) { polygon2._vertices[i] = polygon[i].ToVector2XY(); i++; } } else if (projectionPlane == ProjectionPlanes.XZ) { int j = 0; int vertexCount2 = polygon.VertexCount; while (j < vertexCount2) { polygon2._vertices[j] = polygon[j].ToVector2XZ(); j++; } } else { int k = 0; int vertexCount3 = polygon.VertexCount; while (k < vertexCount3) { polygon2._vertices[k] = polygon[k].ToVector2YZ(); k++; } } polygon2.UpdateEdges(); return(polygon2); }