-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to latest native, add more bindings, add ApplyBuoyancyImpulse …
…and DebugRenderer (WIP), bump version to 2.9.1
- Loading branch information
1 parent
7987b36
commit 6236bfc
Showing
23 changed files
with
517 additions
and
62 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (c) Amer Koleci and Contributors. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. | ||
|
||
using System.Numerics; | ||
using System.Runtime.InteropServices; | ||
using static JoltPhysicsSharp.JoltApi; | ||
|
||
namespace JoltPhysicsSharp; | ||
|
||
public abstract class DebugRenderer : NativeObject | ||
{ | ||
public enum CastShadow : uint | ||
{ | ||
/// <summary> | ||
/// This shape should cast a shadow | ||
/// </summary> | ||
On, | ||
/// <summary> | ||
/// This shape should not cast a shadow | ||
/// </summary> | ||
Off | ||
} | ||
|
||
public enum DrawMode : uint | ||
{ | ||
/// <summary> | ||
/// Draw as a solid shape | ||
/// </summary> | ||
Solid = 0, | ||
/// <summary> | ||
/// Draw as wireframe | ||
/// </summary> | ||
Wireframe = 1, | ||
} | ||
|
||
|
||
private readonly unsafe JPH_DebugRenderer_Procs _listener_Procs = new() | ||
{ | ||
DrawLine = &OnDrawLine, | ||
DrawTriangle = &OnDrawTriangle, | ||
DrawText3D = &OnDrawText3D, | ||
}; | ||
|
||
protected DebugRenderer() | ||
{ | ||
nint listenerContext = DelegateProxies.CreateUserData(this, true); | ||
Handle = JPH_DebugRenderer_Create(_listener_Procs, listenerContext); | ||
} | ||
|
||
protected DebugRenderer(nint handle) | ||
: base(handle) | ||
{ | ||
} | ||
|
||
~DebugRenderer() => Dispose(disposing: false); | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
JPH_DebugRenderer_Destroy(Handle); | ||
} | ||
} | ||
|
||
public void NextFrame() => JPH_DebugRenderer_NextFrame(Handle); | ||
|
||
protected abstract void DrawLine(Vector3 from, Vector3 to, uint color); | ||
|
||
protected virtual void DrawTriangle(Vector3 v1, Vector3 v2, Vector3 v3, uint color, CastShadow castShadow = CastShadow.Off) | ||
{ | ||
|
||
} | ||
|
||
protected abstract void DrawText3D(Vector3 position, string? text, uint color, float height = 0.5f); | ||
|
||
#region DebugRendererListener | ||
[UnmanagedCallersOnly] | ||
private static unsafe void OnDrawLine(nint context, Vector3* from, Vector3* to, uint color) | ||
{ | ||
DebugRenderer listener = DelegateProxies.GetUserData<DebugRenderer>(context, out _); | ||
|
||
listener.DrawLine(*from, *to, color); | ||
} | ||
|
||
[UnmanagedCallersOnly] | ||
private static unsafe void OnDrawTriangle(nint context, Vector3* v1, Vector3* v2, Vector3* v3, uint color, CastShadow castShadow) | ||
{ | ||
DebugRenderer listener = DelegateProxies.GetUserData<DebugRenderer>(context, out _); | ||
|
||
listener.DrawTriangle(*v1, *v2, *v3, color, castShadow); | ||
} | ||
|
||
[UnmanagedCallersOnly] | ||
private static unsafe void OnDrawText3D(nint context, Vector3* position, byte* textPtr, uint color, float height) | ||
{ | ||
DebugRenderer listener = DelegateProxies.GetUserData<DebugRenderer>(context, out _); | ||
|
||
listener.DrawText3D(*position, ConvertToManaged(textPtr), color, height); | ||
} | ||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright (c) Amer Koleci and Contributors. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. | ||
|
||
using System.Numerics; | ||
|
||
namespace JoltPhysicsSharp; | ||
|
||
public struct DrawSettings | ||
{ | ||
/// <summary> | ||
/// Draw the GetSupport() function, used for convex collision detection | ||
/// </summary> | ||
public Bool8 DrawGetSupportFunction = false; | ||
/// <summary> | ||
/// When drawing the support function, also draw which direction mapped to a specific support point | ||
/// </summary> | ||
public Bool8 DrawSupportDirection = false; | ||
/// <summary> | ||
/// Draw the faces that were found colliding during collision detection | ||
/// </summary> | ||
public Bool8 DrawGetSupportingFace = false; | ||
/// <summary> | ||
/// Draw the shapes of all bodies | ||
/// </summary> | ||
public Bool8 DrawShape = true; | ||
/// <summary> | ||
/// When mDrawShape is true and this is true, the shapes will be drawn in wireframe instead of solid. | ||
/// </summary> | ||
public Bool8 DrawShapeWireframe = false; | ||
/// <summary> | ||
/// Coloring scheme to use for shapes | ||
/// </summary> | ||
public ShapeColor DrawShapeColor = ShapeColor.MotionTypeColor; | ||
/// <summary> | ||
/// Draw a bounding box per body | ||
/// </summary> | ||
public Bool8 DrawBoundingBox = false; | ||
/// <summary> | ||
/// Draw the center of mass for each body | ||
/// </summary> | ||
public Bool8 DrawCenterOfMassTransform = false; | ||
/// <summary> | ||
/// Draw the world transform (which can be different than the center of mass) for each body | ||
/// </summary> | ||
public Bool8 DrawWorldTransform = false; | ||
/// <summary> | ||
/// Draw the velocity vector for each body | ||
/// </summary> | ||
public Bool8 DrawVelocity = false; | ||
/// <summary> | ||
/// Draw the mass and inertia (as the box equivalent) for each body | ||
/// </summary> | ||
public Bool8 DrawMassAndInertia = false; | ||
/// <summary> | ||
/// Draw stats regarding the sleeping algorithm of each body | ||
/// </summary> | ||
public Bool8 DrawSleepStats = false; | ||
/// <summary> | ||
/// Draw the vertices of soft bodies | ||
/// </summary> | ||
public Bool8 DrawSoftBodyVertices = false; | ||
/// <summary> | ||
/// Draw the velocities of the vertices of soft bodies | ||
/// </summary> | ||
public Bool8 DrawSoftBodyVertexVelocities = false; | ||
/// <summary> | ||
/// Draw the edge constraints of soft bodies | ||
/// </summary> | ||
public Bool8 DrawSoftBodyEdgeConstraints = false; | ||
/// <summary> | ||
/// Draw the bend constraints of soft bodies | ||
/// </summary> | ||
public Bool8 DrawSoftBodyBendConstraints = false; | ||
/// <summary> | ||
/// Draw the volume constraints of soft bodies | ||
/// </summary> | ||
public Bool8 DrawSoftBodyVolumeConstraints = false; | ||
/// <summary> | ||
/// Draw the skin constraints of soft bodies | ||
/// </summary> | ||
public Bool8 DrawSoftBodySkinConstraints = false; | ||
/// <summary> | ||
/// Draw the LRA constraints of soft bodies | ||
/// </summary> | ||
public Bool8 DrawSoftBodyLRAConstraints = false; | ||
/// <summary> | ||
/// Draw the predicted bounds of soft bodies | ||
/// </summary> | ||
public Bool8 DrawSoftBodyPredictedBounds = false; | ||
/// <summary> | ||
/// Coloring scheme to use for soft body constraints | ||
/// </summary> | ||
public SoftBodyConstraintColor DrawSoftBodyConstraintColor = SoftBodyConstraintColor.ConstraintType; | ||
|
||
public DrawSettings() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.