Sign in to follow this  

Newton + C#

Recommended Posts

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) Free Image Hosting at 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++)
            indices[i] = (short)indexList.Read(typeof(short));

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

            vertices[i] = (Vector3)stm.Read(typeof(Vector3));

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;


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 this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this