Built-in hinge joint limits

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Built-in hinge joint limits

Postby Ender13 » Fri Feb 20, 2009 2:50 pm

Well, looking through the documentation I've found 2 or 3 ways to implement hinge joint limits, but they all require callbacks. I'm using the Leadwerks Engine and BlitzMax, and using callbacks to the dll requires me to use byte pointers, and I'm no pro programmer so it's way over my head.

Since ball and socket joints have a built in command to set the cone limits I was wondering why there isn't a built in command for hinge limits. It seems like a pretty standard feature for joints in a physics engine. I have been battling getting ragdolls in Leadwerks Engine and the lack of hinge joint limits is driving me crazy! :mrgreen:
Ender13
 
Posts: 4
Joined: Tue Dec 30, 2008 7:03 pm

Re: Built-in hinge joint limits

Postby Julio Jerez » Fri Feb 20, 2009 3:00 pm

that joint inteface is part of an opsoleted interface in which each feature had to be hard code inside the engine.
The Custom Joint Library supersede all of the build in joints and they have a C inteface as well.
The cudtom joint allow the end user to write the control regulat joints in data drive way rather than by using callbacks.
For that the joint libary now provides this interface.
Code: Select all
// Generic 6 degree of Freedom Joint
JOINTLIBRARY_API NewtonCustomJoint *CreateCustomJoint6DOF (const dFloat* pinsAndPivoChildFrame, const dFloat* pinsAndPivoParentFrame, const NewtonBody* child, const NewtonBody* parent);
JOINTLIBRARY_API void CustomJoint6DOF_SetLinearLimits (NewtonCustomJoint* customJoint6DOF, const dFloat* minLinearLimits, const dFloat* maxLinearLimits);
JOINTLIBRARY_API void CustomJoint6DOF_SetAngularLimits (NewtonCustomJoint* customJoint6DOF, const dFloat* minAngularLimits, const dFloat* maxAngularLimits);
JOINTLIBRARY_API void CustomJoint6DOF_GetLinearLimits (NewtonCustomJoint* customJoint6DOF, dFloat* minLinearLimits, dFloat* maxLinearLimits);
JOINTLIBRARY_API void CustomJoint6DOF_GetAngularLimits (NewtonCustomJoint* customJoint6DOF, dFloat* minAngularLimits, dFloat* maxAngularLimits);
JOINTLIBRARY_API void CustomJoint6DOF_SetReverseUniversal (NewtonCustomJoint* customJoint6DOF, int order);


It is a general 6DOF joint that can be set to recreate most of all regulnr joints, and set limits in a data driven way, rather tha in callback way.
I do not knwo if Lewerk exposr that inteface, bu I sugest tio use this one intead of teh old Jopint of 1.53.

FVor more specialized joints The inetface is no exposed yet, but if you get t o that level they you will bave no problleme expaing the inteface to use your own special jopints.

In addition the joint libray is open source so that end application can modify the code and get all the infomation it needs inside teh joint library itself, .
Therefore the Game Engine interface do not have to be extended with a prolifaration of funtions jsut to add minor funtionality.

The Game engien will only need to expose the interface to teh Custom joint callbacks.
My impression is that Custom jopint the inteface must be avialable with Leawerk engine to the end users since he uses the
Car joint and the player joint which are just special custom joints.

Code: Select all
   // player controller functions
   JOINTLIBRARY_API NewtonCustomJoint *CreateCustomPlayerController (const dFloat* pins, const NewtonBody* player, dFloat maxStairStepFactor);
   JOINTLIBRARY_API void CustomPlayerControllerSetPushActorCallback (NewtonCustomJoint* playerController, PlayerCanPuchThisBodyCalback callback);
   JOINTLIBRARY_API void CustomPlayerControllerSetVelocity (NewtonCustomJoint* playerController, dFloat forwardSpeed, dFloat sideSpeed, dFloat heading);
   JOINTLIBRARY_API void CustomPlayerControllerSetMaxSlope (NewtonCustomJoint* playerController, dFloat maxSlopeAngleIndRadian);
   JOINTLIBRARY_API dFloat CustomPlayerControllerGetMaxSlope (NewtonCustomJoint* playerController);
   JOINTLIBRARY_API const NewtonCollision* CustomPlayerControllerGetVerticalSensorShape (NewtonCustomJoint* playerController);
   JOINTLIBRARY_API const NewtonCollision* CustomPlayerControllerGetHorizontalSensorShape (NewtonCustomJoint* playerController);
   JOINTLIBRARY_API const NewtonCollision* CustomPlayerControllerGetDynamicsSensorShape (NewtonCustomJoint* playerController);



Code: Select all
    JOINTLIBRARY_API NewtonCustomJoint *DGRaycastVehicleCreate (int maxTireCount, const dFloat* cordenateSytem, NewtonBody* carBody);
    JOINTLIBRARY_API void DGRaycastVehicleAddTire (NewtonCustomJoint *car, void *userData, const dFloat* localPosition, dFloat mass, dFloat radius, dFloat width, dFloat friction, dFloat suspensionLength, dFloat springConst, dFloat springDamper, int castMode);
    JOINTLIBRARY_API void DGRayCarGetChassisMatrixLocal(NewtonCustomJoint *car, dFloat* chassisMatrix);
    JOINTLIBRARY_API void DGRayCarTireMatrix(NewtonCustomJoint *car, int tire, dFloat* tireMatrix);
   JOINTLIBRARY_API void DGRayCarSuspensionMatrix(NewtonCustomJoint *car, int tire, dFloat param, dFloat* SuspensionMatrix);   
   JOINTLIBRARY_API const NewtonCollision* DGRayCarTireShape(NewtonCustomJoint *car, int tireIndex);   
   JOINTLIBRARY_API dFloat DGRaycastVehicleGetSpeed(NewtonCustomJoint *car);
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Built-in hinge joint limits

Postby Ender13 » Fri Feb 20, 2009 3:33 pm

Yeah, the JointLibrary.dll is included with LE now. I'll have to figure out how user joints work... I've tried a few times but get lost about the time that around 7 linear rows were added to a hinge joint...

It appears that the JointLibrary is actually exposed through LE, so I'll have to see if I can get that working.


I noticed the 2.0 SDK has a CustomHinge.cpp file. I couldn't follow it though because it was drawing code from what seemed like 20 or so other cpp files through multiple headers. :cry:
Ender13
 
Posts: 4
Joined: Tue Dec 30, 2008 7:03 pm

Re: Built-in hinge joint limits

Postby Julio Jerez » Fri Feb 20, 2009 3:52 pm

If yo uread teh FAQ in teh forum, you will get teh idea how to use teh 6DOF joint

viewtopic.php?f=15&t=3501

There are varios exampel of how to make standrd joint by using the Custom6DOF,
For exampel a JHing with limit woudl be this

Code: Select all
dMatrix pinsAndPivoFrame (location);
dVector minLinearLimits (0.0f, 0.0f, 0.0f, 0.0f);
dVector maxLinearLimits (0.0f, 0.0f, 0.0f, 0.0f);
dVector minAngularLimits (-30.0f * 3.1416 / 180.0f, 0.0f, 0.0f, 0.0f);
dVector maxAngularLimits ( 30.0f * 3.1416 / 180.0f, 0.0f, 0.0f, 0.0f);
new Custom6DOF (pinsAndPivoFrame, pinsAndPivoFrame, minLinearLimits, maxLinearLimits, minAngularLimits, maxAngularLimits, boxBody, NULL);


using the C interface would be sometjhing like this

// Generic 6 degree of Freedom Joint

JOINTLIBRARY_API void CustomJoint6DOF_SetLinearLimits (NewtonCustomJoint* customJoint6DOF, const dFloat* minLinearLimits, const dFloat* maxLinearLimits);
JOINTLIBRARY_API void CustomJoint6DOF_SetAngularLimits (NewtonCustomJoint* customJoint6DOF, const dFloat* minAngularLimits, const dFloat* maxAngularLimits);
JOINTLIBRARY_API void CustomJoint6DOF_GetLinearLimits (NewtonCustomJoint* customJoint6DOF, dFloat* minLinearLimits, dFloat* maxLinearLimits);
JOINTLIBRARY_API void CustomJoint6DOF_GetAngularLimits (NewtonCustomJoint* customJoint6DOF, dFloat* minAngularLimits, dFloat* maxAngularLimits);
JOINTLIBRARY_API void CustomJoint6DOF_SetReverseUniversal (NewtonCustomJoint* customJoint6DOF, int order);

Code: Select all
set the matrix here (the last 4 float and the pivot, the firt threes floats is the pin direction)
float pinsAndPivoChildFrame[16] //
hinge = CreateCustomJoint6DOF (pinsAndPivoChildFrame,  pinsAndPivoParentFrame, child, parent);

float lowLimitInradian;  // a negative value
float highLimitInradian;  // a positive value

float minLinearLimits[4] =  (0.0f, 0.0f, 0.0f, 0.0f);
float maxLinearLimits[4] = (0.0f, 0.0f, 0.0f, 0.0f);
minAngularLimits (lowLimitInradian, 0.0f, 0.0f, 0.0f);
maxAngularLimits (highLimitInradian, 0.0f, 0.0f, 0.0f);

CustomJoint6DOF_SetLinearLimits (hinge, minLinearLimits,  maxLinearLimits);
CustomJoint6DOF_SetAngularLimits (hinge, minAngularLimits, maxAngularLimits);

and badabim badabum you get a joint withe limits.

The Custom Hinge is for when you wnat to make soem special funtionality in teh callback itself.

It is also possible to make special funtionality using the #DOF fiund bu you will have to do the same precedure you nee to do fo custimizing the Hinge.
you can see the Custom joint like Shaders for the physics engine.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Built-in hinge joint limits

Postby Ender13 » Fri Feb 20, 2009 7:44 pm

So to replicate this method of hinge limits in BlitzMax I'll have to convert the Custom6DOF.h, Custom6DOF.cpp, NewtonCustomJoint.h, and NewtonCustomJoint.cpp to BlitzMax code? Is that everything that is needed for a Custom6DOF joint?

I'm starting to regret using BlitzMax with Leadwerks! :lol:


By the way, what is "JOINTLIBRARY_API" in the code?
Ender13
 
Posts: 4
Joined: Tue Dec 30, 2008 7:03 pm

Re: Built-in hinge joint limits

Postby Leadwerks » Fri May 08, 2009 9:32 pm

I've been talking to Dave on MSN, and this is really complicated. The problem is there are a lot of little parts and even if I got one part right, I would have no way of knowing it. I think this should be added to the main API, along with slider limits and fixed joints. I could spend a month on this and get nowhere.
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Built-in hinge joint limits

Postby Leadwerks » Mon May 11, 2009 1:57 pm

.
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Built-in hinge joint limits

Postby Dave Gravel » Tue May 12, 2009 2:28 am

Anyway one thing where i'm sure it is not a problem from newton.
The problem is from something about the matrix transformation's...

Same code that I use in c++ and delphi pascal opengl and directx set right handed seen to work good.
It is possible that you use the left hand and in the main transform callback you corect the matrix for fit it with your system or something like this ?
Maybe it is better to fix this problem with setting a offsetmatrix, I don't know what for now but something happening about the matrix.
In other language's all of this working like a charm, i'm sure with blitz it can work like a charm too but something is wrong somewhere.
It's not fun to debug and find what exactly but this is not a newton problem.

Thanks.
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: Built-in hinge joint limits

Postby Dave Gravel » Wed May 13, 2009 2:21 am

Here just some experimental tests from my part.
http://oxnewton.googlepages.com/Leadwer ... ntTest.zip
The pins or matrix need to come fixed, but this part of code can surely help...
I don't have more times to work on it from my side, have good luck.
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: Built-in hinge joint limits

Postby Leadwerks » Wed May 13, 2009 9:56 pm

Thanks to Dave, I got the fixed joint working.
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Built-in hinge joint limits

Postby Leadwerks » Wed May 13, 2009 10:19 pm

How are the pinsAndPivoChildFrame and pinsAndPivoParentFrame matrices calculated? I found this code in the demo source. Is it always the same for each kind of joint?:

Code: Select all
dMatrix pinAndPivot (GetIdentityMatrix());
      pinAndPivot.m_front = dVector (0.0, 1.0f, 0.0f, 0.0f);
      pinAndPivot.m_up = location.m_front * pinAndPivot.m_front;
      pinAndPivot.m_up = pinAndPivot.m_up.Scale (1.0f /dSqrt (pinAndPivot.m_up % pinAndPivot.m_up));
      pinAndPivot.m_right = pinAndPivot.m_front * pinAndPivot.m_up;
      pinAndPivot.m_posit = location.m_posit - location.m_front.Scale (size.m_x * 0.5f);
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Built-in hinge joint limits

Postby Dave Gravel » Thu May 14, 2009 12:34 am

Is it always the same for each kind of joint?:


NO, some use similar and some is totally diff.
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: Built-in hinge joint limits

Postby Leadwerks » Fri May 15, 2009 5:44 pm

For the hinge joint, I found that all I had to do was create a matrix from a direction and position. It did not have to be local to either body matrix, and it works regardless of parent and child position and rotation. Both matrix arguments receive this same matrix. I actually had to align the first row of the matrix (x) to the pin direction, which is a little weird, but consistent with the Newton matrix convention of the first row being "front"; just in case anyone else runs into a problem with this.
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron