OK, I now have a working example.
It appears that there is a different default value for SetObject3DPhysicsCanSleep() on a freshly generated physics object.
The first and second buttons rig the jointed object up with and without the setting and you can observe different behaviour.
Also, you can see the never going to sleep after the impulse and dejointing occurs.
[edit - fixed small bug in example]
In fact, just the impulse without doing the joints shows it..
// Project: test_sleep
// Created: 2017-04-01
// show all errors
global Cube1 as Integer
global Cube2 as Integer
global JointID as Integer
SetErrorMode(2)
// set window properties
SetWindowTitle( "test_sleep" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetSyncRate(60,0)
SetPrintSize(20)
SetSunActive(0)
CreatePointLight(1,0,100,0,500,255,255,255)
SetPointLightMode(1,1)
AddVirtualButton(1,400,35,60)
SetVirtualButtonText(1,"SetJoint"+chr(10)+"force sleep")
AddVirtualButton(2,480,35,60)
SetVirtualButtonText(2,"SetJoint"+chr(10)+"default sleep")
AddVirtualButton(3,560,35,60)
SetVirtualButtonText(3,"impulse")
Init3DWorld()
SetCameraRange(1,0.1,10000)
SetCameraFOV(1,45.24)
SetCameraPosition(1,0,50,-420)
SetCameraLookAt(1,0,50,0,0)
Cube1=CreateObjectBox(10,10,10)
SetObjectPosition(Cube1,-60,50,0)
PhysicsOn(Cube1)
Cube2=CreateObjectBox(10,10,10)
SetObjectPosition(Cube2,60,50,0)
SetObjectColor(Cube2,0,255,0,255)
PhysicsOn(Cube2)
// we have to manage our jointID ourselves...
JointID=-1
do
if GetVirtualButtonPressed(1) then SetJoint(1)
if GetVirtualButtonPressed(2) then SetJoint(0)
if GetVirtualButtonPressed(3) then Impulse()
Print( ScreenFPS() )
Print ("Physics bodies="+Str(Get3DPhysicsTotalObjects()))
Print ("Active Physics="+Str(Get3DPhysicsActiveObjects()))
Print(ShowVelocity())
Step3DPhysicsWorld()
Sync()
loop
end
function PhysicsOn(obj)
Create3DPhysicsDynamicBody(obj)
SetObjectShapeConvexHull(obj)
SetObject3DPhysicsMass(obj,10)
endfunction
function PhysicsOff(obj)
Delete3DPhysicsBody(obj)
endfunction
function SetJoint(ForceSleepMode)
PhysicsOff(cube1)
PhysicsOff(cube2)
SetObjectPosition(Cube1,0,15,0)
SetObjectPosition(Cube2,0,5,0)
SetObjectRotation(Cube1,0,0,0)
SetObjectRotation(Cube2,0,0,0)
// make sure there's no joint
KillJoint()
PhysicsOn(cube1)
PhysicsOn(cube2)
jpVec=CreateVector3(0,10,0)
jrVec=CreateVector3(0,0,1)
JointID=Create3DPhysicsHingeJoint(Cube1,Cube2,jpVec,jrVec,0)
DeleteVector3(jpVec)
DeleteVector3(jrVec)
// objects should have this already set, but behaviour is different if you don't set this straight after jointing the objects (they will wobble for a bit)
if ForceSleepMode=1
SetObject3DPhysicsCanSleep(Cube1,1)
SetObject3DPhysicsCanSleep(Cube2,1)
endif
endfunction
function KillJoint()
if JointID>0
Delete3DPhysicsJoint(JointID)
JointID=-1
endif
endfunction
function Impulse()
// if object is slept, then this allows it to be affected
SetObject3DPhysicsCanSleep(Cube1,0)
SetObject3DPhysicsAngularVelocity(Cube1,0,0,1,1500)
KillJoint()
// now we should set this so it can go to sleep again.
// doesn't matter if you unjoint before or after this command. Object won't go back to sleep again.
SetObject3DPhysicsCanSleep(Cube1,1)
// just in case?!
SetObject3DPhysicsCanSleep(Cube2,1)
endfunction
function Init3DWorld()
Create3DPhysicsWorld()
Set3DPhysicsGravity(0.0, -10.0, 0.0)
FloorBoxID=CreateObjectBox(500,32,500)
SetObjectColor(FloorBoxID,255,0,0,255)
SetObjectPosition(FloorBoxID,0,-16,0)
Create3DPhysicsStaticBody(floorBoxID)
SetObjectShapeBox(floorBoxID)
endfunction
function ShowVelocity()
v$="linear="+str(GetObject3DPhysicsLinearVelocityX(Cube1))+","+str(GetObject3DPhysicsLinearVelocityY(Cube1))+","+str(GetObject3DPhysicsLinearVelocityZ(Cube1))+chr(10)
v$=v$+"angular="+str(GetObject3DPhysicsAngularVelocityX(Cube1))+","+str(GetObject3DPhysicsAngularVelocityY(Cube1))+","+str(GetObject3DPhysicsAngularVelocityZ(Cube1))+chr(10)
v$=v$+"threshold="+Str(GetObject3DPhysicsAngularSleepingThreshold(Cube1))+chr(10)
v$=v$+"threshold="+Str(GetObject3DPhysicsLinearSleepingThreshold(Cube1))+chr(10)
v$=v$+"friction="+Str(GetObject3DPhysicsFriction(Cube1))
endfunction v$