Problem with the playerController

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Problem with the playerController

Postby JoeJ » Wed May 29, 2013 4:16 am

I used 2010 project.

To make sandbox run in VirtualBox, or old OpenGL machine change this in DemoEntityManager.cpp:

if (wglSwapIntervalEXT) wglSwapIntervalEXT(0); // check zero pointer if extension unavailable - then ragdoll demo runs at 5 fps ... yeah :)

I compared inertias. Both sandbox and my app calculate correct and equal values.
I also loaded serialized file from my app in sandbox. It works in sandbox, so it does not make sense to upload file again.

Seems debugging Enclaves demo is the only way...
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Problem with the playerController

Postby Enclave » Wed May 29, 2013 4:52 am

JoeJ

I think I need to implement in my project wireframe mode to see the collision and other debug infos, because I we need to see what happens while box standing on its edge.
But do this is not so easy, because my DirectX render is not finished yet...

I have one idea, maybe this issue is only graphical bug.

I'm not sure whether I treat Transform Callback, there must be a correct conversion from Newton quaternion to a rotation matrix, as my graphics engine uses a matrix to rotate the mesh.

Here is code:
Do you think it's right?


Code: Select all
void TGE_Physics::TransformCallback (const NewtonBody* body, const float* matrix, int threadIndex)
{
/* This is a Newton Sandbox version
   DemoEntity* const ent = (DemoEntity*) NewtonBodyGetUserData(body);
   
   DemoEntityManager* const scene = (DemoEntityManager*) NewtonWorldGetUserData(NewtonBodyGetWorld(body));
   dMatrix transform (matrix);
   dQuaternion rot (transform);
   ent->SetMatrix (*scene, rot, transform.m_posit);
*/
   cObject* ent;
   ent = (cObject*) NewtonBodyGetUserData(body);

   D3DXQUATERNION rotation;

   // we will ignore the Rotation part of matrix and use the quaternion rotation stored in the body
   NewtonBodyGetRotation(body, &rotation.x);

   dMatrix trans (matrix);

   // order is reversed, unlike DX : WZYX -->> XYZW
   float t;

   SWAP(rotation.x, rotation.w, t);
   SWAP(rotation.y, rotation.z, t);
   ent->Move(trans.m_posit.m_x,trans.m_posit.m_y,trans.m_posit.m_z);
   ent->Rotate(&rotation);
}


This is only idea, maybe bug in somewhere another place.
Enclave
 
Posts: 81
Joined: Wed May 01, 2013 6:00 am

Re: Problem with the playerController

Postby JoeJ » Wed May 29, 2013 6:57 am

I don't use transform feedback yet, i render directly from body matrices. Rendering seems right also in sandbox in any Mode.
I don't think there's a bug in the shape itself, but wrong inertia explanes the edge behaviour from your video.
Inertia is correct and in post scaled state, but maybe newton does scale it a second time at runtime under some condition we don't know.
Are you able to reproduce any wrong behaviour without player controller in sandbox? I'm not, but you talked about wrong collision display in sandbox... sure about that?

You can avoid quaternion and use the matrix from transform feeback directly instead, but as you use DirectX you'd need to swap rows an columns == transpose matrix.
At least that should be faster.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Problem with the playerController

Postby Enclave » Wed May 29, 2013 7:31 am

but wrong inertia explanes the edge behaviour from your video.


How I can set it to correct value? The Sandbox dont do anything for setting inertia?

Are you able to reproduce any wrong behaviour without player controller in sandbox?


In the Sandbox my serialized scene works without any issues.

I dont use scaling, I am scale only my meshes, and do not use the any Newton Scaling functions.

but as you use DirectX you'd need to swap rows an columns == transpose matrix.


Not sure about this so. I read here that Newton uses the same row-major matrices as in the DirectX.
Enclave
 
Posts: 81
Joined: Wed May 01, 2013 6:00 am

Re: Problem with the playerController

Postby JoeJ » Wed May 29, 2013 8:08 am

You did NOT use scaling for the boxes in the video? That changes a lot...

Usually you let newton calculate inertia for you, i assume you already do so, but take a look at my body creation code.
There's an old way and a new one which is a single call to NewtonBodySetMassProperties (). Both work.
You have that too?


Code: Select all
NewtonBody* CreateRigidBody (float mass, sMat4 &trans, NewtonCollision *shape)
   {
      float origin[4];
      float inertia[4];
      NewtonBody* body;

#ifdef NEWTON_300
      body = NewtonCreateDynamicBody (world, shape, &trans[0][0]);
#else
      body = NewtonCreateBody (world, shape, &trans[0][0]);
#endif

if (0)
{
      NewtonConvexCollisionCalculateInertialMatrix (shape, &inertia[0], &origin[0]);   

      // set the body mass matrix
#ifdef NEWTON_300
      NewtonBodySetMassMatrix (body, mass, mass * inertia[0], mass * inertia[1], mass * inertia[2]);
#else      
      NewtonBodySetMassMatrix (body, mass, mass * inertia[0], mass * inertia[1], mass * inertia[2]);
#endif
      NewtonBodySetCentreOfMass (body, &origin[0]);
}
else
{
      NewtonBodySetMassProperties (body, mass, shape);
}

      return body;
   }
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Problem with the playerController

Postby Enclave » Wed May 29, 2013 8:15 am

Yes, I did not use scaling. I have a mesh, then I make Newton mesh from my mesh (ID3DXMESH), then I am create a collision from Newton mesh and thats all.

This is my function: (the same as in the Sandbox)

Code: Select all
NewtonBody* TGE_Physics::CreateSimpleBody (void* const userData, float mass, const dMatrix& matrix, NewtonCollision* const collision, int materialId)
{
   //create the rigid body
   NewtonBody* const rigidBody = NewtonCreateDynamicBody (g_world, collision, &matrix[0][0]);

   // use a more convenient function for setting mass and inertia matrix
   NewtonBodySetMassProperties (rigidBody, mass, collision);

   // save the pointer to the graphic object with the body.
   NewtonBodySetUserData (rigidBody, userData);

   // assign the wood id
   NewtonBodySetMaterialGroupID (rigidBody, materialId);

   // set a destructor for this rigid body
   NewtonBodySetDestructorCallback (rigidBody, TGE_Physics::PhysicsBodyDestructor);

   // set the transform call back function
   NewtonBodySetTransformCallback (rigidBody, TGE_Physics::TransformCallback);

   // set the force and torque call back function
   NewtonBodySetForceAndTorqueCallback (rigidBody, TGE_Physics::PhysicsApplyGravityForce);

   return rigidBody;
}
Enclave
 
Posts: 81
Joined: Wed May 01, 2013 6:00 am

Re: Problem with the playerController

Postby Julio Jerez » Wed May 29, 2013 9:12 am

I still need one more day to get the dJoint dll project working.

I have running now, but I have a problem with memory and Templates. This si one of the short coming of CPP.
Template are issue on the call code, but the destructor as call for anywhere, so you can run in the cituation that a piece of memory is allocated in one heap, and then try to be destroyed by a different heap on a DLL.

To solve this I would he to make the dContainer dll also, but I am no going to do that, instead I will implement a mini list for the manager that does all it allocation form within the DLL.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with the playerController

Postby Julio Jerez » Wed May 29, 2013 11:35 am

Urey I have the dJointLibrary minimally compiling and running as dll.

I will re enable the player controller manage and check this in, the we fix the rest a we need it. It is no really that much work.


JoeJ wrote:if (wglSwapIntervalEXT) wglSwapIntervalEXT(0); // check zero pointer if extension unavailable - then ragdoll demo runs at 5 fps ... yeah :)

is there a reason why?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with the playerController

Postby JoeJ » Wed May 29, 2013 12:46 pm

wglSwapIntervalEXT pointer is zero in VirtualBox so it crashes there. I assume because this extension is unavailable, glew leves it at zero.
With the branch everything works.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Problem with the playerController

Postby Julio Jerez » Thu May 30, 2013 12:11 am

Ha, ok Joe I added that check to the demos.
I just checked in the dll configurations for the dJointLibrarry for visual studio 2010 and 2008 professionals.

Later I will make the changes to all of the VS express versions. that should be just setting few parameters in the solutions.

@Enclave
can you please sync to SVN and see if you can link to the jointLibrary dll, if you can do that then you maybe you can send me and executable so that I can see what is going on with your scene.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with the playerController

Postby Enclave » Thu May 30, 2013 2:07 am

Yes, it works! An executable now has smaller size, and jointlibrary.dll are now properly loaded at runtime.

Thanks a lot. :D

I have to prepare my project for you (because it not run now outside Visual Studio), it will take a little time, then I can send you an executable. You can play with game characters, player and boxes, create them, setup its positions and change the level map on any what you want.
Enclave
 
Posts: 81
Joined: Wed May 01, 2013 6:00 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron