internal static void DestroyRigidBody(PhysicsBodyHandle body) { LosgapSystem.InvokeOnMasterAsync(() => InteropUtils.CallNative( NativeMethods.PhysicsManager_DestroyRigidBody, body ).ThrowOnFailure()); }
internal static void SetBodyMass(PhysicsBodyHandle body, float newMass) { LosgapSystem.InvokeOnMasterAsync(() => InteropUtils.CallNative( NativeMethods.PhysicsManager_SetBodyMass, body, newMass ).ThrowOnFailure()); }
internal unsafe static void RemoveAllForceAndTorqueFromBody(PhysicsBodyHandle body) { LosgapSystem.InvokeOnMasterAsync(() => { InteropUtils.CallNative(NativeMethods.PhysicsManager_RemoveAllForceAndTorqueFromBody, body ).ThrowOnFailure(); }); }
internal static void SetBodyCCD(PhysicsBodyHandle body, float minSpeed, float ccdRadius) { LosgapSystem.InvokeOnMasterAsync(() => InteropUtils.CallNative( NativeMethods.PhysicsManager_SetBodyCCD, body, minSpeed, ccdRadius )); }
public static extern InteropBool PhysicsManager_SetBodyProperties( IntPtr failReason, PhysicsBodyHandle body, float restitution, float linearDamping, float angularDamping, float friction, float rollingFriction );
public static extern InteropBool PhysicsManager_CreateFixedConstraint( IntPtr failReason, PhysicsBodyHandle parentBodyHandle, PhysicsBodyHandle childBodyHandle, IntPtr parentInitTranslation, // Vector4* IntPtr parentInitRotation, // Quaternion* IntPtr childInitTranslation, // Vector4* IntPtr childInitRotation, // Quaternion* IntPtr outConstraintHandle // FixedConstraintHandle* );
private bool KeyContainedInCRB(PhysicsBodyHandle pbh) // This function exists because dict.ContainsKey() boxes struct keys { foreach (PhysicsBodyHandle key in collisionReportableBodies.Keys) { if (key == pbh) { return(true); } } return(false); }
internal static void UpdateBodyTransform(PhysicsBodyHandle bodyHandle) { // WARNING: No longer thread-safe unsafe { char *failReason = stackalloc char[InteropUtils.MAX_INTEROP_FAIL_REASON_STRING_LENGTH + 1]; bool success = NativeMethods.PhysicsManager_UpdateBodyTransform((IntPtr)failReason, bodyHandle); if (!success) { throw new NativeOperationFailedException(Marshal.PtrToStringUni((IntPtr)failReason)); } } }
internal unsafe static void AddTorqueImpulseToBody(PhysicsBodyHandle body, Vector3 torque) { LosgapSystem.InvokeOnMasterAsync(() => { AlignedAllocation <Vector4> vec4Aligned = new AlignedAllocation <Vector4>(16L, (uint)sizeof(Vector4)); *((Vector4 *)vec4Aligned.AlignedPointer) = torque; InteropUtils.CallNative(NativeMethods.PhysicsManager_AddTorqueImpulseToBody, body, vec4Aligned.AlignedPointer ).ThrowOnFailure(); vec4Aligned.Dispose(); }); }
public void DisposePhysicsBody() { if (physicsBody != PhysicsBodyHandle.NULL) { if (collisionDetected != null) { EntityModule.RemoveCollisionCallbackReportingForEntity(this); } LosgapSystem.InvokeOnMasterAsync(() => { physicsBody.Dispose(); physicsBody = PhysicsBodyHandle.NULL; }); } }
public static Entity RayTestNearest(Ray ray, out Vector3 hitPoint) { if (ray.IsInfiniteLength) { ray = ray.WithLength(RAY_TEST_INF_LENGTH_ACTUAL); } PhysicsBodyHandle matchingHandle = PhysicsManager.RayTestNearest(ray.StartPoint, ray.EndPoint.Value, out hitPoint); if (matchingHandle == PhysicsBodyHandle.NULL) { return(null); } lock (staticMutationLock) { return(entityList.FirstOrDefault(e => e.PhysicsBody == matchingHandle)); } }
internal unsafe static Vector3 GetBodyAngularVelocity(PhysicsBodyHandle body) { return(LosgapSystem.InvokeOnMaster(() => { AlignedAllocation <Vector4> vec4Aligned = new AlignedAllocation <Vector4>(16L, (uint)sizeof(Vector4)); InteropUtils.CallNative(NativeMethods.PhysicsManager_GetBodyAngularVelocity, body, vec4Aligned.AlignedPointer ).ThrowOnFailure(); try { return (Vector3)(*((Vector4 *)vec4Aligned.AlignedPointer)); } finally { vec4Aligned.Dispose(); } })); }
internal static void SetBodyProperties(PhysicsBodyHandle body, float restitution, float linearDamping, float angularDamping, float friction, float rollingFriction) { LosgapSystem.InvokeOnMasterAsync(() => InteropUtils.CallNative( NativeMethods.PhysicsManager_SetBodyProperties, body, restitution, linearDamping, angularDamping, friction, rollingFriction ).ThrowOnFailure()); }
internal unsafe static Vector3 GetBodyLinearVelocity(PhysicsBodyHandle body) { AlignedAllocation <Vector4> vec4Aligned = new AlignedAllocation <Vector4>(16L, (uint)sizeof(Vector4)); // WARNING: No longer thread-safe unsafe { char *failReason = stackalloc char[InteropUtils.MAX_INTEROP_FAIL_REASON_STRING_LENGTH + 1]; bool success = NativeMethods.PhysicsManager_GetBodyLinearVelocity((IntPtr)failReason, body, vec4Aligned.AlignedPointer); if (!success) { throw new NativeOperationFailedException(Marshal.PtrToStringUni((IntPtr)failReason)); } } try { return((Vector3)(*((Vector4 *)vec4Aligned.AlignedPointer))); } finally { vec4Aligned.Dispose(); } }
internal unsafe static void SetBodyGravity(PhysicsBodyHandle body, Vector3 gravity) { AlignedAllocation <Vector4> gravityAligned = new AlignedAllocation <Vector4>(16L, (uint)sizeof(Vector4)); *((Vector4 *)gravityAligned.AlignedPointer) = gravity; // WARNING: No longer thread-safe try { unsafe { char *failReason = stackalloc char[InteropUtils.MAX_INTEROP_FAIL_REASON_STRING_LENGTH + 1]; bool success = NativeMethods.PhysicsManager_SetBodyGravity((IntPtr)failReason, body, gravityAligned.AlignedPointer); if (!success) { throw new NativeOperationFailedException(Marshal.PtrToStringUni((IntPtr)failReason)); } } } finally { gravityAligned.Dispose(); } }
public void SetPhysicsShape( PhysicsShapeHandle shapeHandle, Vector3 physicsShapeOffset, float mass, bool forceIntransigence = false, bool disablePerformanceDeactivation = false, bool collideOnlyWithWorld = false, bool collideWithOnlyDynamics = false, float restitution = PhysicsManager.DEFAULT_RESTITUTION, float linearDamping = PhysicsManager.DEFAULT_LINEAR_DAMPING, float angularDamping = PhysicsManager.DEFAULT_ANGULAR_DAMPING, float friction = PhysicsManager.DEFAULT_FRICTION, float rollingFriction = PhysicsManager.DEFAULT_ROLLING_FRICTION) { LosgapSystem.InvokeOnMaster(() => { // Anti-deadlock measures x.x lock (InstanceMutationLock) { if (physicsBody != PhysicsBodyHandle.NULL) { physicsBody.Dispose(); } if (this.physicsShapeOffset == null) { this.physicsShapeOffset = new AlignedAllocation <Vector4>(TRANSFORM_ALIGNMENT, (uint)sizeof(Vector4)); } this.physicsShapeOffset.Value.Write(physicsShapeOffset); physicsBody = PhysicsManager.CreateRigidBody( shapeHandle, mass, disablePerformanceDeactivation, forceIntransigence, collideOnlyWithWorld, collideWithOnlyDynamics, transform.AlignedPointer + 32, transform.AlignedPointer + 16, this.physicsShapeOffset.Value.AlignedPointer ); } }); SetPhysicsProperties(restitution, linearDamping, angularDamping, friction, rollingFriction); }
internal unsafe static FixedConstraintHandle CreateFixedConstraint( PhysicsBodyHandle parentBody, PhysicsBodyHandle childBody, Vector3 parentInitialTranslation, Quaternion parentInitialRotation, Vector3 childInitialTranslation, Quaternion childInitialRotation) { return(LosgapSystem.InvokeOnMaster(() => { Vector3 parentInitTransLocal = parentInitialTranslation; Quaternion parentInitRotLocal = parentInitialRotation; Vector3 childInitTransLocal = childInitialTranslation; Quaternion childInitRotLocal = childInitialRotation; FixedConstraintHandle result; InteropUtils.CallNative(NativeMethods.PhysicsManager_CreateFixedConstraint, parentBody, childBody, (IntPtr)(&parentInitTransLocal), (IntPtr)(&parentInitRotLocal), (IntPtr)(&childInitTransLocal), (IntPtr)(&childInitRotLocal), (IntPtr)(&result) ); return result; })); }
public static extern InteropBool PhysicsManager_GetBodyLinearVelocity( IntPtr failReason, PhysicsBodyHandle body, IntPtr outVelocity // Vector4* );
public static extern InteropBool PhysicsManager_AddTorqueImpulseToBody( IntPtr failReason, PhysicsBodyHandle body, IntPtr torque // Vector4* );
public static extern InteropBool PhysicsManager_ReactivateBody( IntPtr failReason, PhysicsBodyHandle body );
public static extern InteropBool PhysicsManager_SetBodyAngularVelocity( IntPtr failReason, PhysicsBodyHandle body, IntPtr velocity // Vector4* );
public static extern InteropBool PhysicsManager_SetBodyGravity( IntPtr failReason, PhysicsBodyHandle body, IntPtr gravity // Vector4* );
public static extern InteropBool PhysicsManager_SetBodyMass( IntPtr failReason, PhysicsBodyHandle body, float mass );
public static extern InteropBool PhysicsManager_SetBodyCCD( IntPtr failReason, PhysicsBodyHandle body, float minSpeed, float ccdRadius );
public static extern InteropBool PhysicsManager_AddForceToBody( IntPtr failReason, PhysicsBodyHandle body, IntPtr force // Vector4* );
public static extern InteropBool PhysicsManager_DestroyRigidBody( IntPtr failReason, PhysicsBodyHandle body );
public static extern InteropBool PhysicsManager_UpdateBodyTransform( IntPtr failReason, PhysicsBodyHandle body );
public static extern InteropBool PhysicsManager_RemoveAllForceAndTorqueFromBody( IntPtr failReason, PhysicsBodyHandle body );