forked from mrvux/dx11-vvvv
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
95 changed files
with
6,107 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
Nodes/VVVV.DX11.Nodes.Bullet/DataTypes/Constraints/AbstractConstraintDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Nodes/VVVV.DX11.Nodes.Bullet/DataTypes/Constraints/AbstractSingleBodyConstraintDef.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Nodes/VVVV.DX11.Nodes.Bullet/DataTypes/Constraints/P2PSingleConstraintDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
Nodes/VVVV.DX11.Nodes.Bullet/DataTypes/Shapes/Rigid/AbstractRigidShapeDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Nodes/VVVV.DX11.Nodes.Bullet/DataTypes/Shapes/Rigid/BoxShapeDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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)); | ||
} | ||
|
||
|
||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
Nodes/VVVV.DX11.Nodes.Bullet/DataTypes/Shapes/Rigid/BvhShapeDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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);*/ | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
Nodes/VVVV.DX11.Nodes.Bullet/DataTypes/Shapes/Rigid/CompoundShapeDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.