Newton .Net Wrapper for 2.0 and MDX

Share with us how are you using the powerrrr of the force

Moderator: Alain

Newton .Net Wrapper for 2.0 and MDX

Postby Haddd » Thu Mar 17, 2005 3:29 pm

Well, it seems that the fantastic .net wrapper avaialbe in sourceforge has been discontinuity. So, i'm doing a new one, but this time trying and putting examples about workint with it.

I'm just beginnig, so...be patient, and please..¡help me!

Ok. The first one, the mini Wrapper:

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using System.Runtime.InteropServices; // DllImport
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

#endregion

namespace Haddd.Core
{
public class NewtonWrapper
{
[DllImport("Newton2.Dll")]
public static extern int NewtonCreate(int a, int b);
[DllImport("Newton2.Dll")]
public static extern int NewtonCreateBox(int newtonWorld, float dx, float dy, float dz, float[] offsetMatrix);
[DllImport("Newton2.Dll")]
public static extern int NewtonCreateBody(int newtonWorld, int collisionPtr);
[DllImport("Newton2.Dll")]
public static extern void NewtonReleaseCollision(int newtonWorld, int collisionPtr);
[DllImport("Newton2.Dll")]
public static extern void NewtonBodySetMassMatrix(int bodyPtr, float mass, float Ixx, float Iyy, float Izz);
[DllImport("Newton2.Dll")]
public static extern void NewtonBodySetMatrix(int bodyPtr, ref Matrix matrix);
[DllImport("Newton2.Dll")]
public static extern void NewtonBodySetOmega(int bodyPtr, ref Vector3 omega);
[DllImport("Newton2.Dll")]
public static extern void NewtonUpdate(int newtonWorld, float timestep);
[DllImport("Newton2.Dll")]
public static extern void NewtonBodyGetMatrix(int bodyPtr,ref Matrix matrix);
}
}

And the little example:

Creation:

nWorld = NewtonWrapper.NewtonCreate(0, 0);

// create the collsion shape
collision = NewtonWrapper.NewtonCreateBox(nWorld, 2.0f, 2.0f, 2.0f, null);

ribidBodyBox = NewtonWrapper.NewtonCreateBody(nWorld, collision);

NewtonWrapper.NewtonReleaseCollision(nWorld, collision);

NewtonWrapper.NewtonBodySetMassMatrix(ribidBodyBox, 1.0f, 1.0f, 1.0f, 1.0f);

Matrix mat = Matrix.Identity;

NewtonWrapper.NewtonBodySetMatrix(ribidBodyBox, ref mat);

Vector3 omega = new Vector3(5, 5, 5);

NewtonWrapper.NewtonBodySetOmega(ribidBodyBox,ref omega);


Update:


NewtonWrapper.NewtonUpdate(nWorld, Haddd.Timer.DeltaTime);

Matrix matrix=Matrix.Zero;

NewtonWrapper.NewtonBodyGetMatrix(ribidBodyBox, ref matrix);

cubo.AbsoluteTM = matrix;


It's the first example in the SDK, but C# and MDX compliant. :D
Haddd
 
Posts: 35
Joined: Wed Mar 16, 2005 5:06 am

Postby The unProfessional » Thu Mar 17, 2005 7:57 pm

If you want you can grab the source code and just build upon the existing wrapper.
The unProfessional
 
Posts: 131
Joined: Sun May 02, 2004 9:08 pm
Location: Southern California

Postby Haddd » Fri Mar 18, 2005 3:29 am

Thanks, i will take a look at your code!! :wink:
Haddd
 
Posts: 35
Joined: Wed Mar 16, 2005 5:06 am

2nd tutorial wrapper

Postby Haddd » Sat Mar 19, 2005 2:14 pm

i've resolved the problems with delegates, at last!!!

Here is the wrapper for the 2nd tutorial. It's only net 2.0 compatible!!

#region Using directives

using System;
using System.Collections;
using System.Text;

using System.Runtime.InteropServices; // DllImport
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

using Haddd.Scene;

#endregion

namespace Haddd.Core
{
[UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
public delegate void SetTransformCB(int body, ref Matrix matrix);
[UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
public delegate void SetForceAndTorqueCB(int body);

public class NewtonWrapper
{

static Hashtable userData=new Hashtable();
static Hashtable transform = new Hashtable();

[DllImport("Newton.Dll")]
public static extern int NewtonCreate(int a, int b);
[DllImport("Newton.Dll")]
public static extern void NewtonSetSolverModel(int a, int b);
[DllImport("Newton.Dll")]
public static extern void NewtonSetFrictionModel(int a, int b);
[DllImport("Newton.Dll")]
public static extern int NewtonCreateBox(int newtonWorld, float dx, float dy, float dz, float[] offsetMatrix);
[DllImport("Newton.Dll")]
public static extern int NewtonCreateBody(int newtonWorld, int collisionPtr);
[DllImport("Newton.Dll")]
public static extern void NewtonReleaseCollision(int newtonWorld, int collisionPtr);
[DllImport("Newton.Dll")]
public static extern void NewtonBodySetMassMatrix(int bodyPtr, float mass, float Ixx, float Iyy, float Izz);
[DllImport("Newton.Dll")]
public static extern void NewtonBodyGetMassMatrix(int bodyPtr, out float mass, out float Ixx, out float Iyy, out float Izz);
[DllImport("Newton.Dll")]
public static extern void NewtonBodySetMatrix(int bodyPtr, ref Matrix matrix);
[DllImport("Newton.Dll")]
public static extern void NewtonBodySetOmega(int bodyPtr, ref Vector3 omega);
[DllImport("Newton.Dll")]
public static extern void NewtonBodySetForce(int bodyPtr, ref Vector3 force);
[DllImport("Newton.Dll")]
public static extern void NewtonUpdate(int newtonWorld, float timestep);
[DllImport("Newton.Dll")]
public static extern void NewtonBodyGetMatrix(int bodyPtr,ref Matrix matrix);

public static void NewtonBodySetUserData(int bodyPtr, Object o)
{
if (userData.ContainsKey(bodyPtr))
{
userData.Remove(bodyPtr);
}
userData.Add(bodyPtr, o);
}

public static Object NewtonBodyGetUserData(int bodyPtr)
{
return userData[bodyPtr];
}
[DllImport("Newton.Dll", CallingConvention =CallingConvention.StdCall)]
public static extern void NewtonBodySetTransformCallback(int bodyPtr, SetTransformCB cb);
[DllImport("Newton.Dll", CallingConvention = CallingConvention.StdCall)]
public static extern void NewtonBodySetForceAndTorqueCallback(int bodyPtr, SetForceAndTorqueCB cb);


}
}
Haddd
 
Posts: 35
Joined: Wed Mar 16, 2005 5:06 am

Postby The unProfessional » Sat Mar 19, 2005 8:56 pm

Might be dangerous to make it .net 2.0-only, since very few people are using it. As far as I know, only Whidbey compiles for it, right?
The unProfessional
 
Posts: 131
Joined: Sun May 02, 2004 9:08 pm
Location: Southern California

Postby Haddd » Sun Mar 20, 2005 5:27 am

I'm doing my engine with VC# express Beta and .NET 2.0. The problem with the delegates solves with 2.0 ( 3 days looking for a solution !!). But somebody can get the code and make a little trick to works in 1.0, if wants. I'm not fluid with Managed C++, but maybe the solution could be make a little little wrap for the callbacks the way you do. :D

I have the 3rd tutorial converted. Going for the 4th!! :D

When i have all tutorials converted, i will send the code to Newton to include, if they want of course, with the library. :D
Haddd
 
Posts: 35
Joined: Wed Mar 16, 2005 5:06 am

Postby SnprBoB86 » Sun Mar 20, 2005 1:36 pm

Haddd,

I actually took a stab at this myself recently. I was going to do a Object Oriented .NET 2.0 wrapper using Managed C++ 2.0 but ran into a "BadImageFormatException" both using DllImport and using MC++. Did you experiance any difficulty using the platform invoke mechinisms with .NET 2.0 and NGD?
SnprBoB86
 
Posts: 26
Joined: Mon Jan 24, 2005 5:53 pm

Postby Haddd » Sun Mar 20, 2005 2:58 pm

I'm developing a 3d engine for about 5 months with Visual C# express beta, and i have not found any problems. It's a great job from Microsoft.

I'm using Net 2.0, templates,...Working heavy with it and seems not to be any problems.

But i've found bugs with MDX, very important bugs. One of them was than can not be possible to work with MC++, but i think with the Febreary Edition you can work with it.

Maybe you can make the wrapper with C#...
Haddd
 
Posts: 35
Joined: Wed Mar 16, 2005 5:06 am

Postby SnprBoB86 » Mon Mar 21, 2005 7:00 pm

OK, I have a wrapper going in C# 2.0

Im avoiding .net 2.0 features, so the same code should compile for 1.0 or 1.1

I am not sure about the performance for c# interop vs mc++, but it shouldn't be a big deal. I'd be interested to see if anyone has links to an article on this, however.

I should have something to show within a few days. Expect a true .NET style class library.
SnprBoB86
 
Posts: 26
Joined: Mon Jan 24, 2005 5:53 pm

Postby The unProfessional » Mon Mar 21, 2005 7:55 pm

There's significant overhead with Interop, but I'm not sure what it amounts to in terms of performance differences :-\
The unProfessional
 
Posts: 131
Joined: Sun May 02, 2004 9:08 pm
Location: Southern California

Postby Haddd » Tue Mar 22, 2005 4:04 am

are you using my wrapper ?
Haddd
 
Posts: 35
Joined: Wed Mar 16, 2005 5:06 am

Postby SnprBoB86 » Tue Mar 22, 2005 2:36 pm

No, I am trying 2 build a wrapper thats actually a class library rather than a C-style set of functions.

I should have the basics of it all layed out by the end of the week, maybe then we can join forces and throw the project up on source forge.
SnprBoB86
 
Posts: 26
Joined: Mon Jan 24, 2005 5:53 pm

Postby Haddd » Tue Mar 22, 2005 3:34 pm

Well, i'm going to release the wrapper to public domain. I'm wrapping the C functions as i need, because i'm trying to make the tutorials work on the engine. I'm saving the tutorials on C# so people can see the wrapper working. :D
Haddd
 
Posts: 35
Joined: Wed Mar 16, 2005 5:06 am

Postby Haddd » Wed Mar 30, 2005 2:59 pm

Well, here is the wrapper by now. Use it at your own risk :D

Code: Select all
#region Using directives

using System;
using System.Collections;
using System.Text;

using System.Runtime.InteropServices; // DllImport
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

using Haddd.Scene;

#endregion

/*
ATENCION

Debo crear a veces 2 métodos diferentes, porque al esperar un float *, es posible
que se le pase un null desde la aplicación.
Si paso un null esperando como un parámetro ref Matrix, me da un error

[DllImport("Newton.Dll", EntryPoint = "NewtonCreateBox")]
public static extern int CreateBox(int newtonWorld, float dx, float dy, float dz, ref Matrix offsetMatrix);

[DllImport("Newton.Dll", EntryPoint = "NewtonCreateBox")]
public static extern int CreateBox(int newtonWorld, float dx, float dy, float dz, float[] matrix);
*/
namespace Haddd.Physics
{
    #region Delegates

    [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
    public delegate void SetTransformCB(int body, ref Matrix matrix);
    [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
    public delegate void SetForceAndTorqueCB(int body);
    [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
    public delegate void CreateTreeCollision(int bodyWithTreeCollision,int body,float[] vertex,int vertexstrideInBytes, int indexCount, int[] indexArray);
    [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
    public delegate int MaterialSetCollisionBegin(int material, int body0, int body1);
    [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
    public delegate int MaterialSetCollisionProcess(int material, int contact);
    [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
    public delegate void MaterialSetCollisionEnd(int material);
    [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
    public delegate void BodyLeaveWorld(int body);
    [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
    public delegate void BodyIterator(int body);
    [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
    public delegate void WorldRayFilter(int body);

    #endregion

    #region Wrapper

    public class NewtonWrapper
    {

        #region WorldInterface

        [DllImport("Newton.Dll",EntryPoint="NewtonCreate")]public static extern int Create(int a, int b);
        [DllImport("Newton.Dll", EntryPoint = "NewtonGetGlobalScale")]public static extern float GetGlobalScale(int newtonWorld);
        [DllImport("Newton.Dll", EntryPoint = "NewtonSetSolverModel")]public static extern void SetSolverModel(int a, int b);
        [DllImport("Newton.Dll", EntryPoint = "NewtonSetFrictionModel")]public static extern void SetFrictionModel(int a, int b);
        [DllImport("Newton.Dll", EntryPoint = "NewtonUpdate")]public static extern void Update(int newtonWorld, float timestep);
        [DllImport("Newton.Dll", EntryPoint = "NewtonWorldCollide ")]public static extern void WorldCollide(int newtonWorld, int maxSize,int collisionA,ref Matrix offsetA,int collisionB,ref Matrix offsetB,float[] contacts,float[] normals,float[] penetration);
        [DllImport("Newton.Dll", EntryPoint = "NewtonDestroy")]public static extern void Destroy(int newtonWorld);
        [DllImport("Newton.Dll", EntryPoint = "NewtonSetMinimumFrameRate")]public static extern void SetMinimumFrameRate(int newtonWorld, float frameRate);
        [DllImport("Newton.Dll", EntryPoint = "NewtonGetTimeStep ")]public static extern float GetTimeStep(int newtonWorld);
        [DllImport("Newton.Dll", EntryPoint = "NewtonDestroyAllBodies")]public static extern void DestroyAllBodies(int newtonWorld);
        [DllImport("Newton.Dll", EntryPoint = "NewtonSetWorldSize")]public static extern void SetWorldSize(int newtonWorld, ref Vector3 min,ref Vector3 max);
        [DllImport("Newton.Dll", EntryPoint = "NewtonSetBodyLeaveWorldEvent")]public static extern void SetBodyLeaveWorldEvent(int newtonWorld, BodyLeaveWorld cb);
        [DllImport("Newton.Dll", EntryPoint = "NewtonWorldFreezeBody ")]public static extern void WorldFreezeBody(int newtonWorld,int body);
        [DllImport("Newton.Dll", EntryPoint = "NewtonWorldUnfreezeBody ")]public static extern void WorldUnfreezeBody(int newtonWorld, int body);
        [DllImport("Newton.Dll", EntryPoint = "NewtonWorldForEachBodyDo")]public static extern void WorldForEachBodyDo(int newtonWorld, BodyIterator cb);
        [DllImport("Newton.Dll", EntryPoint = "NewtonGetVersion ")]public static extern int GetVersion(int newtonWorld);
        [DllImport("Newton.Dll", EntryPoint = "NewtonWorldSetUserData")]public static extern void WorldSetUserData(int bodyPtr, [MarshalAs(UnmanagedType.IUnknown)] Object o);
        [DllImport("Newton.Dll", EntryPoint = "NewtonWorldGetUserData")][return: MarshalAs(UnmanagedType.IUnknown)]public static extern Object WorldGetUserData(int bodyPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonWorldRayCast")]public static extern void WorldRayCast(int newtonWorld, ref Vector3 p0, ref Vector3 p1, WorldRayFilter cb, [MarshalAs(UnmanagedType.IUnknown)] Object userData);

        #endregion

        #region GroupID interface

        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialGetDefaultGroupID")]public static extern int MaterialGetDefaultGroupID(int newtonWorld);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialCreateGroupID")]public static extern int MaterialCreateGroupID(int newtonWorld);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialDestroyAllGroupID")]
        public static extern void MaterialDestroyAllGroupID(int newtonWorld);
       
        #endregion

        #region Material setup interface

        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialSetDefaultSoftness")]public static extern void MaterialSetDefaultSoftness(int newtonWorld, int id0, int id1, float softnessCoef);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialSetDefaultElasticity")]public static extern void MaterialSetDefaultElasticity(int newtonWorld, int id0, int id1, float elasticCoef);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialSetDefaultCollidable")]public static extern void MaterialSetDefaultCollidable(int newtonWorld, int id0, int id1, int state);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialSetDefaultFriction")]public static extern void MaterialSetDefaultFriction(int newtonWorld, int id0, int id1, float staticFriction,float kineticFriction);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialSetCollisionCallback")]public static extern void MaterialSetCollisionCallback(int newtonWorld, int id0, int id1, [MarshalAs(UnmanagedType.IUnknown)] Object UserData, MaterialSetCollisionBegin cb1, MaterialSetCollisionProcess cb2, MaterialSetCollisionEnd cb3);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialGetUserData ")]
        public static extern int MaterialGetUserData(int newtonWorld, int id0, int id1);
       
        #endregion

        #region Contact behavior control interface

        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialDisableContact")]
        public static extern void MaterialDisableContact(int materialHandle);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialGetMaterialPairUserData")]
        [return: MarshalAs(UnmanagedType.IUnknown)]
        public static extern Object MaterialGetMaterialPairUserData(int materialHandle);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialGetContactFaceAttribute")]
        public static extern uint MaterialGetContactFaceAttribute(int materialHandle);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialGetCurrentTimestep")]
        public static extern float MaterialGetCurrentTimestep(int materialHandle);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialGetContactNormalSpeed")]
        public static extern float MaterialGetContactNormalSpeed(int materialHandle, int contactHandle);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialGetContactTangentSpeed")]
        public static extern float MaterialGetContactTangentSpeed(int materialHandle, int contactHandle, int index);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialGetContactPositionAndNormal")]
        public static extern void MaterialGetContactPositionAndNormal(int materialHandle, ref Vector3 position, ref Vector3 normal);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialGetContactForce")]
        public static extern void MaterialGetContactForce(int materialHandle, ref Vector3 force);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialGetContactTangentDirections")]
        public static extern void MaterialGetContactTangentDirections(int materialHandle, ref Vector3 dir0, ref Vector3 dir1);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialGetBodyCollisionID")]
        public static extern uint MaterialGetBodyCollisionID(int materialHandle,int body);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialSetContactSoftness")]
        public static extern void MaterialSetContactSoftness(int materialHandle, float softness);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialSetContactElasticity")]
        public static extern void MaterialSetContactElasticity(int materialHandle, float restitution);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialSetContactFrictionState")]
        public static extern void MaterialSetContactFrictionState(int materialHandle, int state,int index);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialSetContactStaticFrictionCoef")]
        public static extern void MaterialSetContactStaticFrictionCoef(int materialHandle, float coef, int index);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialSetContactKineticFrictionCoef")]
        public static extern void MaterialSetContactKineticFrictionCoef(int materialHandle, float coef, int index);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialSetContactTangentAcceleration")]
        public static extern void MaterialSetContactTangentAcceleration(int materialHandle, float accel, int index);
        [DllImport("Newton.Dll", EntryPoint = "NewtonMaterialContactRotateTangentDirections")]
        public static extern void MaterialContactRotateTangentDirections(int materialHandle, ref Vector3 alignVector);

        #endregion

        #region Convex collision primitives interface

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateNull")]
        public static extern int CreateNull(int newtonWorld, float dx, float dy, float dz, ref Matrix offsetMatrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateBox")]
        public static extern int CreateBox(int newtonWorld, float dx, float dy, float dz, ref Matrix offsetMatrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateBox")]
        public static extern int CreateBox(int newtonWorld, float dx, float dy, float dz, float[] matrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateSphere")]
        public static extern int CreateSphere(int newtonWorld, float rx, float ry, float rz, ref Matrix offsetMatrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateSphere")]
        public static extern int CreateSphere(int newtonWorld, float rx, float ry, float rz, float[] matrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateCone")]
        public static extern int CreateCone(int newtonWorld, float radius, float height, ref Matrix offsetMatrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateCone")]
        public static extern int CreateCone(int newtonWorld, float radius, float height, float[] matrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateCapsule")]
        public static extern int CreateCapsule(int newtonWorld, float radius, float height, ref Matrix offsetMatrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateCapsule")]
        public static extern int CreateCapsule(int newtonWorld, float radius, float height, float[] matrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateCylinder")]
        public static extern int CreateCylinder(int newtonWorld, float radius, float height, ref Matrix offsetMatrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateCylinder")]
        public static extern int CreateCylinder(int newtonWorld, float radius, float height, float[] matrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateChamferCylinder")]
        public static extern int CreateChamferCylinder(int newtonWorld, float radius, float height, ref Matrix offsetMatrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateChamferCylinder")]
        public static extern int CreateChamferCylinder(int newtonWorld, float radius, float height, float[] matrix);

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateConvexHull")]
        public static extern int CreateConvexHull(int newtonWorld, int count, float[] vertexCloud, int strideInBytes,ref Matrix offsetMatrix);
        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateConvexHullModifier")]
        public static extern int CreateConvexHullModifier(int newtonWorld, int convexHullCollision);
        [DllImport("Newton.Dll", EntryPoint = "NewtonConvexHullModifierGetMatrix ")]
        public static extern void ConvexHullModifierGetMatrix(int convexHullCollision, ref Matrix matrix);
        [DllImport("Newton.Dll", EntryPoint = "NewtonConvexHullModifierSetMatrix ")]
        public static extern void ConvexHullModifierSetMatrix(int convexHullCollision, ref Matrix matrix);
        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateCompoundCollision")]
        public static extern int CreateCompoundCollision(int newtonWorld, int count, int[] collisionPrimitiveArray);
        [DllImport("Newton.Dll", EntryPoint = "NewtonConvexCollisionSetUserID")]
        public static extern void ConvexCollisionSetUserID(int newtonWorld, uint id);
        [DllImport("Newton.Dll", EntryPoint = "NewtonConvexCollisionGetUserID")]
        public static extern uint ConvexCollisionSetUserID(int newtonWorld);

        #endregion

        #region Complex collision primitives interface

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateTreeCollision")]
        public static extern int CreateTreeCollision(int bodyPtr, CreateTreeCollision cb);
        [DllImport("Newton.Dll", EntryPoint = "NewtonTreeCollisionBeginBuild")]
        public static extern void TreeCollisionBeginBuild(int treeCollision);
        [DllImport("Newton.Dll", EntryPoint = "NewtonTreeCollisionAddFace")]
        public static extern void TreeCollisionAddFace(int bodyPtr, int vertexCount, float[] vertexPtr, int strideInBytes, int faceAttribute);
        [DllImport("Newton.Dll", EntryPoint = "NewtonTreeCollisionEndBuild")]
        public static extern void TreeCollisionEndBuild(int treeCollision, int optimize);
        [DllImport("Newton.Dll", EntryPoint = "NewtonTreeCollisionGetFaceAtribute")]
        public static extern void TreeCollisionGetFaceAtribute(int treeCollision, int[] faceIndexArray);

        #endregion

        #region  Collision miscellaneous interface

        [DllImport("Newton.Dll", EntryPoint = "NewtonReleaseCollision")]public static extern void ReleaseCollision(int newtonWorld, int collisionPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonCollisionCalculateAABB")]public static extern void CollisionCalculateAABB(int collisionPtr, ref Matrix offsetMatrix,ref Vector3 min,ref Vector3 max);
        [DllImport("Newton.Dll", EntryPoint = "NewtonCollisionRayCast")]
        public static extern float CollisionRayCast(int collisionPtr, ref Vector3 p0, ref Vector3 p1,ref Vector3 Normal,int[] attribute);

        #endregion

        #region  Transform utility functions

        [DllImport("Newton.Dll", EntryPoint = "NewtonGetEulerAngle ")]
        public static extern void GetEulerAngle(ref Matrix matrix,ref Vector3 angles);
        [DllImport("Newton.Dll", EntryPoint = "NewtonSetEulerAngle ")]
        public static extern void SetEulerAngle(ref Matrix matrix, ref Vector3 angles);

        #endregion

        #region Rigid body interface

        [DllImport("Newton.Dll", EntryPoint = "NewtonCreateBody")]
        public static extern int CreateBody(int newtonWorld, int collisionPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetUserData")]
        public static extern void BodySetUserData(int bodyPtr, [MarshalAs(UnmanagedType.IUnknown)] Object o);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetUserData")]
        [return: MarshalAs(UnmanagedType.IUnknown)]
        public static extern Object BodyGetUserData(int bodyPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetWorld")]
        public static extern int BodyGetWorld(int bodyPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetTransformCallback")]
        public static extern void BodySetTransformCallback(int bodyPtr, SetTransformCB cb);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetForceAndTorqueCallback")]
        public static extern void BodySetForceAndTorqueCallback(int bodyPtr, SetForceAndTorqueCB cb);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetMassMatrix")]
        public static extern void BodySetMassMatrix(int bodyPtr, float mass, float Ixx, float Iyy, float Izz);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetMassMatrix")]
        public static extern void BodyGetMassMatrix(int bodyPtr, out float mass, out float Ixx, out float Iyy, out float Izz);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetInvMass")]
        public static extern void BodyGetInvMass(int bodyPtr, out float mass, out float Ixx, out float Iyy, out float Izz);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetMatrix")]
        public static extern void BodySetMatrix(int bodyPtr, ref Matrix matrix);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetMatrixRecursive")]
        public static extern void BodySetMatrixRecursive(int bodyPtr, ref Matrix matrix);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetMatrix")]
        public static extern void BodyGetMatrix(int bodyPtr, ref Matrix matrix);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetForce")]
        public static extern void BodySetForce(int bodyPtr, ref Vector3 force);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyAddForce")]
        public static extern void BodyAddForce(int bodyPtr, ref Vector3 force);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetForce")]
        public static extern void BodyGetForce(int bodyPtr, ref Vector3 force);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetTorque")]
        public static extern void BodySetTorque(int bodyPtr, ref Vector3 torque);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyAddTorque")]
        public static extern void BodyAddTorque(int bodyPtr, ref Vector3 torque);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetTorque")]
        public static extern void BodyGetTorque(int bodyPtr, ref Vector3 torque);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetTotalVolume")]
        public static extern float BodyGetTotalVolume(int bodyPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyAddBuoyancyForce")]
        public static extern void BodyAddBuoyancyForce(int bodyPtr,float fluidDensity,float fluidLinearViscosity,float fluidAngularViscosity,float[] gravityVector,int buoyancyPlane);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetCollision")]
        public static extern void BodySetCollision(int bodyPtr, int collision);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyCoriolisForcesMode")]
        public static extern void BodyCoriolisForcesMode(int bodyPtr, int mode);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetCollision")]
        public static extern int BodyGetCollision(int bodyPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetMaterialGroupID")]
        public static extern void BodySetMaterialGroupID(int bodyPtr, int materialID);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetMaterialGroupID")]
        public static extern int BodyGetMaterialGroupID(int bodyPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetJointRecursiveCollision")]
        public static extern void BodySetJointRecursiveCollision(int bodyPtr, int state);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetJointRecursiveCollision")]
        public static extern int BodyGetJointRecursiveCollision(int bodyPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetAutoFreeze")]
        public static extern void BodySetAutoFreeze(int bodyPtr, int state);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetAutoFreeze")]
        public static extern int BodyGetAutoFreeze(int bodyPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetSleepingState")]
        public static extern int NewtonBodyGetSleepingState(int bodyPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetFreezeTreshold")]
        public static extern void BodySetFreezeTreshold(int bodyPtr, float freezeSpeedMag2, float freezeOmegaMag2, int framesCount);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetFreezeTreshold")]
        public static extern void BodyGetFreezeTreshold(int bodyPtr, ref float freezeSpeedMag2, ref float freezeOmegaMag2);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetAABB")]
        public static extern void BodyGetAABB(int bodyPtr, ref Vector3 min,ref Vector3 max);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetVelocity")]
        public static extern void BodySetVelocity(int bodyPtr, ref Vector3 velocity);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetVelocity")]
        public static extern void BodyGetVelocity(int bodyPtr, ref Vector3 velocity);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetOmega")]
        public static extern void BodySetOmega(int bodyPtr, ref Vector3 omega);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetOmega")]
        public static extern void BodyGetOmega(int bodyPtr, ref Vector3 omega);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetLinearDamping")]
        public static extern void NewtonBodySetLinearDamping(int bodyPtr, float linearDamp);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetLinearDamping")]
        public static extern float NewtonBodyGetLinearDamping(int bodyPtr);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodySetAngularDamping ")]
        public static extern void BodySetAngularDamping(int bodyPtr, ref Vector3 angularDamp);
        [DllImport("Newton.Dll", EntryPoint = "NewtonBodyGetAngularDamping")]
        public static extern void BodyGetAngularDamping(int bodyPtr, ref Vector3 angularDamp);
        [DllImport("Newton.Dll", EntryPoint = "NewtonAddBodyImpulse")]
        public static extern void AddBodyImpulse(int bodyPtr, ref Vector3 pointDeltaVeloc, ref Vector3 pointPosit);

        #endregion


    }
    #endregion
}
Haddd
 
Posts: 35
Joined: Wed Mar 16, 2005 5:06 am

Postby The unProfessional » Wed Mar 30, 2005 11:00 pm

It's nice being able to DLLImport everything. With .NET 1.0/1.1, we couldn't, because it didn't support the c calling convention. Hopefully Whidbey will make it out soon.
The unProfessional
 
Posts: 131
Joined: Sun May 02, 2004 9:08 pm
Location: Southern California

Next

Return to User Gallery

Who is online

Users browsing this forum: No registered users and 4 guests

cron