Skip to content

Commit

Permalink
Import bullet
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvux committed Aug 1, 2014
1 parent 66114ba commit 508901f
Show file tree
Hide file tree
Showing 95 changed files with 6,107 additions and 0 deletions.
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BulletSharp;

namespace VVVV.DataTypes.Bullet
{
public abstract class AbstractConstraintDefinition
{
//public abstract TypedConstraint GetConstraint(RigidBody rb1,RigidBody rb2);
}
}
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BulletSharp;

namespace VVVV.DataTypes.Bullet
{
public abstract class AbstractSingleBodyConstraintDef
{

public abstract TypedConstraint GetConstraint(RigidBody body);
}
}
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BulletSharp;

namespace VVVV.DataTypes.Bullet
{
public class P2PSingleConstraintDefinition : AbstractSingleBodyConstraintDef
{
public Vector3 Pivot { get; set; }
public float Damping { get; set; }
public float Tau { get; set; }
public float ImpulseClamp { get; set; }

//public void Test()
//{
// BulletSharp.Point2PointConstraint pt;
// /BulletSharp.Generic6DofConstraint sdof = new Generic6DofConstraint(
// pt.Setting.
//sdof.sett
//}

public override TypedConstraint GetConstraint(RigidBody body)
{
Point2PointConstraint cst = new Point2PointConstraint(body, this.Pivot);
cst.Setting.Damping = this.Damping;
cst.Setting.ImpulseClamp = this.ImpulseClamp;
cst.Setting.Tau = this.Tau;

return cst;
}
}
}
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Text;

using BulletSharp;

using SlimDX.Direct3D9;

using VVVV.Internals.Bullet.EX9;
using VVVV.Internals.Bullet;

namespace VVVV.DataTypes.Bullet
{
public abstract class AbstractRigidShapeDefinition
{
private float mass;
protected Dictionary<int, BulletMesh> mesh = new Dictionary<int, BulletMesh>();



protected Quaternion localRotation = Quaternion.Identity;
protected Vector3 localTranslation = Vector3.Zero;

public abstract int ShapeCount { get; }

public BulletMesh GetMesh(Device device)
{
//Will handle multi screen later
if (!this.mesh.ContainsKey(device.ComPointer.ToInt32()))
{
this.mesh.Add(device.ComPointer.ToInt32(),this.CreateMesh(device));
}
return this.mesh[device.ComPointer.ToInt32()];
}

public void DestroyMesh(Device device)
{
if (!this.mesh.ContainsKey(device.ComPointer.ToInt32()))
{
this.mesh[device.ComPointer.ToInt32()].Dispose();
}
this.mesh.Remove(device.ComPointer.ToInt32());
}

public virtual float Mass
{
get { return mass; }
set { mass = value; }
}

public Vector3 Scaling { get; set; }

public Quaternion Rotation
{
get { return this.localRotation; }
set { this.localRotation = value; }
}

public Vector3 Translation
{
get { return this.localTranslation; }
set { this.localTranslation = value; }
}

public string CustomString { get; set; }
public ICloneable CustomObject { get; set; }

public CollisionShape GetShape(ShapeCustomData sc)
{
CollisionShape shape = this.CreateShape();
shape.LocalScaling = this.Scaling;
sc.CustomString = this.CustomString;
if (sc.CustomObject != null) { sc.CustomObject = (ICloneable)this.CustomObject.Clone(); }
shape.UserObject = sc;
shape.CalculateLocalInertia(this.Mass);

return shape;
}

/*Override that to manage shape
* Probably will split the mesh to the shape def
* but does the job so far
*/
protected abstract CollisionShape CreateShape();

protected abstract BulletMesh CreateMesh(Device device);

public void Dispose()
{
foreach (BulletMesh m in this.mesh.Values)
{
m.Dispose();
}
}


}
}
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Text;
using BulletSharp;

using SlimDX.Direct3D9;

using VVVV.Internals.Bullet.EX9;

namespace VVVV.DataTypes.Bullet
{
public class BoxShapeDefinition : AbstractRigidShapeDefinition
{
private float w,h,d;

public override int ShapeCount
{
get { return 1; }
}

public BoxShapeDefinition(float width, float height, float depth)
{
this.w = width / 2.0f;
this.h = height / 2.0f;
this.d = depth / 2.0f;
}


protected override CollisionShape CreateShape()
{
CollisionShape shape = new BoxShape(this.w,this.h,this.d);
return shape;
}

protected override BulletMesh CreateMesh(Device device)
{
//Build the box mesh
return null;// new BulletMesh(Mesh.CreateBox(device, this.w * 2.0f, this.h * 2.0f, this.d * 2.0f));
}


}
}
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BulletSharp;
using VVVV.DataTypes.Bullet;
using VVVV.Internals.Bullet.EX9;
using AssimpNet;
using SlimDX.Direct3D9;

namespace VVVV.Bullet.DataTypes.Shapes.Rigid
{
public unsafe class BvhShapeDefinition : AbstractRigidShapeDefinition
{
private Vector3[] vertices;
private int[] indices;

public BvhShapeDefinition(Vector3[] vertices, int[] indices)
{
this.vertices = vertices;
this.indices = indices;
}

public BvhShapeDefinition(AssimpMesh mesh)
{
this.vertices = new Vector3[mesh.VerticesCount];
this.indices = mesh.Indices.ToArray();

Vector3* v = (Vector3*)mesh.Positions();



for (int i = 0; i < mesh.VerticesCount; i++)
{
this.vertices[i] = v[i];
}
}

public override int ShapeCount
{
get { return 1; }
}

protected override CollisionShape CreateShape()
{
//ConvexHullShape shape = new ConvexHullShape(this.vertices);
//BvhTriangleMeshShape bvh = new BvhTriangleMeshShape(
//StridingMeshInterface smi = new StridingMeshInterface();
TriangleIndexVertexArray tiv = new TriangleIndexVertexArray(this.indices, this.vertices);
BvhTriangleMeshShape bvh = new BvhTriangleMeshShape(tiv, true, true);
//StridingMeshInterface
return bvh;
}

protected override BulletMesh CreateMesh(Device device)
{
return null;
/*int totalTriangles = this.indices.Length / 3;
int totalVerts = this.vertices.Length;
Mesh m = new Mesh(device, totalTriangles, totalVerts, MeshFlags.Use32Bit | MeshFlags.SystemMemory, VertexFormat.Position | VertexFormat.Normal);
SlimDX.DataStream data = m.LockVertexBuffer(LockFlags.None);
for (int i = 0; i < this.vertices.Length; i++)
{
data.Write(this.vertices[i].X);
data.Write(this.vertices[i].Y);
data.Write(this.vertices[i].Z);
data.Write(0.0f);
data.Write(0.0f);
data.Write(0.0f);
//data.Write(this.texcoords[i]);
}
m.UnlockVertexBuffer();
data = m.LockIndexBuffer(LockFlags.None);
for (int i = 0; i < this.indices.Length; i++)
{
data.Write(this.indices[i]);
}
m.UnlockIndexBuffer();
m.ComputeNormals();
return new BulletMesh(m);*/
}
}
}
@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Text;

using BulletSharp;

using SlimDX.Direct3D9;

using VVVV.Internals.Bullet;
using VVVV.Internals.Bullet.EX9;


namespace VVVV.DataTypes.Bullet
{
public class CompoundShapeDefinition : AbstractRigidShapeDefinition
{
private List<AbstractRigidShapeDefinition> children;
//private float mass;

public CompoundShapeDefinition(List<AbstractRigidShapeDefinition> children)
{
this.children = children;
//this.mass = mass;
}

public List<AbstractRigidShapeDefinition> Children
{
get { return children; }
}


public override float Mass
{
get
{
float mass = 0;
foreach (AbstractRigidShapeDefinition def in this.children)
{
mass += def.Mass;
}
return mass;
}
set
{
base.Mass = value;
}
}

public override int ShapeCount
{
get
{
int cnt = 0;
foreach (AbstractRigidShapeDefinition def in this.children)
{
cnt += def.ShapeCount;
}
return cnt;
}
}


protected override CollisionShape CreateShape()
{
CompoundShape shape = new CompoundShape();
foreach (AbstractRigidShapeDefinition shapedef in this.children)
{
ShapeCustomData sc = new ShapeCustomData();
sc.Id = 0;
sc.ShapeDef = shapedef;

Matrix tr = Matrix.Translation(shapedef.Translation);
Matrix rot = Matrix.RotationQuaternion(shapedef.Rotation);

shape.AddChildShape(Matrix.Multiply(rot, tr), shapedef.GetShape(sc));
}
return shape;
}

protected override BulletMesh CreateMesh(Device device)
{
/*List<Mesh> meshes = new List<Mesh>();
foreach (AbstractRigidShapeDefinition def in this.children)
{
meshes.AddRange(def.GetMesh(device).Meshes);
}
return new BulletMesh(meshes);*/
return null;
}
}
}

0 comments on commit 508901f

Please sign in to comment.