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 JoeJ » Sat Nov 25, 2023 4:20 am

The only issue i see is here:

if(vLength(vForce)) GlobalPropulsionForce = vForce;

The magnitude check is not needed. If force is a zero vector, that's fine and would be even ideal.

Another potential problem: Because we compensate the whole error in one step, the missile may be at the right spot in the next frame. But then it's velocity is too high, so we will overshoot in the next frame after that. So we create an oscillation. To prevent this, we need to resolve only part of the error per step, which unfortunately also increases lag, but still worth to try:

dVector vAccel = (vTargetVel - vCurVel).Scale(1.0/dBodyTimeStep * 0.3);

I would test all those things (impulse and force methods) also without the fixed joint, to see if the math is right.
If not, we work against the joint, forces might increase to the point where we get asserts indicating solver explosions.

But the real question to me is: Why does the fixed joint not work, although it did work for you til yet, with other spacecraft?
Is the acceleration of the airplane much higher?

I guess not? So maybe it's something about the joint.
I have similar issues with the ragdoll. If i cause very high accelerations, the bodies separate at the joints. And then the engine tries to resolve the large error with slow constant velocity movement, similar to what happens if we place a body inside another. The large penetration is resolved slowly, and it takes some time even if i stop my joint motors.
Eventually your lag comes from there. The only solution is to avoid very high accelerations. :/

To make the joint more robust, i see two options:

Make sure the attachment point is at the center of mass of the missile, so there is no arm causing angular stress. I assume you have it like that already.
Experiment with the orientation of the joint. Try to align the hinge axis with the length of the missile, but also try to rotate it 90 degrees so the hinge axis is perpendicular. Might make a difference.

The second option is to use the newer accurate / hard joints, instead the older soft joints. This might actually really help.
To do so, you need to create a skeleton containing both the airplane and the missile bodies.
I still have some old code with Julios advice:
Code: Select all
   void EnableStiffJoints (NewtonWorld *world)
   {
      newtonSkeletonContainer = NewtonSkeletonContainerCreate (world, bodies[HIP], 0);
      //NewtonSkeletonSetSolverMode (newtonSkeletonContainer, 1); // should be uncommented i guess
      //and add all the children using function

      int jointCount = 0;
      NewtonJoint *jointArray[NUM_JOINTS];
      
for (int i=0; i<joints.size(); i++)
      {
         NewtonSkeletonContainerAttachBone (newtonSkeletonContainer, joints[i]->body0, joints[i]->body1);
         NewtonSkeletonContainerAttachBone (newtonSkeletonContainer, joints[i]->body1, joints[i]->body0); // i had those two lines commented out. Maybe only one is needed so we do not add bodies twice
         jointArray[jointCount++] = joints[i]->joint;
      }
      

      NewtonSkeletonContainerAttachJointArray (newtonSkeletonContainer, jointCount, jointArray);

      //and after all the bone are added, the call
      NewtonSkeletonContainerFinalize (newtonSkeletonContainer);

      //and that's it, now that array of bodies and joint will be result exactly.
   }

It's old code and may no longer work, but at least you see some related function calls.

With Newton 4 the skeleton is created automatically for a ndModel and its joints and bodies.
And i need to enable the exact joint solver in the joints constructor:

Code: Select all
   SomeJoint (ndBodyKinematic* body0, ndBodyKinematic* body1)
      : ndJointBilateralConstraint(4, body0, body1, dGetIdentityMatrix())
   {
      //SetSolverModel(m_jointIterativeSoft); // old soft solver
      SetSolverModel(m_jointkinematicOpenLoop); // new exact solver
      //SetSolverModel(m_jointkinematicCloseLoop);   
      //SetSolverModel(m_jointkinematicAttachment);   
   }



I'm not sure if exact joints make a difference for a simple two body, one joint configuration, but i'd have some hope on this. IF you have multiple missiles attached, it should surely help a lot!
If it works, it might be needed to destroy the skeleton once the missile is launched.
But well, hopefully Julio comes back soon... ;)
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

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

Postby misho » Sat Nov 25, 2023 5:39 am

Hey, thanks for chiming in and taking time to write this up. I did some thinking about what Julio wrote, and then it struck me. So, went to test a few things and... I think I know what is going on.

I am setting the position/attitude from the sim data to the airplane Newton body thinking it rigidly follows it - but it does not. When I saw the missile lagging, it was actually airplane body lagging, with the missile firmly attached to it. It is in fact the AIRPLANE Newton body that has a lag. And just like Julio said - it is AIRPLANE body, as a parent, that needs to be applied impulses. I was reading it all wrong. If the airplane Newton body is properly following the sim aircraft, all the attached objects will behave correctly.

So, I went ahead and implemented the changes, namely, I am reading the SIM position, then Newton body position, calculating velocities and impulses per Julio's pseudo code, and applying it to the aircraft body. Attaching a missile doesn't matter, because when I get the Newton body to properly follow SIM aircraft, the attached objects will be in the correct places as well. That, however, is still not happening. Now, even when the SIM aircraft is at a stand still and not moving, I get the body oscillating up and down, and not settling into the aircraft's position. So, there is still something missing. Here is my new code, closely following Julio's algorithm, applied only to the Aircraft's Newton Body:

Code: Select all
void TBEntity::Phys_ApplySimObjectImpulse(double dBodyTimeStep)
{
   if (!dBodyTimeStep)
      return;

   dVector dvSIM_Position;
   dQuaternion dqSIM_Rotation;
   GetSIMPositionRotation(dvSIM_Position, dqSIM_Rotation);
   double dInvBodyMass = GetCurrentBodyMass(true);
   dVector dvNull(0.0, 0.0, 0.0, 1.0);

   dVector vDeltaV = (dvSIM_Position - GetPosition()).Scale(1.0f / dBodyTimeStep);
   dVector LinearImpulse = (vDeltaV - GetVelocity()).Scale(dInvBodyMass);

   NewtonBodyApplyImpulsePair(nBody, &LinearImpulse[0], &dvNull[0], dBodyTimeStep);
}
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 Dave Gravel » Sat Nov 25, 2023 6:13 am

Hi Misho,
I have conducted some quick tests with my engine and your demo. It's not perfect, but some parts of it may help you find a solution.

https://www.youtube.com/watch?v=Qxwe_ov4DUk

My code:
https://orionx3d.sytes.net/dgdemo10.h
https://orionx3d.sytes.net/dgdemo10.cpp

In the video at the beginning, I show you something from Blender 3D. Your meshes seem to be saved without the barrel center centered. In some mesh loaders used to generate collisions, it can cause problems if the barrel center is not properly centered. In such cases, the center position of the mesh becomes the point that you see in Blender. This point becomes the position of your mesh in 3D, similar to the mass centering. This incorrectly placed barrel center can cause issues. In my engine, it can lead to a lot of problems when the barrel center is not properly centered. My loader uses the exported barrel center.
Make sure to be cautious about it.

If you don't have debug lines, perhaps you should consider adding them. Debug lines can be very helpful in understanding certain problems.
It is very useful for seeing the mesh collision shape and checking if the joint is correctly placed and in the right direction same about force and more ...

In the video at the beginning, I tried a force method to move the plane, but it doesn't seem like the best solution. It is not the simplest method to keep the plane stable.

A bit further into the video, I use the joint ndJointKinematicController to move the plane. It seems to work quite well, but it starts causing some problems when I detach the Fuel Tank. I think I forgot to recalculate the mass when the tank is detached. This solution appears to work better in general, but I'm not sure if it could be useful for you.

Perhaps a better solution could be achieved by using a velocity method. I haven't had time to test it further for now.
I may have made a few mistakes; it was getting late, and I did it quickly. I might have overlooked a few things too, hehe. I'll try to see tomorrow if I can find another solution or if there's a way to make it better.
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: Porting from 3.xx to 4.00 - need help

Postby misho » Sat Nov 25, 2023 1:17 pm

Hi Dave!

Thanks for doing this, I really appreciate it! I quickly looked at the demo, looks promising! I am only worried that the speeds at which aircraft moves will cause instability. Is this in 3.14 or 4.00? Can I compile it and run it, or does it have some dependencies that I don't have access to?

As for debug window, I am actually working inside my sim, directly. I have various ways of monitoring data right inside the sim, for example a screen overlay, much like in the DemoSandBox. I reverted back to 3.14 because conversion to 4.00 was taking just too long and I've run into some issues that I have to think through. But since Julio said this can be done in 3.14, I decided to give it a shot in 3.14...

I have to go out for a few hours but I will take a closer look when I get back. Thanks again!
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 Dave Gravel » Sat Nov 25, 2023 4:48 pm

You're welcome; it's my pleasure. At the moment, all the solutions I've tried seem to have some instability issues. In some cases, it seems close to a solution, but there are a few things to iron out. I only had a little free time late at night to experiment. The demo uses Newton 4, but if I recall correctly, the latest Newton 3.14 had similar tools to reproduce the same or very similar results.

Currently, there's no quick way for me to provide you with all the code from my engine for you to compile the demo. I apologize for this; it's my 3D engine, and it's supposed to be public. However, I haven't had the time to clean up certain parts and the resources used. I've created several demos and tried various things, and in the folders, I have many unused resources that I need to remove. Before cleaning up, I need to finish certain demos. I would have liked to release a version for the holiday season or early 2024, but the pandemic and life's demands have taken away some of my free time. However, gradually, I have more and more time to work on my engine. I'll try to aim for a release in early 2024.

But, in general, most of the code is the same as Newton's, with only a few parts coming from my engine for graphics and some options for the parent-child system for visual objects. If you need information about a part that doesn't come from Newton, let me know. But, in general, you should understand the parts related to Newton. If there are pieces of code you need regarding specific commands I use, let me know too. I'll be happy to share the code; it's just that, at the moment, I'm not ready to release a version with everything. But I have no problem sharing parts of code before the public release.

I'll see if I have some time later in the day to explore other solutions or a better approach. Also, some approaches may depend on whether the aircraft should have collisions with other objects. If there's no collision interaction, perhaps a solution involving velocity would be better. When the plane moves, is it important for it to have all the normal interactions with physics? Or should the plane have interactions with physics other than just collisions? With force, the reaction is unstable because it takes into account all the physics, gravity, and linear and rotational forces. With movement through velocity, the result should be good to achieve the same effect as if you were changing the position directly. I had already created a demo that moved a platform in the air only by velocity with objects on the platform, and it worked quite well. Maybe there's a way to achieve something similar with the aircraft.

For my test with force, I use some tools that do not come directly from Newton. These are old tools that were posted here in the forum and that I had in my engine written in Pascal before. I translated them to use in C++ with Newton 4, but I haven't had much time to test them. So, there may be errors in my translation from Pascal to C++. I need to test them more to see if they work correctly. The command to apply a real force to an absolute real position seems to work well. I'll leave the code here in case you would like to experiment with it. If you see an error, I apologize; I haven't had time to test all the tools.
https://orionx3d.sytes.net/force_outils.txt
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: Porting from 3.xx to 4.00 - need help

Postby Dave Gravel » Sat Nov 25, 2023 7:37 pm

I conducted a test here by moving the airplane using velocity. If you integrate the velocity into the body of the tank while it is connected to the joint, it seems to work. If the velocity is not integrated into the body of the tank when it is connected to the joint, the body will experience lag, similar to when you directly change the matrix.
https://www.youtube.com/watch?v=lDEklwR7G4Q
My code:
https://orionx3d.sytes.net/dgdemo10_new.h
https://orionx3d.sytes.net/dgdemo10_new.cpp
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: Porting from 3.xx to 4.00 - need help

Postby misho » Mon Nov 27, 2023 3:13 am

Dave Gravel wrote:I conducted a test here by moving the airplane using velocity. If you integrate the velocity into the body of the tank while it is connected to the joint, it seems to work. If the velocity is not integrated into the body of the tank when it is connected to the joint, the body will experience lag, similar to when you directly change the matrix.
https://www.youtube.com/watch?v=lDEklwR7G4Q
My code:
https://orionx3d.sytes.net/dgdemo10_new.h
https://orionx3d.sytes.net/dgdemo10_new.cpp


Dave,

DEEP bow of gratitude for taking time, looking into this and setting this up for me! I looked through the code, and I have a few questions:

  • If I am reading the code correctly, both airplane and tank objects are Kinematic bodies, attached using a hard joint, correct?
  • I am seeing that a lot of the code is setting up the scene, but the "working" part is in Update() and PostUpdate() functions, correct?
  • You set velocities in Update/PostUpdate loops. I set velocities/forces/impulses in each of the object's callbacks, NewtonBodySetForceAndTorqueCallback, NewtonBodySetTransformCallback. Do I need to set mine in the Update/PostUpdate calls or does it matter where I call them?
  • I am using dynamic bodies in 3.14 and I see you are using kinematic bodies (Julio said Dynamic bodies would work using impulse method). Are they equivalent in 3.14 and 4.00?
  • did you try using Dynamic bodies?

To answer one of your questions in the previous post, yes, I would need all objects (aircraft and tank) to have collisions. One of the functionalities I plan to implement is creating a "cavity" in the airplane, a cargo hold where pallets of cargo will be attached, and with an unloading ramp door in the back. Then, there will be a way of detaching them and "pulling" them out of the cargo hold using a parachute system which will provide pulling force. For that, I obviously need a "floor" in the aircraft to hold the cargo, and then let it slide along the floor surface and out of the aircraft.

I will have more questions shortly :wink:
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 Dave Gravel » Mon Nov 27, 2023 5:32 am

I'm using Newton 4. In Newton 4, you can get a regular body as a kinematic body, and yes, I use a hard joint.

Update() and PostUpdate()

The functions Update() and PostUpdate() both come from the class ndModel. If you look in demo10.h, you can see that I have inherited the class ndModel. While I don't utilize all the features available for the model and the joint, it serves as a convenient place to manage a set of joints and bodies and apply custom forces and more.

You set velocities in Update/PostUpdate loops

Yes.
I have already used the same approach that you used in the old Newton regarding NewtonBodySetForceAndTorqueCallback and NewtonBodySetTransformCallback.
I think this method can work to some extent, but for more precision and synchronization, it is better to use the listener or ndModel when you need to build bodies and joints and control them in some way. Everything is handled in the right place and at the right time using these tools.

However, in the newer version, Julio added the listener in Newton 3.14, and it is equivalent to newton 4 ndModel or something similar. In Newton 3.14, you can find more information about this in the demo file KinematicBodies.cpp.

I am using dynamic bodies in 3.14 and I see you are using kinematic bodies

I am using Newton 4, but normally, you should be able to replicate the same thing regarding the velocity in newton 3.14.

Here, this file is an old version using 3.14 and the listener, accomplishing the same thing. I apologize, but I only have an old Pascal code example with this code. In Pascal, the class names for the listener are not exactly the same as in Newton. It's advisable to refer to the Newton demo for certain parts.
https://orionx3d.sytes.net/ox3d_kinematicplatform.pas
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: Porting from 3.xx to 4.00 - need help

Postby misho » Thu Nov 30, 2023 6:49 pm

Hi Dave!

I am working on this and making incremental progress! I have managed to get my Kinematic body to follow SIM controlled aircraft without any lag. However, I am not able to properly link the fuel tank object, and I am guessing it is the type of joint I am using....so, in your code, you are using:

ndJointFix6dof which is Newton 4

is that equivalent to Newton 3.14's dCustomSixdof?

Or, if not, what would be the equivalent of ndJointFix6dof in Newton 3.14?

EDIT:

Also, in the video I see both the aircraft and the tank falling under gravity, but I don't see where you apply gravity force to the objects... Where is that done?

Where do you create Kinematic Newton Bodies? m_PlaneMesh->InitNewton();?

Where do you set Omegas (rotational velocities) ? I guess you are not changing them so you are not setting them either, right?

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 Dave Gravel » Tue Dec 05, 2023 4:57 pm

Hi, sorry for the delay

If I'm not mistaken, ndJointFix6dof and dCustomSixdof are a bit different. Although both are 6-degree-of-freedom joints, I'm not entirely certain due to the new name. Perhaps you might find ndJointFixDistance more suitable for your needs, You can maybe do some tests with the dCustomKinematicController too.

I don't set the angular velocity (omega); instead, I only configure the linear velocity. This is done within the update method of the ndModel class. In Newton 3.14, this process is located inside the listener class.

In my engine, when I call InitNewton, it creates the Newton shape and the body, setting default values and assigning the transform callback, as well as the force and gravity callback. This is essentially a shortcut to avoid having these details cluttering the demo code; instead, they are configured within the engine.

In my video, I don't apply anything inside the force gravity callback, only the normal gravity force no more. Everything is handled within the ndModel class.

I haven't used joints extensively in the last Newton 4 version, and I'm not entirely familiar with all the changes and differences from version 3.14. As time has passed, version 3.14 is starting to feel a bit outdated for me, and I don't remember all the details. Before I made the switch to Newton 4, even in version 3.14, there were changes that I might not have kept up with.

In the code exemple of my demo you can see where I add the velocity.
void MishoPlane::Update(ndWorld* const world, ndFloat32 timestep)

void MishoPlane::PostUpdate(ndWorld* const world, ndFloat32 timestep)

Both function come from the ndModel, in newton 3.14 from the listener model.
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: Porting from 3.xx to 4.00 - need help

Postby misho » Tue Dec 05, 2023 7:53 pm

Hi Dave!

Again, thanks for your input! So, in my project, I am still using 3.14, and I would like to stay with 3.14 for now because porting the actual project to 4.00 still needs a bit of work, as there are a lot of intricacies that I have to address. So, I'll work with this in 3.14 till I hit a stone wall (and because Julio said what I need to do has been done in 3.14 before)

That being said - in the last week, after you provided your sample, I went ahead (working with a few assumptions) and implemented the class KinematicListener : public dCustomListenermethod right inside my project, using your example as a guide (thank you!). Also, as you suggested, I looked at the KinematicBodies DemoSandbox sample and that also helped me greatly. So now that I have this set up and running, I am STILL :roll: not getting the behaviour you have in your video. I am having a debugger running (alongside with Flight Simulator) and all the numbers look good - it is just that the fuel tank is not fixed to the wing - it moves, but with a lag (as if it is connected with a rubberband)

Reading your message, you suggested using a different joint (ndJointFixDistance), so I will try that as well. I'll post the code in here once I have it running - perhaps you can take a quick look and see if there is anything I missed... or - this approach is simply not possible in 3.14.

If the new joint doesn't work, I will go back to DemoSandbox 4.00 and replicate your code in it using ndModel. (that was actually what I was going to try before I got your message)

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 Dec 05, 2023 9:53 pm

Ok - I implemented the new joint. Here is my code:

KinematicListener.cpp
Code: Select all
void KinematicListener::Clean(void)
{
   for (dList<KinematicBody>::dListNode* ListNode = m_KinematicBodyList.GetFirst(); ListNode; ListNode = ListNode->GetNext())
   {
      m_KinematicBodyList.Remove(ListNode);
   }
}
void KinematicListener::Remove(NewtonBody *pBody)
{
   for (dList<KinematicBody>::dListNode* ListNode = m_KinematicBodyList.GetFirst(); ListNode; ListNode = ListNode->GetNext())
   {
      KinematicBody& ListEntry = ListNode->GetInfo();
      if (ListEntry.m_KinematicBody == pBody)
         m_KinematicBodyList.Remove(ListNode);
   }
}
void KinematicListener::PreUpdate(dFloat timestep)
{
   for (dList<KinematicBody>::dListNode* ListNode = m_KinematicBodyList.GetFirst(); ListNode; ListNode = ListNode->GetNext()) {

      KinematicBody& ListEntry = ListNode->GetInfo();
      TBEntity* pEnt = (TBEntity*)NewtonBodyGetUserData(ListEntry.m_KinematicBody);
      if (pEnt && pEnt->GetObjectType() == SIM_USER_OBJECT)
      {
         dVector dvSIM_Position;
         dQuaternion dqSIM_Rotation;
         pEnt->GetSIMPositionRotation(dvSIM_Position, dqSIM_Rotation);

         // linear velocity
         vParentLinearDifference = dvSIM_Position - pEnt->GetPosition();
         dVector vParentDeltaV = vParentLinearDifference.Scale(1.0f / timestep);

         switch (nMode)
         {
            case SET_VELOCITY:
               {
                  pEnt->SetVelocity(vParentDeltaV);
               }
               break;
            case SET_IMPULSE:
               {
                  dVector LinearImpulse(0.0, 0.0, 0.0, 1.0);
                  dVector dvNull(0.0, 0.0, 0.0, 1.0);
                  double dInvBodyMass = pEnt->GetCurrentBodyMass(true);
                  LinearImpulse = vParentDeltaV.Scale(dInvBodyMass);
                  NewtonBodyApplyImpulsePair(ListEntry.m_KinematicBody, &LinearImpulse[0], &dvNull[0], timestep);
               }
               break;
            default:
               break;
         }
      }
   }
}
void KinematicListener::PostUpdate(dFloat timestep)
{
   for (dList<KinematicBody>::dListNode* ListNode = m_KinematicBodyList.GetFirst(); ListNode; ListNode = ListNode->GetNext()) {
      const KinematicBody& ListEntry = ListNode->GetInfo();
      TBEntity* pEnt = (TBEntity*)NewtonBodyGetUserData(ListEntry.m_KinematicBody);
      if (pEnt)
      {
         if (pEnt->GetObjectType() == SIM_USER_OBJECT)
            NewtonBodyIntegrateVelocity(ListEntry.m_KinematicBody, timestep);
         else
         {
            if (pEnt->GetObjectType() == SIM_SIMOBJECT && pEnt->GetAttachPoint(0)->pHinge != NULL)
            {
               NewtonBodyIntegrateVelocity(ListEntry.m_KinematicBody, timestep);
            }
         }
      }
   }
}
void KinematicListener::AddKinematicBody(NewtonBody *pBody)
{
   KinematicBody& ListEntry = AddBodyToList(pBody);
}
KinematicListener::KinematicBody& KinematicListener::AddBodyToList(NewtonBody *pBody)
{
   KinematicBody& ListEntry = m_KinematicBodyList.Append()->GetInfo();
   ListEntry.m_KinematicBody = pBody;
   return ListEntry;
}


KinematicListener.h
Code: Select all
extern dVector vParentLinearDifference;
extern dVector vParentAngularDifference;
extern dVector vChildLinearDifference;
extern dVector vChildAngularDifference;
class KinematicListener : public dCustomListener
{
   enum {
      SET_NONE,
      SET_POSITION,
      SET_VELOCITY,
      SET_IMPULSE
   };

   int nMode;

   struct KinematicBody
   {
      NewtonBody* m_KinematicBody;
   };

public:
   KinematicListener(TBEntityManager* const scene)
      :dCustomListener(scene->GetNewton(), "")
      , m_KinematicBodyList()
      , nMode(SET_VELOCITY)
   {

   }

   ~KinematicListener()
   {

   }
   void Clean(void);
   void Remove(NewtonBody *pBody);
   void PreUpdate(dFloat timestep);
   virtual void PostUpdate(dFloat timestep);
   void AddKinematicBody(NewtonBody *pBody);

private:
   KinematicBody& AddBodyToList(NewtonBody *pBody);
   dList<KinematicBody> m_KinematicBodyList;
};


The bodies are both 3.14 Kinematic type... and I am attaching them with:

Code: Select all
dMatrix matrixParent;
dMatrix matrixChild;
NewtonBodyGetMatrix(targetEnt->nBody, &matrixParent[0][0]);
NewtonBodyGetMatrix(this->nBody, &matrixChild[0][0]);
new dCustomFixDistance(matrixChild.m_posit, matrixParent.m_posit, this->nBody, targetEnt->nBody);


So - I think I am doing everything as set out in your example, except I am in 3.14. Please let me know if anything jumps out at you...
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 45 guests

cron