Jump to content
  • Advertisement
Sign in to follow this  
leandro81

Newton + C#

This topic is 4028 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 www.ImageShack.us 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 = (short)indexList.Read(typeof(short));
}

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

            vertices = (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;
            faces.Add(face);
                 
}

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


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!