A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Beauty » Wed Aug 13, 2008 5:21 am
I have a little problem with updating MogreNewt for
Mogre (Managed Ogre for .NET).
The problem is SOLVEDIn Newton 2 the method
NewtonBodyForEachPolygonDo is removed and we should use the new method
NewtonCollisionForEachPolygonDo.
But there are more parameters now and I don't know what they mean and where to get it.
Definition Newton 1:
NEWTON_API void
NewtonBodyForEachPolygonDo (const NewtonBody* body, NewtonCollisionIterator callback);
Definition Newton 2:
NEWTON_API void
NewtonCollisionForEachPolygonDo (const NewtonCollision* collision,
const dFloat* matrix, NewtonCollisionIterator callback,
void* useData);
The
collision I can get from
myBody.Collision. In the SDK examples
useData is NULL. But what's about
matrix?
Here is the code where I need it (which chreates debug lines of collisions).
- Code: Select all
void Debugger::ShowLines( MogreNewt::World^ world )
{
m_debugnode->detachAllObjects();
m_debugger_debuglines->clear();
// make the new lines.
//OLD NewtonWorldForEachBodyDo(world->NewtonWorld, Debugger_newtonPerBody); // World, IteratorCallback
//NEW_BEGIN --> moved code of old IteratorCallback function Debugger_newtonPerBody //
for (const NewtonBody* body = NewtonWorldGetFirstBody (world->NewtonWorld);
body;
body = NewtonWorldGetNextBody (world->NewtonWorld, body))
{
//OLD int state = NewtonBodyGetSleepingState(body);
int state = NewtonBodyGetSleepState(body); // NEW
// We choose the color depending on the state of the body.
if (state == 1)
m_debugger_debuglines->begin("__OgreNewt__Debugger__Green__",
Ogre::RenderOperation::OT_LINE_LIST );
else
m_debugger_debuglines->begin("__OgreNewt__Debugger__Red__",
Ogre::RenderOperation::OT_LINE_LIST );
//OLD NewtonBodyForEachPolygonDo( body, Debugger_newtonPerPoly );
NewtonCollisionForEachPolygonDo( body, Debugger_newtonPerPoly ); // NEW
m_debugger_debuglines->end();
} // for
//NEW_END
m_debugnode->attachObject(m_debugger_debuglines);
}
And this is the definition of the IteratorCallback function:
- Code: Select all
void _CDECL Debugger_newtonPerPoly( const NewtonBody* body, int vertexCount, const float* faceVertec, int id )
{
Ogre::Vector3 p0, p1;
int i= vertexCount - 1;
p0 = Ogre::Vector3( faceVertec[(i*3) + 0], faceVertec[(i*3) + 1], faceVertec[(i*3) + 2] );
for (i=0;i<vertexCount;i++)
{
p1 = Ogre::Vector3( faceVertec[(i*3) + 0], faceVertec[(i*3) + 1], faceVertec[(i*3) + 2] );
m_debugger_debuglines->position( p0 );
m_debugger_debuglines->position( p1 );
p0 = p1;
}
}
Last edited by
Beauty on Thu Aug 14, 2008 9:35 am, edited 1 time in total.
-

Beauty
-
- Posts: 30
- Joined: Tue Apr 29, 2008 7:37 am
- Location: Germany
-
by Julio Jerez » Wed Aug 13, 2008 8:50 am
The function is more flexible now because you can render collision info for any shape, all yo unee to do is get teh matrix and teh shape form teh body
here is teh modifyed function.
- Code: Select all
void Debugger::ShowLines( MogreNewt::World^ world )
{
m_debugnode->detachAllObjects();
m_debugger_debuglines->clear();
// make the new lines.
//OLD NewtonWorldForEachBodyDo(world->NewtonWorld, Debugger_newtonPerBody); // World, IteratorCallback
//NEW_BEGIN --> moved code of old IteratorCallback function Debugger_newtonPerBody //
for (const NewtonBody* body = NewtonWorldGetFirstBody (world->NewtonWorld);
body;
body = NewtonWorldGetNextBody (world->NewtonWorld, body))
{
//OLD int state = NewtonBodyGetSleepingState(body);
int state = NewtonBodyGetSleepState(body); // NEW
// We choose the color depending on the state of the body.
Ogre::Matrix matrix;
NewtonCollision* collision;
NewtonBodyGetMatrix (body, &matruix[0][0])
collision = NewtonBodyGetCollision(bopy);
if (state == 1)
m_debugger_debuglines->begin("__OgreNewt__Debugger__Green__", Ogre::RenderOperation::OT_LINE_LIST );
else
m_debugger_debuglines->begin("__OgreNewt__Debugger__Red__", Ogre::RenderOperation::OT_LINE_LIST );
NewtonCollisionForEachPolygonDo (collision, matrix, Debugger_newtonPerPoly, NULL "or any userData want to pass");
m_debugger_debuglines->end();
} // for
//NEW_END
m_debugnode->attachObject(m_debugger_debuglines);
}
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Beauty » Wed Aug 13, 2008 10:56 am
The code I had to change a little bit, but now there is no compiler error - Thanks again
update:Oh, now there are compiler errors. See code comment. Maybe I need a fload variable instead of a matrix?
(I choosed a 3x3 matrix)
- Code: Select all
Mogre::Matrix3 matrix;
NewtonCollision* collision;
NewtonBodyGetMatrix (body, &matrix[0][0]); // ERROR accepting not 1 or 0 arguments
collision = NewtonBodyGetCollision(body);
NewtonCollisionForEachPolygonDo (collision, matrix, Debugger_newtonPerPoly, NULL);
// ERROR can't convert the second parameter to float
By the way - I think you have a small
mistype in definition of
NewtonCollisionForEachPolygonDo.
The last parameters name is
useDate instead of
userData (with U).
This was confusing me.
I think it's related of this line of
Newton.h- Code: Select all
NEWTON_API void NewtonCollisionForEachPolygonDo (const NewtonCollision* collision, const dFloat* matrix, NewtonCollisionIterator callback, void* useData);
-

Beauty
-
- Posts: 30
- Joined: Tue Apr 29, 2008 7:37 am
- Location: Germany
-
by Julio Jerez » Wed Aug 13, 2008 11:32 am
Ha thanks for the bug report, I will change the syntact error
Mogre::Matrix3 matrix, doesn't Ogre has normal 4 x 4 transformation matrices?
if not you can just use a simple 4 x 4 array of
float matrix[4][4];
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Beauty » Wed Aug 13, 2008 3:56 pm
There is also a
Matrix4 class for 4x4.
I didn't know which one I need.
The
Matrix3 and
Matrix4 classes are both of
Real types (the same like
float)
Tomorrow I'll work again. Now I'm tired and drunken

-

Beauty
-
- Posts: 30
- Joined: Tue Apr 29, 2008 7:37 am
- Location: Germany
-
by Beauty » Thu Aug 14, 2008 6:18 am
I still have problems with parameter
matrix.
In the SDK examples I couldn't find helping code.
Here are my trials:
- Code: Select all
Mogre::Matrix4 matrix;
NewtonBodyGetMatrix (body, &matrix[0][0]); // ERROR accepting not 1 or 0 arguments
- Code: Select all
float matrix[4][4];
NewtonCollisionForEachPolygonDo (collision, matrix, Debugger_newtonPerPoly, NULL);
// ERROR can't convert the second parameter from "float [4][4]" to "const float *"
- Code: Select all
const float matrix[4][4]; // ERROR const object must be initialized
NewtonBodyGetMatrix (body, &matrix[0][0]);
// ERROR can't convert the second parameter from "const float *" to "float *"
NewtonCollisionForEachPolygonDo (collision, matrix, Debugger_newtonPerPoly, NULL);
// ERROR can't convert the second parameter from "const float [4][4]" to "const float *"
Newton_API of
NewtonCollisionForEachPolygonDo needs
const dFloat* matrix.
Maybe this is the problem?
Its definition is inside of sour SDK:
- Code: Select all
class dMatrix
{
public:
dMatrix ();
dMatrix (const dVector &front, const dVector &up, const dVector &right, const dVector &posit);
dMatrix (const dQuaternion &rotation, const dVector &position);
dVector& operator[] (int i);
const dVector& operator[] (int i) const;
dMatrix Inverse () const;
dMatrix Transpose () const;
dMatrix Transpose4X4 () const;
dVector GetXYZ_EulerAngles() const;
dVector RotateVector (const dVector &v) const;
dVector UnrotateVector (const dVector &v) const;
dVector TransformVector (const dVector &v) const;
dVector UntransformVector (const dVector &v) const;
dVector TransformPlane (const dVector &localPlane) const;
dVector UntransformPlane (const dVector &globalPlane) const;
void TransformTriplex (void* const dst, int dstStrideInBytes,
void* const src, int srcStrideInBytes, int count) const;
dMatrix operator* (const dMatrix &B) const;
bool SanityCheck() const;
dVector m_front;
dVector m_up;
dVector m_right;
dVector m_posit;
};
By the way -- are the matrices constant for each object?
If so, I could optimize the code.
-

Beauty
-
- Posts: 30
- Joined: Tue Apr 29, 2008 7:37 am
- Location: Germany
-
by Julio Jerez » Thu Aug 14, 2008 8:04 am
try
float matrix[4][4];
NewtonCollisionForEachPolygonDo (collision, &matrix[0][0], Debugger_newtonPerPoly, NULL);
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Beauty » Thu Aug 14, 2008 8:58 am
Ok, the matrix works fine
Then I got an error for the third parameter of
NewtonCollisionForEachPolygonDoThis changing the callback function this problem was fixed.
The reason: The
definition of type NewtonCollisionIterator changed.
Newton 1:
typedef void (*NewtonCollisionIterator) (const NewtonBody* body, int vertexCount, const dFloat* FaceArray, int faceId);Newton 2:
typedef void (*NewtonCollisionIterator) (void* userData, int vertexCount, const dFloat* faceArray, int faceId);I write it here, because (I think) this change was not documented until now. Maybe somebody need this information.
-

Beauty
-
- Posts: 30
- Joined: Tue Apr 29, 2008 7:37 am
- Location: Germany
-
by Overhertz » Tue Jan 25, 2011 12:58 pm
sorry to bring up an old thread but i'm also having problems since newton 2, drawing lines in the correct position seems impossible, sizes, and everything is off..
note i am using delphi, irrlicht and newton 2.28

i have tried multiple by NewtonToIrr but this makes it much too small. and also size is least of the problem, if i moved the model of the vehicle, everything is drawn wrong, note that all collisions work perfectly, only drawing debug does not.

the code i am using is :
- Code: Select all
procedure DebugShowGeometryCollision(userData: Pointer; vertexCount: Integer; const faceVertec: PFloat; id: Integer); cdecl;
var
i: Integer;
line: vector3df;
p0, p1: PVector3df;
begin
if userData = nil then exit;
{$POINTERMATH ON}
i := vertexCount - 1;
p0 := getVector3dfp(faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
for i := 0 to vertexCount-1 do begin
p1 := getVector3dfp(faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
device.getVideoDriver.draw3DLine(p0, p1, RGB(0,0,255));
p0 := p1;
end;
{$POINTERMATH OFF}
end;
procedure DebugCallback(); cdecl;
var
m: matrix4;
//m: array[0..3, 0..3] of Float;
body: PNewtonBody;
begin
body := NewtonWorldGetFirstBody(nWorld);
while body <> nil do begin
NewtonBodyGetMatrix(body, m.pointer);
NewtonCollisionForEachPolygonDo(NewtonBodyGetCollision(body), m.pointer, DebugShowGeometryCollision, NewtonBodyGetUserData(body));
body := NewtonWorldGetNextBody(nWorld, body);
end;
end;
-

Overhertz
-
- Posts: 112
- Joined: Mon Jul 06, 2009 11:19 am
-
by JernejL » Tue Jan 25, 2011 1:59 pm
Are you rendering the final objects & push/pop matrixes in proper transformation? i can vouch that debug rendering in delphi with newton 2.0 works 100% correctly, this is definetly a bug somewhere in your code.
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Overhertz » Wed Jan 26, 2011 3:24 am
rendering is handled by Irrlicht engine.
-

Overhertz
-
- Posts: 112
- Joined: Mon Jul 06, 2009 11:19 am
-
by Overhertz » Fri Jan 28, 2011 2:51 pm
i'm still having alot of problems with drawing debug, and it so far seems that for example i've added a vehicle, and the vehicle debug lines are sent for the body of a wheel, and so on, like 1 body forward, so the body rolls instead of a mesh of the wheel.
is there no way to enable the old newton 1 style debug output? it worked perfectly.
-

Overhertz
-
- Posts: 112
- Joined: Mon Jul 06, 2009 11:19 am
-
by Julio Jerez » Fri Jan 28, 2011 3:04 pm
The old style is the same as the new style.
you just need to get the matrix form teh body and call the debug display on teh collision shape
look at teh file DebufDisplay.cpp in the demos. It is quite simple
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Overhertz » Fri Jan 28, 2011 3:10 pm
i looked, but none of those worked, however i just solved it, i needed to set world transform to the matrix of the first body from newton.
- Code: Select all
procedure DebugCallback(); cdecl;
var
m: matrix4;
body: PNewtonBody;
begin
body := NewtonWorldGetFirstBody(Newton.World);
NewtonBodyGetMatrix(body, m.pointer);
irrVideo.setTransform(ETS_WORLD, m.pointer);
NewtonCollisionForEachPolygonDo(NewtonBodyGetCollision(body), m.pointer, RenderDebugCollision, body); //to save calling getmatrix twice.
body := NewtonWorldGetNextBody(Newton.World, body);
while body <> nil do begin
NewtonBodyGetMatrix(body, m.pointer);
NewtonCollisionForEachPolygonDo(NewtonBodyGetCollision(body), m.pointer, RenderDebugCollision, body);
body := NewtonWorldGetNextBody(Newton.World, body);
end;
end;
-

Overhertz
-
- Posts: 112
- Joined: Mon Jul 06, 2009 11:19 am
-
by Julio Jerez » Fri Jan 28, 2011 4:09 pm
But the do work, I use the in the demo.
If you run the sdk demo and you go to teh emny and click "Show Debug Display"
you will see that it calls
void DebugRenderWorldCollision (const NewtonWorld* world)
that function iterat obver twkl worl renring teh collision meshes, teh funtion tah you have to look at are:
- Code: Select all
static void DebugSubmitGeometryCollision (void* userData, int vertexCount, const dFloat* faceVertec, int id)
{
id;
int i = vertexCount - 1;
dVector p0 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
dVector color(1, 1, 1, 1);
if (userData) {
color = *((dVector*)userData);
}
for (int i = 0; (i < vertexCount) && (debugPointsCount < MAX_DEBUG_CONTACTS); i ++) {
dVector p1 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
debugDisplayList[debugPointsCount].m_color = color;
debugDisplayList[debugPointsCount].m_p0 = p0;
debugDisplayList[debugPointsCount].m_p1 = p1;
debugDisplayList[debugPointsCount].m_isContact = false;
debugPointsCount ++;
p0 = p1;
}
}
void DebugDrawCollision (const NewtonCollision* collision, dMatrix& matrix, dVector color)
{
NewtonCollisionForEachPolygonDo (collision, &matrix[0][0], DebugSubmitGeometryCollision, &color);
}
void DebugShowBodyCollision (const NewtonBody* body, void* userData)
{
dFloat mass;
dFloat Ixx;
dFloat Iyy;
dFloat Izz;
userData;
int sleepState = NewtonBodyGetSleepState(body);
if (sleepState == 1) {
// indicate when body is sleeping
glColor3f(0.42f, 0.73f, 0.98f);
} else {
// body is active
glColor3f(1.0f, 1.0f, 1.0f);
}
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
if (mass > 0.0f) {
dMatrix matrix;
NewtonBodyGetMatrix(body, &matrix[0][0]);
NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(body), &matrix[0][0], DebugShowGeometryCollision, NULL);
} else {
NewtonCollision* collision;
NewtonCollisionInfoRecord info;
collision = NewtonBodyGetCollision (body);
NewtonCollisionGetInfo (collision, &info);
switch (info.m_collisionType)
{
// case SERIALIZE_ID_TREE:
case SERIALIZE_ID_SCENE:
case SERIALIZE_ID_USERMESH:
case SERIALIZE_ID_HEIGHTFIELD:
{
break;
}
default:
{
dMatrix matrix;
NewtonBodyGetMatrix(body, &matrix[0][0]);
NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(body), &matrix[0][0], DebugShowGeometryCollision, NULL);
break;
}
}
}
}
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest