Porting from 3.xx to 4.00 - need help

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Tue Jun 20, 2023 2:33 pm

In any case, as Julio mentioned, I can compute velocities and omegas from previous/current position/orientation.


read the post carefully, it is not the current and previous position of the airplane.
It is the current position of the Rigid body, and the current position of the airplane.

It really does come down to just one problem: To directly set Newton body's position/orientation, or velocities derived from position/orientation.


by doing the previous procedure to extract velocities and passing them to the engine on each frame,
the engine will do the update, you do not need to set position directly,
this is different from 3.14 where the application had to do the integration.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Tue Jun 20, 2023 2:42 pm

Julio Jerez wrote:read the post carefully, it is not the current and previous position of the airplane.
It is the current position of the Rigid body, and the current position of the airplane.


Yes, sorry, my bad, I was typing on the fly! Quite correct.

Julio Jerez wrote:by doing the previous procedure to extract velocities and passing them to the engine on each frame, the engine will do the update, you do not need to set position directly,
this is different from 3.14 where the application had to do the integration.


Ok - so, perfect, I have the answer to my question! I will try this in DemoSandBox first. Thanks!
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Tue Jun 20, 2023 5:17 pm

misho wrote:So, something just dawned on me - a question:
In the DemoSandBox, how is mouse interaction with objects done? What happens when you "grab" an object and move it around? Because that is exactly what I need, an external manipulation of Newton object!


Any comment on this question?
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Tue Jun 20, 2023 9:54 pm

It is the kinematic joint.
You can look at the camera manager file in the sandbox.


You need to add some game logic, that would be particular to the application.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby JoeJ » Wed Jun 21, 2023 3:08 am

misho wrote:
misho wrote:So, something just dawned on me - a question:
In the DemoSandBox, how is mouse interaction with objects done? What happens when you "grab" an object and move it around? Because that is exactly what I need, an external manipulation of Newton object!


Any comment on this question?


It's a kinematic joint, so it moves the body by applying force to the body and integrating it. So option 3 from my list. It's most advanced simulation and ideal from that perspective, but likely it causes worst case lag. I expect it won't work well enough for you, but that's just a guess.

Instead using such joint, you could also use kinematic body, set its velocity and have Newton integrate it to move it. Option 2. If the velocities you get do not match precisely, it will cause some lag as well i guess. It's likely worth to figure out the coordinate system conversion you mentioned, because then you get the current velocity, while calculating it from previous and current transforms will give you velocity from the last step, which is only right if the jet moves in a straight line at constant velocity.

If you can't solve the lag problem after that. Then you have to set the body position directly, so it matches the jet precisely no matter what. Option 1. You need to set velocity as well, as accurately as possible, to make the interaction with the tanks work properly.

That's basically you options as i see it. I would try the last one first, which should work for the jet body without lag.
Assuming it does work, but it gives you problems with the attached tanks, you can still try the other options for the jet body.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Wed Jun 21, 2023 10:34 am

Yes you can make the whole world using kinematic bodies.
But that defeat the purpose of using the physics engine and relegate it to a collision of utility library.

Ideally you would want a world that is 100% driven by the law of physics.

But that is not possible with the current knowledge of physics and technology we have today and some thing has to be kinematic ally driven.
The trick is where to strike the balance.

In this case the plane is kinematic out of necessity.
But in doing that, now you are face with the problem that kinematic bodies do not interact with other kinematic bodies, so the application has to handle that.

The more object type the application make, them it becomes a combinatorial problem for the application.

Kinematic joints, triggers, the animations, player capsule, particle are few of those cases that the engine try to provide support for and it is what make the engine harder to advance.

Kinematic joints are quite handy for game play, an app can use them to place solid attach stuff to the word, that will be
At rest, but that will react naturally plausible on contact without the app doing much effort.

Using kinematic, them the app has to be involved on the calculation of the motion, along with lot of other things.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Wed Jun 21, 2023 12:18 pm

Julio, JoeJ, thanks guys for your insight. I need a better understanding of Dynamic vs Kinematic bodies and joints. I guess there is also a Static body which is basically a body that never moves, it only presents collision surfaces. Is there documentation that covers this? Wiki is still referring to 3.xx and hasn't been updated in a while.

Also, Julio, for this:

ndVector CalcAverageOmega(const ndQuaternion &q1, ndFloat32 invdt) const;

what's the ndQuaternion argument? A difference between two omega quaternions? (aircraft and newton body)
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Wed Jun 21, 2023 3:10 pm

a kinematic object is just an object that is not actuated by forces.
they act just like Dynamic body, just that the method that Integrate them ignore the acceleration produced by the solver step.


on this,
ndVector CalcAverageOmega(const ndQuaternion &q1, ndFloat32 invdt) const;

if you have two rotation matrices, you can convert them to quaternions using matrix to quaternion function.

from there, you can see quaternuon as points of a 4-dimension unit sphere.

q (r0 + r1 + r2 + r3 - 1 = 0)

the shortest path between points quick and q1 is the angular step needed to go from ritation q0 to q1.
so if assume constant motion a long that arch, then you divide the angular step by the time step, '
that gives the average angular velocity you need at q0

there are proof for this that you can get from Wikipedia, I think,
but basically that function gives you the angular velocity to apply to a rotation a
matrix that map to a quaternion q0, so that it reaches quaternion q1 after time dt.
them q1 can be converted back to a matrix

Edit:
In you example.

q0 would be the rotation of the kinematic body attach to the plane.
q1 would be the rotation matrix of the airplane from the flight simulator.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Thu Jun 22, 2023 6:55 pm

Julio Jerez wrote:a kinematic object is just an object that is not actuated by forces.
they act just like Dynamic body, just that the method that Integrate them ignore the acceleration produced by the solver step.


Ok - I started my project by creating 2 bodies using exact same method - one Kinematic, one Dynamic. Dynamic falls, and Kinematic is suspended in the air, because it does not react to forces, as you mentioned. From the code, I ascertained that Dynamic body is a subclass of Kinematic body, and the Kinematic body is a subclass of nBody (base class). So - can you tell me what a sample practical purpose would be of a Kinematic body? A hard wall, or a cliff... an immovable object? Is that what a STATIC body used to be in 3.xx? (If I remember correctly).


Julio Jerez wrote:on this,
ndVector CalcAverageOmega(const ndQuaternion &q1, ndFloat32 invdt) const;

if you have two rotation matrices, you can convert them to quaternions using matrix to quaternion function.

from there, you can see quaternuon as points of a 4-dimension unit sphere.

q (r0 + r1 + r2 + r3 - 1 = 0)

Edit:
In you example.

q0 would be the rotation of the kinematic body attach to the plane.
q1 would be the rotation matrix of the airplane from the flight simulator.


Right. I have to admit that I don't understand this. I am guessing that q0 and q1 are quaternions derived from the state matrices of the FS and kinematic body? Ok - if so - how do I get to a rotation difference quaternion to be used in the equation:

ndVector CalcAverageOmega(const ndQuaternion &q1, ndFloat32 invdt) const;

Do I subtract one from the other?

Also - What is used for callbacks in 4.00 in place of 3.xx ApplyTransformCallback and ApplyForcesCallback? How is that done now? I need to trap keypresses to move FS matrix, and I THINK that should be done in ApplyTransformCallback of Kinematic body.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Thu Jun 22, 2023 8:23 pm

misho wrote:Ok - I started my project by creating 2 bodies using exact same method - one Kinematic, one Dynamic. Dynamic falls, and Kinematic is suspended in the air, because it does not react to forces, as you mentioned. From the code, I ascertained that Dynamic body is a subclass of Kinematic body, and the Kinematic body is a subclass of nBody (base class). So - can you tell me what a sample practical purpose would be of a Kinematic body? A hard wall, or a cliff... an immovable object? Is that what a STATIC body used to be in 3.xx? (If I remember correctly).

in the SDK, triggers and player capsules are kinematic objects.
but in your case the plain will also be a kinematic object,
you can since of the planer as some special player capsule.
you can see the class hierarchy by opening the dixigen file.

misho wrote:ndVector CalcAverageOmega(const ndQuaternion &q1, ndFloat32 invdt) const;
Do I subtract one from the other?


you do not subtract them, I expressed as a subtraction because that's how the derivation of the function is realized. It is from calculus, the limit of two quaternion when time step approach zero, and come out to be
dQ/dt = 0.5 * omega * Q
it is a tedious derivation, but it is in many books and papers, ex:
https://ahrs.readthedocs.io/en/latest/f ... gular.html

but you do not have to worry about that, that function implements the formula for you.

it is my fault that you get confused. I did not statef clear how to use the function.
once you calculate q0 and q1 from the matrices. the formula is

Code: Select all
ndVector omega = q0.CalcAverageOmega(q1, invdt)


so you can see where to plug q0, q1 and time step.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Sat Jun 24, 2023 12:53 am

Julio Jerez wrote:in the SDK, triggers and player capsules are kinematic objects.
but in your case the plain will also be a kinematic object,
you can since of the planer as some special player capsule.
you can see the class hierarchy by opening the dixigen file.


Ok, that clarifies it a bit - thank you! So, I created a Kinematic body, and a Dynamic body. I attached the dynamic body to kinematic body using ndJointFix6dof joint... and the joint is NOT hard - it has a lot of flexibility.

When I attach Dynamic body to another Dynamic body using ndJointFix6dof, the joint is rock hard.

Can I have a rock hard joint between the Dynamic and Kinematic body?

Edit: Both bodies had the same mass. When I made the Dynamic body's mass 1000x smaller, I could no longer move it. However, there is small amount of movement of the dynamic body when I hit the kinematic body with the mouse and try to move it. Kinematic body doesn't move at all. I guess I am not going to be applying any forces to the airplane's kinematic body, but still, I would like for it to be no movement, a completely fixed joint.

Julio Jerez wrote:it is my fault that you get confused. I did not statef clear how to use the function. once you calculate q0 and q1 from the matrices. the formula is

Code: Select all
ndVector omega = q0.CalcAverageOmega(q1, invdt)


so you can see where to plug q0, q1 and time step.


It is actually MY fault - I didn't realize CalcAverageOmega() was a Quaternion member function - I didn't look at docs close enough. I thought it was a stand alone function. Of courese, THAT makes sense! Thanks!
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Sat Jun 24, 2023 5:07 pm

misho wrote:I created a Kinematic body, and a Dynamic body. I attached the dynamic body to kinematic body using ndJointFix6dof joint... and the joint is NOT hard - it has a lot of flexibility.
...
Can I have a rock hard joint between the Dynamic and Kinematic body?


I do not know why attaching a dynamic body to a kinematic is soft, it should be hard.
it could be a weakness on the algorithm that order the joints for the solver.

these are the joint type.
Code: Select all
enum ndJointBilateralSolverModel
{
   m_jointIterativeSoft,
   m_jointkinematicOpenLoop,
   m_jointkinematicCloseLoop,
   m_jointkinematicAttachment,
   m_jointModesCount
};


m_jointIterativeSoft is for soft joint by definition.

m_jointkinematicOpenLoop is for hard joint by definition, and it is the default for most joints.

m_jointkinematicCloseLoop is for breaking tide when two joints can be hard and the app want that joint to be the close loop. example is for example a vehicle tire axel.

m_jointkinematicAttachment hint for joint that come in contact at run time, like one model touching a another model, ex are contacts or runtime attachments.

I believe the algorithm assumes the bodies are dynamic, so if one was kinematic might produce an unexpected order.

can you modify one of the demos to reproduce it?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Mon Jun 26, 2023 12:49 am

Julio Jerez wrote:can you modify one of the demos to reproduce it?


Sure - I put together a separate test case here.

Image

On the left are 2 dynamic objects joined by a ndJointFix6dof joint. On the right is a dynamic object joined to a Kinematic object. When you "grab" a kinematic object and "shake" it, dynamic object on top wobbles a bit, instead of being hard-fixed to the kinematic object.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Mon Jun 26, 2023 9:59 am

ok I pasted in the sandbox.
and I tested it.

I know it seems weird, but this is who is supposed to work.
the kinematic/dynamics connection seems soft, but it is not.

want happen is that you are attaching a dynamics body to a kinematic body with a joint.
them you are try to pick the kinematic body. but the pick code use another joint.

the problem is that joint can only move bodies by calculation the reaction forces between the two bodies they are attached to.
so both joints are calculation the force and torque needed to move the body.
but they can only add forced, but kinematic bodies ignore forces, so they do not move.

it might be possible to move the body by using a ndmodel, and a immediate solver.
the in the model update, run a immediate solve and calculate the velocity generated by the joints and and set to the body. so that is moves.

not sure how would that work,
but my question is why are you doing that?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Mon Jun 26, 2023 11:08 am

Julio Jerez wrote:but my question is why are you doing that?


Hi Julio! Yes - what I am doing - "grabbing" kinematic body, or, applying forces to it through the joint on the "grab" point, will not happen in my application. I will not apply forces to the Flight Simulator airplane body. What I was testing with this case was, I wanted to make sure I am setting up things properly. I noticed the small "wiggle" of the plank on top of the Kinematic body, and I wanted to know if I set things up right or if I am doing anything wrong before I proceed. The more important part is, the dynamic plank on the top of the kinematic body is rock solid, it is absolutely not moving, which is what I wanted to validate as well.

So, the next step is to introduce the key-controlled code to move the Kinematic body. Just to clarify, this is done in

Code: Select all
SetNotifyCallback(new ndDemoEntityNotify(scene, entity));


Where currently ndDemoEntityNotify handles gravity and mouse "grabs", and I have to write a new callback for kinematic body which will be taking key presses and directly moving the body. Is that more or less correct?
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests