strange behaviour of my cuboids

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: strange behaviour of my cuboids

Postby Yustme » Sat Aug 16, 2008 5:21 pm

Hi,

It's not the scale. The sizes of both engine's match perfectly in geometry.

http://yustme.g0dsoft.com/Projects/newtonStrangeBehavior.JPG

It just looks like the collision geometry is both with the graphics object and floating somewhere else too.
Yustme
 
Posts: 37
Joined: Sat Dec 08, 2007 2:06 pm

Re: strange behaviour of my cuboids

Postby JernejL » Sat Aug 16, 2008 5:59 pm

Can you produce a top-down screenshot? it looks as if your floor axis are swapped or someting..
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: strange behaviour of my cuboids

Postby Yustme » Sat Aug 16, 2008 6:07 pm

Yustme
 
Posts: 37
Joined: Sat Dec 08, 2007 2:06 pm

Re: strange behaviour of my cuboids

Postby JernejL » Sat Aug 16, 2008 7:16 pm

I would bet good money that there has to be a issue with your conversion of data from newton matrix to your body mesh here:

mesh->setPosition(mat.getTranslation());
mesh->setRotation(mat.getRotationDegrees());

What does the setposition and setrotation do? can you not just copy the matrix to the object directly? that should just work..

If you are using the rotation and translation separatedly to rebuild the matrix, it is possible you are multiplying matrices in wrong order (i seen similar errors happen when rotation and translation matrixes were multiplied in wrong order)
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: strange behaviour of my cuboids

Postby Julio Jerez » Sat Aug 16, 2008 10:37 pm

I thought somethong like what we see my be going on.
can you just make for one box so the you can determine the relation beter teh body matrix an dteh visual object.
Julio Jerez
Moderator
Moderator
 
Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: strange behaviour of my cuboids

Postby Yustme » Sun Aug 17, 2008 4:59 am

Delfi wrote:I would bet good money that there has to be a issue with your conversion of data from newton matrix to your body mesh here:

mesh->setPosition(mat.getTranslation());
mesh->setRotation(mat.getRotationDegrees());

What does the setposition and setrotation do? can you not just copy the matrix to the object directly? that should just work..

If you are using the rotation and translation separatedly to rebuild the matrix, it is possible you are multiplying matrices in wrong order (i seen similar errors happen when rotation and translation matrixes were multiplied in wrong order)



Hi,

I think you might be right, i've tried this like 3 months ago, copy the matrix directly. But it gives me a nullpointer exception at runtime, no matter what i tried.

Now i got some feedback about this and its confirmed. I''ll try whatever it takes to get this working with matrix!

Thanks Delfi!

I'll let you guys know if it worked.
Yustme
 
Posts: 37
Joined: Sat Dec 08, 2007 2:06 pm

Re: strange behaviour of my cuboids

Postby Yustme » Sun Aug 17, 2008 5:01 am

Julio Jerez wrote:I thought somethong like what we see my be going on.
can you just make for one box so the you can determine the relation beter teh body matrix an dteh visual object.


Hi Julio,

The physics object of the cube is floating somewhere in the sky and the graphics object is on the ground. I have tested this with 1 cuboid.

I made a post about this a few weeks back too btw.

I'll try the matrix Delfi told me about it. See if that works.

Thanks for testing the demo Julio!
Yustme
 
Posts: 37
Joined: Sat Dec 08, 2007 2:06 pm

Re: strange behaviour of my cuboids

Postby JernejL » Sun Aug 17, 2008 6:13 am

I think you might be right, i've tried this like 3 months ago, copy the matrix directly. But it gives me a nullpointer exception at runtime, no matter what i tried.


how exactly did you try? the usual way is to just copy the matrix to userdata body in transform calback.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: strange behaviour of my cuboids

Postby Yustme » Sun Aug 17, 2008 6:18 am

Hi,

This is one of the methods i tried to apply the matrix:

Code: Select all
// set the transformation of a rigid body.
// You have to do this so that the Newton body and irrLicht scene node are in sync,
// and you actually see the changes created by the physics simulation
void CNewton::PhysicsSetTransform(const NewtonBody* body, const float* matrix, int threadIndex)
{
   matrix4 mat;
   memcpy(mat.pointer(), matrix, sizeof(float) * 16);
   
   NewtonWorld *world = NewtonBodyGetWorld(body);
   CNewton* irrWorld = (CNewton*)NewtonWorldGetUserData(world);

   IAnimatedMesh* mesh = (IAnimatedMesh*)NewtonBodyGetUserData(body);
   IMeshManipulator* mm = irrWorld->newtonIrrPtr->getSceneManager()->getMeshManipulator();
   
   if(mesh)
   {
      mm->transformMesh(mesh, mat);
   }
}
Yustme
 
Posts: 37
Joined: Sat Dec 08, 2007 2:06 pm

Re: strange behaviour of my cuboids

Postby JernejL » Sun Aug 17, 2008 6:49 am

Is it possible that not all bodies had userdata assigned? It would cause exactly that: userdata pointer would return null and you don't check the pointer validity before using it to reference the body object, check if "NewtonBodyGetUserData(body) == null" and exit the function if it is (so nullpointer error doesn't happen).

This seems as the most obvious problem in your case, since i can't go thru your code step by step with debugger.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: strange behaviour of my cuboids

Postby Yustme » Sun Aug 17, 2008 7:48 am

Hi Delfi,

I did the extra check you suggested, but i am already checking if the"mesh" isn't null in the if statement in my transformcallback.

When i set the userdata for the body, it was an ISceneNode* object of irrlicht. And in my transformcallback i am trying to get the IAnimatedMesh* data out of the userdata from the body.

And i think that caused the NULL pointer exception at runtime. Now i changed the userdata from ISceneNode to IAnimatedMesh.

After doing some more debugging when i changed the userdata, i found a few new interesting things.

I removed the skybox pictures to see the lines better.

This screenshot is taken when the game started and nothing has been done yet. The collision geometry is right under the graphics floor object:

http://yustme.g0dsoft.com/Projects/temp%20newton%20screenies/floorNotMatchingCollisionPosition.JPG

When i create my pyramid, it looks like this:

http://yustme.g0dsoft.com/Projects/temp%20newton%20screenies/strangePositions.JPG

Positions of the floor objects don't entirely match, because the Y position is the only one that's right in this picture (maybe not really visible, but i went to it with camera). The X and Z are mismatched.

Now when i shoot at my pyramid with a sphere, it looks like this:

http://yustme.g0dsoft.com/Projects/temp%20newton%20screenies/suddenlyFloorMatch.JPG

Suddenly, a perfect match of the floor object, physically and graphically. I don't know why the sphere isn't visible.

And when i shoot a cylinder, which is visible in the screenshot, they bodies act realistically:

http://yustme.g0dsoft.com/Projects/temp%20newton%20screenies/NoStrangeBehavior.JPG

The ISceneNode is responsible for showing the mesh in the game and texturing it and setting position/rotation.

Which i didn't use in this case, only the floor object is made differently than the sphere, cylinder and the cuboids.

This looks like a matrix problem to me.
Yustme
 
Posts: 37
Joined: Sat Dec 08, 2007 2:06 pm

Re: strange behaviour of my cuboids

Postby JernejL » Sun Aug 17, 2008 8:08 am

Try this way:

http://newtondynamics.com/wiki/index.ph ... h_Irrlicht

See: "PhysicsSetTransform" there.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: strange behaviour of my cuboids

Postby Yustme » Sun Aug 17, 2008 8:29 am

Hi,

That is still using the ISceneNode. This was btw, how my transform function looked like at first. Although i removed the scale.

Three more screenshots if you can handle horror-ness (be warned):

http://yustme.g0dsoft.com/Projects/temp%20newton%20screenies/positionsAreWrong.JPG

http://yustme.g0dsoft.com/Projects/temp%20newton%20screenies/AfterShootingSphere.JPG

http://yustme.g0dsoft.com/Projects/temp%20newton%20screenies/DunnoWhatIsHappening.JPG
Yustme
 
Posts: 37
Joined: Sat Dec 08, 2007 2:06 pm

Re: strange behaviour of my cuboids

Postby JernejL » Sun Aug 17, 2008 8:47 am

Your debug wires are off by some weird amout but the world is fine (bodies seem ok now), it now looks to me as if you are rendering the wires with transformations mixed up with the camera matrix or something? i cannot see what else could cause that kind of mismatch.. try asking the irrlicht guys what you are doing wrong, because this is plain weird and is definetly not caused by newton.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: strange behaviour of my cuboids

Postby Julio Jerez » Sun Aug 17, 2008 9:04 am

yustme this do not fixes the offset on the x and z direction but is fixed teh wierd jitter you see in the bodies.
Code: Select all
// set the transformation of a rigid body.
// You have to do this so that the Newton body and irrLicht scene node are in sync,
// and you actually see the changes created by the physics simulation
void CNewton::PhysicsSetTransform(const NewtonBody* body, const float* matrix, int threadIndex)
{
/*
   matrix4 mat;
   memcpy(mat.pointer(), matrix, sizeof(float) * 16);
   
   IMeshSceneNode* mesh = (IMeshSceneNode*)NewtonBodyGetUserData(body);
   
   if(mesh)
   {
      mesh->setPosition(mat.getTranslation());      
      mesh->setRotation(mat.getRotationDegrees());
   }
*/
   IMeshSceneNode* mesh = (IMeshSceneNode*)NewtonBodyGetUserData(body);
   if(mesh)
   {
      const matrix4& mat = *(matrix4*)matrix;
      core::vector3df rotation;

      NewtonGetEulerAngle(mat.pointer(), &rotation.X);
      rotation = rotation * (180.0f/3.1416f);

      mesh->setPosition(mat.getTranslation());      
      mesh->setRotation(rotation);
   }
}


I remember that I told someone about 3 years ago ago about eulers function in Irrlith it is not completlet correct.
In fact I believe I wrote the NewtonGetEulerAngle because Irrlitch use had a hard time getting the angles from a matrix.
anyway I still do nto know why there is an offset bewteen the collision mesh and the visual mesh, it is almost like the visual mesh is parented for some node with a translation offset but I can not see it.
or Delfi maybe right the debug display might be affected by some matrix transformation, the debug display faces are already in global space you should not apply any transform to them.
The collision mesh must match the visual mesh at all time.

I also notice you only use convex hulls for collision, it might be better is you use primitive liek sphere for s[heres and box for boxes.
I may be musg faster
Julio Jerez
Moderator
Moderator
 
Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron