Implement AlignedCollisionObjectArray.IndexOf and Contains
This commit is contained in:
Родитель
ff1bc63ba1
Коммит
5cd77c5062
|
@ -85,7 +85,7 @@ namespace BulletSharp
|
|||
|
||||
public int IndexOf(CollisionObject item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return btAlignedObjectArray_btCollisionObjectPtr_findLinearSearch2(_native, item.Native);
|
||||
}
|
||||
|
||||
public void Insert(int index, CollisionObject item)
|
||||
|
@ -180,8 +180,7 @@ namespace BulletSharp
|
|||
|
||||
public bool Contains(CollisionObject item)
|
||||
{
|
||||
//return btAlignedObjectArray_btCollisionObjectPtr_findLinearSearch(_native, item._native) != Count;
|
||||
throw new NotImplementedException();
|
||||
return IndexOf(item) != -1;
|
||||
}
|
||||
|
||||
public void CopyTo(CollisionObject[] array, int arrayIndex)
|
||||
|
|
|
@ -161,6 +161,8 @@ namespace BulletSharp
|
|||
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
|
||||
public static extern IntPtr btAlignedObjectArray_btCollisionObjectPtr_at(IntPtr obj, int n);
|
||||
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
|
||||
public static extern int btAlignedObjectArray_btCollisionObjectPtr_findLinearSearch2(IntPtr obj, IntPtr key);
|
||||
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
|
||||
public static extern void btAlignedObjectArray_btCollisionObjectPtr_push_back(IntPtr obj, IntPtr val);
|
||||
[DllImport(Native.Dll, CallingConvention = Native.Conv)]
|
||||
public static extern void btAlignedObjectArray_btCollisionObjectPtr_resizeNoInitialize(IntPtr obj, int newSize);
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
using BulletSharp;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace BulletSharpTest
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("AlignedObjectArray")]
|
||||
class AlignedCollisionObjectArrayTests
|
||||
{
|
||||
private DefaultCollisionConfiguration _conf;
|
||||
private CollisionDispatcher _dispatcher;
|
||||
private DbvtBroadphase _broadphase;
|
||||
private SequentialImpulseConstraintSolver _solver;
|
||||
private DiscreteDynamicsWorld _world;
|
||||
private CollisionShape _shape;
|
||||
private RigidBody _body1;
|
||||
private RigidBody _body2;
|
||||
|
||||
[Test]
|
||||
public void AlignedCollisionObjectArrayTest()
|
||||
{
|
||||
var worldArray = _world.CollisionObjectArray;
|
||||
Assert.IsEmpty(worldArray);
|
||||
|
||||
_world.AddRigidBody(_body1);
|
||||
_world.AddRigidBody(_body2);
|
||||
Assert.That(worldArray, Has.Count.EqualTo(2));
|
||||
Assert.AreEqual(2, _world.NumCollisionObjects);
|
||||
|
||||
Assert.True(worldArray.Contains(_body1));
|
||||
Assert.True(worldArray.Contains(_body2));
|
||||
|
||||
Assert.AreEqual(0, worldArray.IndexOf(_body1));
|
||||
Assert.AreEqual(1, worldArray.IndexOf(_body2));
|
||||
|
||||
_world.RemoveRigidBody(_body1);
|
||||
Assert.That(worldArray, Has.Count.EqualTo(1));
|
||||
Assert.AreEqual(1, _world.NumCollisionObjects);
|
||||
|
||||
_world.RemoveRigidBody(_body1);
|
||||
Assert.That(worldArray, Has.Count.EqualTo(1));
|
||||
Assert.AreEqual(1, _world.NumCollisionObjects);
|
||||
|
||||
worldArray.Remove(_body2);
|
||||
Assert.AreEqual(0, _world.NumCollisionObjects);
|
||||
|
||||
_world.AddRigidBody(_body1);
|
||||
_world.AddRigidBody(_body2);
|
||||
worldArray.Clear();
|
||||
Assert.AreEqual(0, _world.NumCollisionObjects);
|
||||
}
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_conf = new DefaultCollisionConfiguration();
|
||||
_dispatcher = new CollisionDispatcher(_conf);
|
||||
_broadphase = new DbvtBroadphase();
|
||||
_solver = new SequentialImpulseConstraintSolver();
|
||||
_world = new DiscreteDynamicsWorld(_dispatcher, _broadphase, _solver, _conf);
|
||||
|
||||
_shape = new BoxShape(1);
|
||||
using (var bodyInfo = new RigidBodyConstructionInfo(1, null, _shape))
|
||||
{
|
||||
_body1 = new RigidBody(bodyInfo);
|
||||
_body2 = new RigidBody(bodyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_world.Dispose();
|
||||
_solver.Dispose();
|
||||
_broadphase.Dispose();
|
||||
_dispatcher.Dispose();
|
||||
_conf.Dispose();
|
||||
|
||||
_shape.Dispose();
|
||||
_body1.Dispose();
|
||||
_body2.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -59,6 +59,7 @@
|
|||
<Reference Include="System.Drawing" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AlignedCollisionObjectArrayTests.cs" />
|
||||
<Compile Include="ContactSensorCallback.cs" />
|
||||
<Compile Include="DebugDrawTest.cs" />
|
||||
<Compile Include="DebugDrawTest2.cs" />
|
||||
|
|
|
@ -32,6 +32,11 @@ btCollisionObject* btAlignedObjectArray_btCollisionObjectPtr_at(btAlignedObjectA
|
|||
return obj->at(n);
|
||||
}
|
||||
|
||||
int btAlignedObjectArray_btCollisionObjectPtr_findLinearSearch2(btAlignedObjectArray_btCollisionObjectPtr* obj, btCollisionObject* key)
|
||||
{
|
||||
return obj->findLinearSearch2(key);
|
||||
}
|
||||
|
||||
void btAlignedObjectArray_btCollisionObjectPtr_push_back(btAlignedObjectArray_btCollisionObjectPtr* obj, btCollisionObject* val)
|
||||
{
|
||||
obj->push_back(val);
|
||||
|
|
|
@ -9,6 +9,7 @@ extern "C" {
|
|||
EXPORT int btAlignedObjectArray_btBroadphasePair_size(btAlignedObjectArray_btBroadphasePair* obj);
|
||||
|
||||
EXPORT btCollisionObject* btAlignedObjectArray_btCollisionObjectPtr_at(btAlignedObjectArray_btCollisionObjectPtr* obj, int n);
|
||||
EXPORT int btAlignedObjectArray_btCollisionObjectPtr_findLinearSearch2(btAlignedObjectArray_btCollisionObjectPtr* obj, btCollisionObject* key);
|
||||
EXPORT void btAlignedObjectArray_btCollisionObjectPtr_push_back(btAlignedObjectArray_btCollisionObjectPtr* obj, btCollisionObject* val);
|
||||
EXPORT void btAlignedObjectArray_btCollisionObjectPtr_resizeNoInitialize(btAlignedObjectArray_btCollisionObjectPtr* obj, int newSize);
|
||||
EXPORT int btAlignedObjectArray_btCollisionObjectPtr_size(btAlignedObjectArray_btCollisionObjectPtr* obj);
|
||||
|
|
Загрузка…
Ссылка в новой задаче