private static DebugColor SpaceDebugDrawColorForShapeCallback(cpShape handleShape, voidptr_t data) { IDebugDraw debugDraw = NativeInterop.FromIntPtr <IDebugDraw>(data); var shape = Shape.FromHandle(handleShape); return(debugDraw.ColorForShape(shape)); }
private static void SpaceDebugDrawPolygonCallback(int count, cpVertPointer verts, double radius, DebugColor outlineColor, DebugColor fillColor, voidptr_t data) { IDebugDraw debugDraw = NativeInterop.FromIntPtr <IDebugDraw>(data); Vect[] vectors = NativeInterop.PtrToStructureArray <Vect>(verts, count); debugDraw.DrawPolygon(vectors, radius, outlineColor, fillColor); }
/// <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 IntPtr ToPointer() { IntPtr drawOptionsPtr = NativeInterop.AllocStructure <cpSpaceDebugDrawOptions>(); #if NETFRAMEWORK Marshal.StructureToPtr(this, drawOptionsPtr, false); #else Marshal.StructureToPtr <cpSpaceDebugDrawOptions>(this, drawOptionsPtr, false); #endif return(drawOptionsPtr); }
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); }
private CollisionHandler(cpCollisionHandlerPointer collisionHandle, ref cpCollisionHandler handler) { handle = collisionHandle; IntPtr data = NativeInterop.RegisterHandle(this); handler.userData = data; TypeA = (int)handler.typeA; TypeB = (int)handler.typeB; cpCollisionHandler.ToPointer(handler, handle); }
internal static CollisionHandler <T> GetOrCreate(cpCollisionHandlerPointer collisionHandle) { Debug.Assert(collisionHandle != IntPtr.Zero, "CollisionHandle cannot be zero"); var handler = cpCollisionHandler.FromHandle(collisionHandle); if (handler.userData != IntPtr.Zero) { return(NativeInterop.FromIntPtr <CollisionHandler <T> >(handler.userData)); } return(new CollisionHandler <T>(collisionHandle, ref handler)); }
public IntPtr AcquireDebugDrawOptions(IDebugDraw debugDraw, DebugDrawFlags flags, DebugDrawColors colors) { this.flags = (int)flags; collisionPointColor = colors.CollisionPoint; constraintColor = colors.Constraint; shapeOutlineColor = colors.ShapeOutline; drawCircle = spaceDebugDrawCircleCallback.ToFunctionPointer(); drawSegment = spaceDebugDrawSegmentCallback.ToFunctionPointer(); drawFatSegment = spaceDebugDrawFatSegmentCallback.ToFunctionPointer(); drawPolygon = spaceDebugDrawPolygonCallback.ToFunctionPointer(); drawDot = spaceDebugDrawDotCallback.ToFunctionPointer(); colorForShape = spaceDebugDrawColorForShapeCallback.ToFunctionPointer(); data = NativeInterop.RegisterHandle(debugDraw); return(ToPointer()); }
/// <summary> /// Get a Constraint object from a native handle. /// </summary> public static Constraint FromHandle(cpConstraint constraint) { cpDataPointer handle = NativeMethods.cpConstraintGetUserData(constraint); return(NativeInterop.FromIntPtr <Constraint>(handle)); }
void ReleaseUserData() { cpDataPointer pointer = NativeMethods.cpConstraintGetUserData(constraint); NativeInterop.ReleaseHandle(pointer); }
void RegisterUserData() { cpDataPointer pointer = NativeInterop.RegisterHandle(this); NativeMethods.cpSpaceSetUserData(space, pointer); }
void ReleaseUserData() { cpDataPointer pointer = NativeMethods.cpBodyGetUserData(body); NativeInterop.ReleaseHandle(pointer); }
private static void SpaceDebugDrawFatSegmentCallback(Vect a, Vect b, double radius, DebugColor outlineColor, DebugColor fillColor, voidptr_t data) { IDebugDraw debugDraw = NativeInterop.FromIntPtr <IDebugDraw>(data); debugDraw.DrawFatSegment(a, b, radius, outlineColor, fillColor); }
/// <summary> /// Get a <see cref="Body"/> object from a native cpBody handle. /// </summary> public static Body FromHandle(cpBody body) { cpDataPointer handle = NativeMethods.cpBodyGetUserData(body); return(NativeInterop.FromIntPtr <Body>(handle)); }
private static void SpaceDebugDrawSegmentCallback(Vect a, Vect b, DebugColor color, voidptr_t data) { IDebugDraw debugDraw = NativeInterop.FromIntPtr <IDebugDraw>(data); debugDraw.DrawSegment(a, b, color); }
private static void SpaceDebugDrawDotCallback(double size, Vect pos, DebugColor color, voidptr_t data) { IDebugDraw debugDraw = NativeInterop.FromIntPtr <IDebugDraw>(data); debugDraw.DrawDot(size, pos, color); }
/// <summary> /// Register managed object in the native user data. /// </summary> protected void RegisterUserData() { cpDataPointer pointer = NativeInterop.RegisterHandle(this); NativeMethods.cpShapeSetUserData(shape, pointer); }
void RegisterUserData() { cpDataPointer pointer = NativeInterop.RegisterHandle(this); NativeMethods.cpBodySetUserData(body, pointer); }
void ReleaseUserData() { cpDataPointer pointer = NativeMethods.cpShapeGetUserData(shape); NativeInterop.ReleaseHandle(pointer); }
/// <summary> /// Get a managed Shape from a native handle. /// </summary> public static Shape FromHandle(cpShape shape) { cpDataPointer handle = NativeMethods.cpShapeGetUserData(shape); return(NativeInterop.FromIntPtr <Shape>(handle)); }
public void ReleaseDebugDrawOptions(IntPtr debugDrawOptionsPointer) { NativeInterop.ReleaseHandle(data); NativeInterop.FreeStructure(debugDrawOptionsPointer); }
/// <summary> /// Register managed object to native user data. /// </summary> internal protected void RegisterUserData() { cpDataPointer pointer = NativeInterop.RegisterHandle(this); NativeMethods.cpConstraintSetUserData(constraint, pointer); }
private static void SpaceDebugDrawCircleCallback(Vect pos, double angle, double radius, DebugColor outlineColor, DebugColor fillColor, voidptr_t data) { IDebugDraw debugDraw = NativeInterop.FromIntPtr <IDebugDraw>(data); debugDraw.DrawCircle(pos, angle, radius, outlineColor, fillColor); }
/// <summary> /// Get a Space object from native cpSpace handle. /// </summary> public static Space FromHandle(cpSpace space) { cpDataPointer handle = NativeMethods.cpSpaceGetUserData(space); return(NativeInterop.FromIntPtr <Space>(handle)); }