mirror of
git://opensimulator.org/git/opensim-libs
synced 2026-08-14 00:58:00 +00:00
* Re-committing Bullet w/libbulletnet
git-svn-id: file:///var/svn/opensim-libs@95 7c4940e8-6ff7-4914-b775-378afef7cd2e
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
|
||||
Bullet Physics Library is an open source project with help from the community at the Physics Forum
|
||||
See the forum at http://bulletphysics.com
|
||||
|
||||
The project was started by Erwin Coumans
|
||||
|
||||
Following people contributed to Bullet
|
||||
(random order, please let us know on the forum if your name should be in this list)
|
||||
|
||||
Gino van den Bergen: LinearMath classes
|
||||
Christer Ericson: parts of the voronoi simplex solver
|
||||
Simon Hobbs: 3d axis sweep and prune, Extras/SATCollision, separating axis theorem + SIMD code
|
||||
Dirk Gregorius: generic D6 constraint
|
||||
Erin Catto: accumulated impulse in sequential impulse
|
||||
Nathanael Presson: EPA penetration depth calculation
|
||||
Francisco Leon: GIMPACT Concave Concave collision
|
||||
Joerg Henrichs: make buildsystem (work in progress)
|
||||
Eric Sunshine: jam + msvcgen buildsystem
|
||||
Steve Baker: GPU physics and general implementation improvements
|
||||
Jay Lee: Double precision support
|
||||
KleMiX, aka Vsevolod Klementjev, managed version, rewritten in C# for XNA
|
||||
Erwin Coumans: most other source code
|
||||
Binary file not shown.
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{B8BA2397-1342-4CF8-91A6-07B2480BF00D}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>BulletConsoleTest</RootNamespace>
|
||||
<AssemblyName>BulletConsoleTest</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BulletDotNET\BulletDotNET.csproj">
|
||||
<Project>{F969D6F1-1B88-489E-A04C-5DCEF5E7BD92}</Project>
|
||||
<Name>BulletDotNET</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,162 @@
|
||||
using System;
|
||||
using BulletDotNET;
|
||||
|
||||
|
||||
namespace BulletConsoleTest
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
btVector3 testvec = new btVector3(-2, 1, 0);
|
||||
Console.WriteLine(String.Format("Original: {0}", testvec.testStr()));
|
||||
btVector3 testvec2 = testvec.absolute();
|
||||
Console.WriteLine(String.Format("absolute: {0}", testvec2.testStr()));
|
||||
Console.WriteLine(String.Format("angle:{0}", testvec.angle(testvec2)));
|
||||
Console.WriteLine(String.Format("closestAxis(orig):{0}", testvec.closestAxis()));
|
||||
btVector3 testvec3 = testvec.cross(testvec2);
|
||||
Console.WriteLine(String.Format("cross: {0}", testvec3.testStr()));
|
||||
Console.WriteLine(String.Format("distance: {0}", testvec.distance(testvec2)));
|
||||
Console.WriteLine(String.Format("distance2: {0}", testvec.distance2(testvec2)));
|
||||
Console.WriteLine(String.Format("dot: {0}", testvec.dot(testvec2)));
|
||||
Console.WriteLine(String.Format("furthestAxis(orig): {0}", testvec.furthestAxis()));
|
||||
btVector3 testvec4 = testvec.normalized();
|
||||
Console.WriteLine(String.Format("normalized: {0}", testvec4.testStr()));
|
||||
testvec4.setInterpolate3(testvec, testvec2, 0.5f);
|
||||
Console.WriteLine(String.Format("interpolate3: {0}", testvec4.testStr()));
|
||||
testvec4.setValue(7f, -0.09f, 2.5f);
|
||||
Console.WriteLine(String.Format("setvec: {0}", testvec4.testStr()));
|
||||
testvec4.setX(5.0f);
|
||||
testvec4.setY(-0.25f);
|
||||
testvec4.setZ(90f);
|
||||
testvec.setValue(0, 0, -1024);
|
||||
testvec2.setValue(256, 256, 1024);
|
||||
Console.WriteLine(String.Format("setvecIndividual: {0}", testvec4.testStr()));
|
||||
btAxisSweep3 testbtAxisSweep3 = new btAxisSweep3(testvec, testvec2, 50);
|
||||
btDefaultCollisionConfiguration colconfig = new btDefaultCollisionConfiguration();
|
||||
btCollisionDispatcher coldisp = new btCollisionDispatcher(colconfig);
|
||||
btSequentialImpulseConstraintSolver seqimpconssol = new btSequentialImpulseConstraintSolver();
|
||||
btDiscreteDynamicsWorld dynamicsWorld = new btDiscreteDynamicsWorld(coldisp, testbtAxisSweep3, seqimpconssol,
|
||||
colconfig);
|
||||
dynamicsWorld.setGravity(new btVector3(0, 0, -9.87f));
|
||||
Console.WriteLine(String.Format("stepWorld: {0}", dynamicsWorld.stepSimulation((6f / 60), 5, (1f / 60))));
|
||||
Console.WriteLine(String.Format("stepWorld: {0}", dynamicsWorld.stepSimulation((6f / 60), 5, (1f / 60))));
|
||||
Console.WriteLine(String.Format("stepWorld: {0}", dynamicsWorld.stepSimulation((6f / 60), 5, (1f / 60))));
|
||||
Console.WriteLine(String.Format("stepWorld: {0}", dynamicsWorld.stepSimulation((6f / 60), 5, (1f / 60))));
|
||||
btQuaternion testquat = new btQuaternion(50, 0, 0, 1);
|
||||
btQuaternion testquatnorm = testquat.normalized();
|
||||
Console.WriteLine(String.Format("testquat: {0}", testquat.testStr()));
|
||||
Console.WriteLine(String.Format("testquatnormalize: {0}", testquatnorm.testStr()));
|
||||
Console.WriteLine(String.Format("testquatLength: {0}", testquat.length()));
|
||||
Console.WriteLine(String.Format("testquatnormalizeLength: {0}", testquatnorm.length()));
|
||||
|
||||
float[] heightdata = new float[256*256];
|
||||
for (int j=0;j<256*256;j++)
|
||||
{
|
||||
if (j%2==0)
|
||||
heightdata[j] = 21f;
|
||||
else
|
||||
heightdata[j] = 28f;
|
||||
|
||||
}
|
||||
|
||||
btHeightfieldTerrainShape obj = new btHeightfieldTerrainShape(256, 256, heightdata, 1.0f, 0, 256,
|
||||
(int)btHeightfieldTerrainShape.UPAxis.Z,
|
||||
(int)btHeightfieldTerrainShape.PHY_ScalarType.
|
||||
PHY_FLOAT, false);
|
||||
|
||||
btCapsuleShape cap = new btCapsuleShape(0.23f, 3);
|
||||
|
||||
btTriangleMesh testMesh = new btTriangleMesh(true, false);
|
||||
testMesh.addTriangle(new btVector3(1, 0, 1), new btVector3(1, 0, -1), new btVector3(-1, 0, -1), false);
|
||||
testMesh.addTriangle(new btVector3(1, -1, 1), new btVector3(1, -1, -1), new btVector3(-1, -1, -1), false);
|
||||
testMesh.addTriangle(new btVector3(1, -1, 1), new btVector3(1, 0, 1), new btVector3(-1, -1, -1), false);
|
||||
testMesh.addTriangle(new btVector3(1, 0, 1), new btVector3(1, -1, -1), new btVector3(-1, 0, -1), false);
|
||||
testMesh.addTriangle(new btVector3(1, -1, -1), new btVector3(-1, 0, -1), new btVector3(-1, -1, -1), false);
|
||||
testMesh.addTriangle(new btVector3(1, -1, -1), new btVector3(1, 0, -1), new btVector3(-1, 0, -1), false);
|
||||
testMesh.addTriangle(new btVector3(1, 0, 1), new btVector3(1, -1, -1), new btVector3(1, 0, -1), false);
|
||||
testMesh.addTriangle(new btVector3(1, -1, 1), new btVector3(1, -1, -1), new btVector3(1, 0, 1), false);
|
||||
btGImpactMeshShape meshtest = new btGImpactMeshShape(testMesh);
|
||||
meshtest.updateBound();
|
||||
|
||||
btRigidBody groundbody = new btRigidBody(0,
|
||||
new btDefaultMotionState(
|
||||
new btTransform(new btQuaternion(0, 0, 0, 1),
|
||||
new btVector3(128, 128, 256f / 2f))), obj,
|
||||
new btVector3(0, 0, 0));
|
||||
|
||||
btRigidBody capbody = new btRigidBody(200,
|
||||
new btDefaultMotionState(
|
||||
new btTransform(new btQuaternion(0, 0, 0, 1),
|
||||
new btVector3(128, 128, 25))), cap,
|
||||
new btVector3(0, 0, 0));
|
||||
|
||||
btRigidBody meshbody = new btRigidBody(200,
|
||||
new btDefaultMotionState(
|
||||
new btTransform(new btQuaternion(0, 0, 0, 1),
|
||||
new btVector3(128, 128, 29))), meshtest,
|
||||
new btVector3(0, 0, 0));
|
||||
|
||||
|
||||
btRigidBodyConstructionInfo constructioninfotest = new btRigidBodyConstructionInfo();
|
||||
constructioninfotest.m_collisionShape = new btBoxShape(new btVector3(0.5f,0.5f,0.5f));
|
||||
constructioninfotest.m_localInertia = new btVector3(0, 0, 0);
|
||||
constructioninfotest.m_motionState = new btDefaultMotionState(new btTransform(new btQuaternion(0.3f, -0.4f, 0.8f, 0.1f), new btVector3(128.5f, 128, 25)),
|
||||
new btTransform(new btQuaternion(0,0,0,1),new btVector3(0,0.25f,0)));
|
||||
constructioninfotest.m_startWorldTransform = new btTransform(new btQuaternion(0,0,0,1),new btVector3(0,0,0));
|
||||
constructioninfotest.m_mass = 2000000;
|
||||
constructioninfotest.m_linearDamping = 0;
|
||||
constructioninfotest.m_angularDamping = 0;
|
||||
constructioninfotest.m_friction = 0.1f;
|
||||
constructioninfotest.m_restitution = 0;
|
||||
constructioninfotest.m_linearSleepingThreshold = 0.8f;
|
||||
constructioninfotest.m_angularSleepingThreshold = 1;
|
||||
constructioninfotest.m_additionalDamping = false;
|
||||
constructioninfotest.m_additionalDampingFactor = 0.005f;
|
||||
constructioninfotest.m_additionalLinearDampingThresholdSqr = 0.01f;
|
||||
constructioninfotest.m_additionalAngularDampingThresholdSqr = 0.01f;
|
||||
constructioninfotest.m_additionalAngularDampingFactor = 0.01f;
|
||||
constructioninfotest.commit();
|
||||
btGImpactCollisionAlgorithm.registerAlgorithm(coldisp);
|
||||
btRigidBody cubetest = new btRigidBody(constructioninfotest);
|
||||
|
||||
dynamicsWorld.addRigidBody(groundbody);
|
||||
dynamicsWorld.addRigidBody(cubetest);
|
||||
dynamicsWorld.addRigidBody(capbody);
|
||||
dynamicsWorld.addRigidBody(meshbody);
|
||||
|
||||
int frame = 0;
|
||||
for (int i = 0; i < 26; i++ )
|
||||
{
|
||||
int frames = dynamicsWorld.stepSimulation(((i%60) / 60f), 10, (1f / 60));
|
||||
frame += frames;
|
||||
Console.WriteLine(String.Format("Cube: frame {0} frames: {1} POS:{2}, quat:{3}", frame, frames, cubetest.getInterpolationWorldTransform().getOrigin().testStr(), cubetest.getWorldTransform().getRotation().testStr()));
|
||||
Console.WriteLine(String.Format("Cap: frame {0} frames: {1} POS:{2}, quat:{3}", frame, frames, capbody.getInterpolationWorldTransform().getOrigin().testStr(), capbody.getWorldTransform().getRotation().testStr()));
|
||||
Console.WriteLine(String.Format("Mesh: frame {0} frames: {1} POS:{2}, quat:{3}", frame, frames, meshbody.getInterpolationWorldTransform().getOrigin().testStr(), meshbody.getWorldTransform().getRotation().testStr()));
|
||||
|
||||
}
|
||||
|
||||
dynamicsWorld.removeRigidBody(meshbody);
|
||||
dynamicsWorld.removeRigidBody(capbody);
|
||||
dynamicsWorld.removeRigidBody(cubetest);
|
||||
dynamicsWorld.removeRigidBody(groundbody);
|
||||
cubetest.Dispose();
|
||||
groundbody.Dispose();
|
||||
capbody.Dispose();
|
||||
cap.Dispose();
|
||||
obj.Dispose();
|
||||
testbtAxisSweep3.Dispose();
|
||||
dynamicsWorld.Dispose();
|
||||
coldisp.Dispose();
|
||||
colconfig.Dispose();
|
||||
seqimpconssol.Dispose();
|
||||
|
||||
|
||||
testvec.Dispose();
|
||||
testvec2.Dispose();
|
||||
testvec3.Dispose();
|
||||
testvec4.Dispose();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("BulletConsoleTest")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("BulletConsoleTest")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2009")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("a4b7bc75-fd33-4385-a0e6-92d3d99b6bec")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{F969D6F1-1B88-489E-A04C-5DCEF5E7BD92}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>BulletDotNET</RootNamespace>
|
||||
<AssemblyName>BulletDotNET</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="bulletCollision\btAxisSweep3.cs" />
|
||||
<Compile Include="bulletCollision\btBroadphaseInterface.cs" />
|
||||
<Compile Include="bulletCollision\btRayResultCallback.cs" />
|
||||
<Compile Include="bulletCollision\ClosestNotMeRayResultCallback.cs" />
|
||||
<Compile Include="bulletCollision\CollisionShapes\btBoxShape.cs" />
|
||||
<Compile Include="bulletCollision\CollisionShapes\btCapsuleShape.cs" />
|
||||
<Compile Include="bulletCollision\btCollisionConfiguration.cs" />
|
||||
<Compile Include="bulletCollision\btCollisionDispatcher.cs" />
|
||||
<Compile Include="bulletCollision\btCollisionObject.cs" />
|
||||
<Compile Include="bulletCollision\btCollisionShape.cs" />
|
||||
<Compile Include="bulletCollision\CollisionShapes\btGImpactCollisionAlgorithm.cs" />
|
||||
<Compile Include="bulletCollision\CollisionShapes\btGImpactMeshShape.cs" />
|
||||
<Compile Include="bulletCollision\CollisionShapes\btSphereShape.cs" />
|
||||
<Compile Include="bulletCollision\CollisionShapes\btStridingMeshInterface.cs" />
|
||||
<Compile Include="bulletCollision\CollisionShapes\btTriangleIndexVertexArray.cs" />
|
||||
<Compile Include="bulletCollision\CollisionShapes\btTriangleMesh.cs" />
|
||||
<Compile Include="bulletDynamics\btCollisionWorld.cs" />
|
||||
<Compile Include="bulletDynamics\btConstraintInfo2.cs" />
|
||||
<Compile Include="bulletDynamics\btConstraintSolver.cs" />
|
||||
<Compile Include="bulletCollision\btDefaultCollisionConfiguration.cs" />
|
||||
<Compile Include="bulletDynamics\btDefaultMotionState.cs" />
|
||||
<Compile Include="bulletDynamics\btDiscreteDynamicsWorld.cs" />
|
||||
<Compile Include="bulletCollision\btDispatcher.cs" />
|
||||
<Compile Include="bulletDynamics\btGeneric6DofConstraint.cs" />
|
||||
<Compile Include="bulletCollision\btGhostObject.cs" />
|
||||
<Compile Include="bulletCollision\btHeightfieldTerrainShape.cs" />
|
||||
<Compile Include="bulletMath\btMatrix3x3.cs" />
|
||||
<Compile Include="bulletDynamics\btMotionState.cs" />
|
||||
<Compile Include="bulletCollision\btPairCachingGhostObject.cs" />
|
||||
<Compile Include="bulletMath\btQuaternion.cs" />
|
||||
<Compile Include="bulletDynamics\btRigidBody.cs" />
|
||||
<Compile Include="bulletDynamics\btRigidBodyConstructionInfo.cs" />
|
||||
<Compile Include="bulletDynamics\btSequentialImpulseConstraintSolver.cs" />
|
||||
<Compile Include="bulletMath\btTransform.cs" />
|
||||
<Compile Include="bulletDynamics\btTypedConstraint.cs" />
|
||||
<Compile Include="bulletMath\btVector3.cs" />
|
||||
<Compile Include="Native.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public static class Native
|
||||
{
|
||||
public const string Dll = "libbulletnet";
|
||||
|
||||
public static object GetObject(IntPtr raw, Type t)
|
||||
{
|
||||
if (raw == IntPtr.Zero)
|
||||
throw new InvalidOperationException();
|
||||
object o;
|
||||
|
||||
try
|
||||
{
|
||||
o = Activator.CreateInstance(t, raw);
|
||||
}
|
||||
catch (TypeLoadException)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("BulletDotNET")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("BulletDotNET")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2009")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("d54a5c1c-3a54-4a8a-a14d-88ebba9ce706")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class ClosestNotMeRayResultCallback : btRayResultCallback, IDisposable
|
||||
{
|
||||
|
||||
public static ClosestNotMeRayResultCallback FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (ClosestNotMeRayResultCallback)Native.GetObject(handle,
|
||||
typeof(ClosestNotMeRayResultCallback));
|
||||
}
|
||||
|
||||
public ClosestNotMeRayResultCallback(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public ClosestNotMeRayResultCallback(btRigidBody body)
|
||||
{
|
||||
m_handle = BulletHelper_CreateClosestNotMeRaycastResultCallback(body.Handle);
|
||||
}
|
||||
|
||||
public bool hasHit()
|
||||
{
|
||||
return BulletHelper_ClosestNotMeRaycastResultCallback_hasHit(m_handle);
|
||||
}
|
||||
|
||||
public btVector3 getHitPointWorld()
|
||||
{
|
||||
IntPtr resultHandle = BulletHelper_ClosestNotMeRaycastResultCallback_getHitPointWorld(m_handle);
|
||||
if (resultHandle != IntPtr.Zero)
|
||||
return btVector3.FromIntPtr(resultHandle);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
#region NativeInvokes
|
||||
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletHelper_CreateClosestNotMeRaycastResultCallback(IntPtr body);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletHelper_ClosestNotMeRaycastResultCallback_hasHit(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletHelper_ClosestNotMeRaycastResultCallback_getHitPointWorld(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletHelper_ClosestNotMeRaycastResultCallback_delete(IntPtr handle);
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletHelper_ClosestNotMeRaycastResultCallback_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~ClosestNotMeRayResultCallback()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btBoxShape : btCollisionShape, IDisposable
|
||||
{
|
||||
public static new btBoxShape FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btBoxShape)Native.GetObject(handle, typeof(btBoxShape));
|
||||
}
|
||||
|
||||
public btBoxShape(IntPtr handle)
|
||||
: base(handle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btBoxShape(btVector3 boxHalfExtents)
|
||||
: base()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtBoxShape(boxHalfExtents.Handle);
|
||||
}
|
||||
|
||||
public btVector3 getHalfExtentsWithMargin()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtBoxShape_getHalfExtentsWithMargin(m_handle));
|
||||
}
|
||||
|
||||
public btVector3 getHalfExtentsWithoutMargin()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtBoxShape_getHalfExtentsWithoutMargin(m_handle));
|
||||
}
|
||||
|
||||
public static int getNumPlanes()
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
|
||||
public static int getNumVerticies()
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
public static int getNumEdges()
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
|
||||
public btVector3 getVertex(int i)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtBoxShape_getVertex(m_handle, i));
|
||||
}
|
||||
|
||||
public bool isInside(btVector3 pt, float tolerance)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtBoxShape_isInside(m_handle, pt.Handle, tolerance);
|
||||
}
|
||||
|
||||
public void setMargins(float collisionMargin)
|
||||
{
|
||||
BulletAPI_BtBoxShape_setMargins(m_handle,collisionMargin);
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtBoxShape(IntPtr boxHalfExtents);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtBoxShape_getHalfExtentsWithMargin(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtBoxShape_getHalfExtentsWithoutMargin(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtBoxShape_getVertex(IntPtr handle, int i);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtBoxShape_isInside(IntPtr handle, IntPtr pt, float tolerance);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtBoxShape_setLocalScaling(IntPtr handle, IntPtr scaling);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtBoxShape_setMargins(IntPtr handle, float collisionMargin);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtBoxShape_delete(IntPtr handle);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual new void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
base.Dispose();
|
||||
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
//BulletAPI_BtRigidBody_delete(m_handle);
|
||||
//m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btBoxShape()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btCapsuleShape : btCollisionShape, IDisposable
|
||||
{
|
||||
public static new btCapsuleShape FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btCapsuleShape)Native.GetObject(handle, typeof(btCapsuleShape));
|
||||
}
|
||||
|
||||
public btCapsuleShape(IntPtr handle)
|
||||
: base(handle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btCapsuleShape(float radius, float height) : base()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtCapsuleShape(radius, height);
|
||||
}
|
||||
|
||||
public float getRadius()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
|
||||
return BulletAPI_BtCapsuleShape_getRadius(m_handle);
|
||||
}
|
||||
|
||||
public float getHalfHeight()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
|
||||
return BulletAPI_BtCapsuleShape_getHalfHeight(m_handle);
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtCapsuleShape(float radius, float height);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCapsuleShape_getRadius(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCapsuleShape_getHalfHeight(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCapsuleShape_delete(IntPtr handle);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual new void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
base.Dispose();
|
||||
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
//BulletAPI_BtRigidBody_delete(m_handle);
|
||||
//m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btCapsuleShape()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public static class btGImpactCollisionAlgorithm
|
||||
{
|
||||
public static void registerAlgorithm(btCollisionDispatcher dispatcher)
|
||||
{
|
||||
dispatcher.RegisterGImpact();
|
||||
}
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btGImpactMeshShape : btCollisionShape, IDisposable
|
||||
{
|
||||
public static new btGImpactMeshShape FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btGImpactMeshShape)Native.GetObject(handle, typeof(btGImpactMeshShape));
|
||||
}
|
||||
|
||||
public btGImpactMeshShape(IntPtr handle)
|
||||
: base(handle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btGImpactMeshShape(btStridingMeshInterface meshInterface)
|
||||
: base()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtGImpactMeshShape(meshInterface.Handle);
|
||||
}
|
||||
|
||||
public void updateBound()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtGImpactMeshShape_updateBound(m_handle);
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtGImpactMeshShape(IntPtr meshInterface);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtGImpactMeshShape_updateBound(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_btSphereShape_delete(IntPtr handle);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual new void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
base.Dispose();
|
||||
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
//BulletAPI_BtRigidBody_delete(m_handle);
|
||||
//m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btGImpactMeshShape()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btSphereShape : btCollisionShape, IDisposable
|
||||
{
|
||||
public static new btSphereShape FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btSphereShape)Native.GetObject(handle, typeof(btSphereShape));
|
||||
}
|
||||
|
||||
public btSphereShape(IntPtr handle)
|
||||
: base(handle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btSphereShape(float radius)
|
||||
: base()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtSphereShape(radius);
|
||||
}
|
||||
|
||||
|
||||
public void setUnscaledRadius(float radius)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtSphereShape_setUnscaledRadius(m_handle, radius);
|
||||
}
|
||||
|
||||
public float getRadius()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_btSphereShape_getRadius(m_handle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtSphereShape(float radius);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_btSphereShape_getRadius(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtSphereShape_setUnscaledRadius(IntPtr handle, float unscaledRadius);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_btSphereShape_delete(IntPtr handle);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual new void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
base.Dispose();
|
||||
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
//BulletAPI_BtRigidBody_delete(m_handle);
|
||||
//m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btSphereShape()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btStridingMeshInterface
|
||||
{
|
||||
public static btStridingMeshInterface FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btStridingMeshInterface)Native.GetObject(handle, typeof(btStridingMeshInterface));
|
||||
}
|
||||
|
||||
public IntPtr m_handle = IntPtr.Zero;
|
||||
public bool m_displosed = false;
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
// Don't use this one except by a base class. You're responsible for setting m_handle!
|
||||
public btStridingMeshInterface()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btStridingMeshInterface(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btTriangleIndexVertexArray : btStridingMeshInterface, IDisposable
|
||||
{
|
||||
private bool usethisdispose = false;
|
||||
|
||||
public static new btTriangleIndexVertexArray FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btTriangleIndexVertexArray)Native.GetObject(handle, typeof(btTriangleIndexVertexArray));
|
||||
}
|
||||
|
||||
public new IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
protected new IntPtr m_handle
|
||||
{
|
||||
get { return base.m_handle; }
|
||||
set { base.m_handle = value; }
|
||||
}
|
||||
|
||||
//Expose m_disposed of base class to derived classes while still being protected.
|
||||
protected bool m_disposed
|
||||
{
|
||||
get { return m_displosed; }
|
||||
set { m_displosed = value; }
|
||||
}
|
||||
|
||||
// Don't use this one except by a base class. You're responsible for setting m_handle!
|
||||
public btTriangleIndexVertexArray()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btTriangleIndexVertexArray(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btTriangleIndexVertexArray(int numTriangles, int[] triangleIndexBase,
|
||||
int triangleIndexStride, int numVerticies,
|
||||
float[] vertexBase, int vertexStride)
|
||||
{
|
||||
usethisdispose = true;
|
||||
m_handle = BulletAPI_CreateBtTriangleIndexVertexArray(numTriangles, triangleIndexBase, triangleIndexStride,
|
||||
numVerticies, vertexBase, vertexStride);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region Native Invokes
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtTriangleIndexVertexArray(int numTriangles, int[] triangleIndexBase,
|
||||
int triangleIndexStride, int numVerticies,
|
||||
float[] vertexBase, int vertexStride);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTriangleIndexVertexArray_delete(IntPtr handle);
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtTriangleIndexVertexArray_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btTriangleIndexVertexArray()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btTriangleMesh : btTriangleIndexVertexArray, IDisposable
|
||||
{
|
||||
|
||||
public static new btTriangleMesh FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btTriangleMesh)Native.GetObject(handle, typeof(btTriangleMesh));
|
||||
}
|
||||
|
||||
public new IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btTriangleMesh(bool use32BitIndices, bool use4componentVertices)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtTriangleMesh(use32BitIndices, use4componentVertices);
|
||||
}
|
||||
|
||||
public void addIndex(int index)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtTriangleMesh_addIndex(m_handle, index);
|
||||
}
|
||||
|
||||
public void addTriangle( btVector3 vertex0, btVector3 vertex1, btVector3 vertex2, bool removeDuplicates)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtTriangleMesh_addTriangle(m_handle, vertex0.Handle, vertex1.Handle, vertex2.Handle,
|
||||
removeDuplicates);
|
||||
}
|
||||
|
||||
public int findOrAddVertex(btVector3 vertex, bool removeDuplicateVertices)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtTriangleMesh_findOrAddVertex(m_handle, vertex.Handle, removeDuplicateVertices);
|
||||
}
|
||||
|
||||
public int getNumTriangles()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtTriangleMesh_getNumTriangles(m_handle);
|
||||
}
|
||||
|
||||
public bool getUse32BitIndices()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtTriangleMesh_getUse32BitIndices(m_handle);
|
||||
}
|
||||
|
||||
public bool getUse4componentVertices()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtTriangleMesh_getUse4componentVertices(m_handle);
|
||||
}
|
||||
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtTriangleMesh(bool use32BitIndices, bool use4componentVerticies);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTriangleMesh_addIndex(IntPtr handle, int index);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTriangleMesh_addTriangle(IntPtr handle, IntPtr vertex0, IntPtr vertex1, IntPtr vertex2, bool removeDuplicateVertices);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtTriangleMesh_findOrAddVertex(IntPtr handle, IntPtr vertex, bool removeDuplicateVertices);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtTriangleMesh_getNumTriangles(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtTriangleMesh_getUse32BitIndices(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtTriangleMesh_getUse4componentVertices(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTriangleMesh_delete(IntPtr handle);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected new virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtTriangleMesh_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btTriangleMesh()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btAxisSweep3 : btBroadphaseInterface, IDisposable
|
||||
{
|
||||
private IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
private bool m_disposed = false;
|
||||
|
||||
public static btAxisSweep3 FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btAxisSweep3)Native.GetObject(handle, typeof(btAxisSweep3));
|
||||
}
|
||||
|
||||
public new IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btAxisSweep3(IntPtr handle) : base(handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btAxisSweep3(btVector3 worldAabbMin, btVector3 worldAabbMax, int MaxProxies)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtAxisSweep3(worldAabbMin.Handle, worldAabbMax.Handle, MaxProxies);
|
||||
base.Handle = m_handle;
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtAxisSweep3(IntPtr worldAabbMin, IntPtr worldAabbMax, int MaxProxies);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtAxisSweep3_delete(IntPtr ax);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtAxisSweep3_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btAxisSweep3()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btBroadphaseInterface
|
||||
{
|
||||
private IntPtr m_handle;
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
set { m_handle = value; }
|
||||
}
|
||||
|
||||
public btBroadphaseInterface(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
public btBroadphaseInterface()
|
||||
{
|
||||
m_handle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btCollisionConfiguration
|
||||
{
|
||||
private IntPtr m_handle;
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
set { m_handle = value; }
|
||||
}
|
||||
|
||||
public btCollisionConfiguration(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
public btCollisionConfiguration()
|
||||
{
|
||||
m_handle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btCollisionDispatcher : btDispatcher, IDisposable
|
||||
{
|
||||
private IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
private bool m_disposed = false;
|
||||
|
||||
public static btCollisionDispatcher FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btCollisionDispatcher)Native.GetObject(handle, typeof(btCollisionDispatcher));
|
||||
}
|
||||
|
||||
public new IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btCollisionDispatcher(IntPtr handle) : base(handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btCollisionDispatcher(btCollisionConfiguration config)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtCollisionDispatcher(config.Handle);
|
||||
base.Handle = m_handle;
|
||||
}
|
||||
|
||||
// Registers using the GImpact collision algorithm (so things will collide)
|
||||
public void RegisterGImpact()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionDispatcher_RegisterGImpact(m_handle);
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtCollisionDispatcher(IntPtr config);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionDispatcher_RegisterGImpact(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionDispatcher_delete(IntPtr obj);
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtCollisionDispatcher_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btCollisionDispatcher()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+592
@@ -0,0 +1,592 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btCollisionObject : IDisposable
|
||||
{
|
||||
protected IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
protected bool m_disposed = false;
|
||||
|
||||
public static btCollisionObject FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btCollisionObject)Native.GetObject(handle,
|
||||
typeof(btCollisionObject));
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btCollisionObject(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btCollisionObject()
|
||||
{
|
||||
//m_handle = BulletAPI_CreateBtCollisionObject();
|
||||
}
|
||||
|
||||
public void activate(bool forceActivate)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_activate(m_handle, forceActivate);
|
||||
}
|
||||
|
||||
public bool checkCollideWith(btCollisionObject collisionObject)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_checkCollideWith(m_handle, collisionObject.Handle);
|
||||
}
|
||||
|
||||
public void forceActivationState(int newState)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_forceActivationState(m_handle, newState);
|
||||
}
|
||||
|
||||
public int getActivationState()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getActivationState(m_handle);
|
||||
}
|
||||
|
||||
public btVector3 getAnisotropicFriction()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtCollisionObject_getAnisotropicFriction(m_handle));
|
||||
}
|
||||
|
||||
// TODO: FIXME: create btBroadPhaseProxy object
|
||||
private IntPtr getBroadPhaseHandle()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getBroadphaseHandle(m_handle);
|
||||
}
|
||||
|
||||
public float getCcdMotionThreshold()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getCcdMotionThreshold(m_handle);
|
||||
}
|
||||
|
||||
public float getCcdSquareMotionThreshold()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getCcdSquareMotionThreshold(m_handle);
|
||||
}
|
||||
|
||||
public float getCcdSweptSphereRadius()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getCcdSweptSphereRadius(m_handle);
|
||||
}
|
||||
|
||||
public int getCollisionFlags()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getCollisionFlags(m_handle);
|
||||
}
|
||||
|
||||
public btCollisionShape getCollisionShape()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btCollisionShape.FromIntPtr(BulletAPI_BtCollisionObject_getCollisionShape(m_handle));
|
||||
}
|
||||
|
||||
public int getCompanionId()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getCompanionId(m_handle);
|
||||
}
|
||||
|
||||
public float getContactProcessingThreshold()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getContactProcessingThreshold(m_handle);
|
||||
}
|
||||
|
||||
public float getDeactivationTime()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getDeactivationTime(m_handle);
|
||||
}
|
||||
|
||||
public float getFriction()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getFriction(m_handle);
|
||||
}
|
||||
|
||||
public float getHitFraction()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getHitFraction(m_handle);
|
||||
}
|
||||
|
||||
public btVector3 getInterpolationAngularVelocity()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtCollisionObject_getInterpolationAngularVelocity(m_handle));
|
||||
}
|
||||
|
||||
public btVector3 getInterpolationLinearVelocity()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtCollisionObject_getInterpolationLinearVelocity(m_handle));
|
||||
}
|
||||
|
||||
public btTransform getInterpolationWorldTransform()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btTransform.FromIntPtr(BulletAPI_BtCollisionObject_getInterpolationWorldTransform(m_handle));
|
||||
}
|
||||
|
||||
public int getIslandTag()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getIslandTag(m_handle);
|
||||
}
|
||||
|
||||
public float getRestitution()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getRestitution(m_handle);
|
||||
}
|
||||
|
||||
public btCollisionShape getRootCollisionShape()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btCollisionShape.FromIntPtr(BulletAPI_BtCollisionObject_getRootCollisionShape(m_handle));
|
||||
}
|
||||
|
||||
public IntPtr getUserPointer()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_getUserPointer(m_handle);
|
||||
}
|
||||
|
||||
public btTransform getWorldTransform()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btTransform.FromIntPtr(BulletAPI_BtCollisionObject_getWorldTransform(m_handle));
|
||||
}
|
||||
|
||||
public bool hasAnisotropicFriction()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_hasAnisotropicFriction(m_handle);
|
||||
}
|
||||
|
||||
public bool hasContactResponse()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_hasContactResponse(m_handle);
|
||||
}
|
||||
|
||||
public bool isActive()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_isActive(m_handle);
|
||||
}
|
||||
|
||||
public bool isKinematicObject()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_isKinematicObject(m_handle);
|
||||
}
|
||||
|
||||
public bool isStaticObject()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_isStaticObject(m_handle);
|
||||
}
|
||||
|
||||
public bool isStaticOrKinematicObject()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_isStaticOrKinematicObject(m_handle);
|
||||
}
|
||||
|
||||
public bool mergesSimulationIslands()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionObject_mergesSimulationIslands(m_handle);
|
||||
}
|
||||
|
||||
|
||||
public void setActivationState(int newState)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setActivationState(m_handle, newState);
|
||||
}
|
||||
|
||||
|
||||
public void setAnisotropicFriction(btVector3 anisotropicFriction)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setAnisotropicFriction(m_handle, anisotropicFriction.Handle);
|
||||
}
|
||||
|
||||
// TODO: FIXME: add btBroadPhaseProxyObject
|
||||
private void setBroadphaseHandle(IntPtr bphandle)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setBroadphaseHandle(m_handle, bphandle);
|
||||
}
|
||||
|
||||
public void setCcdMotionThreshold(float ccdMotionThreshold)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setCcdMotionThreshold(m_handle, ccdMotionThreshold);
|
||||
}
|
||||
|
||||
public void setCcdSweptSphereRadius(float radius)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setCcdSweptSphereRadius(m_handle, radius);
|
||||
}
|
||||
|
||||
public void setCollisionFlags(int flags)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setCollisionFlags(m_handle, flags);
|
||||
}
|
||||
|
||||
public void setCollisionShape(btCollisionShape collisionShape)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setCollisionShape(m_handle, collisionShape.Handle);
|
||||
}
|
||||
|
||||
public void setCompanionId(int id)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setCompanionId(m_handle, id);
|
||||
}
|
||||
|
||||
public void setContactProcessingThreshold(float contactProcessingThreshold)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setContactProcessingThreshold(m_handle, contactProcessingThreshold);
|
||||
}
|
||||
|
||||
public void setDeactivationTime(float time)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setDeactivationTime(m_handle, time);
|
||||
}
|
||||
|
||||
public void setFriction(float frict)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setFriction(m_handle, frict);
|
||||
}
|
||||
|
||||
public void setHitFraction(float hitFraction)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setHitFraction(m_handle, hitFraction);
|
||||
}
|
||||
|
||||
public void setInterpolationAngularVelocity(btVector3 angvel)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setInterpolationAngularVelocity(m_handle, angvel.Handle);
|
||||
}
|
||||
|
||||
public void setInterpolationLinearVelocity(btVector3 linvel)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setInterpolationLinearVelocity(m_handle, linvel.Handle);
|
||||
}
|
||||
|
||||
public void setInterpolationWorldTransform(btTransform trans)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setInterpolationWorldTransform(m_handle, trans.Handle);
|
||||
}
|
||||
|
||||
public void setIslandTag(int tag)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setIslandTag(m_handle, tag);
|
||||
}
|
||||
|
||||
public void setRestitution(float rest)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setRestitution(m_handle, rest);
|
||||
}
|
||||
|
||||
public void setUserPointer(IntPtr userPointer)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setUserPointer(m_handle, userPointer);
|
||||
}
|
||||
|
||||
public void setWorldTransform(btTransform worldTrans)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionObject_setWorldTransform(m_handle, worldTrans.Handle);
|
||||
}
|
||||
|
||||
|
||||
#region Native Invokes
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtCollisionObject();
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_activate(IntPtr handle, bool forceActivate);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionObject_checkCollideWith(IntPtr handle, IntPtr collisionObject);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_forceActivationState(IntPtr handle, int newState);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtCollisionObject_getActivationState(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtCollisionObject_getAnisotropicFriction(IntPtr handle);//btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtCollisionObject_getBroadphaseHandle(IntPtr handle); // btBroadPhaseProxy
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCollisionObject_getCcdMotionThreshold(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCollisionObject_getCcdSquareMotionThreshold(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCollisionObject_getCcdSweptSphereRadius(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtCollisionObject_getCollisionFlags(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtCollisionObject_getCollisionShape(IntPtr handle); //btCollisionShape
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtCollisionObject_getCompanionId(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCollisionObject_getContactProcessingThreshold(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCollisionObject_getDeactivationTime(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCollisionObject_getFriction(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCollisionObject_getHitFraction(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtCollisionObject_getInterpolationAngularVelocity(IntPtr handle);//btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtCollisionObject_getInterpolationLinearVelocity(IntPtr handle);//btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtCollisionObject_getInterpolationWorldTransform(IntPtr handle);//btTransform
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtCollisionObject_getIslandTag(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCollisionObject_getRestitution(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtCollisionObject_getRootCollisionShape(IntPtr handle); //btCollisionShape
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtCollisionObject_getUserPointer(IntPtr handle); // pointer
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtCollisionObject_getWorldTransform(IntPtr handle); //btTransform
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionObject_hasAnisotropicFriction(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionObject_hasContactResponse(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionObject_isActive(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionObject_isKinematicObject(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionObject_isStaticObject(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionObject_isStaticOrKinematicObject(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionObject_mergesSimulationIslands(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setActivationState(IntPtr handle, int newState);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setAnisotropicFriction(IntPtr handle, IntPtr anisotropicFriction); // anisotropicFriction btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setBroadphaseHandle(IntPtr handle, IntPtr bphandle); //btBroadphaseProxy
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setCcdMotionThreshold(IntPtr handle, float ccdMotionThreshold);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setCcdSweptSphereRadius(IntPtr handle, float radius);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setCollisionFlags(IntPtr handle, int flags);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setCollisionShape(IntPtr handle, IntPtr collisionShape); // btCollisionShape
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setCompanionId(IntPtr handle, int id);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setContactProcessingThreshold(IntPtr handle, float contactProcessingThreshold);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setDeactivationTime(IntPtr handle, float time);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setFriction(IntPtr handle, float frict);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setHitFraction(IntPtr handle, float hitFraction);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setInterpolationAngularVelocity(IntPtr handle, IntPtr angvel);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setInterpolationLinearVelocity(IntPtr handle, IntPtr linvel);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setInterpolationWorldTransform(IntPtr handle, IntPtr trans);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setIslandTag(IntPtr handle, int tag);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setRestitution(IntPtr handle, float rest);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setUserPointer(IntPtr handle, IntPtr userPointer);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_setWorldTransform(IntPtr handle, IntPtr worldTrans);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionObject_delete(IntPtr handle);
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtCollisionObject_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btCollisionObject()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+236
@@ -0,0 +1,236 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btCollisionShape : IDisposable
|
||||
{
|
||||
protected IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
protected bool m_disposed = false;
|
||||
|
||||
public static btCollisionShape FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btCollisionShape)Native.GetObject(handle,
|
||||
typeof(btCollisionShape));
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btCollisionShape(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btCollisionShape()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtCollisionShape();
|
||||
}
|
||||
|
||||
public void calculateLocalInertia(float mass, btVector3 inertia)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
BulletAPI_BtCollisionShape_calculateLocalInertia(m_handle, mass, inertia.Handle);
|
||||
}
|
||||
|
||||
public float getAngularMotionDisk()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionShape_getAngularMotionDisk(m_handle);
|
||||
}
|
||||
|
||||
public btVector3 getLocalScaling()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return btVector3.FromIntPtr(BulletAPI_BtCollisionShape_getLocalScaling(m_handle));
|
||||
}
|
||||
|
||||
public float getContactBreakingThreshold()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionShape_getContactBreakingThreshold(m_handle);
|
||||
}
|
||||
|
||||
public float getMargin()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionShape_getMargin(m_handle);
|
||||
}
|
||||
|
||||
public int getShapeType()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionShape_getShapeType(m_handle);
|
||||
}
|
||||
|
||||
public IntPtr getUserPointer()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionShape_getUserPointer(m_handle);
|
||||
}
|
||||
|
||||
public bool isCompound()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionShape_isCompound(m_handle);
|
||||
}
|
||||
|
||||
public bool isConcave()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionShape_isConcave(m_handle);
|
||||
}
|
||||
|
||||
public bool isConvex()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionShape_isConvex(m_handle);
|
||||
}
|
||||
|
||||
public bool isInfinite()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionShape_isInfinite(m_handle);
|
||||
}
|
||||
|
||||
public bool isPolyhedral()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtCollisionShape_isPolyhedral(m_handle);
|
||||
}
|
||||
|
||||
public void setLocalScaling(btVector3 scaling)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionShape_setLocalScaling(m_handle, scaling.Handle);
|
||||
}
|
||||
|
||||
public void setMargin(float scaling)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionShape_setMargin(m_handle, scaling);
|
||||
}
|
||||
|
||||
public void setUserPointer(IntPtr ptr)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtCollisionShape_setUserPointer(m_handle, ptr);
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtCollisionShape();
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionShape_calculateLocalInertia(IntPtr handle, float mass, IntPtr inertia);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCollisionShape_getAngularMotionDisk(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtCollisionShape_getLocalScaling(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCollisionShape_getContactBreakingThreshold(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtCollisionShape_getMargin(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtCollisionShape_getShapeType(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtCollisionShape_getUserPointer(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionShape_isCompound(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionShape_isConcave(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionShape_isConvex(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionShape_isInfinite(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtCollisionShape_isPolyhedral(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionShape_setLocalScaling(IntPtr handle, IntPtr scaling);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionShape_setMargin(IntPtr handle, float margin);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionShape_setUserPointer(IntPtr handle, IntPtr ptr);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtCollisionShape_delete(IntPtr obj);
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// If we deliberately called Dispose, then call the virtual dispose
|
||||
// If a derived class was disposed, then let it handle the unmanaged memory
|
||||
BulletAPI_BtCollisionShape_delete(m_handle);
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
//
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btCollisionShape()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btDefaultCollisionConfiguration : btCollisionConfiguration, IDisposable
|
||||
{
|
||||
private IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
private bool m_disposed = false;
|
||||
|
||||
protected static btDefaultCollisionConfiguration FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btDefaultCollisionConfiguration)Native.GetObject(handle, typeof(btDefaultCollisionConfiguration));
|
||||
}
|
||||
|
||||
public new IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btDefaultCollisionConfiguration(IntPtr handle) : base(handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btDefaultCollisionConfiguration()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtDefaultCollisionConfiguration();
|
||||
base.Handle = m_handle;
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtDefaultCollisionConfiguration();
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtDefaultCollisionConfiguration_delete(IntPtr ax);
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtDefaultCollisionConfiguration_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btDefaultCollisionConfiguration()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btDispatcher
|
||||
{
|
||||
private IntPtr m_handle;
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
set { m_handle = value; }
|
||||
}
|
||||
|
||||
public btDispatcher(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
public btDispatcher()
|
||||
{
|
||||
m_handle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btGhostObject : btCollisionObject, IDisposable
|
||||
{
|
||||
public static new btGhostObject FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btGhostObject)Native.GetObject(handle, typeof(btGhostObject));
|
||||
}
|
||||
|
||||
public btGhostObject(IntPtr handle)
|
||||
: base(handle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btGhostObject() : base()
|
||||
{
|
||||
if (!(this is btPairCachingGhostObject))
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtGhostObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtGhostObject();
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtGhostObject_getNumOverlappingObjects(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtGhostObject_getHalfHeight(IntPtr handle, int index);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtGhostObject_delete(IntPtr handle);
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual new void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
base.Dispose(false);
|
||||
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
//BulletAPI_BtRigidBody_delete(m_handle);
|
||||
//m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btGhostObject()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btHeightfieldTerrainShape : btCollisionShape, IDisposable
|
||||
{
|
||||
public enum UPAxis : int
|
||||
{
|
||||
X = 0,
|
||||
Y = 1,
|
||||
Z = 2
|
||||
}
|
||||
public enum PHY_ScalarType : int
|
||||
{
|
||||
PHY_FLOAT = 0,
|
||||
PHY_DOUBLE = 1,
|
||||
PHY_INTEGER = 2,
|
||||
PHY_SHORT = 3,
|
||||
PHY_FIXEDPOINT88 = 4,
|
||||
PHY_UCHAR = 5
|
||||
}
|
||||
|
||||
public static new btHeightfieldTerrainShape FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btHeightfieldTerrainShape)Native.GetObject(handle, typeof(btHeightfieldTerrainShape));
|
||||
}
|
||||
|
||||
public btHeightfieldTerrainShape(IntPtr handle) : base(handle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength, float[] heightfieldData, float heightScale, float minHeight, float maxHeight, int upAxis, int heightDataType, bool flipQuadEdges)
|
||||
: base()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtHeightfieldTerrainShape(heightStickWidth, heightStickLength, heightfieldData, heightScale, minHeight, maxHeight, upAxis, heightDataType, flipQuadEdges);
|
||||
}
|
||||
|
||||
public btVector3 getLocalScaling()
|
||||
{
|
||||
return btVector3.FromIntPtr(BulletAPI_BtHeightFieldTerrainShape_getLocalScaling(m_handle));
|
||||
}
|
||||
|
||||
public void setLocalScaling(btVector3 scaling)
|
||||
{
|
||||
BulletAPI_BtHeightFieldTerrainShape_setLocalScaling(m_handle, scaling.Handle);
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtHeightfieldTerrainShape (int heightStickWidth, int heightStickLength, [MarshalAs(UnmanagedType.LPArray)] float[] heightfieldData, float heightScale, float minHeight, float maxHeight,int upAxis, int heightDataType, bool flipQuadEdges);
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtHeightFieldTerrainShape_getLocalScaling(IntPtr handle); // btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtHeightFieldTerrainShape_setLocalScaling(IntPtr handle, IntPtr scaling);//btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtHeightFieldTerrainShape_delete(IntPtr handle);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual new void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
base.Dispose();
|
||||
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
//BulletAPI_BtRigidBody_delete(m_handle);
|
||||
//m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btHeightfieldTerrainShape()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btPairCachingGhostObject : btGhostObject
|
||||
{
|
||||
public static new btPairCachingGhostObject FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btPairCachingGhostObject)Native.GetObject(handle, typeof(btPairCachingGhostObject));
|
||||
}
|
||||
|
||||
public btPairCachingGhostObject(IntPtr handle)
|
||||
: base(handle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btPairCachingGhostObject()
|
||||
: base()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtPairCachingGhostObject();
|
||||
}
|
||||
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtPairCachingGhostObject();
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtPairCachingGhostObject_delete(IntPtr handle);
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual new void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
base.Dispose();
|
||||
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
//BulletAPI_BtRigidBody_delete(m_handle);
|
||||
//m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btPairCachingGhostObject()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btRayResultCallback
|
||||
{
|
||||
protected IntPtr m_handle;
|
||||
protected bool m_disposed;
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btCollisionWorld
|
||||
{
|
||||
protected IntPtr m_handle = IntPtr.Zero;
|
||||
protected bool m_disposed = false;
|
||||
|
||||
public btCollisionWorld()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btCollisionWorld(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public void addCollisionObject(btCollisionObject collisionObject, int collisionFilterGroup, int collisionFilterMask)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_btCollisionWorld_addCollisionObject(m_handle, collisionObject.Handle, collisionFilterGroup,
|
||||
collisionFilterMask);
|
||||
}
|
||||
|
||||
public btBroadphaseInterface getBroadPhase()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btAxisSweep3.FromIntPtr(BulletAPI_btCollisionWorld_getBroadphase(m_handle));
|
||||
}
|
||||
|
||||
public btDispatcher getDispatcher()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btCollisionDispatcher.FromIntPtr(m_handle);
|
||||
}
|
||||
|
||||
public int getNumCollisionObjects()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_btCollisionWorld_getNumCollisionObjects(m_handle);
|
||||
}
|
||||
|
||||
public void rayTest(btVector3 rayFromWorld, btVector3 rayToWorld, btRayResultCallback resultCallback)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_btCollisionWorld_rayTest(m_handle, rayFromWorld.Handle, rayToWorld.Handle, resultCallback.Handle);
|
||||
}
|
||||
|
||||
public void removeCollisionObject(btCollisionObject obj)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_btCollisionWorld_removeCollisionObject(m_handle, obj.Handle);
|
||||
|
||||
}
|
||||
|
||||
#region NativeInvokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_btCollisionWorld_addCollisionObject(IntPtr handle, IntPtr collisionObject, int collisionFilterGroup, int collisionFilterMask);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_btCollisionWorld_getBroadphase(IntPtr handle); //btBroadphaseInterface*
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_btCollisionWorld_getPairCache(IntPtr handle); //btOverlappingPairCache*
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_btCollisionWorld_getDispatcher(IntPtr handle); //btDispatcher*
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_btCollisionWorld_getNumCollisionObjects(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_btCollisionWorld_rayTest(IntPtr handle, IntPtr rayFromWorld, IntPtr rayToWorld, IntPtr resultCallback);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_btCollisionWorld_removeCollisionObject(IntPtr handle, IntPtr collisionObject);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btConstraintInfo2 : IDisposable
|
||||
{
|
||||
protected IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
protected bool m_disposed = false;
|
||||
|
||||
public static btConstraintInfo2 FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btConstraintInfo2)Native.GetObject(handle,
|
||||
typeof(btConstraintInfo2));
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btConstraintInfo2(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btConstraintInfo2(float fps, float erp,
|
||||
float m_J1linearAxis,float m_J1angularAxis,float m_J2linearAxis,float m_J2angularAxis,
|
||||
int rowskip, float constraintError, float cfm, float lowerLimit, float upperLimit, float index)
|
||||
{
|
||||
m_handle = BulletAPI_BtTypedConstraint_CreateBtConstraintInfo2(fps, erp, m_J1linearAxis, m_J1angularAxis,
|
||||
m_J2linearAxis, m_J2angularAxis, rowskip,
|
||||
constraintError, cfm, lowerLimit,
|
||||
upperLimit, index);
|
||||
}
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtTypedConstraint_CreateBtConstraintInfo2(float fps, float erp,
|
||||
float m_J1linearAxis,float m_J1angularAxis,float m_J2linearAxis,float m_J2angularAxis,
|
||||
int rowskip, float constraintError, float cfm, float lowerLimit, float upperLimit, float index);
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTypedConstraint_BtConstraintInfo2_delete(IntPtr handle);
|
||||
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual new void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
|
||||
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtTypedConstraint_BtConstraintInfo2_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btConstraintInfo2()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btConstraintSolver
|
||||
{
|
||||
private IntPtr m_handle;
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
set { m_handle = value; }
|
||||
}
|
||||
|
||||
public btConstraintSolver(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
public btConstraintSolver()
|
||||
{
|
||||
m_handle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btDefaultMotionState : btMotionState, IDisposable
|
||||
{
|
||||
|
||||
public static new btDefaultMotionState FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btDefaultMotionState)Native.GetObject(handle, typeof(btDefaultMotionState));
|
||||
}
|
||||
|
||||
|
||||
public btDefaultMotionState(IntPtr handle) : base(handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btDefaultMotionState(): base()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtDefaultMotionState();
|
||||
}
|
||||
|
||||
public btDefaultMotionState(btTransform startTrans) : base()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtDefaultMotionStateStartTrans(startTrans.Handle);
|
||||
}
|
||||
|
||||
public btDefaultMotionState(btTransform startTrans, btTransform centerOfMassOffset)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtDefaultMotionStateStartTransCenterOfMassOffset(startTrans.Handle, centerOfMassOffset.Handle);
|
||||
}
|
||||
|
||||
public void getWorldTransform(out btTransform result)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
result = btTransform.getIdentity();
|
||||
BulletAPI_BtDefaultMotionState_getWorldTransform(m_handle, result.Handle);
|
||||
}
|
||||
|
||||
public void setWorldTransform(btTransform t)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
BulletAPI_BtDefaultMotionState_setWorldTransform(m_handle, t.Handle);
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtDefaultMotionState();
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtDefaultMotionStateStartTrans(IntPtr startTrans);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtDefaultMotionStateStartTransCenterOfMassOffset(IntPtr startTrans,
|
||||
IntPtr
|
||||
centerOfMassOffset);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtDefaultMotionState_getWorldTransform(IntPtr handle, IntPtr centerOfMassWorldTrans );
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtDefaultMotionState_setWorldTransform(IntPtr handle, IntPtr t );
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtDefaultMotionState_delete(IntPtr obj);
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual new void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
base.Dispose();
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btDefaultMotionState()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btDiscreteDynamicsWorld : btCollisionWorld, IDisposable
|
||||
{
|
||||
|
||||
|
||||
protected static btDiscreteDynamicsWorld FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btDiscreteDynamicsWorld)Native.GetObject(handle,
|
||||
typeof(btDiscreteDynamicsWorld));
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btDiscreteDynamicsWorld(IntPtr handle) : base(handle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btDiscreteDynamicsWorld(btDispatcher dispatcher, btBroadphaseInterface broadphase, btConstraintSolver solver, btCollisionConfiguration collisionconfig)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtDynamicsWorld(dispatcher.Handle, broadphase.Handle, solver.Handle, collisionconfig.Handle);
|
||||
}
|
||||
|
||||
public void setGravity(btVector3 v)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtDynamicsWorld_setGravity(m_handle,v.Handle);
|
||||
}
|
||||
|
||||
public int stepSimulation(float timeStep, int maxSubSteps, float fixedTimeStep)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtDynamicsWorld_stepSimulation(m_handle, timeStep, maxSubSteps, fixedTimeStep);
|
||||
}
|
||||
|
||||
public void addRigidBody(btRigidBody body)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtDynamicsWorld_addRigidBody(m_handle, body.Handle);
|
||||
}
|
||||
|
||||
public void removeRigidBody(btRigidBody body)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtDynamicsWorld_removeRigidBody(m_handle, body.Handle);
|
||||
}
|
||||
|
||||
|
||||
public void removeConstraint(btTypedConstraint pconstraint)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
if (pconstraint.Handle == IntPtr.Zero)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtDynamicsWorld_removeConstraint(m_handle, pconstraint.Handle);
|
||||
}
|
||||
|
||||
|
||||
#region Native Invokes
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtDynamicsWorld(IntPtr dispatcher, IntPtr broadphase, IntPtr solver, IntPtr collisionconfig);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtDynamicsWorld_Specific(IntPtr dispatcher, IntPtr broadphase, IntPtr solver, IntPtr collisionconfig);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtDynamicsWorld_addRigidBody(IntPtr handle, IntPtr body);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtDynamicsWorld_removeRigidBody(IntPtr handle, IntPtr body);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtDynamicsWorld_setGravity(IntPtr dynamicsWorld, IntPtr v);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtDynamicsWorld_stepSimulation(IntPtr dynamicsWorld, float timeStep, int maxSubSteps,
|
||||
float fixedTimeStep);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtDynamicsWorld_removeConstraint(IntPtr dynamicsWorld, IntPtr constraint);
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtDynamicsWorld_delete(IntPtr obj);
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtDynamicsWorld_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btDiscreteDynamicsWorld()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btGeneric6DofConstraint : btTypedConstraint, IDisposable
|
||||
{
|
||||
|
||||
public static new btGeneric6DofConstraint FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btGeneric6DofConstraint)Native.GetObject(handle, typeof(btGeneric6DofConstraint));
|
||||
}
|
||||
|
||||
public btGeneric6DofConstraint(IntPtr handle)
|
||||
: base(handle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btGeneric6DofConstraint(btRigidBody rbA, btRigidBody rbB, btTransform frameInA, btTransform frameInB, bool useLinearReferenceFrameA)
|
||||
: base()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtGeneric6DofConstraint(rbA.Handle, rbB.Handle, frameInA.Handle, frameInB.Handle, useLinearReferenceFrameA);
|
||||
}
|
||||
|
||||
public void setLinearUpperLimit(btVector3 linearUpper)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtGeneric6DofConstraint_setLinearUpperLimit(m_handle, linearUpper.Handle);
|
||||
}
|
||||
public void setLinearLowerLimit(btVector3 linearLower)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtGeneric6DofConstraint_setLinearLowerLimit(m_handle, linearLower.Handle);
|
||||
}
|
||||
|
||||
public void setAngularUpperLimit(btVector3 linearUpper)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtGeneric6DofConstraint_setAngularUpperLimit(m_handle, linearUpper.Handle);
|
||||
}
|
||||
|
||||
public void setAngularLowerLimit(btVector3 linearLower)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtGeneric6DofConstraint_setAngularLowerLimit(m_handle, linearLower.Handle);
|
||||
}
|
||||
|
||||
public void setLimits(int axis, float lo, float hi)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtGeneric6DofConstraint_setLimits(m_handle, axis, lo, hi);
|
||||
}
|
||||
|
||||
public bool isLimted(int limitIndex)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtGeneric6DofConstraint_isLimited(m_handle, limitIndex);
|
||||
}
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtGeneric6DofConstraint(IntPtr rbA, IntPtr rbB, IntPtr frameInA, IntPtr frameInB, bool useLinearReferenceFrameA);//btRigidBody/btTranform
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtGeneric6DofConstraint_delete(IntPtr handle);//btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtGeneric6DofConstraint_setLinearUpperLimit(IntPtr handle, IntPtr linearUpper);//btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtGeneric6DofConstraint_setLinearLowerLimit(IntPtr handle, IntPtr linearLower);//btMotionState
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtGeneric6DofConstraint_setAngularUpperLimit(IntPtr handle, IntPtr angularUpper);//btbroadphaseProxy
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtGeneric6DofConstraint_setAngularLowerLimit(IntPtr handle, IntPtr angularLower);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtGeneric6DofConstraint_isLimited(IntPtr handle, int limitIndex);//btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtGeneric6DofConstraint_setLimits(IntPtr handle, int axis, float lo, float hi);
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtGeneric6DofConstraint_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btGeneric6DofConstraint()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btMotionState : IDisposable
|
||||
{
|
||||
protected IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
protected bool m_disposed = false;
|
||||
|
||||
public static btMotionState FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btMotionState)Native.GetObject(handle, typeof(btMotionState));
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do not use!, for C++ Interop only!
|
||||
/// </summary>
|
||||
public btMotionState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btMotionState(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtMotionState_getWorldTransform(IntPtr handle, IntPtr centerOfMassWorldTrans);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtMotionState_setWorldTransform(IntPtr handle, IntPtr t);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtMotionState_delete(IntPtr obj);
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtMotionState_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btMotionState()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,458 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btRigidBody : btCollisionObject
|
||||
{
|
||||
|
||||
protected btRigidBodyConstructionInfo m_constructionInfo;
|
||||
|
||||
|
||||
|
||||
public static new btRigidBody FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btRigidBody)Native.GetObject(handle, typeof(btRigidBody));
|
||||
}
|
||||
|
||||
public btRigidBody(IntPtr handle) : base(handle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public btRigidBody(btRigidBodyConstructionInfo constructionInfo) : base()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtRigidBody(constructionInfo.Handle);
|
||||
m_constructionInfo = constructionInfo;
|
||||
}
|
||||
|
||||
public btRigidBody(float mass, btMotionState motionState, btCollisionShape collisionShape)
|
||||
{
|
||||
|
||||
m_constructionInfo = new btRigidBodyConstructionInfo();
|
||||
m_constructionInfo.m_collisionShape = collisionShape;
|
||||
m_constructionInfo.m_localInertia = new btVector3(0, 0, 0);
|
||||
m_constructionInfo.m_motionState = motionState;
|
||||
m_constructionInfo.m_startWorldTransform = btTransform.getIdentity();
|
||||
m_constructionInfo.SetGenericDefaultValues();
|
||||
m_constructionInfo.m_mass = mass;
|
||||
m_constructionInfo.commit();
|
||||
m_handle = BulletAPI_CreateBtRigidBody(m_constructionInfo.Handle);
|
||||
}
|
||||
|
||||
public btRigidBody(float mass, btMotionState motionState, btCollisionShape collisionShape, btVector3 localInertia)
|
||||
{
|
||||
|
||||
m_constructionInfo = new btRigidBodyConstructionInfo();
|
||||
m_constructionInfo.m_collisionShape = collisionShape;
|
||||
m_constructionInfo.m_localInertia = localInertia;
|
||||
m_constructionInfo.m_motionState = motionState;
|
||||
m_constructionInfo.m_startWorldTransform = btTransform.getIdentity();
|
||||
m_constructionInfo.SetGenericDefaultValues();
|
||||
m_constructionInfo.m_mass = mass;
|
||||
m_constructionInfo.commit();
|
||||
m_handle = BulletAPI_CreateBtRigidBody(m_constructionInfo.Handle);
|
||||
}
|
||||
|
||||
|
||||
public void applyCentralForce(btVector3 force)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_applyCentralForce(m_handle, force.Handle);
|
||||
}
|
||||
|
||||
public void applyCentralImpulse(btVector3 force)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_applyCentralImpulse(m_handle, force.Handle);
|
||||
}
|
||||
|
||||
public void applyForce(btVector3 force, btVector3 rel_pos)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_applyForce(m_handle, force.Handle, rel_pos.Handle);
|
||||
}
|
||||
|
||||
public void applyImpulse(btVector3 force, btVector3 rel_pos)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_applyImpulse(m_handle, force.Handle, rel_pos.Handle);
|
||||
}
|
||||
|
||||
public void applyTorque(btVector3 torque)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_applyTorque(m_handle, torque.Handle);
|
||||
}
|
||||
|
||||
public void applyTorqueImpulse(btVector3 torque)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_applyTorqueImpulse(m_handle, torque.Handle);
|
||||
}
|
||||
|
||||
public void clearForces()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_clearForces(m_handle);
|
||||
}
|
||||
|
||||
public float computeAngularImpulseDenominator(btVector3 axis)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtRigidBody_computeAngularImpulseDenominator(m_handle,axis.Handle);
|
||||
}
|
||||
|
||||
public float computeImpulseDenominator(btVector3 pos, btVector3 normal)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtRigidBody_computeImpulseDenominator(m_handle, pos.Handle, normal.Handle);
|
||||
}
|
||||
|
||||
public float getAngularDamping()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtRigidBody_getAngularDamping(m_handle);
|
||||
}
|
||||
|
||||
public btVector3 getAngularFactor()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtRigidBody_getAngularFactor(m_handle));
|
||||
}
|
||||
|
||||
public float getAngularSleepingThreshold()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtRigidBody_getAngularSleepingThreshold(m_handle);
|
||||
}
|
||||
|
||||
public btVector3 getCenterOfMassPosition()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtRigidBody_getCenterOfMassPosition(m_handle));
|
||||
}
|
||||
|
||||
public btTransform getCenterOfMassTransform()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btTransform.FromIntPtr(BulletAPI_BtRigidBody_getCenterOfMassTransform(m_handle));
|
||||
}
|
||||
|
||||
public btTypedConstraint getConstraintRef(int index)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btTypedConstraint.FromIntPtr(BulletAPI_BtRigidBody_getConstraintRef(m_handle, index));
|
||||
}
|
||||
|
||||
public btVector3 getGravity()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtRigidBody_getGravity(m_handle));
|
||||
}
|
||||
|
||||
public btVector3 getInvInertiaDiagLocal()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtRigidBody_getInvInertiaDiagLocal(m_handle));
|
||||
}
|
||||
|
||||
public btMatrix3x3 getInvInertiaTensorWorld()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btMatrix3x3.FromIntPtr(BulletAPI_BtRigidBody_getInvInertiaTensorWorld(m_handle));
|
||||
}
|
||||
|
||||
public float getInvMass()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtRigidBody_getInvMass(m_handle);
|
||||
}
|
||||
|
||||
public float getLinearDamping()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtRigidBody_getLinearDamping(m_handle);
|
||||
}
|
||||
|
||||
public btMotionState getMotionState()
|
||||
{
|
||||
return btMotionState.FromIntPtr(BulletAPI_BtRigidBody_getMotionState(m_handle));
|
||||
}
|
||||
|
||||
public int getNumConstraintRefs()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtRigidBody_getNumConstraintRefs(m_handle);
|
||||
}
|
||||
|
||||
public btVector3 getTotalForce()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtRigidBody_getTotalForce(m_handle));
|
||||
}
|
||||
|
||||
public btVector3 getVelocityInLocalPoint(btVector3 rel_pos)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtRigidBody_getVelocityInLocalPoint(m_handle,rel_pos.Handle));
|
||||
}
|
||||
|
||||
public bool isInWorld()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtRigidBody_isInWorld(m_handle);
|
||||
}
|
||||
|
||||
public void setAngularFactor(float angFac)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_setAngularFactor(m_handle, angFac);
|
||||
}
|
||||
|
||||
public void setAngularVelocity(btVector3 ang_vel)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_setAngularVelocity(m_handle, ang_vel.Handle);
|
||||
}
|
||||
|
||||
public void setInvInertiaDiagLocal(btVector3 diagInvInertia)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_setInvInertiaDiagLocal(m_handle, diagInvInertia.Handle);
|
||||
}
|
||||
|
||||
public void setLinearVelocity(btVector3 lin_vel)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_setLinearVelocity(m_handle, lin_vel.Handle);
|
||||
}
|
||||
|
||||
public void setMotionState(btMotionState motionState)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_setMotionState(m_handle, motionState.Handle);
|
||||
}
|
||||
|
||||
public void setSleepingThresholds(float linear, float angular)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_setSleepingThresholds(m_handle, linear, angular);
|
||||
}
|
||||
|
||||
public void translate(btVector3 v)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_translate(m_handle, v.Handle);
|
||||
}
|
||||
|
||||
public void updateDeactivation(float timeStep)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtRigidBody_updateDeactivation(m_handle, timeStep);
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtRigidBody(IntPtr constructionInfo);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtRigidBodyParams(float mass, IntPtr motionState, IntPtr collisionShape, IntPtr localInertia);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_applyCentralForce(IntPtr handle, IntPtr force);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_applyCentralImpulse(IntPtr handle, IntPtr impulse);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_applyForce(IntPtr handle, IntPtr force, IntPtr rel_pos);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_applyImpulse(IntPtr handle, IntPtr impulse, IntPtr rel_pos);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_applyTorque(IntPtr handle, IntPtr torque);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_applyTorqueImpulse(IntPtr handle, IntPtr torque);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_clearForces(IntPtr handle);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtRigidBody_computeAngularImpulseDenominator(IntPtr handle, IntPtr axis);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtRigidBody_computeImpulseDenominator(IntPtr handle, IntPtr pos, IntPtr normal);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtRigidBody_getAngularDamping(IntPtr handle);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getAngularFactor(IntPtr handle); //btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtRigidBody_getAngularSleepingThreshold(IntPtr handle);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getAngularVelocity(IntPtr handle); //btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtRigidBody_getLinearSleepingThreshold(IntPtr handle);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getCenterOfMassPosition(IntPtr handle); //btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getCenterOfMassTransform(IntPtr handle); //btTransform
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getConstraintRef(IntPtr handle, int index); //btTypedConstraint
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getGravity(IntPtr handle); //btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getInvInertiaDiagLocal(IntPtr handle); //btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getInvInertiaTensorWorld(IntPtr handle); //btMatrix3x3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtRigidBody_getInvMass(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtRigidBody_getLinearDamping(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getLinearVelocity(IntPtr handle);//btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getMotionState(IntPtr handle);//btMotionState
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtRigidBody_getNumConstraintRefs(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getTotalForce(IntPtr handle);//btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getTotalTorque(IntPtr handle);//btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtRigidBody_getVelocityInLocalPoint(IntPtr handle, IntPtr rel_pos);//btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool BulletAPI_BtRigidBody_isInWorld(IntPtr handle);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_setAngularFactor(IntPtr handle, float angFac);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_setAngularVelocity(IntPtr handle, IntPtr ang_vel);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_setInvInertiaDiagLocal(IntPtr handle, IntPtr diagInvInertia);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_setLinearVelocity(IntPtr handle, IntPtr lin_vel);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_setMotionState(IntPtr handle, IntPtr motionState);//btMotionState
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_setNewBroadphaseProxy(IntPtr handle, IntPtr broadphaseProxy);//btbroadphaseProxy
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_setSleepingThresholds(IntPtr handle, float linear, float angular);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_translate(IntPtr handle, IntPtr v);//btVector3
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_updateDeactivation(IntPtr handle, float timeStep);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBody_delete(IntPtr obj);
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual new void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
|
||||
if (m_constructionInfo.Handle != IntPtr.Zero)
|
||||
{
|
||||
m_constructionInfo.Dispose();
|
||||
}
|
||||
base.Dispose(false);
|
||||
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtRigidBody_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btRigidBody()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
|
||||
public class btRigidBodyConstructionInfo : IDisposable
|
||||
{
|
||||
public float m_mass;
|
||||
|
||||
///When a motionState is provided, the rigid body will initialize its world transform from the motion state
|
||||
///In this case, m_startWorldTransform is ignored.
|
||||
public btMotionState m_motionState;
|
||||
public btTransform m_startWorldTransform;
|
||||
public btCollisionShape m_collisionShape;
|
||||
public btVector3 m_localInertia;
|
||||
public float m_linearDamping;
|
||||
public float m_angularDamping;
|
||||
|
||||
public float m_friction;
|
||||
///best simulation results when friction is non-zero
|
||||
public float m_restitution;
|
||||
public float m_linearSleepingThreshold;
|
||||
public float m_angularSleepingThreshold;
|
||||
|
||||
//Additional damping can help avoiding lowpass jitter motion, help stability for ragdolls etc.
|
||||
//Such damping is undesirable, so once the overall simulation quality of the rigid body dynamics system has improved, this should become obsolete
|
||||
public bool m_additionalDamping;
|
||||
public float m_additionalDampingFactor;
|
||||
public float m_additionalLinearDampingThresholdSqr;
|
||||
public float m_additionalAngularDampingThresholdSqr;
|
||||
public float m_additionalAngularDampingFactor;
|
||||
|
||||
protected IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
protected bool m_disposed = false;
|
||||
|
||||
public static btMotionState FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btMotionState)Native.GetObject(handle, typeof(btMotionState));
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public void commit()
|
||||
{
|
||||
|
||||
BulletAPI_BtRigidBodyConstructionInfo_Commit(m_handle,
|
||||
m_mass, m_motionState.Handle, m_startWorldTransform.Handle, m_collisionShape.Handle,
|
||||
m_localInertia.Handle, m_linearDamping, m_angularDamping, m_friction,
|
||||
m_restitution, m_linearSleepingThreshold, m_angularSleepingThreshold,
|
||||
m_additionalDamping, m_additionalDampingFactor,
|
||||
m_additionalLinearDampingThresholdSqr, m_additionalAngularDampingThresholdSqr,
|
||||
m_additionalAngularDampingFactor);
|
||||
}
|
||||
|
||||
public btRigidBodyConstructionInfo()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtRigidBodyConstructionInfo();
|
||||
}
|
||||
|
||||
public void SetGenericDefaultValues()
|
||||
{
|
||||
m_linearDamping = 0;
|
||||
m_angularDamping = 0;
|
||||
m_friction = 0.5f;
|
||||
m_restitution = 0;
|
||||
m_linearSleepingThreshold = 0.8f;
|
||||
m_angularSleepingThreshold = 1;
|
||||
m_additionalDamping = false;
|
||||
m_additionalDampingFactor = 0.005f;
|
||||
m_additionalLinearDampingThresholdSqr = 0.01f;
|
||||
m_additionalAngularDampingThresholdSqr = 0.01f;
|
||||
m_additionalAngularDampingFactor = 0.01f;
|
||||
}
|
||||
|
||||
public btRigidBodyConstructionInfo(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtRigidBodyConstructionInfo();
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBodyConstructionInfo_Commit(IntPtr constructionInfoloc,
|
||||
float mass, IntPtr motionState, IntPtr startWorldTransform, IntPtr collisionShape,
|
||||
IntPtr localInertia, float linearDamping, float angularDamping, float friction,
|
||||
float restitution, float linearSleepingThreshold, float angularSleepingThreshold,
|
||||
bool additionalDamping, float additionalDampingFactor,
|
||||
float additionalLinearDampingThresholdSqr, float additionalAngularDampingThresholdSqr,
|
||||
float additionalAngularDampingFactor);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtRigidBodyConstructionInfo_delete(IntPtr obj);
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtRigidBodyConstructionInfo_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btRigidBodyConstructionInfo()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btSequentialImpulseConstraintSolver : btConstraintSolver, IDisposable
|
||||
{
|
||||
private IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
private bool m_disposed = false;
|
||||
|
||||
protected static btSequentialImpulseConstraintSolver FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btSequentialImpulseConstraintSolver)Native.GetObject(handle,
|
||||
typeof(btSequentialImpulseConstraintSolver));
|
||||
}
|
||||
|
||||
public new IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btSequentialImpulseConstraintSolver(IntPtr handle) : base(handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btSequentialImpulseConstraintSolver()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtSequentialImpulseConstraintSolver();
|
||||
base.Handle = m_handle;
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtSequentialImpulseConstraintSolver();
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtSequentialImpulseConstraintSolver_delete(IntPtr obj);
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtSequentialImpulseConstraintSolver_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btSequentialImpulseConstraintSolver()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btTypedConstraint
|
||||
{
|
||||
protected IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
protected bool m_disposed = false;
|
||||
|
||||
public static btTypedConstraint FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btTypedConstraint)Native.GetObject(handle,
|
||||
typeof(btTypedConstraint));
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btTypedConstraint(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Don't use this!
|
||||
/// purely for classes derived from this
|
||||
/// </summary>
|
||||
public btTypedConstraint()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void getInfo2(ref btConstraintInfo2 b)
|
||||
{
|
||||
BulletAPI_BtTypedConstraint_getInfo2(m_handle, b.Handle);
|
||||
}
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTypedConstraint_getInfo2(IntPtr handle, IntPtr b);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btMatrix3x3 : IDisposable
|
||||
{
|
||||
|
||||
private IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
private bool m_disposed = false;
|
||||
|
||||
public static btMatrix3x3 FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btMatrix3x3)Native.GetObject(handle,
|
||||
typeof(btMatrix3x3));
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btMatrix3x3(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btMatrix3x3()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtMatrix3x3();
|
||||
}
|
||||
|
||||
public btMatrix3x3(btQuaternion q)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtMatrix3x3Quaternion(q.Handle);
|
||||
}
|
||||
|
||||
public btMatrix3x3(float xx, float xy, float xz, float yx, float yy, float yz, float zx, float zy, float zz)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtMatrix3x3Floats(xx, xy, xz, yx, yy, yz, zx, zy, zz);
|
||||
}
|
||||
|
||||
public btMatrix3x3 absolute()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtMatrix3x3_absolute(m_handle));
|
||||
}
|
||||
|
||||
public btMatrix3x3 adjoint()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtMatrix3x3_adjoint(m_handle));
|
||||
}
|
||||
|
||||
public btMatrix3x3 inverse()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtMatrix3x3_inverse(m_handle));
|
||||
}
|
||||
|
||||
public btMatrix3x3 determinant()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtMatrix3x3_determinant(m_handle));
|
||||
}
|
||||
|
||||
public btVector3 getColumn(int i)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtMatrix3x3_getColumn(m_handle, i));
|
||||
}
|
||||
|
||||
public void getOpenGLSubMatrix(out float[] m)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
m = new float[12];
|
||||
BulletAPI_BtMatrix3x3_getOpenGLSubMatrix(m_handle, m);
|
||||
}
|
||||
|
||||
public void setRotation(btQuaternion q)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtMatrix3x3_setRotation(m_handle, q.Handle);
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtMatrix3x3();
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtMatrix3x3Quaternion(IntPtr q);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtMatrix3x3Floats(float xx, float xy, float xz, float yx, float yy, float yz, float zx, float zy, float zz);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtMatrix3x3Other(IntPtr m);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtMatrix3x3_absolute(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtMatrix3x3_adjoint(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtMatrix3x3_inverse(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtMatrix3x3_determinant(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtMatrix3x3_diagonalize(IntPtr handle, IntPtr rot, float threshold, int maxSteps);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtMatrix3x3_getColumn(IntPtr handle,int i);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtMatrix3x3_getOpenGLSubMatrix(IntPtr handle, [MarshalAs(UnmanagedType.LPArray)]float[] f);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtMatrix3x3_setRotation(IntPtr handle, IntPtr q);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtMatrix3x3_delete(IntPtr obj);
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtMatrix3x3_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btMatrix3x3()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btQuaternion : IDisposable
|
||||
{
|
||||
private IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
private bool m_disposed = false;
|
||||
|
||||
public static btQuaternion FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btQuaternion)Native.GetObject(handle,
|
||||
typeof(btQuaternion));
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btQuaternion(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btQuaternion()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtQuaternion();
|
||||
}
|
||||
|
||||
public btQuaternion(float x, float y, float z, float w)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtQuaternionFourFloats(x,y,z,w);
|
||||
}
|
||||
|
||||
public btQuaternion(btVector3 axis, float w)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtQuaternionAxisAngle(axis.Handle, w);
|
||||
}
|
||||
|
||||
public btQuaternion(float yaw, float pitch, float roll)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtQuaternionEuler(yaw,pitch,roll);
|
||||
}
|
||||
|
||||
public float angle(btQuaternion q)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtQuaternion_angle(m_handle, q.Handle);
|
||||
}
|
||||
|
||||
public float dot(btQuaternion q)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtQuaternion_dot(m_handle, q.Handle);
|
||||
}
|
||||
|
||||
public btQuaternion farthest(btQuaternion q)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtQuaternion_farthest(m_handle, q.Handle));
|
||||
}
|
||||
|
||||
public float getAngle()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtQuaternion_getAngle(m_handle);
|
||||
}
|
||||
|
||||
public btQuaternion inverse()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtQuaternion_inverse(m_handle));
|
||||
}
|
||||
|
||||
public btQuaternion getIdentity()
|
||||
{
|
||||
return new btQuaternion(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
public float length()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtQuaternion_length(m_handle);
|
||||
}
|
||||
|
||||
public float length2()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtQuaternion_length2(m_handle);
|
||||
}
|
||||
|
||||
public btQuaternion normalize()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtQuaternion_normalize(m_handle));
|
||||
}
|
||||
|
||||
public btQuaternion normalized()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtQuaternion_normalized(m_handle));
|
||||
}
|
||||
|
||||
public void setEuler(float yaw, float pitch, float roll)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtQuaternion_setEuler(m_handle, yaw, pitch, roll);
|
||||
}
|
||||
|
||||
public void setEulerZYX(float yaw, float pitch, float roll)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtQuaternion_setEulerZYX(m_handle, yaw, pitch, roll);
|
||||
}
|
||||
|
||||
public void setRotation(btVector3 axis, float angle)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtQuaternion_setRotation(m_handle, axis.Handle, angle);
|
||||
}
|
||||
|
||||
public btQuaternion slerp(btQuaternion q, float t)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtQuaternion_slerp(m_handle, q.Handle, t));
|
||||
}
|
||||
|
||||
public string testStr()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
StringBuilder resulttxt = new StringBuilder();
|
||||
float[] vals = getValues();
|
||||
resulttxt.Append("<");
|
||||
resulttxt.Append(getX());
|
||||
resulttxt.Append(",");
|
||||
resulttxt.Append(getY());
|
||||
resulttxt.Append(",");
|
||||
resulttxt.Append(getZ());
|
||||
resulttxt.Append(",");
|
||||
resulttxt.Append(getW());
|
||||
resulttxt.Append(">");
|
||||
return resulttxt.ToString();
|
||||
}
|
||||
|
||||
public float getW()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtQuaternion_getW(m_handle);
|
||||
}
|
||||
|
||||
public float getX()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtQuaternion_getX(m_handle);
|
||||
}
|
||||
public float getY()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtQuaternion_getY(m_handle);
|
||||
}
|
||||
public float getZ()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return BulletAPI_BtQuaternion_getZ(m_handle);
|
||||
}
|
||||
public float[] getValues()
|
||||
{
|
||||
float[] result = new float[4];
|
||||
|
||||
BulletAPI_BtQuaternion_getValues(m_handle, result);
|
||||
float[] resultm = new float[4];
|
||||
int i = 0;
|
||||
resultm[i] = result[i++];
|
||||
resultm[i] = result[i++];
|
||||
resultm[i] = result[i++];
|
||||
resultm[i] = result[i];
|
||||
return resultm;
|
||||
}
|
||||
#region Native Invokes
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtQuaternion();
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtQuaternionFourFloats(float x, float y, float z, float w);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtQuaternionAxisAngle(IntPtr axis, float angle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtQuaternionEuler(float yaw, float pitch, float roll);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtQuaternion_angle(IntPtr handle, IntPtr q);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtQuaternion_dot(IntPtr handle, IntPtr q);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtQuaternion_farthest(IntPtr handle, IntPtr qd);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtQuaternion_getAngle(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtQuaternion_getW(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtQuaternion_getValues(IntPtr handle,[MarshalAs(UnmanagedType.LPArray)] float[] v);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtQuaternion_getX(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtQuaternion_getY(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtQuaternion_getZ(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtQuaternion_inverse(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtQuaternion_length(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtQuaternion_length2(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtQuaternion_normalize(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtQuaternion_normalized(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtQuaternion_setEuler(IntPtr handle, float yaw, float pitch, float roll);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtQuaternion_setEulerZYX(IntPtr handle, float yaw, float pitch, float roll);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtQuaternion_setRotation(IntPtr handle, IntPtr axis, float angle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtQuaternion_slerp(IntPtr handle, IntPtr q, float t);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtQuaternion_delete(IntPtr obj);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtQuaternion_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btQuaternion()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btTransform : IDisposable
|
||||
{
|
||||
private IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
private bool m_disposed = false;
|
||||
|
||||
public static btTransform FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btTransform)Native.GetObject(handle,
|
||||
typeof(btTransform));
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btTransform(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btTransform()
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtTransform();
|
||||
}
|
||||
|
||||
public btTransform(btQuaternion q, btVector3 v)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtTransformQuaternionVector3(q.Handle, v.Handle);
|
||||
}
|
||||
|
||||
public btTransform(btTransform t)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtTransformOtherTransform(t.Handle);
|
||||
}
|
||||
|
||||
public btMatrix3x3 getBasis()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btMatrix3x3.FromIntPtr(BulletAPI_BtTransform_getBasis(m_handle));
|
||||
}
|
||||
|
||||
public static btTransform getIdentity()
|
||||
{
|
||||
return new btTransform(new btQuaternion(0,0,0,1),new btVector3(0,0,0));
|
||||
}
|
||||
|
||||
public void getOpenGLMatrix(out float[] m)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
m = new float[12];
|
||||
BulletAPI_BtTransform_getOpenGLMatrix(m_handle, m);
|
||||
}
|
||||
|
||||
public btVector3 getOrigin()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btVector3.FromIntPtr(BulletAPI_BtTransform_getOrigin(m_handle));
|
||||
}
|
||||
|
||||
public btQuaternion getRotation()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return btQuaternion.FromIntPtr(BulletAPI_BtTransform_getRotation(m_handle));
|
||||
}
|
||||
|
||||
public btTransform inverse()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtTransform_inverse(m_handle));
|
||||
}
|
||||
|
||||
public btTransform inverseTimes(btTransform t)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtTransform_inverseTimes(m_handle,t.Handle));
|
||||
}
|
||||
|
||||
public btTransform invXform(btVector3 inVec)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
return FromIntPtr(BulletAPI_BtTransform_invXform(m_handle, inVec.Handle));
|
||||
}
|
||||
|
||||
public void mult(btTransform t1, btTransform t2)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtTransform_mult(m_handle, t1.Handle, t2.Handle);
|
||||
}
|
||||
|
||||
public void setBasis(btMatrix3x3 basis)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtTransform_setBasis(m_handle, basis.Handle);
|
||||
}
|
||||
|
||||
public void setFromOpenGLMatrix(float[] m)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtTransform_setFromOpenGLMatrix(m_handle, m);
|
||||
}
|
||||
|
||||
public void setOrigin(btMatrix3x3 origin)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtTransform_setOrigin(m_handle, origin.Handle);
|
||||
}
|
||||
|
||||
public void setRotation(btQuaternion q)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
BulletAPI_BtTransform_setRotation(m_handle, q.Handle);
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtTransform();
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtTransformQuaternionVector3(IntPtr q, IntPtr v);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtTransformMatrix3Vector3(IntPtr m, IntPtr v);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtTransformOtherTransform(IntPtr t);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtTransform_getBasis(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtTransform_getIdentity(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTransform_getOpenGLMatrix(IntPtr handle, [MarshalAs(UnmanagedType.LPArray)] float[] m); // float array!
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtTransform_getOrigin(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtTransform_getRotation(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtTransform_inverse(IntPtr handle);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtTransform_inverseTimes(IntPtr handle, IntPtr t);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtTransform_invXform(IntPtr handle, IntPtr inVec); // // btVector3
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTransform_mult(IntPtr handle, IntPtr t1, IntPtr t2);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTransform_setBasis(IntPtr handle, IntPtr basis);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTransform_setFromOpenGLMatrix(IntPtr handle, [MarshalAs(UnmanagedType.LPArray)] float[] m);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTransform_setOrigin(IntPtr handle, IntPtr origin);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTransform_setRotation(IntPtr handle, IntPtr q);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtTransform_delete(IntPtr handle);
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
try
|
||||
{
|
||||
BulletAPI_BtTransform_delete(m_handle);
|
||||
}
|
||||
catch (AccessViolationException)
|
||||
{
|
||||
}
|
||||
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btTransform()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace BulletDotNET
|
||||
{
|
||||
public class btVector3 : IDisposable
|
||||
{
|
||||
private IntPtr m_handle = IntPtr.Zero;
|
||||
|
||||
private bool m_disposed = false;
|
||||
|
||||
public static btVector3 FromIntPtr(IntPtr handle)
|
||||
{
|
||||
return (btVector3)Native.GetObject(handle, typeof(btVector3));
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return m_handle; }
|
||||
}
|
||||
|
||||
public btVector3(float x, float y, float z)
|
||||
{
|
||||
m_handle = BulletAPI_CreateBtVector3(x, y, z);
|
||||
}
|
||||
|
||||
public btVector3(IntPtr handle)
|
||||
{
|
||||
m_handle = handle;
|
||||
}
|
||||
|
||||
public btVector3 absolute()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return FromIntPtr(BulletAPI_BtVector3_absolute(m_handle));
|
||||
}
|
||||
|
||||
public float angle(btVector3 v)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return BulletAPI_BtVector3_angle(m_handle, v.Handle);
|
||||
}
|
||||
|
||||
public int closestAxis()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return BulletAPI_BtVector3_closestAxis(m_handle);
|
||||
}
|
||||
|
||||
public btVector3 cross(btVector3 v)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return FromIntPtr(BulletAPI_BtVector3_cross(m_handle, v.Handle));
|
||||
}
|
||||
|
||||
public float distance(btVector3 v)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return BulletAPI_BtVector3_distance(m_handle, v.Handle);
|
||||
}
|
||||
|
||||
public float distance2(btVector3 v)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return BulletAPI_BtVector3_distance2(m_handle, v.Handle);
|
||||
}
|
||||
|
||||
public float dot(btVector3 v)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return BulletAPI_BtVector3_dot(m_handle, v.Handle);
|
||||
}
|
||||
|
||||
public int furthestAxis()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return BulletAPI_BtVector3_furthestAxis(m_handle);
|
||||
}
|
||||
|
||||
public float getX()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return BulletAPI_BtVector3_GetX(m_handle);
|
||||
}
|
||||
|
||||
public float getY()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return BulletAPI_BtVector3_GetY(m_handle);
|
||||
}
|
||||
|
||||
public float getZ()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return BulletAPI_BtVector3_GetZ(m_handle);
|
||||
}
|
||||
|
||||
public btVector3 normalized()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
return FromIntPtr(BulletAPI_BtVector3_normalized(m_handle));
|
||||
}
|
||||
|
||||
public void setInterpolate3(btVector3 v0, btVector3 v1, float rt)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
BulletAPI_BtVector3_setInterpolate3(m_handle, v0.Handle, v1.Handle, rt);
|
||||
}
|
||||
|
||||
public void setValue(float x, float y, float z)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
BulletAPI_BtVector3_setValue(m_handle, x, y, z);
|
||||
}
|
||||
|
||||
public void setX(float x)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
BulletAPI_BtVector3_setX(m_handle, x);
|
||||
}
|
||||
|
||||
public void setY(float y)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
BulletAPI_BtVector3_setY(m_handle, y);
|
||||
}
|
||||
|
||||
public void setZ(float z)
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
BulletAPI_BtVector3_setZ(m_handle, z);
|
||||
}
|
||||
|
||||
|
||||
public string testStr()
|
||||
{
|
||||
if (m_disposed)
|
||||
throw new ObjectDisposedException(ToString());
|
||||
|
||||
StringBuilder resulttxt = new StringBuilder();
|
||||
resulttxt.Append("<");
|
||||
resulttxt.Append(getX());
|
||||
resulttxt.Append(",");
|
||||
resulttxt.Append(getY());
|
||||
resulttxt.Append(",");
|
||||
resulttxt.Append(getZ());
|
||||
resulttxt.Append(">");
|
||||
return resulttxt.ToString();
|
||||
}
|
||||
|
||||
#region Native Invokes
|
||||
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_CreateBtVector3(float x, float y, float z);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtVector3_absolute(IntPtr umv);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtVector3_angle(IntPtr umv, IntPtr v);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtVector3_closestAxis(IntPtr umv);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtVector3_cross(IntPtr umv, IntPtr v);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtVector3_distance(IntPtr umv, IntPtr v);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtVector3_distance2(IntPtr umv, IntPtr v);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtVector3_dot(IntPtr umv, IntPtr v);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern int BulletAPI_BtVector3_furthestAxis(IntPtr umv);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtVector3_GetX(IntPtr umv);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtVector3_GetY(IntPtr umv);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern float BulletAPI_BtVector3_GetZ(IntPtr umv);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr BulletAPI_BtVector3_normalized(IntPtr umv);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtVector3_setInterpolate3(IntPtr umv, IntPtr v0, IntPtr v1, float rt);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtVector3_setValue(IntPtr umv, float x, float y, float z);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtVector3_setX(IntPtr umv, float x);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtVector3_setY(IntPtr umv, float y);
|
||||
[DllImport(Native.Dll), SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtVector3_setZ(IntPtr umv, float z);
|
||||
[DllImport(Native.Dll),SuppressUnmanagedCodeSecurity]
|
||||
static extern void BulletAPI_BtVector3_delete(IntPtr umv);
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// none yet
|
||||
}
|
||||
// Release unmanaged resources. If disposing is false,
|
||||
// only the following code is executed.
|
||||
BulletAPI_BtVector3_delete(m_handle);
|
||||
m_handle = IntPtr.Zero;
|
||||
// Note that this is not thread safe.
|
||||
// Another thread could start disposing the object
|
||||
// after the managed resources are disposed,
|
||||
// but before the disposed flag is set to true.
|
||||
// If thread safety is necessary, it must be
|
||||
// implemented by the client.
|
||||
|
||||
}
|
||||
m_disposed = true;
|
||||
}
|
||||
|
||||
~btVector3()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
Free for commercial use, but please mail bullet@erwincoumans.com to report projects, and join the forum at
|
||||
www.continuousphysics.com/Bullet/phpBB2
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,71 @@
|
||||
cmake_minimum_required(VERSION 2.4)
|
||||
|
||||
PROJECT(BULLET_PHYSICS)
|
||||
SET(BULLET_VERSION 2.74)
|
||||
|
||||
IF (NOT CMAKE_BUILD_TYPE)
|
||||
# SET(CMAKE_BUILD_TYPE "Debug")
|
||||
SET(CMAKE_BUILD_TYPE "Release")
|
||||
ENDIF (NOT CMAKE_BUILD_TYPE)
|
||||
|
||||
|
||||
|
||||
IF(COMMAND cmake_policy)
|
||||
cmake_policy(SET CMP0003 NEW)
|
||||
ENDIF(COMMAND cmake_policy)
|
||||
|
||||
|
||||
# This is the shortcut to finding GLU, GLUT and OpenGL if they are properly installed on your system
|
||||
# This should be the case.
|
||||
|
||||
FIND_PACKAGE(OpenGL)
|
||||
IF (OPENGL_FOUND)
|
||||
MESSAGE("OPENGL FOUND")
|
||||
MESSAGE(${OPENGL_LIBRARIES})
|
||||
ELSE (OPENGL_FOUND)
|
||||
MESSAGE("OPENGL NOT FOUND")
|
||||
SET(OPENGL_gl_LIBRARY opengl32)
|
||||
SET(OPENGL_glu_LIBRARY glu32)
|
||||
ENDIF (OPENGL_FOUND)
|
||||
|
||||
# ADD_DEFINITIONS(-DBT_USE_FREEGLUT)
|
||||
|
||||
FIND_PACKAGE(GLU)
|
||||
|
||||
FIND_PACKAGE(GLUT)
|
||||
IF (GLUT_FOUND)
|
||||
MESSAGE("GLUT FOUND")
|
||||
MESSAGE(${GLUT_glut_LIBRARY})
|
||||
ELSE (GLUT_FOUND)
|
||||
|
||||
IF (MINGW)
|
||||
MESSAGE ("GLUT NOT FOUND not found, trying to use MINGW glut32")
|
||||
SET(GLUT_glut_LIBRARY glut32)
|
||||
ENDIF (MINGW)
|
||||
|
||||
IF (MSVC)
|
||||
MESSAGE ("GLUT NOT FOUND, trying to use Bullet/Glut/glut32.lib for MSVC")
|
||||
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Glut/glut32.lib)
|
||||
ENDIF (MSVC)
|
||||
ENDIF (GLUT_FOUND)
|
||||
|
||||
|
||||
IF (WIN32)
|
||||
INCLUDE_DIRECTORIES(${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
ELSE (WIN32)
|
||||
# This is the lines for linux. This should always work if everything is installed and working fine.
|
||||
INCLUDE_DIRECTORIES(/usr/include /usr/local/include ${GLUT_INCLUDE_DIR})
|
||||
ENDIF (WIN32)
|
||||
|
||||
|
||||
OPTION(BUILD_DEMOS "Set when you want to build the demos" ON)
|
||||
IF(BUILD_DEMOS)
|
||||
SUBDIRS(Demos)
|
||||
ENDIF(BUILD_DEMOS)
|
||||
|
||||
OPTION(BUILD_EXTRAS "Set when you want to build the extras" ON)
|
||||
IF(BUILD_EXTRAS)
|
||||
SUBDIRS(Extras)
|
||||
ENDIF(BUILD_EXTRAS)
|
||||
|
||||
SUBDIRS(src)
|
||||
@@ -0,0 +1,724 @@
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Primary author and maintainer: Erwin Coumans
|
||||
|
||||
Todo: update changelog from April - July 2008
|
||||
See http://code.google.com/p/bullet/source/list for more complete log in Subversion
|
||||
|
||||
2008 December 2
|
||||
- Fix contact refresh issues with btCompoundShape, introduced with btDbvt acceleration structure in btCompoundCollisionAlgorithm
|
||||
- Made btSequentialImpulseConstraintSolver 100% compatible with ODE quickstep
|
||||
constraints can use 'solveConstraint' method or 'getInfo/getInfo2'
|
||||
|
||||
2008 November 30
|
||||
- Add highly optimized SIMD branchless PGS/SI solver innerloop
|
||||
|
||||
2008 November 12
|
||||
- Add compound shape export to BulletColladaConverter
|
||||
Thanks to JamesH for the report: http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=12&t=2840
|
||||
- Fix compiler build for Visual Studio 6
|
||||
Thanks to JoF for the report: http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2841
|
||||
|
||||
2008 November 11
|
||||
- Add CProfileManager::dumpAll() to dump performance statistics to console using printf.
|
||||
- Add support for interaction between btSoftBody and btCollisionObject/btGhostObject
|
||||
|
||||
2008 November 8
|
||||
- Fix PosixThreadSupport
|
||||
- Add improved btHeightfieldTerrainShape support and new Demos/TerrainDemo
|
||||
Thanks to tomva, http://code.google.com/p/bullet/issues/detail?id=63&can=1
|
||||
- Moved kinematic character controller from Demos/CharacterDemo into src/BulletDynamics/Character/btKinematicCharacterController.cpp
|
||||
|
||||
2008 November 6
|
||||
- reduced default memory pool allocation from 40Mb to 3Mb. This should be more suitable for all platforms, including iPhone
|
||||
- improved CUDA broadphase
|
||||
- IBM Cell SDK 3.x support, fix ibmsdk Makefiles
|
||||
- improved CMake support with 'install' and 'framework option
|
||||
|
||||
2008 November 4
|
||||
- add btAxisSweep::resetPool to avoid non-determinism due to shuffled linked list
|
||||
Thanks to Ole for the contribution,
|
||||
|
||||
2008 October 30
|
||||
- disabled btTriangleMesh duplicate search by default, it is extremely slow
|
||||
- added Extras/IFF binary chunk serialization library as preparation for in-game native platform serialization (planned COLLADA DOM -> IFF converter)
|
||||
|
||||
2008 October 20
|
||||
- added SCE Physics Effects box-box collision detection for SPU/BulletMultiThreaded version
|
||||
See Bullet/src/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/boxBoxDistance.cpp
|
||||
Thanks to Sony Computer Entertainment Japan, SCEI for the contribution
|
||||
|
||||
2008 October 17
|
||||
- Added btGhostObject support, this helps character controller, explosions, triggers and other local spatial queries
|
||||
|
||||
2008 October 10
|
||||
- Moved aabb to btBroadphaseProxy, improves rayTest dramatically. Further raytest improvements using the broadphase acceleration structures are planned
|
||||
- Moved BulletMultiThreaded from Extras to /src/BulletMultiThreaded for better integration
|
||||
|
||||
|
||||
2008 October 3
|
||||
- Add support for autoconf automake
|
||||
./autogen.sh and ./configure will create both Makefile and Jamfile. CMake and autogenerated Visual Studio projectfiles remain supported too.
|
||||
- Improved ColladaConverter: plane shape export, and callback for shape construction to allow deletion of memory
|
||||
|
||||
2008 Sept 30
|
||||
- Improved Soft Body support, fixed issues related to soft body colliding against concave triangle meshes
|
||||
- Shared more code between regular version and SPU/BulletMultiThreaded, in particular GJK/EPA
|
||||
|
||||
2008 Sept 28
|
||||
- Fixed rotation issues in Dynamic Maya Plugin
|
||||
|
||||
2008 Sept 11
|
||||
- Enable CCD motion clamping for btDiscreteDynamicsWorld, to avoid tunneling. A more advanced solution will be implemented in btContinuousDynamicsWorld.
|
||||
|
||||
2008 Sept 7
|
||||
- Add btScaledBvhTriangleMeshShape, to allow re-use of btBvhTriangleMeshShape of different sizes, without copying of the BVH data.
|
||||
|
||||
2008 Sept 5
|
||||
- Enabled Demos/ForkLiftDemo
|
||||
Thanks Roman Ponomarev.
|
||||
|
||||
2008 Sept 4
|
||||
- Added btCudaBroadphase in Extras/CUDA: some research into accelerating Bullet using CUDA.
|
||||
Thanks to the particle demo from the NVidia CUDA SDK.
|
||||
|
||||
2008 Sept 3
|
||||
- Several bug fixes and contributions related to inertia tensor, memory leaks etc.
|
||||
Thanks to Ole K.
|
||||
|
||||
2008 Sept 1
|
||||
- Updated CDTestFramework, with latest version of OPCODE Array SAP. See Extras/CDTestFramework
|
||||
Thanks to Pierre Terdiman for the update
|
||||
|
||||
2008 August 25
|
||||
- Walt Disney Studios contributes their in-house Maya Plugin for simulating Bullet physics, with options for other engines such as PhysBam or PhysX.
|
||||
Thanks to Nicola Candussi and Arthur Shek
|
||||
|
||||
2008 August 14
|
||||
- Improved performance for btDbvtBroadphase, based on dual dynamic AABB trees (one for static, one for dynamic objects, where objects can move from one to the other tree)
|
||||
Thanks to Nathanael Presson again, for all his work.
|
||||
|
||||
2008 July 31
|
||||
- Added Havok .hkx to COLLADA Physics .dae converter patch+information
|
||||
- Fix btSubsimplexConvexCast
|
||||
Thanks to Nacho, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2422)
|
||||
- Fix in rendering, GL_STENCIL
|
||||
- btTriangleIndexVertexArray indices should be unsigned int/unsigned short int,
|
||||
- Made InternalProcessAllTriangles virtual, thanks to
|
||||
Both thank to Fullmetalcoder, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2401
|
||||
- clamp impulse for btPoint2PointConstraint
|
||||
Thanks to Martijn Reuvers, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2418
|
||||
- Free memory of bvh, pass in scaling factor (optional)
|
||||
Thanks to Roy Eltham, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2375
|
||||
|
||||
2008 July 27
|
||||
|
||||
btDbvtBroadphase:
|
||||
- Fixed a performance issues reported by 'reltham'
|
||||
- Added btDbvtBroadphase::optimize() for people who want good performances right
|
||||
away or don't do dynamics.
|
||||
- fixed compilation issues when DBVT_BP_PROFILE was set.
|
||||
btSoftBody:
|
||||
- Fixed singular matrix issues related to polar decomposition (flat meshes).
|
||||
DemoApplication:
|
||||
- Shadows (enable/disable through 'g' or DemoApplication::setShadows(bool)).
|
||||
- Texture can be enable/disable through 'u'
|
||||
CDFramework:
|
||||
- fixed compilation issues.
|
||||
All thanks to Nathanael Presson
|
||||
|
||||
2008 July 10
|
||||
- Added btMultimaterialTriangleMeshShape and MultiMaterialDemo
|
||||
Thanks to Alex Silverman for the contribution
|
||||
|
||||
2008 June 30
|
||||
- Added initial support for kinematic character controller
|
||||
Thanks to John McCutchan
|
||||
|
||||
2008 April 14
|
||||
- Added ray cast support for Soft Bodies
|
||||
Thanks to Nathanael Presson for the contribution
|
||||
|
||||
2008 April 9
|
||||
- Cleanup of Stan Melax ConvexHull, removed Extras/ConvexHull, moved sources into LinearMath/BulletCollision
|
||||
|
||||
2008 April 4
|
||||
- Added btSliderConstraint and demo
|
||||
Thanks Roman Ponomarev
|
||||
|
||||
2008 April 3
|
||||
- Fixed btMinkowskiSumShape, and added hitpoint to btSubsimplexConvexCast
|
||||
|
||||
2008 April 2
|
||||
- Added Extras/CdTestFrameWork
|
||||
Thanks Pierre Terdiman
|
||||
|
||||
2008 April 1
|
||||
- Added posix thread (pthread) support
|
||||
Thanks Enrico
|
||||
|
||||
2008 March 30
|
||||
- Added Soft Body, cloth, rope and deformable volumes, including demos and interaction
|
||||
Thanks Nathanael Presson for this great contribution
|
||||
|
||||
2008 March 17
|
||||
- Improved BulletColladaConverter
|
||||
Thanks John McCutchan
|
||||
|
||||
2008 March 15
|
||||
- btMultiSapBroadphase in a working state. Needs more optimizations to be fully useable.
|
||||
- Allow btOptimizedBvh to be used for arbitrary objects, not just triangles
|
||||
- added quicksort to btAlignedObjectArray
|
||||
- removed btTypedUserInfo, added btHashMap
|
||||
|
||||
2008 March 30
|
||||
- Moved quickstep solver and boxbox into Bullet/src folder
|
||||
Thanks Russell L. Smith for permission to redistribute Open Dynamics Engine quickstep and box-box under the ZLib license
|
||||
|
||||
2008 Feb 27
|
||||
- Added initial version for Character Control Demo
|
||||
- Applied fixes to IBM Cell SDK 3.0 build makefiles
|
||||
Thanks Jochen and mojo for reporting/providing patch: http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1922
|
||||
|
||||
2008 Feb 8
|
||||
- Bugfixes in ConvexCast support against the world.
|
||||
Thanks to Isgmasa for reporting/providing fix: http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1823
|
||||
|
||||
2008 Feb 6
|
||||
- Added btCapsuleShapeX and btCapsuleShapeZ for capsules around X and Z axis (default capsule is around Y)
|
||||
|
||||
2008 Feb 3
|
||||
- Added btTypedUserInfo, useful for serialization
|
||||
|
||||
2008 Jan 31
|
||||
- Add support for 16 and 32-bit indices for SPU / BulletMultiThreaded version.
|
||||
|
||||
2008 Jan 29
|
||||
- Added COLLADA Physics export/serialization/snapshot from any Bullet btDynamicsWorld. Saving the physics world into a text .xml file is useful for debugging etc.
|
||||
|
||||
2008 Jan 23
|
||||
- Added Stan Melax Convex Hull utility library in Extras/ConvexHull. This is useful to render non-polyhedral convex objects, and to simplify convex polyhedra.
|
||||
|
||||
2008 Jan 14
|
||||
- Add support for batch raycasting on SPU / BulletMultiThreaded
|
||||
|
||||
2007 Dec 16
|
||||
- Added btRigidBodyConstructionInfo, to make it easier to set individual setting (and leave other untouched) during rigid body construction.
|
||||
Thanks Vangelis Kokkevis for pointing this out.
|
||||
- Fixed memoryleak in the ConstraintDemo and Raytracer demo.
|
||||
- Fixed issue with clearing forces/gravity at the end of the stepSimulation, instead of during internalSingleStepSimulation.
|
||||
Thanks chunky for pointing this out: http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1780
|
||||
- Disabled additional damping in rigid body by default, but enable it in most demos. Set btRigidBodyConstructionInfo m_additionalDamping to true to enable this.
|
||||
- Removed obsolete QUICKPROF BEGIN/END_PROFILE, and enabled BT_PROFILE. Profiling is enabled by default (see Bullet/Demos/OpenGL/DemoApplication.cpp how to use this).
|
||||
User can switch off profiling by enabling define BT_NO_PROFILE in Bullet/src/btQuickprof.h.
|
||||
|
||||
2007 Dec 14
|
||||
- Added Hello World and BulletMultiThreaded demos
|
||||
- Add portable version of BulletMultiThreaded, through SequentialThreadSupport (non-parallel but sharing the same code-path)
|
||||
- Add Cmake support for AllBulletDemos
|
||||
|
||||
|
||||
2007 Dec 11
|
||||
- Moved the 'btRigidBody::clearForce' to the end of the stepSimulation, instead of in each substep.
|
||||
See discussion http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1601
|
||||
- Added btConvexPlaneCollisionAlgorithm, makes planes perform better, and prevents tunneling
|
||||
Thanks Andy O'Neil for reporting the performance/functionality issue
|
||||
- Fixes for IBM Cell SDK 3.0
|
||||
Thanks to Jochen Roth for the patch.
|
||||
|
||||
2007 Dec 10
|
||||
- Fixes in btHeightfieldTerrainShape
|
||||
Thanks to Jay Lee for the patch.
|
||||
|
||||
2007 Dec 9
|
||||
- Only update aabb of active objects
|
||||
Thanks Peter Tchernev for reporting (http://bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1764 )
|
||||
- Added workaround to compile libxml under Visual Studio 2008 Beta 2
|
||||
- Make glui compile under MSVC 9.0 beta (vsnprintf is already defined)
|
||||
|
||||
2007 Dec 6
|
||||
- Added DynamicControlDemo, showing dynamic control through constraint motors
|
||||
Thanks to Eddy Boxerman
|
||||
- Add support for generic concave shapes for convex cast.
|
||||
- Added convex cast query to collision world.
|
||||
- Added workaround for OpenGL bug in Mac OS X 10.5.0 (Leopard)
|
||||
- Added concave raycast demo
|
||||
All above thanks to John McCutchan (JMC)
|
||||
- Fixed issues that prevent Linux version to compile.
|
||||
Thanks to Enrico for reporting and patch, see
|
||||
- Fixed misleading name 'numTriangleIndices' into 'numTriangles'
|
||||
Thanks Sean Tasker for reporting:
|
||||
|
||||
2007 Nov 28:
|
||||
- Added raycast against trianglemesh. Will be extended to object cast soon.
|
||||
Thanks John McCutchan (JMC)
|
||||
- make getNumPoints const correct, add const getPoints().
|
||||
Thanks Dirk Gregorius
|
||||
- Bugfix: allow btCollisionObjects (non-btRigidBody) to interact properly with btRigidBody for cache-friendly btSequentialImpulseConstraintSolver.
|
||||
Thanks Andy O'Neil for pointing this out.
|
||||
- Bugfix: don't fail if spheres have identical center, use arbitrary separating normal (1,0,0)
|
||||
Thanks Sean Tasker for reporting! http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1681
|
||||
|
||||
|
||||
2007, November 20
|
||||
- Added hierarchical profiling
|
||||
- Fixed memory leak in btMultiSapBroadphase,
|
||||
- Fixed hash function (typo, should use 2 proxies)
|
||||
Thanks to Stephen (shatcher) for reporting and fixes! http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1696
|
||||
|
||||
2007 Nov 11
|
||||
- Fixed parallel solver (BulletMultiThreaded) friction issue
|
||||
- Terminate Win32 Threads when closing the CcdPhysicsDemo (when USE_PARALLEL_SOLVER/USE_PARALLEL_DISPATCHER is defined)
|
||||
|
||||
2007 Nov 6
|
||||
- Added support for 16-bit indices for triangle meshes
|
||||
- Added support for multiple mesh parts using btBvhTriangleMeshShape.
|
||||
Thanks to Tim Johansson
|
||||
|
||||
2007 Oct 22
|
||||
- All memory allocations go through btAlignedAlloc/btAlignedFree. User can override this to verify memory leaks
|
||||
- added a few more demos to AllBulletDemos
|
||||
- fix for one of the constructors of btHingeConstraint
|
||||
Thanks Marcus Hennix
|
||||
|
||||
2007 Oct 20
|
||||
- included glui, a GLUT/OpenGL based toolkit for some graphical user elements
|
||||
Removed dynamic_cast from glui, to allow linkage without rtti
|
||||
- added Box2D framework using glui, allowing all demos to run within one executable
|
||||
Thanks Erin Catto for the FrameWork skeleton (http://www.box2d.org)
|
||||
|
||||
2007 Ocy 17
|
||||
- Allow user to pass in their own memory (stack and pool) allocators, through collisionConfiguration. See demos how to use this
|
||||
|
||||
2007 Oct 14
|
||||
- Included working version of Cell SPU parallel optimized version for Libspe2 SPU task scheduler.
|
||||
This version compiles and runs on Playstation 3 Linux and IBM CellBlade, see BulletSpuOptimized.pdf for build instructions
|
||||
(Official Playstation 3 developers can request a SPURS version through Sony PS3 Devnet.)
|
||||
Thanks to IBM 'Extreme Blue' project for the contribution
|
||||
http://www-913.ibm.com/employment/us/extremeblue/
|
||||
Thanks Minh Cuong Tran, Benjamin Hoeferlin, Frederick Roth and Martina Huellmann
|
||||
for various contributions to get this initial Libspe2 parallel version up and running.
|
||||
|
||||
2007 Oct 13
|
||||
- made 'btCollisionShape::calculateLocalInertia' const
|
||||
Thanks to cgripeos, see http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1514
|
||||
- applied a large patch to remove warnings
|
||||
Thanks to Enrico, see http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1568
|
||||
- removed SSE includes, added #incude <string.h> for memset in Extras/quickstep, thanks Eternl Knight
|
||||
|
||||
2007 Oct 11
|
||||
- added Hashed Overlapping Pair Cache, recommended by Pierre Terdiman. It works like a charm, thanks Pierre and Erin Catto (code from Box2D)
|
||||
- modified some margins inside btBoxShape, btCylinderShape and btSphereShape
|
||||
- added cone debug rendering (for cones with x, y and z up-axis)
|
||||
- added improvements for optional Extra/quickstep, thanks to Remotion
|
||||
- some performance improvements for Bullet constraint solver
|
||||
|
||||
2007 Sept 28
|
||||
- upgraded GIMPACT to version 0.3
|
||||
Thanks to Francisco Leon
|
||||
|
||||
2007 Sept 27
|
||||
- added contribution from IBM Extreme Blue project for Libspe2 support. This allow to execute BulletMultiThreaded on Cell SPU under PS3 Linux and Cell Blade. See http://www-913.ibm.com/employment/us/extremeblue
|
||||
Thanks to Minh Cuong Tran, Frederick Roth, Martina Heullmann and Benjamin Hoeferlin.
|
||||
|
||||
2007 Sept 13
|
||||
- Improved btGenericD6Constraint. It can be used to create ragdolls (similar to the new btConeTwistConstraint). See GenericJointDemo
|
||||
- Added support for Bullet constraints in the optional Extras/quickstep ODE solver. See CcdPhysicsDemo, enable #COMPARE_WITH_QUICKSTEP and add libquickstep to the dependencies.
|
||||
For both patches/improvements thanks Francisco Leon/projectileman
|
||||
|
||||
2007 Sept 10
|
||||
- removed union from btQuadWordStorage, it caused issues under certain version of gcc/Linux
|
||||
|
||||
2007 Sept 10
|
||||
- Reverted constraint solver, due to some issues. Need to review the recent memory allocation changes.
|
||||
- Fixed issue with kinematic objects rotating at low speed: quaternion was de-normalized, passing value > 1 into acosf returns #IND00 invalid values
|
||||
- 16 byte memory alignment for BVH serialization
|
||||
- memory cleanup for btPoolAllocator
|
||||
|
||||
2007 Sept 9
|
||||
- Added serialization for BVH/btBvhTriangleMeshShape, including endian swapping. See ConcaveDemo for an example.
|
||||
Thanks to Phil Knight for the contribution.
|
||||
- Fixed issues related to stack allocator/compound collision algorithm
|
||||
Thanks Proctoid, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=18&t=1460
|
||||
- Increase some default memory pool settings, and added a fallback for the constraints solver to use heap memory
|
||||
- Removed accidential testing code in btScalar.h related to operator new.
|
||||
- Enable btAxis3Sweep and bt32BitAxis3Sweep to be linked in at the same time, using template
|
||||
|
||||
2007 Sept 7
|
||||
- Replaced several dynamic memory allocations by stack allocation and pool allocations
|
||||
- Added branch-free quantized aabb bounding box overlap check, works better on Playstation 3 and XBox 360
|
||||
Thanks to Phil Knight. Also see www.cellperformance.com for related articles
|
||||
- Collision algorithms and settings for the memory/stack allocator can be done using btDefaultCollisionConfiguration
|
||||
This is an API change. See demos how to modify existing implementations with a one-liner.
|
||||
- Register several collision algorithms by default (sphere-sphere, sphere-box, sphere-triangle)
|
||||
- Use other traveral method for BVH by default, this improves triangle mesh collision performance.
|
||||
|
||||
2007 Aug 31
|
||||
- fixed MSVC 6 build
|
||||
Thanks Proctoid, http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1375
|
||||
- fixed double precision build issues
|
||||
Thanks Alex Silverman, http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1434
|
||||
|
||||
2007 Aug 24
|
||||
- fixed bug in btMatrix3x3::transposeTimes(const btMatrix3x3& m) const. Luckily it wasn't used in core parts of the library (yet).
|
||||
Thanks to Jay Lee
|
||||
|
||||
2007 Aug 15
|
||||
- fixed bug in Extras/GIMPACT 0.2 related to moving triangle meshes
|
||||
Thanks Thomas, http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1368
|
||||
|
||||
2007 Aug 14
|
||||
- added parallel constraint solver. Works on Playstation 3 Cell SPU and multi core (Win Threads on PC and XBox 360).
|
||||
See Extras/BulletMultiThreaded for SpuSolverTask subfolder and SpuParallelSolver.cpp
|
||||
Thanks Marten Svanfeldt (Starbreeze Studios)
|
||||
- fixed some bugs related to parallel collision detection (Extras/BulletMultiThreaded)
|
||||
Thanks Marten Svanfeldt (Starbreeze Studios)
|
||||
|
||||
2007 Aug 2
|
||||
- added compound and concave-convex (swapped) case for BulletMultiThreaded collision detection, thanks to Marten Svanfeldt
|
||||
- refactored broadphase and overlapping pair cache. This allows performance improvement by combining multiple broadphases. This helps add/remove of large batches of objects and large worlds. See also Pierre Terdiman forum topic:
|
||||
http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1329
|
||||
|
||||
|
||||
2007 July 27
|
||||
- added Ragdoll Demo
|
||||
Thanks to Marten Svanfeldt (Starbreeze Studios)
|
||||
|
||||
- added Vector Math library for SIMD 3D graphics linear algebra (vector, matrix, quaternion)
|
||||
See Bullet/Extras/vectormathlibrary
|
||||
Supports SIMD SSE, PowerPC PPU and Cell SPU (including PS3 Linux and CellBlade), as well as generic portable scalar version
|
||||
Will be used to improve BulletMultiThreaded performance
|
||||
Open Sourced by Sony Computer Entertainment Inc. under the new BSD license
|
||||
- added SIMD math library
|
||||
4-way SIMD for common math functions like atan2f4, cosf4, floorf4, fabsf4, rsqrtf4 etc. Used by Vector Math library under PPU and SPU.
|
||||
Supports PowerPC (PPU) and Cell SPU, including PS3 Linux and CellBlade.
|
||||
See Bullet/Extras/simdmathlibrary
|
||||
Open sourced by Sony Computer Entertainment Inc. under the new BSD license
|
||||
|
||||
|
||||
2007 July 25
|
||||
- added several patches: per-rigidbody sleeping threshold. added Assert to prevent deletion of rigidbody while constraints are still pointing at it
|
||||
Thanks to Marten Svanfeldt (Starbreeze Studios)
|
||||
|
||||
2007 July 13
|
||||
- fixed relative #include paths again. We can't use "../" relative paths: some compilers choke on it (it causes extreme long paths)
|
||||
Within the libraries, we always need to start with "BulletCollision/" or "BulletDynamics/ or "LinearMath/"
|
||||
|
||||
2007 July 10
|
||||
- Updated Bullet User Manual
|
||||
|
||||
2007 July 5
|
||||
- added btConeTwistConstraint, especially useful for ragdolls. See Demos/RagdollDemo
|
||||
Thanks to Marten Svanfeldt (Starbreeze Studios)
|
||||
|
||||
2007 June 29
|
||||
- btHeightfieldTerrainShape: Added heightfield support, with customizations
|
||||
- Upgraded to GIMPACT 0.2, see Extras/GIMPACT and MovingConcaveDemo
|
||||
- Several patches from Marten Svanfeldt (Starbreeze Studios)
|
||||
Improved collision filtering (in broadphase and rigidbody)
|
||||
Improved debug rendering
|
||||
Allow to set collision filter group/mask in addRigidBody
|
||||
|
||||
|
||||
2007 June 15
|
||||
- Changed btAlignedObjectArray to call copy constructor/replacement new for duplication, rather then assignment operator (operator=).
|
||||
|
||||
2007 June 11
|
||||
- Added multi-threading. Originally for Playstation 3 Cell SPU, but the same code can run using Win32 Threads using fake DMA transfers (memcpy)
|
||||
Libspe2 support for Cell Blade / PS3 Linux is upcoming
|
||||
See Extras/BulletMultiThreaded. Usage: replace btCollisionDispatcher by btSpuGatheringCollisionDispatcher
|
||||
|
||||
- Added managed Bullet library, entirely rewritten in C# for Windows and XBox 360 XNA
|
||||
See Extras/BulletX
|
||||
Thanks to KleMiX, aka Vsevolod Klementjev
|
||||
|
||||
2007 May 31
|
||||
- sign-bit went wrong in case of 32-bit broadphase, causing quantization problems.
|
||||
Thanks DevO for reporting.
|
||||
|
||||
2007 May 23
|
||||
- Fixed quantization problem for planar triangle meshes in btOptimizedBvh
|
||||
Thanks Phil Knight for reporting and helping to fix this bug.
|
||||
|
||||
2007 May 20
|
||||
- btAxisSweep3: Fixed a bug in btAxisSweep3 (sweep and prune) related to object removal. Only showed up when at least one btStaticPlaneShape was inserted.
|
||||
Thanks tbp for more details on reproducing case.
|
||||
- btAxisSweep3: Fixed issue with full 32bit precision btAxisSweep3 (define BP_USE_FIXEDPOINT_INT_32), it used only 0xffff/65536 for quantization instead of full integer space (0xffffffff)
|
||||
- btRaycastVehicle: Added 'getForwardVector' and getCurrentSpeedKmHour utility functions
|
||||
- Fixed local scaling issues (btConvexTriangleMeshShape, btBvhTriangleMeshShape, removed scaling from btMatrix3x3).
|
||||
Thanks Volker for reporting!
|
||||
- Added second filename search, so that starting BspDemo and ConvexDecompositionDemo from within Visual Studio (without setting the starting path) still works
|
||||
|
||||
2007 April 22
|
||||
- Added braking functionality to btRaycastVehicle
|
||||
- Removed tons of warnings, under MSVC 2005 compilation in -W4
|
||||
|
||||
2007 March 21
|
||||
- Fixed issues: comma at end of enum causes errors for some compilers
|
||||
- Fixed initialization bug in LocalRayResult ( m_localShapeInfo(localShapeInfo) )
|
||||
|
||||
2007 March 20
|
||||
- Added refit tree to quantized stackless tree, and updated ConcaveDemo as example.
|
||||
|
||||
2007 March 17
|
||||
- Added constraint solver optimizations, avoiding cross products during iterations, and gather rigidbody/constraint info in contiguous memory (btSolverBody/btSolverConstraint)
|
||||
- These optimizations don't give large benefit yet, but it has good potential. Turned on by default. Can be switched off using solver->setSolverMode(SOLVER_RANDMIZE_ORDER).
|
||||
- Enabled anti-jitter for rigid bodies. This is experimental, and can be switched off by setting a global (it is experimental so no proper interface) gJitterVelocityDampingFactor = 1.0;
|
||||
- Fixed bug in islandmanifold.heapSort(btPersistentManifoldSortPredicate()); , thanks Noehrgel for reporting this (affected Sun Solaris)
|
||||
|
||||
2007 March 12
|
||||
- Added compile-time toggle between on 16-bit and 32-bit fixed-point SAP broadphase.
|
||||
This allows the number of bodies to exceed 32767
|
||||
- Enable useQuantizedAabbCompression on btTriangleMesh, see ColladaDemo
|
||||
|
||||
2007 March 8
|
||||
- Fixed bug in constraint/island sorting (caused by replacing STL by dedicated btAlignedObjectArray with heapSort)
|
||||
Thanks Clemens Unterkofler for pointing this out!
|
||||
|
||||
2007 March 6
|
||||
- removed STL from the Bullet library: replace std::vector by btAlignedObjectArray. Also removed the std::set for overlapping pair set, and turned it into an overlapping pair array. The SAP only adds objects, never removed. Removal is postponed for during traversal of overlapping pairs (duplicates and non-overlapping pairs are removed during that traversal).
|
||||
- added heap sort and binary search/linear search to btAlignedObjectArray
|
||||
- fixed wrong cast, thanks Hamstray, http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1015
|
||||
|
||||
|
||||
2007 Feb 25
|
||||
- Improved performance of convex collision shapes, cache local AABB instead of recomputation. This fixes issue with very slow performance in larger .bsp levels
|
||||
|
||||
2007 Feb 24
|
||||
- Added compressed/quantized AABB tree, 16 bytes per node, while supporting 32-bit (triangle) indices.
|
||||
Should be faster and smaller then original version (quantized aabb check is done in integer space)
|
||||
Original aabb tree nodes are still supported. They are 44 bytes, with full floating point precision and additional subPart index.
|
||||
- added meter-unit scaling support in ColladaConverter.cpp
|
||||
|
||||
2007 Feb 21
|
||||
- Build system: updated bullet.pc.in library names
|
||||
- Updated EPA comparison integration (missing parameter)
|
||||
|
||||
2007 Jan 04
|
||||
- fixed optimized AABB tree building: in some cases the tree building fails due to unbalanced trees, which generated stack overflow
|
||||
|
||||
2006 Dec 15
|
||||
- added contribution to allow double precision collision detection/dynamics. Define BT_USE_DOUBLE_PRECISION in your project and libraries that include Bullet
|
||||
|
||||
2006 Dec 14
|
||||
- merged contact and non-contact constraint solving into one loop, will improve stability of jointed bodies during collisions
|
||||
- added first draft for hingeConstraint motor
|
||||
|
||||
2006 Dec 8, Erwin Coumans
|
||||
- preparation for SIMD: added btAlignedAllocator and btAlignedObjectArray, to replace stl std::vector, same interface, but compatible with 16 byte alignment
|
||||
- cleaned up dependencies in autogenerated msvc projectfiles
|
||||
- aligned btVector3 on 16 bytes boundary, under win32. see if developers will come up with problems
|
||||
|
||||
2006 Dec 04, Erwin Coumans
|
||||
Added btNearCallback. This is similar to Open Dynamics Engine (ODE) dNearCallback, but important differences:
|
||||
- contact points are persistent (lifetime more then one frame, for warmstarting/incremental contact point management)
|
||||
- continuous collision detection, time of impact
|
||||
Added btRigidBody::isInWorld(), returns true if btRigidBody is inside a btCollisionWorld/btDynamicsWorld derived class
|
||||
Added angularFactor to btRigidbody, this helps some character control (no angular impulse applied)
|
||||
|
||||
|
||||
2006 Nov 28
|
||||
Moved StackAlloc from EPA into LinearMath/btStackAlloc
|
||||
renamed internal class ConcaveShape into btConcaveShape
|
||||
added btHeightfieldTerrainShape (not completed yet)
|
||||
|
||||
2006 Nov 15 Nathanael Presson
|
||||
Added EPA penetration depth algorithm, Expanding Polytope Algorithm
|
||||
Added Pierre Terdiman penetration depth comparison/test DEMO
|
||||
Fixed Bullet's Minkowski sampling penetration depth solver
|
||||
Contributed by Nathanael Presson
|
||||
|
||||
2006 Nov 11 Francisco León Nájera
|
||||
Added GIMPACT trimesh collision detection: concave versus concave,
|
||||
Contributed by Francisco León Nájera
|
||||
|
||||
2006 Nov 2
|
||||
Minor refactoring: btCollisionObject changes from struct into class, added accessor methods
|
||||
Force use of btMotionState to synchronize graphics transform, disabled old btRigidBody constructor that accepts btTransform
|
||||
Renamed treshold into threshold throughout the code
|
||||
|
||||
2006 Oct 30
|
||||
Enable decoupling of physics and graphics framerate using interpolation and internal fixed timestep, based on btMotionState
|
||||
Enabled raycast vehicle demo (still needs tuning)
|
||||
Refresh contact points, even when they are already persistent.
|
||||
Fixed debugDraw colors (thanks pc0de for reporting)
|
||||
Use Dispatcher in ConcaveConvexCollisionAlgorithm (so it uses the registered collision algorithm, not hardcoded convexconcave)
|
||||
Improved performance of constraint solver by precalculating the cross product/impulse arm
|
||||
Added collision comparison code: ODE box-box, also sphere-triangle
|
||||
Added safety check into GJK, and an assert for AABB's that are very large
|
||||
Fixed kinematic support (deriving velocities for animated objects)
|
||||
Updated comparison/optional quickstep solver in Extras
|
||||
UserCollisionAlgorithm demonstrates btTriangleMesh usage (easier trimesh compared to index array version)
|
||||
Removed scaling from btTransform (we only want to deal with rigid transforms)
|
||||
|
||||
2006 Oct 4
|
||||
Fixed minor leak in btOptimizeBVH
|
||||
Cleanup of btRigidBody construction
|
||||
added getW() in btQuaternion
|
||||
assert when setLinearVelocity is called on btRigidBody
|
||||
renamed projectfile library from collada-dom to colladadom (to make VC6 happy)
|
||||
|
||||
2006 Sept 27
|
||||
Big Refactoring: renamed and moved files, create a replacement for CcdPhysicsEnvironment/CcdPhysicsController.
|
||||
All Bullet classes in LinearMath, BulletCollision and BulletDynamics start with bt, and methods start with lowercase.
|
||||
Moved classes into src folder, which is the only include folder needed.
|
||||
Added 2 headerfiles in src: btBulletCollisionCommon.h and btBulletDynamicsCommon.h
|
||||
|
||||
2006 Sept 23
|
||||
Fixed 2 bugs, causing crashes when removing objects. Should do better unit-testing. UnionFind and 3D SAP were involved.
|
||||
|
||||
2006 Sept 19
|
||||
Allow programmable friction and contact solver model. User can register their own functions for several interaction types.
|
||||
Improved performance, and removed hardcoded maximum overlaps (switched from C-array to stl::set)
|
||||
|
||||
2006 Sept 16
|
||||
Added Bullet 2.0 User Manual
|
||||
Allow registration of custom user collision algorithms
|
||||
|
||||
2006 Sept 10
|
||||
Started cleaning up demos
|
||||
|
||||
2006 Sept 4
|
||||
Fixed concave collision bug (caused instability/missing collisions in meshes/compounds)
|
||||
Fixed memoryleak in OptimizedBvh, added RayTestSingle to CollisionWorld
|
||||
Prepared for VehicleDemo
|
||||
Increased Performance (island generation for sleeping objects took too much time)
|
||||
Better COLLADA 1.4.1 physics conformance in ColladaDemo
|
||||
|
||||
2006 August 11
|
||||
Added Quake BspDemo
|
||||
Improved CCD for compound and non-convex objects
|
||||
|
||||
2006 August 10
|
||||
Added per-triangle material (friction/restitution) support for non-convex meshes. See ConcaveDemo for usage.
|
||||
|
||||
2006 August 9
|
||||
Added CMake support (see http://cmake.org)
|
||||
This can autogenerate makefiles, projectfiles cross platform (including MacOS X Xcode )
|
||||
Just run cmake . in the root folder and it will autogenerate build files
|
||||
|
||||
2006 July 26 Erwin Coumans
|
||||
Upgraded to COLLADA-DOM 1.4.1, latest SVN version
|
||||
ColladaDemo can export snapshots to .dae
|
||||
|
||||
2006 July 24 Erwin Coumans
|
||||
Added Compound CollisionShape support
|
||||
(this is still low performance -> requires stackless tree-versus-tree traversal for better performance)
|
||||
|
||||
2006 July 15 Erwin Coumans
|
||||
Added initial support for Parallel execution (collision detection, constraint solving)
|
||||
See ParallelPhysicsEnvironment in Extras\PhysicsInterface\CcdPhysics
|
||||
|
||||
2006 July 10 Erwin Coumans
|
||||
Added MacOS X support (some build issues mainly)
|
||||
|
||||
2006 July 5 Erwin Coumans
|
||||
Improved COLLADA 1.4 physics import, both COLLADA-DOM and FCollada
|
||||
|
||||
2006 June 29 Erwin Coumans
|
||||
Refactoring of the broadphase
|
||||
Moved some optional files to Extras: Algebraic ccd and EPA, quickstep
|
||||
Moved the limits on bodies/overlap to 32k and 65k
|
||||
|
||||
2006 June 25 Erwin Coumans
|
||||
Added basic Collision Filtering, during broadphase
|
||||
Allow adding meshes to the TriangleIndexVertexArray,
|
||||
(input for TriangleMeshShape)
|
||||
Preparation for CompoundShape
|
||||
|
||||
2006 June 19 Erwin Coumans
|
||||
Added support for COLLADA Physics Import.
|
||||
Both jam and Visual Studio can compile ColladaDemo
|
||||
|
||||
2006 June 18 Dirk Gregorius <dirk@dirkgregorius.de>
|
||||
Started implementing Generic6DOF joint and setup basic interface
|
||||
|
||||
|
||||
2006 June 17 Frank Richter <resqu@gmx.ch>
|
||||
Bumped version in configure.ac to 1.5.6 (assuming that "1.5f" is
|
||||
the next version released).
|
||||
Updated files in mk/autoconf and mk/jam with copies from CS; fixes a
|
||||
GLU detection issue on MinGW.
|
||||
Set msvc/bullet_ico.ico as the default application icon.
|
||||
Disabled exceptions for gcc builds.
|
||||
Applied a patch from Michael D. Adams to fix a warning with gcc.
|
||||
2006 jUNE 16 Erwin Coumans
|
||||
Constraints now merge simulation islands.
|
||||
|
||||
2006 May 24
|
||||
Improved GJK accuracy, fixed GjkConvexCast issue, thanks to ~MyXa~ for reporting
|
||||
|
||||
2006 May 19
|
||||
Added restitution support
|
||||
Moved out Friction and Dynamics info from ManifoldPoint (removed logical dependency)
|
||||
Added a void* m_userPersistentData in ManifoldPoint.
|
||||
Added a ContactDestroyedCallback, to allow user to handle destruction of m_userPersistentData
|
||||
|
||||
2006 May 13
|
||||
Fixed some bugs in friction / jacobian calculations. Reported by Dirk Gregorius. Thanks!
|
||||
|
||||
2006 May 9
|
||||
Fixed raycasting filtering
|
||||
Moved repository to SVN at https://svn.sourceforge.net/svnroot/bullet
|
||||
|
||||
2006 April 27
|
||||
Moved raycasting to CollisionWorld, to make it more generic
|
||||
Added basic CCD option in the CcdCollisionDemo
|
||||
Fixed 'noResponse' mode, for triggering rigidbodies (useful for Artificial Intelligence queries)
|
||||
Improved Bullet/ODE sample (in Extras)
|
||||
|
||||
2006 April 10
|
||||
Separating Axis Test (SAT) convex hull collision detector, contribution by Simon Hobbs
|
||||
Added SIMD SSE Math classes (for above SAT)
|
||||
Added Mouse picking in CcdPhysicsDemo
|
||||
Improved penetration depth estimation in MinkowskiPenetrationDepthSolver, both accuracy and performance
|
||||
Added Hinge constraint
|
||||
Added quickprof profiling (see http://sourceforge.net/projects/quickprof )
|
||||
|
||||
2006 March 21 Frank Richter <resqu@gmx.ch>
|
||||
Removed VC manifest files.
|
||||
Removed superfluous "grpplugins" projects.
|
||||
|
||||
2006 March 20 Erwin Coumans
|
||||
Clamped the acculumated impulse rather then intermediate impulse (within the iteration)
|
||||
Use the persistent contacts for reusing the impulse
|
||||
Separated friction and normal solving for better stability
|
||||
Decreased the default number of iterations of the constraint solver from 10 to 4
|
||||
|
||||
2006 March 19 Frank Richter <resqu@gmx.ch>
|
||||
Removed a couple of CSisms from the VC projects.
|
||||
Fixed VC include & lib paths to go to the Addtional* options
|
||||
instead the command line arguments.
|
||||
Added pkgconfig support.
|
||||
|
||||
2006 March 14 Frank Richter <resqu@gmx.ch>
|
||||
Added support for shipped GLUT on MinGW.
|
||||
Fixed GLUT support on MinGW.
|
||||
|
||||
2006 March 13 Frank Richter <resqu@gmx.ch>
|
||||
Bolted on Jam-based build system.
|
||||
Generated VC project files.
|
||||
Fixed GCC warnings.
|
||||
Fixed Linux build issues.
|
||||
|
||||
2006 March 13
|
||||
Added 3D Sweep and Prune Broadphase Collision Detection, Contribution from Simon Hobbs.
|
||||
|
||||
2006 March 2
|
||||
Minor change in license to ZLib/LibPNG
|
||||
This makes it legally a bit easier to deploy on Playstation 3
|
||||
Prepared for more generic constraints, added ConstraintsDemo
|
||||
|
||||
2006 Feb 23
|
||||
Rearranged files and dependencies to allow for easier standalone Collision Detection without Bullet Dynamics.
|
||||
See Demos/CollisionInterfaceDemo and Extras/ode/ode/test/test_BulletGjk.cpp for examples how to use.
|
||||
|
||||
2005 August 6
|
||||
Bullet 0.2 release with demos, sources, doxygen, draft manual
|
||||
|
||||
2005 June 1
|
||||
First public release of Bullet
|
||||
|
||||
|
||||
... todo: add history
|
||||
|
||||
2003 Initial version (continuous collision detection)
|
||||
@@ -0,0 +1,48 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
LINK_DIRECTORIES(
|
||||
"C:/MinGW/lib"
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/BulletColladaConverter ${BULLET_PHYSICS_SOURCE_DIR}/Extras ${BULLET_PHYSICS_SOURCE_DIR}/Extras/GIMPACTUtils ${BULLET_PHYSICS_SOURCE_DIR}/Extras/ConvexDecomposition ${BULLET_PHYSICS_SOURCE_DIR}/Extras/LibXML ${BULLET_PHYSICS_SOURCE_DIR}/Extras/LibXML/include ${BULLET_PHYSICS_SOURCE_DIR}/Extras/COLLADA_DOM/include/1.4 ${BULLET_PHYSICS_SOURCE_DIR}/Extras/COLLADA_DOM/include ${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL }
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
BulletColladaConverter GLUI GIMPACTUtils ConvexDecomposition ColladaDom XML OpenGLSupport BulletSoftBody BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
|
||||
|
||||
ADD_EXECUTABLE(AppAllBulletDemos
|
||||
Main.cpp
|
||||
DemoEntries.cpp
|
||||
../CcdPhysicsDemo/CcdPhysicsDemo.cpp
|
||||
../BasicDemo/BasicDemo.cpp
|
||||
../Benchmarks/BenchmarkDemo.cpp
|
||||
../BspDemo/BspDemo.cpp
|
||||
../BspDemo/BspConverter.cpp
|
||||
../BspDemo/BspLoader.cpp
|
||||
../DynamicControlDemo/MotorDemo.cpp
|
||||
../ConcaveDemo/ConcavePhysicsDemo.cpp
|
||||
../ConcaveRaycastDemo/ConcaveRaycastDemo.cpp
|
||||
../ConcaveConvexcastDemo/ConcaveConvexcastDemo.cpp
|
||||
../ConvexDecompositionDemo/ConvexDecompositionDemo.cpp
|
||||
../SliderConstraintDemo/SliderConstraintDemo.cpp
|
||||
../RagdollDemo/RagdollDemo.cpp
|
||||
../GimpactTestDemo/GimpactTestDemo.cpp
|
||||
../Raytracer/Raytracer.cpp
|
||||
../GjkConvexCastDemo/LinearConvexCastDemo.cpp
|
||||
../ForkLiftDemo/ForkLiftDemo.cpp
|
||||
../SoftDemo/SoftDemo.cpp
|
||||
../ConstraintDemo/ConstraintDemo.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "DemoEntries.h"
|
||||
|
||||
#include "../CcdPhysicsDemo/CcdPhysicsDemo.h"
|
||||
#include "../BspDemo/BspDemo.h"
|
||||
#include "../BasicDemo/BasicDemo.h"
|
||||
#include "../ConcaveDemo/ConcaveDemo.h"
|
||||
#include "../ConcaveRaycastDemo/ConcaveRaycastDemo.h"
|
||||
#include "../ConcaveConvexcastDemo/ConcaveConvexcastDemo.h"
|
||||
#include "../ConvexDecompositionDemo/ConvexDecompositionDemo.h"
|
||||
#include "../DynamicControlDemo/MotorDemo.h"
|
||||
#include "../SliderConstraintDemo/SliderConstraintDemo.h"
|
||||
#include "../RagdollDemo/RagdollDemo.h"
|
||||
#include "../GimpactTestDemo/GimpactTestDemo.h"
|
||||
#include "../Raytracer/Raytracer.h"
|
||||
#include "../GjkConvexCastDemo/LinearConvexCastDemo.h"
|
||||
#include "../ForkLiftDemo/ForkLiftDemo.h"
|
||||
#include "../ConstraintDemo/ConstraintDemo.h"
|
||||
#include "../Benchmarks/BenchmarkDemo.h"
|
||||
#include "../SoftDemo/SoftDemo.h"
|
||||
|
||||
|
||||
#include "GlutStuff.h"//OpenGL stuff
|
||||
#include "BMF_Api.h"//font stuff
|
||||
|
||||
extern int gNumAlignedAllocs;
|
||||
extern int gNumAlignedFree;
|
||||
extern int gTotalBytesAlignedAllocs;
|
||||
|
||||
class btEmptyDebugDemo : public DemoApplication
|
||||
{
|
||||
public:
|
||||
btEmptyDebugDemo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual void clientMoveAndDisplay()
|
||||
{
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
float xOffset = 10.f;
|
||||
float yStart = 20.f;
|
||||
float yIncr = 20.f;
|
||||
char buf[124];
|
||||
|
||||
|
||||
glColor3f(0, 0, 0);
|
||||
|
||||
setOrthographicProjection();
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"gNumAlignedAllocs= %d",gNumAlignedAllocs);
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"gNumAlignedFree= %d",gNumAlignedFree);
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"# alloc-free = %d",gNumAlignedAllocs-gNumAlignedFree);
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
glRasterPos3f(xOffset,yStart,0);
|
||||
sprintf(buf,"gTotalBytesAlignedAllocs = %d",gTotalBytesAlignedAllocs);
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||
yStart += yIncr;
|
||||
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
btEmptyDebugDemo* demo = new btEmptyDebugDemo();
|
||||
demo->myinit();
|
||||
return demo;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
btDemoEntry g_demoEntries[] =
|
||||
{
|
||||
|
||||
{"ConstraintDemo",ConstraintDemo::Create},
|
||||
{"ForkLift Demo",ForkLiftDemo::Create},
|
||||
{"Ragdoll Demo",RagdollDemo::Create},
|
||||
{"Basic Demo", BasicDemo::Create},
|
||||
{"Convex Decomposition",ConvexDecompositionDemo::Create},
|
||||
{"Concave Moving", GimpactConcaveDemo::Create},
|
||||
// {"Dynamic Control Demo",MotorDemo::Create},
|
||||
//{"ConcaveDemo",ConcaveDemo::Create},
|
||||
{"Concave Convexcast Demo",ConcaveConvexcastDemo::Create},
|
||||
// {"SoftBody Cloth",SoftDemo0::Create},
|
||||
|
||||
{"SoftBody Ropes Attach",SoftDemo4::Create},
|
||||
{"SoftBody Cloth Attach",SoftDemo5::Create},
|
||||
{"SoftBody Cluster Collide1",SoftDemo19::Create},
|
||||
// {"SoftBody Volume",SoftDemo2::Create},
|
||||
{"SoftBody Pressure",SoftDemo1::Create},
|
||||
{"SoftBody Cluster Car",SoftDemo24::Create},
|
||||
{"SoftBody Cluster Robot",SoftDemo25::Create},
|
||||
// {"SoftBody Ropes",SoftDemo3::Create},
|
||||
{"SoftBody Sticks",SoftDemo6::Create},
|
||||
// {"SoftBody Collide",SoftDemo7::Create},
|
||||
// {"SoftBody Collide2",SoftDemo8::Create},
|
||||
// {"SoftBody Collide3",SoftDemo9::Create},
|
||||
// {"SoftBody Impact",SoftDemo10::Create},
|
||||
{"SoftBody Aero",SoftDemo11::Create},
|
||||
// {"SoftBody Friction",SoftDemo12::Create},
|
||||
// {"SoftBody Torus",SoftDemo13::Create},
|
||||
// {"SoftBody Torus Match",SoftDemo14::Create},
|
||||
// {"SoftBody Bunny",SoftDemo15::Create},
|
||||
// {"SoftBody Bunny Match",SoftDemo16::Create},
|
||||
{"SoftBody Init Cutting",SoftDemo17::Create},
|
||||
// {"SoftBody Cluster Deform",SoftDemo18::Create},
|
||||
|
||||
// {"SoftBody Cluster Collide2",SoftDemo20::Create},
|
||||
// {"SoftBody Cluster Socket",SoftDemo21::Create},
|
||||
// {"SoftBody Cluster Hinge",SoftDemo22::Create},
|
||||
// {"SoftBody Cluster Combine",SoftDemo23::Create},
|
||||
// {"SoftBody Cluster Stack Soft",SoftDemo26::Create},
|
||||
{"SoftBody Cluster Stack Mixed",SoftDemo27::Create},
|
||||
|
||||
// {"SliderConstraint",SliderConstraintDemo::Create},
|
||||
{"CcdPhysicsDemo", CcdPhysicsDemo::Create},
|
||||
// {"ConcaveRaycastDemo",ConcaveRaycastDemo::Create},
|
||||
//{"BspDemo", BspDemo::Create},
|
||||
// {"Raytracer Test",Raytracer::Create},
|
||||
// {"GjkConvexCast",LinearConvexCastDemo::Create},
|
||||
{"Benchmark 3000 FALL",BenchmarkDemo1::Create},
|
||||
{"Benchmark 1000 STACK",BenchmarkDemo2::Create},
|
||||
{"Benchmark 136 RAGDOLLS",BenchmarkDemo3::Create},
|
||||
{"Benchmark 1000 CONVEX",BenchmarkDemo4::Create},
|
||||
{"Benchmark Mesh-Prim",BenchmarkDemo5::Create},
|
||||
{"Benchmark Mesh-Convex",BenchmarkDemo6::Create},
|
||||
{"Benchmark Raycast",BenchmarkDemo7::Create},
|
||||
|
||||
{"MemoryLeak Checker",btEmptyDebugDemo::Create},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_DEMO_ENTRIES_H
|
||||
#define BT_DEMO_ENTRIES_H
|
||||
|
||||
|
||||
class DemoApplication;
|
||||
|
||||
typedef DemoApplication* DemoCreateFcn();
|
||||
|
||||
struct btDemoEntry
|
||||
{
|
||||
const char *name;
|
||||
DemoCreateFcn *createFcn;
|
||||
};
|
||||
|
||||
extern btDemoEntry g_demoEntries[];
|
||||
|
||||
|
||||
|
||||
#endif //BT_DEMO_ENTRIES_H
|
||||
@@ -0,0 +1,24 @@
|
||||
SubDir TOP Demos AllBulletDemos ;
|
||||
|
||||
FrameWorkDemo AllBulletDemos :
|
||||
[ Wildcard *.h *.cpp ]
|
||||
../CcdPhysicsDemo/CcdPhysicsDemo.cpp
|
||||
../BasicDemo/BasicDemo.cpp
|
||||
../Benchmarks/BenchmarkDemo.cpp
|
||||
../BspDemo/BspDemo.cpp
|
||||
../BspDemo/BspConverter.cpp
|
||||
../BspDemo/BspLoader.cpp
|
||||
../DynamicControlDemo/MotorDemo.cpp
|
||||
../ConcaveDemo/ConcavePhysicsDemo.cpp
|
||||
../ConcaveRaycastDemo/ConcaveRaycastDemo.cpp
|
||||
../ConcaveConvexcastDemo/ConcaveConvexcastDemo.cpp
|
||||
../ConvexDecompositionDemo/ConvexDecompositionDemo.cpp
|
||||
../RagdollDemo/RagdollDemo.cpp
|
||||
../SliderConstraintDemo/SliderConstraintDemo.cpp
|
||||
../GimpactTestDemo/GimpactTestDemo.cpp
|
||||
../Raytracer/Raytracer.cpp
|
||||
../GjkConvexCastDemo/LinearConvexCastDemo.cpp
|
||||
../ForkLiftDemo/ForkLiftDemo.cpp
|
||||
../SoftDemo/SoftDemo.cpp
|
||||
../ConstraintDemo/ConstraintDemo.cpp
|
||||
;
|
||||
@@ -0,0 +1,534 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "glui/GL/glui.h"
|
||||
#include "LinearMath/btScalar.h"
|
||||
#include "LinearMath/btMinMax.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
|
||||
#include "DemoApplication.h"
|
||||
#include "DemoEntries.h"
|
||||
#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
int testIndex=1;
|
||||
int testSelection=0;
|
||||
btDemoEntry* entry;
|
||||
DemoApplication* demo;
|
||||
int iterationCount;
|
||||
int width;
|
||||
int height;
|
||||
int framePeriod;//todo: test if this value should be 0
|
||||
int mainWindow;
|
||||
GLUI *glui;
|
||||
float hz;
|
||||
float viewZoom=20.f;
|
||||
float viewX;
|
||||
float viewY;
|
||||
int tx, ty, tw, th;
|
||||
int gDrawAabb;
|
||||
int gWireFrame;
|
||||
int gHelpText;
|
||||
int gDebugConstraints;
|
||||
int gDebugContacts;
|
||||
int gDrawTextures=1;
|
||||
int gDrawShadows=0;
|
||||
int gDrawClusters=0;
|
||||
int gDebugNoDeactivation;
|
||||
int gUseWarmstarting;
|
||||
int gRandomizeConstraints;
|
||||
int gUseSplitImpulse;
|
||||
float gErp;
|
||||
float gSlop;
|
||||
float gErp2;
|
||||
float gWarmStartingParameter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setDefaultSettings()
|
||||
{
|
||||
viewX = 0.0f;
|
||||
viewY = 0.0f;
|
||||
framePeriod = 6;//16;//16;//todo: test if this value should be 0
|
||||
|
||||
width = 800;//640;
|
||||
height = 600;//1024;//480;
|
||||
iterationCount = 10;
|
||||
gDrawAabb=0;
|
||||
gWireFrame=0;
|
||||
gDebugContacts=0;
|
||||
//enable constraint debug visualization for first demo, only if user hasn't overridden the setting
|
||||
if (testSelection>1)
|
||||
{
|
||||
gDebugConstraints=0;
|
||||
} else
|
||||
{
|
||||
gDebugConstraints=1;
|
||||
}
|
||||
gHelpText = 0;
|
||||
gDrawTextures=1;
|
||||
gDrawShadows=0;
|
||||
gDrawClusters=0;
|
||||
|
||||
gDebugNoDeactivation = 0;
|
||||
gUseSplitImpulse = 0;
|
||||
gUseWarmstarting = 1;
|
||||
gRandomizeConstraints = 1;
|
||||
gErp = 0.2f;
|
||||
gSlop=0.0f;
|
||||
gErp2 = 0.1f;
|
||||
gWarmStartingParameter = 0.85f;
|
||||
|
||||
}
|
||||
|
||||
void setDefaultSettingsAndSync()
|
||||
{
|
||||
setDefaultSettings();
|
||||
glui->sync_live();
|
||||
}
|
||||
|
||||
|
||||
void TogglePause()
|
||||
{
|
||||
if (demo)
|
||||
demo->toggleIdle();
|
||||
}
|
||||
|
||||
void ResetScene()
|
||||
{
|
||||
if (demo)
|
||||
demo->clientResetScene();
|
||||
}
|
||||
|
||||
void NextScene()
|
||||
{
|
||||
testSelection++;
|
||||
if (testSelection>1)
|
||||
{
|
||||
gDebugConstraints=0;
|
||||
} else
|
||||
{
|
||||
gDebugConstraints=1;
|
||||
}
|
||||
|
||||
if(testSelection>23)
|
||||
testSelection=0;
|
||||
if (glui)
|
||||
glui->sync_live();
|
||||
}
|
||||
|
||||
|
||||
void SingleSimulationStep()
|
||||
{
|
||||
if (demo)
|
||||
demo->clientMoveAndDisplay();
|
||||
}
|
||||
|
||||
|
||||
void Resize(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
|
||||
GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
|
||||
glViewport( tx, ty, tw, th );
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
if (demo)
|
||||
demo->reshape(tw, th);
|
||||
}
|
||||
|
||||
DemoApplication* CreatDemo(btDemoEntry* entry)
|
||||
{
|
||||
DemoApplication* demo = entry->createFcn();
|
||||
btAssert(demo);
|
||||
if (demo->getDynamicsWorld())
|
||||
{
|
||||
demo->getDynamicsWorld()->setDebugDrawer(new GLDebugDrawer());
|
||||
gDrawTextures = demo->getTexturing();
|
||||
gDrawShadows = demo->getShadows();
|
||||
if (glui)
|
||||
glui->sync_live();
|
||||
}
|
||||
|
||||
#ifndef BT_NO_PROFILE
|
||||
CProfileManager::Reset();
|
||||
#endif //BT_NO_PROFILE
|
||||
|
||||
return demo;
|
||||
|
||||
}
|
||||
|
||||
/*b2Vec2 ConvertScreenToWorld(int x, int y)
|
||||
{
|
||||
b2Vec2 p;
|
||||
|
||||
float ratio = float(tw) / float(th);
|
||||
float u = x / float(tw);
|
||||
float v = (th - y) / float(th);
|
||||
p.x = viewZoom * (viewX - ratio) * (1.0f - u) + viewZoom * (ratio + viewX) * u;
|
||||
p.y = viewZoom * (viewY - 0.1f) * (1.0f - v) + viewZoom * (viewY + 1.9f) * v;
|
||||
return p;
|
||||
}
|
||||
*/
|
||||
|
||||
// This is used to control the frame rate (60Hz).
|
||||
void Timer(int)
|
||||
{
|
||||
glutSetWindow(mainWindow);
|
||||
glutPostRedisplay();
|
||||
glutTimerFunc(framePeriod, Timer, 0);
|
||||
}
|
||||
|
||||
void SimulationLoop()
|
||||
{
|
||||
Resize(width, height);
|
||||
|
||||
|
||||
|
||||
if (gDrawAabb)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_DrawAabb);
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_DrawAabb));
|
||||
}
|
||||
if (gWireFrame)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_DrawWireframe);
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_DrawWireframe));
|
||||
|
||||
}
|
||||
if (gHelpText)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_NoHelpText));
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_NoHelpText);
|
||||
}
|
||||
if (gDebugConstraints)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_DrawConstraints+btIDebugDraw::DBG_DrawConstraintLimits);
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_DrawConstraints+btIDebugDraw::DBG_DrawConstraintLimits));
|
||||
}
|
||||
if (gDebugContacts)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_DrawContactPoints);
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_DrawContactPoints));
|
||||
}
|
||||
|
||||
demo->setTexturing(0!=gDrawTextures);
|
||||
demo->setShadows(0!=gDrawShadows);
|
||||
demo->setDrawClusters(0!=gDrawClusters);
|
||||
|
||||
if (gDebugNoDeactivation)
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() |btIDebugDraw::DBG_NoDeactivation);
|
||||
} else
|
||||
{
|
||||
demo->setDebugMode(demo->getDebugMode() & (~btIDebugDraw::DBG_NoDeactivation));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getWorldType() == BT_DISCRETE_DYNAMICS_WORLD)
|
||||
{
|
||||
btDiscreteDynamicsWorld* discreteWorld = (btDiscreteDynamicsWorld*) demo->getDynamicsWorld();
|
||||
discreteWorld->getSolverInfo().m_numIterations = iterationCount;
|
||||
discreteWorld->getSolverInfo().m_erp = gErp;
|
||||
discreteWorld->getSolverInfo().m_erp2 = gErp2;
|
||||
|
||||
discreteWorld->getSolverInfo().m_linearSlop = gSlop;
|
||||
|
||||
discreteWorld->getSolverInfo().m_warmstartingFactor = gWarmStartingParameter;
|
||||
discreteWorld->getSolverInfo().m_splitImpulse = gUseSplitImpulse;
|
||||
|
||||
btSequentialImpulseConstraintSolver* solver = ((btSequentialImpulseConstraintSolver*) discreteWorld->getConstraintSolver());
|
||||
|
||||
if (gUseWarmstarting)
|
||||
{
|
||||
discreteWorld->getSolverInfo().m_solverMode |= SOLVER_USE_WARMSTARTING;
|
||||
} else
|
||||
{
|
||||
discreteWorld->getSolverInfo().m_solverMode &= (~SOLVER_USE_WARMSTARTING);
|
||||
}
|
||||
if (gRandomizeConstraints)
|
||||
{
|
||||
discreteWorld->getSolverInfo().m_solverMode |= SOLVER_RANDMIZE_ORDER;
|
||||
} else
|
||||
{
|
||||
discreteWorld->getSolverInfo().m_solverMode &= (~SOLVER_RANDMIZE_ORDER);
|
||||
}
|
||||
}
|
||||
|
||||
if (!demo->isIdle())
|
||||
{
|
||||
demo->clientMoveAndDisplay();
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
demo->displayCallback();
|
||||
}
|
||||
if (testSelection != testIndex)
|
||||
{
|
||||
if (testSelection>1)
|
||||
{
|
||||
gDebugConstraints=0;
|
||||
} else
|
||||
{
|
||||
gDebugConstraints=1;
|
||||
}
|
||||
|
||||
testIndex = testSelection;
|
||||
if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getDebugDrawer())
|
||||
delete demo->getDynamicsWorld()->getDebugDrawer();
|
||||
delete demo;
|
||||
entry = g_demoEntries + testIndex;
|
||||
demo = CreatDemo(entry);
|
||||
viewZoom = 20.0f;
|
||||
viewX = 0.0f;
|
||||
viewY = 0.0f;
|
||||
Resize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
void RestartScene()
|
||||
{
|
||||
if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getDebugDrawer())
|
||||
delete demo->getDynamicsWorld()->getDebugDrawer();
|
||||
delete demo;
|
||||
entry = g_demoEntries + testIndex;
|
||||
demo = CreatDemo(entry);
|
||||
viewZoom = 20.0f;
|
||||
viewX = 0.0f;
|
||||
viewY = 0.0f;
|
||||
Resize(width, height);
|
||||
}
|
||||
|
||||
void Keyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case 27:
|
||||
exit(0);
|
||||
break;
|
||||
|
||||
// Press 'r' to reset.
|
||||
case 'r':
|
||||
if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getDebugDrawer())
|
||||
delete demo->getDynamicsWorld()->getDebugDrawer();
|
||||
delete demo;
|
||||
demo = CreatDemo(entry);
|
||||
Resize(width,height);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (demo)
|
||||
{
|
||||
demo->keyboardCallback(key,x,y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardSpecialUp(int key, int x, int y)
|
||||
{
|
||||
if (demo)
|
||||
{
|
||||
demo->specialKeyboardUp(key,x,y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void KeyboardSpecial(int key, int x, int y)
|
||||
{
|
||||
|
||||
if (demo)
|
||||
{
|
||||
demo->specialKeyboard(key,x,y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Mouse(int button, int state, int x, int y)
|
||||
{
|
||||
if (demo)
|
||||
demo->mouseFunc(button,state,x,y);
|
||||
}
|
||||
|
||||
void MouseMotion(int x, int y)
|
||||
{
|
||||
demo->mouseMotionFunc(x,y);
|
||||
}
|
||||
|
||||
#ifdef BT_USE_FREEGLUT
|
||||
#include "GL/freeglut_ext.h"
|
||||
#endif
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
//#define CHECK_FPU_EXCEPTIONS 1
|
||||
#ifdef CHECK_FPU_EXCEPTIONS
|
||||
|
||||
int cw = _control87(0, 0);
|
||||
|
||||
// Set the exception masks off, turn exceptions on
|
||||
cw &= ~(EM_ZERODIVIDE | EM_INVALID);
|
||||
|
||||
printf("control87 = %#x\n", cw);
|
||||
|
||||
// Set the control word
|
||||
_control87(cw, MCW_EM);
|
||||
#endif //CHECK_FPU_EXCEPTIONS
|
||||
|
||||
|
||||
setDefaultSettings();
|
||||
|
||||
int bulletVersion = btGetVersion();
|
||||
printf("Bullet version %d\n",bulletVersion);
|
||||
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE |GLUT_DEPTH | GLUT_STENCIL);
|
||||
glutInitWindowSize(width, height);
|
||||
mainWindow = glutCreateWindow("http://bulletphysics.com");
|
||||
#ifdef BT_USE_FREEGLUT
|
||||
glutSetOption (GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
|
||||
#endif
|
||||
entry = g_demoEntries + testIndex;
|
||||
demo = CreatDemo(entry);
|
||||
|
||||
glutDisplayFunc(SimulationLoop);
|
||||
GLUI_Master.set_glutReshapeFunc(Resize);
|
||||
GLUI_Master.set_glutKeyboardFunc(Keyboard);
|
||||
GLUI_Master.set_glutSpecialFunc(KeyboardSpecial);
|
||||
GLUI_Master.set_glutSpecialUpFunc(KeyboardSpecialUp);
|
||||
GLUI_Master.set_glutMouseFunc(Mouse);
|
||||
glutMotionFunc(MouseMotion);
|
||||
|
||||
|
||||
glui = GLUI_Master.create_glui_subwindow( mainWindow,
|
||||
GLUI_SUBWINDOW_RIGHT );
|
||||
|
||||
|
||||
|
||||
glui->add_statictext("Tests");
|
||||
GLUI_Listbox* testList =
|
||||
glui->add_listbox("", &testSelection);
|
||||
glui->add_button("Next Scene", 0,(GLUI_Update_CB)NextScene);
|
||||
|
||||
glui->add_separator();
|
||||
|
||||
GLUI_Spinner* iterationSpinner =
|
||||
glui->add_spinner("Iterations", GLUI_SPINNER_INT, &iterationCount);
|
||||
iterationSpinner->set_int_limits(1, 250);
|
||||
|
||||
/* GLUI_Spinner* hertzSpinner =
|
||||
glui->add_spinner("Hertz", GLUI_SPINNER_FLOAT, &hz);
|
||||
hertzSpinner->set_float_limits(5.0f, 200.0f);
|
||||
*/
|
||||
|
||||
|
||||
glui->add_checkbox("DisableDeactivation", &gDebugNoDeactivation);
|
||||
glui->add_checkbox("Split Impulse", &gUseSplitImpulse);
|
||||
GLUI_Spinner* spinner = 0;
|
||||
|
||||
spinner = glui->add_spinner("ERP", GLUI_SPINNER_FLOAT, &gErp);
|
||||
// spinner->set_float_limits(0.f,1.f);
|
||||
// spinner = glui->add_spinner("ERP2", GLUI_SPINNER_FLOAT, &gErp2);
|
||||
spinner->set_float_limits(0.f,1.f);
|
||||
spinner = glui->add_spinner("Slop", GLUI_SPINNER_FLOAT, &gSlop);
|
||||
spinner->set_float_limits(0.f,1.f);
|
||||
// spinner = glui->add_spinner("WSP", GLUI_SPINNER_FLOAT,&gWarmStartingParameter);
|
||||
// spinner->set_float_limits (0.f,1.0);
|
||||
glui->add_checkbox("Warmstarting", &gUseWarmstarting);
|
||||
glui->add_checkbox("Randomize Constraints", &gRandomizeConstraints);
|
||||
|
||||
|
||||
glui->add_button("Reset Defaults", 0,(GLUI_Update_CB)setDefaultSettingsAndSync);
|
||||
glui->add_separator();
|
||||
|
||||
GLUI_Panel* drawPanel = glui->add_panel("Debug Draw");
|
||||
|
||||
|
||||
glui->add_checkbox_to_panel(drawPanel, "Help", &gHelpText);
|
||||
glui->add_checkbox_to_panel(drawPanel, "AABBs", &gDrawAabb);
|
||||
glui->add_checkbox_to_panel(drawPanel, "Wireframe", &gWireFrame);
|
||||
glui->add_checkbox_to_panel(drawPanel, "Contacts", &gDebugContacts);
|
||||
glui->add_checkbox_to_panel(drawPanel, "Constraints", &gDebugConstraints);
|
||||
|
||||
glui->add_checkbox_to_panel(drawPanel, "Textures", &gDrawTextures);
|
||||
glui->add_checkbox_to_panel(drawPanel, "Shadows", &gDrawShadows);
|
||||
glui->add_checkbox_to_panel(drawPanel, "Clusters", &gDrawClusters);
|
||||
|
||||
int testCount = 0;
|
||||
btDemoEntry* e = g_demoEntries;
|
||||
while (e->createFcn)
|
||||
{
|
||||
testList->add_item(testCount, e->name);
|
||||
++testCount;
|
||||
++e;
|
||||
}
|
||||
|
||||
glui->add_separator();
|
||||
|
||||
glui->add_button("Toggle Pause", 0,(GLUI_Update_CB)TogglePause);
|
||||
|
||||
glui->add_button("Single Step", 0,(GLUI_Update_CB)SingleSimulationStep);
|
||||
glui->add_button("Reset Scene", 0,(GLUI_Update_CB)ResetScene);
|
||||
glui->add_button("Restart Scene", 0,(GLUI_Update_CB)RestartScene);
|
||||
|
||||
glui->add_separator();
|
||||
|
||||
// glui->add_button("Exit", 0,(GLUI_Update_CB)exit);
|
||||
|
||||
glui->set_main_gfx_window( mainWindow );
|
||||
|
||||
// Use a timer to control the frame rate.
|
||||
glutTimerFunc(framePeriod, Timer, 0);
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
noinst_PROGRAMS=AllBulletDemo
|
||||
|
||||
AllBulletDemo_SOURCES=\
|
||||
../SoftDemo/SoftDemo.cpp \
|
||||
../Benchmarks/BenchmarkDemo.cpp \
|
||||
../ConstraintDemo/ConstraintDemo.cpp \
|
||||
../ForkLiftDemo/ForkLiftDemo.cpp \
|
||||
../RagdollDemo/RagdollDemo.cpp \
|
||||
../BasicDemo/BasicDemo.cpp \
|
||||
../CcdPhysicsDemo/CcdPhysicsDemo.cpp \
|
||||
../SliderConstraintDemo/SliderConstraintDemo.cpp \
|
||||
../ConcaveRaycastDemo/ConcaveRaycastDemo.cpp \
|
||||
../Raytracer/Raytracer.cpp \
|
||||
../BspDemo/BspDemo.cpp \
|
||||
../BspDemo/BspLoader.cpp \
|
||||
../BspDemo/BspConverter.cpp \
|
||||
../ConcaveConvexcastDemo/ConcaveConvexcastDemo.cpp \
|
||||
../ConvexDecompositionDemo/ConvexDecompositionDemo.cpp \
|
||||
../GimpactTestDemo/GimpactTestDemo.cpp \
|
||||
../GjkConvexCastDemo/LinearConvexCastDemo.cpp \
|
||||
../ConcaveDemo/ConcavePhysicsDemo.cpp \
|
||||
../DynamicControlDemo/MotorDemo.cpp \
|
||||
DemoEntries.cpp \
|
||||
DemoEntries.h\
|
||||
Main.cpp
|
||||
AllBulletDemo_CXXFLAGS=\
|
||||
-I@top_builddir@/src \
|
||||
-I@top_builddir@/Extras/GIMPACTUtils \
|
||||
-I@top_builddir@/Extras/ConvexDecomposition \
|
||||
-I@top_builddir@/Extras \
|
||||
-I@top_builddir@/Demos/OpenGL \
|
||||
-I@top_builddir@/Demos/SoftDemo \
|
||||
-I@top_builddir@/Demos/Benchmarks \
|
||||
$(CXXFLAGS)
|
||||
AllBulletDemo_LDADD=-L../OpenGL -lbulletopenglsupport -L../../src -L../../Extras -lgimpactutils -lconvexdecomposition -lbulletsoftbody -lbulletdynamics -lbulletcollision -lbulletmath -lglui @opengl_LIBS@
|
||||
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
///create 125 (5x5x5) dynamic object
|
||||
#define ARRAY_SIZE_X 5
|
||||
#define ARRAY_SIZE_Y 5
|
||||
#define ARRAY_SIZE_Z 5
|
||||
|
||||
//maximum number of objects (and allow user to shoot additional boxes)
|
||||
#define MAX_PROXIES (ARRAY_SIZE_X*ARRAY_SIZE_Y*ARRAY_SIZE_Z + 1024)
|
||||
|
||||
///scaling of the objects (0.1 = 20 centimeter boxes )
|
||||
#define SCALING 1.
|
||||
#define START_POS_X -5
|
||||
#define START_POS_Y -5
|
||||
#define START_POS_Z -3
|
||||
|
||||
#include "BasicDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
|
||||
void BasicDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//simple dynamics world doesn't handle fixed-time-stepping
|
||||
float ms = getDeltaTimeMicroseconds();
|
||||
|
||||
///step the simulation
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
m_dynamicsWorld->stepSimulation(ms / 1000000.f);
|
||||
//optional but useful: debug drawing
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
}
|
||||
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
|
||||
glutSwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BasicDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
renderme();
|
||||
|
||||
//optional but useful: debug drawing to detect problems
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void BasicDemo::initPhysics()
|
||||
{
|
||||
setTexturing(true);
|
||||
setShadows(true);
|
||||
|
||||
setCameraDistance(btScalar(SCALING*50.));
|
||||
|
||||
///collision configuration contains default setup for memory, collision setup
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
//m_collisionConfiguration->setConvexConvexMultipointIterations();
|
||||
|
||||
///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
|
||||
m_broadphase = new btDbvtBroadphase();
|
||||
|
||||
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
|
||||
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
|
||||
m_solver = sol;
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
|
||||
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
|
||||
|
||||
///create a few basic rigid bodies
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
|
||||
// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50);
|
||||
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
|
||||
btTransform groundTransform;
|
||||
groundTransform.setIdentity();
|
||||
groundTransform.setOrigin(btVector3(0,-50,0));
|
||||
|
||||
//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
|
||||
{
|
||||
btScalar mass(0.);
|
||||
|
||||
//rigidbody is dynamic if and only if mass is non zero, otherwise static
|
||||
bool isDynamic = (mass != 0.f);
|
||||
|
||||
btVector3 localInertia(0,0,0);
|
||||
if (isDynamic)
|
||||
groundShape->calculateLocalInertia(mass,localInertia);
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
|
||||
//add the body to the dynamics world
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
//create a few dynamic rigidbodies
|
||||
// Re-using the same collision is better for memory usage and performance
|
||||
|
||||
btCollisionShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
|
||||
//btCollisionShape* colShape = new btSphereShape(btScalar(1.));
|
||||
m_collisionShapes.push_back(colShape);
|
||||
|
||||
/// Create Dynamic Objects
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
|
||||
btScalar mass(1.f);
|
||||
|
||||
//rigidbody is dynamic if and only if mass is non zero, otherwise static
|
||||
bool isDynamic = (mass != 0.f);
|
||||
|
||||
btVector3 localInertia(0,0,0);
|
||||
if (isDynamic)
|
||||
colShape->calculateLocalInertia(mass,localInertia);
|
||||
|
||||
float start_x = START_POS_X - ARRAY_SIZE_X/2;
|
||||
float start_y = START_POS_Y;
|
||||
float start_z = START_POS_Z - ARRAY_SIZE_Z/2;
|
||||
|
||||
for (int k=0;k<ARRAY_SIZE_Y;k++)
|
||||
{
|
||||
for (int i=0;i<ARRAY_SIZE_X;i++)
|
||||
{
|
||||
for(int j = 0;j<ARRAY_SIZE_Z;j++)
|
||||
{
|
||||
startTransform.setOrigin(SCALING*btVector3(
|
||||
2.0*i + start_x,
|
||||
20+2.0*k + start_y,
|
||||
2.0*j + start_z));
|
||||
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
//body->setContactProcessingThreshold(colShape->getContactBreakingThreshold());
|
||||
body->setActivationState(ISLAND_SLEEPING);
|
||||
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
body->setActivationState(ISLAND_SLEEPING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
clientResetScene();
|
||||
}
|
||||
|
||||
|
||||
void BasicDemo::exitPhysics()
|
||||
{
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
delete m_solver;
|
||||
|
||||
delete m_broadphase;
|
||||
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef BASIC_DEMO_H
|
||||
#define BASIC_DEMO_H
|
||||
|
||||
#include "DemoApplication.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
|
||||
///BasicDemo is good starting point for learning the code base and porting.
|
||||
class BasicDemo : public DemoApplication
|
||||
{
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
public:
|
||||
|
||||
BasicDemo()
|
||||
{
|
||||
}
|
||||
virtual ~BasicDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BasicDemo* demo = new BasicDemo;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //BASIC_DEMO_H
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# This is the variable for Windows. I use this to define the root of my directory structure.
|
||||
SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL }
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppBasicDemo
|
||||
main.cpp
|
||||
BasicDemo.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
SubDir TOP Demos BasicDemo ;
|
||||
|
||||
BulletDemo BasicDemo : [ Wildcard *.h *.cpp ] ;
|
||||
@@ -0,0 +1,5 @@
|
||||
noinst_PROGRAMS=BasicDemo
|
||||
|
||||
BasicDemo_SOURCES=BasicDemo.cpp BasicDemo.h main.cpp
|
||||
BasicDemo_CXXFLAGS=-I@top_builddir@/src -I@top_builddir@/Demos/OpenGL $(CXXFLAGS)
|
||||
BasicDemo_LDADD=-L../OpenGL -lbulletopenglsupport -L../../src -lbulletdynamics -lbulletcollision -lbulletmath @opengl_LIBS@
|
||||
@@ -0,0 +1,49 @@
|
||||
__ARCH_BITS__ := 32
|
||||
|
||||
# define macros
|
||||
RM=rm -f
|
||||
OUTDIR=.
|
||||
CELLSDKDIR=/opt/ibm/cell-sdk
|
||||
ARCHITECTUREFLAG=-m$(__ARCH_BITS__)
|
||||
USE_CESOF=1
|
||||
ifeq "$(__ARCH_BITS__)" "64"
|
||||
DEFFLAGS= -DUSE_LIBSPE2 -DUSE_ADDR64 -DUSE_PARALLEL_DISPATCHER
|
||||
GCC=ppu-g++
|
||||
else
|
||||
DEFFLAGS= -DUSE_LIBSPE2 -DUSE_PARALLEL_DISPATCHER
|
||||
GCC=ppu32-g++
|
||||
endif
|
||||
DEBUGFLAG=
|
||||
ifeq "$(USE_CESOF)" "1"
|
||||
CFLAGS= $(ARCHITECTUREFLAG) $(DEBUGFLAG) -DUSE_CESOF -W -Wall -Winline -O3 -mabi=altivec -maltivec -include altivec.h -include stdbool.h -c
|
||||
else
|
||||
CFLAGS= $(ARCHITECTUREFLAG) $(DEBUGFLAG) -W -Wall -Winline -O3 -mabi=altivec -maltivec -include altivec.h -include stdbool.h -c
|
||||
endif
|
||||
INCLUDEDIR= -I. -I$(CELLSDKDIR)/prototype/sysroot/usr/include -I../../src -I../OpenGL
|
||||
LFLAGS= $(ARCHITECTUREFLAG) -Wl,-m,elf$(__ARCH_BITS__)ppc
|
||||
ifeq "$(USE_CESOF)" "1"
|
||||
LIBRARIES= -lstdc++ -lsupc++ -lgcc -lgcov -lspe2 -lpthread -L../../out/linuxppc/optimize/libs \
|
||||
-lbulletmultithreaded -lspu -lbulletdynamics -lbulletcollision -lbulletmath \
|
||||
-L$(CELLSDKDIR)/prototype/sysroot/usr/lib$(__ARCH_BITS__) -R$(CELLSDKDIR)/prototype/sysroot/usr/lib
|
||||
else
|
||||
LIBRARIES= -lstdc++ -lsupc++ -lgcc -lgcov -lspe2 -lpthread -L../../out/linuxppc/optimize/libs \
|
||||
-lbulletmultithreaded -lbulletdynamics -lbulletcollision -lbulletmath \
|
||||
-L$(CELLSDKDIR)/prototype/sysroot/usr/lib$(__ARCH_BITS__) -R$(CELLSDKDIR)/prototype/sysroot/usr/lib
|
||||
endif
|
||||
|
||||
DemoApplication :
|
||||
$(GCC) $(DEFFLAGS) $(CFLAGS) $(INCLUDEDIR) -o $(OUTDIR)/$@.o ../OpenGL/$@.cpp
|
||||
|
||||
|
||||
BasicDemo : DemoApplication
|
||||
$(GCC) $(DEFFLAGS) $(CFLAGS) $(INCLUDEDIR) -o $(OUTDIR)/$@.o $@.cpp
|
||||
|
||||
|
||||
|
||||
all : BasicDemo
|
||||
$(GCC) -o$(OUTDIR)/BasicDemo $(OUTDIR)/BasicDemo.o $(OUTDIR)/DemoApplication.o $(LFLAGS) $(LIBRARIES)
|
||||
|
||||
|
||||
clean :
|
||||
$(RM) $(OUTDIR)/BasicDemo ; $(RM) $(OUTDIR)/BasicDemo.o ; $(RM) $(OUTDIR)/DemoApplication.o
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "BasicDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
|
||||
class OurValue
|
||||
{
|
||||
int m_uid;
|
||||
|
||||
public:
|
||||
OurValue(const btVector3& initialPos)
|
||||
:m_position(initialPos)
|
||||
{
|
||||
static int gUid=0;
|
||||
m_uid=gUid;
|
||||
gUid++;
|
||||
}
|
||||
|
||||
btVector3 m_position;
|
||||
int getUid() const
|
||||
{
|
||||
return m_uid;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
|
||||
///testing the btHashMap
|
||||
btHashMap<btHashKey<OurValue>,OurValue> map;
|
||||
|
||||
OurValue value1(btVector3(2,3,4));
|
||||
btHashKey<OurValue> key1(value1.getUid());
|
||||
map.insert(key1,value1);
|
||||
|
||||
|
||||
OurValue value2(btVector3(5,6,7));
|
||||
btHashKey<OurValue> key2(value2.getUid());
|
||||
map.insert(key2,value2);
|
||||
|
||||
|
||||
{
|
||||
OurValue value3(btVector3(7,8,9));
|
||||
btHashKey<OurValue> key3(value3.getUid());
|
||||
map.insert(key3,value3);
|
||||
}
|
||||
|
||||
|
||||
map.remove(key2);
|
||||
|
||||
const OurValue* ourPtr = map.find(key1);
|
||||
for (int i=0;i<map.size();i++)
|
||||
{
|
||||
OurValue* tmp = map.getAtIndex(i);
|
||||
//printf("tmp value=%f,%f,%f\n",tmp->m_position.getX(),tmp->m_position.getY(),tmp->m_position.getZ());
|
||||
}
|
||||
|
||||
BasicDemo ccdDemo;
|
||||
ccdDemo.initPhysics();
|
||||
ccdDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
|
||||
#ifdef CHECK_MEMORY_LEAKS
|
||||
ccdDemo.exitPhysics();
|
||||
#else
|
||||
return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.com",&ccdDemo);
|
||||
#endif
|
||||
|
||||
//default glut doesn't return from mainloop
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef BENCHMARK_DEMO_H
|
||||
#define BENCHMARK_DEMO_H
|
||||
|
||||
#include "DemoApplication.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#define NUMRAYS 500
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
|
||||
///BenchmarkDemo is provides several performance tests
|
||||
class BenchmarkDemo : public DemoApplication
|
||||
{
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btAlignedObjectArray<class RagDoll*> m_ragdolls;
|
||||
|
||||
btBroadphaseInterface* m_overlappingPairCache;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
int m_benchmark;
|
||||
|
||||
void createTest1();
|
||||
void createTest2();
|
||||
void createTest3();
|
||||
void createTest4();
|
||||
void createTest5();
|
||||
void createTest6();
|
||||
void createTest7();
|
||||
|
||||
void createWall(const btVector3& offsetPosition,int stackSize,const btVector3& boxSize);
|
||||
void createPyramid(const btVector3& offsetPosition,int stackSize,const btVector3& boxSize);
|
||||
void createTowerCircle(const btVector3& offsetPosition,int stackSize,int rotSize,const btVector3& boxSize);
|
||||
void createLargeMeshBody();
|
||||
|
||||
|
||||
class SpuBatchRaycaster* m_batchRaycaster;
|
||||
class btThreadSupportInterface* m_batchRaycasterThreadSupport;
|
||||
|
||||
void castRays();
|
||||
void initRays();
|
||||
|
||||
public:
|
||||
|
||||
BenchmarkDemo(int benchmark)
|
||||
:m_benchmark(benchmark)
|
||||
{
|
||||
}
|
||||
virtual ~BenchmarkDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
class BenchmarkDemo1 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo1()
|
||||
:BenchmarkDemo(1)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo1* demo = new BenchmarkDemo1;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
class BenchmarkDemo2 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo2()
|
||||
:BenchmarkDemo(2)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo2* demo = new BenchmarkDemo2;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
class BenchmarkDemo3 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo3()
|
||||
:BenchmarkDemo(3)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo3* demo = new BenchmarkDemo3;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
class BenchmarkDemo4 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo4()
|
||||
:BenchmarkDemo(4)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo4* demo = new BenchmarkDemo4;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class BenchmarkDemo5 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo5()
|
||||
:BenchmarkDemo(5)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo5* demo = new BenchmarkDemo5;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class BenchmarkDemo6 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo6()
|
||||
:BenchmarkDemo(6)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo6* demo = new BenchmarkDemo6;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
class BenchmarkDemo7 : public BenchmarkDemo
|
||||
{
|
||||
public:
|
||||
BenchmarkDemo7()
|
||||
:BenchmarkDemo(7)
|
||||
{
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BenchmarkDemo7* demo = new BenchmarkDemo7;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //BENCHMARK_DEMO_H
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL }
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppBenchmarks
|
||||
main.cpp
|
||||
BenchmarkDemo.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
SubDir TOP Demos Benchmarks ;
|
||||
|
||||
BulletDemo Benchmarks : [ Wildcard *.h *.cpp ] ;
|
||||
@@ -0,0 +1,188 @@
|
||||
#define TaruVtxCount 43
|
||||
#define TaruIdxCount 132
|
||||
|
||||
float TaruVtx[] = {
|
||||
1.08664f,-1.99237f,0.0f,
|
||||
0.768369f,-1.99237f,-0.768369f,
|
||||
1.28852f,1.34412e-007f,-1.28852f,
|
||||
1.82224f,1.90735e-007f,0.0f,
|
||||
0.0f,-1.99237f,-1.08664f,
|
||||
0.0f,0.0f,-1.82224f,
|
||||
0.0f,-1.99237f,-1.08664f,
|
||||
-0.768369f,-1.99237f,-0.768369f,
|
||||
-1.28852f,1.34412e-007f,-1.28852f,
|
||||
0.0f,0.0f,-1.82224f,
|
||||
-1.08664f,-1.99237f,1.82086e-007f,
|
||||
-1.82224f,1.90735e-007f,1.59305e-007f,
|
||||
-0.768369f,-1.99237f,0.76837f,
|
||||
-1.28852f,2.47058e-007f,1.28852f,
|
||||
1.42495e-007f,-1.99237f,1.08664f,
|
||||
2.38958e-007f,2.70388e-007f,1.82224f,
|
||||
0.768369f,-1.99237f,0.768369f,
|
||||
1.28852f,2.47058e-007f,1.28852f,
|
||||
0.768369f,1.99237f,-0.768369f,
|
||||
1.08664f,1.99237f,0.0f,
|
||||
0.0f,1.99237f,-1.08664f,
|
||||
-0.768369f,1.99237f,-0.768369f,
|
||||
0.0f,1.99237f,-1.08664f,
|
||||
-1.08664f,1.99237f,0.0f,
|
||||
-0.768369f,1.99237f,0.768369f,
|
||||
1.42495e-007f,1.99237f,1.08664f,
|
||||
0.768369f,1.99237f,0.768369f,
|
||||
1.42495e-007f,-1.99237f,1.08664f,
|
||||
-0.768369f,-1.99237f,0.76837f,
|
||||
-1.08664f,-1.99237f,1.82086e-007f,
|
||||
-0.768369f,-1.99237f,-0.768369f,
|
||||
0.0f,-1.99237f,-1.08664f,
|
||||
0.768369f,-1.99237f,-0.768369f,
|
||||
1.08664f,-1.99237f,0.0f,
|
||||
0.768369f,-1.99237f,0.768369f,
|
||||
0.768369f,1.99237f,-0.768369f,
|
||||
0.0f,1.99237f,-1.08664f,
|
||||
-0.768369f,1.99237f,-0.768369f,
|
||||
-1.08664f,1.99237f,0.0f,
|
||||
-0.768369f,1.99237f,0.768369f,
|
||||
1.42495e-007f,1.99237f,1.08664f,
|
||||
0.768369f,1.99237f,0.768369f,
|
||||
1.08664f,1.99237f,0.0f,
|
||||
};
|
||||
|
||||
float TaruNml[] = {
|
||||
0.938103f,-0.346356f,0.0f,
|
||||
0.663339f,-0.346356f,-0.663339f,
|
||||
0.707107f,0.0f,-0.707107f,
|
||||
1.0f,0.0f,0.0f,
|
||||
0.0f,-0.346356f,-0.938103f,
|
||||
0.0f,0.0f,-1.0f,
|
||||
0.0f,-0.346356f,-0.938103f,
|
||||
-0.663339f,-0.346356f,-0.663339f,
|
||||
-0.707107f,0.0f,-0.707107f,
|
||||
0.0f,0.0f,-1.0f,
|
||||
-0.938103f,-0.346356f,0.0f,
|
||||
-1.0f,0.0f,0.0f,
|
||||
-0.663339f,-0.346356f,0.663339f,
|
||||
-0.707107f,0.0f,0.707107f,
|
||||
0.0f,-0.346356f,0.938103f,
|
||||
1.21445e-007f,0.0f,1.0f,
|
||||
0.663339f,-0.346356f,0.663339f,
|
||||
0.707107f,0.0f,0.707107f,
|
||||
0.663339f,0.346356f,-0.663339f,
|
||||
0.938103f,0.346356f,0.0f,
|
||||
0.0f,0.346356f,-0.938103f,
|
||||
-0.663339f,0.346356f,-0.663339f,
|
||||
0.0f,0.346356f,-0.938103f,
|
||||
-0.938103f,0.346356f,0.0f,
|
||||
-0.663339f,0.346356f,0.663339f,
|
||||
1.2508e-007f,0.346356f,0.938103f,
|
||||
0.663339f,0.346356f,0.663339f,
|
||||
0.0f,-1.0f,0.0f,
|
||||
0.0f,-1.0f,0.0f,
|
||||
0.0f,-1.0f,0.0f,
|
||||
0.0f,-1.0f,0.0f,
|
||||
0.0f,-1.0f,0.0f,
|
||||
0.0f,-1.0f,0.0f,
|
||||
0.0f,-1.0f,0.0f,
|
||||
0.0f,-1.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,
|
||||
0.0f,1.0f,0.0f,
|
||||
};
|
||||
|
||||
float TaruTex[] = {
|
||||
0.75f,0.0f,
|
||||
0.875f,0.0f,
|
||||
0.875f,0.5f,
|
||||
0.75f,0.5f,
|
||||
1.0f,0.0f,
|
||||
1.0f,0.5f,
|
||||
0.0f,0.0f,
|
||||
0.125f,0.0f,
|
||||
0.125f,0.5f,
|
||||
0.0f,0.5f,
|
||||
0.25f,0.0f,
|
||||
0.25f,0.5f,
|
||||
0.375f,0.0f,
|
||||
0.375f,0.5f,
|
||||
0.5f,0.0f,
|
||||
0.5f,0.5f,
|
||||
0.625f,0.0f,
|
||||
0.625f,0.5f,
|
||||
0.875f,1.0f,
|
||||
0.75f,1.0f,
|
||||
1.0f,1.0f,
|
||||
0.125f,1.0f,
|
||||
0.0f,1.0f,
|
||||
0.25f,1.0f,
|
||||
0.375f,1.0f,
|
||||
0.5f,1.0f,
|
||||
0.625f,1.0f,
|
||||
1.0f,0.5f,
|
||||
0.853553f,0.146447f,
|
||||
0.5f,0.0f,
|
||||
0.146447f,0.146447f,
|
||||
0.0f,0.5f,
|
||||
0.146447f,0.853553f,
|
||||
0.5f,1.0f,
|
||||
0.853553f,0.853553f,
|
||||
0.146447f,0.853553f,
|
||||
0.0f,0.5f,
|
||||
0.146447f,0.146447f,
|
||||
0.5f,0.0f,
|
||||
0.853553f,0.146447f,
|
||||
1.0f,0.5f,
|
||||
0.853553f,0.853553f,
|
||||
0.5f,1.0f,
|
||||
};
|
||||
|
||||
unsigned short TaruIdx[] = {
|
||||
0,1,2,
|
||||
2,3,0,
|
||||
1,4,5,
|
||||
5,2,1,
|
||||
6,7,8,
|
||||
8,9,6,
|
||||
7,10,11,
|
||||
11,8,7,
|
||||
10,12,13,
|
||||
13,11,10,
|
||||
12,14,15,
|
||||
15,13,12,
|
||||
14,16,17,
|
||||
17,15,14,
|
||||
16,0,3,
|
||||
3,17,16,
|
||||
3,2,18,
|
||||
18,19,3,
|
||||
2,5,20,
|
||||
20,18,2,
|
||||
9,8,21,
|
||||
21,22,9,
|
||||
8,11,23,
|
||||
23,21,8,
|
||||
11,13,24,
|
||||
24,23,11,
|
||||
13,15,25,
|
||||
25,24,13,
|
||||
15,17,26,
|
||||
26,25,15,
|
||||
17,3,19,
|
||||
19,26,17,
|
||||
27,28,29,
|
||||
29,30,31,
|
||||
31,32,33,
|
||||
29,31,33,
|
||||
27,29,33,
|
||||
34,27,33,
|
||||
35,36,37,
|
||||
37,38,39,
|
||||
39,40,41,
|
||||
37,39,41,
|
||||
35,37,41,
|
||||
42,35,41,
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "BenchmarkDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
|
||||
BenchmarkDemo1 benchmarkDemo;
|
||||
// BenchmarkDemo2 benchmarkDemo;
|
||||
// BenchmarkDemo3 benchmarkDemo;
|
||||
// BenchmarkDemo4 benchmarkDemo;
|
||||
// BenchmarkDemo5 benchmarkDemo;
|
||||
// BenchmarkDemo6 benchmarkDemo;
|
||||
// BenchmarkDemo7 benchmarkDemo;
|
||||
|
||||
|
||||
benchmarkDemo.initPhysics();
|
||||
benchmarkDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.com",&benchmarkDemo);
|
||||
|
||||
//default glut doesn't return from mainloop
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "BspConverter.h"
|
||||
#include "BspLoader.h"
|
||||
#include "LinearMath/btVector3.h"
|
||||
#include "LinearMath/btGeometryUtil.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void BspConverter::convertBsp(BspLoader& bspLoader,float scaling)
|
||||
{
|
||||
{
|
||||
|
||||
float playstartf[3] = {0,0,100};
|
||||
|
||||
if (bspLoader.findVectorByName(&playstartf[0],"info_player_start"))
|
||||
{
|
||||
printf("found playerstart\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bspLoader.findVectorByName(&playstartf[0],"info_player_deathmatch"))
|
||||
{
|
||||
printf("found deatchmatch start\n");
|
||||
}
|
||||
}
|
||||
|
||||
btVector3 playerStart (playstartf[0],playstartf[1],playstartf[2]);
|
||||
|
||||
|
||||
playerStart[2] += 20.f; //start a bit higher
|
||||
|
||||
playerStart *= scaling;
|
||||
|
||||
|
||||
|
||||
//progressBegin("Loading bsp");
|
||||
|
||||
for (int i=0;i<bspLoader.m_numleafs;i++)
|
||||
{
|
||||
printf("Reading bspLeaf %i from total %i (%f procent)\n",i, bspLoader.m_numleafs,(100.f*(float)i/float(bspLoader.m_numleafs)) );
|
||||
|
||||
bool isValidBrush = false;
|
||||
|
||||
BSPLeaf& leaf = bspLoader.m_dleafs[i];
|
||||
|
||||
for (int b=0;b<leaf.numLeafBrushes;b++)
|
||||
{
|
||||
btAlignedObjectArray<btVector3> planeEquations;
|
||||
|
||||
int brushid = bspLoader.m_dleafbrushes[leaf.firstLeafBrush+b];
|
||||
|
||||
BSPBrush& brush = bspLoader.m_dbrushes[brushid];
|
||||
if (brush.shaderNum!=-1)
|
||||
{
|
||||
if (bspLoader.m_dshaders[ brush.shaderNum ].contentFlags & BSPCONTENTS_SOLID)
|
||||
{
|
||||
brush.shaderNum = -1;
|
||||
|
||||
for (int p=0;p<brush.numSides;p++)
|
||||
{
|
||||
int sideid = brush.firstSide+p;
|
||||
BSPBrushSide& brushside = bspLoader.m_dbrushsides[sideid];
|
||||
int planeid = brushside.planeNum;
|
||||
BSPPlane& plane = bspLoader.m_dplanes[planeid];
|
||||
btVector3 planeEq;
|
||||
planeEq.setValue(
|
||||
plane.normal[0],
|
||||
plane.normal[1],
|
||||
plane.normal[2]);
|
||||
planeEq[3] = scaling*-plane.dist;
|
||||
|
||||
planeEquations.push_back(planeEq);
|
||||
isValidBrush=true;
|
||||
}
|
||||
if (isValidBrush)
|
||||
{
|
||||
|
||||
btAlignedObjectArray<btVector3> vertices;
|
||||
btGeometryUtil::getVerticesFromPlaneEquations(planeEquations,vertices);
|
||||
|
||||
bool isEntity = false;
|
||||
btVector3 entityTarget(0.f,0.f,0.f);
|
||||
addConvexVerticesCollider(vertices,isEntity,entityTarget);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define USE_ENTITIES
|
||||
#ifdef USE_ENTITIES
|
||||
|
||||
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<bspLoader.m_num_entities;i++)
|
||||
{
|
||||
const BSPEntity& entity = bspLoader.m_entities[i];
|
||||
const char* cl = bspLoader.getValueForKey(&entity,"classname");
|
||||
if ( !strcmp( cl, "trigger_push" ) ) {
|
||||
btVector3 targetLocation(0.f,0.f,0.f);
|
||||
|
||||
cl = bspLoader.getValueForKey(&entity,"target");
|
||||
if ( strcmp( cl, "" ) ) {
|
||||
//its not empty so ...
|
||||
|
||||
/*
|
||||
//lookup the target position for the jumppad:
|
||||
const BSPEntity* targetentity = bspLoader.getEntityByValue( "targetname" , cl );
|
||||
if (targetentity)
|
||||
{
|
||||
if (bspLoader.getVectorForKey( targetentity , "origin",&targetLocation[0]))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
cl = bspLoader.getValueForKey(&entity,"model");
|
||||
if ( strcmp( cl, "" ) ) {
|
||||
// add the model as a brush
|
||||
if (cl[0] == '*')
|
||||
{
|
||||
int modelnr = atoi(&cl[1]);
|
||||
if ((modelnr >=0) && (modelnr < bspLoader.m_nummodels))
|
||||
{
|
||||
const BSPModel& model = bspLoader.m_dmodels[modelnr];
|
||||
for (int n=0;n<model.numBrushes;n++)
|
||||
{
|
||||
btAlignedObjectArray<btVector3> planeEquations;
|
||||
bool isValidBrush = false;
|
||||
|
||||
//convert brush
|
||||
const BSPBrush& brush = bspLoader.m_dbrushes[model.firstBrush+n];
|
||||
{
|
||||
for (int p=0;p<brush.numSides;p++)
|
||||
{
|
||||
int sideid = brush.firstSide+p;
|
||||
BSPBrushSide& brushside = bspLoader.m_dbrushsides[sideid];
|
||||
int planeid = brushside.planeNum;
|
||||
BSPPlane& plane = bspLoader.m_dplanes[planeid];
|
||||
btVector3 planeEq;
|
||||
planeEq.setValue(
|
||||
plane.normal[0],
|
||||
plane.normal[1],
|
||||
plane.normal[2]);
|
||||
planeEq[3] = scaling*-plane.dist;
|
||||
planeEquations.push_back(planeEq);
|
||||
isValidBrush=true;
|
||||
}
|
||||
if (isValidBrush)
|
||||
{
|
||||
|
||||
btAlignedObjectArray<btVector3> vertices;
|
||||
btGeometryUtil::getVerticesFromPlaneEquations(planeEquations,vertices);
|
||||
|
||||
bool isEntity=true;
|
||||
addConvexVerticesCollider(vertices,isEntity,targetLocation);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("unsupported trigger_push model, md3 ?\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //USE_ENTITIES
|
||||
|
||||
|
||||
|
||||
//progressEnd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BSP_CONVERTER_H
|
||||
#define BSP_CONVERTER_H
|
||||
|
||||
class BspLoader;
|
||||
#include "LinearMath/btVector3.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
///BspConverter turns a loaded bsp level into convex parts (vertices)
|
||||
class BspConverter
|
||||
{
|
||||
public:
|
||||
|
||||
void convertBsp(BspLoader& bspLoader,float scaling);
|
||||
virtual ~BspConverter()
|
||||
{
|
||||
}
|
||||
|
||||
///this callback is called for each brush that succesfully converted into vertices
|
||||
virtual void addConvexVerticesCollider(btAlignedObjectArray<btVector3>& vertices, bool isEntity, const btVector3& entityTargetLocation) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif //BSP_CONVERTER_H
|
||||
|
||||
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
|
||||
#define QUAKE_BSP_IMPORTING 1
|
||||
|
||||
#ifdef QUAKE_BSP_IMPORTING
|
||||
#include "BspLoader.h"
|
||||
#include "BspConverter.h"
|
||||
#endif //QUAKE_BSP_IMPORTING
|
||||
|
||||
#include "BMF_Api.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
|
||||
#include "BspDemo.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define CUBE_HALF_EXTENTS 1
|
||||
#define EXTRA_HEIGHT -20.f
|
||||
|
||||
|
||||
|
||||
///BspToBulletConverter extends the BspConverter to convert to Bullet datastructures
|
||||
class BspToBulletConverter : public BspConverter
|
||||
{
|
||||
BspDemo* m_demoApp;
|
||||
|
||||
public:
|
||||
|
||||
BspToBulletConverter(BspDemo* demoApp)
|
||||
:m_demoApp(demoApp)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void addConvexVerticesCollider(btAlignedObjectArray<btVector3>& vertices, bool isEntity, const btVector3& entityTargetLocation)
|
||||
{
|
||||
///perhaps we can do something special with entities (isEntity)
|
||||
///like adding a collision Triggering (as example)
|
||||
|
||||
if (vertices.size() > 0)
|
||||
{
|
||||
float mass = 0.f;
|
||||
btTransform startTransform;
|
||||
//can use a shift
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,0,-10.f));
|
||||
//this create an internal copy of the vertices
|
||||
|
||||
btCollisionShape* shape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
|
||||
m_demoApp->m_collisionShapes.push_back(shape);
|
||||
|
||||
//btRigidBody* body = m_demoApp->localCreateRigidBody(mass, startTransform,shape);
|
||||
m_demoApp->localCreateRigidBody(mass, startTransform,shape);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BspDemo::~BspDemo()
|
||||
{
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
//delete solver
|
||||
delete m_solver;
|
||||
|
||||
//delete broadphase
|
||||
delete m_broadphase;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
}
|
||||
|
||||
void BspDemo::initPhysics(char* bspfilename)
|
||||
{
|
||||
setTexturing(true);
|
||||
setShadows(false);
|
||||
|
||||
m_cameraUp = btVector3(0,0,1);
|
||||
m_forwardAxis = 1;
|
||||
|
||||
setCameraDistance(22.f);
|
||||
|
||||
///Setup a Physics Simulation Environment
|
||||
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
// btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50));
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
btVector3 worldMin(-1000,-1000,-1000);
|
||||
btVector3 worldMax(1000,1000,1000);
|
||||
m_broadphase = new btDbvtBroadphase();
|
||||
//m_broadphase = new btAxisSweep3(worldMin,worldMax);
|
||||
//btOverlappingPairCache* broadphase = new btSimpleBroadphase();
|
||||
m_solver = new btSequentialImpulseConstraintSolver();
|
||||
//ConstraintSolver* solver = new OdeConstraintSolver;
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
|
||||
m_dynamicsWorld->setGravity(-m_cameraUp * 10);
|
||||
|
||||
|
||||
#ifdef QUAKE_BSP_IMPORTING
|
||||
|
||||
void* memoryBuffer = 0;
|
||||
|
||||
FILE* file = fopen(bspfilename,"r");
|
||||
if (!file)
|
||||
{
|
||||
//try again other path,
|
||||
//sight... visual studio leaves the current working directory in the projectfiles folder
|
||||
//instead of executable folder. who wants this default behaviour?!?
|
||||
bspfilename = "../../BspDemo.bsp";
|
||||
file = fopen(bspfilename,"r");
|
||||
}
|
||||
if (!file)
|
||||
{
|
||||
//try again other path,
|
||||
//sight... visual studio leaves the current working directory in the projectfiles folder
|
||||
//instead of executable folder. who wants this default behaviour?!?
|
||||
bspfilename = "BspDemo.bsp";
|
||||
file = fopen(bspfilename,"r");
|
||||
}
|
||||
|
||||
if (file)
|
||||
{
|
||||
BspLoader bspLoader;
|
||||
int size=0;
|
||||
if (fseek(file, 0, SEEK_END) || (size = ftell(file)) == EOF || fseek(file, 0, SEEK_SET)) { /* File operations denied? ok, just close and return failure */
|
||||
printf("Error: cannot get filesize from %s\n", bspfilename);
|
||||
} else
|
||||
{
|
||||
//how to detect file size?
|
||||
memoryBuffer = malloc(size+1);
|
||||
fread(memoryBuffer,1,size,file);
|
||||
bspLoader.loadBSPFile( memoryBuffer);
|
||||
|
||||
BspToBulletConverter bsp2bullet(this);
|
||||
float bspScaling = 0.1f;
|
||||
bsp2bullet.convertBsp(bspLoader,bspScaling);
|
||||
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
clientResetScene();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void BspDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
float dt = getDeltaTimeMicroseconds() * 0.000001f;
|
||||
|
||||
m_dynamicsWorld->stepSimulation(dt);
|
||||
|
||||
//optional but useful: debug drawing
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BspDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
renderme();
|
||||
|
||||
//optional but useful: debug drawing
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//some code that de-mangles the windows filename passed in as argument
|
||||
char cleaned_filename[512];
|
||||
char* getLastFileName()
|
||||
{
|
||||
return cleaned_filename;
|
||||
}
|
||||
char* makeExeToBspFilename(const char* lpCmdLine)
|
||||
{
|
||||
|
||||
|
||||
// We might get a windows-style path on the command line, this can mess up the DOM which expects
|
||||
// all paths to be URI's. This block of code does some conversion to try and make the input
|
||||
// compliant without breaking the ability to accept a properly formatted URI. Right now this only
|
||||
// displays the first filename
|
||||
const char *in = lpCmdLine;
|
||||
char* out = cleaned_filename;
|
||||
*out = '\0';
|
||||
// If the first character is a ", skip it (filenames with spaces in them are quoted)
|
||||
if(*in == '\"')
|
||||
{
|
||||
in++;
|
||||
}
|
||||
int i;
|
||||
for(i =0; i<512; i++)
|
||||
{
|
||||
//if we get '.' we stop as well, unless it's the first character. Then we add .bsp as extension
|
||||
// If we hit a null or a quote, stop copying. This will get just the first filename.
|
||||
if(i && (in[0] == '.') && (in[1] == 'e') && (in[2] == 'x') && (in[3] == 'e'))
|
||||
break;
|
||||
|
||||
// If we hit a null or a quote, stop copying. This will get just the first filename.
|
||||
if(*in == '\0' || *in == '\"')
|
||||
break;
|
||||
// Copy while swapping backslashes for forward ones
|
||||
if(*in == '\\')
|
||||
{
|
||||
*out = '/';
|
||||
}
|
||||
else
|
||||
{
|
||||
*out = *in;
|
||||
}
|
||||
in++;
|
||||
out++;
|
||||
}
|
||||
*(out++) = '.';
|
||||
*(out++) = 'b';
|
||||
*(out++) = 's';
|
||||
*(out++) = 'p';
|
||||
*(out++) = 0;
|
||||
|
||||
return cleaned_filename;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef BSP_DEMO_H
|
||||
#define BSP_DEMO_H
|
||||
|
||||
#include "DemoApplication.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
|
||||
|
||||
///BspDemo shows the convex collision detection, by converting a Quake BSP file into convex objects and allowing interaction with boxes.
|
||||
class BspDemo : public DemoApplication
|
||||
{
|
||||
public:
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
|
||||
|
||||
|
||||
virtual ~BspDemo();
|
||||
|
||||
void initPhysics(char* bspfilename);
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
BspDemo* demo = new BspDemo;
|
||||
demo->myinit();
|
||||
demo->initPhysics("BspDemo.bsp");
|
||||
return demo;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //BSP_DEMO_H
|
||||
|
||||
|
||||
@@ -0,0 +1,730 @@
|
||||
/*
|
||||
===========================================================================
|
||||
Copyright (C) 1999-2005 Id Software, Inc.
|
||||
|
||||
This file is part of Quake III Arena source code.
|
||||
|
||||
Quake III Arena source code is free software; you can redistribute it
|
||||
and/or modify it under the terms of the GNU bteral Public License as
|
||||
published by the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
Quake III Arena source code is distributed in the hope that it will be
|
||||
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU bteral Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU bteral Public License
|
||||
along with Foobar; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
|
||||
#include "BspLoader.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char filename[1024];
|
||||
char *buffer,*script_p,*end_p;
|
||||
int line;
|
||||
} BSPScript;
|
||||
|
||||
#define MAX_INCLUDES 8
|
||||
BSPScript scriptstack[MAX_INCLUDES];
|
||||
BSPScript *script;
|
||||
int scriptline;
|
||||
|
||||
char token[BSPMAXTOKEN];
|
||||
bool endofscript;
|
||||
bool tokenready; // only true if UnGetToken was just called
|
||||
|
||||
//
|
||||
//loadBSPFile
|
||||
//
|
||||
|
||||
int extrasize = 100;
|
||||
|
||||
BspLoader::BspLoader()
|
||||
:m_num_entities(0)
|
||||
{
|
||||
m_Endianness = getMachineEndianness();
|
||||
if (m_Endianness == BSP_BIG_ENDIAN)
|
||||
{
|
||||
printf("Machine is BIG_ENDIAN\n");
|
||||
} else
|
||||
{
|
||||
printf("Machine is Little Endian\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool BspLoader::loadBSPFile( void* memoryBuffer) {
|
||||
|
||||
BSPHeader *header = (BSPHeader*) memoryBuffer;
|
||||
|
||||
// load the file header
|
||||
if (header)
|
||||
{
|
||||
// swap the header
|
||||
swapBlock( (int *)header, sizeof(*header) );
|
||||
|
||||
int length = (header->lumps[BSPLUMP_SHADERS].filelen) / sizeof(BSPShader);
|
||||
m_dshaders.resize(length+extrasize);
|
||||
m_numShaders = copyLump( header, BSPLUMP_SHADERS, &m_dshaders[0], sizeof(BSPShader) );
|
||||
|
||||
length = (header->lumps[LUMP_MODELS].filelen) / sizeof(BSPModel);
|
||||
m_dmodels.resize(length+extrasize);
|
||||
m_nummodels = copyLump( header, LUMP_MODELS, &m_dmodels[0], sizeof(BSPModel) );
|
||||
|
||||
length = (header->lumps[BSPLUMP_PLANES].filelen) / sizeof(BSPPlane);
|
||||
m_dplanes.resize(length+extrasize);
|
||||
m_numplanes = copyLump( header, BSPLUMP_PLANES, &m_dplanes[0], sizeof(BSPPlane) );
|
||||
|
||||
length = (header->lumps[BSPLUMP_LEAFS].filelen) / sizeof(BSPLeaf);
|
||||
m_dleafs.resize(length+extrasize);
|
||||
m_numleafs = copyLump( header, BSPLUMP_LEAFS, &m_dleafs[0], sizeof(BSPLeaf) );
|
||||
|
||||
length = (header->lumps[BSPLUMP_NODES].filelen) / sizeof(BSPNode);
|
||||
m_dnodes.resize(length+extrasize);
|
||||
m_numnodes = copyLump( header, BSPLUMP_NODES, &m_dnodes[0], sizeof(BSPNode) );
|
||||
|
||||
length = (header->lumps[BSPLUMP_LEAFSURFACES].filelen) / sizeof(m_dleafsurfaces[0]);
|
||||
m_dleafsurfaces.resize(length+extrasize);
|
||||
m_numleafsurfaces = copyLump( header, BSPLUMP_LEAFSURFACES, &m_dleafsurfaces[0], sizeof(m_dleafsurfaces[0]) );
|
||||
|
||||
length = (header->lumps[BSPLUMP_LEAFBRUSHES].filelen) / sizeof(m_dleafbrushes[0]) ;
|
||||
m_dleafbrushes.resize(length+extrasize);
|
||||
m_numleafbrushes = copyLump( header, BSPLUMP_LEAFBRUSHES, &m_dleafbrushes[0], sizeof(m_dleafbrushes[0]) );
|
||||
|
||||
length = (header->lumps[LUMP_BRUSHES].filelen) / sizeof(BSPBrush);
|
||||
m_dbrushes.resize(length+extrasize);
|
||||
m_numbrushes = copyLump( header, LUMP_BRUSHES, &m_dbrushes[0], sizeof(BSPBrush) );
|
||||
|
||||
|
||||
length = (header->lumps[LUMP_BRUSHSIDES].filelen) / sizeof(BSPBrushSide);
|
||||
m_dbrushsides.resize(length+extrasize);
|
||||
m_numbrushsides = copyLump( header, LUMP_BRUSHSIDES, &m_dbrushsides[0], sizeof(BSPBrushSide) );
|
||||
|
||||
|
||||
length = (header->lumps[LUMP_SURFACES].filelen) / sizeof(BSPSurface);
|
||||
m_drawSurfaces.resize(length+extrasize);
|
||||
m_numDrawSurfaces = copyLump( header, LUMP_SURFACES, &m_drawSurfaces[0], sizeof(BSPSurface) );
|
||||
|
||||
|
||||
length = (header->lumps[LUMP_DRAWINDEXES].filelen) / sizeof(m_drawIndexes[0]);
|
||||
m_drawIndexes.resize(length+extrasize);
|
||||
m_numDrawIndexes = copyLump( header, LUMP_DRAWINDEXES, &m_drawIndexes[0], sizeof(m_drawIndexes[0]) );
|
||||
|
||||
length = (header->lumps[LUMP_VISIBILITY].filelen) / 1;
|
||||
m_visBytes.resize(length+extrasize);
|
||||
m_numVisBytes = copyLump( header, LUMP_VISIBILITY, &m_visBytes[0], 1 );
|
||||
|
||||
length = (header->lumps[LUMP_LIGHTMAPS].filelen) / 1;
|
||||
m_lightBytes.resize(length+extrasize);
|
||||
m_numLightBytes = copyLump( header, LUMP_LIGHTMAPS, &m_lightBytes[0], 1 );
|
||||
|
||||
length = (header->lumps[BSPLUMP_ENTITIES].filelen) / 1;
|
||||
m_dentdata.resize(length+extrasize);
|
||||
m_entdatasize = copyLump( header, BSPLUMP_ENTITIES, &m_dentdata[0], 1);
|
||||
|
||||
length = (header->lumps[LUMP_LIGHTGRID].filelen) / 1;
|
||||
m_gridData.resize(length+extrasize);
|
||||
m_numGridPoints = copyLump( header, LUMP_LIGHTGRID, &m_gridData[0], 8 );
|
||||
|
||||
// swap everything
|
||||
swapBSPFile();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char* BspLoader::getValueForKey( const BSPEntity* ent, const char* key ) const {
|
||||
|
||||
const BSPKeyValuePair* ep;
|
||||
|
||||
for (ep=ent->epairs ; ep ; ep=ep->next) {
|
||||
if (!strcmp(ep->key, key) ) {
|
||||
return ep->value;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
float BspLoader::getFloatForKey( const BSPEntity *ent, const char *key ) {
|
||||
const char *k;
|
||||
|
||||
k = getValueForKey( ent, key );
|
||||
return float(atof(k));
|
||||
}
|
||||
|
||||
bool BspLoader::getVectorForKey( const BSPEntity *ent, const char *key, BSPVector3 vec ) {
|
||||
|
||||
const char *k;
|
||||
k = getValueForKey (ent, key);
|
||||
if (strcmp(k, ""))
|
||||
{
|
||||
sscanf (k, "%f %f %f", &vec[0], &vec[1], &vec[2]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
parseFromMemory
|
||||
==============
|
||||
*/
|
||||
void BspLoader::parseFromMemory (char *buffer, int size)
|
||||
{
|
||||
script = scriptstack;
|
||||
script++;
|
||||
if (script == &scriptstack[MAX_INCLUDES])
|
||||
{
|
||||
//printf("script file exceeded MAX_INCLUDES");
|
||||
}
|
||||
strcpy (script->filename, "memory buffer" );
|
||||
|
||||
script->buffer = buffer;
|
||||
script->line = 1;
|
||||
script->script_p = script->buffer;
|
||||
script->end_p = script->buffer + size;
|
||||
|
||||
endofscript = false;
|
||||
tokenready = false;
|
||||
}
|
||||
|
||||
|
||||
bool BspLoader::isEndOfScript (bool crossline)
|
||||
{
|
||||
if (!crossline)
|
||||
//printf("Line %i is incomplete\n",scriptline);
|
||||
|
||||
if (!strcmp (script->filename, "memory buffer"))
|
||||
{
|
||||
endofscript = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//free (script->buffer);
|
||||
if (script == scriptstack+1)
|
||||
{
|
||||
endofscript = true;
|
||||
return false;
|
||||
}
|
||||
script--;
|
||||
scriptline = script->line;
|
||||
//printf ("returning to %s\n", script->filename);
|
||||
return getToken (crossline);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
==============
|
||||
getToken
|
||||
==============
|
||||
*/
|
||||
bool BspLoader::getToken (bool crossline)
|
||||
{
|
||||
char *token_p;
|
||||
|
||||
if (tokenready) // is a token allready waiting?
|
||||
{
|
||||
tokenready = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (script->script_p >= script->end_p)
|
||||
return isEndOfScript (crossline);
|
||||
|
||||
//
|
||||
// skip space
|
||||
//
|
||||
skipspace:
|
||||
while (*script->script_p <= 32)
|
||||
{
|
||||
if (script->script_p >= script->end_p)
|
||||
return isEndOfScript (crossline);
|
||||
if (*script->script_p++ == '\n')
|
||||
{
|
||||
if (!crossline)
|
||||
{
|
||||
//printf("Line %i is incomplete\n",scriptline);
|
||||
}
|
||||
scriptline = script->line++;
|
||||
}
|
||||
}
|
||||
|
||||
if (script->script_p >= script->end_p)
|
||||
return isEndOfScript (crossline);
|
||||
|
||||
// ; # // comments
|
||||
if (*script->script_p == ';' || *script->script_p == '#'
|
||||
|| ( script->script_p[0] == '/' && script->script_p[1] == '/') )
|
||||
{
|
||||
if (!crossline)
|
||||
{
|
||||
//printf("Line %i is incomplete\n",scriptline);
|
||||
}
|
||||
while (*script->script_p++ != '\n')
|
||||
if (script->script_p >= script->end_p)
|
||||
return isEndOfScript (crossline);
|
||||
scriptline = script->line++;
|
||||
goto skipspace;
|
||||
}
|
||||
|
||||
// /* */ comments
|
||||
if (script->script_p[0] == '/' && script->script_p[1] == '*')
|
||||
{
|
||||
if (!crossline)
|
||||
{
|
||||
//printf("Line %i is incomplete\n",scriptline);
|
||||
}
|
||||
script->script_p+=2;
|
||||
while (script->script_p[0] != '*' && script->script_p[1] != '/')
|
||||
{
|
||||
if ( *script->script_p == '\n' ) {
|
||||
scriptline = script->line++;
|
||||
}
|
||||
script->script_p++;
|
||||
if (script->script_p >= script->end_p)
|
||||
return isEndOfScript (crossline);
|
||||
}
|
||||
script->script_p += 2;
|
||||
goto skipspace;
|
||||
}
|
||||
|
||||
//
|
||||
// copy token
|
||||
//
|
||||
token_p = token;
|
||||
|
||||
if (*script->script_p == '"')
|
||||
{
|
||||
// quoted token
|
||||
script->script_p++;
|
||||
while (*script->script_p != '"')
|
||||
{
|
||||
*token_p++ = *script->script_p++;
|
||||
if (script->script_p == script->end_p)
|
||||
break;
|
||||
if (token_p == &token[BSPMAXTOKEN])
|
||||
{
|
||||
//printf ("Token too large on line %i\n",scriptline);
|
||||
}
|
||||
}
|
||||
script->script_p++;
|
||||
}
|
||||
else // regular token
|
||||
while ( *script->script_p > 32 && *script->script_p != ';')
|
||||
{
|
||||
*token_p++ = *script->script_p++;
|
||||
if (script->script_p == script->end_p)
|
||||
break;
|
||||
if (token_p == &token[BSPMAXTOKEN])
|
||||
{
|
||||
//printf ("Token too large on line %i\n",scriptline);
|
||||
}
|
||||
}
|
||||
|
||||
*token_p = 0;
|
||||
|
||||
if (!strcmp (token, "$include"))
|
||||
{
|
||||
//getToken (false);
|
||||
//AddScriptToStack (token);
|
||||
return false;//getToken (crossline);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
char *BspLoader::copystring(const char *s)
|
||||
{
|
||||
char *b;
|
||||
b = (char*) malloc( strlen(s)+1);
|
||||
strcpy (b, s);
|
||||
return b;
|
||||
}
|
||||
|
||||
void BspLoader::stripTrailing( char *e ) {
|
||||
char *s;
|
||||
|
||||
s = e + strlen(e)-1;
|
||||
while (s >= e && *s <= 32)
|
||||
{
|
||||
*s = 0;
|
||||
s--;
|
||||
}
|
||||
}
|
||||
/*
|
||||
=================
|
||||
parseEpair
|
||||
=================
|
||||
*/
|
||||
BSPKeyValuePair *BspLoader::parseEpair( void ) {
|
||||
BSPKeyValuePair *e;
|
||||
|
||||
e = (struct BSPPair*) malloc( sizeof(BSPKeyValuePair));
|
||||
memset( e, 0, sizeof(BSPKeyValuePair) );
|
||||
|
||||
if ( strlen(token) >= BSPMAX_KEY-1 ) {
|
||||
//printf ("ParseEpar: token too long");
|
||||
}
|
||||
e->key = copystring( token );
|
||||
getToken( false );
|
||||
if ( strlen(token) >= BSPMAX_VALUE-1 ) {
|
||||
|
||||
//printf ("ParseEpar: token too long");
|
||||
}
|
||||
e->value = copystring( token );
|
||||
|
||||
// strip trailing spaces that sometimes get accidentally
|
||||
// added in the editor
|
||||
stripTrailing( e->key );
|
||||
stripTrailing( e->value );
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
================
|
||||
parseEntity
|
||||
================
|
||||
*/
|
||||
bool BspLoader::parseEntity( void ) {
|
||||
BSPKeyValuePair *e;
|
||||
BSPEntity *mapent;
|
||||
|
||||
if ( !getToken (true) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( strcmp (token, "{") ) {
|
||||
|
||||
//printf ("parseEntity: { not found");
|
||||
}
|
||||
|
||||
BSPEntity bla;
|
||||
bla.brushes = 0;
|
||||
bla.epairs = 0;
|
||||
bla.firstDrawSurf = 0;
|
||||
bla.origin[0] = 0.f;
|
||||
bla.origin[1] = 0.f;
|
||||
bla.origin[2] = 0.f;
|
||||
bla.patches = 0;
|
||||
|
||||
m_entities.push_back(bla);
|
||||
mapent = &m_entities[m_entities.size()-1];
|
||||
m_num_entities++;
|
||||
|
||||
do {
|
||||
if ( !getToken (true) ) {
|
||||
//printf("parseEntity: EOF without closing brace");
|
||||
}
|
||||
if ( !strcmp (token, "}") ) {
|
||||
break;
|
||||
}
|
||||
e = (struct BSPPair*)parseEpair ();
|
||||
e->next = mapent->epairs;
|
||||
mapent->epairs = e;
|
||||
} while (1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
parseEntities
|
||||
|
||||
Parses the dentdata string into entities
|
||||
================
|
||||
*/
|
||||
void BspLoader::parseEntities( void ) {
|
||||
m_num_entities = 0;
|
||||
m_entities.clear();
|
||||
|
||||
parseFromMemory( &m_dentdata[0], m_entdatasize );
|
||||
|
||||
while ( parseEntity () ) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int BspLoader::getMachineEndianness()
|
||||
{
|
||||
long int i = 1;
|
||||
const char *p = (const char *) &i;
|
||||
if (p[0] == 1) // Lowest address contains the least significant byte
|
||||
return BSP_LITTLE_ENDIAN;
|
||||
else
|
||||
return BSP_BIG_ENDIAN;
|
||||
}
|
||||
|
||||
short BspLoader::isLittleShort (short l)
|
||||
{
|
||||
if (machineEndianness() == BSP_BIG_ENDIAN)
|
||||
{
|
||||
unsigned char b1,b2;
|
||||
|
||||
b1 = l&255;
|
||||
b2 = (l>>8)&255;
|
||||
|
||||
return (b1<<8) + b2;
|
||||
}
|
||||
//little endian
|
||||
return l;
|
||||
}
|
||||
|
||||
short BspLoader::isBigShort (short l)
|
||||
{
|
||||
if (machineEndianness() == BSP_BIG_ENDIAN)
|
||||
{
|
||||
return l;
|
||||
}
|
||||
|
||||
unsigned char b1,b2;
|
||||
|
||||
b1 = l&255;
|
||||
b2 = (l>>8)&255;
|
||||
|
||||
return (b1<<8) + b2;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int BspLoader::isLittleLong (int l)
|
||||
{
|
||||
if (machineEndianness() == BSP_BIG_ENDIAN)
|
||||
{
|
||||
unsigned char b1,b2,b3,b4;
|
||||
|
||||
b1 = l&255;
|
||||
b2 = (l>>8)&255;
|
||||
b3 = (l>>16)&255;
|
||||
b4 = (l>>24)&255;
|
||||
|
||||
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
|
||||
}
|
||||
|
||||
//little endian
|
||||
return l;
|
||||
|
||||
}
|
||||
|
||||
int BspLoader::isBigLong (int l)
|
||||
{
|
||||
if (machineEndianness() == BSP_BIG_ENDIAN)
|
||||
{
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
unsigned char b1,b2,b3,b4;
|
||||
|
||||
b1 = l&255;
|
||||
b2 = (l>>8)&255;
|
||||
b3 = (l>>16)&255;
|
||||
b4 = (l>>24)&255;
|
||||
|
||||
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
|
||||
|
||||
}
|
||||
|
||||
|
||||
float BspLoader::isLittleFloat (float l)
|
||||
{
|
||||
if (machineEndianness() == BSP_BIG_ENDIAN)
|
||||
{
|
||||
union {unsigned char b[4]; float f;} in, out;
|
||||
|
||||
in.f = l;
|
||||
out.b[0] = in.b[3];
|
||||
out.b[1] = in.b[2];
|
||||
out.b[2] = in.b[1];
|
||||
out.b[3] = in.b[0];
|
||||
|
||||
return out.f;
|
||||
}
|
||||
|
||||
//little endian
|
||||
return l;
|
||||
}
|
||||
|
||||
float BspLoader::isBigFloat (float l)
|
||||
{
|
||||
if (machineEndianness() == BSP_BIG_ENDIAN)
|
||||
{
|
||||
return l;
|
||||
}
|
||||
//little endian
|
||||
union {unsigned char b[4]; float f;} in, out;
|
||||
|
||||
in.f = l;
|
||||
out.b[0] = in.b[3];
|
||||
out.b[1] = in.b[2];
|
||||
out.b[2] = in.b[1];
|
||||
out.b[3] = in.b[0];
|
||||
|
||||
return out.f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// swapBlock
|
||||
// If all values are 32 bits, this can be used to swap everything
|
||||
//
|
||||
|
||||
void BspLoader::swapBlock( int *block, int sizeOfBlock ) {
|
||||
int i;
|
||||
|
||||
sizeOfBlock >>= 2;
|
||||
for ( i = 0 ; i < sizeOfBlock ; i++ ) {
|
||||
block[i] = isLittleLong( block[i] );
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// copyLump
|
||||
//
|
||||
|
||||
int BspLoader::copyLump( BSPHeader *header, int lump, void *dest, int size ) {
|
||||
int length, ofs;
|
||||
|
||||
length = header->lumps[lump].filelen;
|
||||
ofs = header->lumps[lump].fileofs;
|
||||
|
||||
//if ( length % size ) {
|
||||
// printf ("loadBSPFile: odd lump size");
|
||||
//}
|
||||
|
||||
memcpy( dest, (unsigned char *)header + ofs, length );
|
||||
|
||||
return length / size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// swapBSPFile
|
||||
//
|
||||
|
||||
void BspLoader::swapBSPFile( void ) {
|
||||
int i;
|
||||
|
||||
// models
|
||||
swapBlock( (int *) &m_dmodels[0], m_nummodels * sizeof( m_dmodels[0] ) );
|
||||
|
||||
// shaders (don't swap the name)
|
||||
for ( i = 0 ; i < m_numShaders ; i++ ) {
|
||||
m_dshaders[i].contentFlags = isLittleLong( m_dshaders[i].contentFlags );
|
||||
m_dshaders[i].surfaceFlags = isLittleLong( m_dshaders[i].surfaceFlags );
|
||||
}
|
||||
|
||||
// planes
|
||||
swapBlock( (int *)&m_dplanes[0], m_numplanes * sizeof( m_dplanes[0] ) );
|
||||
|
||||
// nodes
|
||||
swapBlock( (int *)&m_dnodes[0], m_numnodes * sizeof( m_dnodes[0] ) );
|
||||
|
||||
// leafs
|
||||
swapBlock( (int *)&m_dleafs[0], m_numleafs * sizeof( m_dleafs[0] ) );
|
||||
|
||||
// leaffaces
|
||||
swapBlock( (int *)&m_dleafsurfaces[0], m_numleafsurfaces * sizeof( m_dleafsurfaces[0] ) );
|
||||
|
||||
// leafbrushes
|
||||
swapBlock( (int *)&m_dleafbrushes[0], m_numleafbrushes * sizeof( m_dleafbrushes[0] ) );
|
||||
|
||||
// brushes
|
||||
swapBlock( (int *)&m_dbrushes[0], m_numbrushes * sizeof( m_dbrushes[0] ) );
|
||||
|
||||
// brushsides
|
||||
swapBlock( (int *)&m_dbrushsides[0], m_numbrushsides * sizeof( m_dbrushsides[0] ) );
|
||||
|
||||
// vis
|
||||
((int *)&m_visBytes)[0] = isLittleLong( ((int *)&m_visBytes)[0] );
|
||||
((int *)&m_visBytes)[1] = isLittleLong( ((int *)&m_visBytes)[1] );
|
||||
|
||||
|
||||
// drawindexes
|
||||
swapBlock( (int *)&m_drawIndexes[0], m_numDrawIndexes * sizeof( m_drawIndexes[0] ) );
|
||||
|
||||
// drawsurfs
|
||||
swapBlock( (int *)&m_drawSurfaces[0], m_numDrawSurfaces * sizeof( m_drawSurfaces[0] ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool BspLoader::findVectorByName(float* outvec,const char* name)
|
||||
{
|
||||
const char *cl;
|
||||
BSPVector3 origin;
|
||||
|
||||
bool found = false;
|
||||
|
||||
parseEntities();
|
||||
|
||||
for ( int i = 1; i < m_num_entities; i++ ) {
|
||||
cl = getValueForKey (&m_entities[i], "classname");
|
||||
if ( !strcmp( cl, "info_player_start" ) ) {
|
||||
getVectorForKey( &m_entities[i], "origin", origin );
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if ( !strcmp( cl, "info_player_deathmatch" ) ) {
|
||||
getVectorForKey( &m_entities[i], "origin", origin );
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
outvec[0] = origin[0];
|
||||
outvec[1] = origin[1];
|
||||
outvec[2] = origin[2];
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const BSPEntity * BspLoader::getEntityByValue( const char* name, const char* value)
|
||||
{
|
||||
const BSPEntity* entity = NULL;
|
||||
|
||||
for ( int i = 1; i < m_num_entities; i++ ) {
|
||||
|
||||
const BSPEntity& ent = m_entities[i];
|
||||
|
||||
const char* cl = getValueForKey (&m_entities[i], name);
|
||||
if ( !strcmp( cl, value ) ) {
|
||||
entity = &ent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
===========================================================================
|
||||
Copyright (C) 1999-2005 Id Software, Inc.
|
||||
|
||||
This file is part of Quake III Arena source code.
|
||||
|
||||
Quake III Arena source code is free software; you can redistribute it
|
||||
and/or modify it under the terms of the GNU bteral Public License as
|
||||
published by the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
Quake III Arena source code is distributed in the hope that it will be
|
||||
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU bteral Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU bteral Public License
|
||||
along with Foobar; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef BSP_LOADER_H
|
||||
#define BSP_LOADER_H
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
#define BSPMAXTOKEN 1024
|
||||
#define BSPMAX_KEY 32
|
||||
#define BSPMAX_VALUE 1024
|
||||
#define BSPCONTENTS_SOLID 1
|
||||
#define BSPCONTENTS_AREAPORTAL 0x8000
|
||||
#define BSPLUMP_ENTITIES 0
|
||||
#define BSPLUMP_SHADERS 1
|
||||
#define BSPLUMP_PLANES 2
|
||||
#define BSPLUMP_NODES 3
|
||||
#define BSPLUMP_LEAFS 4
|
||||
#define BSPLUMP_LEAFSURFACES 5
|
||||
#define BSPLUMP_LEAFBRUSHES 6
|
||||
#define LUMP_MODELS 7
|
||||
#define LUMP_BRUSHES 8
|
||||
#define LUMP_BRUSHSIDES 9
|
||||
#define LUMP_DRAWVERTS 10
|
||||
#define LUMP_DRAWINDEXES 11
|
||||
#define LUMP_SURFACES 13
|
||||
#define LUMP_LIGHTMAPS 14
|
||||
#define LUMP_LIGHTGRID 15
|
||||
#define LUMP_VISIBILITY 16
|
||||
#define HEADER_LUMPS 17
|
||||
#define MAX_QPATH 64
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
int fileofs, filelen;
|
||||
} BSPLump;
|
||||
|
||||
typedef float BSPVector3[3];
|
||||
|
||||
typedef struct {
|
||||
int ident;
|
||||
int version;
|
||||
|
||||
BSPLump lumps[HEADER_LUMPS];
|
||||
} BSPHeader;
|
||||
|
||||
|
||||
typedef struct {
|
||||
float mins[3], maxs[3];
|
||||
int firstSurface, numSurfaces;
|
||||
int firstBrush, numBrushes;
|
||||
} BSPModel;
|
||||
|
||||
typedef struct {
|
||||
char shader[MAX_QPATH];
|
||||
int surfaceFlags;
|
||||
int contentFlags;
|
||||
} BSPShader;
|
||||
|
||||
typedef struct {
|
||||
float normal[3];
|
||||
float dist;
|
||||
} BSPPlane;
|
||||
|
||||
typedef struct {
|
||||
int planeNum;
|
||||
int children[2];
|
||||
int mins[3];
|
||||
int maxs[3];
|
||||
} BSPNode;
|
||||
|
||||
typedef struct {
|
||||
int cluster;
|
||||
int area;
|
||||
|
||||
int mins[3];
|
||||
int maxs[3];
|
||||
|
||||
int firstLeafSurface;
|
||||
int numLeafSurfaces;
|
||||
|
||||
int firstLeafBrush;
|
||||
int numLeafBrushes;
|
||||
} BSPLeaf;
|
||||
|
||||
typedef struct {
|
||||
int planeNum;
|
||||
int shaderNum;
|
||||
} BSPBrushSide;
|
||||
|
||||
typedef struct {
|
||||
int firstSide;
|
||||
int numSides;
|
||||
int shaderNum;
|
||||
} BSPBrush;
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct BSPPair {
|
||||
struct BSPPair *next;
|
||||
char *key;
|
||||
char *value;
|
||||
} BSPKeyValuePair;
|
||||
|
||||
typedef struct {
|
||||
BSPVector3 origin;
|
||||
struct bspbrush_s *brushes;
|
||||
struct parseMesh_s *patches;
|
||||
int firstDrawSurf;
|
||||
BSPKeyValuePair *epairs;
|
||||
} BSPEntity;
|
||||
|
||||
typedef enum {
|
||||
MST_BAD,
|
||||
MST_PLANAR,
|
||||
MST_PATCH,
|
||||
MST_TRIANGLE_SOUP,
|
||||
MST_FLARE
|
||||
} BSPMapSurface;
|
||||
|
||||
typedef struct {
|
||||
int shaderNum;
|
||||
int fogNum;
|
||||
int surfaceType;
|
||||
|
||||
int firstVert;
|
||||
int numVerts;
|
||||
|
||||
int firstIndex;
|
||||
int numIndexes;
|
||||
|
||||
int lightmapNum;
|
||||
int lightmapX, lightmapY;
|
||||
int lightmapWidth, lightmapHeight;
|
||||
|
||||
BSPVector3 lightmapOrigin;
|
||||
BSPVector3 lightmapVecs[3];
|
||||
|
||||
int patchWidth;
|
||||
int patchHeight;
|
||||
} BSPSurface;
|
||||
|
||||
|
||||
|
||||
///GPL code from IdSofware to parse a Quake 3 BSP file
|
||||
///check that your platform define __BIG_ENDIAN__ correctly (in BspLoader.cpp)
|
||||
class BspLoader
|
||||
{
|
||||
int m_Endianness;
|
||||
|
||||
public:
|
||||
|
||||
BspLoader();
|
||||
|
||||
bool loadBSPFile( void* memoryBuffer);
|
||||
|
||||
const char* getValueForKey( const BSPEntity *ent, const char *key ) const;
|
||||
|
||||
bool getVectorForKey( const BSPEntity *ent, const char *key, BSPVector3 vec );
|
||||
|
||||
float getFloatForKey( const BSPEntity *ent, const char *key );
|
||||
|
||||
void parseEntities( void );
|
||||
|
||||
bool findVectorByName(float* outvec,const char* name);
|
||||
|
||||
const BSPEntity * getEntityByValue( const char* name, const char* value);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void parseFromMemory (char *buffer, int size);
|
||||
|
||||
|
||||
|
||||
bool isEndOfScript (bool crossline);
|
||||
|
||||
bool getToken (bool crossline);
|
||||
|
||||
char *copystring(const char *s);
|
||||
|
||||
void stripTrailing( char *e );
|
||||
|
||||
BSPKeyValuePair * parseEpair( void );
|
||||
|
||||
bool parseEntity( void );
|
||||
|
||||
short isLittleShort (short l);
|
||||
int isLittleLong (int l);
|
||||
float isLittleFloat (float l);
|
||||
|
||||
int isBigLong (int l);
|
||||
short isBigShort (short l);
|
||||
float isBigFloat (float l);
|
||||
|
||||
void swapBlock( int *block, int sizeOfBlock );
|
||||
|
||||
int copyLump( BSPHeader *header, int lump, void *dest, int size );
|
||||
|
||||
void swapBSPFile( void );
|
||||
|
||||
|
||||
|
||||
|
||||
public: //easier for conversion
|
||||
int m_num_entities;
|
||||
btAlignedObjectArray<BSPEntity> m_entities;
|
||||
|
||||
int m_nummodels;
|
||||
btAlignedObjectArray<BSPModel> m_dmodels;
|
||||
|
||||
int m_numShaders;
|
||||
btAlignedObjectArray<BSPShader> m_dshaders;
|
||||
|
||||
int m_entdatasize;
|
||||
btAlignedObjectArray<char> m_dentdata;
|
||||
|
||||
int m_numleafs;
|
||||
btAlignedObjectArray<BSPLeaf> m_dleafs;
|
||||
|
||||
int m_numplanes;
|
||||
btAlignedObjectArray<BSPPlane> m_dplanes;
|
||||
|
||||
int m_numnodes;
|
||||
btAlignedObjectArray<BSPNode> m_dnodes;
|
||||
|
||||
int m_numleafsurfaces;
|
||||
btAlignedObjectArray<int> m_dleafsurfaces;
|
||||
|
||||
int m_numleafbrushes;
|
||||
btAlignedObjectArray<int> m_dleafbrushes;
|
||||
|
||||
int m_numbrushes;
|
||||
btAlignedObjectArray<BSPBrush> m_dbrushes;
|
||||
|
||||
int m_numbrushsides;
|
||||
btAlignedObjectArray<BSPBrushSide> m_dbrushsides;
|
||||
|
||||
int m_numLightBytes;
|
||||
btAlignedObjectArray<unsigned char> m_lightBytes;
|
||||
|
||||
int m_numGridPoints;
|
||||
btAlignedObjectArray<unsigned char> m_gridData;
|
||||
|
||||
int m_numVisBytes;
|
||||
btAlignedObjectArray<unsigned char> m_visBytes;
|
||||
|
||||
|
||||
int m_numDrawIndexes;
|
||||
btAlignedObjectArray<int> m_drawIndexes;
|
||||
|
||||
int m_numDrawSurfaces;
|
||||
btAlignedObjectArray<BSPSurface> m_drawSurfaces;
|
||||
|
||||
enum
|
||||
{
|
||||
BSP_LITTLE_ENDIAN = 0,
|
||||
BSP_BIG_ENDIAN = 1
|
||||
};
|
||||
|
||||
//returns machines big endian / little endian
|
||||
//
|
||||
int getMachineEndianness();
|
||||
|
||||
inline int machineEndianness()
|
||||
{
|
||||
return m_Endianness;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //BSP_LOADER_H
|
||||
@@ -0,0 +1,26 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL }
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppBspPhysicsDemo
|
||||
main.cpp
|
||||
BspDemo.cpp
|
||||
BspLoader.cpp
|
||||
BspConverter.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
SubDir TOP Demos BspDemo ;
|
||||
|
||||
BulletDemo BspDemo : [ Wildcard *.h *.cpp ] ;
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#include "BspDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
char* makeExeToBspFilename(const char* lpCmdLine);
|
||||
char* getLastFileName();
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
BspDemo* bspDemo = new BspDemo();
|
||||
|
||||
const char* bspfilename = "BspDemo.bsp";
|
||||
|
||||
printf("argc=%i\n",argc);
|
||||
{
|
||||
for (int i=0;i<argc;i++)
|
||||
{
|
||||
printf("argv[%i]=%s\n",i,argv[i]);
|
||||
}
|
||||
|
||||
bspfilename = makeExeToBspFilename(argv[0]);
|
||||
printf("new name=%s\n",bspfilename);
|
||||
}
|
||||
if (argc>1)
|
||||
{
|
||||
bspfilename = argv[1];
|
||||
}
|
||||
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
|
||||
// Enrico: TODO: Should change parameter type of initPhysics() to std::string or at least const char *
|
||||
bspDemo->initPhysics((char*)bspfilename);
|
||||
|
||||
bspDemo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
|
||||
|
||||
return glutmain(argc, argv,640,480,"Bullet Quake BSP Physics Viewer http://bulletphysics.org",bspDemo);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,996 @@
|
||||
|
||||
/* This demo has been modified to use the Bullet C-API.
|
||||
The C-API is minimal, and will develop based on developer feedback.
|
||||
The C++ API is recommended, and compatible with the C-API.
|
||||
*/
|
||||
|
||||
/* Copyright (c) Mark J. Kilgard, 1994, 1997. */
|
||||
|
||||
/* This program is freely distributable without licensing fees
|
||||
and is provided without guarantee or warrantee expressed or
|
||||
implied. This program is -not- in the public domain. */
|
||||
|
||||
/* Example for PC game developers to show how to *combine* texturing,
|
||||
reflections, and projected shadows all in real-time with OpenGL.
|
||||
Robust reflections use stenciling. Robust projected shadows
|
||||
use both stenciling and polygon offset. PC game programmers
|
||||
should realize that neither stenciling nor polygon offset are
|
||||
supported by Direct3D, so these real-time rendering algorithms
|
||||
are only really viable with OpenGL.
|
||||
|
||||
The program has modes for disabling the stenciling and polygon
|
||||
offset uses. It is worth running this example with these features
|
||||
toggled off so you can see the sort of artifacts that result.
|
||||
|
||||
Notice that the floor texturing, reflections, and shadowing
|
||||
all co-exist properly. */
|
||||
|
||||
/* When you run this program: Left mouse button controls the
|
||||
view. Middle mouse button controls light position (left &
|
||||
right rotates light around dino; up & down moves light
|
||||
position up and down). Right mouse button pops up menu. */
|
||||
|
||||
/* Check out the comments in the "redraw" routine to see how the
|
||||
reflection blending and surface stenciling is done. You can
|
||||
also see in "redraw" how the projected shadows are rendered,
|
||||
including the use of stenciling and polygon offset. */
|
||||
|
||||
/* This program is derived from glutdino.c */
|
||||
|
||||
/* Compile: cc -o dinoshade dinoshade.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h> /* for cos(), sin(), and sqrt() */
|
||||
#ifdef WIN32//for glut.h
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef CALLBACK
|
||||
#define CALLBACK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//think different
|
||||
#if defined(__APPLE__) && !defined (VMDMESA)
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#include <GLUT/glut.h>
|
||||
#define GLVOIDPTR GLvoid(*)()
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#include <GL/glext.h>
|
||||
#define GLVOIDPTR void(CALLBACK*)()
|
||||
#endif
|
||||
|
||||
/* Some <math.h> files do not define M_PI... */
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
|
||||
//#include "../../include/Bullet-C-Api.h"
|
||||
#include "Bullet-C-Api.h"
|
||||
|
||||
|
||||
|
||||
plPhysicsSdkHandle physicsSdk=0;
|
||||
plDynamicsWorldHandle dynamicsWorld=0;
|
||||
plRigidBodyHandle floorRigidBody;
|
||||
plRigidBodyHandle dinoRigidBody;
|
||||
|
||||
/* Variable controlling various rendering modes. */
|
||||
static int stencilReflection = 1, stencilShadow = 1, offsetShadow = 1;
|
||||
static int renderShadow = 1, renderDinosaur = 1, renderReflection = 1;
|
||||
static int linearFiltering = 0, useMipmaps = 0, useTexture = 1;
|
||||
static int reportSpeed = 0;
|
||||
static int animation = 1;
|
||||
static GLboolean lightSwitch = GL_TRUE;
|
||||
static int directionalLight = 1;
|
||||
static int forceExtension = 0;
|
||||
|
||||
/* Time varying or user-controled variables. */
|
||||
static float jump = 0.0;
|
||||
static float lightAngle = 0.0, lightHeight = 20;
|
||||
GLfloat angle = -150; /* in degrees */
|
||||
GLfloat angle2 = 30; /* in degrees */
|
||||
|
||||
int moving, startx, starty;
|
||||
int lightMoving = 0, lightStartX, lightStartY;
|
||||
|
||||
enum {
|
||||
MISSING, EXTENSION, ONE_DOT_ONE
|
||||
};
|
||||
int polygonOffsetVersion;
|
||||
|
||||
static GLdouble bodyWidth = 3.0;
|
||||
/* *INDENT-OFF* */
|
||||
static GLfloat body[][2] = { {0, 3}, {1, 1}, {5, 1}, {8, 4}, {10, 4}, {11, 5},
|
||||
{11, 11.5}, {13, 12}, {13, 13}, {10, 13.5}, {13, 14}, {13, 15}, {11, 16},
|
||||
{8, 16}, {7, 15}, {7, 13}, {8, 12}, {7, 11}, {6, 6}, {4, 3}, {3, 2},
|
||||
{1, 2} };
|
||||
static GLfloat arm[][2] = { {8, 10}, {9, 9}, {10, 9}, {13, 8}, {14, 9}, {16, 9},
|
||||
{15, 9.5}, {16, 10}, {15, 10}, {15.5, 11}, {14.5, 10}, {14, 11}, {14, 10},
|
||||
{13, 9}, {11, 11}, {9, 11} };
|
||||
static GLfloat leg[][2] = { {8, 6}, {8, 4}, {9, 3}, {9, 2}, {8, 1}, {8, 0.5}, {9, 0},
|
||||
{12, 0}, {10, 1}, {10, 2}, {12, 4}, {11, 6}, {10, 7}, {9, 7} };
|
||||
static GLfloat eye[][2] = { {8.75, 15}, {9, 14.7}, {9.6, 14.7}, {10.1, 15},
|
||||
{9.6, 15.25}, {9, 15.25} };
|
||||
static GLfloat lightPosition[4];
|
||||
static GLfloat lightColor[] = {0.8, 1.0, 0.8, 1.0}; /* green-tinted */
|
||||
static GLfloat skinColor[] = {0.1, 1.0, 0.1, 1.0}, eyeColor[] = {1.0, 0.2, 0.2, 1.0};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* Nice floor texture tiling pattern. */
|
||||
static char *circles[] = {
|
||||
"....xxxx........",
|
||||
"..xxxxxxxx......",
|
||||
".xxxxxxxxxx.....",
|
||||
".xxx....xxx.....",
|
||||
"xxx......xxx....",
|
||||
"xxx......xxx....",
|
||||
"xxx......xxx....",
|
||||
"xxx......xxx....",
|
||||
".xxx....xxx.....",
|
||||
".xxxxxxxxxx.....",
|
||||
"..xxxxxxxx......",
|
||||
"....xxxx........",
|
||||
"................",
|
||||
"................",
|
||||
"................",
|
||||
"................",
|
||||
};
|
||||
|
||||
static void
|
||||
makeFloorTexture(void)
|
||||
{
|
||||
GLubyte floorTexture[16][16][3];
|
||||
GLubyte *loc;
|
||||
int s, t;
|
||||
loc=0;
|
||||
|
||||
/* Setup RGB image for the texture. */
|
||||
loc = (GLubyte*) floorTexture;
|
||||
for (t = 0; t < 16; t++) {
|
||||
for (s = 0; s < 16; s++) {
|
||||
if (circles[t][s] == 'x') {
|
||||
/* Nice green. */
|
||||
loc[0] = 0x1f;
|
||||
loc[1] = 0x8f;
|
||||
loc[2] = 0x1f;
|
||||
} else {
|
||||
/* Light gray. */
|
||||
loc[0] = 0xaa;
|
||||
loc[1] = 0xaa;
|
||||
loc[2] = 0xaa;
|
||||
}
|
||||
loc += 3;
|
||||
}
|
||||
}
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
if (useMipmaps) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
GL_LINEAR_MIPMAP_LINEAR);
|
||||
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 16, 16,
|
||||
GL_RGB, GL_UNSIGNED_BYTE, floorTexture);
|
||||
} else {
|
||||
if (linearFiltering) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
} else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,
|
||||
GL_RGB, GL_UNSIGNED_BYTE, floorTexture);
|
||||
}
|
||||
}
|
||||
|
||||
enum {
|
||||
X, Y, Z, W
|
||||
};
|
||||
enum {
|
||||
A, B, C, D
|
||||
};
|
||||
|
||||
/* Create a matrix that will project the desired shadow. */
|
||||
void
|
||||
shadowMatrix(GLfloat shadowMat[4][4],
|
||||
GLfloat groundplane[4],
|
||||
GLfloat lightpos[4])
|
||||
{
|
||||
GLfloat dot;
|
||||
|
||||
/* Find dot product between light position vector and ground plane normal. */
|
||||
dot = groundplane[X] * lightpos[X] +
|
||||
groundplane[Y] * lightpos[Y] +
|
||||
groundplane[Z] * lightpos[Z] +
|
||||
groundplane[W] * lightpos[W];
|
||||
|
||||
shadowMat[0][0] = dot - lightpos[X] * groundplane[X];
|
||||
shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y];
|
||||
shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z];
|
||||
shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W];
|
||||
|
||||
shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X];
|
||||
shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y];
|
||||
shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z];
|
||||
shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W];
|
||||
|
||||
shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X];
|
||||
shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y];
|
||||
shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z];
|
||||
shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W];
|
||||
|
||||
shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X];
|
||||
shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y];
|
||||
shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z];
|
||||
shadowMat[3][3] = dot - lightpos[W] * groundplane[W];
|
||||
|
||||
}
|
||||
|
||||
/* Find the plane equation given 3 points. */
|
||||
void
|
||||
findPlane(GLfloat plane[4],
|
||||
GLfloat v0[3], GLfloat v1[3], GLfloat v2[3])
|
||||
{
|
||||
GLfloat vec0[3], vec1[3];
|
||||
|
||||
/* Need 2 vectors to find cross product. */
|
||||
vec0[X] = v1[X] - v0[X];
|
||||
vec0[Y] = v1[Y] - v0[Y];
|
||||
vec0[Z] = v1[Z] - v0[Z];
|
||||
|
||||
vec1[X] = v2[X] - v0[X];
|
||||
vec1[Y] = v2[Y] - v0[Y];
|
||||
vec1[Z] = v2[Z] - v0[Z];
|
||||
|
||||
/* find cross product to get A, B, and C of plane equation */
|
||||
plane[A] = vec0[Y] * vec1[Z] - vec0[Z] * vec1[Y];
|
||||
plane[B] = -(vec0[X] * vec1[Z] - vec0[Z] * vec1[X]);
|
||||
plane[C] = vec0[X] * vec1[Y] - vec0[Y] * vec1[X];
|
||||
|
||||
plane[D] = -(plane[A] * v0[X] + plane[B] * v0[Y] + plane[C] * v0[Z]);
|
||||
}
|
||||
|
||||
void
|
||||
extrudeSolidFromPolygon(GLfloat data[][2], unsigned int dataSize,
|
||||
GLdouble thickness, GLuint side, GLuint edge, GLuint whole)
|
||||
{
|
||||
static GLUtriangulatorObj *tobj = NULL;
|
||||
GLdouble vertex[3], dx, dy, len;
|
||||
int i;
|
||||
int count = dataSize / (2 * sizeof(GLfloat));
|
||||
|
||||
if (tobj == NULL) {
|
||||
tobj = gluNewTess(); /* create and initialize a GLU
|
||||
polygon * * tesselation object */
|
||||
gluTessCallback(tobj, (GLenum)GLU_BEGIN, (GLVOIDPTR)glBegin);
|
||||
gluTessCallback(tobj, (GLenum)GLU_VERTEX, (GLVOIDPTR)glVertex2fv); /* semi-tricky */
|
||||
gluTessCallback(tobj, (GLenum)GLU_END, (GLVOIDPTR)glEnd);
|
||||
}
|
||||
glNewList(side, GL_COMPILE);
|
||||
glShadeModel(GL_SMOOTH); /* smooth minimizes seeing
|
||||
tessellation */
|
||||
gluBeginPolygon(tobj);
|
||||
for (i = 0; i < count; i++) {
|
||||
vertex[0] = data[i][0];
|
||||
vertex[1] = data[i][1];
|
||||
vertex[2] = 0;
|
||||
gluTessVertex(tobj, vertex, data[i]);
|
||||
}
|
||||
gluEndPolygon(tobj);
|
||||
glEndList();
|
||||
glNewList(edge, GL_COMPILE);
|
||||
glShadeModel(GL_FLAT); /* flat shade keeps angular hands
|
||||
from being "smoothed" */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= count; i++) {
|
||||
/* mod function handles closing the edge */
|
||||
glVertex3f(data[i % count][0], data[i % count][1], 0.0);
|
||||
glVertex3f(data[i % count][0], data[i % count][1], thickness);
|
||||
/* Calculate a unit normal by dividing by Euclidean
|
||||
distance. We * could be lazy and use
|
||||
glEnable(GL_NORMALIZE) so we could pass in * arbitrary
|
||||
normals for a very slight performance hit. */
|
||||
dx = data[(i + 1) % count][1] - data[i % count][1];
|
||||
dy = data[i % count][0] - data[(i + 1) % count][0];
|
||||
len = sqrt(dx * dx + dy * dy);
|
||||
glNormal3f(dx / len, dy / len, 0.0);
|
||||
}
|
||||
glEnd();
|
||||
glEndList();
|
||||
glNewList(whole, GL_COMPILE);
|
||||
glFrontFace(GL_CW);
|
||||
glCallList(edge);
|
||||
glNormal3f(0.0, 0.0, -1.0); /* constant normal for side */
|
||||
glCallList(side);
|
||||
glPushMatrix();
|
||||
glTranslatef(0.0, 0.0, thickness);
|
||||
glFrontFace(GL_CCW);
|
||||
glNormal3f(0.0, 0.0, 1.0); /* opposite normal for other side */
|
||||
glCallList(side);
|
||||
glPopMatrix();
|
||||
glEndList();
|
||||
}
|
||||
|
||||
/* Enumerants for refering to display lists. */
|
||||
typedef enum {
|
||||
RESERVED, BODY_SIDE, BODY_EDGE, BODY_WHOLE, ARM_SIDE, ARM_EDGE, ARM_WHOLE,
|
||||
LEG_SIDE, LEG_EDGE, LEG_WHOLE, EYE_SIDE, EYE_EDGE, EYE_WHOLE
|
||||
} displayLists;
|
||||
|
||||
static void
|
||||
makeDinosaur(void)
|
||||
{
|
||||
extrudeSolidFromPolygon(body, sizeof(body), bodyWidth,
|
||||
BODY_SIDE, BODY_EDGE, BODY_WHOLE);
|
||||
extrudeSolidFromPolygon(arm, sizeof(arm), bodyWidth / 4,
|
||||
ARM_SIDE, ARM_EDGE, ARM_WHOLE);
|
||||
extrudeSolidFromPolygon(leg, sizeof(leg), bodyWidth / 2,
|
||||
LEG_SIDE, LEG_EDGE, LEG_WHOLE);
|
||||
extrudeSolidFromPolygon(eye, sizeof(eye), bodyWidth + 0.2,
|
||||
EYE_SIDE, EYE_EDGE, EYE_WHOLE);
|
||||
}
|
||||
|
||||
static void
|
||||
drawDinosaur(void)
|
||||
|
||||
{
|
||||
plReal matrix[16];
|
||||
|
||||
glPushMatrix();
|
||||
/* Translate the dinosaur to be at (0,8,0). */
|
||||
|
||||
plGetOpenGLMatrix(dinoRigidBody,matrix);
|
||||
// plGetPosition(dinoRigidBody,dinoWorldPos);
|
||||
// glTranslatef(-8, 0, -bodyWidth / 2);
|
||||
//glTranslatef(0.0, jump, 0.0);
|
||||
// glTranslatef(dinoWorldPos[0],dinoWorldPos[1],dinoWorldPos[2]);
|
||||
|
||||
#ifdef BT_USE_DOUBLE_PRECISION
|
||||
glMultMatrixd(matrix);
|
||||
#else
|
||||
glMultMatrixf(matrix);
|
||||
#endif
|
||||
// glutSolidCube(15);
|
||||
glTranslatef(-8.5, -8.5, 0);
|
||||
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, skinColor);
|
||||
glCallList(BODY_WHOLE);
|
||||
glTranslatef(0.0, 0.0, bodyWidth);
|
||||
glCallList(ARM_WHOLE);
|
||||
glCallList(LEG_WHOLE);
|
||||
glTranslatef(0.0, 0.0, -bodyWidth - bodyWidth / 4);
|
||||
glCallList(ARM_WHOLE);
|
||||
glTranslatef(0.0, 0.0, -bodyWidth / 4);
|
||||
glCallList(LEG_WHOLE);
|
||||
glTranslatef(0.0, 0.0, bodyWidth / 2 - 0.1);
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, eyeColor);
|
||||
glCallList(EYE_WHOLE);
|
||||
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
static GLfloat floorVertices[4][3] = {
|
||||
{ -20.0, 0.0, 20.0 },
|
||||
{ 20.0, 0.0, 20.0 },
|
||||
{ 20.0, 0.0, -20.0 },
|
||||
{ -20.0, 0.0, -20.0 },
|
||||
};
|
||||
|
||||
/* Draw a floor (possibly textured). */
|
||||
static void
|
||||
drawFloor(void)
|
||||
{
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
if (useTexture) {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0, 0.0);
|
||||
glVertex3fv(floorVertices[0]);
|
||||
glTexCoord2f(0.0, 16.0);
|
||||
glVertex3fv(floorVertices[1]);
|
||||
glTexCoord2f(16.0, 16.0);
|
||||
glVertex3fv(floorVertices[2]);
|
||||
glTexCoord2f(16.0, 0.0);
|
||||
glVertex3fv(floorVertices[3]);
|
||||
glEnd();
|
||||
|
||||
if (useTexture) {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
static GLfloat floorPlane[4];
|
||||
static GLfloat floorShadow[4][4];
|
||||
|
||||
static void
|
||||
redraw(void)
|
||||
{
|
||||
int start = 0, end = 0 ;
|
||||
|
||||
if (reportSpeed) {
|
||||
start = glutGet(GLUT_ELAPSED_TIME);
|
||||
}
|
||||
|
||||
/* Clear; default stencil clears to zero. */
|
||||
if ((stencilReflection && renderReflection) || (stencilShadow && renderShadow)) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
} else {
|
||||
/* Avoid clearing stencil when not using it. */
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
/* Reposition the light source. */
|
||||
lightPosition[0] = 12*cos(lightAngle);
|
||||
lightPosition[1] = lightHeight;
|
||||
lightPosition[2] = 12*sin(lightAngle);
|
||||
if (directionalLight) {
|
||||
lightPosition[3] = 0.0;
|
||||
} else {
|
||||
lightPosition[3] = 1.0;
|
||||
}
|
||||
|
||||
shadowMatrix(floorShadow, floorPlane, lightPosition);
|
||||
|
||||
glPushMatrix();
|
||||
/* Perform scene rotations based on user mouse input. */
|
||||
glRotatef(angle2, 1.0, 0.0, 0.0);
|
||||
glRotatef(angle, 0.0, 1.0, 0.0);
|
||||
|
||||
/* Tell GL new light source position. */
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
|
||||
|
||||
if (renderReflection) {
|
||||
if (stencilReflection) {
|
||||
/* We can eliminate the visual "artifact" of seeing the "flipped"
|
||||
dinosaur underneath the floor by using stencil. The idea is
|
||||
draw the floor without color or depth update but so that
|
||||
a stencil value of one is where the floor will be. Later when
|
||||
rendering the dinosaur reflection, we will only update pixels
|
||||
with a stencil value of 1 to make sure the reflection only
|
||||
lives on the floor, not below the floor. */
|
||||
|
||||
/* Don't update color or depth. */
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
|
||||
/* Draw 1 into the stencil buffer. */
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
||||
glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
|
||||
|
||||
/* Now render floor; floor pixels just get their stencil set to 1. */
|
||||
drawFloor();
|
||||
|
||||
/* Re-enable update of color and depth. */
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* Now, only render where stencil is set to 1. */
|
||||
glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if ==1 */
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
/* The critical reflection step: Reflect dinosaur through the floor
|
||||
(the Y=0 plane) to make a relection. */
|
||||
glScalef(1.0, -1.0, 1.0);
|
||||
|
||||
/* Reflect the light position. */
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
|
||||
|
||||
/* To avoid our normals getting reversed and hence botched lighting
|
||||
on the reflection, turn on normalize. */
|
||||
glEnable(GL_NORMALIZE);
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
/* Draw the reflected dinosaur. */
|
||||
drawDinosaur();
|
||||
|
||||
/* Disable noramlize again and re-enable back face culling. */
|
||||
glDisable(GL_NORMALIZE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
/* Switch back to the unreflected light position. */
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
|
||||
|
||||
if (stencilReflection) {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
/* Back face culling will get used to only draw either the top or the
|
||||
bottom floor. This let's us get a floor with two distinct
|
||||
appearances. The top floor surface is reflective and kind of red.
|
||||
The bottom floor surface is not reflective and blue. */
|
||||
|
||||
/* Draw "bottom" of floor in blue. */
|
||||
glFrontFace(GL_CW); /* Switch face orientation. */
|
||||
glColor4f(0.1, 0.1, 0.7, 1.0);
|
||||
drawFloor();
|
||||
glFrontFace(GL_CCW);
|
||||
|
||||
if (renderShadow) {
|
||||
if (stencilShadow) {
|
||||
/* Draw the floor with stencil value 3. This helps us only
|
||||
draw the shadow once per floor pixel (and only on the
|
||||
floor pixels). */
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glStencilFunc(GL_ALWAYS, 3, 0xffffffff);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw "top" of floor. Use blending to blend in reflection. */
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor4f(0.7, 0.0, 0.0, 0.3);
|
||||
glColor4f(1.0, 1.0, 1.0, 0.3);
|
||||
drawFloor();
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
if (renderDinosaur) {
|
||||
/* Draw "actual" dinosaur, not its reflection. */
|
||||
drawDinosaur();
|
||||
}
|
||||
|
||||
if (renderShadow) {
|
||||
|
||||
/* Render the projected shadow. */
|
||||
|
||||
if (stencilShadow) {
|
||||
|
||||
/* Now, only render where stencil is set above 2 (ie, 3 where
|
||||
the top floor is). Update stencil with 2 where the shadow
|
||||
gets drawn so we don't redraw (and accidently reblend) the
|
||||
shadow). */
|
||||
glStencilFunc(GL_LESS, 2, 0xffffffff); /* draw if ==1 */
|
||||
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
||||
}
|
||||
|
||||
/* To eliminate depth buffer artifacts, we use polygon offset
|
||||
to raise the depth of the projected shadow slightly so
|
||||
that it does not depth buffer alias with the floor. */
|
||||
if (offsetShadow) {
|
||||
switch (polygonOffsetVersion) {
|
||||
case EXTENSION:
|
||||
#ifdef GL_VERSION_1_1
|
||||
case ONE_DOT_ONE:
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
break;
|
||||
#endif
|
||||
case MISSING:
|
||||
/* Oh well. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Render 50% black shadow color on top of whatever the
|
||||
floor appareance is. */
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_LIGHTING); /* Force the 50% black. */
|
||||
glColor4f(0.0, 0.0, 0.0, 0.5);
|
||||
|
||||
glPushMatrix();
|
||||
/* Project the shadow. */
|
||||
glMultMatrixf((GLfloat *) floorShadow);
|
||||
drawDinosaur();
|
||||
glPopMatrix();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
if (offsetShadow) {
|
||||
switch (polygonOffsetVersion) {
|
||||
#ifdef GL_VERSION_1_1
|
||||
case ONE_DOT_ONE:
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
break;
|
||||
#endif
|
||||
case MISSING:
|
||||
/* Oh well. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (stencilShadow) {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor3f(1.0, 1.0, 0.0);
|
||||
if (directionalLight) {
|
||||
/* Draw an arrowhead. */
|
||||
glDisable(GL_CULL_FACE);
|
||||
glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);
|
||||
glRotatef(lightAngle * -180.0 / M_PI, 0, 1, 0);
|
||||
glRotatef(atan(lightHeight/12) * 180.0 / M_PI, 0, 0, 1);
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glVertex3f(0, 0, 0);
|
||||
glVertex3f(2, 1, 1);
|
||||
glVertex3f(2, -1, 1);
|
||||
glVertex3f(2, -1, -1);
|
||||
glVertex3f(2, 1, -1);
|
||||
glVertex3f(2, 1, 1);
|
||||
glEnd();
|
||||
/* Draw a white line from light direction. */
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(0, 0, 0);
|
||||
glVertex3f(5, 0, 0);
|
||||
glEnd();
|
||||
glEnable(GL_CULL_FACE);
|
||||
} else {
|
||||
/* Draw a yellow ball at the light source. */
|
||||
glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);
|
||||
glutSolidSphere(1.0, 5, 5);
|
||||
}
|
||||
glEnable(GL_LIGHTING);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
if (reportSpeed) {
|
||||
glFinish();
|
||||
end = glutGet(GLUT_ELAPSED_TIME);
|
||||
printf("Speed %.3g frames/sec (%d ms)\n", 1000.0/(end-start), end-start);
|
||||
}
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
/* ARGSUSED2 */
|
||||
static void
|
||||
mouse(int button, int state, int x, int y)
|
||||
{
|
||||
if (button == GLUT_LEFT_BUTTON) {
|
||||
if (state == GLUT_DOWN) {
|
||||
moving = 1;
|
||||
startx = x;
|
||||
starty = y;
|
||||
}
|
||||
if (state == GLUT_UP) {
|
||||
moving = 0;
|
||||
}
|
||||
}
|
||||
if (button == GLUT_MIDDLE_BUTTON) {
|
||||
if (state == GLUT_DOWN) {
|
||||
lightMoving = 1;
|
||||
lightStartX = x;
|
||||
lightStartY = y;
|
||||
}
|
||||
if (state == GLUT_UP) {
|
||||
lightMoving = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ARGSUSED1 */
|
||||
static void
|
||||
motion(int x, int y)
|
||||
{
|
||||
if (moving) {
|
||||
angle = angle + (x - startx);
|
||||
angle2 = angle2 + (y - starty);
|
||||
startx = x;
|
||||
starty = y;
|
||||
glutPostRedisplay();
|
||||
}
|
||||
if (0){//lightMoving) {
|
||||
lightAngle += (x - lightStartX)/40.0;
|
||||
lightHeight += (lightStartY - y)/20.0;
|
||||
lightStartX = x;
|
||||
lightStartY = y;
|
||||
glutPostRedisplay();
|
||||
}
|
||||
}
|
||||
|
||||
/* Advance time varying state when idle callback registered. */
|
||||
static void
|
||||
idle(void)
|
||||
{
|
||||
static float time = 0.0;
|
||||
static float prevtime = 0.0;
|
||||
float dtime;
|
||||
prevtime = time;
|
||||
|
||||
time = glutGet(GLUT_ELAPSED_TIME) / 500.0;
|
||||
dtime = time - prevtime;
|
||||
|
||||
jump = 4.0 * fabs(sin(time)*0.5);
|
||||
if (!lightMoving) {
|
||||
lightAngle = time;
|
||||
}
|
||||
|
||||
if (dynamicsWorld)
|
||||
plStepSimulation(dynamicsWorld,dtime);
|
||||
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
enum {
|
||||
M_NONE, M_MOTION, M_LIGHT, M_TEXTURE, M_SHADOWS, M_REFLECTION, M_DINOSAUR,
|
||||
M_STENCIL_REFLECTION, M_STENCIL_SHADOW, M_OFFSET_SHADOW,
|
||||
M_POSITIONAL, M_DIRECTIONAL, M_PERFORMANCE
|
||||
};
|
||||
|
||||
static void
|
||||
controlLights(int value)
|
||||
{
|
||||
switch (value) {
|
||||
case M_NONE:
|
||||
return;
|
||||
case M_MOTION:
|
||||
animation = 1 - animation;
|
||||
if (animation) {
|
||||
glutIdleFunc(idle);
|
||||
} else {
|
||||
glutIdleFunc(NULL);
|
||||
}
|
||||
break;
|
||||
case M_LIGHT:
|
||||
lightSwitch = !lightSwitch;
|
||||
if (lightSwitch) {
|
||||
glEnable(GL_LIGHT0);
|
||||
} else {
|
||||
glDisable(GL_LIGHT0);
|
||||
}
|
||||
break;
|
||||
case M_TEXTURE:
|
||||
useTexture = !useTexture;
|
||||
break;
|
||||
case M_SHADOWS:
|
||||
renderShadow = 1 - renderShadow;
|
||||
break;
|
||||
case M_REFLECTION:
|
||||
renderReflection = 1 - renderReflection;
|
||||
break;
|
||||
case M_DINOSAUR:
|
||||
renderDinosaur = 1 - renderDinosaur;
|
||||
break;
|
||||
case M_STENCIL_REFLECTION:
|
||||
stencilReflection = 1 - stencilReflection;
|
||||
break;
|
||||
case M_STENCIL_SHADOW:
|
||||
stencilShadow = 1 - stencilShadow;
|
||||
break;
|
||||
case M_OFFSET_SHADOW:
|
||||
offsetShadow = 1 - offsetShadow;
|
||||
break;
|
||||
case M_POSITIONAL:
|
||||
directionalLight = 0;
|
||||
break;
|
||||
case M_DIRECTIONAL:
|
||||
directionalLight = 1;
|
||||
break;
|
||||
case M_PERFORMANCE:
|
||||
reportSpeed = 1 - reportSpeed;
|
||||
break;
|
||||
}
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
/* When not visible, stop animating. Restart when visible again. */
|
||||
static void
|
||||
visible(int vis)
|
||||
{
|
||||
if (vis == GLUT_VISIBLE) {
|
||||
if (animation)
|
||||
glutIdleFunc(idle);
|
||||
} else {
|
||||
if (!animation)
|
||||
glutIdleFunc(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Press any key to redraw; good when motion stopped and
|
||||
performance reporting on. */
|
||||
/* ARGSUSED */
|
||||
static void
|
||||
key(unsigned char c, int x, int y)
|
||||
{
|
||||
if (c == 27) {
|
||||
exit(0); /* IRIS GLism, Escape quits. */
|
||||
}
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
/* Press any key to redraw; good when motion stopped and
|
||||
performance reporting on. */
|
||||
/* ARGSUSED */
|
||||
static void
|
||||
special(int k, int x, int y)
|
||||
{
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
static int
|
||||
supportsOneDotOne(void)
|
||||
{
|
||||
const char *version;
|
||||
int major, minor;
|
||||
|
||||
version = (char *) glGetString(GL_VERSION);
|
||||
if (sscanf(version, "%d.%d", &major, &minor) == 2)
|
||||
return ((major > 1) || (major >= 1 && minor >= 1));
|
||||
return 0; /* OpenGL version string malformed! */
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
plCollisionShapeHandle floorShape;
|
||||
plCollisionShapeHandle dinoShape,dinoChildShape;
|
||||
plVector3 floorPos,childPos;
|
||||
plVector3 dinoPos;
|
||||
plQuaternion childOrn,dinoOrient;
|
||||
|
||||
void* user_data=NULL;
|
||||
|
||||
physicsSdk = plNewBulletSdk();
|
||||
dynamicsWorld = plCreateDynamicsWorld(physicsSdk);
|
||||
|
||||
//create ground plane
|
||||
|
||||
floorShape = plNewConvexHullShape();
|
||||
|
||||
for (i=0;i<4;i++)
|
||||
{
|
||||
// floorVertices
|
||||
plAddVertex(floorShape,floorVertices[i][0],floorVertices[i][1],floorVertices[i][2]);
|
||||
}
|
||||
|
||||
|
||||
floorShape = plNewBoxShape(120,0,120);
|
||||
|
||||
floorRigidBody = plCreateRigidBody(user_data,0.f,floorShape);
|
||||
floorPos[0] = 0;
|
||||
floorPos[1] = 0;
|
||||
floorPos[2] = 0;
|
||||
|
||||
plSetPosition(floorRigidBody,floorPos);
|
||||
plAddRigidBody(dynamicsWorld,floorRigidBody);
|
||||
|
||||
//create dino rigidbody
|
||||
dinoChildShape = plNewBoxShape(8.5,8.5,8.5);
|
||||
dinoShape = plNewCompoundShape();
|
||||
childPos[0] = 0;
|
||||
childPos[1] = 0;
|
||||
childPos[2] = 0;
|
||||
childOrn[0] = 0;
|
||||
childOrn[1] = 0;
|
||||
childOrn[2] = 0;
|
||||
childOrn[3] = 1;
|
||||
|
||||
plAddChildShape(dinoShape,dinoChildShape,childPos,childOrn);
|
||||
|
||||
dinoPos[0] = -10; dinoPos[1] = 28; dinoPos[2] = 0;
|
||||
dinoRigidBody = plCreateRigidBody(0,1.0,dinoShape);
|
||||
plSetPosition(dinoRigidBody,dinoPos);
|
||||
plSetEuler(0,0,3.15*0.20,dinoOrient);
|
||||
plSetOrientation(dinoRigidBody,dinoOrient);
|
||||
|
||||
plAddRigidBody(dynamicsWorld,dinoRigidBody);
|
||||
|
||||
printf("BulletDino\n");
|
||||
glutInit(&argc, argv);
|
||||
|
||||
for (i=1; i<argc; i++) {
|
||||
if (!strcmp("-linear", argv[i])) {
|
||||
linearFiltering = 1;
|
||||
} else if (!strcmp("-mipmap", argv[i])) {
|
||||
useMipmaps = 1;
|
||||
} else if (!strcmp("-ext", argv[i])) {
|
||||
forceExtension = 1;
|
||||
}
|
||||
}
|
||||
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL | GLUT_MULTISAMPLE);
|
||||
|
||||
#if 0
|
||||
/* In GLUT 4.0, you'll be able to do this an be sure to
|
||||
get 2 bits of stencil if the machine has it for you. */
|
||||
glutInitDisplayString("samples stencil>=2 rgb double depth");
|
||||
#endif
|
||||
|
||||
glutCreateWindow("Shadowy Leapin' Lizards");
|
||||
|
||||
if (glutGet(GLUT_WINDOW_STENCIL_SIZE) <= 1) {
|
||||
printf("dinoshade: Sorry, I need at least 2 bits of stencil.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Register GLUT callbacks. */
|
||||
glutDisplayFunc(redraw);
|
||||
glutMouseFunc(mouse);
|
||||
glutMotionFunc(motion);
|
||||
glutVisibilityFunc(visible);
|
||||
glutKeyboardFunc(key);
|
||||
glutSpecialFunc(special);
|
||||
|
||||
glutCreateMenu(controlLights);
|
||||
|
||||
glutAddMenuEntry("Toggle motion", M_MOTION);
|
||||
glutAddMenuEntry("-----------------------", M_NONE);
|
||||
glutAddMenuEntry("Toggle light", M_LIGHT);
|
||||
glutAddMenuEntry("Toggle texture", M_TEXTURE);
|
||||
glutAddMenuEntry("Toggle shadows", M_SHADOWS);
|
||||
glutAddMenuEntry("Toggle reflection", M_REFLECTION);
|
||||
glutAddMenuEntry("Toggle dinosaur", M_DINOSAUR);
|
||||
glutAddMenuEntry("-----------------------", M_NONE);
|
||||
glutAddMenuEntry("Toggle reflection stenciling", M_STENCIL_REFLECTION);
|
||||
glutAddMenuEntry("Toggle shadow stenciling", M_STENCIL_SHADOW);
|
||||
glutAddMenuEntry("Toggle shadow offset", M_OFFSET_SHADOW);
|
||||
glutAddMenuEntry("----------------------", M_NONE);
|
||||
glutAddMenuEntry("Positional light", M_POSITIONAL);
|
||||
glutAddMenuEntry("Directional light", M_DIRECTIONAL);
|
||||
glutAddMenuEntry("-----------------------", M_NONE);
|
||||
glutAddMenuEntry("Toggle performance", M_PERFORMANCE);
|
||||
glutAttachMenu(GLUT_RIGHT_BUTTON);
|
||||
makeDinosaur();
|
||||
|
||||
#ifdef GL_VERSION_1_1
|
||||
if (supportsOneDotOne() && !forceExtension) {
|
||||
polygonOffsetVersion = ONE_DOT_ONE;
|
||||
glPolygonOffset(-2.0, -1.0);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
{
|
||||
polygonOffsetVersion = MISSING;
|
||||
printf("\ndinoshine: Missing polygon offset.\n");
|
||||
printf(" Expect shadow depth aliasing artifacts.\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glLineWidth(3.0);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
gluPerspective( /* field of view in degree */ 40.0,
|
||||
/* aspect ratio */ 1.0,
|
||||
/* Z near */ 20.0, /* Z far */ 100.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
gluLookAt(0.0, 8.0, 60.0, /* eye is at (0,0,30) */
|
||||
0.0, 8.0, 0.0, /* center is at (0,0,0) */
|
||||
0.0, 1.0, 0.); /* up is in postivie Y direction */
|
||||
|
||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
|
||||
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
|
||||
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
makeFloorTexture();
|
||||
|
||||
/* Setup floor plane for projected shadow calculations. */
|
||||
findPlane(floorPlane, floorVertices[1], floorVertices[2], floorVertices[3]);
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
plDeleteDynamicsWorld(dynamicsWorld);
|
||||
plDeletePhysicsSdk(physicsSdk);
|
||||
|
||||
|
||||
return 0; /* ANSI C requires main to return int. */
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# This is the variable for Windows. I use this to define the root of my directory structure.
|
||||
SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
# This is the shortcut to finding GLU, GLUT and OpenGL if they are properly installed on your system
|
||||
# This should be the case.
|
||||
INCLUDE (${CMAKE_ROOT}/Modules/FindGLU.cmake)
|
||||
INCLUDE (${CMAKE_ROOT}/Modules/FindGLUT.cmake)
|
||||
INCLUDE (${CMAKE_ROOT}/Modules/FindOpenGL.cmake)
|
||||
|
||||
|
||||
IF (WIN32)
|
||||
# This is the Windows code for which Opengl, and Glut are not properly installed
|
||||
# since I can't install them I must cheat and copy libraries around
|
||||
INCLUDE_DIRECTORIES(${GLUT_ROOT})
|
||||
# LINK_DIRECTORIES(${GLUT_ROOT}\\lib)
|
||||
IF (${GLUT_glut_LIBRARY} MATCHES "GLUT_glut_LIBRARY-NOTFOUND")
|
||||
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Glut/glut32.lib)
|
||||
# LINK_LIBRARIES(${GLUT_ROOT}\\lib\\glut32 ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY})
|
||||
# TARGET_LINK_LIBRARIES(table ${GLUT_ROOT}\\lib\\glut32)
|
||||
#
|
||||
# ADD_CUSTOM_COMMAND(TARGET table POST_BUILD COMMAND copy ${GLUT_ROOT}\\lib\\glut32.dll ${GLUT_ROOT}\\bin\\vs2005\\Debug
|
||||
# COMMAND copy ${GLUT_ROOT}\\lib\\glut32.dll ${GLUT_ROOT}\\bin\\vs2003\\Debug
|
||||
# COMMAND copy ${GLUT_ROOT}\\lib\\glut32.dll ${GLUT_ROOT}\\bin\\vs6\\Debug)
|
||||
ELSE (${GLUT_glut_LIBRARY} MATCHES "GLUT_glut_LIBRARY-NOTFOUND")
|
||||
# LINK_LIBRARIES(${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY})
|
||||
# TARGET_LINK_LIBRARIES(table ${GLUT_glut_LIBRARY})
|
||||
ENDIF(${GLUT_glut_LIBRARY} MATCHES "GLUT_glut_LIBRARY-NOTFOUND")
|
||||
# TARGET_LINK_LIBRARIES(table ${OPENGL_gl_LIBRARY})
|
||||
# TARGET_LINK_LIBRARIES(table ${OPENGL_glu_LIBRARY})
|
||||
ELSE (WIN32)
|
||||
# This is the lines for linux. This should always work if everything is installed and working fine.
|
||||
# SET(CMAKE_BUILD_TYPE Debug)
|
||||
# SET(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
INCLUDE_DIRECTORIES(/usr/include /usr/local/include ${GLUT_INCLUDE_DIR})
|
||||
# TARGET_LINK_LIBRARIES(table ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY})
|
||||
# TARGET_LINK_LIBRARIES(checker ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY})
|
||||
ENDIF (WIN32)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL }
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
LibOpenGLSupport LibBulletDynamics LibBulletCollision LibLinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glU_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(BulletDino
|
||||
BulletDino.c
|
||||
)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
SubDir TOP Demos BulletDinoDemo ;
|
||||
|
||||
BulletDemo BulletDino : [ Wildcard *.h *.c ] ;
|
||||
@@ -0,0 +1,12 @@
|
||||
if (CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
SUBDIRS( OpenGL AllBulletDemos ConvexDecompositionDemo Benchmarks HelloWorld
|
||||
CcdPhysicsDemo ConstraintDemo SliderConstraintDemo GenericJointDemo
|
||||
RagdollDemo ForkLiftDemo BasicDemo BspDemo MovingConcaveDemo VehicleDemo
|
||||
ColladaDemo UserCollisionAlgorithm CharacterDemo SoftDemo HeightFieldFluidDemo)
|
||||
else (CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
SUBDIRS( OpenGL AllBulletDemos ConvexDecompositionDemo Benchmarks HelloWorld
|
||||
MultiThreadedDemo CcdPhysicsDemo ConstraintDemo SliderConstraintDemo
|
||||
GenericJointDemo RagdollDemo ForkLiftDemo BasicDemo BspDemo MovingConcaveDemo
|
||||
VehicleDemo ColladaDemo UserCollisionAlgorithm CharacterDemo SoftDemo
|
||||
HeightFieldFluidDemo)
|
||||
endif (CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
@@ -0,0 +1,26 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL }
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppCcdPhysicsDemo
|
||||
main.cpp
|
||||
CcdPhysicsDemo.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,681 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
//enable just one, DO_BENCHMARK_PYRAMIDS or DO_WALL
|
||||
//#define DO_BENCHMARK_PYRAMIDS 1
|
||||
#define DO_WALL 1
|
||||
|
||||
//Note: some of those settings need 'DO_WALL' demo
|
||||
//#define USE_KINEMATIC_GROUND 1
|
||||
//#define PRINT_CONTACT_STATISTICS 1
|
||||
//#define USER_DEFINED_FRICTION_MODEL 1
|
||||
//#define USE_CUSTOM_NEAR_CALLBACK 1
|
||||
//#define CENTER_OF_MASS_SHIFT 1
|
||||
//#define VERBOSE_TIMESTEPPING_CONSOLEOUTPUT 1
|
||||
|
||||
//#define USE_PARALLEL_DISPATCHER 1
|
||||
//#define USE_PARALLEL_SOLVER 1 //experimental parallel solver
|
||||
|
||||
|
||||
//from Bullet 2.68 onwards ODE Quickstep constraint solver is optional part of Bullet, re-distributed under the ZLib license with permission of Russell L. Smith
|
||||
//#define COMPARE_WITH_QUICKSTEP 1
|
||||
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h"
|
||||
#include "BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h"
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#include "../../Extras/BulletMultiThreaded/SpuGatheringCollisionDispatcher.h"
|
||||
#ifdef WIN32
|
||||
#include "../../Extras/BulletMultiThreaded/Win32ThreadSupport.h"
|
||||
#include "../../Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h"
|
||||
#endif //WIN32
|
||||
|
||||
#ifdef USE_LIBSPE2
|
||||
#include "../../Extras/BulletMultiThreaded/SpuLibspe2Support.h"
|
||||
#endif //USE_LIBSPE2
|
||||
|
||||
#ifdef USE_PARALLEL_SOLVER
|
||||
#include "../../Extras/BulletMultiThreaded/SpuParallelSolver.h"
|
||||
#include "../../Extras/BulletMultiThreaded/SpuSolverTask/SpuParallellSolverTask.h"
|
||||
#endif //USE_PARALLEL_SOLVER
|
||||
|
||||
#endif//USE_PARALLEL_DISPATCHER
|
||||
|
||||
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
|
||||
#include "BMF_Api.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
static float gCollisionMargin = 0.05f;
|
||||
#include "CcdPhysicsDemo.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
|
||||
#include "GlutStuff.h"
|
||||
|
||||
btTransform comOffset;
|
||||
btVector3 comOffsetVec(0,2,0);
|
||||
|
||||
extern float eye[3];
|
||||
extern int glutScreenWidth;
|
||||
extern int glutScreenHeight;
|
||||
|
||||
const int maxProxies = 32766;
|
||||
const int maxOverlap = 65535;
|
||||
|
||||
bool createConstraint = true;//false;
|
||||
#ifdef CENTER_OF_MASS_SHIFT
|
||||
bool useCompound = true;
|
||||
#else
|
||||
bool useCompound = false;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
const int gNumObjects = 120;
|
||||
#else
|
||||
const int gNumObjects = 120;//try this in release mode: 3000. never go above 16384, unless you increate maxNumObjects value in DemoApplication.cp
|
||||
#endif
|
||||
|
||||
|
||||
const int maxNumObjects = 32760;
|
||||
|
||||
int shapeIndex[maxNumObjects];
|
||||
|
||||
|
||||
#define CUBE_HALF_EXTENTS 0.5
|
||||
|
||||
#define EXTRA_HEIGHT -10.f
|
||||
//GL_LineSegmentShape shapeE(btVector3(-50,0,0),
|
||||
// btVector3(50,0,0));
|
||||
|
||||
|
||||
void CcdPhysicsDemo::createStack( btCollisionShape* boxShape, float halfCubeSize, int size, float zPos )
|
||||
{
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
|
||||
for(int i=0; i<size; i++)
|
||||
{
|
||||
// This constructs a row, from left to right
|
||||
int rowSize = size - i;
|
||||
for(int j=0; j< rowSize; j++)
|
||||
{
|
||||
btVector3 pos;
|
||||
pos.setValue(
|
||||
-rowSize * halfCubeSize + halfCubeSize + j * 2.0f * halfCubeSize,
|
||||
halfCubeSize + i * halfCubeSize * 2.0f,
|
||||
zPos);
|
||||
|
||||
trans.setOrigin(pos);
|
||||
btScalar mass = 1.f;
|
||||
|
||||
btRigidBody* body = 0;
|
||||
body = localCreateRigidBody(mass,trans,boxShape);
|
||||
#ifdef USER_DEFINED_FRICTION_MODEL
|
||||
///Advanced use: override the friction solver
|
||||
body->m_frictionSolverType = USER_CONTACT_SOLVER_TYPE1;
|
||||
#endif //USER_DEFINED_FRICTION_MODEL
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
//by default, Bullet will use its own nearcallback, but you can override it using dispatcher->setNearCallback()
|
||||
void customNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo)
|
||||
{
|
||||
btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
|
||||
btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
|
||||
|
||||
if (dispatcher.needsCollision(colObj0,colObj1))
|
||||
{
|
||||
//dispatcher will keep algorithms persistent in the collision pair
|
||||
if (!collisionPair.m_algorithm)
|
||||
{
|
||||
collisionPair.m_algorithm = dispatcher.findAlgorithm(colObj0,colObj1);
|
||||
}
|
||||
|
||||
if (collisionPair.m_algorithm)
|
||||
{
|
||||
btManifoldResult contactPointResult(colObj0,colObj1);
|
||||
|
||||
if (dispatchInfo.m_dispatchFunc == btDispatcherInfo::DISPATCH_DISCRETE)
|
||||
{
|
||||
//discrete collision detection query
|
||||
collisionPair.m_algorithm->processCollision(colObj0,colObj1,dispatchInfo,&contactPointResult);
|
||||
} else
|
||||
{
|
||||
//continuous collision detection query, time of impact (toi)
|
||||
float toi = collisionPair.m_algorithm->calculateTimeOfImpact(colObj0,colObj1,dispatchInfo,&contactPointResult);
|
||||
if (dispatchInfo.m_timeOfImpact > toi)
|
||||
dispatchInfo.m_timeOfImpact = toi;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//experimental jitter damping (1 = no damping, 0 = total damping once motion below threshold)
|
||||
extern btScalar gJitterVelocityDampingFactor;
|
||||
|
||||
|
||||
|
||||
|
||||
extern int gNumManifold;
|
||||
extern int gOverlappingPairs;
|
||||
|
||||
|
||||
void CcdPhysicsDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
#ifdef USE_KINEMATIC_GROUND
|
||||
//btQuaternion kinRotation(btVector3(0,0,1),0.);
|
||||
btVector3 kinTranslation(-0.01,0,0);
|
||||
//kinematic object
|
||||
btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[0];
|
||||
//is this a rigidbody with a motionstate? then use the motionstate to update positions!
|
||||
if (btRigidBody::upcast(colObj) && btRigidBody::upcast(colObj)->getMotionState())
|
||||
{
|
||||
btTransform newTrans;
|
||||
btRigidBody::upcast(colObj)->getMotionState()->getWorldTransform(newTrans);
|
||||
newTrans.getOrigin()+=kinTranslation;
|
||||
btRigidBody::upcast(colObj)->getMotionState()->setWorldTransform(newTrans);
|
||||
} else
|
||||
{
|
||||
m_dynamicsWorld->getCollisionObjectArray()[0]->getWorldTransform().getOrigin() += kinTranslation;
|
||||
}
|
||||
|
||||
#endif //USE_KINEMATIC_GROUND
|
||||
|
||||
|
||||
float dt = getDeltaTimeMicroseconds() * 0.000001f;
|
||||
|
||||
// printf("dt = %f: ",dt);
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
|
||||
//#define FIXED_STEP 1
|
||||
#ifdef FIXED_STEP
|
||||
m_dynamicsWorld->stepSimulation(1.0f/60.f,0);
|
||||
|
||||
#else
|
||||
//during idle mode, just run 1 simulation step maximum
|
||||
int maxSimSubSteps = m_idle ? 1 : 1;
|
||||
if (m_idle)
|
||||
dt = 1.0/420.f;
|
||||
|
||||
int numSimSteps = 0;
|
||||
numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps);
|
||||
|
||||
//optional but useful: debug drawing
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
#ifdef VERBOSE_TIMESTEPPING_CONSOLEOUTPUT
|
||||
if (!numSimSteps)
|
||||
printf("Interpolated transforms\n");
|
||||
else
|
||||
{
|
||||
if (numSimSteps > maxSimSubSteps)
|
||||
{
|
||||
//detect dropping frames
|
||||
printf("Dropped (%i) simulation steps out of %i\n",numSimSteps - maxSimSubSteps,numSimSteps);
|
||||
} else
|
||||
{
|
||||
printf("Simulated (%i) steps\n",numSimSteps);
|
||||
}
|
||||
}
|
||||
#endif //VERBOSE_TIMESTEPPING_CONSOLEOUTPUT
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
btProfiler::beginBlock("render");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
renderme();
|
||||
|
||||
|
||||
//render the graphics objects, with center of mass shift
|
||||
|
||||
updateCamera();
|
||||
|
||||
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
btProfiler::endBlock("render");
|
||||
#endif
|
||||
glFlush();
|
||||
//some additional debugging info
|
||||
#ifdef PRINT_CONTACT_STATISTICS
|
||||
printf("num manifolds: %i\n",gNumManifold);
|
||||
printf("num gOverlappingPairs: %i\n",gOverlappingPairs);
|
||||
|
||||
#endif //PRINT_CONTACT_STATISTICS
|
||||
|
||||
|
||||
glutSwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CcdPhysicsDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
renderme();
|
||||
|
||||
//optional but useful: debug drawing
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///User-defined friction model, the most simple friction model available: no friction
|
||||
float myFrictionModel( btRigidBody& body1, btRigidBody& body2, btManifoldPoint& contactPoint, const btContactSolverInfo& solverInfo )
|
||||
{
|
||||
//don't do any friction
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
void CcdPhysicsDemo::initPhysics()
|
||||
{
|
||||
setTexturing(true);
|
||||
setShadows(false);
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#ifdef WIN32
|
||||
m_threadSupportSolver = 0;
|
||||
m_threadSupportCollision = 0;
|
||||
#endif //
|
||||
#endif
|
||||
|
||||
//#define USE_GROUND_PLANE 1
|
||||
#ifdef USE_GROUND_PLANE
|
||||
m_collisionShapes.push_back(new btStaticPlaneShape(btVector3(0,1,0),0.5));
|
||||
#else
|
||||
|
||||
///Please don't make the box sizes larger then 1000: the collision detection will be inaccurate.
|
||||
///See http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=346
|
||||
m_collisionShapes.push_back(new btBoxShape (btVector3(200,CUBE_HALF_EXTENTS,200)));
|
||||
#endif
|
||||
|
||||
#ifdef DO_BENCHMARK_PYRAMIDS
|
||||
m_collisionShapes.push_back(new btBoxShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)));
|
||||
#else
|
||||
// m_collisionShapes.push_back(new btBoxShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)));
|
||||
m_collisionShapes.push_back(new btCylinderShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)));
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef DO_BENCHMARK_PYRAMIDS
|
||||
setCameraDistance(32.5f);
|
||||
#endif
|
||||
|
||||
#ifdef DO_BENCHMARK_PYRAMIDS
|
||||
m_azi = 90.f;
|
||||
#endif //DO_BENCHMARK_PYRAMIDS
|
||||
|
||||
m_dispatcher=0;
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
int maxNumOutstandingTasks = 4;
|
||||
|
||||
#ifdef USE_WIN32_THREADING
|
||||
|
||||
m_threadSupportCollision = new Win32ThreadSupport(Win32ThreadSupport::Win32ThreadConstructionInfo(
|
||||
"collision",
|
||||
processCollisionTask,
|
||||
createCollisionLocalStoreMemory,
|
||||
maxNumOutstandingTasks));
|
||||
#else
|
||||
|
||||
#ifdef USE_LIBSPE2
|
||||
|
||||
spe_program_handle_t * program_handle;
|
||||
#ifndef USE_CESOF
|
||||
program_handle = spe_image_open ("./spuCollision.elf");
|
||||
if (program_handle == NULL)
|
||||
{
|
||||
perror( "SPU OPEN IMAGE ERROR\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "IMAGE OPENED\n");
|
||||
}
|
||||
#else
|
||||
extern spe_program_handle_t spu_program;
|
||||
program_handle = &spu_program;
|
||||
#endif
|
||||
SpuLibspe2Support* threadSupportCollision = new SpuLibspe2Support( program_handle, maxNumOutstandingTasks);
|
||||
#endif //USE_LIBSPE2
|
||||
|
||||
///Playstation 3 SPU (SPURS) version is available through PS3 Devnet
|
||||
/// For Unix/Mac someone could implement a pthreads version of btThreadSupportInterface?
|
||||
///you can hook it up to your custom task scheduler by deriving from btThreadSupportInterface
|
||||
#endif
|
||||
|
||||
|
||||
m_dispatcher = new SpuGatheringCollisionDispatcher(m_threadSupportCollision,maxNumOutstandingTasks,m_collisionConfiguration);
|
||||
// m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
#else
|
||||
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
#endif //USE_PARALLEL_DISPATCHER
|
||||
|
||||
#ifdef USE_CUSTOM_NEAR_CALLBACK
|
||||
//this is optional
|
||||
m_dispatcher->setNearCallback(customNearCallback);
|
||||
#endif
|
||||
|
||||
|
||||
m_broadphase = new btDbvtBroadphase();
|
||||
|
||||
#ifdef COMPARE_WITH_QUICKSTEP
|
||||
m_solver = new btOdeQuickstepConstraintSolver();
|
||||
#else
|
||||
|
||||
|
||||
#ifdef USE_PARALLEL_SOLVER
|
||||
|
||||
m_threadSupportSolver = new Win32ThreadSupport(Win32ThreadSupport::Win32ThreadConstructionInfo(
|
||||
"solver",
|
||||
processSolverTask,
|
||||
createSolverLocalStoreMemory,
|
||||
maxNumOutstandingTasks));
|
||||
|
||||
m_solver = new btParallelSequentialImpulseSolver(m_threadSupportSolver,maxNumOutstandingTasks);
|
||||
#else
|
||||
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver();
|
||||
|
||||
m_solver = solver;//new btOdeQuickstepConstraintSolver();
|
||||
|
||||
#endif //USE_PARALLEL_SOLVER
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
m_dynamicsWorld = world;
|
||||
|
||||
#ifdef USER_DEFINED_FRICTION_MODEL
|
||||
//user defined friction model is not supported in 'cache friendly' solver yet, so switch to old solver
|
||||
|
||||
world->getSolverInfo().m_solverMode = SOLVER_RANDMIZE_ORDER;
|
||||
|
||||
#endif //USER_DEFINED_FRICTION_MODEL
|
||||
|
||||
#ifdef DO_BENCHMARK_PYRAMIDS
|
||||
world->getSolverInfo().m_numIterations = 4;
|
||||
#endif //DO_BENCHMARK_PYRAMIDS
|
||||
|
||||
m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
|
||||
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
|
||||
|
||||
|
||||
|
||||
#ifdef USER_DEFINED_FRICTION_MODEL
|
||||
{
|
||||
//m_solver->setContactSolverFunc(ContactSolverFunc func,USER_CONTACT_SOLVER_TYPE1,DEFAULT_CONTACT_SOLVER_TYPE);
|
||||
solver->SetFrictionSolverFunc(myFrictionModel,USER_CONTACT_SOLVER_TYPE1,DEFAULT_CONTACT_SOLVER_TYPE);
|
||||
solver->SetFrictionSolverFunc(myFrictionModel,DEFAULT_CONTACT_SOLVER_TYPE,USER_CONTACT_SOLVER_TYPE1);
|
||||
solver->SetFrictionSolverFunc(myFrictionModel,USER_CONTACT_SOLVER_TYPE1,USER_CONTACT_SOLVER_TYPE1);
|
||||
//m_physicsEnvironmentPtr->setNumIterations(2);
|
||||
}
|
||||
#endif //USER_DEFINED_FRICTION_MODEL
|
||||
|
||||
|
||||
|
||||
int i;
|
||||
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
|
||||
|
||||
for (i=0;i<gNumObjects;i++)
|
||||
{
|
||||
if (i>0)
|
||||
{
|
||||
shapeIndex[i] = 1;//sphere
|
||||
}
|
||||
else
|
||||
shapeIndex[i] = 0;
|
||||
}
|
||||
|
||||
if (useCompound)
|
||||
{
|
||||
btCompoundShape* compoundShape = new btCompoundShape();
|
||||
btCollisionShape* oldShape = m_collisionShapes[1];
|
||||
m_collisionShapes[1] = compoundShape;
|
||||
btVector3 sphereOffset(0,0,2);
|
||||
|
||||
comOffset.setIdentity();
|
||||
|
||||
#ifdef CENTER_OF_MASS_SHIFT
|
||||
comOffset.setOrigin(comOffsetVec);
|
||||
compoundShape->addChildShape(comOffset,oldShape);
|
||||
|
||||
#else
|
||||
compoundShape->addChildShape(tr,oldShape);
|
||||
tr.setOrigin(sphereOffset);
|
||||
compoundShape->addChildShape(tr,new btSphereShape(0.9));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DO_WALL
|
||||
|
||||
for (i=0;i<gNumObjects;i++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[shapeIndex[i]];
|
||||
shape->setMargin(gCollisionMargin);
|
||||
|
||||
bool isDyna = i>0;
|
||||
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
|
||||
if (i>0)
|
||||
{
|
||||
//stack them
|
||||
int colsize = 10;
|
||||
int row = (i*CUBE_HALF_EXTENTS*2)/(colsize*2*CUBE_HALF_EXTENTS);
|
||||
int row2 = row;
|
||||
int col = (i)%(colsize)-colsize/2;
|
||||
|
||||
|
||||
if (col>3)
|
||||
{
|
||||
col=11;
|
||||
row2 |=1;
|
||||
}
|
||||
|
||||
btVector3 pos(col*2*CUBE_HALF_EXTENTS + (row2%2)*CUBE_HALF_EXTENTS,
|
||||
row*2*CUBE_HALF_EXTENTS+CUBE_HALF_EXTENTS+EXTRA_HEIGHT,0);
|
||||
|
||||
trans.setOrigin(pos);
|
||||
} else
|
||||
{
|
||||
trans.setOrigin(btVector3(0,EXTRA_HEIGHT-CUBE_HALF_EXTENTS,0));
|
||||
}
|
||||
|
||||
float mass = 1.f;
|
||||
|
||||
if (!isDyna)
|
||||
mass = 0.f;
|
||||
|
||||
btRigidBody* body = localCreateRigidBody(mass,trans,shape);
|
||||
#ifdef USE_KINEMATIC_GROUND
|
||||
if (mass == 0.f)
|
||||
{
|
||||
body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
body->setActivationState(DISABLE_DEACTIVATION);
|
||||
}
|
||||
#endif //USE_KINEMATIC_GROUND
|
||||
|
||||
|
||||
// Only do CCD if motion in one timestep (1.f/60.f) exceeds CUBE_HALF_EXTENTS
|
||||
body->setCcdMotionThreshold( CUBE_HALF_EXTENTS );
|
||||
|
||||
//Experimental: better estimation of CCD Time of Impact:
|
||||
body->setCcdSweptSphereRadius( 0.2*CUBE_HALF_EXTENTS );
|
||||
|
||||
#ifdef USER_DEFINED_FRICTION_MODEL
|
||||
///Advanced use: override the friction solver
|
||||
body->m_frictionSolverType = USER_CONTACT_SOLVER_TYPE1;
|
||||
#endif //USER_DEFINED_FRICTION_MODEL
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DO_BENCHMARK_PYRAMIDS
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
|
||||
btScalar halfExtents = CUBE_HALF_EXTENTS;
|
||||
|
||||
trans.setOrigin(btVector3(0,-halfExtents,0));
|
||||
|
||||
|
||||
|
||||
localCreateRigidBody(0.f,trans,m_collisionShapes[shapeIndex[0]]);
|
||||
|
||||
int numWalls = 15;
|
||||
int wallHeight = 15;
|
||||
float wallDistance = 3;
|
||||
|
||||
|
||||
for (int i=0;i<numWalls;i++)
|
||||
{
|
||||
float zPos = (i-numWalls/2) * wallDistance;
|
||||
createStack(m_collisionShapes[shapeIndex[1]],halfExtents,wallHeight,zPos);
|
||||
}
|
||||
// createStack(m_collisionShapes[shapeIndex[1]],halfExtends,20,10);
|
||||
|
||||
// createStack(m_collisionShapes[shapeIndex[1]],halfExtends,20,20);
|
||||
#define DESTROYER_BALL 1
|
||||
#ifdef DESTROYER_BALL
|
||||
btTransform sphereTrans;
|
||||
sphereTrans.setIdentity();
|
||||
sphereTrans.setOrigin(btVector3(0,2,40));
|
||||
btSphereShape* ball = new btSphereShape(2.f);
|
||||
m_collisionShapes.push_back(ball);
|
||||
btRigidBody* ballBody = localCreateRigidBody(10000.f,sphereTrans,ball);
|
||||
ballBody->setLinearVelocity(btVector3(0,0,-10));
|
||||
#endif
|
||||
#endif //DO_BENCHMARK_PYRAMIDS
|
||||
// clientResetScene();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void CcdPhysicsDemo::exitPhysics()
|
||||
{
|
||||
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
m_collisionShapes[j] = 0;
|
||||
delete shape;
|
||||
}
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
//delete solver
|
||||
delete m_solver;
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#ifdef WIN32
|
||||
if (m_threadSupportSolver)
|
||||
{
|
||||
delete m_threadSupportSolver;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//delete broadphase
|
||||
delete m_broadphase;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#ifdef WIN32
|
||||
if (m_threadSupportCollision)
|
||||
{
|
||||
delete m_threadSupportCollision;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef CCD_PHYSICS_DEMO_H
|
||||
#define CCD_PHYSICS_DEMO_H
|
||||
|
||||
#include "DemoApplication.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
class btBroadphaseInterface;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
class btDefaultCollisionConfiguration;
|
||||
|
||||
|
||||
///CcdPhysicsDemo shows basic stacking using Bullet physics, and allows toggle of Ccd (using key '1')
|
||||
class CcdPhysicsDemo : public DemoApplication
|
||||
{
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btBroadphaseInterface* m_broadphase;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#ifdef WIN32
|
||||
class Win32ThreadSupport* m_threadSupportCollision;
|
||||
class Win32ThreadSupport* m_threadSupportSolver;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
btConstraintSolver* m_solver;
|
||||
|
||||
btCollisionAlgorithmCreateFunc* m_boxBoxCF;
|
||||
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual ~CcdPhysicsDemo()
|
||||
{
|
||||
exitPhysics();
|
||||
}
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
void createStack( btCollisionShape* boxShape, float halfCubeSize, int size, float zPos );
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
CcdPhysicsDemo* demo = new CcdPhysicsDemo;
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //CCD_PHYSICS_DEMO_H
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
SubDir TOP Demos CcdPhysicsDemo ;
|
||||
|
||||
BulletDemo CcdPhysicsDemo : [ Wildcard *.h *.cpp ] ;
|
||||
@@ -0,0 +1,5 @@
|
||||
noinst_PROGRAMS=CcdPhysicsDemo
|
||||
|
||||
CcdPhysicsDemo_SOURCES=CcdPhysicsDemo.cpp CcdPhysicsDemo.h main.cpp
|
||||
CcdPhysicsDemo_CXXFLAGS=-I@top_builddir@/src -I@top_builddir@/Demos/OpenGL $(CXXFLAGS)
|
||||
CcdPhysicsDemo_LDADD=-L../OpenGL -lbulletopenglsupport -L../../src -lbulletdynamics -lbulletcollision -lbulletmath @opengl_LIBS@
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "CcdPhysicsDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#ifdef __DEBUG_FPU_ISSUES
|
||||
#define _GNU_SOURCE
|
||||
#include <fenv.h>
|
||||
#endif
|
||||
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
CcdPhysicsDemo* ccdDemo = new CcdPhysicsDemo();
|
||||
|
||||
#ifdef __DEBUG_FPU_ISSUES
|
||||
// feenableexcept (FE_DIVBYZERO);
|
||||
// feenableexcept (FE_INEXACT);
|
||||
// feenableexcept (FE_INVALID);
|
||||
// feenableexcept (FE_OVERFLOW|FE_DIVBYZERO|FE_UNDERFLOW);
|
||||
// feenableexcept (FE_UNDERFLOW);
|
||||
#endif
|
||||
|
||||
ccdDemo->initPhysics();
|
||||
ccdDemo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
|
||||
glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.com",ccdDemo);
|
||||
|
||||
delete ccdDemo;
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
//#define USE_GROUND_BOX 1
|
||||
#define PRINT_CONTACT_STATISTICS 1
|
||||
#define USE_PARALLEL_DISPATCHER 1
|
||||
|
||||
|
||||
//#define USE_SIMPLE_DYNAMICS_WORLD 1
|
||||
|
||||
int gNumObjects = 5;
|
||||
#define HALF_EXTENTS btScalar(1.)
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
btScalar deltaTime = btScalar(1./60.);
|
||||
btScalar gCollisionMargin = btScalar(0.05);
|
||||
#include "BasicDemo2.h"
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
#include "BulletMultiThreaded/SpuGatheringCollisionDispatcher.h"
|
||||
#include "BulletMultiThreaded/Win32ThreadSupport.h"
|
||||
#include "BulletMultiThreaded/SpuLibspe2Support.h"
|
||||
#include "BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h"
|
||||
#endif//USE_PARALLEL_DISPATCHER
|
||||
|
||||
|
||||
#include <LinearMath/btAlignedObjectArray.h>
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
BasicDemo ccdDemo;
|
||||
ccdDemo.initPhysics();
|
||||
|
||||
int i;
|
||||
for (i=0;i<5;i++)
|
||||
ccdDemo.clientMoveAndDisplay();
|
||||
ccdDemo.exitPhysics();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern int gNumManifold;
|
||||
|
||||
void BasicDemo::clientMoveAndDisplay()
|
||||
{
|
||||
|
||||
//simple dynamics world doesn't handle fixed-time-stepping
|
||||
float ms = m_clock.getTimeMicroseconds();
|
||||
m_clock.reset();
|
||||
float minFPS = 1000000.f/60.f;
|
||||
if (ms > minFPS)
|
||||
ms = minFPS;
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->stepSimulation(ms / 1000000.f);
|
||||
|
||||
//some additional debugging info
|
||||
#ifdef PRINT_CONTACT_STATISTICS
|
||||
printf("num contact manifolds: %i\n",gNumManifold);
|
||||
int numManifolds = m_dynamicsWorld->getDispatcher()->getNumManifolds();
|
||||
for (int i=0;i<numManifolds;i++)
|
||||
{
|
||||
btPersistentManifold* contactManifold = m_dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
|
||||
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
|
||||
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
|
||||
|
||||
int numContacts = contactManifold->getNumContacts();
|
||||
for (int j=0;j<numContacts;j++)
|
||||
{
|
||||
btManifoldPoint& pt = contactManifold->getContactPoint(j);
|
||||
btVector3 ptA = pt.getPositionWorldOnA();
|
||||
btVector3 ptB = pt.getPositionWorldOnB();
|
||||
printf("contact manifold[%d],pointA[%d]=(%f,%f,%f)\n",i,j,ptA[0],ptA[1],ptA[2]);
|
||||
}
|
||||
}
|
||||
#endif //PRINT_CONTACT_STATISTICS
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void BasicDemo::initPhysics()
|
||||
{
|
||||
|
||||
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
|
||||
int maxNumOutstandingTasks = 1;//number of maximum outstanding tasks
|
||||
#ifdef USE_WIN32_THREADING
|
||||
|
||||
Win32ThreadSupport* threadSupport = new Win32ThreadSupport(Win32ThreadSupport::Win32ThreadConstructionInfo(
|
||||
"collision",
|
||||
processCollisionTask,
|
||||
createCollisionLocalStoreMemory,
|
||||
maxNumOutstandingTasks));
|
||||
#else
|
||||
|
||||
spe_program_handle_t * program_handle;
|
||||
#ifndef USE_CESOF
|
||||
char* spuFileName = "../../../src/BulletMultiThreaded/out/spuCollision.elf";
|
||||
|
||||
program_handle = spe_image_open (spuFileName);
|
||||
if (program_handle == NULL)
|
||||
{
|
||||
printf( "SPU OPEN IMAGE ERROR:%s\n",spuFileName);
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "IMAGE OPENED:%s\n",spuFileName);
|
||||
}
|
||||
#else
|
||||
extern spe_program_handle_t spu_program;
|
||||
program_handle = &spu_program;
|
||||
#endif
|
||||
SpuLibspe2Support* threadSupport = new SpuLibspe2Support( program_handle, maxNumOutstandingTasks);
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
|
||||
m_dispatcher = new SpuGatheringCollisionDispatcher(threadSupport,maxNumOutstandingTasks,collisionConfiguration);
|
||||
#else
|
||||
m_dispatcher = new btCollisionDispatcher(collisionConfiguration);
|
||||
#endif //USE_PARALLEL_DISPATCHER
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
|
||||
|
||||
#define USE_SWEEP_AND_PRUNE 1
|
||||
#ifdef USE_SWEEP_AND_PRUNE
|
||||
#define maxProxies 8192
|
||||
btVector3 worldAabbMin(-10000,-10000,-10000);
|
||||
btVector3 worldAabbMax(10000,10000,10000);
|
||||
m_overlappingPairCache = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
|
||||
//m_overlappingPairCache = new btMultiSapBroadphase();
|
||||
|
||||
|
||||
#else
|
||||
m_overlappingPairCache = new btSimpleBroadphase;
|
||||
#endif //USE_SWEEP_AND_PRUNE
|
||||
|
||||
|
||||
|
||||
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
|
||||
m_solver = sol;
|
||||
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver,m_collisionConfiguration);
|
||||
m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
|
||||
|
||||
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
|
||||
|
||||
|
||||
///create a few basic rigid bodies
|
||||
|
||||
|
||||
//static ground
|
||||
#ifdef USE_GROUND_BOX
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
|
||||
#else
|
||||
btCollisionShape* groundShape = new btSphereShape(btScalar(50.));
|
||||
#endif//USE_GROUND_BOX
|
||||
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
|
||||
btTransform groundTransform;
|
||||
groundTransform.setIdentity();
|
||||
groundTransform.setOrigin(btVector3(0,-50,0));
|
||||
localCreateRigidBody(btScalar(0.),groundTransform,groundShape);
|
||||
|
||||
//create a few dynamic sphere rigidbodies (re-using the same sphere shape)
|
||||
//btCollisionShape* sphereShape = new btBoxShape(btVector3(1,1,1));
|
||||
btCollisionShape* sphereShape = new btSphereShape(btScalar(1.));
|
||||
m_collisionShapes.push_back(sphereShape);
|
||||
|
||||
int i;
|
||||
for (i=0;i<gNumObjects;i++)
|
||||
{
|
||||
|
||||
sphereShape->setMargin(gCollisionMargin);
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
//stack them
|
||||
int colsize = 2;
|
||||
int row = (int)((i*HALF_EXTENTS*2)/(colsize*2*HALF_EXTENTS));
|
||||
int row2 = row;
|
||||
int col = (i)%(colsize)-colsize/2;
|
||||
btVector3 pos(col*2*HALF_EXTENTS + (row2%2)*HALF_EXTENTS,
|
||||
row*2*HALF_EXTENTS+HALF_EXTENTS,0);
|
||||
|
||||
trans.setOrigin(pos);
|
||||
//btRigidBody* body = localCreateRigidBody(btScalar(1.),trans,sphereShape);
|
||||
localCreateRigidBody(btScalar(1.),trans,sphereShape);
|
||||
}
|
||||
|
||||
//clientResetScene();
|
||||
}
|
||||
|
||||
btRigidBody* BasicDemo::localCreateRigidBody(btScalar mass,const btTransform& startTrans,btCollisionShape* colShape)
|
||||
{
|
||||
btVector3 inertia(0,0,0);
|
||||
if (mass)
|
||||
colShape->calculateLocalInertia(mass,inertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbci(mass,0,colShape,inertia);
|
||||
rbci.m_startWorldTransform = startTrans;
|
||||
|
||||
btRigidBody* body = new btRigidBody(rbci);
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
return body;
|
||||
|
||||
}
|
||||
void BasicDemo::exitPhysics()
|
||||
{
|
||||
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
//delete solver
|
||||
delete m_solver;
|
||||
|
||||
//delete broadphase
|
||||
delete m_overlappingPairCache;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef BASIC_DEMO_H
|
||||
#define BASIC_DEMO_H
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
|
||||
class btDiscreteDynamicsworld;
|
||||
class btCollisionShape;
|
||||
class btOverlappingPairCache;
|
||||
class btCollisionDispatcher;
|
||||
class btConstraintSolver;
|
||||
struct btCollisionAlgorithmCreateFunc;
|
||||
|
||||
///BasicDemo is good starting point for learning the code base and porting.
|
||||
class BasicDemo
|
||||
{
|
||||
btClock m_clock;
|
||||
|
||||
//keep the collision shapes, for deletion/cleanup
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
btBroadphaseInterface* m_overlappingPairCache;
|
||||
|
||||
btCollisionDispatcher* m_dispatcher;
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
btConstraintSolver* m_solver;
|
||||
btDiscreteDynamicsWorld* m_dynamicsWorld;
|
||||
|
||||
btCollisionAlgorithmCreateFunc* m_sphereSphereCF;
|
||||
btCollisionAlgorithmCreateFunc* m_sphereBoxCF;
|
||||
btCollisionAlgorithmCreateFunc* m_boxSphereCF;
|
||||
|
||||
btRigidBody* localCreateRigidBody(btScalar mass,const btTransform& startTrans,btCollisionShape* colShape);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //BASIC_DEMO_H
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# ---------------------------------------------------------------
|
||||
# PLEASE DO NOT MODIFY THIS SECTION
|
||||
# This prolog section is automatically generated.
|
||||
#
|
||||
# (C) Copyright 2001,2006,
|
||||
# International Business Machines Corporation,
|
||||
#
|
||||
# All Rights Reserved.
|
||||
# ---------------------------------------------------------------
|
||||
# --------------------------------------------------------------
|
||||
# PROLOG END TAG zYx
|
||||
|
||||
########################################################################
|
||||
# Source Code
|
||||
########################################################################
|
||||
VPATH = ../
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
ROOT = ../../..
|
||||
HOSTINC = /usr/include
|
||||
PROGRAM_ppu := BasicDemo2
|
||||
|
||||
#######################################################################
|
||||
# Objs
|
||||
######################################################################
|
||||
OBJS = BasicDemo2.o
|
||||
|
||||
########################################################################
|
||||
# Libraries, Include paths, Defines
|
||||
########################################################################
|
||||
INCLUDE = -DUSE_LIBSPE2 \
|
||||
-I../ \
|
||||
-I$(ROOT)/src \
|
||||
-I$(ROOT)/Demos/OpenGL \
|
||||
-I$(HOSTINC)
|
||||
SYS_LIBS := -lspe2 -lm
|
||||
|
||||
IMPORTS = $(ROOT)/lib/ibmsdk/bulletmultithreaded.a \
|
||||
$(ROOT)/lib/ibmsdk/bulletdynamics.a \
|
||||
$(ROOT)/lib/ibmsdk/bulletcollision.a \
|
||||
$(ROOT)/lib/ibmsdk/bulletmath.a
|
||||
|
||||
#######################################################################
|
||||
# Install files/dirs
|
||||
#######################################################################
|
||||
INSTALL_DIR = $(ROOT)/ibmsdk
|
||||
INSTALL_FILES = $(PROGRAM_ppu)
|
||||
########################################################################
|
||||
# make.footer
|
||||
########################################################################
|
||||
|
||||
|
||||
IBM_CELLSDK_VERSION := $(shell if [ -d /opt/cell ]; then echo "3.0"; fi)
|
||||
|
||||
ifeq ("$(IBM_CELLSDK_VERSION)","3.0")
|
||||
CELL_TOP ?= /opt/cell/sdk
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
CELL_TOP ?= /opt/ibm/cell-sdk/prototype
|
||||
include $(CELL_TOP)/make.footer
|
||||
endif
|
||||
|
||||
|
||||
$(PPMS):
|
||||
cp textures/$@ .
|
||||
|
||||
cleanlocal:
|
||||
rm -f $(PPMS)
|
||||
@@ -0,0 +1,31 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL }
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppCharacterDemo
|
||||
DynamicCharacterController.cpp
|
||||
DynamicCharacterController.h
|
||||
CharacterDemo.cpp
|
||||
CharacterDemo.h
|
||||
../BspDemo/BspConverter.cpp
|
||||
../BspDemo/BspConverter.h
|
||||
../BspDemo/BspLoader.cpp
|
||||
../BspDemo/BspLoader.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,490 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"
|
||||
#include "BulletCollision/CollisionDispatch/btGhostObject.h"
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
#include "GL_ShapeDrawer.h"
|
||||
|
||||
#include "GlutStuff.h"
|
||||
#include "CharacterDemo.h"
|
||||
#ifdef DYNAMIC_CHARACTER_CONTROLLER
|
||||
#include "DynamicCharacterController.h"
|
||||
#else
|
||||
#include "BulletDynamics/Character/btKinematicCharacterController.h"
|
||||
#endif
|
||||
|
||||
const int maxProxies = 32766;
|
||||
const int maxOverlap = 65535;
|
||||
|
||||
static int gForward = 0;
|
||||
static int gBackward = 0;
|
||||
static int gLeft = 0;
|
||||
static int gRight = 0;
|
||||
static int gJump = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
CharacterDemo::CharacterDemo()
|
||||
:
|
||||
m_cameraHeight(4.f),
|
||||
m_minCameraDistance(3.f),
|
||||
m_maxCameraDistance(10.f),
|
||||
m_indexVertexArrays(0),
|
||||
m_vertices(0)
|
||||
{
|
||||
m_character = 0;
|
||||
m_cameraPosition = btVector3(30,30,30);
|
||||
}
|
||||
|
||||
|
||||
void CharacterDemo::initPhysics()
|
||||
{
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50));
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
btVector3 worldMin(-1000,-1000,-1000);
|
||||
btVector3 worldMax(1000,1000,1000);
|
||||
btAxisSweep3* sweepBP = new btAxisSweep3(worldMin,worldMax);
|
||||
m_overlappingPairCache = sweepBP;
|
||||
|
||||
m_constraintSolver = new btSequentialImpulseConstraintSolver();
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_constraintSolver,m_collisionConfiguration);
|
||||
|
||||
#ifdef DYNAMIC_CHARACTER_CONTROLLER
|
||||
m_character = new DynamicCharacterController ();
|
||||
#else
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity ();
|
||||
startTransform.setOrigin (btVector3(0.0, 4.0, 0.0));
|
||||
|
||||
m_ghostObject = new btPairCachingGhostObject();
|
||||
m_ghostObject->setWorldTransform(startTransform);
|
||||
sweepBP->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
|
||||
btScalar characterHeight=1.75;
|
||||
btScalar characterWidth =1.75;
|
||||
btConvexShape* capsule = new btCapsuleShape(characterWidth,characterHeight);
|
||||
m_ghostObject->setCollisionShape (capsule);
|
||||
m_ghostObject->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);
|
||||
|
||||
btScalar stepHeight = btScalar(0.35);
|
||||
m_character = new btKinematicCharacterController (m_ghostObject,capsule,stepHeight);
|
||||
#endif
|
||||
|
||||
////////////////
|
||||
|
||||
/// Create some basic environment from a Quake level
|
||||
|
||||
//m_dynamicsWorld->setGravity(btVector3(0,0,0));
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
|
||||
char* bspfilename = "BspDemo.bsp";
|
||||
void* memoryBuffer = 0;
|
||||
|
||||
FILE* file = fopen(bspfilename,"r");
|
||||
if (!file)
|
||||
{
|
||||
//visual studio leaves the current working directory in the projectfiles folder
|
||||
bspfilename = "../../BspDemo.bsp";
|
||||
file = fopen(bspfilename,"r");
|
||||
}
|
||||
if (!file)
|
||||
{
|
||||
//visual studio leaves the current working directory in the projectfiles folder
|
||||
bspfilename = "BspDemo.bsp";
|
||||
file = fopen(bspfilename,"r");
|
||||
}
|
||||
|
||||
if (file)
|
||||
{
|
||||
BspLoader bspLoader;
|
||||
int size=0;
|
||||
if (fseek(file, 0, SEEK_END) || (size = ftell(file)) == EOF || fseek(file, 0, SEEK_SET)) { /* File operations denied? ok, just close and return failure */
|
||||
printf("Error: cannot get filesize from %s\n", bspfilename);
|
||||
} else
|
||||
{
|
||||
//how to detect file size?
|
||||
memoryBuffer = malloc(size+1);
|
||||
fread(memoryBuffer,1,size,file);
|
||||
bspLoader.loadBSPFile( memoryBuffer);
|
||||
|
||||
BspToBulletConverter bsp2bullet(this);
|
||||
float bspScaling = 0.1f;
|
||||
bsp2bullet.convertBsp(bspLoader,bspScaling);
|
||||
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
///only collide with static for now (no interaction with dynamic objects)
|
||||
m_dynamicsWorld->addCollisionObject(m_ghostObject,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
|
||||
|
||||
m_dynamicsWorld->addAction(m_character);
|
||||
|
||||
|
||||
///////////////
|
||||
|
||||
clientResetScene();
|
||||
|
||||
setCameraDistance(56.f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//to be implemented by the demo
|
||||
void CharacterDemo::renderme()
|
||||
{
|
||||
updateCamera();
|
||||
|
||||
DemoApplication::renderme();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CharacterDemo::debugDrawContacts()
|
||||
{
|
||||
// printf("numPairs = %d\n",m_customPairCallback->getOverlappingPairArray().size());
|
||||
{
|
||||
btManifoldArray manifoldArray;
|
||||
btBroadphasePairArray& pairArray = m_ghostObject->getOverlappingPairCache()->getOverlappingPairArray();
|
||||
int numPairs = pairArray.size();
|
||||
|
||||
for (int i=0;i<numPairs;i++)
|
||||
{
|
||||
manifoldArray.clear();
|
||||
|
||||
const btBroadphasePair& pair = pairArray[i];
|
||||
|
||||
btBroadphasePair* collisionPair = m_overlappingPairCache->getOverlappingPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1);
|
||||
if (!collisionPair)
|
||||
continue;
|
||||
|
||||
if (collisionPair->m_algorithm)
|
||||
collisionPair->m_algorithm->getAllContactManifolds(manifoldArray);
|
||||
|
||||
for (int j=0;j<manifoldArray.size();j++)
|
||||
{
|
||||
btPersistentManifold* manifold = manifoldArray[j];
|
||||
for (int p=0;p<manifold->getNumContacts();p++)
|
||||
{
|
||||
const btManifoldPoint&pt = manifold->getContactPoint(p);
|
||||
|
||||
btVector3 color(255,255,255);
|
||||
m_dynamicsWorld->getDebugDrawer()->drawContactPoint(pt.getPositionWorldOnB(),pt.m_normalWorldOnB,pt.getDistance(),pt.getLifeTime(),color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CharacterDemo::clientMoveAndDisplay()
|
||||
{
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
float dt = getDeltaTimeMicroseconds() * 0.000001f;
|
||||
|
||||
/* Character stuff &*/
|
||||
if (m_character)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
debugDrawContacts();
|
||||
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
//during idle mode, just run 1 simulation step maximum
|
||||
int maxSimSubSteps = m_idle ? 1 : 2;
|
||||
if (m_idle)
|
||||
dt = 1.0/420.f;
|
||||
|
||||
///set walkDirection for our character
|
||||
btTransform xform;
|
||||
xform = m_ghostObject->getWorldTransform ();
|
||||
|
||||
btVector3 forwardDir = xform.getBasis()[2];
|
||||
// printf("forwardDir=%f,%f,%f\n",forwardDir[0],forwardDir[1],forwardDir[2]);
|
||||
btVector3 upDir = xform.getBasis()[1];
|
||||
btVector3 strafeDir = xform.getBasis()[0];
|
||||
forwardDir.normalize ();
|
||||
upDir.normalize ();
|
||||
strafeDir.normalize ();
|
||||
|
||||
btVector3 walkDirection = btVector3(0.0, 0.0, 0.0);
|
||||
btScalar walkVelocity = btScalar(1.1) * 4.0; // 4 km/h -> 1.1 m/s
|
||||
btScalar walkSpeed = walkVelocity * dt;
|
||||
|
||||
if (gLeft)
|
||||
walkDirection += strafeDir;
|
||||
|
||||
if (gRight)
|
||||
walkDirection -= strafeDir;
|
||||
|
||||
if (gForward)
|
||||
walkDirection += forwardDir;
|
||||
|
||||
if (gBackward)
|
||||
walkDirection -= forwardDir;
|
||||
|
||||
|
||||
m_character->setWalkDirection(walkDirection*walkSpeed);
|
||||
|
||||
|
||||
int numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps);
|
||||
|
||||
//optional but useful: debug drawing
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
//#define VERBOSE_FEEDBACK
|
||||
#ifdef VERBOSE_FEEDBACK
|
||||
if (!numSimSteps)
|
||||
printf("Interpolated transforms\n");
|
||||
else
|
||||
{
|
||||
if (numSimSteps > maxSimSubSteps)
|
||||
{
|
||||
//detect dropping frames
|
||||
printf("Dropped (%i) simulation steps out of %i\n",numSimSteps - maxSimSubSteps,numSimSteps);
|
||||
} else
|
||||
{
|
||||
printf("Simulated (%i) steps\n",numSimSteps);
|
||||
}
|
||||
}
|
||||
#endif //VERBOSE_FEEDBACK
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
btProfiler::beginBlock("render");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
|
||||
renderme();
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
btProfiler::endBlock("render");
|
||||
#endif
|
||||
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CharacterDemo::displayCallback(void)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
renderme();
|
||||
|
||||
//optional but useful: debug drawing
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
debugDrawContacts();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
void CharacterDemo::clientResetScene()
|
||||
{
|
||||
m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(m_ghostObject->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher());
|
||||
|
||||
m_character->reset ();
|
||||
///WTF
|
||||
m_character->warp (btVector3(0, -2.0, 0.));
|
||||
}
|
||||
|
||||
void CharacterDemo::specialKeyboardUp(int key, int x, int y)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case GLUT_KEY_UP:
|
||||
{
|
||||
gForward = 0;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_DOWN:
|
||||
{
|
||||
gBackward = 0;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_LEFT:
|
||||
{
|
||||
gLeft = 0;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_RIGHT:
|
||||
{
|
||||
gRight = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DemoApplication::specialKeyboardUp(key,x,y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CharacterDemo::specialKeyboard(int key, int x, int y)
|
||||
{
|
||||
|
||||
// printf("key = %i x=%i y=%i\n",key,x,y);
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case GLUT_KEY_UP:
|
||||
{
|
||||
gForward = 1;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_DOWN:
|
||||
{
|
||||
gBackward = 1;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_LEFT:
|
||||
{
|
||||
gLeft = 1;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_RIGHT:
|
||||
{
|
||||
gRight = 1;
|
||||
}
|
||||
break;
|
||||
case GLUT_KEY_F1:
|
||||
{
|
||||
if (m_character && m_character->canJump())
|
||||
gJump = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DemoApplication::specialKeyboard(key,x,y);
|
||||
break;
|
||||
}
|
||||
|
||||
// glutPostRedisplay();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CharacterDemo::updateCamera()
|
||||
{
|
||||
|
||||
//#define DISABLE_CAMERA 1
|
||||
#ifdef DISABLE_CAMERA
|
||||
DemoApplication::updateCamera();
|
||||
return;
|
||||
#endif //DISABLE_CAMERA
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
btTransform characterWorldTrans;
|
||||
|
||||
//look at the vehicle
|
||||
characterWorldTrans = m_ghostObject->getWorldTransform();
|
||||
btVector3 up = characterWorldTrans.getBasis()[1];
|
||||
btVector3 backward = -characterWorldTrans.getBasis()[2];
|
||||
up.normalize ();
|
||||
backward.normalize ();
|
||||
|
||||
m_cameraTargetPosition = characterWorldTrans.getOrigin();
|
||||
m_cameraPosition = m_cameraTargetPosition + up * 2.0 + backward * 12.0;
|
||||
|
||||
//update OpenGL camera settings
|
||||
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10000.0);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
gluLookAt(m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2],
|
||||
m_cameraTargetPosition[0],m_cameraTargetPosition[1], m_cameraTargetPosition[2],
|
||||
m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
CharacterDemo::~CharacterDemo()
|
||||
{
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
if (m_character)
|
||||
{
|
||||
m_dynamicsWorld->removeCollisionObject(m_ghostObject);
|
||||
}
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
|
||||
delete m_indexVertexArrays;
|
||||
delete m_vertices;
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
//delete solver
|
||||
delete m_constraintSolver;
|
||||
|
||||
//delete broadphase
|
||||
delete m_overlappingPairCache;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef CHARACTER_DEMO_H
|
||||
#define CHARACTER_DEMO_H
|
||||
|
||||
|
||||
///DYNAMIC_CHARACTER_CONTROLLER is not fully implemented yet at the moment
|
||||
//#define DYNAMIC_CHARACTER_CONTROLLER 1
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btConvexHullShape.h"
|
||||
|
||||
class btCharacterControllerInterface;
|
||||
class btDynamicCharacterController;
|
||||
class btKinematicCharacterController;
|
||||
|
||||
class btCollisionShape;
|
||||
|
||||
|
||||
#include "DemoApplication.h"
|
||||
|
||||
///CharacterDemo shows how to setup and use the built-in raycast vehicle
|
||||
class CharacterDemo : public DemoApplication
|
||||
{
|
||||
public:
|
||||
|
||||
#ifdef DYNAMIC_CHARACTER_CONTROLLER
|
||||
btCharacterControllerInterface* m_character;
|
||||
#else
|
||||
btKinematicCharacterController* m_character;
|
||||
class btPairCachingGhostObject* m_ghostObject;
|
||||
#endif
|
||||
|
||||
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
class btBroadphaseInterface* m_overlappingPairCache;
|
||||
|
||||
class btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
class btConstraintSolver* m_constraintSolver;
|
||||
|
||||
class btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
class btTriangleIndexVertexArray* m_indexVertexArrays;
|
||||
|
||||
btVector3* m_vertices;
|
||||
|
||||
void debugDrawContacts();
|
||||
|
||||
float m_cameraHeight;
|
||||
|
||||
float m_minCameraDistance;
|
||||
float m_maxCameraDistance;
|
||||
|
||||
|
||||
CharacterDemo();
|
||||
|
||||
virtual ~CharacterDemo();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
///a very basic camera following the character
|
||||
virtual void updateCamera();
|
||||
|
||||
virtual void specialKeyboard(int key, int x, int y);
|
||||
|
||||
virtual void specialKeyboardUp(int key, int x, int y);
|
||||
|
||||
void renderme();
|
||||
|
||||
void initPhysics();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
CharacterDemo* demo = new CharacterDemo();
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define QUAKE_BSP_IMPORTING 1
|
||||
#ifdef QUAKE_BSP_IMPORTING
|
||||
#include "../BspDemo/BspLoader.h"
|
||||
#include "../BspDemo/BspConverter.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class BspToBulletConverter : public BspConverter
|
||||
{
|
||||
CharacterDemo* m_demoApp;
|
||||
|
||||
public:
|
||||
|
||||
BspToBulletConverter(CharacterDemo* demoApp)
|
||||
:m_demoApp(demoApp)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void addConvexVerticesCollider(btAlignedObjectArray<btVector3>& vertices, bool isEntity, const btVector3& entityTargetLocation)
|
||||
{
|
||||
///perhaps we can do something special with entities (isEntity)
|
||||
///like adding a collision Triggering (as example)
|
||||
|
||||
if (vertices.size() > 0)
|
||||
{
|
||||
float mass = 0.f;
|
||||
btTransform startTransform;
|
||||
//can use a shift
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-10.0f,0.0f));
|
||||
//this create an internal copy of the vertices
|
||||
for (int i = 0; i < vertices.size(); i++)
|
||||
{
|
||||
vertices[i] *= btScalar(0.5);
|
||||
float t = vertices[i].getZ() * btScalar(0.75);
|
||||
vertices[i].setZ(-vertices[i].getY());
|
||||
vertices[i].setY(t);
|
||||
}
|
||||
|
||||
btCollisionShape* shape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
|
||||
m_demoApp->m_collisionShapes.push_back(shape);
|
||||
|
||||
//btRigidBody* body = m_demoApp->localCreateRigidBody(mass, startTransform,shape);
|
||||
m_demoApp->localCreateRigidBody(mass, startTransform,shape);
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif //QUAKE_BSP_IMPORTING
|
||||
|
||||
|
||||
#endif //CHARACTER_DEMO_H
|
||||
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
|
||||
#include "LinearMath/btDefaultMotionState.h"
|
||||
#include "DynamicCharacterController.h"
|
||||
|
||||
DynamicCharacterController::DynamicCharacterController ()
|
||||
{
|
||||
m_rayLambda[0] = 1.0;
|
||||
m_rayLambda[1] = 1.0;
|
||||
m_halfHeight = 1.0;
|
||||
m_turnAngle = 0.0;
|
||||
m_maxLinearVelocity = 10.0;
|
||||
m_walkVelocity = 8.0; // meters/sec
|
||||
m_turnVelocity = 1.0; // radians/sec
|
||||
m_shape = NULL;
|
||||
m_rigidBody = NULL;
|
||||
}
|
||||
|
||||
DynamicCharacterController::~DynamicCharacterController ()
|
||||
{
|
||||
}
|
||||
|
||||
void DynamicCharacterController::setup (btScalar height, btScalar width, btScalar stepHeight)
|
||||
{
|
||||
btVector3 spherePositions[2];
|
||||
btScalar sphereRadii[2];
|
||||
|
||||
sphereRadii[0] = width;
|
||||
sphereRadii[1] = width;
|
||||
spherePositions[0] = btVector3 (0.0, (height/btScalar(2.0) - width), 0.0);
|
||||
spherePositions[1] = btVector3 (0.0, (-height/btScalar(2.0) + width), 0.0);
|
||||
|
||||
m_halfHeight = height/btScalar(2.0);
|
||||
|
||||
m_shape = new btMultiSphereShape (btVector3(width/btScalar(2.0), height/btScalar(2.0), width/btScalar(2.0)), &spherePositions[0], &sphereRadii[0], 2);
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity ();
|
||||
startTransform.setOrigin (btVector3(0.0, 2.0, 0.0));
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo cInfo(1.0, myMotionState, m_shape);
|
||||
m_rigidBody = new btRigidBody(cInfo);
|
||||
// kinematic vs. static doesn't work
|
||||
//m_rigidBody->setCollisionFlags( m_rigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
m_rigidBody->setSleepingThresholds (0.0, 0.0);
|
||||
m_rigidBody->setAngularFactor (0.0);
|
||||
|
||||
}
|
||||
|
||||
void DynamicCharacterController::destroy ()
|
||||
{
|
||||
if (m_shape)
|
||||
{
|
||||
delete m_shape;
|
||||
}
|
||||
|
||||
if (m_rigidBody)
|
||||
{
|
||||
delete m_rigidBody;
|
||||
m_rigidBody = 0;
|
||||
}
|
||||
}
|
||||
|
||||
btCollisionObject* DynamicCharacterController::getCollisionObject ()
|
||||
{
|
||||
return m_rigidBody;
|
||||
}
|
||||
|
||||
void DynamicCharacterController::preStep (const btCollisionWorld* collisionWorld)
|
||||
{
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
btVector3 down = -xform.getBasis()[1];
|
||||
btVector3 forward = xform.getBasis()[2];
|
||||
down.normalize ();
|
||||
forward.normalize();
|
||||
|
||||
m_raySource[0] = xform.getOrigin();
|
||||
m_raySource[1] = xform.getOrigin();
|
||||
|
||||
m_rayTarget[0] = m_raySource[0] + down * m_halfHeight * btScalar(1.1);
|
||||
m_rayTarget[1] = m_raySource[1] + forward * m_halfHeight * btScalar(1.1);
|
||||
|
||||
class ClosestNotMe : public btCollisionWorld::ClosestRayResultCallback
|
||||
{
|
||||
public:
|
||||
ClosestNotMe (btRigidBody* me) : btCollisionWorld::ClosestRayResultCallback(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 0.0, 0.0))
|
||||
{
|
||||
m_me = me;
|
||||
}
|
||||
|
||||
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
|
||||
{
|
||||
if (rayResult.m_collisionObject == m_me)
|
||||
return 1.0;
|
||||
|
||||
return ClosestRayResultCallback::addSingleResult (rayResult, normalInWorldSpace
|
||||
);
|
||||
}
|
||||
protected:
|
||||
btRigidBody* m_me;
|
||||
};
|
||||
|
||||
ClosestNotMe rayCallback(m_rigidBody);
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
rayCallback.m_closestHitFraction = 1.0;
|
||||
collisionWorld->rayTest (m_raySource[i], m_rayTarget[i], rayCallback);
|
||||
if (rayCallback.hasHit())
|
||||
{
|
||||
m_rayLambda[i] = rayCallback.m_closestHitFraction;
|
||||
} else {
|
||||
m_rayLambda[i] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicCharacterController::playerStep (const btCollisionWorld* dynaWorld,btScalar dt,
|
||||
int forward,
|
||||
int backward,
|
||||
int left,
|
||||
int right,
|
||||
int jump)
|
||||
{
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
|
||||
/* Handle turning */
|
||||
if (left)
|
||||
m_turnAngle -= dt * m_turnVelocity;
|
||||
if (right)
|
||||
m_turnAngle += dt * m_turnVelocity;
|
||||
|
||||
xform.setRotation (btQuaternion (btVector3(0.0, 1.0, 0.0), m_turnAngle));
|
||||
|
||||
btVector3 linearVelocity = m_rigidBody->getLinearVelocity();
|
||||
btScalar speed = m_rigidBody->getLinearVelocity().length();
|
||||
|
||||
btVector3 forwardDir = xform.getBasis()[2];
|
||||
forwardDir.normalize ();
|
||||
btVector3 walkDirection = btVector3(0.0, 0.0, 0.0);
|
||||
btScalar walkSpeed = m_walkVelocity * dt;
|
||||
|
||||
if (forward)
|
||||
walkDirection += forwardDir;
|
||||
if (backward)
|
||||
walkDirection -= forwardDir;
|
||||
|
||||
|
||||
|
||||
if (!forward && !backward && onGround())
|
||||
{
|
||||
/* Dampen when on the ground and not being moved by the player */
|
||||
linearVelocity *= btScalar(0.2);
|
||||
m_rigidBody->setLinearVelocity (linearVelocity);
|
||||
} else {
|
||||
if (speed < m_maxLinearVelocity)
|
||||
{
|
||||
btVector3 velocity = linearVelocity + walkDirection * walkSpeed;
|
||||
m_rigidBody->setLinearVelocity (velocity);
|
||||
}
|
||||
}
|
||||
|
||||
m_rigidBody->getMotionState()->setWorldTransform (xform);
|
||||
m_rigidBody->setCenterOfMassTransform (xform);
|
||||
}
|
||||
|
||||
bool DynamicCharacterController::canJump () const
|
||||
{
|
||||
return onGround();
|
||||
}
|
||||
|
||||
void DynamicCharacterController::jump ()
|
||||
{
|
||||
if (!canJump())
|
||||
return;
|
||||
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
btVector3 up = xform.getBasis()[1];
|
||||
up.normalize ();
|
||||
btScalar magnitude = (btScalar(1.0)/m_rigidBody->getInvMass()) * btScalar(8.0);
|
||||
m_rigidBody->applyCentralImpulse (up * magnitude);
|
||||
}
|
||||
|
||||
bool DynamicCharacterController::onGround () const
|
||||
{
|
||||
return m_rayLambda[0] < btScalar(1.0);
|
||||
}
|
||||
|
||||
void DynamicCharacterController::reset ()
|
||||
{
|
||||
}
|
||||
void DynamicCharacterController::warp (const btVector3& origin)
|
||||
{
|
||||
}
|
||||
void DynamicCharacterController::registerPairCacheAndDispatcher (btOverlappingPairCache* pairCache, btCollisionDispatcher* dispatcher)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef CHARACTER_CONTROLLER_H
|
||||
#define CHARACTER_CONTROLLER_H
|
||||
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
#include "BulletDynamics/Character/btCharacterControllerInterface.h"
|
||||
|
||||
class btCollisionShape;
|
||||
class btRigidBody;
|
||||
class btCollisionWorld;
|
||||
|
||||
///DynamicCharacterController is obsolete/unsupported at the moment
|
||||
class DynamicCharacterController : public btCharacterControllerInterface
|
||||
{
|
||||
protected:
|
||||
btScalar m_halfHeight;
|
||||
btCollisionShape* m_shape;
|
||||
btRigidBody* m_rigidBody;
|
||||
|
||||
btVector3 m_raySource[2];
|
||||
btVector3 m_rayTarget[2];
|
||||
btScalar m_rayLambda[2];
|
||||
btVector3 m_rayNormal[2];
|
||||
|
||||
btScalar m_turnAngle;
|
||||
|
||||
btScalar m_maxLinearVelocity;
|
||||
btScalar m_walkVelocity;
|
||||
btScalar m_turnVelocity;
|
||||
public:
|
||||
DynamicCharacterController ();
|
||||
~DynamicCharacterController ();
|
||||
void setup (btScalar height = 2.0, btScalar width = 0.25, btScalar stepHeight = 0.25);
|
||||
void destroy ();
|
||||
|
||||
virtual void reset ();
|
||||
virtual void warp (const btVector3& origin);
|
||||
virtual void registerPairCacheAndDispatcher (btOverlappingPairCache* pairCache, btCollisionDispatcher* dispatcher);
|
||||
|
||||
btCollisionObject* getCollisionObject ();
|
||||
|
||||
void preStep (const btCollisionWorld* collisionWorld);
|
||||
void playerStep (const btCollisionWorld* collisionWorld,btScalar dt,
|
||||
int forward,
|
||||
int backward,
|
||||
int left,
|
||||
int right,
|
||||
int jump);
|
||||
bool canJump () const;
|
||||
void jump ();
|
||||
|
||||
bool onGround () const;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
SubDir TOP Demos CharacterDemo ;
|
||||
|
||||
BulletDemo CharacterDemo : [ Wildcard *.h *.cpp ]
|
||||
../BspDemo/BspConverter.cpp
|
||||
../BspDemo/BspConverter.h
|
||||
../BspDemo/BspLoader.cpp
|
||||
../BspDemo/BspLoader.h
|
||||
|
||||
;
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
#include "CharacterDemo.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
CharacterDemo* characterDemo = new CharacterDemo;
|
||||
|
||||
characterDemo->initPhysics();
|
||||
characterDemo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
return glutmain(argc, argv,640,480,"Bullet Character Demo. http://www.continuousphysics.com/Bullet/phpBB2/", characterDemo);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/BulletColladaConverter ${BULLET_PHYSICS_SOURCE_DIR}/Extras/LibXML ${BULLET_PHYSICS_SOURCE_DIR}/Extras/LibXML/include ${BULLET_PHYSICS_SOURCE_DIR}/Extras/COLLADA_DOM/include/1.4 ${BULLET_PHYSICS_SOURCE_DIR}/Extras/COLLADA_DOM/include ${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL }
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
BulletColladaConverter ColladaDom XML OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppColladaDemo
|
||||
ColladaDemo.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
#include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h"
|
||||
|
||||
//COLLADA_DOM and LibXML source code are included in Extras/ folder.
|
||||
//COLLADA_DOM should compile under all platforms, and is enabled by default.
|
||||
|
||||
#include "ColladaConverter.h"
|
||||
|
||||
#include "BMF_Api.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
float deltaTime = 1.f/60.f;
|
||||
|
||||
#include "ColladaDemo.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
|
||||
///custom version of the converter, that creates physics objects/constraints
|
||||
class MyColladaConverter : public ColladaConverter
|
||||
{
|
||||
DemoApplication* m_demoApp;
|
||||
|
||||
public:
|
||||
MyColladaConverter(DemoApplication* demoApp)
|
||||
: ColladaConverter(demoApp->getDynamicsWorld()),
|
||||
m_demoApp(demoApp)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void setCameraInfo(const btVector3& camUp,int forwardAxis)
|
||||
{
|
||||
m_demoApp->setCameraUp(camUp);
|
||||
m_demoApp->setCameraForwardAxis(forwardAxis);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MyColladaConverter* gColladaConverter = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
GLDebugDrawer debugDrawer;
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
/// Import Collada 1.4 Physics objects
|
||||
/// also can pass filename in as argument
|
||||
const char* filename = "jenga.dae";
|
||||
printf("argc=%i\n",argc);
|
||||
{
|
||||
for (int i=0;i<argc;i++)
|
||||
{
|
||||
printf("argv[%i]=%s\n",i,argv[i]);
|
||||
}
|
||||
}
|
||||
if (argc>1)
|
||||
{
|
||||
filename = argv[1];
|
||||
}
|
||||
|
||||
ColladaDemo* colladaDemo = new ColladaDemo();
|
||||
|
||||
colladaDemo->initPhysics(filename);
|
||||
|
||||
|
||||
// colladaDemo->clientResetScene();
|
||||
|
||||
colladaDemo->setCameraDistance(26.f);
|
||||
|
||||
return glutmain(argc, argv,640,480,"Bullet COLLADA Physics Viewer http://bulletphysics.org",colladaDemo);
|
||||
}
|
||||
|
||||
void ColladaDemo::initPhysics(const char* filename)
|
||||
{
|
||||
m_cameraUp = btVector3(0,0,1);
|
||||
m_ele = 60;
|
||||
m_forwardAxis = 1;
|
||||
|
||||
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
|
||||
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
|
||||
|
||||
btVector3 worldMin(-1000,-1000,-1000);
|
||||
btVector3 worldMax(1000,1000,1000);
|
||||
btBroadphaseInterface* pairCache = new btAxisSweep3(worldMin,worldMax);
|
||||
btConstraintSolver* constraintSolver = new btSequentialImpulseConstraintSolver();
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration);
|
||||
|
||||
//m_dynamicsWorld = new btSimpleDynamicsWorld();
|
||||
|
||||
m_dynamicsWorld->setDebugDrawer(&debugDrawer);
|
||||
|
||||
|
||||
MyColladaConverter* converter = new MyColladaConverter(this);
|
||||
|
||||
bool result = converter->load(filename);
|
||||
if (result)
|
||||
{
|
||||
gColladaConverter = converter;
|
||||
} else
|
||||
{
|
||||
gColladaConverter = 0;
|
||||
printf("gColladaConverter = 0\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ColladaDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
float dt = getDeltaTimeMicroseconds() * 0.000001f;
|
||||
|
||||
m_dynamicsWorld->stepSimulation(dt);
|
||||
|
||||
//optional but useful: debug drawing
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ColladaDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
|
||||
renderme();
|
||||
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ColladaDemo::keyboardCallback(unsigned char key, int x, int y)
|
||||
{
|
||||
if (key =='e')
|
||||
{
|
||||
//save a COLLADA .dae physics snapshot
|
||||
if (gColladaConverter)
|
||||
{
|
||||
if (gColladaConverter->getLastFileName())
|
||||
{
|
||||
//deal with the name pre/post fixing etc.
|
||||
char saveName[550];
|
||||
static int saveCount=1;
|
||||
sprintf(saveName,"%s%i",gColladaConverter->getLastFileName(),saveCount++);
|
||||
char* name = &saveName[0];
|
||||
if (name[0] == '/')
|
||||
{
|
||||
name = &saveName[1];
|
||||
}
|
||||
gColladaConverter->save(name);
|
||||
|
||||
} else
|
||||
{
|
||||
gColladaConverter->save("brandNew.dae");
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
DemoApplication::keyboardCallback(key,x,y);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user