A completely rigid joint

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

A completely rigid joint

Postby JernejL » Wed Nov 22, 2023 8:16 am

I need in my game (still newton 3) a very simple joint, one which could be used to temporarily lock two bodies together in similar manner to compound collision - and then separate them.

But it has to do so in a way that the primary body completely controls second body mass and inertia wise, basically a very primitive way of carrying a object.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: A completely rigid joint

Postby Sweenie » Wed Nov 22, 2023 11:15 am

Haven't been using Newton for a while so may remember things wrong but creating a "near" perfect rigid joint in Newton 3 is difficult.

You could use cheap tricks like setting a very low mass on the attached body but it would still affect the main body and break apart if too much force is applied to it such as getting stuck etc.
You said "like a compound" and I think that is the best choice even though that will create extra work of rebuilding the compound when attaching/detaching the body.

If you would have used v4 making the attached body a kinematic body controlled by a joint would be my next choice.
But as far as i remember v3 doesn't have kinematic bodies, only static bodies which could act a bit like a kinematic body but if correct physics interactions with the attached body is important, moving a static body that way isn't a good idea.

Misho may have some good insights here because I remember he made some complex setups with rockets and attachable parts.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: A completely rigid joint

Postby misho » Wed Nov 22, 2023 5:40 pm

JernejL wrote:I need in my game (still newton 3) a very simple joint, one which could be used to temporarily lock two bodies together in similar manner to compound collision - and then separate them.

But it has to do so in a way that the primary body completely controls second body mass and inertia wise, basically a very primitive way of carrying a object.


Hi JernejL,

I have been using the code below (Newton 3.xx) and it works very well. I use it to attach very heavy rocket stages and, obviously, they go through a lot of stress during launch, and I have never seen one break :wink:

Code: Select all
         case LINK_FIXED:
         default:
         {
            dMatrix  mSourceMatrix;
            NewtonBodyGetMatrix(targetEnt->nBody, &mSourceMatrix[0][0]);
            dCustomHinge* const pHinge = new dCustomHinge(mSourceMatrix, targetEnt->nBody, this->nBody);
            if (pHinge)
            {
               pHinge->EnableMotor(false, 0.0);
               pHinge->SetAsSpringDamper(false, 0.0, 0.0);
               pHinge->EnableLimits(true);
               pHinge->SetLimits(0.0, 0.0);
               SetHingeBodyMassScaleRatio(targetEnt, pHinge);
               sourceAP->pHinge = pHinge;
            }
            else
               if (bVerboseTBEntityAP) TB_PRINTF("\nFAILED TO LINK %s AND %s WITH HARD JOINT\n", targetEnt->GetTitleStr().c_str(), this->GetTitleStr().c_str());
         }
         break;


This is the piece of code that is a member of a CHILD entity (class), and it is used to connect to a PARENT entity (targetEnt) class. My TBEntity class is set up the same way as in the DemoSandbox Entity class, plus expanded for my own functionality, AND it contains a pointer to Newton Body object of that entity.

SourceAP is an "attachpoint" class which has a location x,y,z vector, orientation vector (so that the object we are attaching can be properly oriented) and a pointer *pHinge to a dCustomHinge object - basically, child's and parent's attach points share the same hinge.

Hope this helps!
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: A completely rigid joint

Postby JernejL » Thu Nov 23, 2023 3:57 am

misho wrote:
This is the piece of code that is a member of a CHILD entity (class), and it is used to connect to a PARENT entity (targetEnt) class. My TBEntity class is set up the same way as in the DemoSandbox Entity class, plus expanded for my own functionality, AND it contains a pointer to Newton Body object of that entity.


This is customhinge with strict no-rotation limits basically?

It will if i understand correctly, this will still apply that mass of both objects will be taken into account, both bodies will affect each others still?
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: A completely rigid joint

Postby JoeJ » Thu Nov 23, 2023 11:26 am

JernejL wrote:It will if i understand correctly, this will still apply that mass of both objects will be taken into account, both bodies will affect each others still?


Yes, although idk the SetHingeBodyMassScaleRatio() function or what it does.

But in general, the purpose of joints is to solve the constraint respecting laws of physics, so masses of both bodies must be used.

The question is: Why do you want to ignore one of the masses, and why do you still want a physical representation of such a massless body at all?
If it is to get collision feedback, i would use a trigger volume instead.
If you want full collision resolution, i would use a compound, setting its mass properties as desired.

EDIT: If you want a body that can push others away but does not get affected itself, kinetic bodies exist in 3.14. You can set their transform manually each step, and there are helper functions to calculate it's velocities from that. (The velocities are needed for proper interaction with other, dynamic bodies.)
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: A completely rigid joint

Postby misho » Thu Nov 23, 2023 1:04 pm

JoeJ wrote:
Yes, although idk the SetHingeBodyMassScaleRatio() function or what it does.


Sorry - this fn uses a member of CustomJoint:

SetBodyMassScale(dFloat scaleBody0, dFloat scaleBody1);

Gist of the function:

Code: Select all
   double dSourceMass = this->GetCurrentBodyMass();
   double dTargetMass = targetEnt->GetCurrentBodyMass();
   {
      if (dSourceMass > dTargetMass)
      {
         pHinge->SetBodyMassScale(dSourceMass, dTargetMass);
      }
      else
      {
         pHinge->SetBodyMassScale(dTargetMass, dSourceMass);
      }
   }

I can't remember exactly what this does, but I remember Julio suggesting to add it in when the joint showed some instability.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: A completely rigid joint

Postby misho » Thu Nov 23, 2023 1:11 pm

JernejL wrote:
This is customhinge with strict no-rotation limits basically?

It will if i understand correctly, this will still apply that mass of both objects will be taken into account, both bodies will affect each others still?


Basically, yes. The joint above will be rigid.

If you mean that if I attach 2 bodies, they will act as one rigid body as far as MOI and such, then yes. If you have a big heavy sphere, and you attach a smaller lighter sphere to it, and if you spin this "assembly", it will wobble.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: A completely rigid joint

Postby JernejL » Fri Nov 24, 2023 5:11 am

While this is super useful in my case aswell for some other use, i'd like carrying to not have smaller body affect carrier, because my actor controller is not proper ik character, but just a moving convex hull.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: A completely rigid joint

Postby JoeJ » Fri Nov 24, 2023 7:49 am

JernejL wrote:i'd like carrying to not have smaller body affect carrier, because my actor controller is not proper ik character, but just a moving convex hull.


You could drive the carried object with external force.
If the external force negates gravity and makes it follow the trajectory of the carrier, the joint (if still needed at all) will generate only very small forces to compensate inaccuracy, and the carrier would barely be affected from that.
If the carried object collides with something, both bodies will be affected (if there is a joint), but i guess that's what you want in this situation.

Kniematic body would not be needed, so if the carrier drops the object it behaves as usual.

To implement this, it's easier to drive it by setting velocities at first. After this works, convert the velocities to force and torque.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 38 guests