on the other hand i have found that we can simulate spring by using two adjacent hinge joints, and it seems this is a universal approach and works with other engines.
the two joints such as this:
MP_ConstraintCreateHinge(beam,0,0,1,0,0,0)
MP_ConstraintCreateHinge(beam,0,0,1,0.05,0,0)
when we push one side of the beam and then release it will return to its original position
make the second joint more closely
MP_ConstraintCreateHinge(beam,0,0,1,0,0,0)
MP_ConstraintCreateHinge(beam,0,0,1,0.01,0,0)
and the spring will be very soft
make the joints seperated too much
MP_ConstraintCreateHinge(beam,0,0,1,0,0,0)
MP_ConstraintCreateHinge(beam,0,0,1,0.08,0,0)
and the spring is too hard
Code: Select all
Declare dropWeight(pos.f)
MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "spring ..Z/X drop weights ")
camera = MP_CreateCamera()
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
MP_PositionEntity(cam0, 0, 10, -4)
MP_EntityLookAt(cam0, 0, 2, 0)
tex0 = MP_CreateTextureColor(128, 128, RGBA(0, 255, 0, 0))
MP_MaterialEmissiveColor(tex0, 0, 122, 132, 132)
Global tex1 = MP_CreateTextureColor(128, 128, RGBA(25, 15, 255, 250))
MP_MaterialEmissiveColor(tex1, 0, 122, 132, 132)
tex2 = MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\MRAMOR6X6.jpg")
ground = MP_CreateRectangle(5, 0.5, 5)
MP_PositionEntity(ground, 0, -2,0)
MP_EntitySetTexture(ground, tex0)
MP_PositionEntity(cam0, 0, 5, -5) ; to look better
MP_EntityLookAt(cam0, 0, 1, 0)
texture = MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\MRAMOR6X6.jpg")
beam = MP_CreateRectangle(4,0.2,0.7)
MP_EntitySetTexture(beam, tex2)
MP_PositionEntity(beam, 0.0, 2.0, 0 )
MP_PositionEntity(beam, 0.0, 1.0, 0 )
MP_PhysicInit()
MP_EntityPhysicBody(beam, 2, 0.5)
; Hinge
;MP_ConstraintCreateHinge(beam,0,0,1)
;MP_ConstraintCreateHinge(beam,0.2,0,1)
;MP_ConstraintCreateHinge(Entity, PinX.f, PinY.f, PinZ.f [, Pivotx.f, Pivoty.f, Pivotz.f [, MasterEntity]])
MP_ConstraintCreateHinge(beam,0,0,1,0,0,0)
MP_ConstraintCreateHinge(beam,0,0,1,0.05,0,0)
MP_EntityPhysicBody(ground, 1, 1)
;mp_wireframe(1)
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
;MP_EntityAddImpulse(beam, -0.1, 0, 0 , 0, 0, 2.0)
If MP_KeyHit(#PB_Key_X)
dropWeight(1.8)
ElseIf MP_KeyHit(#PB_Key_Z)
dropWeight(-1.8)
EndIf
MP_PhysicUpdate()
MP_RenderWorld() ; Erstelle die Welt
MP_Flip () ; Stelle Sie dar
Wend
End
Procedure dropWeight(pos.f)
box = MP_CreateRectangle(0.2,0.2,0.2)
MP_EntitySetTexture(box, tex1)
MP_PositionEntity(box, pos.f, 2.7, 0 )
MP_EntityPhysicBody(box, 2, 0.2)
EndProcedure
**MP_PositionMesh ---> MP_PositionEntity
**all camera move and position to Entity move or position
**MP_ChangeMeshCoord should be deleted
these functions are every where in the examples, i suggest using a utility such as search and replace to replace or delete these obsolete functions
Edit: edited lines 42, 43 so to be compatible with the Docs
;MP_ConstraintCreateHinge(Entity, PinX.f, PinY.f, PinZ.f [, Pivotx.f, Pivoty.f, Pivotz.f [, MasterEntity]])
Code: Select all
MP_ConstraintCreateHinge(beam,0,0,1,0,0,0)
MP_ConstraintCreateHinge(beam,0,0,1,0.05,0,0)
this version means that the 2 joints have same orientation but separated slightly on X coordinate.