Playing around a bit more with picking up objects and dropping them. Most of the time it looks like it works - but try holding an object then turn around. The rotation kinda flips out when you drop it (but only when using dynamicBody)
It seems that
Create3DPhysicsDynamicBody( LeftHandContact ) // <<<<< This rotates the object ?
Create3DPhysicsKinematicBody( LeftHandContact ) // <<<< This works fine ....
/Wopag
//Load the AGKVR plugin
#import_plugin AGKVR
#constant FALSE = 0
#constant TRUE = 1
A_down as integer = FALSE
B_down as integer = FALSE
Global fixedThing as integer = FALSE
//Init App
SetWindowTitle( "demo" )
SetSyncRate(0, 0)
SetWindowSize( 1024, 768, 0 )
SetScissor(0, 0, 0, 0)
`Setup Physics
Create3DPhysicsWorld(1)
InitError As Integer
RightEyeImg As Integer = 500
LeftEyeImg As Integer = 501
InitError = AGKVR.Init( RightEyeImg, LeftEyeImg )
AGKVR.LockPlayerTurn( 1 )
AGKVR.LockPlayerPitch( 0 )
//Hand Model ID numbers
RightHandModel as integer = 100
LeftHandModel as integer = 101
HandModelImg as integer = 100
UseNewDefaultFonts( 1 )
SetPrintSize( 10 )
SetPrintColor( 255,0,0 )
SetShadowMappingMode( 3 )
SetShadowSmoothing( 1 )
// 0 = no smoothing --- no gradients
// 1 = multismapling --- pixelated gradients
// 2 = random multisampling --- gradients smoothed with shimering noise
SetShadowMapSize( 2048, 2048 ) // Higher equals better quality shadows
SetShadowRange( 30 ) // -1 to use the full camera range
SetShadowBias( 0.0012 ) // offset shadows slightly to avoid shadow artifacts
//Generate Mipmaps for nicer looking textures
SetGenerateMipmaps( 1 )
//Create Skybox
SetSkyBoxHorizonColor( 200, 200, 255 )
SetSkyBoxHorizonSize( 10, 2 )
SetSkyBoxSkyColor( 50, 50, 255)
SetSkyBoxSunColor( 255,255,255 )
SetSkyBoxVisible( 1 )
SetSkyBoxSunSize( 1, 3.0 )
SetSkyBoxSunVisible( 1 )
//Load Hand Models
//---------------------------
//Right Hand
LoadObjectWithChildren(RightHandModel,"RHand.FBX")
SetObjectScale(RightHandModel,1.15,1.15,1.15)
SetObjectPosition(RightHandModel,0.0,0.0,-0.07)
SetObjectRotation(RightHandModel,0.0,180.0,90.0)
FixObjectPivot(RightHandModel)
SetObjectAnimationSpeed(RightHandModel,20)
LoadImage(HandModelImg,"Hand.png")
SetObjectImage(RightHandModel,HandModelImg,0)
SetObjectVisible(RightHandModel,0)
SetObjectCollisionMode(RightHandModel,0)
//Left Hand
LoadObjectWithChildren(LeftHandModel,"LHand.FBX")
SetObjectScale(LeftHandModel,1.15,1.15,1.15)
SetObjectPosition(LeftHandModel,0.0,0.0,-0.07)
SetObjectRotation(LeftHandModel,0.0,180.0,270.0)
FixObjectPivot(LeftHandModel)
SetObjectAnimationSpeed(LeftHandModel,20)
SetObjectImage(LeftHandModel,HandModelImg,0)
SetObjectVisible(LeftHandModel,0)
SetObjectCollisionMode(LeftHandModel,0)
//Call function to load world models
Gosub _LoadWorld
AGKVR.SetCameraRange( 0.01, 1000.0 )
gosub _CreatePhysicsObjects
do
//Get AGKVR's Player container's current Position, which will be used later for collision purposes:
PlayerPosX as float
PlayerPosY as float
PlayerPosZ as float
PlayerPosX = AGKVR.GetPlayerX()
PlayerPosY = AGKVR.GetPlayerY()
PlayerPosZ = AGKVR.GetPlayerZ()
//Control Player Turn Angle with Left Controller Joystick
valx as float
valz as float
valx = AGKVR.LeftController_JoyX( )
AGKVR.RotatePlayerLocalY( valx )
//Control Player Movement based on Right Controller Joystick
valx = AGKVR.RightController_JoyX( )
valz = AGKVR.RightController_JoyY( )
AGKVR.MovePlayerLocalZ( valz*0.06 )
AGKVR.MovePlayerLocalX( valx*0.06 )
Rvalue as float
Lvalue as float
Rvalue = AGKVR.RightController_Trigger( )
Lvalue = AGKVR.LeftController_Trigger( )
SetObjectAnimationFrame(RightHandModel, GetObjectAnimationName( RightHandModel, 1 ), GetObjectAnimationDuration(RightHandModel,GetObjectAnimationName( RightHandModel, 1 ))*Rvalue,0)
SetObjectAnimationFrame(LeftHandModel, GetObjectAnimationName( LeftHandModel, 1 ), GetObjectAnimationDuration(LeftHandModel,GetObjectAnimationName( LeftHandModel, 1 ))*Lvalue,0)
AGKVR.UpdatePlayer( )
//Position Hand Objects
if AGKVR.RightControllerFound( ) = 1
SetObjectPosition( RightHandModel, AGKVR.GetRightHandX(), AGKVR.GetRightHandY(), AGKVR.GetRightHandZ())
SetObjectRotation( RightHandModel, AGKVR.GetRightHandAngleX(), AGKVR.GetRightHandAngleY(), AGKVR.GetRightHandAngleZ())
SetObjectVisible( RightHandModel, 1 )
SetObjectPosition( RHandPhys, AGKVR.GetRightHandX(), AGKVR.GetRightHandY(), AGKVR.GetRightHandZ())
else
SetObjectVisible( RightHandModel, 0 )
endif
if AGKVR.LeftControllerFound( ) = 1
SetObjectPosition( LeftHandModel, AGKVR.GetLeftHandX(), AGKVR.GetLeftHandY(), AGKVR.GetLeftHandZ())
SetObjectRotation( LeftHandModel, AGKVR.GetLeftHandAngleX(), AGKVR.GetLeftHandAngleY(), AGKVR.GetLeftHandAngleZ())
SetObjectVisible( LeftHandModel, 1 )
SetObjectPosition( LHandPhys, AGKVR.GetLeftHandX(), AGKVR.GetLeftHandY(), AGKVR.GetLeftHandZ())
else
SetObjectVisible( LeftHandModel, 0 )
endif
`Grab and manipulate 3D Objects
`-------------------------------------
CheckContact = 0
if LeftHandContact = 0 and LHandJoint = 0 and AGKVR.LeftController_Trigger( ) > 0.5
ObjectSphereCast( 0, AGKVR.GetLeftHandX()-0.01, AGKVR.GetLeftHandY()-0.01, AGKVR.GetLeftHandZ()-0.01, AGKVR.GetLeftHandX()+0.01, AGKVR.GetLeftHandY()+0.01, AGKVR.GetLeftHandZ()+0.01, 0.2)
if GetObjectRayCastNumHits() = TRUE // if an object is currently being hit ...
touchedObject = GetObjectRayCastHitID(0)
AGKVR.LeftController_TriggerPulse( 0,1000 )
LeftHandContact = touchedObject
SetObjectCollisionMode(LeftHandContact,0) // turn off collision
Delete3DPhysicsBody(LeftHandContact) // get rid of physics body
// parent is object 1, child is object 2
rotw# = GetObjectQuatW(LeftHandModel)
rotx# = GetObjectQuatX(LeftHandModel)
roty# = GetObjectQuatY(LeftHandModel)
rotz# = GetObjectQuatZ(LeftHandModel)
posx# = GetObjectX(LeftHandModel)
posy# = GetObjectY(LeftHandModel)
posz# = GetObjectZ(LeftHandModel)
// use object 1 to do the inverse transform
SetObjectPosition( LeftHandModel, 0,0,0 )
SetObjectRotationQuat( LeftHandModel, -rotw#, rotx#, roty#, rotz# )
// use object 2 to do the forward transform
SetObjectPosition( LeftHandContact, GetObjectX(LeftHandContact)-posx#, GetObjectY(LeftHandContact)-posy#, GetObjectZ(LeftHandContact)-posz# )
FixObjectToObject(LeftHandContact,LeftHandModel)
// the world coordinates combine the two transforms
newx# = GetObjectWorldX( LeftHandContact )
newy# = GetObjectWorldY( LeftHandContact )
newz# = GetObjectWorldZ( LeftHandContact )
newrotw# = GetObjectWorldQuatW( LeftHandContact )
newrotx# = GetObjectWorldQuatX( LeftHandContact )
newroty# = GetObjectWorldQuatY( LeftHandContact )
newrotz# = GetObjectWorldQuatZ( LeftHandContact )
// set object 2 to use the new transform
SetObjectPosition( LeftHandContact, newx#, newy#, newz# )
SetObjectRotationQuat( LeftHandContact, newrotw#, newrotx#, newroty#, newrotz# )
endif
endif
if LeftHandContact > 0 and AGKVR.LeftController_Trigger( ) < 0.5
newx# = GetObjectWorldX( LeftHandContact)
newy# = GetObjectWorldY( LeftHandContact)
newz# = GetObjectWorldZ( LeftHandContact)
newx1# = GetObjectWorldAngleX( LeftHandContact)
newy1# = GetObjectWorldAngleY( LeftHandContact)
newz1# = GetObjectWorldAngleZ( LeftHandContact)
newx# = GetObjectWorldX( LeftHandContact )
newy# = GetObjectWorldY( LeftHandContact )
newz# = GetObjectWorldZ( LeftHandContact )
newrotw# = GetObjectWorldQuatW( LeftHandContact )
newrotx# = GetObjectWorldQuatX( LeftHandContact )
newroty# = GetObjectWorldQuatY( LeftHandContact )
newrotz# = GetObjectWorldQuatZ( LeftHandContact )
FixObjectToObject(LeftHandContact, 0)
SetObjectPosition( LeftHandContact, newx#, newy#, newz# )
SetObjectRotationQuat( LeftHandContact, newrotw#, newrotx#, newroty#, newrotz# )
// recreate 3d physics
Create3DPhysicsDynamicBody( LeftHandContact ) // <<<<< Dynamic rotates the object even tho we have specified where it should be ?
//Create3DPhysicsKinematicBody( LeftHandContact ) // uncomment this - rotation works
SetObjectShapeBox( LeftHandContact )
SetObjectCollisionMode(LeftHandContact,1)
LeftHandContact = 0
endif
//The camera's position and rotation will determine what is displayed on the monitor, not the HMD
SetCameraPosition( 1, AGKVR.GetHMDX(), AGKVR.GetHMDY(), AGKVR.GetHMDZ())
SetCameraRotation( 1, AGKVR.GetHMDAngleX(), AGKVR.GetHMDAngleY(), AGKVR.GetHMDAngleZ())
//This command renders to the HMD.
AGKVR.Render( )
Step3DPhysicsWorld()
Sync()
loop
_LoadWorld:
scaleval as float = 0.037
floorBoxID = CreateObjectBox( 200, 10, 200 )
SetObjectColor( floorBoxID, 255, 255, 255, 255 )
SetObjectLightMode( floorBoxID, 1 )
SetObjectPosition( floorBoxID, 0, -5, 0 )
Create3DPhysicsStaticBody( floorBoxID )
SetObjectShapeBox( floorBoxID ) //
return
_CreatePhysicsObjects:
cone = CreateObjectCone(2,2,16)
Create3DPhysicsDynamicBody( cone )
SetObjectPosition(cone,1,1,2)
SetObjectScale(cone,0.4,0.4,0.4)
SetObjectShapeConvexHull( cone)
SetObjectCollisionMode(cone,1)
SetObjectColor( cone, 0, 255, 255, 255 )
RightHandContact as integer = 0
RHandJoint as integer = 0
LeftHandContact as integer = 0
LHandJoint as integer = 0
`Right Hand Object
RHandPhys = CreateObjectSphere( 0.1, 16, 32 )
SetObjectColor( RHandPhys, 0, 150, 150, 220 )
SetObjectPosition(RHandPhys , 0.0,0.0, 0.0 )
SetObjectVisible(RHandPhys,0)
SetObjectCollisionMode(RHandPhys,0)
`Left Hand Object
LHandPhys = CreateObjectSphere( 0.1, 16, 32 )
SetObjectColor( LHandPhys, 0, 150, 150, 220 )
SetObjectPosition(LHandPhys , 0.0,0.0, 0.0 )
SetObjectVisible(LHandPhys,0)
SetObjectCollisionMode(LHandPhys,0)
return