Fixed joint, again

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Fixed joint, again

Postby Leadwerks » Fri May 08, 2009 2:33 pm

I keep putting off joint constraints and fixed joints, because every time I start working on them, I never get very far, and something else takes my attention away. This is just about the only thing left to implement in my engine, so I want to take care of this now.

This explanation does not make sense to me. There is a custom joint in the Newton SDK, and there is also the extra joint library. I don't know which of these this is using, nor do I understand how to access this with the BlitzMax programming language:
viewtopic.php?f=15&t=4056

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

Re: Fixed joint, again

Postby Dave Gravel » Fri May 08, 2009 5:27 pm

The simple joints is only some custom joints already done in newton library,
Surely by julio in the pass for save some times when you don't need any special modification on the joint.
This is coming with the old newton version, now it is replaced with the jointlibrary.dll in a sence...
Why remove something from a lib when it working good already and it is debuged a lot already.

With a game or more complex simulation you can need to override or totally rewrite a special joint and have some special internal variables, function, procedure.
This is the custom joint task.

You use the base custom joint class and rewrite around and override your personal joint.
In the link that you post, you can see a custom joint creation and it is inherited from the base custom joint object class.
The pins placement and direction is all set and done by the custom joint creation.
With more complex joint creation it is possible to update the pins in runtime from the SubmitConstrainst.
The custom joint creation reproduce 2 initial matrix information with the objects space, CalculateLocalMatrix.

The other part this one is really important is the SubmitConstrainst.
It is again inherited from the custom joint base object class and override with your personal commands.
CalculateGlobalMatrix permit to work in the joint space when you add Constrainsts in your joint.
The other important thing is to respect the maxdof count.

1 maxdof = one row constrainst command like this NewtonUserJointAddLinearRow ...
If you have two row constrainst commands you increment the maxdof.
Just to make attention when you use exemple [if and else] in the SubmitConstrainst

exemple:
if limitemax < 0 then
NewtonUserJointAddLinearRow
else
NewtonUserJointAddLinearRow
This is egal to only 1 maxdof.

Edited:
If you like to use customjoint,
You create a personal base joint object class and you implement it the way that you like and prefer.
It depending a lot from the system that you use for create and control your objects.
After you can use it like a userdata and you can call and retrive it from the custom joint callback creation and in runtime too.


Sorry for my english i'm not super good to explain stuff, 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: Fixed joint, again

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

I got the beginning of the joint set up:

Code: Select all
   'General joint creation function
   Function Create:TFixedJoint(parent:TBody,child:TBody,pos:Byte Ptr,style=BALLJOINT,pin1:Byte Ptr=Null,pin2:Byte Ptr=Null)
      Local joint:TFixedJoint=New TJoint
      joint.newtonjoint=NewtonConstraintCreateUserJoint(joint.newtonWorld,6,NewtonUserBilateralCallBack,NewtonUserBilateralGetInfoCallBack,child.newtonBody,parent.newtonBody)
      
      Return joint
   EndFunction
   
   Function UserBilateralCallBack(userJoint:Byte Ptr,timestep:Float,threadIndex:Int)
      Local joint:TJoint
      joint=TJoint(NewtonGetJointUserData(userjoint))
      
   EndFunction
   
   Function NewtonUserBilateralGetInfoCallBack(userJoint:Byte Ptr,info:Byte Ptr)
      Local joint:TJoint
      joint=TJoint(NewtonGetJointUserData(userjoint))
      
   EndFunction
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Fixed joint, again

Postby Leadwerks » Wed May 13, 2009 4:17 pm

With Dave Gravel's help, the wiki, and some divine inspiration, I got a fixed joint working perfectly. Here is the code:
Code: Select all
Rem
bbdoc:
EndRem
Type TJointCustomFixed Extends TJointCustom
   
   Field childrelativeposition:TVec3
   Field childrelativeaxes:TVec3[3]
   Field parentrelativeaxes:TVec3[3]
   
   Method SubmitConstraint(timestep:Float,threadIndex:Int)
      Local matrix0: TMat4=New TMat4
      Local matrix1: TMat4=New TMat4
      Local desiredposition:TVec3
      Local p0:TVec3
      Local p1:TVec3
      Const dist:Float=5000
      
      newtonbodygetmatrix parent.newtonbody,matrix0
      newtonbodygetmatrix child.newtonbody,matrix1
      desiredposition=TFormPointm(childrelativeposition,matrix0,Null)
      
      NewtonUserJointAddLinearRow( newtonJoint, matrix1.Translation(), desiredposition, vec3(1,0,0) )
      NewtonUserJointAddLinearRow( newtonJoint, matrix1.Translation(), desiredposition, vec3(0,1,0) )
      NewtonUserJointAddLinearRow( newtonJoint, matrix1.Translation(), desiredposition, vec3(0,0,1) )
      
      p0=matrix0.Translation().plus( TFormVectorm(parentrelativeaxes[0],matrix0,Null).Scale( dist ) )
      p1=matrix1.Translation().plus( TFormVectorm(childrelativeaxes[0],matrix1,Null).Scale( dist ) )
      NewtonUserJointAddLinearRow(NewtonJoint, p1, p0, matrix0.J() )
      NewtonUserJointAddLinearRow(NewtonJoint, p1, p0, matrix0.K() )
      
      p0=matrix0.Translation().plus( TFormVectorm(parentrelativeaxes[1],matrix0,Null).Scale( dist ) )
      p1=matrix1.Translation().plus( TFormVectorm(childrelativeaxes[1],matrix1,Null).Scale( dist ) )
      NewtonUserJointAddLinearRow (NewtonJoint, p1, p0, matrix0.K() )
   EndMethod
   
   Function Create:TJointCustomFixed(parent:TBody,child:TBody)
      Local joint:TJointCustomFixed=New TJointCustomFixed
      joint.parent=parent
      joint.child=child
      
      joint.childrelativeposition=TFormPoint(joint.child.position,joint.child.parent,joint.parent)
      joint.childrelativeaxes[0]=TFormVector(vec3(1,0,0),Null,joint.child)
      joint.childrelativeaxes[1]=TFormVector(vec3(0,1,0),Null,joint.child)
      joint.childrelativeaxes[2]=TFormVector(vec3(0,0,1),Null,joint.child)
      joint.parentrelativeaxes[0]=TFormVector(vec3(1,0,0),Null,joint.parent)
      joint.parentrelativeaxes[1]=TFormVector(vec3(0,1,0),Null,joint.parent)
      joint.parentrelativeaxes[2]=TFormVector(vec3(0,0,1),Null,joint.parent)
      
      joint.NewtonJoint=NewtonConstraintCreateUserJoint(parent.world.newtonWorld,6,NewtonUserBilateralCallBack,Null,child.newtonBody,parent.newtonBody )
      
      NewtonJointSetUserData(joint.newtonJoint,joint)
      joint.ConnectLinks()
      Return joint
   EndFunction
   
EndType

Rem
bbdoc: Creates a new joint.
EndRem
Function CreateJointFixed:TJointCustomFixed(parent:TBody,child:TBody)
   Return TJointCustomFixed.Create(parent,child)
EndFunction
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 19 guests

cron