Share with us how are you using the powerrrr of the force
Moderator: Alain
by SnprBoB86 » Fri Mar 25, 2005 7:54 pm
I've got a decent portion of my Newton.NET library done. It's writen with Managed C++ 2.0 and hence requires the .NET 2.0 beta framework to run. Unlike the existing .NET wrappers, it is a true .NET managed class library (like the Newton++ library)
Below is what the second tutorial looks like with my new wrapper. I intend to publish the other tutorials as well as the wrapper source soon. Let me know what you guys think.
- Code: Select all
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Newton;
namespace Tutorials
{
public class Tutorial1 : Tutorial
{
World world;
Body body;
Mesh box;
protected override void InitializeGraphics()
{
base.InitializeGraphics();
this.box = Mesh.Box(this.renderDevice, 2.0f, 2.0f, 2.0f);
this.box.ComputeNormals();
}
protected override void InitializePhysics()
{
this.world = new World();
using (Collision collision = new BoxCollision(world, 2.0f, 2.0f, 2.0f))
{
this.body = new Body(collision);
this.body.SetMassMatrix(1.0f, 1.0f, 1.0f, 1.0f);
this.body.TransformMatrix = NewtonHelpers.ToFloatArray(Matrix.Translation(0.0f, 0.0f, 0.0f));
this.body.AngularVelocity = new float[] { 1.0f, 1.0f, 1.0f };
}
}
protected override void Simulate()
{
world.Update(0.01f);
}
protected override void RenderBodies()
{
this.renderDevice.Transform.World = NewtonHelpers.ToMatrix(body.TransformMatrix);
this.box.DrawSubset(0);
}
}
}
-
SnprBoB86
-
- Posts: 26
- Joined: Mon Jan 24, 2005 5:53 pm
by Haddd » Mon Mar 28, 2005 10:51 am
Hi, good job, i'm doing the same, but i'm converting tutorial 5 now!!
Well, 2 thinks...
this.world = new World();
using (Collision collision = new BoxCollision(world, 2.0f, 2.0f, 2.0f))
I put "world" into a global variable and any time i need it, i take it from there. Dou you really need the parameter world?
Isn't it bettet this way ?
using (Collision collision = new BoxCollision( 2.0f, 2.0f, 2.0f))
That's the way i do.
The second one i want to put your attention in...
this.body.TransformMatrix = NewtonHelpers.ToFloatArray(Matrix.Translation(0.0f, 0.0f, 0.0f));
do you now that the marshal automatically converts it for you ?
Look at this piece of code:
dllimport[....]
static extern void NewtonSetMatrix(int word, ref Matrix)
and the implementation:
Matrix m=Matrix.Identity;
NewtonSetMatrix(world,ref m);
I hope this comments will help you!!!
-
Haddd
-
- Posts: 35
- Joined: Wed Mar 16, 2005 5:06 am
by SnprBoB86 » Mon Mar 28, 2005 11:33 am
Thanks Haddd,
The world global is a nice idea, but it removes the ability to have more than one Newton world. While that isn't a major common user need from what I understand, it makes no sense to remove a freature just to save a single method parameter.
As for the automatic marshalling, I am aware of this. My library is MC++ and therefore I must manually marshal objects. I could quiet simply provide an overload that accepts a DirectX.Matrix and uses a pin pointer just as the automatic C# marshaller would do, but I am trying 2 avoid a dependancy on DirectX. I am trying to figure out a performant way to eliminate the manual conversion while not creating a dependancy on MDX.
Maybe you and I should join forces?
-
SnprBoB86
-
- Posts: 26
- Joined: Mon Jan 24, 2005 5:53 pm
by Haddd » Tue Mar 29, 2005 4:58 am
I'm going to release the code to the public domain. It's C# and should be very very easy to read. But i will publish only the wrapper, because the classes will be focused on my own engine.
-
Haddd
-
- Posts: 35
- Joined: Wed Mar 16, 2005 5:06 am
Return to User Gallery
Who is online
Users browsing this forum: No registered users and 1 guest