diff --git a/BulletSharp/BulletSharp.csproj b/BulletSharp/BulletSharp.csproj
index c76c52a1..fd9f8165 100644
--- a/BulletSharp/BulletSharp.csproj
+++ b/BulletSharp/BulletSharp.csproj
@@ -58,6 +58,8 @@
+
+
@@ -208,6 +210,7 @@
+
Code
diff --git a/BulletSharp/Collision/CompoundShape.cs b/BulletSharp/Collision/CompoundShape.cs
index 9840d82a..8b8e7f57 100644
--- a/BulletSharp/Collision/CompoundShape.cs
+++ b/BulletSharp/Collision/CompoundShape.cs
@@ -134,7 +134,7 @@ namespace BulletSharp
public CompoundShapeChildArray ChildList => _childList;
- public Dbvt DynamicAabbTree => new Dbvt(btCompoundShape_getDynamicAabbTree(Native), true);
+ public Dbvt DynamicAabbTree => new Dbvt(btCompoundShape_getDynamicAabbTree(Native));
public int NumChildShapes => _childList.Count;
diff --git a/BulletSharp/Collision/Dbvt.cs b/BulletSharp/Collision/Dbvt.cs
index c367bc4a..7c11fad9 100644
--- a/BulletSharp/Collision/Dbvt.cs
+++ b/BulletSharp/Collision/Dbvt.cs
@@ -136,19 +136,40 @@ namespace BulletSharp
public class DbvtNode
{
- internal IntPtr Native;
+ internal readonly IntPtr Native;
internal DbvtNode(IntPtr native)
{
Native = native;
}
- /*
+
+ public override bool Equals(object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ var objDbvt = obj as DbvtNode;
+ if (objDbvt == null)
+ {
+ return false;
+ }
+
+ return Native == objDbvt.Native;
+ }
+
+ public override int GetHashCode() => (int)Native;
public DbvtNodePtrArray Childs
{
- get { return btDbvtNode_getChilds(Native); }
+ get
+ {
+ int childCount = IsLeaf ? 0 : 2;
+ return new DbvtNodePtrArray(btDbvtNode_getChilds(Native), childCount);
+ }
}
- */
+
public IntPtr Data
{
get => btDbvtNode_getData(Native);
@@ -163,7 +184,7 @@ namespace BulletSharp
public bool IsInternal => btDbvtNode_isinternal(Native);
- public bool Isleaf => btDbvtNode_isleaf(Native);
+ public bool IsLeaf => btDbvtNode_isleaf(Native);
public DbvtNode Parent
{
@@ -193,7 +214,7 @@ namespace BulletSharp
}
}
- public class Dbvt : IDisposable
+ public class Dbvt
{
public class IClone : IDisposable
{
@@ -570,18 +591,11 @@ namespace BulletSharp
}
}
- internal IntPtr Native;
- bool _preventDelete;
+ internal readonly IntPtr Native;
- internal Dbvt(IntPtr native, bool preventDelete)
+ internal Dbvt(IntPtr native)
{
Native = native;
- _preventDelete = preventDelete;
- }
-
- public Dbvt()
- {
- Native = btDbvt_new();
}
/*
public static int Allocate(AlignedIntArray ifree, AlignedStkNpsArray stock,
@@ -661,7 +675,7 @@ namespace BulletSharp
{
return btDbvt_empty(Native);
}
- /*
+ /*
public static void EnumLeaves(DbvtNode root, ICollide policy)
{
btDbvt_enumLeaves(root.Native, policy.Native);
@@ -671,13 +685,31 @@ namespace BulletSharp
{
btDbvt_enumNodes(root.Native, policy.Native);
}
+ */
+ public override bool Equals(object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ var objDbvt = obj as Dbvt;
+ if (objDbvt == null)
+ {
+ return false;
+ }
+
+ return Native == objDbvt.Native;
+ }
+ /*
public static void ExtractLeaves(DbvtNode node, AlignedDbvtNodeArray leaves)
{
btDbvt_extractLeaves(node.Native, leaves.Native);
}
*/
- public DbvtNode Insert(DbvtVolume box, IntPtr data)
+ public override int GetHashCode() => (int)Native;
+
+ public DbvtNode Insert(DbvtVolume box, IntPtr data)
{
return new DbvtNode(btDbvt_insert(Native, box.Native, data));
}
@@ -811,27 +843,5 @@ namespace BulletSharp
get { return btDbvt_getStkStack(Native); }
}
*/
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (Native != IntPtr.Zero)
- {
- if (!_preventDelete)
- {
- btDbvt_delete(Native);
- }
- Native = IntPtr.Zero;
- }
- }
-
- ~Dbvt()
- {
- Dispose(false);
- }
}
}
diff --git a/BulletSharp/Collision/DbvtArray.cs b/BulletSharp/Collision/DbvtArray.cs
new file mode 100644
index 00000000..f328d98f
--- /dev/null
+++ b/BulletSharp/Collision/DbvtArray.cs
@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using static BulletSharp.UnsafeNativeMethods;
+
+namespace BulletSharp
+{
+ public class DbvtArrayEnumerator : IEnumerator
+ {
+ private int _i;
+ private int _count;
+ private IList _array;
+
+ public DbvtArrayEnumerator(IList array)
+ {
+ _array = array;
+ _count = array.Count;
+ _i = -1;
+ }
+
+ public void Dispose()
+ {
+ }
+
+ public bool MoveNext()
+ {
+ _i++;
+ return _i != _count;
+ }
+
+ public void Reset()
+ {
+ _i = 0;
+ }
+
+ public Dbvt Current => _array[_i];
+
+ object System.Collections.IEnumerator.Current => _array[_i];
+ }
+
+ [DebuggerDisplay("Count = {Count}")]
+ [DebuggerTypeProxy(typeof(ListDebugView))]
+ public class DbvtArray : FixedSizeArray, IList
+ {
+ internal DbvtArray(IntPtr native, int count)
+ : base(native, count)
+ {
+ }
+
+ public int IndexOf(Dbvt item)
+ {
+ return btDbvt_array_index_of(_native, item != null ? item.Native : IntPtr.Zero, _count);
+ }
+
+ public void Insert(int index, Dbvt item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public Dbvt this[int index]
+ {
+ get
+ {
+ if ((uint)index >= (uint)Count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ IntPtr ptr = btDbvt_array_at(_native, index);
+ return new Dbvt(ptr);
+ }
+ set
+ {
+ throw new NotSupportedException();
+ }
+ }
+
+ public void Add(Dbvt item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public bool Contains(Dbvt item)
+ {
+ return IndexOf(item) != -1;
+ }
+
+ public void CopyTo(Dbvt[] array, int arrayIndex)
+ {
+ if (array == null)
+ throw new ArgumentNullException(nameof(array));
+
+ if (arrayIndex < 0)
+ throw new ArgumentOutOfRangeException(nameof(array));
+
+ int count = Count;
+ if (arrayIndex + count > array.Length)
+ throw new ArgumentException("Array too small.", "array");
+
+ for (int i = 0; i < count; i++)
+ {
+ array[arrayIndex + i] = this[i];
+ }
+ }
+
+ public bool Remove(Dbvt item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ return new DbvtArrayEnumerator(this);
+ }
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return new DbvtArrayEnumerator(this);
+ }
+ }
+}
diff --git a/BulletSharp/Collision/DbvtBroadphase.cs b/BulletSharp/Collision/DbvtBroadphase.cs
index e205be59..b171376d 100644
--- a/BulletSharp/Collision/DbvtBroadphase.cs
+++ b/BulletSharp/Collision/DbvtBroadphase.cs
@@ -160,7 +160,7 @@ namespace BulletSharp
set => btDbvtBroadphase_setReleasepaircache(Native, value);
}
- //public DbvtArray Sets => btDbvtBroadphase_getSets(Native);
+ public DbvtArray Sets => new DbvtArray(btDbvtBroadphase_getSets(Native), 2);
public int StageCurrent
{
diff --git a/BulletSharp/Collision/DbvtNodePtrArray.cs b/BulletSharp/Collision/DbvtNodePtrArray.cs
new file mode 100644
index 00000000..692301bd
--- /dev/null
+++ b/BulletSharp/Collision/DbvtNodePtrArray.cs
@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using static BulletSharp.UnsafeNativeMethods;
+
+namespace BulletSharp
+{
+ public class DbvtNodePtrArrayEnumerator : IEnumerator
+ {
+ private int _i;
+ private int _count;
+ private IList _array;
+
+ public DbvtNodePtrArrayEnumerator(IList array)
+ {
+ _array = array;
+ _count = array.Count;
+ _i = -1;
+ }
+
+ public void Dispose()
+ {
+ }
+
+ public bool MoveNext()
+ {
+ _i++;
+ return _i != _count;
+ }
+
+ public void Reset()
+ {
+ _i = 0;
+ }
+
+ public DbvtNode Current => _array[_i];
+
+ object System.Collections.IEnumerator.Current => _array[_i];
+ }
+
+ [DebuggerDisplay("Count = {Count}")]
+ [DebuggerTypeProxy(typeof(ListDebugView))]
+ public class DbvtNodePtrArray : FixedSizeArray, IList
+ {
+ internal DbvtNodePtrArray(IntPtr native, int count)
+ : base(native, count)
+ {
+ }
+
+ public int IndexOf(DbvtNode item)
+ {
+ return btDbvtNodePtr_array_index_of(_native, item != null ? item.Native : IntPtr.Zero, _count);
+ }
+
+ public void Insert(int index, DbvtNode item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public DbvtNode this[int index]
+ {
+ get
+ {
+ if ((uint)index >= (uint)Count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ IntPtr ptr = btDbvtNodePtr_array_at(_native, index);
+ return (ptr != IntPtr.Zero) ? new DbvtNode(ptr) : null;
+ }
+ set
+ {
+ throw new NotSupportedException();
+ }
+ }
+
+ public void Add(DbvtNode item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public bool Contains(DbvtNode item)
+ {
+ return IndexOf(item) != -1;
+ }
+
+ public void CopyTo(DbvtNode[] array, int arrayIndex)
+ {
+ if (array == null)
+ throw new ArgumentNullException(nameof(array));
+
+ if (arrayIndex < 0)
+ throw new ArgumentOutOfRangeException(nameof(array));
+
+ int count = Count;
+ if (arrayIndex + count > array.Length)
+ throw new ArgumentException("Array too small.", "array");
+
+ for (int i = 0; i < count; i++)
+ {
+ array[arrayIndex + i] = this[i];
+ }
+ }
+
+ public bool Remove(DbvtNode item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ return new DbvtNodePtrArrayEnumerator(this);
+ }
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return new DbvtNodePtrArrayEnumerator(this);
+ }
+ }
+}
diff --git a/BulletSharp/Collision/ShapeHull.cs b/BulletSharp/Collision/ShapeHull.cs
index 6fe09ff7..18b22713 100644
--- a/BulletSharp/Collision/ShapeHull.cs
+++ b/BulletSharp/Collision/ShapeHull.cs
@@ -1,9 +1,10 @@
+using BulletSharp.Math;
using System;
using static BulletSharp.UnsafeNativeMethods;
namespace BulletSharp
{
- public class ShapeHull : IDisposable
+ public class ShapeHull : IDisposable
{
internal IntPtr Native;
diff --git a/BulletSharp/LinearMath/Collections.cs b/BulletSharp/LinearMath/Collections.cs
index 35872d05..c865d92d 100644
--- a/BulletSharp/LinearMath/Collections.cs
+++ b/BulletSharp/LinearMath/Collections.cs
@@ -29,27 +29,6 @@ namespace BulletSharp
}
};
- internal class Vector3ListDebugView
- {
- private IList _list;
-
- public Vector3ListDebugView(IList list)
- {
- _list = list;
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public Vector3[] Items
- {
- get
- {
- var arr = new Vector3[_list.Count];
- _list.CopyTo(arr, 0);
- return arr;
- }
- }
- };
-
public class CompoundShapeChildArrayEnumerator : IEnumerator
{
private int _i;
@@ -116,39 +95,6 @@ namespace BulletSharp
object System.Collections.IEnumerator.Current => _array[_i];
}
- public class Vector3ArrayEnumerator : IEnumerator
- {
- private int _i;
- private int _count;
- private IList _array;
-
- public Vector3ArrayEnumerator(IList array)
- {
- _array = array;
- _count = array.Count;
- _i = -1;
- }
-
- public void Dispose()
- {
- }
-
- public bool MoveNext()
- {
- _i++;
- return _i != _count;
- }
-
- public void Reset()
- {
- _i = 0;
- }
-
- public Vector3 Current => _array[_i];
-
- object System.Collections.IEnumerator.Current => _array[_i];
- }
-
public class FixedSizeArray
{
internal IntPtr _native;
@@ -349,89 +295,4 @@ namespace BulletSharp
throw new NotSupportedException();
}
}
-
- [DebuggerDisplay("Count = {Count}")]
- [DebuggerTypeProxy(typeof(Vector3ListDebugView))]
- public class Vector3Array : FixedSizeArray, IList
- {
- internal Vector3Array(IntPtr native, int count)
- : base(native, count)
- {
- }
-
- public int IndexOf(Vector3 item)
- {
- throw new NotImplementedException();
- }
-
- public void Insert(int index, Vector3 item)
- {
- throw new NotSupportedException();
- }
-
- public Vector3 this[int index]
- {
- get
- {
- if ((uint)index >= (uint)Count)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- Vector3 value;
- btVector3_array_at(_native, index, out value);
- return value;
- }
- set
- {
- if ((uint)index >= (uint)Count)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- btVector3_array_set(_native, index, ref value);
- }
- }
-
- public void Add(Vector3 item)
- {
- throw new NotSupportedException();
- }
-
- public bool Contains(Vector3 item)
- {
- throw new NotImplementedException();
- }
-
- public void CopyTo(Vector3[] array, int arrayIndex)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
-
- if (arrayIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(array));
-
- int count = Count;
- if (arrayIndex + count > array.Length)
- throw new ArgumentException("Array too small.", "array");
-
- for (int i = 0; i < count; i++)
- {
- array[arrayIndex + i] = this[i];
- }
- }
-
- public bool Remove(Vector3 item)
- {
- throw new NotSupportedException();
- }
-
- public IEnumerator GetEnumerator()
- {
- return new Vector3ArrayEnumerator(this);
- }
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return new Vector3ArrayEnumerator(this);
- }
- }
}
diff --git a/BulletSharp/Math/Vector3Array.cs b/BulletSharp/Math/Vector3Array.cs
new file mode 100644
index 00000000..21c31f98
--- /dev/null
+++ b/BulletSharp/Math/Vector3Array.cs
@@ -0,0 +1,146 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using static BulletSharp.UnsafeNativeMethods;
+
+namespace BulletSharp.Math
+{
+ internal class Vector3ListDebugView
+ {
+ private IList _list;
+
+ public Vector3ListDebugView(IList list)
+ {
+ _list = list;
+ }
+
+ [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
+ public Vector3[] Items
+ {
+ get
+ {
+ var arr = new Vector3[_list.Count];
+ _list.CopyTo(arr, 0);
+ return arr;
+ }
+ }
+ };
+
+ public class Vector3ArrayEnumerator : IEnumerator
+ {
+ private int _i;
+ private int _count;
+ private IList _array;
+
+ public Vector3ArrayEnumerator(IList array)
+ {
+ _array = array;
+ _count = array.Count;
+ _i = -1;
+ }
+
+ public void Dispose()
+ {
+ }
+
+ public bool MoveNext()
+ {
+ _i++;
+ return _i != _count;
+ }
+
+ public void Reset()
+ {
+ _i = 0;
+ }
+
+ public Vector3 Current => _array[_i];
+
+ object System.Collections.IEnumerator.Current => _array[_i];
+ }
+
+ [DebuggerDisplay("Count = {Count}")]
+ [DebuggerTypeProxy(typeof(Vector3ListDebugView))]
+ public class Vector3Array : FixedSizeArray, IList
+ {
+ internal Vector3Array(IntPtr native, int count)
+ : base(native, count)
+ {
+ }
+
+ public int IndexOf(Vector3 item)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Insert(int index, Vector3 item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public Vector3 this[int index]
+ {
+ get
+ {
+ if ((uint)index >= (uint)Count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ Vector3 value;
+ btVector3_array_at(_native, index, out value);
+ return value;
+ }
+ set
+ {
+ if ((uint)index >= (uint)Count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ btVector3_array_set(_native, index, ref value);
+ }
+ }
+
+ public void Add(Vector3 item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public bool Contains(Vector3 item)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void CopyTo(Vector3[] array, int arrayIndex)
+ {
+ if (array == null)
+ throw new ArgumentNullException(nameof(array));
+
+ if (arrayIndex < 0)
+ throw new ArgumentOutOfRangeException(nameof(array));
+
+ int count = Count;
+ if (arrayIndex + count > array.Length)
+ throw new ArgumentException("Array too small.", "array");
+
+ for (int i = 0; i < count; i++)
+ {
+ array[arrayIndex + i] = this[i];
+ }
+ }
+
+ public bool Remove(Vector3 item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ return new Vector3ArrayEnumerator(this);
+ }
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return new Vector3ArrayEnumerator(this);
+ }
+ }
+}
diff --git a/BulletSharp/SoftBody/SoftBody.cs b/BulletSharp/SoftBody/SoftBody.cs
index a5c4d123..4e1bbd30 100644
--- a/BulletSharp/SoftBody/SoftBody.cs
+++ b/BulletSharp/SoftBody/SoftBody.cs
@@ -3234,7 +3234,7 @@ namespace BulletSharp.SoftBody
{
if (_clusterDbvt == null)
{
- _clusterDbvt = new Dbvt(btSoftBody_getCdbvt(Native), true);
+ _clusterDbvt = new Dbvt(btSoftBody_getCdbvt(Native));
}
return _clusterDbvt;
}
@@ -3294,7 +3294,7 @@ namespace BulletSharp.SoftBody
{
if (_faceDbvt == null)
{
- _faceDbvt = new Dbvt(btSoftBody_getFdbvt(Native), true);
+ _faceDbvt = new Dbvt(btSoftBody_getFdbvt(Native));
}
return _faceDbvt;
}
@@ -3353,7 +3353,7 @@ namespace BulletSharp.SoftBody
{
if (_nodeDbvt == null)
{
- _nodeDbvt = new Dbvt(btSoftBody_getNdbvt(Native), true);
+ _nodeDbvt = new Dbvt(btSoftBody_getNdbvt(Native));
}
return _nodeDbvt;
}
diff --git a/BulletSharp/UnsafeNativeMethods.cs b/BulletSharp/UnsafeNativeMethods.cs
index 1fa90b65..63c49326 100644
--- a/BulletSharp/UnsafeNativeMethods.cs
+++ b/BulletSharp/UnsafeNativeMethods.cs
@@ -295,7 +295,7 @@ namespace BulletSharp
public static extern int btAlignedObjectArray_btSoftBody_Tetra_size(IntPtr obj);
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
- public static extern IntPtr btSoftBodyNodePtrArray_at(IntPtr obj, int n);
+ public static extern IntPtr btSoftBodyNodePtrArray_at(IntPtr obj, int index);
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
public static extern IntPtr btSoftBodyNodePtrArray_set(IntPtr obj, IntPtr value, int index);
@@ -1214,7 +1214,7 @@ namespace BulletSharp
public static extern void btCompoundShapeChild_setTransform(IntPtr obj, [In] ref Matrix value);
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
- public static extern IntPtr btCompoundShapeChild_array_at(IntPtr obj, int n);
+ public static extern IntPtr btCompoundShapeChild_array_at(IntPtr obj, int index);
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
public static extern void btConcaveShape_processAllTriangles(IntPtr obj, IntPtr callback, [In] ref Vector3 aabbMin, [In] ref Vector3 aabbMax);
@@ -1861,6 +1861,11 @@ namespace BulletSharp
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
public static extern void btDbvtNode_setParent(IntPtr obj, IntPtr value);
+ [DllImport(Native.Dll, CallingConvention = Native.Conv)]
+ public static extern IntPtr btDbvtNodePtr_array_at(IntPtr obj, int index);
+ [DllImport(Native.Dll, CallingConvention = Native.Conv)]
+ public static extern int btDbvtNodePtr_array_index_of(IntPtr obj, IntPtr value, int length);
+
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
public static extern IntPtr btDbvtProxy_getLeaf(IntPtr obj);
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
@@ -1872,8 +1877,6 @@ namespace BulletSharp
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
public static extern void btDbvtProxy_setStage(IntPtr obj, int value);
- [DllImport(Native.Dll, CallingConvention = Native.Conv)]
- public static extern IntPtr btDbvt_new();
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
public static extern int btDbvt_allocate(IntPtr ifree, IntPtr stock, IntPtr value);
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
@@ -1946,10 +1949,13 @@ namespace BulletSharp
public static extern bool btDbvt_update6(IntPtr obj, IntPtr leaf, IntPtr volume, [In] ref Vector3 velocity, float margin);
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
public static extern void btDbvt_write(IntPtr obj, IntPtr iwriter);
- [DllImport(Native.Dll, CallingConvention = Native.Conv)]
- public static extern void btDbvt_delete(IntPtr obj);
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
+ public static extern IntPtr btDbvt_array_at(IntPtr obj, int index);
+ [DllImport(Native.Dll, CallingConvention = Native.Conv)]
+ public static extern int btDbvt_array_index_of(IntPtr obj, IntPtr value, int length);
+
+ [DllImport(Native.Dll, CallingConvention = Native.Conv)]
public static extern IntPtr btDbvtAabbMm_new();
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
public static extern void btDbvtAabbMm_Center(IntPtr obj, out Vector3 value);
@@ -7128,9 +7134,9 @@ namespace BulletSharp
public static extern void btUsageBitfield_setUsedVertexD(IntPtr obj, bool value);
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
- public static extern IntPtr btVector3_array_at(IntPtr obj, int n, [Out] out Vector3 value);
+ public static extern IntPtr btVector3_array_at(IntPtr obj, int index, [Out] out Vector3 value);
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
- public static extern IntPtr btVector3_array_set(IntPtr obj, int n, [In] ref Vector3 value);
+ public static extern IntPtr btVector3_array_set(IntPtr obj, int index, [In] ref Vector3 value);
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
public static extern IntPtr btVoronoiSimplexSolver_new();
diff --git a/BulletSharp/demos/DemoFramework/DebugInfo/DebugInfoForm.Designer.cs b/BulletSharp/demos/DemoFramework/DebugInfo/DebugInfoForm.Designer.cs
new file mode 100644
index 00000000..acd926b5
--- /dev/null
+++ b/BulletSharp/demos/DemoFramework/DebugInfo/DebugInfoForm.Designer.cs
@@ -0,0 +1,72 @@
+namespace DemoFramework.DebugInfo
+{
+ partial class DebugInfoForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.worldTree = new System.Windows.Forms.TreeView();
+ this.snapshotButton = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // worldTree
+ //
+ this.worldTree.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)));
+ this.worldTree.Location = new System.Drawing.Point(13, 42);
+ this.worldTree.Name = "worldTree";
+ this.worldTree.Size = new System.Drawing.Size(381, 416);
+ this.worldTree.TabIndex = 0;
+ //
+ // snapshotButton
+ //
+ this.snapshotButton.Location = new System.Drawing.Point(13, 13);
+ this.snapshotButton.Name = "snapshotButton";
+ this.snapshotButton.Size = new System.Drawing.Size(108, 23);
+ this.snapshotButton.TabIndex = 1;
+ this.snapshotButton.Text = "Take snapshot";
+ this.snapshotButton.UseVisualStyleBackColor = true;
+ this.snapshotButton.Click += new System.EventHandler(this.snapshotButton_Click);
+ //
+ // DebugInfoForm
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(625, 470);
+ this.Controls.Add(this.snapshotButton);
+ this.Controls.Add(this.worldTree);
+ this.Name = "DebugInfoForm";
+ this.Text = "Debug Info";
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.TreeView worldTree;
+ private System.Windows.Forms.Button snapshotButton;
+ }
+}
\ No newline at end of file
diff --git a/BulletSharp/demos/DemoFramework/DebugInfo/DebugInfoForm.cs b/BulletSharp/demos/DemoFramework/DebugInfo/DebugInfoForm.cs
new file mode 100644
index 00000000..e3cb4a9e
--- /dev/null
+++ b/BulletSharp/demos/DemoFramework/DebugInfo/DebugInfoForm.cs
@@ -0,0 +1,200 @@
+using BulletSharp;
+using System.Collections.Generic;
+using System.Windows.Forms;
+
+namespace DemoFramework.DebugInfo
+{
+ public partial class DebugInfoForm : Form
+ {
+ private readonly Demo _demo;
+
+ public DebugInfoForm(Demo demo)
+ {
+ _demo = demo;
+
+ InitializeComponent();
+
+ TakeSnapshot();
+ }
+
+ private void TakeSnapshot()
+ {
+ SetWorldTreeInfo();
+ }
+
+ private void SetWorldTreeInfo()
+ {
+ var world = _demo.Simulation.World;
+
+ TreeNode worldNode = GetOrCreateWorldNode(world);
+
+ SetCollisionObjectsInfo(world.CollisionObjectArray, worldNode);
+ SetBroadphaseInfo(world.Broadphase, worldNode);
+ }
+
+ private TreeNode GetOrCreateWorldNode(DiscreteDynamicsWorld world)
+ {
+ TreeNode worldNode;
+ if (worldTree.Nodes.Count == 1)
+ {
+ worldNode = worldTree.Nodes[0];
+ if (worldNode.Tag == world)
+ {
+ return worldNode;
+ }
+ worldTree.Nodes.Clear();
+ }
+ worldNode = worldTree.Nodes.Add(world.GetType().Name);
+ worldNode.Tag = world;
+ worldNode.Expand();
+ return worldNode;
+ }
+
+ private void SetCollisionObjectsInfo(IList collisionObjects, TreeNode worldNode)
+ {
+ TreeNode objectsNode = GetOrCreateChildNode("Objects", worldNode);
+
+ foreach (CollisionObject collisionObject in collisionObjects)
+ {
+ SetCollisionObjectInfo(collisionObject, objectsNode);
+ }
+
+ RemoveMissingObjects(collisionObjects, objectsNode);
+ }
+
+ private void SetCollisionObjectInfo(CollisionObject collisionObject, TreeNode objectsNode)
+ {
+ string objectName = collisionObject.GetType().Name;
+ CollisionShape shape = collisionObject.CollisionShape;
+ string shapeName = shape.GetType().Name;
+
+ string text = $"{objectName} ({shapeName})";
+ GetOrCreateChildNode(collisionObject, text, objectsNode);
+ }
+
+ private void SetBroadphaseInfo(BroadphaseInterface broadphase, TreeNode worldNode)
+ {
+ string text = broadphase.GetType().Name;
+ TreeNode broadphaseNode = GetOrCreateChildNode(broadphase, text, worldNode);
+
+ var dbvtBroadphase = broadphase as DbvtBroadphase;
+ if (dbvtBroadphase != null)
+ {
+ SetDbvtBroadphaseInfo(dbvtBroadphase, broadphaseNode);
+ }
+ }
+
+ private void SetDbvtBroadphaseInfo(DbvtBroadphase dbvtBroadphase, TreeNode broadphaseNode)
+ {
+ var sets = dbvtBroadphase.Sets;
+ Dbvt dynamicSet = sets[0];
+ Dbvt staticSet = sets[1];
+
+ TreeNode dynamicSetNode = GetOrCreateChildNode(dynamicSet, "Dynamic set", broadphaseNode);
+ SetDbvtInfo(dynamicSet, dynamicSetNode);
+
+ TreeNode staticSetNode = GetOrCreateChildNode(staticSet, "Static set", broadphaseNode);
+ SetDbvtInfo(staticSet, staticSetNode);
+
+ RemoveMissingObjects(sets, broadphaseNode);
+ }
+
+ private void SetDbvtInfo(Dbvt dbvtSet, TreeNode dbvtNode)
+ {
+ SetDbvtNodeInfo(dbvtSet.Root, dbvtNode);
+ }
+
+ private void SetDbvtNodeInfo(DbvtNode dbvtNode, TreeNode parentNode)
+ {
+ if (dbvtNode == null)
+ {
+ return;
+ }
+
+ string text = dbvtNode.GetType().Name + " " + dbvtNode.Data;
+ TreeNode dbvtNodeNode = GetOrCreateChildNode(dbvtNode, text, parentNode);
+
+ foreach (DbvtNode child in dbvtNode.Childs)
+ {
+ SetDbvtNodeInfo(child, dbvtNodeNode);
+ }
+
+ RemoveMissingObjects(dbvtNode.Childs, dbvtNodeNode);
+ }
+
+ private void snapshotButton_Click(object sender, System.EventArgs e)
+ {
+ TakeSnapshot();
+ }
+
+ private TreeNode GetOrCreateChildNode(object tag, string text, TreeNode parent)
+ {
+ TreeNode child = FindChildByTag(parent, tag);
+ if (child == null)
+ {
+ child = parent.Nodes.Add(text);
+ child.Tag = tag;
+ }
+ else
+ {
+ child.Text = text;
+ }
+ return child;
+ }
+
+ private TreeNode GetOrCreateChildNode(string text, TreeNode parent)
+ {
+ TreeNode child = FindChildByText(parent, text);
+ if (child == null)
+ {
+ child = parent.Nodes.Add(text);
+ }
+ else
+ {
+ child.Text = text;
+ }
+ return child;
+ }
+
+ private TreeNode FindChildByText(TreeNode parent, string text)
+ {
+ foreach (TreeNode node in parent.Nodes)
+ {
+ if (node.Text == text)
+ {
+ return node;
+ }
+ }
+ return null;
+ }
+
+ private TreeNode FindChildByTag(TreeNode parent, object tag)
+ {
+ foreach (TreeNode node in parent.Nodes)
+ {
+ if (Equals(node.Tag, tag))
+ {
+ return node;
+ }
+ }
+ return null;
+ }
+
+ private void RemoveMissingObjects(ICollection collection, TreeNode parentNode) where T : class
+ {
+ IList nodesToRemove = new List();
+ foreach (TreeNode objectNode in parentNode.Nodes)
+ {
+ if (!collection.Contains(objectNode.Tag as T))
+ {
+ nodesToRemove.Add(objectNode);
+ }
+ }
+
+ foreach (TreeNode node in nodesToRemove)
+ {
+ parentNode.Nodes.Remove(node);
+ }
+ }
+ }
+}
diff --git a/BulletSharp/demos/DemoFramework/DebugInfo/DebugInfoForm.resx b/BulletSharp/demos/DemoFramework/DebugInfo/DebugInfoForm.resx
new file mode 100644
index 00000000..29dcb1b3
--- /dev/null
+++ b/BulletSharp/demos/DemoFramework/DebugInfo/DebugInfoForm.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/BulletSharp/demos/DemoFramework/Demo.cs b/BulletSharp/demos/DemoFramework/Demo.cs
index d13c556e..84c4d127 100644
--- a/BulletSharp/demos/DemoFramework/Demo.cs
+++ b/BulletSharp/demos/DemoFramework/Demo.cs
@@ -1,5 +1,6 @@
using BulletSharp;
using BulletSharp.Math;
+using DemoFramework.DebugInfo;
using System;
using System.Drawing;
using System.Globalization;
@@ -267,6 +268,10 @@ namespace DemoFramework
case Keys.F3:
IsDebugDrawEnabled = !IsDebugDrawEnabled;
break;
+ case Keys.F5:
+ var debugForm = new DebugInfoForm(this);
+ debugForm.Show();
+ break;
case Keys.F8:
Input.ClearKeyCache();
GraphicsLibraryManager.ExitWithReload = true;
diff --git a/BulletSharp/demos/DemoFramework/DemoFramework.csproj b/BulletSharp/demos/DemoFramework/DemoFramework.csproj
index 2c0c8fcb..1303da54 100644
--- a/BulletSharp/demos/DemoFramework/DemoFramework.csproj
+++ b/BulletSharp/demos/DemoFramework/DemoFramework.csproj
@@ -76,11 +76,18 @@
..\..\bin\Release\BulletSharp.dll
+
+
+ Form
+
+
+ DebugInfoForm.cs
+
@@ -115,6 +122,9 @@
+
+ DebugInfoForm.cs
+
LibrarySelection.cs
Designer
diff --git a/BulletSharp/demos/DemoFramework/Simulation/BodyPicker.cs b/BulletSharp/demos/DemoFramework/Simulation/BodyPicker.cs
index 7e7993aa..776215e4 100644
--- a/BulletSharp/demos/DemoFramework/Simulation/BodyPicker.cs
+++ b/BulletSharp/demos/DemoFramework/Simulation/BodyPicker.cs
@@ -1,5 +1,4 @@
-using System;
-using BulletSharp;
+using BulletSharp;
using System.Windows.Forms;
using BulletSharp.Math;
diff --git a/libbulletc/src/btDbvt_wrap.cpp b/libbulletc/src/btDbvt_wrap.cpp
index 78414770..edacfbcb 100644
--- a/libbulletc/src/btDbvt_wrap.cpp
+++ b/libbulletc/src/btDbvt_wrap.cpp
@@ -402,11 +402,6 @@ void btDbvt_sStkNPS_delete(btDbvt_sStkNPS* obj)
}
-btDbvt* btDbvt_new()
-{
- return new btDbvt();
-}
-
int btDbvt_allocate(btAlignedObjectArray_int* ifree, btAlignedObjectArray_btDbvt_sStkNPS* stock,
const btDbvt_sStkNPS* value)
{
@@ -656,7 +651,38 @@ void btDbvt_write(btDbvt* obj, btDbvt_IWriter* iwriter)
obj->write(iwriter);
}
-void btDbvt_delete(btDbvt* obj)
+
+btDbvt* btDbvt_array_at(btDbvt* obj, int index)
{
- delete obj;
+ return &obj[index];
+}
+
+int btDbvt_array_index_of(btDbvt* obj, btDbvt* value, int length)
+{
+ for (int i = 0; i < length; i++)
+ {
+ if (&obj[i] == value)
+ {
+ return i;
+ }
+ }
+ return -1;
+}
+
+
+btDbvtNode* btDbvtNodePtr_array_at(btDbvtNode** obj, int index)
+{
+ return obj[index];
+}
+
+int btDbvtNodePtr_array_index_of(btDbvtNode** obj, btDbvtNode* value, int length)
+{
+ for (int i = 0; i < length; i++)
+ {
+ if (obj[i] == value)
+ {
+ return i;
+ }
+ }
+ return -1;
}
diff --git a/libbulletc/src/btDbvt_wrap.h b/libbulletc/src/btDbvt_wrap.h
index d8d14f3c..77bee1f8 100644
--- a/libbulletc/src/btDbvt_wrap.h
+++ b/libbulletc/src/btDbvt_wrap.h
@@ -85,7 +85,6 @@ extern "C" {
EXPORT void btDbvt_sStkNPS_setValue(btDbvt_sStkNPS* obj, btScalar value);
EXPORT void btDbvt_sStkNPS_delete(btDbvt_sStkNPS* obj);
- EXPORT btDbvt* btDbvt_new();
EXPORT int btDbvt_allocate(btAlignedObjectArray_int* ifree, btAlignedObjectArray_btDbvt_sStkNPS* stock, const btDbvt_sStkNPS* value);
EXPORT void btDbvt_benchmark();
EXPORT void btDbvt_clear(btDbvt* obj);
@@ -131,7 +130,12 @@ extern "C" {
EXPORT bool btDbvt_update5(btDbvt* obj, btDbvtNode* leaf, btDbvtVolume* volume, const btVector3* velocity);
EXPORT bool btDbvt_update6(btDbvt* obj, btDbvtNode* leaf, btDbvtVolume* volume, const btVector3* velocity, btScalar margin);
EXPORT void btDbvt_write(btDbvt* obj, btDbvt_IWriter* iwriter);
- EXPORT void btDbvt_delete(btDbvt* obj);
+
+ EXPORT btDbvt* btDbvt_array_at(btDbvt* obj, int index);
+ EXPORT int btDbvt_array_index_of(btDbvt* obj, btDbvt* value, int length);
+
+ EXPORT btDbvtNode* btDbvtNodePtr_array_at(btDbvtNode** obj, int index);
+ EXPORT int btDbvtNodePtr_array_index_of(btDbvtNode** obj, btDbvtNode* value, int length);
#ifdef __cplusplus
}
#endif