Mogrenewt 2.0 [Binary on first post]

GantZ

05-02-2009 17:51:25

The mogrenewt 2.0 source related to the newton 2.0 version are available on bitbucket here :
http://bitbucket.org/mogre/mogreaddons/src/tip/MogreNewt/

keep in mind that newton 2.0 still in beta, so the wrapper is subject to changes.

Update 26.10.2010 :

here a binary of the latest version. compiled against Mogre 1.7.1 and Newton 2.25. the newton library is included within the MogreNewt dll, so you don't need to download it separately.

The SDK is required if you want to compile it from source : http://newtondynamics.com/forum/downloads.php

[attachment=0]MogreNewt.zip[/attachment]

Original Post :

Hi,

i was wondering if someone plan to update mogrenewt to the last newton version. Since i need the possibility to use only the collision detection of newton, i was thinking of upgrading, but after checking the change made on ogrenewt here http://www.ogre3d.org/addonforums/viewtopic.php?f=4&t=9020 , and do some test on the last mogrenewt version, i have understand that it will need more time and work that i have expected at first. :)

i will probably try to update it later. so, if someone have already start to port it or plan to do it later, we could join our work

Beauty

18-02-2009 14:15:30

Newton 2.0 is still only a beta version, unpublished, but generally ready (as I read).
So we could update the wrapper and it should be compatible with the upcoming official release version.

I tried to update the MogreNewt wrapper, but had big problems, because I don't know C++. (The thread is here)
Then Bekas helped me and made the wrapper working with the new Newton library.

BUT this update is only releated to collision detection. (Newton 2 has nice improvements.)
Inside of Body and Collision class not all functions are updated.
Some other classes I completely removed (e.g. physically things).

So it could be a good start point for updating, because you can compile it without errors.
In my application it works fine.
Give me your e-mail address and I'll send you the wrapper and a simple test application.


update:

MogreNewt is similar to OgreNewt.
Maybe it could help you to make the update.
OgreNewt is maintained by Walaber.
Here you can download a OgreNewt version for 2.0.
If you need the current version, ask Walaber.

Maybe also this wiki page helps you:
http://www.ogre3d.org/wiki/index.php/Co ... ith_Newton

GantZ

18-02-2009 18:41:40

thanks for your answer, i will give it a go next week, so having a working version will greatly help me

i haven't noticed the thread you have mention before (i haven't search enough :oops: ), i will post any update/question i have on your thread to prevent having multiple thread for the same thing.

Give me your e-mail address and I'll send you the wrapper and a simple test application.
pm sent !

Beauty

25-03-2009 16:47:21

The great GantZ made a complete update of MogreNewt for Newton 2.0.
More information he'll post soon.
Also he aked to get write access to the related SVN. The code will be available there.
If you need it immediatelly, just ask GantZ.

GantZ

26-03-2009 11:36:54

About the Wrapper

I have finally commit my code to the mogre svn :
https://mogre.svn.sourceforge.net/svnro ... /MogreNewt

for this release you will need the newton version available here :
http://www.newtondynamics.com/forum/vie ... f=9&t=4922

keep in mind that newton 2.0 is still in beta. for the moment, it's better to use the 1.53 stable release until a final version of newton 2.0 is out.

you can access the source code of the previous mogrenewt version here :
https://mogre.svn.sourceforge.net/svnro ... eNewt-1.53

What new

here the main modification i have made (other than update the wrapper), some based on the ogrenewt2 version on the ogre svn :
- Debugger now draws objects color coded based on mass (grey = static, bright blue = dynamic and awake, dull blue = dynamic and asleep)
- Debugger class can now also draw all contacts between bodies as well.
- MomentOfInertia namespace and helper functions removed entirely. Newton can now calculate inertia and center of
mass automatically, use ConvexCollision.calculateInertialMatrix, and multiply by objects Mass.
- Body.AttachToNode has been renamed to AttachNode, better implying the relationship between the body and the Mogre.Node.
- removed the freeze function , autosleep replace autofreeze, IsAsleep replace freeze(), unfreeze() functions
- vehicule and tire class not working atm due to change on newton
- adding files OgreNewt_CollisionSerializer.h and .cpp
- removing treecollision serializer files due to deletion of the associated newton functions

bugs / problems i have encountered

debugger : using showlines and showcontacts at the same time does not work (the functions alone work)
warning at compile time : ogre_newtjoint : c4677 : http://msdn.microsoft.com/en-us/library/0wb44ssy.aspx
it something that lies with the jointdestructor function, don't know if it's a problem or not

Example

the first sample application as been updated, you can use it to see some of the change of the wrapper
https://mogre.svn.sourceforge.net/svnro ... /Basics.cs

feel free to test it and give me a feedback :wink:

Beauty

26-03-2009 13:24:02

In an old MogreNewt thread I made bug report, but this is some months ago.
So I repeat it here. If the problem is still there, it would be nice if it will be fixed.

The MogreNewt code of MogreNewt::CollisionPrimitives::ConvexHull in file OgreNewt_Body.cpp should be extended.
This also can be done for the current MogreNewt sources (related to Newton 1.53).

Problem 1:
Only the first attached entity will be handled.
Better: add vertices of all attached entities

Problem 2:
If the entity is a ManualObject there comes an exception.
This should be fixed.

Debugger class can now also draw all contacts between bodies as well.
Does we have to enable this functionality? If yes, please tell how to do.

Beauty

26-03-2009 17:55:46

In the archive of Newton2 are 4 directories with a newton.dll file.
What is the difference and which we should use?
dll_double_vs7
dll_double_vs9
dll_vs7
dll_vs9

Zero23

26-03-2009 18:18:11

Hi

The VS is the Version number of Visual Studio. For 2005 use the vs 7 too.
And I think the "double" stands for double precision, when you activate them.

Zero

Beauty

26-03-2009 18:20:19

MomentOfInertia namespace and helper functions removed entirely.
Strange - the method Body.SetMassMatrix() still needs the parameters mass and internia.
The internia was created by MomentOfInertia() (in my application).
Is the second param wrong or how to get it?

I hope this will make no trouble for my collision detection (which doesn't use physics functionality).
Because without definition of Body.SetMassMatrix() it doesn't work in my old 2.0 beta nor in Newton 1.53. (although I don't understand why a mass is needed for collision detection)


colHull = new MogreNewt.CollisionPrimitives.ConvexHull(nWorld, targetNode, collisionHullTolerance);
The tolerance param seems to be removed. Did you do it or was it an API change?
(This was new for Newton 2, but my last used wrapper + Newton beta is about 6 months old.)


The class ContactJoint seems not been implemented.

Also this member:
Body.ContactJointEnumerator
Body.GetContactJoints()

--> GantZ: you can look into my partially updated wrapper for this

So I can't use/test it with my application. :(

Zero23

26-03-2009 18:48:43

I dont know that is in the Mogre-Wrapper but in OgreNewt there is for "MomentOfInertia()" in the class "ConvexCollision" the function "calculateInertialMatrix"
with them you can calculate them.

And thank you for this with the ConvexHull^^ In OgreNewt there is that "0.001f", but I will fix this there ;)

Zero

GantZ

26-03-2009 21:02:17


Debugger class can also draw all contacts between bodies as well. .
Does we have to enable this functionality? If yes, please tell how to do.


use Debugger.Instance.ShowContacts, it work like the showlines function


Strange - the method Body.SetMassMatrix() still needs the parameters mass and internia.
The internia was created by MomentOfInertia() (in my application).
Is the second param wrong or how to get it?


as Zero23 say, you have to use the function calculateInertialMatrix of the class convexcollision (instead of collision like it was before), this function give you the inertia. after that, you have to multiply the inertia by the mass


The class ContactJoint seems not been implemented.

the class was not implemented in the ogrenewt version i have used as a basis. since it have been added now, i will implement it along with the other change from the ogrenewt svn version.


Body.ContactJointEnumerator
Body.GetContactJoints()


i haven't find this function in the original ogrenewt wrapper, i will check the newton doc and your application for that.


So I can't use/test it with my application. :(

i will use the sample you have send to me to test next time, this way it should be ok :wink:

Beauty

26-03-2009 22:39:50

i haven't find this function in the original ogrenewt wrapper, i will check the newton doc and your application for that.
I looked to my MOD wrapper. (so I call the partially updated wrapper I use for my collision detection case)
In the file OgreNewt_Body.h there was added this code:


public ref class Body
{
public:
// ...

value class ContactJointEnumerator sealed : Collections::Generic::IEnumerator<ContactJoint>
{
const ::NewtonBody* _body;
NewtonJoint* _current;

public:
ContactJointEnumerator(Body^ body);

virtual bool MoveNext();

property ContactJoint Current
{
virtual ContactJoint get();
}
property Object^ NonGenericCurrent
{
private: virtual Object^ get() sealed = Collections::IEnumerator::Current::get
{
return Current;
}
}

virtual void Reset() {
_current = (NewtonJoint*)-1;
}
};


value class ContactJointsEnumerable : Collections::Generic::IEnumerable<ContactJoint>
{
Body^ m_body;

public:
ContactJointsEnumerable(Body^ body) : m_body(body) {}

private: virtual Collections::IEnumerator^ NonGenericGetEnumerator() sealed = Collections::IEnumerable::GetEnumerator
{
return ContactJointEnumerator(m_body);
}
public: virtual Collections::Generic::IEnumerator<ContactJoint>^ GetEnumerator()
{
return ContactJointEnumerator(m_body);
}
};


property ContactJointsEnumerable ContactJoints {
ContactJointsEnumerable get() {
return ContactJointsEnumerable(this);
}
}

// ...
} // class Body


OgreNewt_Body


Body::ContactJointEnumerator::ContactJointEnumerator(Body^ body) {
_body = body->NewtonBody;
Reset();
}

bool Body::ContactJointEnumerator::MoveNext() {
if (_current == (NewtonJoint*)-1) {
_current = NewtonBodyGetFirstContactJoint(_body);
}
else {
if (_current != NULL)
_current = NewtonBodyGetNextContactJoint( _body, _current);
}

return (_current != NULL);
}

ContactJoint Body::ContactJointEnumerator::Current::get()
{
return ContactJoint(_current);
}


And in the file OgreNewt_World.h we added this code:


public ref class World
{
public:
// ...
value class BodyEnumerator : Collections::Generic::IEnumerator<Body^>
{
const NewtonWorld* _world;
NewtonBody* _current;

internal:
BodyEnumerator(const NewtonWorld* world) : _world(world) {
Reset();
}

public:
BodyEnumerator(World^ world);

virtual bool MoveNext();

property Body^ Current
{
virtual Body^ get();
}
property Object^ NonGenericCurrent
{
private: virtual Object^ get() sealed = Collections::IEnumerator::Current::get
{
return Current;
}
}

virtual void Reset() {
_current = (NewtonBody*)-1;
}
};

value class BodiesEnumerable : Collections::Generic::IEnumerable<Body^>
{
World^ m_World;

public:
BodiesEnumerable(World^ world) : m_World(world) {}

private: virtual Collections::IEnumerator^ NonGenericGetEnumerator() sealed = Collections::IEnumerable::GetEnumerator
{
return BodyEnumerator(m_World);
}
public: virtual Collections::Generic::IEnumerator<Body^>^ GetEnumerator()
{
return BodyEnumerator(m_World);
}
};


property BodiesEnumerable Bodies {
BodiesEnumerable get() {
return BodiesEnumerable(this);
}
}

//! update the bodies that have change position in the multigrid (without updating the physics world)
/*!
CollisionUpdate is useful for using the Newton collision detection independent of Newton physic.
So the internally state will be updated when body positions did change by MogreNewt.Body.SetPositionOrientation().
Bodies/Collisions moved by SetPositionOrientation() maybe will not give a contact feedback.
*/
void CollisionUpdate();
// ...
}


OgreNewt_World.cpp


World::BodyEnumerator::BodyEnumerator(World^ world) {
_world = world->NewtonWorld;
Reset();
}

bool World::BodyEnumerator::MoveNext() {
if (_current == (NewtonBody*)-1) {
_current = NewtonWorldGetFirstBody(_world);
}
else {
if (_current != NULL)
_current = NewtonWorldGetNextBody( _world, _current);
}

return (_current != NULL);
}

Body^ World::BodyEnumerator::Current::get()
{
if (_current == NULL)
return nullptr;
return static_cast<BodyNativeInfo*>( NewtonBodyGetUserData( _current ) )->managedBody;
}



void World::CollisionUpdate()
{
NewtonCollisionUpdate( m_world );
}


Maybe it helps you?
Also I need the method World.CollisionUpdate(). Maybe it's implemented in your code? I don't remember. If not, the source code for this you see in the snippits above, too.

I'm not shure, if I did send you my MOD wrapper or only the test application.
So here I uploaded it again. (I hope this was the most recent version.)
http://beauty.online.de/pub/MogreNewt_MOD_Bekas.rar

Also I don't remember if the test application use the ContactJointEnumerator. (I think this method was commented out in the code)

The ContactJointEnumerator is new in Newton 2. Julio (the author of Newton) told me about. The advantage for this is, that you can query only one object for contacts. This is very fast if you need infos for just a few objects. So Newton doesn't check all objects for collision, what can be very CPU intensive if you have many movings objects.



For Debugger.Instance.ShowContacts and Debugger.Instance.ShowLines it would be nice if you add a method with wich you can set the colour for the 3 states.
For example Debugger.Instance.SetColour(Enum lineType, Vector3 colour) - Vector3 for RGB.


By the way - as you write, it seems so that you ported again OgreNewt (instead of updating the old MogreNewt code). Is this right? Or is the code so similar that this makes no difference?

Beauty

26-03-2009 23:50:52

I looked to my test application now.

The interesting code is in method Scene_FrameStarted(...)

I made a copy of this application.
The second one is for Iterator, but I don't understand, why VisualStudio doesn't compile. It says there is a depency problem, although it works for the first copy. Also refreshing the dll links doesn't work.

In the class Program is a very simple test code of Bekas (without graphical output).

Here cloned my test application. So there are 3 versions of it with each an other way.
Sorry, 2 of them are not runnable now. But I have to go to bed now.
Maybe it helps you to check it.
http://beauty-of-darkness.de/pub/Collis ... _types.rar

GantZ

27-03-2009 12:42:42

i have just commit new change to the svn, here the changelog :

- remove warning message of the joint destructor
- add using Beauty/Bekas source the files contactjoint contactmaterial and material
- modify the contact callback to use contactjoint instead contactiterator
- remove contactiterator class
- add tolerance parameter to convexhull class
- remove (comment) function showcontacts in debugger because of deletion of ContactIterator class, change will be made soon on the debugger class
TODO : a lot of change have occured in the debugger class of ogrenewt, this class need to be remade
- add in body class property ContactJoints from Beauty/Bekas source
- add in world class property Bodies from Beauty/Bekas source
- add BodiesEnumerable in world class
- add ContactJointEnumerator in body class

i have test the new dll with your sample applications, and it compile and run ok. still, please check on your side to see if you get the desired result.


By the way - as you write, it seems so that you ported again OgreNewt (instead of updating the old MogreNewt code). Is this right? Or is the code so similar that this makes no difference?


i have used the source code straight from the mogre svn (1.53), and use one of the early ogrenewt 2.0 versions. it is why a lot of code is missing since i haven't implement all the change of newton 2.0 apart for the most obvious one.


For Debugger.Instance.ShowContacts and Debugger.Instance.ShowLines it would be nice if you add a method with wich you can set the colour for the 3 states.
For example Debugger.Instance.SetColour(Enum lineType, Vector3 colour) - Vector3 for RGB.


the debugger class have greatly change on the current ogrenewt version, from seeing the source, it seem possible to change the color of a specific material (haven't check for the state). i will port that later.

Bekas

27-03-2009 13:12:56


- add using Beauty/Bekas source the files contactjoint contactmaterial and material
- modify the contact callback to use contactjoint instead contactiterator
- remove contactiterator class
- add tolerance parameter to convexhull class
- remove (comment) function showcontacts in debugger because of deletion of ContactIterator class, change will be made soon on the debugger class

Hi GantZ,

Just want to mention that I added these classes without looking at the source code of OgreNewt 2.0, so if they need to be adapted for better compatibility with OgreNewt, you are more than welcome to modify them.
But I would strongly suggest to keep the Enumerator/Enumerable idiom instead of a custom ContactIterator class; this is a very useful and widely used idiom in the .NET world (i.e. C#'s 'foreach').

Beauty

27-03-2009 13:55:40

Thanks for the updates. I'll check it.
Do you know, why my test application "Collision by Iterator" did not compile on my computer?
Also I can clean up the code and offer it as public demo, what can help other people.


it seem possible to change the color of a specific material (haven't check for the state).
Yes, you are right - it's just a material. So it can be changed the common way.
On the other hand it would be more simple to just call a method of the debugger.

Suggestion:
Debugger.Instance.SetColour(Enum lineType, Vector3 colour)
--> change the colour of the default material(s) of Debugger
Debugger.Instance.SetColour(Enum lineType, String materialName)
--> use a self defined material for the line type

Here you can see how to create material by code:
http://www.ogre3d.org/wiki/index.php/MOGRE_Line_3D
http://www.ogre3d.org/wiki/index.php/Line3D
How to create (transparent) surfaces you can see here:
http://www.ogre3d.org/wiki/index.php/Cr ... with_MOGRE


remove warning message of the joint destructor
You could send warning messages to the Ogre log.
In the wiki I wrote how to do that (look here).

Beauty

27-03-2009 15:00:07

I'm to stupid to compile C++ projects.
I added the wanted pathes and depencies to the project properties and linker field, but still get errors :(
After I fixed some problems, now there is a one, about which I have no idea.
It's something about "can't find path" and "error in post build event", but without more information. Now I don't know what to do now. Maybe start again from the basic source?
I could ask you for a compiled dll file, but it would be better if I can do it myself in the future.
What a shit - somehow I hate C++
... ok, I know it's my own stupidness

Beauty

27-03-2009 15:33:20

There is an include directory for C/C++
C:\Program Files (x86)\NewtonSDK\sdk

What is the target?
The 2.00 beta has different subdirectories.
And the content of 2.00 beta is different to the NewtonSDK (only available for Newton 1.x )
* [Newton 2.0.rar]/sdk
* [Newton 2.0.rar]/sdk/x32
* [Newton 2.0.rar]/sdk/x32/dll_vs7
* [Newton 1 SDK]/sdk (??)
Which files are expected in the target directory?


Related to the additionally linker libraries - there is a path for
..\..\Mogre\ogrenew\lib
But there is no lib directory in Mogre\ogrenew.
Or does I have to compile Mogre before I can compile MogreNewt?
... for me it's looking like more personal trouble :evil:

Also for linker libraries there is a path for
c:\program files (x86)\NewtonSDK\sdk\dll
Shall I replace it with
[Newton 2.0.rar]/sdk/x32/dll_vs7 (for VS 2005) ?

Beauty

27-03-2009 15:41:22

I made some new tries.
Now the compiler tells: Assembly "Mogre.dll" not found
But I did update the reference to this file.

smiley80

27-03-2009 16:17:55

Great job, GantZ!

Here's a binary of the latest revision:
(Release config, linked against 'x32\dll_vs9')

GantZ

27-03-2009 16:35:57


Great job, GantZ!
Here's a binary of the latest revision:
(Release config, linked against 'x32\dll_vs9')


thanks, this is greatly appreciated :)


@ Beauty

configuration of c++ project could be tricky some time, my main advice here is to double check all you path and the properties of the project as well as the general options of visual studios (tools > options > solutions and project > VC++ directory)

the directory \NewtonWin-2.00\sdk\ contains the include file
for the lib files i use \NewtonWin-2.00\sdk\x32\dll_vs9 (i suppose it's vs 7 if you use the 2005 version )

Beauty

27-03-2009 16:55:35

Thanks.
Now I only have one error in my target application.

Code:
Body.ContactJointEnumerator cen = body.GetContactJoints();
Error:
"MogreNewt.Body" has no definition for"GetContactJoints"

So I tried this:
Body.ContactJointEnumerator cen = body.ContactJoints;
Error:
An implicite conversion from type MogreNewt.Body.ContactJointsEnumerable
to MogreNewt.Body.ContactJointEnumerator is not possible


@GantZ
Now I see - my target application use VS 2005, but the wrapper code was opened in VS 2008. So maybe I choosed the wrong path.


..\..\Mogre\ogrenew\lib
Can somebody give me the needed files for this directory, please? I suppose this will created by compiling Mogre, but I don't want to get trouble with this, too. My e-mail-Address is beautyod at gmx.de

GantZ

27-03-2009 17:59:49

try this

Body.ContactJointEnumerator cen = (Body.ContactJointEnumerator)body.ContactJoints.GetEnumerator();



..\..\Mogre\ogrenew\lib
Can somebody give me the needed files for this directory, please? I suppose this will created by compiling Mogre, but I don't want to get trouble with this


you can find the file needed directly in the Mogresdk in the Lib directory, you don't need to rebuild mogre.

Bekas

27-03-2009 18:42:21

How about

foreach (ContactJoint joint in body.ContactJoints) {
.....
}

Beauty

28-03-2009 05:21:33

@Bekas
Foreach is fine, but I'm a little bit afrait that it costs more CPU time.
My application needs high performance, because this will be called in very short intervals.

@GantZ
I'll try it later. Now I'm ready with my second job (disco) and will go to be.

Generally it would be nice to have XML comments to make the life more easy.
They could be taken from a Newton API help page. This is still available only for Newton 1, but many functions are similar (I suppose).
Such things I could do without C++ knowledge.
... or wait - the wrapper is written in C++. Are there XML comments possible?

Beauty

30-03-2009 02:21:50

Now I can compile and run.
But the collision detection doesn't work.

Body.ContactJointEnumerator cen = (Body.ContactJointEnumerator)body.ContactJoints.GetEnumerator();
cen.Reset();
while (cen.MoveNext()) // ALWAYS FALSE
{
ContactJoint joint = cen.Current;
// ...
}


Also by using foreach (ContactJoint joint in body.ContactJoints) { ... }
the loop never will be entered.

After moving a body I use World.CollisionUpdate(); to tell the Newton system that something has changed. Is this method also fully implemented?

Well, I will add this code to my test application. So it's more easy for you to find out the reason.

GantZ

30-03-2009 11:23:27

i have test it on your example application (collision by iterator) and i have no problems getting the contact joints of a body (with or without enumerator)

the collision update system is implemented and work ok.

you can send me your test application, this way, i could check it.

Bekas

30-03-2009 11:40:03

@Bekas
Foreach is fine, but I'm a little bit afrait that it costs more CPU time.

Why do you think that ? AFAIK 'foreach' has the same functionality as the manual loop that you posted, there's no additional overhead.

Beauty

30-03-2009 12:33:52

I updated my test application (collison detection by iteration)
http://rapidshare.com/files/215279131/C ... r.rar.html

The used members are these:
MogreNewt.Body(...)
MogreNewt.CollisionPrimitives.ConvexHull(...)

MaterialID(...)
MaterialPair(...)

MogreNewt.World()
World.SetWorldSize(...)
World.CollisionUpdate()
World.Dispose()

Body.UserData
Body.SetPositionOrientation(...)
Body.Dispose()

MogreNewt.Debugger.Instance.Init()
MogreNewt.Debugger.Instance.ShowLines(...)
MogreNewt.Debugger.Instance.HideLines()
MogreNewt.Debugger.Instance.DeInit()
MogreNewt.Debugger.Instance.Dispose()


The version number of the Newton.dll library is 0.0.0.0 - I think it would be good to update it.
Maybe 2.0.0.256
2.0 for related Newton version - 256 for MogreNewt revision

Beauty

30-03-2009 12:44:40

Foreach is fine, but I'm a little bit afrait that it costs more CPU time.
Why do you think that ? AFAIK 'foreach' has the same functionality as the manual loop that you posted, there's no additional overhead.


foreach(Sting line in stringList)
{
// do something with line
}

E.g. for this example I supposed that a copy of stringList will be created. Or for line always a value copy will be created.
Ok, now when I think more about - it seems to be that I had stupid thoughts.
In future I'll use the nice looking foreach loop.
In an old version of MogreNewt MOD the foreach loop didn't work, so I used the iterator instead. Later you updated the wrapper to support foreach for ContactJoints.

Beauty

30-03-2009 13:30:19

Bug report

When I use the Debugger (showing lines for Newton objects) and close the application then
sometimes I get a System.NullReferenceException
at line MogreNewt.Debugger.HideLines()

MogreNewt.Debugger.Instance is not null.
The source of exception is MogreNewt.

Before I call MogreNewt.Debugger.HideLines() I check if the Debugger was initialized. Otherwhise this line will be skipped (to avoid exceptions).


It would be nice if you add internal status checks to the methods to avoid unnessesary exceptions.

MogreNewt.Debugger.Instance.Init();
* only init if it wasn't init before
* debuggerEnabled = true

MogreNewt.Debugger.Instance.ShowLines(...)
* only do if debuggerEnabled

MogreNewt.Debugger.Instance.HideLines()
* only do if debuggerEnabled

MogreNewt.Debugger.Instance.DeInit()
MogreNewt.Debugger.Instance.Dispose()

* only do if debuggerEnabled
* before: hide lines
* debuggerEnabled = false

What's the difference between DeInit() and Dispose() ?
What's the right order to call? (does one of it call the other one?)

Also add checks for other depencies (e.g World != null )

update
Here is the StackTrace (if this helps)

at MogreNewt.Debugger.HideLines()
at MyApp.Sonar.Clear() in C:\OgreSDK\projekte\MyApp\MyApp\Sonar.cs:Zeile 1179.
at MyApp.OgreForm.OgreForm_Disposed(Object sender, EventArgs e) in C:\OgreSDK\projekte\MyApp\MyApp\OgreForm.cs:Zeile 526.
at System.ComponentModel.Component.Dispose(Boolean disposing)
at System.Windows.Forms.Control.Dispose(Boolean disposing)
at System.Windows.Forms.Form.Dispose(Boolean disposing)
at MyApp.OgreForm.Dispose(Boolean disposing) in C:\OgreSDK\projekte\MyApp\MyApp\OgreForm.Designer.cs:Zeile 20.
at System.ComponentModel.Component.Dispose()
at System.Windows.Forms.Form.WmClose(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmSysCommand(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmNcButtonDown(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.DoEvents()
at MyApp.Scene.Render(OgreForm oForm) in C:\OgreSDK\projekte\MyApp\MyApp\Scene.cs:Zeile 680.
at MyApp.OgreForm.startButton_Click(Object sender, EventArgs e) in C:\OgreSDK\projekte\MyApp\MyApp\OgreForm.cs:Zeile 938.
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at MyApp.Program.StartApplication(Scene mScene, OgreForm mForm, Boolean justCompiled) in C:\OgreSDK\projekte\MyApp\MyApp\Program.cs:Zeile 117.
at MyApp.Program.StartApplication_CatchOnlyOgreExceptions(Scene mScene, OgreForm mForm, Boolean justCompiled) in C:\OgreSDK\projekte\MyApp\MyApp\Program.cs:Zeile 86.
at MyApp.Program.Main() in C:\OgreSDK\projekte\MyApp\MyApp\Program.cs:Zeile 33.
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Beauty

30-03-2009 13:50:57

More suggestions to improve the stability of MogreNewt.

Aware that the wrapper doesn't try to get information about deleted bodies - Body.Dispose()

By calling DisposeWorld()
the debugger should be disposed, too.

Add a catch block for problems coming from:
* a needed Material was removed
* call of SceneManager.DestroyAllManualObjects()
* call of Root.Dispose()

Maybe send a message to the Ogre logfile system if hard problems were detected.
(With option to enable/disable it? What should be the default option?)

If you have more suggestions, tell it.

Beauty

30-03-2009 15:46:16

One more idea: Complete Logging

If the user enables logging, then all the names of called methods/properties/constructors will be logged to a file.
(maybe by use of a second logging thread)
MogreNewt.Debugger.Instance.LoggingEnabled (Boolean property, read/write)
We also can use a second property for the logging level
MogreNewt.Debugger.Instance.LoggingWithParams (Boolean)

Then we add this line to every (public) MogreNewt member:
MogreNewt.Debugger.Instance.LogEntry(message)
message is an object list (arbitary count of params) that will be processed by .ToString()
If LoggingEnabled is false then the method just returns.


Example for Body.SetPositionOrientation(position, orientation)
LogEntry("Body.SetPositionOrientation(position, orientation)", position, orientation)
(Is there a method to get the Name of the current method/property?)

Output to logfile:
Body.SetPositionOrientation(position, orientation)
Vector3(3747.851, 384.3294, 6177.545)
Quaternion(0.8802248, 0.02151819, -0.4697984, -0.06348804)


This would be a good helper to find out the source of bugs.
Also this information can be used for "playback" which helps to check if errors are reproducible.
What do you thing about this?


Why the debugger members are in MogreNewt.Debugger.Instance and not in MogreNewt.Debugger?

GantZ

30-03-2009 17:11:45

i have check your source code of your application, it seem that the function (CheckForCollision(tetraBody);) where you check for collision is commented in the Scene_FrameStarted function .
i have commented out this part and it work.

for the debugger, i will stick with the implementation made in ogrenewt. a lot of change have been made on debugger on the last ogrenewt revision on svn, so i will implement it on mogrenewt when i will have some free time.

Beauty

31-03-2009 16:17:50

Right, this was the mistake in my test application.
In my main application it was an other problem.
Collision detection only works, if you define a mass for it (greater then 0).

This line I commented out, because of the canged methods.
Later I forgot to correct it.

Now my application works fine :)
Also an ugly bug is much more rar in the current Newton release.
(sometimes deadlocks happened by calling Word.CollsisionUpdate() and I had to kill/restart my application)

Quall

21-04-2009 21:38:32

Hello. Is there something different with MogreNewt 2.0 that needs to be done in order to update?

I create a simple object and try to add force to it. I add everything similar to how the previous mogrenewt was set up. The only difference is how I set the MassMatrix. I put in a message box in the force callback and it is being called. The physics collision sphere is not moving though. Any help?

Scroll to the bottom to see the physics code.

class demo
{
private MogreNewt.World w;

public void Initialize()
{
Mogre.Root Root = new Root();
Mogre.RenderWindow window;
if ( Root.ShowConfigDialog() )
window = Root.Initialise( true , "Game" );
else
throw new Exception( "Ogre root failed to initialise" );

// Load resource paths from config file
ConfigFile cf = new ConfigFile();
cf.Load( "resources.cfg" , "\t:=" , true );
ConfigFile.SectionIterator seci = cf.GetSectionIterator();
String secName , typeName , archName;
while ( seci.MoveNext() )
{
secName = seci.CurrentKey;
ConfigFile.SettingsMultiMap settings = seci.Current;
foreach ( KeyValuePair<string , string> pair in settings )
{
typeName = pair.Key;
archName = pair.Value;
ResourceGroupManager.Singleton.AddResourceLocation( archName , typeName , secName );
}
}
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

Mogre.SceneManager sceneMgr = Root.CreateSceneManager( SceneType.ST_GENERIC );

Mogre.Camera cam = sceneMgr.CreateCamera( "PlayerCam" );
cam.NearClipDistance = 5;
cam.Position = new Vector3( 20 , 0 , 100 );
cam.LookAt( new Vector3( 0 , 0 , 0 ) );
window.AddViewport( cam );

Mogre.SceneNode player = sceneMgr.RootSceneNode.CreateChildSceneNode();
Mogre.Entity ent2 = sceneMgr.CreateEntity( "player" , "player.mesh" );
player.AttachObject( ent2 );
player.Scale( 10 , 10 , 10 );
player.Position = new Vector3( 50 , 3 , -100 );
window.GetViewport( 0 ).BackgroundColour = ( Mogre.ColourValue.Black );

//! Create newton world
w = new MogreNewt.World();
w.SetWorldSize( new Vector3( -1000 , -1000 , -1000 ) , new Vector3( 1000 , 1000 , 1000 ) );

//Create collision object.
Vector3 d,s;
MogreNewt.CollisionPrimitives.Ellipsoid el = new MogreNewt.CollisionPrimitives.Ellipsoid( w , new Vector3( 1 , 1 , 1 ) , player.Position );
el.CalculateInertialMatrix( out d , out s );

//Create body and attack collision object
MogreNewt.Body bp = new MogreNewt.Body( w , el );
bp.SetMassMatrix( 1000 , d );
bp.MaterialGroupID = w.DefaultMaterialID;
bp.ForceCallback += new MogreNewt.ForceCallbackHandler( bp_ForceCallback );
bp.AutoSleep = false;
bp.IsAsleep = false;
bp.IsGravityEnabled = false;
el.Dispose();

//! Show debug info
MogreNewt.Debugger.Instance.Init( sceneMgr );
MogreNewt.Debugger.Instance.ShowLines( w );

//! Run game loop
Mogre.Timer timer = new Timer();
while(true)
{
//!update physics and objects
float t_step = timer.Milliseconds / 1000;
timer.Reset();
w.Update(t_step);

//! Render the frame
Root.RenderOneFrame();
Mogre.WindowEventUtilities.MessagePump();
}
}

void bp_ForceCallback( MogreNewt.Body body , float timeStep , int threadIndex )
{
float mass;
Vector3 inertia;
body.GetMassMatrix( out mass , out inertia );
Vector3 force = new Vector3( -200f , -200f , -200f );
force *= mass;
body.AddForce( force );
}
}

Beauty

22-04-2009 02:43:39

The only difference is how I set the MassMatrix.
If I understood right, the method CalculateInertialMatrix(...) was removed. It will be calculated internally now.
Without a mass a Body doesn't move, because then the physic engine suppose it's a static object.

Change this line:
bp.SetMassMatrix( 1000 , d );
to:
bp.SetMassMatrix(1000f, new Vector3(1.0f, 1.0f, 1.0f));

Also you can remove this lines:
Vector3 d,s;
// ...
el.CalculateInertialMatrix( out d , out s );


Please tell us, if this solves the solution.

By the way - if you search for Newton related information, in the OgreNewt Forum and in the Forum of the Newton Website you find useful information. Also this is a good place for general questions that are not Mogre related.
Well, here we also try to help, but on the other forums are much more people and they are more competent in Newton questions. So there is a bigger chance to get a helping answer.

GantZ

22-04-2009 09:01:47

just a precision, the inertia must be multiplied by the mass before being applied to the object using SetMassMatrix. In your exemple, it would be

d = d * 1000 ;

otherwise, you could do as beauty suggested and set yourself the mass and the inertia

Quall

23-04-2009 00:30:13

Thanks for the heads up about the mass matrix. I didn't realize that I had to update the scenenode's position to the body's position myself. I am using the build from Smiley on page 2.

Beauty

23-04-2009 02:08:15

Here is some information that I added to the wiki. Maybe this is useful for you.
-----------

If you set Body.AttachToNode() then this will happen:
* if the Body is moved by Newton physics -> the position/orientation of the Ogre SceneNode will be updated automaticly
* if the SceneNode will be moved in Ogre -> the Body in Newton world will not be moved

Note:
* The position / orientation of Newton Body are related to the SceneNode.WorldPosition / SceneNode.WorldOrientation

(remember it, when you attach a SceneNode to a Body. If the parent of the SceneNode is not the RootNode you will get in trouble, because the SceneNode can be moved to somewhere else in the world)

* Use the debugger lines to validate size / position / orientation of the Body.Collision in Newton world

GantZ

23-04-2009 10:27:57

Body.AttachToNode()

btw it as been renamed AttachNode, for the reason you exposed. This way, it's more obvious that the scenenode move when the body move and not the contrary.

koirat

30-04-2009 21:35:25

I have just build MogreNewt with mogre 1.6.2.1 and newton 2.0
But It seams to not implement all the functionality. For Example:

////! set softness of the current contact
//void SetContactSoftness( Mogre::Real softness ) { NewtonMaterialSetContactSoftness( _mat, (float)softness ); }

////! set elasticity of the current contact
//void SetContactElasticity( Mogre::Real elasticity ) { NewtonMaterialSetContactElasticity( _mat, (float)elasticity ); }

////! set friction state of current contact
//void SetContactFrictionState( int state, int index ) { NewtonMaterialSetContactFrictionState( _mat, state, index ); }

////! set tangent acceleration for contact
//void SetContactTangentAcceleration( Mogre::Real accel, int index ) { NewtonMaterialSetContactTangentAcceleration( _mat, (float)accel, index ); }

////! align tangent vectors with a user supplied direction
//void RotateTangentDirections( Mogre::Vector3 dir ) { NewtonMaterialContactRotateTangentDirections( _mat, &dir.x ); }

////! manually set the normal for the collision.
//void SetContactNormalDirection( Mogre::Vector3 dir ) { NewtonMaterialSetContactNormalDirection( _mat, &dir.x ); }

////! manually set the acceleration along the collision normal.
//void SetContactNormalAcceleration( Mogre::Real accel ) { NewtonMaterialSetContactNormalAcceleration( _mat, accel ); }


All those lines in ContactMaterial are commented and i do not have any other possibility to change friction and so one.
Is newton 2.0 in such an early stage that it does not implement it yet ??

GantZ

01-05-2009 00:23:12

just a little omission :)
these function are implemented. It have been probably commented out in an early version and let this way.
You can comment them out and recompile. I will update it on svn later.

koirat

01-05-2009 10:19:27

[edit][/edit]

Let me ask one more question please.

NewtonMaterialSetContactFrictionCoef <-- I dont see this function in a code, even in commented one. Have you implemented all the functions ??

Beauty

01-05-2009 16:46:18

@koirat
Please don't quote if not necessary. This is not good for overview ...

koirat

01-05-2009 20:14:15

Forgive me.
This was an accident :oops:

ps. I almost quoted your post :P

GantZ

03-05-2009 18:52:08



Let me ask one more question please.

NewtonMaterialSetContactFrictionCoef <-- I dont see this function in a code, even in commented one. Have you implemented all the functions ??


basically, the current version is an update of the 1.53 version to work with newton 2. Some new function have been implemented, but not all of them. i try to stick to the implementation of ogrenewt, but change are made on a regular basis, so don't be surprised if some function are missing.

also, i'm working actually on implementing the new debugger of ogrenewt. there is some breaking change here, and i would like to have the opinion of mogrenewt user. the new debugger feature :

- display of debug information for a body using the movabletext class
- caching of debug lines, improve performance of the debugger
- function to change the color of debug lines by materialid

thing that change and that could be annoying are :
- you need to have a specific font to use the movabletext class, without it, the debugger crash
- no change of color when a body is asleep, awake or with a mass of zero, every debug lines have the same color by default regardless of the state of the body

what do you think about that ? i'm trying to keep the debugger as flexible as possible, and keep the old and new behavior in the same code. is it relevant ? also, i will probably add the possibility to log the debug information as beauty have suggested earlier, what informations would you like to be able to log?

Beauty

04-05-2009 00:12:29

Nice news.

1)
About the new functions. Maybe somebody like to make an overview of all new functions and then look, which one still aren't implemented. (I suppose the information is included in the changelog file)
Maybe we can create a wiki page for a Todo List, ideas, open problems, etc.
This page can be a common one together with the OgreNewt developers (maybe with Mogre related sub sections). Because the wrappers are very similar.


2)
In an other thread I asked about the version compatibility. Maybe this thread is better for discussion.
There are some little API differences between Ogre 1.4 and 1.6.
Mogre 1.6 is still only a beta version.
Maybe some users want to use Newton 2 with Mogre 1.4.

So how we want to handle it in the MogreNewt SVN?
Make it compatible to 1.4 or 1.6?
Or split into 2 branches, what would be not so nice for updates.



3a)
The debugging news sounds great!
- you need to have a specific font to use the movabletext class, without it, the debugger crash
MovableText is nice. Will it be included to the MogreNewt library or does it need to be included in Mogre itself?
We could include a font check. If there is no needed font then a Boolean flag will be set and the related operations will be skipped. Also the Ogre Logfile can get an entry "Warning: MogreNewt misses the font Xyz". (I think there is a class/method to add own entries to the ogre logfile.)
Good would be to use a font with verry less licene so that it can be used for all kind of application.
The 3D modelling program Blender has a font (for its GUI), which is also good readable with tiny size. The filename is .bfont.ttf and the extention is the same like that one in the default SDK pack OgreCore.zip. I think some year ago I used it for GUI tests. But I don't know the licence. Maybe one of the default Ogre fonts are good enough? (in OgreSDK\media\packs\OgreCore.zip)


3b)
- no change of color when a body is asleep, awake or with a mass of zero, every debug lines have the same color by default regardless of the state of the body
Are the problems with the old debugger, too?
I suppose there are 3 different materials for the states.
One more idea: If somebody like, he can add a custom colour/material to each MaterialID.

In my main application I included to change colours on the fly. There I had a similar problem. Not all colours changed. Reason: I have a method which returns the name of a needed material. If the material was not created, then it will be created on the fly (dependend to the method parameters). If the material still was created, it just returned the irght material name. (Only the name of the material is needed for creating a ManualObject.)
The solution: I added the flag forceUpdateIfExists to the method.
For updating a material I used this (simlified) code. Maybe it solves your problem, too.

String materialName = "...MyBodyState..."; // name of the existing material
// get pointer to the existing Material
MaterialPtr moMaterial = MaterialManager.Singleton.GetByName(materialName);
// it the Material doesn't exists yes, use Create(materialName, ...) instead

// set new params (= update)
moMaterial.ReceiveShadows = false;
moMaterial.GetTechnique(0).SetLightingEnabled(true);
// use a Pass for more params
Pass matPass = moMaterial.GetTechnique(0).GetPass(0); // direct access to material settings
matPass.SetDiffuse(colour.R, colour.G, colour.B, 0);
matPass.SetAmbient(colour.R, colour.G, colour.B);
matPass.SetSelfIllumination(colour.R, colour.G, colour.B);
matPass.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);
// for more settings look to forum/API etc.

// now the Ogre material is updated and we don't need the pointer anymore.
// (If we need it later, we can create it again the same way)
moMaterial.Dispose();



3c)
what do you think about that ? i'm trying to keep the debugger as flexible as possible, and keep the old and new behavior in the same code. is it relevant ?
Nice that you improve the debugger :)
The old debugger has not much functionality (I suppose). Generally only ShowLines / ShowNoLines / ColourChangeDependentToState.
Or am I wrong?
Also there was a bug. When I initialized again after deinitialization then I got a crash.
Maybe there is only a little compatibility problems for updated applications. But if somebody replaces Newton 1 with 2 then he can do the few more changes in the code. Good would be a changelog information in the wiki (or in a logfile) for removed / renamed class members.


3d)
also, i will probably add the possibility to log the debug information as beauty have suggested earlier, what informations would you like to be able to log?
I implemented a logging functionality to my main application, because there was a bug (deadlock) in a new Newton function. Then I wrote an application, which repeated all needed calls. So the author of Newton could reproduce the problem at his computer only with this test application.
It's only a simple code and could be better, but maybe you can catch the idea.
For logging I found a nice DLL. log4net is fast, robust, flexible and widespreaded. I didn't know about before, but I think this is a good worker (Apache licence). More information about log4net I wrote in this thread.

We in the logging class (or a subclass) we can create properties called "Log_MethodName", e.g. Log_SetWorldSize, Log_MaterialID, Log_SetPositionOrientation. They are boolean and if true, then the related methods will send a message to the logfile for each call.

Every line of the logfile is one call. Starting with a defined Name (type of call) and the related params.
Aware: for floating point values force the english culture, because the decimal seperators are different in some contries which cause trouble. E.g. in Germany we write "0,5" instead of "0.5".
Using example:
// define var "encu" (for "english culture") for better overview and less keyboard presses
System.Globalization.CultureInfo encu = new System.Globalization.CultureInfo("en-US");
// ...
String.Format(encu, "Value: {0}", myValue);


Here is the class which initialize log4net and members for logging:
http://beauty-of-darkness.de/pub/NewtonDebugLog.rar

Using example:
myBody.SetPositionOrientation(node.WorldPosition, node.WorldOrientation);
if (debugLogging)
sonDebug.NewtLogPostionOrientation(node);

// ...
public void NewtLogPostionOrientation(SceneNode node)
{
newtLogger.Debug(String.Format(Misc.englishCulture(),
"Newton_SetPositionOrientation\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}",
node.WorldPosition.x, node.WorldPosition.y, node.WorldPosition.z,
node.WorldOrientation.w, node.WorldOrientation.x, node.WorldOrientation.y, node.WorldOrientation.z, node.Name));

} // NewtLog_PostionOrientation()


Here is my test application for repeating the recorded things.
http://beauty-of-darkness.de/pub/Collis ... -05-25.rar (7 MB)
Maybe this helps or is useful for ideas.

Some example lines of a logfile:
Newton_NewObject_AABB boat 2.435999 0.612957 0.499914
Newton_SetPositionOrientation 3746 384 6174 0.8454338 -0.04157699 -0.5282857 0.06653709 boat
Newton_NewObject_AABB sensorPrototype 1.999999 1.999999 2
Newton_SetPositionOrientation 3747.851 384.3294 6177.545 0.8454338 -0.04157699 -0.5282857 0.06653709 sensorPrototype
Newton_NewObject_Vertices sensorPrototype~Lobe000000000 2.998144;0.01308195;0.1046985__2.998144;0.01308195;-0.1046985__2.998144;-0.01308195;-0.1046985__2.998144;-0.01308195;0.1046985__3.997525;0.0174426;0.139598__3.997525;0.0174426;-0.139598__3.997525;-0.0174426;-0.139598__3.997525;-0.0174426;0.139598
Newton_NewObject_Vertices sensorPrototype~Lobe00000110 11.99258;0.05232782;0.418794__11.99258;0.05232782;-0.418794__11.99258;-0.05232782;-0.418794__11.99258;-0.05232782;0.418794__12.99196;0.05668847;0.4536935__12.99196;0.05668847;-0.4536935__12.99196;-0.05668847;-0.4536935__12.99196;-0.05668847;0.4536935

Newton_SetPositionOrientation -7961 10559.7 -8260.11 0.9933792 -0.00638283 0.06946383 -0.09127873 sensorPrototype~Lobe000000
Newton_SetPositionOrientation 2039 559.7 1739.89 0.9933792 -0.00638283 0.06946383 -0.09127873 sensorPrototype~Lobe0000000
Newton_WorldCollisionUpdate
Newton_SetPositionOrientation -7961 10559.7 -8260.11 0.9933792 -0.00638283 0.06946383 -0.09127873 sensorPrototype~Lobe0000000
Newton_SetPositionOrientation 2039 559.7 1739.89 0.9933792 -0.00638283 0.06946383 -0.09127873 sensorPrototype~Lobe00000000
Newton_WorldCollisionUpdate
Newton_SetPositionOrientation -7961 10559.7 -8260.11 0.9933792 -0.00638283 0.06946383 -0.09127873 sensorPrototype~Lobe00000000
Newton_SetPositionOrientation 2039 559.7 1739.89 0.9933792 -0.00638283 0.06946383 -0.09127873 sensorPrototype~Lobe000000000
Newton_WorldCollisionUpdate


A problem was the creation of a ConvexHull for meshes. So I just created AABBs with the same size. Better would be to get all vertex positions, but I didn't understand the related source codes.
Alternatively the name of the Mesh file could be saved in the logfile.

Generally it's a question - what somebody wants to do with the logged information.
Reading, replay, something else?



Ok, this was fucking much text (and even more time to create it ~2.5h).
Please quote only these parts which are really needed. Or use the numbers like 2) instead.
The next 2 weeks I'm in holiday. So don't worry if I don't write again soon.

Beauty

20-05-2009 12:00:25

4)
In Newton forum I read/discussed about the param NewtonSetPlatformArchitecture.

The default doesn't architecture specific hardware optimization. The param 2 set the best possible performance setting. (MogreNewt uses an enum instead of a number). On older/other platforms this never causes a crash. The speedup can be significant.

What do you think about to set the "best" performance value as default?
Good for people who doesn't know this param.
Not so good for OgreNewt compatibility.
Some round off errors can be different to the default.
The author doesn't set the "best" param as default for a better performance comparability.

If we doesn't set this param as default, we could add a hint to the ogre logfile.
Only one time of application rum. And maybe write it at first call of World.Update(...) or World.CollisionUpdate().
(if the param isn't set manually until this point)

MogreNewt INFO: Speed up is possible by setting World.SetPlatformArchitecture(World.PlatformArchitecture.PA_BEST_HARDWARE)


More information is here:
http://www.newtondynamics.com/wiki/inde ... chitecture

Beauty

24-05-2009 22:38:42

It's very quiet around this thread ...

I found a bug in a new Newton 2 function.
Now I wrote a test application which reproduces the problem.
This should help the developer of Newton to debug his library.

But my test application doesn't work on his PC.
It would be nice if somebody can help.
Look to this thread:
viewtopic.php?f=8&t=10113 (solved)

GantZ

26-05-2009 17:44:52

ok, i have finally commit the new version of the debugger on the svn.the main improvements are the addition of a movable text for each body with debug information, logging of these informations, and improved performance.

how to use it

initialization

m_World.DebuggerInstance.Init(sceneMgr); //[attachment=0]MogreNewt.zip[/attachment]initialise the debugger for the newton world

on each frame

m_World.DebuggerInstance.ShowDebugInformation();


ShowDebugInformation() come with 2 new optionals parameter:
ShowDebugText : boolean, show a movable text on the top of each body, you need the font BlueHighway-10 in your resources to make it work, you can find it in the media files of the mogreSDK (a warning show on the log file if mogrenewt can't find it)
LogDebugText : boolean, log the text displayed by the movabletext, you can keep track of a body state this way

also, you have the ability to change the color of the debug line, you have to do it on the initialization ,there is no update of the color of debug lines on each frame


m_World.DebuggerInstance.SetDefaultColors(ColourValue)
m_World.DebuggerInstance.SetMaterialColor(MaterialID,ColourValue)


color change based on the state of the body (freezed, unfreezed, mass = 0) don't work atm, i will see what i can do to solve this issue.

here a binary version compiled with the 1.6.2_2 version of Mogre
[attachment=0]MogreNewt.zip[/attachment]

@Beauty
2) for the moment, i will concentrate on the new version of Mogre. also, the change needed for Mogrenewt between the 2 version are really thin (just an include or 2 to remove to compile it on the 1.6 version)
3a) Movabletext class is include in mogrenewt, but it is the ogre version.
3b) no, the old debugger change the color of the debuglines depending on the state. that why i want to find a solution for the new debugger. Also, with this new version you can change the color of the debuglines for a specific material id using m_World.DebuggerInstance.SetMaterialColor()
3d) atm, this version just show the same information as the movabletext on the ogre log file. i prefer avoid add new dependency in mogrenewt for the moment.
also having the ability to log any information of a body would be great. maybe using reflection ?

Beauty

27-05-2009 00:58:36

Interesting news, especially for the text and it's logging.


About the logging:
* Generally it would be good to use an own thread for logging (is it done by Ogre internal logging?).
(Give the message to it by a method call, let it work parallel and don't thwart the main application.)
* If MogreNewt will use an own logfile in the future, it would be useful to add also a public method for custom log entries.
* Also an option to set path + filename of the logfile.
* I don't know what is reflection. There is a logging class available in .NET, but I forgot the name. Maybe this it is.
Right, additionally depencies are not sweet. (It was just an idea.)



Nice would be an option to mark colliding bodies (e.g. by colour or debug text).

Generally it's nice to set the (default) colour by MaterialID.
Internally for each body an own material could be created.
So it would be easy to change the colour of a singe body without rebuilding the ManualObject.
Just update the material of the single body. This is easy (as shown in 3b) ) and I suppose it's fast.



If it's so easy to change the Mogre 1.6 depency to Mogre 1.4
it would be nice if you can build/publish both versions.
And/or describe somewhere what do change in the souce code (e.g. for this create the file "Building for Mogre 1.4.txt" in the SVN).

koirat

27-06-2009 18:29:42

I'm doing

world.DebuggerInstance.Init(sceneManager);

after it I'm doing each update

world.DebuggerInstance.ShowDebugInformation();

The result is "Object reference not set to an instance of an object."
at MogreNewt.MaterialID.get_ID()
at MogreNewt.Debugger.ProcessBody(Body body)
at MogreNewt.Debugger.ShowDebugInformation()

Did I forget to do something ??

redhead

30-06-2009 17:12:59

Hi,
I tried to upgrade to newton 2.0, compile and runs fine, but physics are somehow bad. Simple box shooting against wall behaves very strange. It is used in my application which was running fine in newton 1.5x (or so), now it can be seen that there is some collision, box collides against wall but somehow it gets throw it.

Other example - my player which tries to go from flat to angled ramp goes throw the ramp, when I stop player body very slowly climbs to "match" the ramp height.
Cant go on stairs neither.

Code is exactly the same, just adjusted for newton 2.0 functions.
Maybe it is inertia and mass, here is how I set it


//mass = 10
body.SetMassMatrix(10, body.Intertia * 10);

Is this right??

thanks for any help

Beauty

01-07-2009 06:51:31

Maybe it's a bug of Newton 2.
So please repeat this question in the Newton forum.
Here is the talk about Newton 2.0:
http://www.newtondynamics.com/forum/vie ... &start=135
Newton experts and the developer itself can reply.

P.S.
It's Inertia instead of Intertia

GantZ

01-07-2009 16:28:45

@Koirat

i have recently corrected a bug related to a crash with the debugger when no materialgroupid have been assigned to a body, do you use the last svn version ? if not, try to update and see if it solve your problem

@redhead

do you use CalculateInertialMatrix ? usually, i use


float mass = entity.BoundingBox.Volume() * 10f;
MogreNewt.ConvexCollision _colPrimitives = new MogreNewt.CollisionPrimitives.ConvexHull(m_World, scenenode, 0);
_colPrimitives.CalculateInertialMatrix(out inertia, out offset);
inertia = inertia * mass;
MogreNewt.Body _CollisionBody = new MogreNewt.Body(m_World, _colPrimitives);
_colPrimitives.Dispose();
_CollisionBody.SetMassMatrix(mass, inertia);

koirat

02-07-2009 11:26:56

I'm using the one you posted few post before this post

here a binary version compiled with the 1.6.2_2 version of Mogre
MogreNewt.zip
MogreNewt 2.0
(69.67 KiB)

koirat

04-07-2009 09:07:16

I have compiled SVN for MogreNewt and now i have.

"Could not find font BlueHighway-10 in MovableText::setFontName"

And i did add MogreSDK/Media/fonts path to resources. Where i have bluehigh.ttf.

GantZ

06-07-2009 00:29:08

And i did add MogreSDK/Media/fonts path to resources. Where i have bluehigh.ttf.

you should have a .fontdef file in your resources with this code:


BlueHighway-10
{
type truetype
source bluehigh.ttf
size 10
resolution 96
}



still, even if you don't use movabletext, the library crash when the font is not found, i will make a fix, and upload it to svn.

koirat

06-07-2009 12:46:39

Thanks Gantz now it is working like a charm. "After editing .fontdef"

Btw. would you mind adding

//! Set friction for contact
void SetContactFrictionCoef(dFloat staticFrictionCoef, dFloat kineticFrictionCoef, int index)
{NewtonMaterialSetContactFrictionCoef(_mat,staticFrictionCoef,kineticFrictionCoef,index);}


To ContactMaterial.h it looks like it is missing.

GantZ

07-07-2009 14:34:14

no problem, i've just add it to the svn, i've also fix the bug related to the crash when the font of the debug text is not found.

i've updated the binary version i've posted earlier, this way, you can get it directly.

koirat

10-07-2009 08:53:39

I have got problem with destroying bodies.

I'm making gun bullets as an ellipsoids. I'm firing this bullets and they and up stucking on the newton world boundary.
This bullets are programed so they will destroy itself after 2 seconds. After this time I'm destroying their newton bodies with Body.Dispose(). Since I have destroyed them I have got access violation to most of their parameters in Visual Studio debugger. But newton debugger shows this bodies even after destroying them !!!

My other questions are:
When i create Bodies I use Collision Primitives. Should I Dispose of this Primitives after creating newton Body ?
When Disposing Newton Body with Dispose() i still have access to it's Collision should i dispose of It explicitly.

Beauty

10-07-2009 09:41:55

Does the problem happens only with activated debugger or in general?
This would be interesting for finding the problem.


The collision you need only at allocating to the body.
(Then internally the body saves a copy or similar structure - I suppose)
After allocating to the body you can dispose the collision.

Here an example for a collision hull. For collision primitives it's the same.

CollisionPrimitives.ConvexHull colHull
= new CollisionPrimitives.ConvexHull(nWorld, targetNode, collisionHullTolerance);
Body myBody = new MogreNewt.Body(nWorld, colHull);
colHull.Dispose()
// ... now use body

koirat

10-07-2009 10:18:51

You are talking about VS debugger or MogreNewt debugger ?
The body is destroyed for sure. I just tested it. Bodies dont have to be freezed on a world boundary for bug to happen. I have just dimnished speed of my bullets to nearly 0. I put them on a slope of a hill. They start to roll and after 2 seconds when the body is disposed they freez on a slope. Of course I can see their collision shape only while MogreNewt debugging mode is activated.

Beauty

10-07-2009 11:43:39

I mean the MogreNewt debugger.
If the bug would be only at enabled debugger, than there could be the problem.
But sorry, I can't help. It was just an idea for the MogreNewt developers.

Interesting would be to know if the problem also happens with OgreNewt. If not, then the source codes could be compared. Maybe something was forgotten (e.g. dispose an object which points to the disposed body).
If there is an error message in the ogre logfile, please post it.

GantZ

10-07-2009 13:41:47

it's my mistake. since all the debug lines are cached in a Dictionary, they have a flag to check if they have been updated or not (destroyed body are obviously not updated)

the problem lie with the flag m_updated always set to True, so the debug lines related to a destroyed body were never cleaned. i don't know if the same problem would occur in ogrenewt, i haven't found where they reset the flag.

i've just corrected this issue, it's in the svn now. also, please see the first post for the latest binary, i will update the first post each time i update the binaries.

koirat

10-07-2009 15:37:06

It just came to my mind but maybe you should think about changing pure Dispose() into "Dispose() ; event Disposed ; bool IsDisposed " pattern. Since i have got MogreNewt.Body inside my own Body wrapper I have got this notifications. But still it would be better to got it inside MogreNewt.Body class.
And thanks for correcting the bug i will check it out in not time.

Beauty

10-07-2009 18:13:13

i haven't found where they reset the flag.
Maybe in the wrapper method Body.Dispose()?
This would be a good place I think.

GantZ

13-07-2009 11:42:57

@Beauty

i was referring to the ogre wrapper, not the mogre one, there is no dispose function in the ogrenewt wrapper. now that i re read what i have written, maybe it wasn't really clear :)

@Koirat

not a bad idea. i will think about it . right now, i haven't much time to spare for mogrenewt. still, it isn't a big modification, so i will try to integrate it next time i update the wrapper.

Chulein

09-09-2009 09:23:14

Ive been playing around abit with MogreNewt 2.0 and Ive been having some problems.
Using the tutorial ive set up a project using VS 2009, Mogre 1.6.2, and Newton 2.0.
I get a crash with the message

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

in the line

MogreNewt.ConvexCollision col = new MogreNewt.CollisionPrimitives.Box(m_World, size);


Full code

public Body MakeSimpleBox(Vector3 size, Vector3 pos, Quaternion orient,SceneManager sceneMgr)
{
// base mass on the size of the object.
float mass = size.x * size.y * size.z * 2.5f;

// calculate the inertia based on box formula and mass
Vector3 inertia;
Vector3 offset;


Entity box1;
SceneNode box1node;

box1 = sceneMgr.CreateEntity("Entity2", "cage.mesh");
box1node = sceneMgr.RootSceneNode.CreateChildSceneNode();
box1node.AttachObject(box1);
box1node.SetScale(size);

//Collision col = new MogreNewt.CollisionPrimitives.Null(m_World);//, 10.0f, 10.0f);
MogreNewt.ConvexCollision col = new MogreNewt.CollisionPrimitives.Box(m_World, size);
col.CalculateInertialMatrix(out inertia, out offset);
inertia = inertia * mass;
MogreNewt.Body bod = new MogreNewt.Body(m_World, col);
col.Dispose();

bod.AttachNode(box1node);
bod.SetMassMatrix(mass, inertia);
bod.IsGravityEnabled = true;

box1.SetMaterialName("Examples/10PointBlock");


bod.SetPositionOrientation(pos, orient);

return bod;
}


taken from https://mogre.svn.sourceforge.net/svnroot/mogre/trunk/MogreNewt/Samples/Basics/Basics.cs



all is up and running and gravity works when i use Collision col = new MogreNewt.CollisionPrimitives.Null(m_World);//, 10.0f, 10.0f);
instead.....

Anybody had the same problem?

redhead

09-09-2009 15:20:44

I would try


MogreNewt.Collision col = new MogreNewt.CollisionPrimitives.Box(m_World, size);

GantZ

09-09-2009 17:13:48

just test it, i got no problem with your code.

check that you use the first newton 2.0 dlls, not the revised one (2.0X or so). MogreNewt is compiled against the first beta SDK of newton 2.0.

usually, you get this kind of error when a managed dll try to access an unmanaged dll different that the one used at compilation time

Chulein

10-09-2009 11:03:30

Great!

I switched to the 2.0 version and now it works great.
It was just as you said because i used the 2.09 version before.

Thanks GantZ!


Chulein.

Chulein

15-09-2009 08:57:08

Im getting random freezes in my test application using mogrenewt 2.0
Ive created a simple terrain, and i use the "shootbox function in the newton test application.
also the boxes disappears at random in some places in the frustrum....

Chulein.

GantZ

15-09-2009 19:56:42

Im getting random freezes in my test application using mogrenewt 2.0
could you provide more informations about that ? what freeze exactly, the objects or the application ?

if possible, could you post your code ?

GantZ

05-11-2009 17:41:23

note to every MogreNewt user : the current SVN head use the 2.09 version of Newton, and i have added some new functions and property. the modification haven't be tested so stick to the previous version if your don't need to upgrade. i will release a binary when i will finish implementing all the ogrenewt addition. see the svn log to get more detail

GantZ

13-11-2009 16:55:23

new version available ! see first post

Beauty

14-11-2009 01:55:05

Im getting random freezes in my test application using mogrenewt 2.0
Ive created a simple terrain, and i use the "shootbox function in the newton test application.
also the boxes disappears at random in some places in the frustrum....


I had a similar problem some months ago.
The freeze was at call of WorldCollisionUpdate() - I think internally the Newton function name is NewtonCollisionUpdate().
Then I extended my main application so that all access of between my application and Newton were logged to a file.
Then I wrote a tiny application, which just reproduced the Newton access.
So I could reproduce the freezes and the developer just had to start my exe file.
After debugging he quickly found the problem and fixed it.

The problem was that I had big, but very flat objects. Because of this an optimization runs into an endless loop.

Beauty

14-11-2009 02:00:51

Today randomly I recognized a little problem.

When an object has scale 0 then Ogre works normal and has no exception.
But when I call MogreNewt.CollisionPrimitives.ConvexHull() to create a Newton body of it then there comes an Access Violation Exception. It tooks some time to find out the reason.

So my suggestion:
Add a check to ConvexHull() method.
If the scale is 0 then don't call the internal newton function. Just ignore it.
And a logfile entry would be good.

Beauty

14-11-2009 02:10:31

Long time ago I reported about a problem.
When a SceneNode has a ManualObject as entity (instead of a Mesh) then there was a problem.
(I'm not shure if an exception or if it just was ignored.)

Is it now possible to add SceneNodes with ManualObject?
If not, it would be good to add this feature.
Or at least avoid an exception and write a logfile entry that this feature isn't supported yet.

This is just a hint to improve MogreNewt.

P.S.
Thanks Gantz for all your work !! (Mogre updates, MogreNewt updates, and maybe more)
And sorry that I lost my activity. I has less time and my freetime motivation is somewhere else now. Maybe I will be more active in future again. It would be for a good purpose.

GantZ

14-11-2009 21:48:31

hi Beauty, long time no see :) thanks for your reports, i have add all the existing bugs of MogreNewt in the OgreNewt.h file, so that everyone using the source will know what bug the library currently has. so far, i haven't fix the bugs, i have rather implement the new functionalities, but i intend to do so in the future, (at least before the final version of Newton 2.0).

PS : thanks for what you have done so far for Mogre (especially on the wiki), you help will always be appreciated , everyone have their own priorities so don't worry about it ;)

Beauty

14-11-2009 22:46:07

I would never get the idea to look to a .h file for a bug list.
Maybe it's better to use an extra file (e.g. buglist.txt or bugs+todo.txt).
Or just use the wiki!

By the way - our current wiki page about MogreNewt is really poor.
Maybe I'll improve it.

Also it would be good to publish binaries of MogreNewt.
Here in this thread and also in the wiki.
Maybe including a direct download link to the related Newton package. (Unfortunatelly it's not allowed to publish it together - If I understood the Newton licence right.)

Beauty

15-11-2009 23:55:04

Currently I try to update my main project from Mogre 1.4.3 to 1.6.4.
There I also want to include the current MogreNewt.
It would be nice if somebody publish the MogreNewt.dll file of 2.0.9.
(I use a 32 bit Windows, so maybe I need a 32 bit compilation?)

Just a note:
In April I tried an update to Mogre 1.6.2. If I remember right, there was a problem with my bad self updated MogreNewt code. Now I want to give a next try to disembrass my application frome the Stone Age :wink:

GantZ

16-11-2009 00:37:28

I would never get the idea to look to a .h file for a bug list.
Maybe it's better to use an extra file (e.g. buglist.txt or bugs+todo.txt).
Or just use the wiki!


i must admit that it was intend for my personal use at first :) i will add bug in the wiki and on a separate file then. i will also add the link to the binary on the wiki.

Currently I try to update my main project from Mogre 1.4.3 to 1.6.4.
There I also want to include the current MogreNewt.
It would be nice if somebody publish the MogreNewt.dll file of 2.0.9.


check out the first post, i have update the MogreNewt dll to use the 2.10 version of newton. it work on 32 bit OS.

Beauty

16-11-2009 01:28:11

Right ... the first post

Beauty

16-11-2009 13:33:17

make sure to grab the latest newton SDK available here : http://newtondynamics.com/forum/downloads.php

There are 6 different newton.dll files in the Windows package.
The differences are between
* 32/64 bit
* vs7 / vs9
* with / without double prefix

Always I was confused which to use.
Does it only depend to the related MogreNewt compilation?
Or does the bit-setting and VS-Version depend to the target application development?

Good would be to combine the right combinations of MogreNewt.dll and newton.dll in one package.
But I'm not shure if it's allowed by the Newton licence.

[...]
If the LICENSEE does not accept the terms and conditions, then LICENSEE must not accept the SOFTWARE.
If at a later time the LICENSEE decides not to continue licensing the SOFTWARE under these terms and
conditions, then the LICENSEE must delete permanently all files constituting the SOFTWARE.


LICENSE AGREEMENT
Newton Game Dynamics Limited grants to the LICENSEE and the LICENSEE hereby accepts a perpetual
nontransferable and nonexclusive license to use and distribute the SOFTWARE, for any purpose.
In addition, the following conditions apply:

1) The LICENSEE may not use the SOFTWARE to reverse engineer the computer algorithm used by the SOFTWARE.
2) The origin of the SOFTWARE must not be misrepresented; If the LICENSEE uses the SOFTWARE to distribute
a product, the LICENSEE must not claim that He or She wrote the original SOFTWARE.
3) The LICENSEE agrees to credit the use of the Newton Game Dynamics in any program information,
including credit screens, "About" dialogs, program notes or instructions and shrink-wrapped packaging.
4) The LICENSEE may not redistribute the SOFTWARE, except as part of a compiled software program that is
not itself a physics library.
5) The LICENSEE agrees to notify http://www.newtondynamics.com of any products, commercial, shareware or free
that incorporate the Newton Game Dynamics technology.

Beauty

16-11-2009 15:35:05

One more whish:

Nice would be to have XML comments to the members of MogreNewt.
I think it's possible, but I don't know how to do, because it must be defined in the wrapper (written in C++).

An other thing is, how much information we should include.
Maybe include the name of the original Newton function?
(This would help to find related information in the Newton wiki.)
Generally comments would make programmers life more easy.

koirat

16-11-2009 17:07:20

The only way I can think of would be to add wrapper over MogreNewt made in c# with XML comments (proxy pattern as I remeber). Same name for dll and functions, for writing code more intellisens-ed :P. And compile it with original MogreNewt.dll before releasing.

Beauty

16-11-2009 17:08:34

MogreNewt.CollisionPrimitives.ConvexHull() has a new param. It's name is id.
What's the intension of it?
In the Newton wiki I didn't found this param at function NewtonCreateConvexHull.

Is it the MaterialID?
Normally this is attached to the Body and not to the Collision.
("collision" in Newton means collision hull in general understanding)
If so then this could cause problems. Because one collision can attached to several bodies with different MaterialIDs.
(Also a body doesn't refer to a collision. When you create a body, it seems to store an own instance of it.)

GantZ

16-11-2009 19:11:38

MogreNewt.CollisionPrimitives.ConvexHull() has a new param. It's name is id.
What's the intension of it?


the id parameter stand for shapeID. I have just include so it's available for further uses. here an example of why shapeID have been include in newton
http://newtondynamics.com/wiki/index.php5?title=Tutorial_201:_-_Advanced_Custom_Material_System

about the dll, you have to use the 32 bit vs_9 version, it directly related to the configuration of MogreNewt (which is 32 bit/ compile under vs_9 by default). the double version are related to use of __USE_DOUBLE_PRECISION__ flag in newton. MogreNewt use float (the default configuration).

about the static linking of newton into MogreNewt, the best would be to ask directly the newton author. but by reading the license state that you cannot redistribute the dll (and probably include it) with a physics library.
The LICENSEE may not redistribute the SOFTWARE, except as part of a compiled software program that is
not itself a physics library.

Beauty

16-11-2009 19:35:29

Suggestion:

Add the property nWorld.DebuggerInstance.IsInitialized (read only).
Currently I have my own flag for this. But it would be more nice, if it's implemented inside of MogreNewt itself.

GantZ

16-11-2009 20:13:17

added to my todo list ;)

Beauty

16-11-2009 20:45:01

MogreNewt.CollisionPrimitives.ConvexHull() has a new param. It's name is id.
What's the intension of it?

the id parameter stand for shapeID. I have just include so it's available for further uses.

You mean in the moment this param is without effect?
Then I can set it to 0 on each collision.

Would it be more clear to call it shapeID instead of just id? (Would this make sense?)
Alternatively you don't add it to the constructor. Instead add it as a property to ConvexHull (and other collision types).
An other alternative could be to add contructors with and without this param. (this would be more work for you)



Here an example of why shapeID have been include in newton
http://newtondynamics.com/wiki/index.php5?title=Tutorial_201:_-_Advanced_Custom_Material_System

Much text, but I'm not shure what's the main intension. Something about a workaround to extend the Newton material system. (sub materials? For non-rigid bodies?)
Nice is that the Newton wiki support syntax highlight. This I wanted for the Ogre wiki, searched related plugin-websites, but Sinbad didn't include it :evil:


about the dll, you have to use the 32 bit vs_9 version
This note I added to the wiki. You also can add it to your first post.


about the static linking of newton into MogreNewt, the best would be to ask directly the newton author. but by reading the license state that you cannot redistribute the dll (and probably include it) with a physics library.
The LICENSEE may not redistribute the SOFTWARE, except as part of a compiled software program that is
not itself a physics library.

I don't think that MogreNewt is a physics library like the license means. It's just a wrapper for C#.
When we add a tiny binary test application to the dll files, then it could be allowed to publish it together. (A small single exe file would be good. This could also be written in C++ and create just text output *g*)
Also I can ask Julio Jerez about his opinion.

Beauty

17-11-2009 00:01:05

Ok, I updated my main application from Mogre 1.4.3 + a very old MogreNewt 2 version
to Mogre 1.6.4-1 + Newton 2.10.
It uses Newton for collision detection only (and the MogreNewt debugger).
Here is a list of used methods: viewtopic.php?p=56302#p56302

After some needed changes generally my application worked fine :)

From time to time there were some strange problems and exceptions, but this I will study later.
(I think this is not Newton related. Maybe a Mogre problem or something else. For example I had an exception from System.Windows.Forms before.)

GantZ

18-11-2009 11:54:28

i have updated the binary of MogreNewt, changelog from the svn :

-> add IsInitialized property in the Debugger class
-> add Dispose(), IsDisposed, event Dispose pattern for the Body and world class
-> add the KnownBugs.txt file

i will change the name of the id parameter later, and probably add a constructor without it, i just want to add that this parameter is mandatory with the newton function to create collision primitives. (the wiki of newton isn't up to date)

Beauty

18-11-2009 16:11:28

nice - now my code is a little bit more clear (-:

Beauty

26-11-2009 13:55:46

The feature HeightFieldCollision (used by library function NewtonHeightFieldCollision) isn't implemented until now.
(also not in OgreNewt as I see in Walabers notes in MogreNewt_Main/inc/OgreNewt.h, v2.09)

Would it generally be possible to use this feature with the Terrain Scene Manager?

As I read in very old threads, this scene manager was not supported by OgreNewt 1.x.
But the paging scene manager (PLS2) could do (which is an improvement of the terrain scene manager).

update:
For this I also started a new thread in OgreNewt forum:
viewtopic.php?f=4&t=11696

Beauty

26-11-2009 14:07:35

Smiley80 wrote the Mogre XML commentation tool, which can create comments for the Mogre library.
I asked him if it's possible to do the same for MogreNewt.

Here you can download the result of the first try:
http://sites.google.com/site/infralicht ... ects=0&d=1
Just copy the file MogreNewt.xml to the same directory where MogreNewt.dll is.

If somebody wants to improve the tool (for usage with MogreNewt), then you can talk about in this thread.

Also it would be nice to add the file MogreNewt.xml to the official download package of MogreNewt.

Beauty

30-11-2009 22:26:50

I asked Julio Jerez (the author of Newton) because of the permission to integrate the newton.dll file to a project in a public SVN.
It is allowed!
The old licence doesn't matter and Julio said we can do whatever we want with it.
(Even we are allowed to clain it's from somebody else.)

We can forget the old licence of Newton 1.x.
Here is the new "licence":

/* Copyright (c) <2009> <Newton Game Dynamics>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely

*/


So I would say we publish the MogreNewt binary together with the correct newton.dll file.

Also you are welcome to add Newton applications as a sample to the MogreSDK.
If you have questions (or want to have SVN access) look to the thread Mogre SDK development.

GantZ

01-12-2009 11:41:00

in this case, it should be possible to statically link newton to MogreNewt, this way, only one dll will be needed to use newton with mogre.

Beauty

01-12-2009 12:16:32

You mean to add MogreNewt to Mogre.dll?
I think this merge is not so nice, because for each update both parts has to be updated/compiled.
Also maybe somebody don't want to integrate Newton / MogreNewt to a project. So there could be a file not found exception.
For me it's ok to add one more link manually.
Or did I misunderstand you?
Maybe you mean to integrate newton.dll to MogreNewt.dll? This would be ok.

GantZ

01-12-2009 17:50:53

Maybe you mean to integrate newton.dll to MogreNewt.dll? This would be ok.
that's it, i just want to have one MogreNewt.dll without a newton.dll beside it. (like Bekas have done with MOIS)

Beauty

02-12-2009 21:43:05

Some months ago Bekas tried the same for Mogre.
He wanted to put Mogre.dll and Ogre.dll to just one file. (I suppose Ogre.dll)
He said this would solve some problems with add-ons and would make it more easy to integrate/use them.
But when he tried, after some hours of building he had an out of memory problem.
Maybe there is a way to fix it. But ok, this is the wrong thread. It just came into my minde because of you suggestion.

Beauty

03-12-2009 14:13:49

The version number of the current MogreNewt.dll file is 0.0.0.0.
Please update it for the next release.

I would say, the first numbers should be equal to the used Newton.dll. (e.g. 2.10.x.x)
The third or last number we could use for MogreNewt updates related to the used Newton version.

For example 2.10.0.1 ... after an update of our wrapper 2.10.0.2 ... and after using a new Newton library version it becames 2.11.0.0

GantZ

03-12-2009 17:46:29

i have managed to include newton (the 2.11 version) within MogreNewt, try it out and let me know if there is any issue. As always, binary on first post.

About including OgreMain with Mogre, it also in my mind, i will try it when i got a new computer (hopefully soon :)). It would fix all this HRESULT errors and simplify the setup of an application for a newbie. The problem is that OgreMain and Mogre are 2 huge library to process.

CoMPMStR

11-12-2009 21:30:30

I've been using Mogre+MogreNewt for a few months now, and it's been working great until recently when my Framework gets more and more complex. I began encountering access violations ("Attempted to read or write protected memory. This is often an indication that other memory is corrupt.") when I try to implement new classes and methods, but I've been able to get rid of them until now (this time it's occuring with MogreNewt).

If you create a simple project with nothing but 2 entities, then have the entities collide when each other; when the AABB's overlap you will get an access violation (at least I do). Note this only occurs anytime I assign any body a MaterialGroupID greater than 0 (check the commented lines in the OgreSceneCreated method below), and I don't know how to overcome it. Is there any way to prevent getting these access violation exceptions, or is there anything you (GantZ) can do about it? Please note that I'm using VB.NET, but I've also tried the same example in C# and the error appears there as well. Here's a snippet of the example:

using Mogre;
using MogreNewt;
using MogreCore.OgreCore;
using MogreCore.OgreSettings;
using System.Collections.Generic;

public class OgreGame
{
private OgreGraphicsConfig mGraphicConfig;
private bool isQuitting = false;
private System.Drawing.Size winSize = new System.Drawing.Size(800, 600);
private string winTitle = "OgreGame";
private Root mRoot;
private SceneManager mSceneManager;
private RenderWindow mWindow;
private Camera mCamera;
private Viewport mViewport;

const float mUpdate = 1 / 60;
private float mElapsed;
private World mWorld;

private string resourceFile = "resources.cfg";
private string pluginFile = "plugins.cfg";
private string configFile = "ogre.cfg";
private string logFile = "ogre.log";

private bool FrameStarted(FrameEvent e)
{
mElapsed += e.timeSinceLastFrame;
if (mElapsed > mUpdate)
{
mWorld.Update(mUpdate);
mElapsed -= mUpdate;
}
else
{
// this is where the access violation will occur when a MaterialID is assigned
mWorld.Update(mElapsed);
mElapsed = 0;
}

return !isQuitting;
}

private void OgreOptionsRefreshed(OgreGraphicsConfig opt, ref int index)
{
for (int r = opt.Systems.Count; --r >= 0; )
{
if (opt.Systems[r].Name == "Direct3D9 Rendering Subsystem")
{
for (int g = opt.Systems[r].Settings.Count; --g >= 0; )
{
if (opt.Systems[r].Settings[g].Name == "Full Screen")
{
opt.Systems[r].Settings[g].CurrentValue = "No";
}
else if (opt.Systems[r].Settings[g].Name == "VSync")
{
opt.Systems[r].Settings[g].CurrentValue = "Yes";
}
}
}
}
}

private void OgreSceneCreated()
{
//set world size and ambient colour
mWorld.SetWorldSize(new AxisAlignedBox(-1000, -1000, -1000, 1000, 1000, 1000));
mSceneManager.AmbientLight = ColourValue.White * 0.5f;

//create a dynamic entity
Entity mEntity = mSceneManager.CreateEntity("robot", "robot.mesh");
SceneNode mNode = mSceneManager.RootSceneNode.CreateChildSceneNode("robotNode", Vector3.UNIT_Y * 300);
mNode.AttachObject(mEntity);
Vector3 size = new Vector3(1);
mNode.Scale(size);
Vector3 sz = new Vector3(size.x * mNode.GetScale().x, size.y * mNode.GetScale().y, size.z * mNode.GetScale().z);
MogreNewt.CollisionPrimitives.ConvexHull hcollision = new MogreNewt.CollisionPrimitives.ConvexHull(mWorld, mNode, 0, 0);
Vector3 inertia = default(Vector3);
Vector3 com = default(Vector3);
float ms = sz.x * sz.y * sz.z;
hcollision.CalculateInertialMatrix(out inertia, out com);
inertia *= ms;
Body body = new Body(mWorld, hcollision);
hcollision.Dispose();
hcollision = null;
body.AttachNode(mNode);
body.SetPositionOrientation(mNode.Position, mNode.Orientation);
body.SetMassMatrix(ms, inertia);
body.CenterOfMass = com;
body.ForceCallback += BodyForceCallback; //normal gravity callback
//body.MaterialGroupID = new MaterialID(mWorld, 1);
// if the above line is uncommented, the access violation will occur

//create a dynamic entity
mEntity = mSceneManager.CreateEntity("robot0", "robot.mesh");
mNode = mSceneManager.RootSceneNode.CreateChildSceneNode("robot0Node", Vector3.UNIT_Y * -300);
mNode.AttachObject(mEntity);
mNode.Scale(size);
sz = new Vector3(size.x * mNode.GetScale().x, size.y * mNode.GetScale().y, size.z * mNode.GetScale().z);
hcollision = new MogreNewt.CollisionPrimitives.ConvexHull(mWorld, mNode, 0, 0);
inertia = new Vector3();
com = new Vector3();
ms = sz.x * sz.y * sz.z;
hcollision.CalculateInertialMatrix(out inertia, out com);
inertia *= ms;
body = new Body(mWorld, hcollision);
hcollision.Dispose();
hcollision = null;
body.AttachNode(mNode);
body.SetPositionOrientation(mNode.Position, mNode.Orientation);
body.SetMassMatrix(ms, inertia);
body.CenterOfMass = com;
body.ForceCallback += Body1ForceCallback; //reverse gravity callback
//body.MaterialGroupID = new MaterialID(mWorld, 1);
// if the above line is uncommented, the access violation will occur
}

public Vector3 ApplyStandardForce(Body body, Vector3 force)
{
float mass = 0;
Vector3 inertia = new Vector3();
body.GetMassMatrix(out mass, out inertia);
force = force * mass;
body.AddForce(force);
return force;
}

private void BodyForceCallback(Body body, float timeStep, int threadIndex)
{
ApplyStandardForce(body, Vector3.UNIT_Y * -9.8f * 8);
}

private void Body1ForceCallback(Body body, float timeStep, int threadIndex)
{
ApplyStandardForce(body, Vector3.UNIT_Y * 9.8f * 8);
}

public void Run()
{
if (mRoot != null) throw new System.Exception("Ogre is already initialized!");
mRoot = new Root(pluginFile, configFile, logFile);

SetupDirectX();
Initialize();
InitializeResources();
CreateCamera();
CreateViewPort();
mWorld = new World();

OgreSceneCreated();
mRoot.StartRendering();
}

private void SetupDirectX()
{
int gfxindex = 0;
mGraphicConfig = new OgreGraphicsConfig(mRoot);
OgreOptionsRefreshed(mGraphicConfig, ref gfxindex);
mGraphicConfig.SetOptions(gfxindex);
}

private void Initialize()
{
mRoot.Initialise(false, winTitle);
bool fs = (mGraphicConfig.LastSystem.GetByName("Full Screen").CurrentValue == "Yes" ? true : false);
mWindow = mRoot.CreateRenderWindow(winTitle, (uint)winSize.Width, (uint)winSize.Height, fs);
mWindow.Resize((uint)winSize.Width, (uint)winSize.Height);
Vector2 wsize = OgreHelper.GetScreenSize();
mWindow.Reposition((int)(wsize.x / 2 - winSize.Width / 2), (int)(wsize.y / 2 - winSize.Height / 2));
mRoot.FrameStarted += FrameStarted;
mSceneManager = mRoot.CreateSceneManager(SceneType.ST_GENERIC, "CoreSceneManager");
}

private void InitializeResources()
{
ConfigFile cf = new ConfigFile();
cf.Load(resourceFile, "\t:=", true);
ConfigFile.SectionIterator seci = cf.GetSectionIterator();
string secName = null;
string typeName = null;
string archName = null;
while ((seci.MoveNext()))
{
secName = seci.CurrentKey;
ConfigFile.SettingsMultiMap settings = seci.Current;
foreach (KeyValuePair<string, string> pair in settings)
{
typeName = pair.Key;
archName = pair.Value;
ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName);
}
}
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
}

private void CreateCamera()
{
mCamera = mSceneManager.CreateCamera("CoreCamera");
mCamera.Position = new Vector3(0, 500, 500);
mCamera.LookAt(Vector3.ZERO);
mCamera.NearClipDistance = 0.1f;
mCamera.FarClipDistance = 100000f;
}

private void CreateViewPort()
{
mViewport = mWindow.AddViewport(mCamera);
mViewport.BackgroundColour = new ColourValue(0, 0, 0, 1);
}
}

GantZ

13-12-2009 20:34:56

about materialID ,just use the first constructor (without id), it automatically create a new id which is used internally by newton. i don't remember exactly why the second constructor as been added, but it's unusable. i will remove it in further version.

CoMPMStR

14-12-2009 02:21:45

Thank you! That did the trick about the access violation exceptions, but how do I specify my own MaterialID for each entity? Rather than having newton automatically assign a new ID; how can I use, for example, a flag enum as my ID?

I have an enum that defines my materials (rough = 1, smooth = 2, bouncy = 4, etc) and I want to build my MaterialID objects from this enum (what if I don't need to use a Rough material for a certain level). If I construct a MaterialID using only the first parameter, the ID automatically increments instead of using my value of, for example, rough | bouncy or smooth | bouncy. Am I supposed to create a new ID for each combination or is there a better way to go about achieving the same result? Could the ID property be made to read/write instead of just readonly?

GantZ

14-12-2009 18:32:02

i suggest you to use the userdata property of a body, materialpair and contactcallback. you can assign any dotnet type you want to it. you can retrieve it in a ContactCallback later. example :


mybody1.UserData = myenum.value1;
mybody2.UserData = myenum.value2;

mymaterialpair1 = new MaterialPair(m_World, mybodymaterial1, mybodymaterial2);
mymaterialpair1.SetContactCallback(new MyCustomContactCallback());

public class MyCustomContactCallback : ContactCallback
{
public override void UserProcess(ContactJoint contact, float timestep, int threadIndex)
{
object mycustomval = contact.Body0.UserData;
if(mycustomval.ToString() == myenum.value1.ToString()) //here check the value of the body for this contactcallback
//change body property, (velocity, etc...)
}
}


the problem with materialid is that the id property is internal to newton, and there is no way to change it.

CoMPMStR

15-12-2009 15:00:32

Thanks again for the help, everything now works as I expected it to at first. :D I do have another question though.

I am trying to gather some tips on how to create a decent character controller using Newton, but there doesn't seem to be much available on the subject (at least people aren't willing to just post source codes) and it's a little tough getting everything working correctly. I already have the movement and jumping implemented but stair stepping, crouching, and such seems to be harder. Anyway, I came across a post that suggested taking a look at the OgreNewt SVN where there was a demo consisting of a character controller being used in Newton 2.0. After looking through the source I noticed there was an OgreNewt::PlayerController class that isn't available in MogreNewt.

My question is will this be available in the next (or future) release or is there some reason for it not to be? Maybe it could be possible to implement the SimpleVehicle class that's also available on the SVN, allowing it to be inherited in case of a more complex situation? I'm sure I could convert the C++ code to C# or VB but it would be much easier having it available from MogreNewt itself. Thanks again!

GantZ

15-12-2009 17:43:16

about character controller, i have no plan to port it right now. i will probably port it in the future, but for the moment, it's not in my todo list. this is because this feature is not finished on ogrenewt, so for now, you will probably need to implement your own character controller if you want precise behavior.

Vehicle and joint are currently untested with newton 2.0 (and vehicle class is not implemented in the default ogrenewt configuration), I will probably look into it later, but again, it's not top priority for me.

Beauty

16-12-2009 20:02:08

Related to the collision detection:
I use it in my application and it works fine.
But I don't use the callback method. Instead I check the iterator of bodies. (Normally the callback method is better, but my application has special requirements).

You use body.MaterialGroupID = new MaterialID(mWorld, 1).

In my application I use it like this:

// define variables in my class:
MaterialID material1;
MaterialID material2;
MaterialPair materialPair;

// set values in initialization method:
material1 = new MaterialID(myWorld);
material2 = new MaterialID(myWorld);
materialPair = new MaterialPair(myWorld, material1, material2); // MaterialPair is only needed for callback method, not for iterator method

// later set the properity to the bodies:
body1.MaterialGroupID = material1;
body2.MaterialGroupID = material2;


I'm not shure, but I think alternatively you can just set a number to MaterialGroupID. Internally it's just a number.
Example: myBody.MaterialGroupID = 1;
Just try it (and give feedback).

Body.UserData is a great thing!
You can store there everythink you need. (custom properties, references, flags, name of SceneNodes, etc.)

GantZ

16-12-2009 20:26:24

i have upload a new version, compiled against newton 2.13, see first post

Beauty

17-12-2009 00:06:27

The download doesn't include newton.dll. Did you include the file to MogreNewt.dll (as you suggested) or is it needed seperatly?

GantZ

17-12-2009 11:30:17

quote from the first post

up to this version, the newton library is included within the MogreNewt dll, so you don't need to download it separately anymore.

koirat

18-12-2009 18:49:27

God bless you.

GantZ

11-02-2010 18:20:08

new version available ! this version use newton 2.16 and include convexcast class. i also add empty constructor for both basicraycast and basicconvexcast class, so that inheritance is easier.
Thanks to Kraj0t who help me testing this new release :)

kraj0t

12-02-2010 10:49:24

Thanks go to you, dude :-)

idcsteve

22-03-2010 15:53:25

Hi Guys,

I'm in DLL hell. :(

I've installed the Mogre 1.6.5 beta. I've got VC# Express 2008, which I can only make work in debug config, but that's a separate problem. To make life more complicated, I'm running on the 64bit version of Windows 7.

I've tried running MogreNewt with the latest release (viewtopic.php?f=8&t=9193). I think this includes the Newton DLL,
the newton library is included within the MogreNewt dll, so you don't need to download it separately.

So I don't need to include that, right?

Either way, I keep getting FileNotFoundExceptions.

I'm not sure where I've gone wrong - it could be something in the way I've set up the project, which is why it only runs in the debug version. It could be a problem with running a 32 bit app in a 64 bit environment. Or I could be doing something simple wrong with MogreNewt. Does anyone have any suggestions?

I'm happy to provide any details you may need - I just don't know what would be helpful.

Regards,
Steve

idcsteve

22-03-2010 17:17:28

So I went home and used my laptop with XP 32 and the full version of Visual Studio. Miracle of miracles, it works (at least, I'm out of DLL hell, I haven't actually tried to do much with it yet :) ).

So the question is, what is the most likely explanation for why I couldn't run it at work? The debug config or the 64bit configuration? Or some other silly thing that I've missed? Has anyone had any similar experiences?

GantZ

09-05-2010 17:20:37

new version released, see first post

yan007

16-06-2010 17:08:05

Hi all,

could someone plz help me with the following problem:
I had an Ogre + OgreNewt application created in VS 2005
now I want to Convert it to Mogre + Mogrenewt in VS 2010
the Mogre part is already ok but when I add MogreNewt my application keeps crashing (I used the version 2.0 of 09/05)


public void CreateScene()
{
world = new World(); // Adding this line causes an application crash


exception:

A procedure imported by 'MogreNewt.dll' could not be loaded.
DefaultWorkQueue('Root') shutting down on thread main.
Unregistering ResourceManager for type BspLevel
*-*-* OGRE Shutdown
Unregistering ResourceManager for type Compositor

Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at Ogre.Root.{dtor}(Root* )
at Mogre.Root.!Root()
at Mogre.Root.Dispose(Boolean )
at Mogre.Root.Finalize()
Press any key to continue . . .


Trying the demo's also gave me the same exception,

I can't find the cause ..

Y.

Beauty

17-06-2010 00:26:32

Maybe you found my old demo application for collission detection? :lol:
There I used VS 2005.
If so, than there is an old MogreNewt dll file and the newton file is called MogreNewt MOD.dll. The MOD file is just an early wrapper for Newton 2 where most things are commented out. (But world should work.)

Did you use the current versions of dll files for Mogre and MogreNewt?
Also be shure that the MogreNewt.dll file is related to the same Mogre version.
Your exception looks like a problem with the file MogreNewt.dll. Be shure you linked the right MogreNewt.dll file.
Where did you find the demo application?

For updating from VS2005 to VS2010 I can't help you. Couldn't it be imported/converted? Maybe try to convert to VS2008 and then to VS2010.

yan007

17-06-2010 10:42:05

Yes,

about the versions I'm sure:
used Mogre 1.7.1 and for MogreNewt (2.20.0.0) I used the zip:

MogreNewt.zip
Last update 09.05.2010
(730.14 KiB) Downloaded 45 times


For Mogre i used the binairies for VS 2010 (those are for the .Net Framework 4.0), they are provided separatly.
Normally that shouldn't give any problems, because the CLR for 2.0 and 4.0 can work togheter in the same process (for example the MOIS.dll is also for .net 2.0 and it's working fine).

The samples I tried are are located here: https://mogre.svn.sourceforge.net/svnroot/mogre/trunk/MogreNewt/Samples/
Are those correct? Else plz give me the correct URL.
Or can you give me code that works, so I can try that and make sure it's not a bug.

I have some extra questions:
-When will Mogrenewt 2.0 officially be released?
-Will it also be provided with the binairies for the .Net Framework 4.0 just like for Mogre?

Y.

Beauty

17-06-2010 16:28:04

I never used this examples. Maybe I tried 3 years ago, but I can't remember. I even did not know that there are samples in the SVN :lol:
But in general it would be good when they work with the current Mogre version.

Unfortunately I see that no Newton example is in the MogreSDK.
Does somebody has a tiny demo application which we could include to the MogreSDK?



-When will Mogrenewt 2.0 officially be released?
The Newton 2.0 development started about 2 years ago. The beta version official was published about 1 year ago. It seems to be very stable, but the developer wants to remove the beta state only when he's really shure, that it's free of bugs. (He's afraid of bad reputation when it's stable and someone still find a bug.)
I suppose the MogreNewt wrapper works well on applications of users who tried. (we hope bugs will be reported here) But if I know right, not all classes are wrapped (GantZ want to do it when somebody needs). Also there is additional code for useful debugging possibilities. Now there is a question at which point we declare it as stable? Only when a few users tell it works well on their application? On the other hand maybe there are some uncertainties if there could be troubles after switching to Oge 1.7.

In general I would say - give MogreNewt a chance. Be welcome to post about problems (as you did). This improves it's further development.

yan007

17-06-2010 16:59:33

So can somebody give me a possible cause of the problem (see post made 16th june) I'm having with MogreNewt ?

And can somebody create a demo application (preferably convert one of the OgreNewt demos) in VS2010 with the .net 4.0 binairies of Mogre ?

Update: Can somebody plz take a look, because I'm totally blokked by this

GantZ

22-06-2010 14:25:57

hi,

if you use the vs2010 binary of mogre, you need to recompile mogrenewt using vs2010, and using the lib for vs2010. I haven't tried mogrenewt with vs2010 so i cannot assure you that it's work. Also, it seem that newton don't have any lib for vs2010, i don't know if it's possible to use mogrenewt at all in this case.

yan007

22-06-2010 16:49:06

ok, can you give some steps involved in the build process (or is it just creating a vs2010 project, add mogrenewt code and build ?)
Update: I'm trying but didn't realized yet to build, It would be handy if a build step sequence would be posted on the wiki ..

does there already exist a project for this on bitbucket ?

Update: the latest code is on bitbucket right?, because the wiki refers to https://mogre.svn.sourceforge.net/svnroot/mogre/trunk/MogreNewt
What's the reason behind this? Maybe it would be best to have a single place for the code?

I think this is important to investigate because the usage of Visual Studio 2010 will increase a lot and Mogre is already supported for this ..

GantZ

22-06-2010 22:44:39

the problem is, can ogrenewt work with vs2010 ? since newton has no lib for vs2010, i'm not sure it work with it yet.

For the sourcecode of mogrenewt, go on bitbucket here : http://bitbucket.org/gantz/mogre , on the addons directory i have update the vcproj files to the one i have used for the last version (vs2008). Just change the path in the config.

Basically, you just need to provide the path to the ogremain.lib,newton.lib (from the newton sdk) files and the include directory used to compile your mogre version (check out the repository of mstoyke http://bitbucket.org/mstoyke/ogre171vs2010)

you also need to install boost, http://www.boostpro.com/download

Beauty

23-06-2010 08:36:15

I looked to the newton forum.
There seems to be problems with VS 2010. Maybe they will be solved?
Details are here:
http://www.newtondynamics.com/forum/vie ... f=9&t=5911

yan007

23-06-2010 19:39:25

I managed to get MogreNewt build with VS 2010 (so now the target .Net framework is 4.0) but my problem still exists !

It's possible MogreNewt can't handle VS 2010 (I'm not sure if the problem depends on the Newton Game Dynamics library, they don't give support for 2010 but is this really needed?)

I would appreciate if someone could also give it a try because I'm out of ideas AND to be 100% sure it's not possible to use MogreNewt in vs 2010 ..

Beauty

23-06-2010 19:51:04

The MogreNewt.dll file doesn't work with VS 2010?
I thought you just need to link it. If not - is VS 2010 not backward compatible?
If the problems are only related the build process. Is it possible to build the library with VS 2008 and copy it to the VS 2010 project?

yan007

24-06-2010 01:33:03

The MogreNewt.dll doesn't work indeed. But it's a runtime error (see post Wed Jun 16: Unhandled Exception: System.AccessViolationException..).
An idea was to build MogreNewt from source for .net 4.0 in vs 2010, which i did and succeeded. But the runtime error still exists.
Tomorrow I'm gone try to create a project with .net framework 2.0 as target framework. Normally MogreNewt should work in this case.

The backward compatibility depends on the used target .net framework I guess. But default in vs 2010 you create .net 4.0 projects to get the new functionalities .. (also because Mogre already makes this possible)

GantZ

24-06-2010 13:22:36

The problem is that the dll provided here is for the vs2008 version of mogre, it won't work with the vs2010 one. and since newton don't provide a lib for vs2010, you won't be able to compile mogrenewt on vs2010. The only solution here is to try using the vs2008 version of mogre with vs2010, i know that in cpp you can force vs2010 to use vs2008 mode, but i don't know how it could work in csharp.

yan007

24-06-2010 13:31:37

Gantz, as mentioned in a previous post I managed to compile mogrenewt on vs2010 but it gives a runtime error using the dll

I successfully used MogreNewt in a VS 2010 project with .net target framework 2.0
So there is a problem for .net framework 4.0 either with the MogreNewt code OR with the newton game dynamics engine ..
Can this be added to the remaining work so it will be supported in the future?

koirat

30-06-2010 16:19:41

I'm afraid there is something wrong with

MogreNewt.ConvexModifierCollision.ScalarMatrix

It's always null even after you set this property to something else.

Beauty

03-07-2010 13:26:35

This feature I found in the thread Collision detection.
It would be nice when our wrapper includes this functionality (or is it still wrapped?).

Julio pointed me to this one

World.BodyInAABB.Go(AABB aabb)

Besically it will get all the objects inside AABB from the world.

Looks like I will give Newton the second chance :P

koirat

03-07-2010 15:27:58

MogreNewt support's this functionality, that's what I have wrote.
Since I was wrong suspecting that Newton don't have such a capabilities and Julio introduced me to this function.

In Newton this function is called

NewtonWorldForEachBodyInAABBDo

yan007

04-07-2010 01:30:08

I get the following error 'MogreNewt.Debugger' does not contain a definition for 'Instance'
the purpose is to show the body lines

I found the following solution:
MogreNewt.Debugger debugger;
debugger = new Debugger(world);
debugger.Init(sceneMgr);
debugger.ShowDebugInformation();


Is this ok? Or can the error be solved?

Beauty

04-07-2010 18:03:26

If I remember right, the debug tools of MogreNewt needs some ressources (maybe a special font?).
Sorry - more I can't tell you, because I didn't find the discussion posts.
Is there an interesting log entry in the ogre log file?

yan007

05-07-2010 07:53:25

And there is also a class missing: MogreNewt.Vehicle ?

Beauty

05-07-2010 14:09:30

My application throwed AccessViolationExceptions.

NewtonReleaseCollision(NewtonWorld* , NewtonCollision* )
MogreNewt.Collision.!Collision()
MogreNewt.Collision.Dispose(Boolean )
MogreNewt.CollisionPrimitives.ConvexHull..ctor(World world, SceneNode node, Single tolerance, Int32 id)
... (my application)


"OGRE EXCEPTION(2:InvalidParametersException): Object index out of bounds.
in SceneNode::getAttachedObject at ..\\src\\OgreSceneNode.cpp (line 159)"


Then I found out the reason:
When MogreNewt wants to create a ConvexHull of a SceneNode which has no attached mesh then this error happens.
This also happens when the first attached entity is a ManualObject (the ManualObject bug I added to the bug list many months ago).

ConvexHull colHull = new MogreNewt.CollisionPrimitives.ConvexHull(
nWorld, targetNode, collisionHullTolerance, 0); // CRASH when no mesh attached


The related wrapper code I found in the file OgreNewt_CollisionPrimitives.cpp
at this method:

// MogreNewt::CollisionPrimitives::ConvexHull
void ConvexHull::_ctor( Mogre::SceneNode^ mnode, Mogre::Quaternion orient, Mogre::Vector3 pos ,dFloat tolerance,int id)
{
Ogre::SceneNode* node = mnode;

Ogre::Vector3 scale(1.0,1.0,1.0);


//get the mesh!
Ogre::Entity* obj = (Ogre::Entity*)node->getAttachedObject(0);
Ogre::MeshPtr mesh = obj->getMesh();

// ...

float matrix[16];

MogreNewt::Converter::QuatPosToMatrix( orient, pos, &matrix[0] );

//okay, let's try making the ConvexHull!
m_col = NewtonCreateConvexHull( m_world->NewtonWorld, (int)total_verts, (float*)&vertices[0].x, sizeof(Ogre::Vector3),tolerance, id,&matrix[0] );

delete []vertices;

}


My suggestion:
Add a check to see if there is an entity attached and if it's a mesh.
If not then we could we have this options:
1) throw an exception (not nice, but the programmer will know the reason)
2) call NewtonCreateConvexHull() with an empty vertex list (the best way if this works without problems)
3) set m_col to null, so the method CollisionPrimitives.ConvexHull() returns null
Additionally there could be added a warning to the ogre.log file: "Warning: Can't create ConvexHull from SceneNode 'MyNAME', because there is no entity attached."

Inside the same method we could add a switch for an attached ManualObject.
Instead of catching the mesh vertices, we would catch the ManualObject vertices.
Or (temporarily) create a mesh from the ManualObject and use the same processing.

Unfortunately I have so less C++ knowledge that I can't do the work.
Maybe someone else like to do it?

(In my application I will add an entity check before calling the ConvexHull method. But an check inside the wrapper)

Beauty

05-07-2010 15:14:47

I found out, inside Ogre there is no attached type called mesh.
Objects attached to a SceneNode are called MovableObject. And attached Meshes have the type name Entity.


Now I tried to write a checker code.
Some code is redundant, because of different log entries (warnings) and the extend possibility for ManualObject support.
But I don't know if the syntax is right nor I know if it works.
Maybe somebody can add and test it?


void ConvexHull::_ctor( ... )
{
Ogre::SceneNode* node = mnode;

Ogre::Vector3 scale(1.0,1.0,1.0);

if (node->numAttachedObjects() == 0)
{
// TODO: send warning to ogre.log

// create empty hull // DOES IT WORK??
float matrix[16];
MogreNewt::Converter::QuatPosToMatrix(Mogre::Quaternion::IDENTITY, Mogre::Vector3::ZERO, &matrix[0]);
Ogre::Vector3* vertices = new Ogre::Vector3[0];
m_col = NewtonCreateConvexHull( m_world->NewtonWorld, (int)0, (float*)&vertices[0].x, sizeof(Ogre::Vector3), tolerance, id, &matrix[0] );
}
else
{
if (node->getAttachedObject(0)->getMovableType() != "Entity")
// if (node->getAttachedObject(0)->getMovableType() == "ManualObject")
// {
// TODO: process for ManualObject
// e.g. by converting ManualObject to Entity (Mesh)
// }
// else
{
// TODO: send warning to ogre.log

// create empty hull // DOES IT WORK??
float matrix[16];
MogreNewt::Converter::QuatPosToMatrix(Mogre::Quaternion::IDENTITY, Mogre::Vector3::ZERO, &matrix[0]);
Ogre::Vector3* vertices = new Ogre::Vector3[0];
m_col = NewtonCreateConvexHull( m_world->NewtonWorld, (int)0, (float*)&vertices[0].x, sizeof(Ogre::Vector3), tolerance, id, &matrix[0] );
}

/ ...

yan007

06-07-2010 08:47:00

1)Does anybody know why the method 'CalculateInertialMatrix' is missing for a MogreNewt.CollisionPrimitives.CompoundCollision
is this a bug or is there an alternative ?

2)before in a previous version of OgreNewt I used the method body->setStandardForceCallback();
does this still exist and how is it called in MogreNewt?
Update: Found: body.IsGravityEnabled = true;

3)Could someone update MogreNewt.Vehicle (is missing because of changes in Newton Game Dynamics 2.x)

Beauty

06-07-2010 14:10:31

1)Does anybody know why the method 'CalculateInertialMatrix' is missing for a MogreNewt.CollisionPrimitives.CompoundCollision
is this a bug or is there an alternative ?


I'm really not shure, but maybe in Newton 2 there is no need for InertialMatrix.
I also was confused about this (or an other) method and then I read that it was removed (by the Newton author). The calculation was needed for an other method (collision creation??). Now the calculation of the "helper" function is inside the other method.
Maybe it was the CalculateInertialMatrix method.


3)Could someone update MogreNewt.Vehicle (is missing because of changes in Newton Game Dynamics 2.x)
I don't know if there is currently an active developer. The MogreNewt maintainer GantZ retired some weeks ago.
Even when we get no new maintainer for the next time, I hope some people do update or add some parts (what depends to their personal need) and then publish it.

I'm not shure, but I suppose that MogreNewt is similar to OgreNewt. If you want to update something yourself, have a look to the sister project. This could help when you see how the wrapper works for Ogre applications.

yan007

08-07-2010 23:16:08

1) I believe CalculateInertialMatrix is the new function in Newton 2, but only for compound collision its missing
Maybe in a compound collision the inertia is the sum of all subobjects and you have to calculate that manually?

3) I did some research for the Vehicle:
In Newton 2 is has moved from the basic joints to the custom joints. As far as I know custom joints haven't been implemented in OgreNewt
so we have to wait for this first.

ianhfar

09-07-2010 13:42:48

The new debug setting for version 2 is


public void Init_Newton()
{
// Newton initialization
m_World = new World();
m_World.SetWorldSize(new Vector3(-500, -200, -500), new Vector3(500, 200, 500));
m_World.DebuggerInstance.Init(sceneMgr);
m_World.DebuggerInstance.ShowDebugInformation();
} // Init_Newton()


This seems to have been changed since Beauty provided his examples

was

// Newton initialization
m_World = new World();
MogreNewt.Debugger.Instance.Init(sceneMgr);
MogreNewt.Debugger.Instance.ShowLines(m_World);


Hope this helps

Beauty

09-07-2010 18:12:22

My examples are related to Newton 2, but it uses only a developer Newton 2.0 library and an early MogreNewt wrapper prototype (the full change from Newton 1 to 2 was to difficult for me).
Later MogreNewt got a professional update by user GantZ. Also he added an improved debugging system (similar to the OgreNewt one).
So my collision detection examples are a little bit outdated and I suppose the debugger code has to be changed.
But it basically shows how you can do collision detection with Newton 2.

Right, I should update my examples to the current MogreNewt state.
Also it would be good to update the related wiki pages. E.g. page Collision detection with Newton. There I added an (outdated?) snippet how to enable the debugger.

yan007

12-07-2010 07:09:24

Beauty,

I think it would be great to ad a page in the MogreNewt wiki "Porting v1.53 to v2.0" or something,
if you update your examples to the current MogreNewt it's easy to find the differences, as mentioned before in this thread there are at least 3 changes I know:

1) MogreNewt.Debugger replaced with

world.DebuggerInstance.Init(sceneMgr);
world.DebuggerInstance.ShowDebugInformation();


2) Vector3 inertia = MogreNewt.MomentOfInertia.CalcBoxSolid(mass, size); replaced with

MogreNewt.ConvexCollision _colPrimitives = new MogreNewt.CollisionPrimitives.ConvexHull(m_World, scenenode, 0);
_colPrimitives.CalculateInertialMatrix(out inertia, out offset);
inertia = inertia * mass;

3) Vehicle class
Not implemeted yet (moved to custom joints)

Update:
I noticed the following link is broken: "For MogreNewt 2.0, You can find the binary here : MogreNewt 2.0 Binary" ..

Beauty

14-07-2010 20:28:36

Thanks for your feedback.
My examples are still based on Newton 2.0, but an early beta version.
Newton 1.x I never used. So I can't write details to the wiki for porting.
But right, something like a FAQ section for porting could be interesting.
The main task should be to update the current wiki content to the current state. (e.g. the dead download link)
Also somewhere was an 1.x MogreNewt sample. (in the SVN? Or in a very old SDK?) This could be updated.
A second focus would be how to use Newton (e.g. with snippets or demos).
In my eyes an update guide is less interesting. This would only focus to people who have still experiences.
Newcomers want/should start with Newton 2.x directly.

In my case I have only experiences with the collision detection. Physics I never used. So I can't write much about.
Every help on the wiki is welcome :D

update:
The download link I updated in the wiki, but much more update work is needed.

Also I found the old newton examples:
https://mogre.svn.sourceforge.net/svnro ... t/Samples/
Are they still in the new Mercurial repository?
If yes, are they updated for current Mogre versions and Newton 2?

yan007

15-07-2010 01:08:22

But right, something like a FAQ section for porting could be interesting.
Ok, you are right, first the main wiki should be updated, but could you at least create a page with the stuff i mentioned (it cost me some time to find those answers so I'm sure its handy ..)

If I find time I will update the basics example, the vehicle example isn't possible to update because the customvehicle joint should be implemented in OgreNewt (then after this in MogreNewt)
I'll send you the code if I'm ready

Beauty

19-07-2010 10:31:30

GantZ, in your first post you still have the download link
http://bitbucket.org/[b]gantz[/b]/mogre/src/tip/Addons/MogreNewt

The source code is on our new Mogre main repository, too.
http://bitbucket.org/[b]mogre[/b]/mogreaddons/src/tip/MogreNewt

So it would be better to change the URL in your first post and make your private repository readonly or remove it to avoid confusions.
I also could update your first post, but I don't know if both repositories have the current state of development or if one is newer.

Currently my wiki work is idle, because at home I have no internet for a while. And at work I don't have so much time.
At home I want to update my collision examples. Maybe also the other demos. When it's done, I'll publish it here.

the vehicle example isn't possible to update because the customvehicle joint should be implemented in OgreNewt
Is somebody here who also follows the OgreNewt (C++) development?
If so, it would be great to give us a notice, when the custom vehicle joint is implemented there or when there are other interesting/important changes.

GantZ - you was the maintainer of MogreNewt.
Can you tell us the current state in comparism to OgreNewt?
You wanted to keep synchronized with the OgreNewt development. (e.g. implement the improved debugging system)
What's the current state? Are there some things missing or important differences?

GantZ

19-07-2010 19:34:58

i have update the link on the first post.

the last version of MogreNewt is related to the revision 2766 of the ogrenewt svn. I will remove rights to my repo later, but i think most people who have write access already know about the last repository location.

mstoyke

20-07-2010 10:16:47

Please let me know if anybody needs write access to the new addon repository at bitbucket/mogre. Just send me a PM with the bitbucket username(s) I should add (and in case it does not match the username in these forum, let me know who is who).

Beauty

09-08-2010 13:16:58

Some months ago I created a thread in the OgreNewt forum section about the HeightFieldCollision feature:
Terrain with Newton 2.0 (API NewtonHeightFieldCollision)

There someone published a code snippet with which you can use this Newton function.
Did somebody port this code to C#?

If yes, it would be useful to include this code directly to the MogreNewt wrapper.


A problem for me is that the C++ code uses the class member Ogre::Terrain.
In Mogre I can't find something like this. Is Ogre::Terrain the new terrain manager?
Also the snippet author wrote it's needed to add #include<OgreTerrain.h> to the file OgreNewt_Prerequisites.h.

For my main application I use the Terrain Scene Manager. But I couldn't find out how to access its data. I just see, that terrain data can be loaded from a config file by SceneManager.SetWorldGeometry(). Is there a way how to get access to the internal terrain data? (e.g. the matix of the height values)

Beauty

09-08-2010 13:58:38

This I found in the OgreNewt forum section:
OgreNewt should now work with Ogre 1.7.1 and there are also solution and project files for VS2010.

There is also a new environment variable that needs to be set:
"OGRE_BUILD_HOME" - directory where you built your Ogre 1.7

Give it a spin and let me know if something does not work and better yet, a solution :wink:

But I wrote there would be still problems with the OgreNewt demos under VS2010.

What's about MogreNewt?
Is it usable now with Visual Studio 2010?
Any experiences?

Beauty

09-08-2010 14:05:28

I found an interesting post of the Newton developer.
When I tried to update the MogreNewt wrapper for use with Newton 2.0 (long time ago) I was confused of the different newton lib files and didn't know which to use. (In the 2.0 beta16 were 6 types of the newton.lib file)

This is why I like mt libraries, the make bigger EXE but the are self contained and run on any version of windows.
while the md, will link to the version of the run time you have in your system but they required intaller to install a runtime.

mt are good for end casual users hwo do no wnat to install, but not good for develeopers
md are good for developers but the end user will have to run intaller.
I guess you wnat and mt that is good for developers so that he can make apps for end user that do not require installation.


Maybe it's interesting for somebody to know :wink:

Pyritie

09-08-2010 19:19:30

where would be the best place to get mogrenewt help? Here?

Beauty

10-08-2010 12:52:31

There are no specific rules.
I would say the main task of this thread is for development/update of MogreNewt.
Also for bug reports or whishes.


When you need information how to do something with Newton or if you have problems by using Newton I would suggest this:

* For general questions (how Newton works, its logic, etc.) you find good help in the external Newton forum.

* For questions how to do something in interaction with Ogre (and Mogre), you can use the OgreNewt section of the Ogre Add-ons forum. There is a better chance to get an answer, because there are much more users who know to handle with Newton. Here in the Mogre section are not so much people with Newton knowledge (because C++ Ogre is more common).

* For Mogre and MogreNewt specific questions the Mogre section of this forum is a good place. Just create a new topic (your topic title should include the word MogreNewt).


A good help could also be:

* Newton wiki
* Newton API description - seems to be only related to Newton 1.x, but most functions are similar

Beauty

17-09-2010 10:15:31

There is an open MogreNewt question since ~4 weeks in the thread powered hinge problem.
Maybe somebody knows a solution, but didn't see the post.

koirat

20-09-2010 22:15:46

Today I stumbled upon some Bug in MogreNewt.
Basically there is a World property in Collision class but it is always NULL.
When you try to use CollisionSerializer.ExportCollision it throws NullReferenceException since it is using World from collision object.

Right now I will try to forcibly set it via Reflection on collision object, but such a hack can't be a solution.

GantZ

21-09-2010 19:43:47

do you use a collision object that is not linked to a body ? I use CollisionSerializer.ExportCollision with the collision of a body and the treecollisionsceneparser, and haven't encountered this bug.

koirat

21-09-2010 20:57:21

No I was using collision from Body.Collision.
Strange maybe I'm using some old MogreNewt version.
I will check this out.

koirat

21-09-2010 21:22:51

Collision.World is set to Null after I Dispose of it.
I'm calling Dispose since I assume it is doing the same as NewtonReleaseCollision.
And there is a reference counter in newton anyway so it will collect collision after it is no longer used.


MogreNewt.CollisionPrimitives.TreeCollisionSceneParser treeParser = new MogreNewt.CollisionPrimitives.TreeCollisionSceneParser(world);
treeParser.ParseScene(node, optimize, id);
MogreNewt.Body bod = new Body(world, treeParser);
treeParser.Dispose();

GantZ

22-09-2010 18:34:29

The fix here would be to remove setting the world reference of the collision object to null in Dispose().

I always use exportcollision before disposing my collision object, so it wasn't a problem for me.

koirat

22-09-2010 20:30:07

Do you think it should be changed ?
Are you (or somebody) MogreNewt maintainer or is it free for all ?

GantZ

23-09-2010 18:24:37

NewtonReleaseCollision could be put in a dedicated function in the collision object. i think dispose must be called only when you no longer need the object, so it seem logical that the world reference is set to null.

there is no official maintainer for mogrenewt right now, so it's FFA :) .

zeroonea

19-10-2010 21:32:45

What is different between MogreNewt.dll and MogreNewt_d.dll? I can not get it work with visual 2008. When running, it throw exception below

The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Error at line:


MogreNewt.World world = new MogreNewt.World();


Edit:

I'm using mogre dll from this: http://nchc.dl.sourceforge.net/project/ ... 008Libs.7z and mogrenewt dll in first post of this topic. Exception is File not found but it not display which file is missing. Should need to copy Newton.dll and which version?

GantZ

20-10-2010 18:07:28

you get the error with the two dll ? it's usually an error related to ogremain.dll that is not found by mogre.dll (should be in the same folder of your exe). The _d version is for debug, it allow you to step in the code of the dll. (you need the source of mogrenewt on your computer). Also, the debug version require that you use the _d version of mogre and all of it plugins.

Should I need to copy Newton.dll and which version?
No, the version used is the 2.20, but the newton lib is included in the mogrenewt one, so you don't need it.

prefer using the dll from the sdk http://sourceforge.net/projects/mogre/, that's the one i use, i can't assure you that it's work with other dll without recompilation.

zeroonea

20-10-2010 21:12:27

I monitor with process monitor and figure out ogremain.dll is missing. It work great now.

zeroonea

21-10-2010 09:37:06

I dig into an example at https://mogre.svn.sourceforge.net/svnro ... /Basics.cs and write a code below. Game crash at line stat_col.ParseScene(floor_node, true, 0); with no exception. If I change collision primitives to box, it work fine.


SceneNode floor_node = SceneMgr.RootSceneNode.CreateChildSceneNode("floor");
floor = SceneMgr.CreateEntity("floor1", "simple_terrain.mesh");
floor.SetMaterialName("Simple/BeachStones");
floor.CastShadows = false;
floor_node.AttachObject(floor);
floor_node.SetPosition(80.0f, 0.0f, 0.0f);
floor_node.Scale(20f, 20f, 20f);

MogreNewt.CollisionPrimitives.TreeCollisionSceneParser stat_col = new MogreNewt.CollisionPrimitives.TreeCollisionSceneParser(mWorld);
stat_col.ParseScene(floor_node, true, 0);//Crash here with no exception
//MogreNewt.CollisionPrimitives.Box stat_col = new MogreNewt.CollisionPrimitives.Box(mWorld, new Vector3(1500, 10, 1500), 1);
MogreNewt.Body floor_body = new MogreNewt.Body(mWorld, stat_col);
stat_col.Dispose();
floor_body.AttachNode(floor_node);

GantZ

21-10-2010 20:09:51

try to use this code instead.

stat_col.ParseScene(SceneMgr.RootSceneNode, true, 0);

GantZ

26-10-2010 18:21:37

i have update mogrenewt to 2.25 version of newton. check first post for the binaries

Beauty

24-11-2010 17:12:47

Today I tried to update my application from Ogre 1.6.4 to 1.7.1.
Also I updated the MogreNewt library from version "0.0.0.0" (Date: 2009-12-16) to the current version (2.25.0.0).

Unfortunately now I get crashes when I enable my Newton based collision detection.
(Without Newton the Mogre library seems to work fine after tiny code modifications.)

The AccessViolationExceptions happens at call of

MogreNewt.CollisionPrimitives.ConvexHull colHull = ...
// ...
MogreNewt.Body body = new MogreNewt.Body(mWorld, colHull);
// CRASH

Several bodies can be created but somewhen there is this exception.
The collision hulls are very similar. (Cubes created by 8 vertices)
Exactly the same objects never throwed an exception with my older libraries.


Additionally:
When I don't get a crash at Body creation then I get a crash at an other place.
In this case (for some unknown reason) the Dispose() method of my application will be called.
My application dispose method tries to dispose Newton and the result is an AccessViolationException again:

if (nWorld != null)
mWorld.Dispose();
// CRASH

The call of my the application Dispose happens before finishing the loop for object creation.


I can't figure out the source of the problem.
So I think I will switch back again to the older Mogre and MogreNewt libraries.

But I wanted to give you a feedback and tell you that there are some problems (which I didn't had in an older MogreNewt version).
So I suppose: Either it's a problem of the MogreNewt wrapper or a problem of Newton itself.

If somebody has any idea how we could find out more details about the problem, just tell me.
If anybody likes to debug himself -- maybe I can update my "Newton Test Application" to reproduce the problem. But I only will touch my test application, if somebody is really interested to use it for debugging. (In other cases the test application update would be waste of time.)

Beauty

24-11-2010 18:16:04

To localise the MogreNewt problem I would like to:
* try the last version related to Mogre 1.6 and
* try the first published version related to Mogre 1.7.

Unfortunately these binary files aren't any more available .
Does somebody has them? Maybe GantZ?

Additionally somebody could try to wrap and compile my working newton.dll file against Mogre 1.7.1.
Then we know if the exceptions are related to the new Mogre version or the newton.dll library.
(If there are wrapping problems because of changed/added Newton functions, just comment them out.)
Here you can download my old (working) newton library which has the file date 2010-12-16, but no version number (just 0.0.0.0)
http://rapidshare.com/files/432888596/newton.dll

Beauty

30-11-2010 12:55:00

The archives with the precompiled libraries doesn't contain the XML commentation file, which is very important for development. By use of this file you can see a description for the class members of MogreNewt inside of Visual Studio.

So it would be great, when you add the file MogreNewt.xml to the binary download file.

You can download the current version here:
http://mogresdk.googlecode.com/svn/trun ... reNewt.xml
(right click, save target as ...)

If you want to build a new XML commentation file (e.g. for a newer version), you can use the tool of smiley80.
Details you find on this wiki page.

GantZ

03-12-2010 12:06:51

Here The 2.16 version compiled against 1.6.5 version.

[attachment=0]MogreNewt_2_16.zip[/attachment]

I haven't a working vc++ 2008, so i can't try to compile a version with 1.7 and an old newton release. the only thing i could say is that MogreNewt haven't change between 1.6 and 1.7. so it's either a problem with newton or Mogre 1.7

Beauty

03-12-2010 12:23:56

Thanks!
I'll check it next week when I'm back at home.

Beauty

07-12-2010 19:15:14

Here is my report:
MogreNewt for Newton 2.16 compiled against Mogre 1.6.5 works fine with my application.

If you will have a working vc++ 2008 again, you could try this:
* compile Newton 2.16 against Mogre 1.7.x
* compile the latest Newton version against Mogre 1.6.5
Then I can check them to see if Newton or Mogre causes the exceptions.

By the way - is there a public documentation how to compile MogreNewt?
Maybe I can try to do the compile job myself.

GantZ

07-12-2010 19:24:21

everything needed is on the addons repository. the only thing you need to take care is to update the include / library / using path. the best way is to link to the latest sdk files. it's what i use to compile mogrenewt.

so far, i haven't be able to fix my install, i would like to avoid reinstalling windows. now, i will remember not touching the winsxs folder anymore :)

FrozenKiller42

17-12-2010 22:29:03

Hi all,

When I try to create a TreeCollision in MogreNewt 2.25, I get a AccessViolation

MogreNewt.CollisionPrimitives.TreeCollision col;

col = new MogreNewt.CollisionPrimitives.TreeCollision(mWorld, ent, true, 1);

MogreNewt.Body bod = new MogreNewt.Body(mWorld, col); //VIOLATION HERE
col.Dispose();

bod.AttachNode(Node);
bod.IsGravityEnabled = true;


bod.SetPositionOrientation(Node.Position, Node.Orientation);


I am using .NET 4.0 with VS 2010 Ultimate

TIA

Beauty

18-12-2010 16:27:01

Note: I moved the last post (from a seperate forum topic) to here.

I'm not shure, but some months a go I did read, that the Newton library has problems with Visual Studio 2010.
I don't know if this was/is right. You could try to run the same code by VS 2008 to see if this is the reason.
If somebody else has good/bad experiences with VS2010 in combination with MogreNewt, please give us a short feedback.

TreeCollisions I never used.
Does it work with MogreNewt.CollisionPrimitives.ConvexHull ?
Is you entity ent a Mesh or a ManualObject?
When I tried to create a ConvexHull from a ManualObject I got a crash, because in the past it wasn't supported by the MogreNewt wrapper. (Is this problem fixed now? If not - maybe a solution can be found in OgreNewt.)

koirat

11-02-2011 20:01:48

I find automatic interpolation of graphics in OgreNewt very useful. But i don't see

world->setUpdateFPS(..);

In the latest update (if this one in this thread is the latest) of MogreNewt, are there any plans for an update ?

Also I have got another questions that is puzzling me, why we are not wrapping OgreNewt is performance hit that big ?

Beauty

11-02-2011 22:50:57

A wrapper for a wrapper?
Ok, OgreNewt is more than a wrapper. It adds more functionality.

Generally a wrapper is more easy to maintain.

The opposites in case of MogreNewt are:
* A wrapper-wrapper has to be created from the scratch. (To add new functions of MogreNewt needs less effort.)
* The chance to have wrapper problems (e.g. because of bad wrapper code) is higher for a wrapper-wrapper.
(Just my personal view. I don't know technical details, maybe I'm wrong.)

I don't know how complex the OgreNewt and MogreNewt is.
If it's complex and changes (inside the wrapper) are big, then a wrapper-wrapper could be useful in the long term.
If the code is light wight or the changes/additions are only tiny, then it would be useful to just port the modified code.


By the way:

* Were there many modifications for OgreNewt in the last months? (e.g. related to the debug display system.)
* GantZ ported the debug display system (many months ago). Are there some parts of the OgreNewt wrapper which aren't yet ported/added to MogreNewt?

Just to get an overview of the wrapper state.

Beauty

07-03-2011 12:53:53

A Mogre user published the source code of a project, which can visualize bodies of MogreNewt.
The aim is to contruct compound collisons.

The application uses the MogreNewt debugger to display the newton bodies. I wanted a way where I could try manually build up a compound collision type. For example if I had a chair made up of 6 blocks, 4 legs, a horizontal seat and a sloping back rest. I wanted and for this simple example can manually place,scale and rotate the Newton box coillisions around the Mesh and then combine them to make a corresponding compound collision.



The project isn't finished and the author wants to stop the develop.
Maybe it's useful for somebody who follows this MogreNewt topic.
So I want to give indicate to this project.

Details are here:
MogreNewt Visualisation tool

ianhfar

07-03-2011 14:43:47

FrozenKiller42

Try changing your face winding order of the tree collision.

eg.

MogreNewt.Collision col = new MogreNewt.CollisionPrimitives.TreeCollision(
world, node, false, 0, MogreNewt.CollisionPrimitives.FaceWinding.FW_REVERSE);

Beauty

24-04-2011 12:51:55

One month ago somebody created a forum topic with a detailed bug report.
The source can be inside the MogreNewt wrapper with high priority.
Until today there was no answer.

If you don't know this topic and like to know details, look here:
Mogre+MogreNewt = buggy raycasts

Beauty

06-08-2011 10:54:08

Good news:
Our new community member Cygon updated Mogre for 1.7.3.
He also updated the MogreNewt wrapper.

* Added Newton 2.33 binaries (both x86 and x64 builds)
* Updated MogreNewt to work with Newton 2.33, also fixed a minor bug in the wrapper


The download link is in the first post of this forum topic.
We would be happy if people test it and give a feedback.

Beauty

12-09-2011 21:49:54

Last weekend I tried the builds of Cygan.
The bundle of Mogre and MogreNewt works fine with my application and I had no problems.

Important:
The file MogreNewt.dll of Cygan does NOT contain the file Newton.dll.
You have to grabb it from his archive (in an other directory) and add it to your binary directory.

gKreator

15-10-2011 08:46:37

I downloaded the MogreNewt lib http://www.ogre3d.org/addonforums/download/file.php?id=668 Last update 26.10.2010 and tried the https://mogre.svn.sourceforge.net/svnroot/mogre/trunk/MogreNewt/Samples/Basics/ I have all the references but I get tons of errors. Is there a new MogreNewt Lib?

Beauty

19-10-2011 21:59:11

Hi gKreator,

the MogreNewt.dll file has to be compiled against the same Mogre version as you have as Mogre.dll.
Also some MogreNewt.dll binaries needs the newton.dll file (in the same version used for compiling MogreNewt).

I suggest to use the Mogre 1.7.3 binary bundle of user Cygon.
It also contains MogreNewt.dll and newton.dll in the correct version.

The MogreNewt examples are very old and the Newton and MogreNewt API changed a little bit.
So I suppose you have to update some lines of the example code.
Unfortunately nobody updated the examples. If you get them run, we would be happy when you publish the updated source code. :wink:

Beauty

05-03-2012 09:18:03

Many months ago, user amirabiri started to create the MogreBuilder tool for an easy and mostly automatically wrapping and building process of Mogre.
McDonte and Zarifus continued the work. Most problems are solved and it seems to work fine.

Why I write this to this topic?
It would be great, if we add an option to the MogreBuilder tool for building the MogreNewt binaries, too.
I think it's not difficult (by support of user Zarifus).
So if anybody is interested to help on this point, then raise your hand in the topic My mission to build a better Mogre.

Beauty

06-03-2012 10:39:50

Where is the lastest state of MogreNewt? :?:

The lastest version which I found is in on bitbucket.org/mogre/mogreaddons in directory MogreNewt.
It seems so that the code there wasn't touched since February 2011.


Somebody (GantZ?) improved MogreNewt by inspiration of new OgreNewt features (e.g. improved debug visualisation).
Where is this code?
I would like to have it in the official repository.
Especially now, when user Zarifus wants to extend his MogreBuilder to automatically build MogreNewt.

Beauty

06-03-2012 10:43:16

I find automatic interpolation of graphics in OgreNewt very useful. But i don't see

world->setUpdateFPS(..);

In the latest update (if this one in this thread is the latest) of MogreNewt, are there any plans for an update ?

Also I have got another questions that is puzzling me, why we are not wrapping OgreNewt is performance hit that big ?

Well, your post is one year old.
Now I wanted to add your suggestion to the bug tracker and recognized, there is no one for the Mogre add-ons.
So I created a bug tracker in our official repository.
There can be inserted all suggestions and bugs.


The first entry is your one about setUpdateFPS(...).

Beauty

19-03-2012 21:05:42

Here is a quote from an other topic, where GantZ gives notes for building MogreNewt.
Thanks Gantz. :D
Just a quick note about MogreNewt, since there is some confusion about how it's built, and where is the source code :

  1. The last version of MogreNewt is on the mogreAddons repository over bitbucket, it worked with newton 2.25[/*:m]
  2. Last time I built it, no version of newton were available for vs10. now that newton is open source, you probably can build it for vs10.[/*:m]
  3. The repository for the newton source code is available over googlecode : http://code.google.com/p/newton-dynamics/[/*:m]
  4. The build of MogreNewt is pretty straightforward, just compile it directly using visual studio,or use msbuild to automate the process. you need to download the newtonsdk first, assure yourself that you target the last mogre lib file. It's build like most of the plugins outside of the ogre project range (hydrax, caelum, skyx, etc...)[/*:m][/list:u]

    You can use the existing vc9 project file as a reference if you want to build it for vc10.

Beauty

19-03-2012 21:29:03

Ok, I also added your notes to the MogreNewt wiki page.
http://www.ogre3d.org/tikiwiki/tiki-ind ... nary_notes

Well, that page would need a fresh up.
So if somebody like to do that, Newton newcomers will be happy. :wink:

crankyslap

15-10-2012 12:27:39

I picked up the MogreNewt source code from the repo and am now trying to build it agains Ogre 1.7.4 / Mogre 1.7.4 and Newton 2.25 (that's the Newton version the source was linking against) but I am receiving the following error:

error C2440: 'delete' : cannot convert from 'Ogre::ManualObject' to 'void *'
In MogreNewt_Main\src\OgreNewt_Debugger.cpp:508

I have no experience with c++ so I don't know what to do.. any help? ;)

void Debugger::ClearRaycastsRecorded()
{
if( m_raycastsnode )
{
m_raycastsnode->removeAndDestroyAllChildren();
}

for each(ManageRaycastObject rObj in mRecordedRaycastObjects)
{
delete(*rObj.RaycastObject); //Right here
}

mRecordedRaycastObjects->Clear();
}

I am building as Release/Win32

Beauty

29-10-2012 00:25:44

MogreNewt and MogreBuilder


Sorry for my late answer.
I don't know this kind of error and have no idea what's the reason. (My C++ knowledge is bad.)
Perhaps there is a version problem. (linking vom MogreNewt to Ogre/Mogre and to Newton)

How did you build MogreNewt?
By use of MogreBuilder or manually?

If you use MogreBuilder, it will create the needed Ogre/Mogre source files.

MogreBuilder should be able to compile the MogreNewt add-on, too.
For this use the MogreBuilder option "-mogrenewt".
The first run will fail (for building MogreNewt), but will create the subdirectory input_Newton in the MogreBuilder target directory.
<YourMogreBuilderTargetDirectory> \ MogreAddons \ MogreNewt \ MogreNewt_Main \ input_Newton

There you need to insert the needed Newton files manually. (newton.lib, etc.)
You find them inside of the download bundles at the Newton website.
After inserting the files, you should call MogreBuilder again (with the "-mogrenewt" option).


Note:
Several months ago I updated the paths of the MogreNewt configuration (in Visual Studio project settings).
Now I commited the changes to the MogreAdd-ons Repository.
To get the latest sources of MogreNewt, you should use an empty target directory for the MogreBuilder.
Then MogreBuilder will download them again (instead of using the previous source files).


I know, this is no good written "guide". Nevertheless I hope you understand what I mean.
If you try MogreBuilder for building MogreNewt, please post a small report.
For questions I try to help.

Additionally I can offer to upload my compiled bundle of Mogre and MogreNewt.

Beauty

29-10-2012 15:27:50

Today I checked my MogreNewt stuff, which I updated a half year ago.
Unfortunately I had no time to commit the changes to the official repository.

Now I spend several hours for figuring out the changes, build tests and repository updates.
The needed Newton files I uploaded to the download section of the official MogreAddons repository.
Additionally I wrote a small guide for building MogreNewt.

You find the latest MogreNewt sources here:
https://bitbucket.org/mogre/mogreaddons

Now it compiles against Newton 2.35.

Here are the build instructions (which I added here to the repository).


Some instructions for compiling MogreNewt.
======================================================


It's recommend to use the MogreBuilder (with option "-mogrenewt") for some preparations.


1)
Call MogreBuilder with the option "-mogrenewt".
It builds Mogre, download the MogreNewt sources and creates some needed subdirectories.



2)
Call MogreBuilder again with the option "-mogrenewt -onlyaddons"
It doesn't build Mogre again, but copies some needed files to the MogreNewt subdirectories.



3)
Download the needed filed of the Newton library.

You find them here:
https://bitbucket.org/mogre/mogreaddons ... s_2.35.zip

If the link is dead, look here:
https://bitbucket.org/mogre/mogreaddons/downloads
http://code.google.com/p/newton-dynamics/downloads/list

Copy the files of the zip package to the directory "input_Newton".

You find this directory at this path:
<MogreBuilderTargetDirectory> \ MogreAddons \ MogreNewt \ MogreNewt_Main \ input_Newton



4)
Open the file "MogreNewt_VS2010.sln" with Visual Studio and compile it.

Important:
Choose the "Release" build setting before you build.
You can do this by the ComboBox below the menu of Visual Studio.
Otherwise you will get a "Mogre_d.dll not found" error.



5)
Copy the files "MogreNewt.dll" AND "newton.dll" to the binary directory your project.

"newton.dll" you find here:
<MogreBuilderTargetDirectory> \ MogreAddons \ MogreNewt \ MogreNewt_Main \ input_Newton

"MogreNewt.dll" you find here:
<MogreBuilderTargetDirectory> \ MogreAddons \ MogreNewt \ MogreNewt_Main \ lib \ Release




For questions related to MogreNewt use this forum topic:
viewtopic.php?f=8&t=9193

For questions related to MogreBuilder use this forum topic:
viewtopic.php?f=8&t=29272


Greetings
Beauty
(written in 2012)


Well, currently MogreBuilder can't build MogreNewt.
But in current state it does some useful preperations.
It creates the needed Ogre/Mogre files and copy them to specific directories (related to my updated MogreNewt configuration).

Beauty

09-01-2014 07:18:26

TODO:
Add the improvement of user ianhfar to the official repository.
(But please test the modification, before you put it into the repository. The improvement was posted in November 2012.)
viewtopic.php?p=100349#p100349

QUOTE:
-----------------------------------
Hi Beauty

With MogreNewt / Newton 2.34 , I used to use "GetBodyCollisionID" to get the subcomponent from a compound mesh. This is no longer available in Newton 2.35 upwards. I have made a change to the following files to provide similar functionality on 2.35 upwards.

I have attached the two files I changed, I am not sure if everybody would want to use this, so I have left it open, let me know if I should submit this as a patch.

The changes reside in the following two Mogrenewt files

ContactMaterial.h and ContactMaterial.cpp


int ContactMaterial::GetBodyCollidingShapeID( MogreNewt::Body^ body )
{
NewtonCollision* col = NewtonMaterialGetBodyCollidingShape (_mat, body->NewtonBody);
NewtonCollisionInfoRecord *info = new NewtonCollisionInfoRecord();
NewtonCollisionGetInfo( col, info );
return info->m_collisionUserID;
}


Seems I'm getting an error saying
Sorry, the board attachment quota has been reached.
when trying to upload attachment

so here's the code
ContactMaterial.h

#pragma once

#pragma managed(push, off)
#include <Newton.h>
#include <Ogre.h>
#pragma managed(pop)
#include "OgreNewt_Prerequisites.h"
#include "OgreNewt_Collision.h"

// OgreNewt namespace. all functions and classes use this namespace.
namespace MogreNewt
{

ref class Body;

public value class ContactMaterial
{
NewtonMaterial *_mat;

internal:
ContactMaterial(NewtonMaterial *material);

public:
property unsigned ContactFaceAttribute
{
unsigned get();
}

// NOTE: This function was removed in Newton 2.34
// unsigned GetBodyCollisionID( MogreNewt::Body^ body );

int GetBodyCollidingShapeID( MogreNewt::Body^ body );

property dFloat ContactNormalSpeed
{
dFloat get();
}

Mogre::Vector3 GetContactForce( MogreNewt::Body^ body );

Mogre::Vector3 GetContactPosition( MogreNewt::Body^ body );

Mogre::Vector3 GetContactNormal( MogreNewt::Body^ body );

Mogre::Vector3 GetContactFirstTangent( MogreNewt::Body^ body );

Mogre::Vector3 GetContactSecondTangent( MogreNewt::Body^ body );

void GetContactPositionAndNormal(
MogreNewt::Body^ body,
[Out] Mogre::Vector3 %position, [Out] Mogre::Vector3 %normal
);
void GetContactTangentDirections(
MogreNewt::Body^ body,
[Out] Mogre::Vector3 %dir0, [Out] Mogre::Vector3 %dir1
);
dFloat GetContactTangentSpeed(int index);


//! set softness of the current contact
void SetContactSoftness( Mogre::Real softness ) { NewtonMaterialSetContactSoftness( _mat, (float)softness ); }

//! set elasticity of the current contact
void SetContactElasticity( Mogre::Real elasticity ) { NewtonMaterialSetContactElasticity( _mat, (float)elasticity ); }

//! set friction state of current contact
void SetContactFrictionState( int state, int index ) { NewtonMaterialSetContactFrictionState( _mat, state, index ); }

//! set tangent acceleration for contact
void SetContactTangentAcceleration( Mogre::Real accel, int index ) { NewtonMaterialSetContactTangentAcceleration( _mat, (float)accel, index ); }

//! align tangent vectors with a user supplied direction
void RotateTangentDirections( Mogre::Vector3 dir ) { NewtonMaterialContactRotateTangentDirections( _mat, &dir.x ); }

//! manually set the normal for the collision.
void SetContactNormalDirection( Mogre::Vector3 dir ) { NewtonMaterialSetContactNormalDirection( _mat, &dir.x ); }

//! manually set the acceleration along the collision normal.
void SetContactNormalAcceleration( Mogre::Real accel ) { NewtonMaterialSetContactNormalAcceleration( _mat, accel ); }

//! Set friction for contact
void SetContactFrictionCoef(dFloat staticFrictionCoef, dFloat kineticFrictionCoef, int index)
{NewtonMaterialSetContactFrictionCoef(_mat,staticFrictionCoef,kineticFrictionCoef,index);}
};


} // end namespace MogreNewt



ContactMaterial.cpp

#include <ContactMaterial.h>
#include "OgreNewt_Body.h"
#include "OgreNewt_Collision.h"

namespace MogreNewt
{

ContactMaterial::ContactMaterial(NewtonMaterial *material) {
if (material == NULL)
throw gcnew Exception("Cannot create a Material from a null NewtonMaterial");
_mat = material;
}


// NOTE: This function was removed in Newton 2.34

//unsigned ContactMaterial::GetBodyCollisionID( MogreNewt::Body^ body )
//{
// return NewtonMaterialGetBodyCollisionID( _mat, body->NewtonBody );
//}

int ContactMaterial::GetBodyCollidingShapeID( MogreNewt::Body^ body )
{
NewtonCollision* col = NewtonMaterialGetBodyCollidingShape (_mat, body->NewtonBody);
NewtonCollisionInfoRecord *info = new NewtonCollisionInfoRecord();
NewtonCollisionGetInfo( col, info );
return info->m_collisionUserID;
}

unsigned ContactMaterial::ContactFaceAttribute::get()
{
return NewtonMaterialGetContactFaceAttribute(_mat);
}

dFloat ContactMaterial::ContactNormalSpeed::get()
{
return NewtonMaterialGetContactNormalSpeed(_mat);
}


Mogre::Vector3 ContactMaterial::GetContactForce( MogreNewt::Body^ body )
{
Mogre::Vector3 force;
NewtonMaterialGetContactForce( _mat, body->NewtonBody, &force.x );
return force;
}

Mogre::Vector3 ContactMaterial::GetContactPosition( MogreNewt::Body^ body )
{
Mogre::Vector3 pos, norm;
GetContactPositionAndNormal(body, pos, norm);
return pos;
}

Mogre::Vector3 ContactMaterial::GetContactNormal( MogreNewt::Body^ body )
{
Mogre::Vector3 pos, norm;
GetContactPositionAndNormal(body, pos, norm);
return norm;
}

Mogre::Vector3 ContactMaterial::GetContactFirstTangent( MogreNewt::Body^ body )
{
Mogre::Vector3 t1, t2;
GetContactTangentDirections(body, t1, t2);
return t1;
}

Mogre::Vector3 ContactMaterial::GetContactSecondTangent( MogreNewt::Body^ body )
{
Mogre::Vector3 t1, t2;
GetContactTangentDirections(body, t1, t2);
return t2;
}

void ContactMaterial::GetContactPositionAndNormal(
MogreNewt::Body^ body, Mogre::Vector3% pos, Mogre::Vector3% norm
)
{
pin_ptr<Mogre::Vector3> p_pos = &pos;
pin_ptr<Mogre::Vector3> p_norm = &norm;
NewtonMaterialGetContactPositionAndNormal( _mat, body->NewtonBody, &p_pos->x, &p_norm->x );
}


void ContactMaterial::GetContactTangentDirections(
MogreNewt::Body^ body, Mogre::Vector3% dir0, Mogre::Vector3% dir1
)
{
pin_ptr<Mogre::Vector3> p_dir0 = &dir0;
pin_ptr<Mogre::Vector3> p_dir1 = &dir1;
NewtonMaterialGetContactTangentDirections( _mat, body->NewtonBody, &p_dir0->x, &p_dir1->x );
}

dFloat ContactMaterial::GetContactTangentSpeed(int index) {
return NewtonMaterialGetContactTangentSpeed(_mat, index);
}

} // end namespace MogreNewt