[Irrlicht-Newton] Centre of world aligning?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

[Irrlicht-Newton] Centre of world aligning?

Postby Kapitan » Sun Oct 19, 2008 1:52 pm

Hi,
i don't know if it's the right place...

I've a little problem on aligning the collision "mesh"
of newton and the IMesh on irrlicht...

I know the problem isn't a real problem because the
use of matrix's trasformation, but i wish to debug
my Newton collision and bodies, so i've tried to
draw some line3d in Irrlicht engine with vertex
taken from Newton's Callbacks.

I've red this:

* Using 3DSMax 5 and .3DS format

Set your units and system units to the units you're going to base your physics on (e.g. metres). After creating the object you wish to export, centre it to 0,0,0 and reset the pivot. This will make the created collision object match the imported mesh in global space properly.

But don't know if this works even if the exported object is
different from a 3ds mesh, and if it's a complete scene instead
of a single object.

In IrrNewt package i've seen that the author uses a conversion,
he multiplies vertices by a number (32.0f), but in my case this
would done a complete mess...

Any advice?

Thanks.
Kapitan
 
Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Julio Jerez » Sun Oct 19, 2008 7:23 pm

I am confused as to what you are trying to do.

basically you can see a newton body as a root node.
The collision is a child o fteh node and it is offset by teh collision offset matrix.

also the body can have a cenetr of mass that is indepened from teh body origin.

for example say you have a box with a pivot at teh botton.

you can make a Box that is off set by the height/2 for the bottom,
teh you can set teh cenetr of mass also at height/2

that will make teh body att as a regular newtgonia physics object with its origin at the center of mass, but it will behave as a game object with a pivot at the bottom
it gives you the most flexibility.
Julio Jerez
Moderator
Moderator
 
Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Kapitan » Mon Oct 20, 2008 1:56 am

No, is not a mass problem, is simply a visualization problem.

From NewtonForEachPolygonDo i take the vertices of the body
and i try to display it on irrlicht with the "line3d" function.

But the problem is (maybe) that Newton and Irrlicht world centre
are not the same, so the two are in different positions.

Or something else goes wrong but i don't know why.

I'll insert a jpg soon and some code.

Thanks.
Kapitan
 
Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Julio Jerez » Mon Oct 20, 2008 7:39 am

can you post and image of who it looks?
Julio Jerez
Moderator
Moderator
 
Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Kapitan » Mon Oct 20, 2008 2:36 pm

Collision.JPG
Collision.JPG (48.07 KiB) Viewed 6441 times


Here is the file, Red is the Bounding Box, Yellow is the Collision Mesh
taken from NewtonForEachPolygonDo.
Kapitan
 
Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Julio Jerez » Tue Oct 21, 2008 9:27 am

Are you using 2.0 beta 17?
Is the collision a convex hull?
Julio Jerez
Moderator
Moderator
 
Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Kapitan » Tue Oct 21, 2008 3:07 pm

No i'm not using beta, and yes is a convex hull
Kapitan
 
Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Julio Jerez » Wed Oct 22, 2008 10:03 am

ok it look look the object inside is smaller.
it the object entiretly inside the collision mesh of offset?
Julio Jerez
Moderator
Moderator
 
Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Kapitan » Wed Oct 22, 2008 1:40 pm

Sorry, i've posted a bad image.

The yellow is not bigger, but traslated in the x,y,z direction.
I'll post another image in the future.

The function that builds the collision takes the coordinates
and adds them to the NewtonConvexHullCollision. No other
operations are done.

Probably the problem is that x,y,z in the irrlicht world are
not the same as newton's world.

Naturally they depends on world center, that is not correlated
between the two (i mean irr and newt).

So i've asked if someone else have had this problem, that is
only a visualization problem, because the matrix taken from
newton can be applied on irrlicht mesh without the "x,y,z problem".

This is my opinion and don't know if true, so i've asked....
Kapitan
 
Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Stucuk » Thu Oct 23, 2008 6:34 am

Are you removing the Position from the object's vertex's when you are passing them to newton so the center of the object is (0,0,0)? AFAIK newton doesn't automaticaly center your objects and takes whatever is at (0,0,0) as the center by default.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Kapitan » Fri Oct 24, 2008 7:40 am

I've not understood, i post some code:

Code: Select all
void MyDiceApp::NewtonDebugCollision(const NewtonBody* body, int vertexCount, const dFloat* faceVertec, int id)
{
   
   int i;
   i = vertexCount - 1;

   
   
   core::vector3df p0 (faceVertec[i * 3 + 0] * kNewtonToIrr, faceVertec[i * 3 + 1] * kNewtonToIrr, faceVertec[i * 3 + 2]* kNewtonToIrr);
   
   if (driver != 0) {
      
      video::SMaterial material;
      material.Lighting = false;
      driver->setMaterial(material);
      driver->setTransform(video::ETS_WORLD, core::matrix4());
      for (i = 0; i < vertexCount; i++) {
         core::vector3df p1 (faceVertec[i * 3 + 0] * kNewtonToIrr, faceVertec[i * 3 + 1] * kNewtonToIrr, faceVertec[i * 3 + 2] * kNewtonToIrr);
         
                        driver->draw3DLine (p0, p1, AYELLOW);

         p0 = p1;
      }
}


Code: Select all
void MyDiceApp::NewtonDebugBody (const NewtonBody* body)
{
   dFloat *nMinVertex = new dFloat(); // 3*3 floats
   dFloat *nMaxVertex = new dFloat();

   irrAllocatorFast<dFloat> *iaf = new irrAllocatorFast<dFloat>;
   nMinVertex = (dFloat*)iaf->allocate(3);
   nMaxVertex = (dFloat*)iaf->allocate(3);
   NewtonBodyGetAABB(body,nMinVertex,nMaxVertex);
   
   vector3df irrMinVert = NewToIrrFloatVector(nMinVertex);
   vector3df irrMaxVert = NewToIrrFloatVector(nMaxVertex);
   
   irrMinVert *= kNewtonToIrr;
   irrMaxVert *= kNewtonToIrr;

   video::SMaterial material;
   material.Lighting = false;
   driver->setMaterial(material);
   core::matrix4 mat;
   driver->setTransform(video::ETS_WORLD, mat );
   aabbox3df box(irrMinVert,irrMaxVert);
   driver->draw3DBox(box,ARED);

   iaf->destruct(nMinVertex);
   iaf->destruct(nMaxVertex);
    if (debugMode == 2)
      NewtonBodyForEachPolygonDo(body, MyDiceApp::NewtonDebugCollision);

}


Code: Select all
irr::u32 nMeshBuffer = 0; //Mesh Buffer count
   IMeshBuffer *mesh_buffer = 0;
   dFloat *vertices; //Array to store vertices

   u32 nVertices = 0;

   for( nMeshBuffer=0 ; nMeshBuffer < irr_mesh->getMeshBufferCount() ; nMeshBuffer++ )
   {
      nVertices += irr_mesh->getMeshBuffer(nMeshBuffer)->getVertexCount();
   }

   vertices = new dFloat[nVertices * 3];
   u32 tmpCounter = 0;

   for( nMeshBuffer=0 ; nMeshBuffer < irr_mesh->getMeshBufferCount() ; nMeshBuffer++ )
   {

      mesh_buffer = irr_mesh->getMeshBuffer(nMeshBuffer);

      if (mesh_buffer->getVertexType() != EVT_STANDARD)
         return 0;

      S3DVertex *S3vertices = (S3DVertex*)mesh_buffer->getVertices();

   for(irr::u32 i=0; i<mesh_buffer->getVertexCount(); i++)
   {

         vertices[tmpCounter++] = S3vertices[i].Pos.X;
         vertices[tmpCounter++] = S3vertices[i].Pos.Y;
         vertices[tmpCounter++] = S3vertices[i].Pos.Z;

      }

   }

   //Create Newton collision object
   NewtonCollision *collision_obj = NewtonCreateConvexHull(nWorld,nVertices,vertices,sizeof(float)*3,NULL);

   //delete vertices
   delete [] vertices;


First two are callback, the third is the creation of ConvexHull, don't worry
about the kNewtonToIr, its value is 1.0f.
Kapitan
 
Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Kapitan » Sun Oct 26, 2008 8:01 am

I've maybe found.
I'm really a newbie, i'm forgetting to pass the 4x4 matrix
from Irrlicht to Newton.

Now i gave set the trasform matrix with NewtonBodySetMatrix
and with NewtonBodyGetMatrix i'll take and apply for displaying
the collision mesh.

The Trasform Matrix is used in the collision
detection right?

And the newton trasform callback returns me a matrix
that i can apply directly on irrlich mesh, or i have
to add that matrix to the irrlich trasform matrix?
Kapitan
 
Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Julio Jerez » Sun Oct 26, 2008 12:35 pm

you apply the matrix directly.
It there a reason why you do no wnat to try teh newer vertion?
It is a lot easier to help you if you are in teh newrte version, send me a PM
Julio Jerez
Moderator
Moderator
 
Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Kapitan » Mon Oct 27, 2008 2:06 pm

And The NewtonBodySetMatrix i think has the same meaning
than the Trasform Matrix but is the first applied on the collision
(for collision detection for example) in all newton operations?

Or i have to insert all vertices after applying the initial irrlicht
matrix of traslation, rotation and scale?

And,finally, in my callback for trasformations do i have to take
collision than apply the NewtonBodyGetMatrix, then the
Matrix passed by to the callback by Newton ?
Kapitan
 
Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

Re: [Irrlicht-Newton] Centre of world aligning?

Postby Kapitan » Tue Oct 28, 2008 2:56 am

I have solved appling the matrix from irrlicht to Newton BEFORE
adding verteces to the ConvexHull Collision.

The main in reason is that:
Code: Select all
NewtonBody *body = NewtonCreateBody(nWorld, tmp);
   
   matrix4 mat = sn->getRelativeTransformation();
   
   dFloat *matArray = mat.pointer();
   
   //here matArray correctly has the Scale diagonal
   
   NewtonBodySetMatrix(body,matArray);
   NewtonBodySetUserData(body,sn);

   dFloat *nTransMat;
   irrAllocatorFast<dFloat> *iaf = new irrAllocatorFast<dFloat>;
   nTransMat = (dFloat*)iaf->allocate(16);
   NewtonBodyGetMatrix(body,nTransMat);
      
   //here nTransMat has the diagonal set to 1.0f
      
   iaf->deallocate(nTransMat);


Now maybe i've not understande the use of NewtonBodySetMatrix, but
if i set a matrix with a body and take that matrix just after why the
two are not the same?

I've not made call to update() functions, nor to ApplyForceAndTorque,
nothing else then adding vertex to the collision mesh and then create
then body.
Kapitan
 
Posts: 37
Joined: Thu Apr 17, 2008 6:07 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests