/// <summary> /// Calculate the moment of inertia for a solid polygon shape assuming its center of gravity /// is at its centroid. The offset is added to each vertex. /// </summary> public static double MomentForPolygon(double mass, IReadOnlyList <Vect> vertices, Vect offset, double radius) { IntPtr verticesPtr = NativeInterop.StructureArrayToPtr(vertices); double moment = NativeMethods.cpMomentForPoly(mass, vertices.Count, verticesPtr, offset, radius); NativeInterop.FreeStructure(verticesPtr); return(moment); }
/// <summary> /// Calculate the natural centroid of a polygon. /// </summary> public static Vect CentroidForPoly(IReadOnlyList <Vect> vertices) { IntPtr verticesPtr = NativeInterop.StructureArrayToPtr(vertices); Vect centroid = NativeMethods.cpCentroidForPoly(vertices.Count, verticesPtr); NativeInterop.FreeStructure(verticesPtr); return(centroid); }
/// <summary> /// Calculate the signed area of this polygon. Vertices specified such that they connect in /// a clockwise fashion (called winding) give a positive area measurement. This is probably /// backwards to what you might expect. /// </summary> public static double AreaForPoly(IReadOnlyList <Vect> vertices, double radius) { IntPtr verticesPtr = NativeInterop.StructureArrayToPtr(vertices); double area = NativeMethods.cpAreaForPoly(vertices.Count, verticesPtr, radius); NativeInterop.FreeStructure(verticesPtr); return(area); }
private static IntPtr CreatePolygonShape(Body body, Vect[] verts, double radius) { Debug.Assert(verts.Length > 2); IntPtr ptrVectors = NativeInterop.StructureArrayToPtr(verts); IntPtr handle = NativeMethods.cpPolyShapeNewRaw(body.Handle, verts.Length, ptrVectors, radius); NativeInterop.FreeStructure(ptrVectors); return(handle); }
private static IntPtr CreatePolygonShape(Body body, IReadOnlyList <Vect> verts, Transform transform, double radius) { Debug.Assert(verts.Count > 2); IntPtr ptrVectors = NativeInterop.StructureArrayToPtr(verts); IntPtr handle = NativeMethods.cpPolyShapeNew(body.Handle, verts.Count, ptrVectors, transform, radius); NativeInterop.FreeStructure(ptrVectors); return(handle); }