# Newton + C#

## Recommended Posts

leandro81    192
Hi folks, First, sorry if this is the wrong forum to post this kind of subject. So, I am trying to use Newton Physics Library with a DirectX C# application (using this wrapper). If I use only primitives, everything is fine, but when i use a Tree Collision (on the table) this is what happens: (Yellow lines are draw using debug functions of Newton) As you can see, the polygons get all messed up, and this is the code i have used to import the geometry:
List<Face> faces = new List<Face>();

GraphicsStream indexList = obj.ObjectMesh.IndexBuffer.Lock(0, 0, LockFlags.None);
GraphicsStream stm = obj.ObjectMesh.VertexBuffer.Lock(0, 0, LockFlags.None);

short[] indices = new short[obj.ObjectMesh.NumberFaces * 3];
for (int i = 0; i < obj.ObjectMesh.NumberFaces * 3; i++)
{
}

Vector3[] vertices = new Vector3[obj.ObjectMesh.NumberVertices];
for (int i = 0; i < obj.ObjectMesh.NumberVertices; i++)
{

}

float[] floats = new float[9];
for (int i = 0; i < obj.ObjectMesh.NumberFaces; i++)
{

Face face = new Face();
face.Vertex1.X = vertices[indices[(i * 3) + 0]].X;
face.Vertex1.Y = vertices[indices[(i * 3) + 0]].Y;
face.Vertex1.Z = vertices[indices[(i * 3) + 0]].Z;

face.Vertex2.X = vertices[indices[(i * 3) + 1]].X;
face.Vertex2.Y = vertices[indices[(i * 3) + 1]].Y;
face.Vertex2.Z = vertices[indices[(i * 3) + 1]].Z;

face.Vertex3.X = vertices[indices[(i * 3) + 2]].X;
face.Vertex3.Y = vertices[indices[(i * 3) + 2]].Y;
face.Vertex3.Z = vertices[indices[(i * 3) + 2]].Z;

}

obj.ObjectMesh.VertexBuffer.Unlock();
obj.ObjectMesh.IndexBuffer.Unlock();

TreeCollision collision = TreeCollision.newTreeCollision(world, faces, true);


The way I see it, the code above could be wrong, but the C# wrapper could have a bug as well. My question is if any of you have been through anything similar, and could shed some light? Thanks in advance, Leandro

##### Share on other sites
Aph3x    288
Is there a way to turn off Newton's collision optimisation through the wrapper? I'd try that.