Support with simple systems

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Support with simple systems

Postby Paril » Tue Mar 10, 2009 9:32 pm

Is it possible to use Newton with an engine that only supports simple dynamics for rendering, ie only having a vector origin and euler angles?
I know Newton uses matrixes for operations and I want to make sure I can extract an origin and angles from these matrixes.

-Paril
Paril
 
Posts: 13
Joined: Mon Jul 14, 2008 12:48 am

Re: Support with simple systems

Postby Dave Gravel » Thu Mar 12, 2009 11:25 pm

You can extract origin and angle from any matrix if they is good, I don't see why not from newton...
Newton matrix is use for replace the object visual, on this case it containe all of what you need.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Support with simple systems

Postby Paril » Tue Mar 17, 2009 11:15 pm

Okay.

Now here's my problem. Basically I've set up Newton to work with Quake2, and it works great so far, but there's some really odd things happening with angles and origins.

Sometimes, like if I throw a box on stairs, the box will violently twist and rotate in very very weird directions, or it will come to a stop on an angle (like a 45 degree angle).. I don't know if this is my code or not, here's my callback:

Code: Select all
void SetMeshTransformEvent(const NewtonBody* body, const float* matrix)
{
   edict_t *attached = (edict_t*)NewtonBodyGetUserData (body);
   // copy the matrix into an irrlicht matrix4
   mat4x4_t mat;
   memcpy(mat, matrix, sizeof(float)*16);

   // Retreive the user data attached to the newton body
   //gi.dprintf ("%f %f %f\n", mat[12], mat[13], mat[14]);
   attached->s.origin[0] = mat[12];
   attached->s.origin[2] = mat[13];
   attached->s.origin[1] = mat[14];

   //NewtonBodyGetMatrix (body, &mat[0]);
   NewtonGetEulerAngle (&mat[0], &attached->s.angles[0]);
   attached->s.angles[0] = RAD2DEG(attached->s.angles[0]);
   attached->s.angles[1] = RAD2DEG(attached->s.angles[1]);
   attached->s.angles[2] = RAD2DEG(attached->s.angles[2]);

   gi.linkentity(attached);
}


Now, I just want to note that Quake2 ONLY supports euler angles and origin in MIDDLE of body, am I to assume that the matrix will always fulfill these, or will the origin shift depending on the center of gravity?

Another example is, for example, cylinders; now I assume that the "resting" (or starting) of a cylinder is sitting on it's sides so that it would roll, right? It seems that when spheres or cylinders roll, they are rolling in the wrong direction (angle-wise)! If I stack boxes, they will fall down correctly, but again, angles will violently twist for no reason. Also, cylinders seem to stack at spawn, so do they spawn on their top or on their side? The documentation is unclear on this..

-Paril
Paril
 
Posts: 13
Joined: Mon Jul 14, 2008 12:48 am

Re: Support with simple systems

Postby Dave Gravel » Tue Mar 17, 2009 11:35 pm

I'm not familiar with quake2 code, but you can surely override the rendering method by adding a matrix and you replace the rendering way with a gl matrix push.
This can save a lot of work with physics rendering.

Maybe the problem is the orientation when the object is create, it can look good but maybe the initial rotation is not the same in all side.
I talk about the direction and up and right, when you create the visual object you really need to have the same dir,up,right that newton using.
Do you have try to play with the offset matrix when you create your newton object ? maybe it can fix your problem.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Support with simple systems

Postby Paril » Tue Mar 17, 2009 11:38 pm

This is how I create a box:

Code: Select all
NewtonBody *MakeAStupidBox (edict_t *ent, NewtonCollision *collision, float x, float y, float z)
{
   NewtonBody *body = NewtonCreateBody(nWorld, collision);

   float Ixx = 10.0f * (16*16 + 8*8) / 12;
   float Iyy = 10.0f * (16*16 + 8*8) / 12;
   float Izz = 10.0f * (16*16 + 16*16) / 12;

   NewtonBodySetMassMatrix (body, 10.0f, Ixx, Iyy, Izz);
   NewtonBodySetTransformCallback(body, SetMeshTransformEvent);
   NewtonBodySetForceAndTorqueCallback(body, ApplyForceAndTorqueEvent);

   mat4x4_t mat;
   Matrix4_Identity (mat);
   Matrix4_Translate (mat, x, y, z);
   //Matrix4_Rotate (mat, 30, 1, 1, 0);
   NewtonBodySetMatrix (body, &mat[0]);

   edict_t *init = G_Spawn();
   init->s.origin[0] = x;
   init->s.origin[1] = y;
   init->s.origin[2] = z;
   Vec3Copy (init->s.origin, init->s.oldOrigin);
   init->s.modelIndex = gi.modelindex("models/cone.md2");
   gi.linkentity(init);
   NewtonBodySetUserData (body, (void*)init);

   if (ent && Q_stricmp(gi.argv(1), "force") == 0)
   {
      init->owner = ent;   
      init->air_finished = 1;
   }
   else
      init->air_finished = 0;

   if (ent)
   {
      Matrix4_Rotate (mat, ent->s.angles[1], 0, 1, 0);
      NewtonBodySetMatrix (body, &mat[0]);
   }

   return body;
}


I can't change the rendering method because I'm working with the game DLL only, not the engine. I'm limited to working with a right-handed coordinate system and degree euler angles.


-Paril
Paril
 
Posts: 13
Joined: Mon Jul 14, 2008 12:48 am

Re: Support with simple systems

Postby Dave Gravel » Tue Mar 17, 2009 11:44 pm

Right handed is ok, how you create the collision ? the offset matrix is when you create the collision.
Maybe the box is so stupid hehe joking...

Do you pass NULL for the offsetmatrix when you call NewtonCreateBox ?
Try to change the initial rotation with a matrix rotation.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Support with simple systems

Postby Paril » Tue Mar 17, 2009 11:53 pm

Code: Select all
   NewtonCollision *boxColl = NewtonCreateBox (nWorld, 26, 26, 26, NULL);


I forget if it's left or right, but I had to invert the 2 and 1, which was no problem.

That's how I create the collision; no initial matrix on the collision.

Is the origin of a Newton object ALWAYS the center?

I should probably mention, the reason I don't use matrixes here is because my engine doesn't have rudimentary support FOR matrixes, which is a real problem.. I've been using these Matrix4_ macros that the engine has, but besides that I don't have anything to work with.

Do you think I would benefit from using the DMatrix class?

EDIT: Okay, I have an idea.. I'll show you what my code is doing, illustrating with words.
Take a flight of stairs. Now take a box. Position it so it falls where one end goes further off the flight. What do you expect it to do? You expect it to tilt towards the front then tumble down frontwards. In my code, instead of tumbling frontwards, it tumbles sidewards! It looks like a corkscrew joint almost when spinning down stairs..

-Paril
Paril
 
Posts: 13
Joined: Mon Jul 14, 2008 12:48 am

Re: Support with simple systems

Postby Dave Gravel » Wed Mar 18, 2009 12:40 am

This offset matrix is only for the object creation, you can change object rotation with it...
After this matrix is not use anymore because the newton callback give to you a new matrix result based on this initial matrix.
Yes the default is all times centred if you don't change it, but exemple if the default newton matrix use a different direction, or up that what you use with the 3d.
This can cause very strange problem, the best is to try to change the offset matrix and see the result and learn by testing different matrix rotation.
Sometime it's hard to get the right offset matrix for your need, it depending from how the visual object is create.

DMatrix class?
No idea but maybe it can help if you use the offset matrix, may this matrix class have some tools function for generate matrix rotation.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Support with simple systems

Postby Dave Gravel » Wed Mar 18, 2009 12:56 am

The newton visual debug work with your q2 implementation ?
If yes may you can create the box in different size like [13 26 26], [26 13 26], [26 26 13], on this way you can see if the visual debug is all times fitting right with the visual 3d obj.

Remember you all objects can use different offset matrix setup it really depend from how the visual is create at the base.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Support with simple systems

Postby Paril » Wed Mar 18, 2009 1:03 am

I could have a client side OpenGL implementation running alongside the DLL as far as I know but I don't know how to enable/use it..

I wish I had this so I could see the values I get from Newton in real time.

I fixed my corkscrew problem, all I had to do was add 90 to the final angles[1], and things are rotating in the right direction now, but they still violently shake every now and then (it seems to affect the collision too, so I'm not sure what the problem is)..

-Paril
Paril
 
Posts: 13
Joined: Mon Jul 14, 2008 12:48 am

Re: Support with simple systems

Postby Dave Gravel » Wed Mar 18, 2009 1:08 am

It's a big project ?
It's something public ?
It can compile from visual express ?
Maybe I can try it, and see more what happening.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Support with simple systems

Postby Paril » Wed Mar 18, 2009 1:14 am

It's small, gearing just towards my own little creation & possibly a sandbox mod for Quake2.

You'd need Quake2 to run it. I compile with Visual Studio 2008. Do you use MSN? Perhaps we can talk more on there

-Paril
Paril
 
Posts: 13
Joined: Mon Jul 14, 2008 12:48 am

Re: Support with simple systems

Postby Stucuk » Wed Mar 18, 2009 2:55 pm

Quake 2 Full Source code was released, so you can recompile the rendering side to add in matrix's.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: Support with simple systems

Postby Paril » Thu Mar 19, 2009 12:21 am

You're not getting me.. this is a mod, not a game, I can't touch the rendering engine. My projects follow a strict rule about compatibility with engines.

-Paril
Paril
 
Posts: 13
Joined: Mon Jul 14, 2008 12:48 am

Re: Support with simple systems

Postby Stucuk » Thu Mar 19, 2009 3:02 pm

Paril wrote:You're not getting me.. this is a mod, not a game, I can't touch the rendering engine. My projects follow a strict rule about compatibility with engines.

-Paril


1. You could do what Deus Ex mods do. The decent ones copy important Deus Ex files, so you effectivly now have 2 copies of the game, that gets around the "compatibility" problems.
2. You could make a modifyed rendering DLL to at least get a debug display working while your developing it, then remove that when you release. Unless you can get the OGL pointers (To functions/etc) from the rendering DLL which i highly doubt, then afaik(I think there ment to be instanced to your active rendering context) you can never render custom stuff like a debug display without modifying the rendering DLL. This would be very limiting as you have no clue what newton's world is actual doing.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 12 guests

cron