/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct ObjCtlStr = [ POBJCTL_id : I, POBJCTL_sName : S, POBJCTL_obj : SO3_OBJECT, POBJCTL_defObj : SO3_OBJECT, POBJCTL_body : SO3_PHYSICBODY, POBJCTL_objTrigger : SO3_OBJECT, POBJCTL_objTrackPip : SO3_OBJECT, POBJCTL_lBtnState : [I r1], POBJCTL_iMode : I, POBJCTL_initPos : [[F F F] [F F F F]], POBJCTL_bState : I, POBJCTL_bRayState : I, POBJCTL_fRumbleVal : F, POBJCTL_iRumbleTime : I, POBJCTL_iRumbleDuration : I, POBJCTL_pGrabBody : SO3_PHYSICBODY, POBJCTL_pGrabJoint : SO3_PHYSICCONTRAINT, POBJCTL_pGrabbedBody : SO3_PHYSICBODY, POBJCTL_bGrab : I, POBJCTL_oPointerSrc : SO3_OBJECT, POBJCTL_oPointer : SO3_OBJECT, POBJCTL_oRayDummy : SO3_OBJECT, POBJCTL_oRay1 : SO3_OBJECT, POBJCTL_oRay2 : SO3_OBJECT, POBJCTL_oTarget : SO3_OBJECT, POBJCTL_matRay : SO3_MATERIAL, POBJCTL_bRayVisible : I, POBJCTL_fLastWheel : F, POBJCTL_fLastVel : [F F F], POBJCTL_fLastOmega : [F F F], POBJCTL_vOffset : [[F F F] [F F F F]], POBJCTL_vDefOffset : [[F F F] [F F F F]], POBJCTL_bObjChanged : I, POBJCTL_iTeleportState : I, POBJCTL_iLastAutoClick : I ]mkObjCtlStr;; struct ObjOpenvrStr = [ POPENVR_inst : PInstance, POPENVR_sGroupName : S, POPENVR_device : ObjOpenvr, POPENVR_controllers : [ObjCtlStr r1], POPENVR_tLastYPR : [F F F], POPENVR_tLastPos : [F F F], POPENVR_tPrevHeadPos : [[F F F] [F F F F]], POPENVR_bConnected : I, POPENVR_iFrameAcc : I, POPENVR_iNbFrame : I, POPENVR_lostTick : I, POPENVR_wTimer : Timer, POPENVR_bControl : I, POPENVR_bOrientation : I, POPENVR_bPosition : I, POPENVR_bLeftControl : I, POPENVR_bLeftOrientation : I, POPENVR_bLeftPosition : I, POPENVR_bLeftTrigger : I, POPENVR_bLeftTouch : I, POPENVR_bRightControl : I, POPENVR_bRightOrientation : I, POPENVR_bRightPosition : I, POPENVR_bRightTrigger : I, POPENVR_bRightTouch : I, POPENVR_bOnMaterial : I, POPENVR_Material : SO3_MATERIAL, POPENVR_iTechnique : I, POPENVR_iPass : I, POPENVR_iTexture : I, POPENVR_win : SO3_WIDGET, POPENVR_iPosX : I, POPENVR_iPosY : I, POPENVR_iWidth : I, POPENVR_iHeight : I, POPENVR_tPercent : [I I I I I I I I], POPENVR_tAlign : [I I], POPENVR_iOpacity : I, POPENVR_DetectBuffer : ObjBitmap, POPENVR_bBackground : I, POPENVR_lastCamera : SO3_OBJECT, POPENVR_bAdjustMatrix : I, POPENVR_bCameraShow : I, POPENVR_bInitCamera : I, POPENVR_bDetectAR : I, POPENVR_CamParam : ObjArCameraParam, POPENVR_tLastCamSize : [I I], POPENVR_bIgnoreControllerPhysics : I, POPENVR_bCurrentMouseRay : I, POPENVR_bVisible : I, POPENVR_bCtrlState : I, POPENVR_iShowRay : I, POPENVR_iShowRayMode : I, POPENVR_iTeleportMode : I, POPENVR_iTeleportController : I, POPENVR_iTeleportCur : I, POPENVR_bAutoClick : I, POPENVR_fAutoClickDist : F ]mkObjOpenvrStr;; proto stopStereo = fun [ObjOpenvrStr] I;; var BtnMenu = 0;; var BtnGrip = 1;; var BtnA = 2;; var BtnTouch = 3;; var BtnTrigger = 4;; fun restoreTexture(obstr)= if (obstr.POPENVR_win == nil) then nil else ( V3DremoveWidgetControl (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) obstr.POPENVR_win; SO3WidgetDestroy obstr.POPENVR_win; set obstr.POPENVR_win = nil; _DSbitmap obstr.POPENVR_DetectBuffer; set obstr.POPENVR_DetectBuffer = nil; ); 0;; fun computePosSize(obstr, vw, vh)= let obstr.POPENVR_tPercent -> [px py pw ph xo yo wo ho] in let obstr.POPENVR_tAlign -> [ax ay] in let if pw then (ftoi (((itof obstr.POPENVR_iWidth) /. 100.0) *. (itof vw))) + wo else obstr.POPENVR_iWidth -> pw in let if ph then (ftoi (((itof obstr.POPENVR_iHeight) /. 100.0) *. (itof vh))) + ho else obstr.POPENVR_iHeight -> ph in let if px then (ftoi (((itof obstr.POPENVR_iPosX) /. 100.0) *. (itof vw))) + xo else obstr.POPENVR_iPosX -> px in let if (ax == 1) then ((vw / 2) - (pw / 2)) + px else if (ax == 2) then (vw - pw) - px else px -> px in let if py then (ftoi (((itof obstr.POPENVR_iPosY) /. 100.0) *. (itof vh))) + yo else obstr.POPENVR_iPosY -> py in let if (ay == 1) then ((vh / 2) - (ph / 2)) + py else if (ay == 2) then (vh - ph) - py else py -> py in [px py pw ph];; fun scaleProjectionMatrix(m, scale)= let scale -> [sx sy] in let m -> [[m0 m1 m2 m3] [m4 m5 m6 m7] [m8 m9 m10 m11] v4] in [[m0 *. sx m1 *. sx m2 m3] [m4 m5 *. sy m6 *. sx m7] [m8 m9 m10 m11] v4];; fun transProjectionMatrix(m, offset)= let m -> [[m0 m1 m2 m3] [m4 m5 m6 m7] [m8 m9 m10 m11] v4] in let offset -> [ox oy oz] in let if ox == nil then m3 else ox -> ox in let if oy == nil then m7 else oy -> oy in let if oz == nil then m11 else oz -> oz in [[m0 m1 m2 ox] [m4 m5 m6 oy] [m8 m9 m10 oz] v4];; fun logCameraMatrix(m)= let m -> [[m0 m1 m2 m3] [m4 m5 m6 m7] [m8 m9 m10 m11] v4] in addLogMessage strcatn "Cam matrix - focal length: "::(ftoa m0)::" x "::(ftoa m5)::" center: "::(ftoa m2)::" x "::(ftoa m6)::" trans: "::(ftoa m3)::" x "::(ftoa m7)::" x "::(ftoa m11)::nil; m;; fun updateCameraSize(viewstr, obstr)= let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let _GetOpenvrCameraStereoMode obstr.POPENVR_device -> stereomode in let [1.0 1.0] -> bscale in ( if obstr.POPENVR_win == nil then nil else ( //update camera setting on current camera change if (obstr.POPENVR_bCameraShow && obstr.POPENVR_bAdjustMatrix) then ( if (camera == obstr.POPENVR_lastCamera) then nil else ( //reset camera matrix SO3CameraSetProjectionMatrix obstr.POPENVR_lastCamera nil; set obstr.POPENVR_lastCamera = camera; ); ) else nil; if obstr.POPENVR_bOnMaterial then nil else let computePosSize obstr vw vh -> [px py pw ph] in let obstr.POPENVR_tLastCamSize -> [cw ch] in ( if (cw == nil || cw == 0 || ch == nil || ch == 0) then nil else let (itof cw) /. (itof ch) -> camratio in let (itof pw) /. (itof ph) -> bgratio in if (camratio == bgratio) then nil else ( let if (bgratio <. camratio) then [ftoi ((itof ph) *. camratio) ph] else [pw ftoi ((itof pw) /. camratio)] -> [npw nph] in let if (stereomode) then [ftoi ((itof npw) *. 1.5) ftoi ((itof nph) *. 1.5)] else [npw nph] -> [npw nph] in let [(px - ((npw - pw) / 2)) (py - ((nph - ph) / 2))] -> [px py] in ( SO3WidgetSetPosition obstr.POPENVR_win px py; SO3WidgetSetSize obstr.POPENVR_win npw nph; set bscale = [((itof npw) /. (itof pw)) ((itof nph) /. (itof ph))]; ); ); if (stereomode) then nil else ( let scaleProjectionMatrix (_GETarProjectionMatrix obstr.POPENVR_CamParam vw vh) bscale -> cmat in SO3CameraSetProjectionMatrix obstr.POPENVR_lastCamera cmat; ); ); ); ); 0;; fun cbShowCamera(inst, from, action, param, reply, obstr)= SO3WidgetSetVisibility obstr.POPENVR_win 1; set obstr.POPENVR_bCameraShow = 1; if (obstr.POPENVR_bAdjustMatrix) then ( let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ w h] in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let _GetOpenvrCameraStereoMode obstr.POPENVR_device -> stereomode in ( set obstr.POPENVR_lastCamera = camera; SO3CameraSetProjectionMatrix obstr.POPENVR_lastCamera nil; updateCameraSize viewstr obstr; ); ) else nil; 0;; fun cbHideCamera(inst, from, action, param, reply, obstr)= SO3WidgetSetVisibility obstr.POPENVR_win 0; //reset camera matrix if (!obstr.POPENVR_bAdjustMatrix) then nil else SO3CameraSetProjectionMatrix obstr.POPENVR_lastCamera nil; set obstr.POPENVR_bCameraShow = 0; 0;; fun cbShowRay(inst, from, action, param, reply, obstr)= set obstr.POPENVR_iShowRay = 1; 0;; fun cbHideRay(inst, from, action, param, reply, obstr)= if (obstr.POPENVR_iShowRayMode != 2) then set obstr.POPENVR_iShowRay = 0 else set obstr.POPENVR_iShowRay = 2; 0;; fun cbSetTeleportMode(inst, from, action, param, reply, obstr)= if (param == nil) then nil else set obstr.POPENVR_iTeleportMode = atoi param; 0;; fun cbResizeCtrl(inst, viewstr, ww, wh, obstr)= updateCameraSize viewstr obstr; 0;; fun cbSetPosition(inst, from, action, param, reply, obstr)= if param == nil then nil else let strextr param -> lp in let (nth_list (hd lp) 0) -> sx in let (nth_list (hd lp) 1) -> sy in let V3DgetSessionView c3dXsession -> viewstr in ( let 0 -> xpercent in let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then ( set xpercent = 1; atoi sx; ) else atoi sx -> px in let 0 -> ypercent in let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then ( set ypercent = 1; atoi sy; ) else atoi sy -> py in let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in ( mutate obstr.POPENVR_tPercent <- [xpercent ypercent _ _ _ _ _ _]; set obstr.POPENVR_iPosX = px; set obstr.POPENVR_iPosY = py; updateCameraSize viewstr obstr; ); ); 0;; fun cbSetSize(inst, from, action, param, reply, obstr)= if param == nil then nil else let strextr param -> lp in let (nth_list (hd lp) 0) -> sx in let (nth_list (hd lp) 1) -> sy in let V3DgetSessionView c3dXsession -> viewstr in ( let 0 -> wpercent in let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then ( set wpercent = 1; atoi sx; ) else atoi sx -> px in let 0 -> hpercent in let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then ( set hpercent = 1; atoi sy; ) else atoi sy -> py in let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in ( mutate obstr.POPENVR_tPercent <- [_ _ wpercent hpercent _ _ _ _]; set obstr.POPENVR_iWidth = px; set obstr.POPENVR_iHeight = py; updateCameraSize viewstr obstr; ); ); 0;; fun cbStartCamera(inst, from, action, param, rep, obstr)= if (obstr.POPENVR_device == nil) then nil else ( set obstr.POPENVR_bInitCamera = 1; let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let _GetOpenvrIPD obstr.POPENVR_device -> ipd in if (!_OpenOpenvrCamera obstr.POPENVR_device) then nil else ( let _GetOpenvrCameraSize obstr.POPENVR_device -> [ocw och] in let _GetOpenvrCameraStereoMode obstr.POPENVR_device -> stereomode in let if (stereomode == 1) then [(ocw / 2) och] else if (stereomode == 2) then [ocw (och / 2)] else [ocw och] -> [cw ch] in ( set obstr.POPENVR_tLastCamSize = [cw ch]; // change the global variable set c3dxCameraSize = [cw ch]; set c3dxCameraFlip = 0; let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let SO3CameraGetNearClipDistance camera -> nclip in let SO3CameraGetFarClipDistance camera -> fclip in let _GetOpenvrCameraIntrinsics obstr.POPENVR_device 0 -> [[fx fy] [cx cy]] in set obstr.POPENVR_CamParam = _CRarCameraParamIntrinsics _channel cw ch nclip fclip [fx fy] [cx cy]; if (!stereomode) then nil else _SETcameraOffset obstr.POPENVR_CamParam [(ipd *. (-.0.5)) 0.0 0.0]; if obstr.POPENVR_win != nil then nil else ( V3DremoveWidgetControl viewportstr obstr.POPENVR_win; SO3WidgetDestroy obstr.POPENVR_win; if obstr.POPENVR_bOnMaterial then ( set obstr.POPENVR_win = SO3BitmapWidgetCreateOnMaterial (V3DgetSession c3dXsession) obstr.POPENVR_Material (strcat (getPluginInstanceName inst) "_OVRcaptureCtrl") obstr.POPENVR_iWidth obstr.POPENVR_iHeight obstr.POPENVR_iTechnique obstr.POPENVR_iPass obstr.POPENVR_iTexture; 0; ) else if obstr.POPENVR_bBackground then ( let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let computePosSize obstr vw vh -> [px py pw ph] in ( set obstr.POPENVR_win = SO3BitmapWidgetCreateBackground (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_OVRcaptureCtrl") px py pw ph; if (!pw || !ph || (obstr.POPENVR_iWidth != 100) || (obstr.POPENVR_iWidth != 100)) then nil else set obstr.POPENVR_bAdjustMatrix = 1; ); 0; ) else ( let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let computePosSize obstr vw vh -> [px py pw ph] in set obstr.POPENVR_win = SO3BitmapWidgetCreate (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_OVRcaptureCtrl") px py pw ph 100; SO3WidgetSetTopOnFocus obstr.POPENVR_win 0; SO3WidgetSetForeground obstr.POPENVR_win 1; 0; ); updateCameraSize viewstr obstr; V3DaddWidgetControl viewportstr obstr.POPENVR_win; SO3WidgetSetKeyboardEnable obstr.POPENVR_win 0; SO3WidgetSetMouseEnable obstr.POPENVR_win 0; SO3WidgetSetStereo obstr.POPENVR_win if (stereomode == 2) then 3 else stereomode; SO3WidgetSetOpacity obstr.POPENVR_win (itof obstr.POPENVR_iOpacity) *. 0.01; ); SendPluginEvent inst "Camera started" nil nil; ); if (obstr.POPENVR_bCameraShow) then SO3WidgetSetVisibility obstr.POPENVR_win 1 else SO3WidgetSetVisibility obstr.POPENVR_win 0; ); ); 0;; fun cbStopCamera(inst, from, action, param, rep, obstr)= _CloseOpenvrCamera obstr.POPENVR_device; restoreTexture obstr; _DSarCameraParam obstr.POPENVR_CamParam; set obstr.POPENVR_CamParam = nil; //reset camera matrix SO3CameraSetProjectionMatrix obstr.POPENVR_lastCamera nil; set obstr.POPENVR_lastCamera = nil; SendPluginEvent inst "Camera stopped" nil nil; 0;; fun getControllerTrigger(parent)= let SO3ObjectGetChildren parent -> sons in let nil -> found in ( while (sons != nil && found == nil) do ( let hd sons -> obj in let SO3ObjectGetName obj -> name in if ((strfind "trigger" name 0) == nil) then set found = getControllerTrigger obj else set found = obj; set sons = tl sons; ); found; );; fun getControllerTrack(parent)= let SO3ObjectGetChildren parent -> sons in let nil -> found in ( while (sons != nil && found == nil) do ( let hd sons -> obj in let SO3ObjectGetName obj -> name in if ((strfind "track_pip" name 0) == nil) then set found = getControllerTrack obj else set found = obj; set sons = tl sons; ); found; );; fun isCollideBody(body)= if ((SO3BodyGetType body) & 1) then 1 else 0;; fun isAnInvalidBody(obstr, ctrlstr, pos, body)= let SO3BodyGetMassMatrix body -> [mass _] in let SO3PhysicsGetMaterialName (SO3BodyGetMaterial body) -> bmat in if ((!strcmp bmat "nograb") || (!strcmp bmat "ignore") || /*(mass == 0.0) ||*/ ((SO3BodyGetType body) & 4) || (SO3BodyGetIgnoreCollision body) || (body == (SO3SceneNodeGetBody ctrlstr.POBJCTL_obj)) || (isCollideBody body) || (SO3BodyGetFluid body)) && (!(SO3BodyGetType body) & 2) then ( 1; ) else let 0 -> res in ( let 0 -> i in let sizelist obstr.POPENVR_controllers -> size in while (i < size) do ( let nth_list obstr.POPENVR_controllers i -> sctrlstr in if ((sctrlstr.POBJCTL_body == body) || (sctrlstr.POBJCTL_pGrabBody == body)) then set res = 1; set i = i + 1; ); res; );; fun isAnInvalidTeleportBody(obstr, ctrlstr, pos, body)= let if pos == 0 then 1 else 0 -> i in let nth_list obstr.POPENVR_controllers i -> sctrlstr in let SO3PhysicsGetMaterialName (SO3BodyGetMaterial body) -> bmat in if ((!strcmp bmat "nonav") || (!strcmp bmat "ignore") || (SO3BodyGetIgnoreCollision body) || (body == (SO3SceneNodeGetBody ctrlstr.POBJCTL_obj)) || (isCollideBody body) || (SO3BodyGetFluid body) || (sctrlstr.POBJCTL_body == body) || (sctrlstr.POBJCTL_pGrabBody == body) || (sctrlstr.POBJCTL_pGrabbedBody == body)) then 1 else 0;; fun getValidRay(lray, obstr, ctrlstr, pos, cbtest)= let nil -> body in let 0.0 -> dist in let [0.0 1.0 0.0] -> normal in ( while ((lray != nil) && (body == nil)) do ( let hd lray -> [tbody tdist tnormal] in if (exec cbtest with [obstr ctrlstr pos tbody]) then nil else ( set body = tbody; set dist = tdist; set normal = tnormal; ); set lray = tl lray; ); [body dist normal] );; fun resetBodiesSimulation(l)= if l == nil then nil else let hd l -> obj in let SO3SceneNodeGetBody obj -> body in ( SO3BodySetVelocity body [0.0 0.0 0.0]; SO3BodySetOmega body [0.0 0.0 0.0]; //force physic body to obj pos if ((SO3SceneNodeGetBody obj) == nil) then nil else ( SO3ObjectSetPosition obj SO3ObjectGetPosition obj; SO3ObjectSetOrientation obj SO3ObjectGetOrientation obj; ); resetBodiesSimulation SO3GetRootBonesFromMesh obj; resetBodiesSimulation (SO3ObjectGetChildren obj); resetBodiesSimulation (tl l); ); 0;; fun setObjectRenderQueue(l, queue, sons)= if l == nil then nil else let hd l -> obj in ( if (!sons) then nil else setObjectRenderQueue (SO3ObjectGetChildren obj) queue sons; SO3ObjectSetRenderQueue obj queue; setObjectRenderQueue (tl l) queue sons; ); 0;; fun setObjectVisibility(l, state, sons)= if l == nil then nil else let hd l -> obj in ( if (!sons) then nil else setObjectVisibility (SO3ObjectGetChildren obj) state sons; if ((SO3ObjectGetType obj) == SO3_TYPE_LIGHT) then nil else SO3ObjectSetVisible obj state 0; setObjectVisibility (tl l) state sons; ); 0;; fun setObjectControlerFlags(l, flag, state, sons)= if l == nil then nil else let hd l -> obj in ( if (!sons) then nil else setObjectControlerFlags (SO3ObjectGetChildren obj) flag state sons; if (state) then SO3ObjectSetFlags obj (SO3ObjectGetFlags obj) | flag else SO3ObjectSetFlags obj (SO3ObjectGetFlags obj) & ~flag; setObjectControlerFlags (tl l) flag state sons; ); 0;; fun cbOpenvrPreRenderCam(inst, sessionstr, etime, obstr)= _UpdateOpenvr obstr.POPENVR_device; let sessionstr.V3D_sessionView -> viewstr in let V3DgetDefaultViewport (V3DgetSessionView c3dXsession) -> viewportstr in if !(_GetOpenvrVisibility obstr.POPENVR_device) then ( set obstr.POPENVR_tLastPos = nil; set obstr.POPENVR_tLastYPR = nil; set obstr.POPENVR_bVisible = 0; 0; ) else ( //skip first sent pos if (!obstr.POPENVR_bVisible) then ( //first hmd pos can be negative on initialisation ? let _GetOpenvrPosition obstr.POPENVR_device -> [_ hmdheight _] in if (hmdheight <. 0.0) then nil else set obstr.POPENVR_bVisible = 1; ) else ( let _GetOpenvrOrientation obstr.POPENVR_device -> quat in let _GetOpenvrPosition obstr.POPENVR_device -> pos in let V3DgetObjectByName c3dXsession "Current camera" -> camera in let SO3ObjectGetParent SO3ObjectGetParent camera -> dcam in //neckdummy //let SO3ObjectGetGlobalOrientation dcam -> oquat in let SO3ObjectGetPosition dcam -> [_ camheight _] in let pos -> [_ hmdheight _] in let SO3MathsQuatToEulerDegreePYR quat -> [pitch yaw roll] in let quatInverse SO3MathsEulerPYRToQuat (let SO3MathsQuatToEulerPYR quat -> [_ ydir _] in [0.0 ydir 0.0]) -> dirquat in ( if (quat == nil || pos == nil) then nil else ( let if (obstr.POPENVR_tLastPos == nil) then [0.0 0.0 0.0] else SO3MathsQuatGetDirection dirquat (subVectorF pos obstr.POPENVR_tLastPos) -> [px _ pz] in let hmdheight -> py in ( let if (obstr.POPENVR_tLastYPR == nil) then 0.0 else let obstr.POPENVR_tLastYPR -> [ly _ _] in yaw -. ly -> ryaw in let if ryaw >. 180.0 then ryaw -. 360.0 else if ryaw <. (-.180.0) then ryaw +. 360.0 else ryaw -> ryaw in if (!obstr.POPENVR_bControl) then nil else ( let ftoa pitch -> sax in let ftoa ryaw -> say in let ftoa roll -> saz in SendPluginEvent obstr.POPENVR_inst "Control" (strcatn (ftoa px)::" "::(ftoa py)::" "::(ftoa pz)::"\n"::sax::" "::say::" "::saz::"\n3"::nil) obstr.POPENVR_inst.INST_sName; ); ); if (!obstr.POPENVR_bOrientation) then nil else SendPluginEvent obstr.POPENVR_inst "Orientation" (strcatn (ftoa pitch)::" "::(ftoa yaw)::" "::(ftoa roll)::nil) obstr.POPENVR_inst.INST_sName; set obstr.POPENVR_tLastYPR = [yaw pitch roll]; if (!obstr.POPENVR_bPosition) then nil else let pos -> [px py pz] in SendPluginEvent obstr.POPENVR_inst "Position" (strcatn (ftoa px)::" "::(ftoa py)::" "::(ftoa pz)::nil) obstr.POPENVR_inst.INST_sName; set obstr.POPENVR_tLastPos = pos; ); ); 0; ); );; fun cbOpenvrPreRender(inst, viewstr, obstr)= let V3DgetDefaultViewport (V3DgetSessionView c3dXsession) -> viewportstr in if (!obstr.POPENVR_bVisible) then nil else ( let _GetOpenvrOrientation obstr.POPENVR_device -> quat in let _GetOpenvrPosition obstr.POPENVR_device -> pos in let V3DgetObjectByName c3dXsession "Current camera" -> camera in let SO3ObjectGetParent SO3ObjectGetParent camera -> dcam in //neckdummy //let SO3ObjectGetGlobalOrientation dcam -> oquat in let SO3ObjectGetPosition dcam -> [_ camheight _] in let pos -> [_ hmdheight _] in let SO3MathsQuatToEulerDegreePYR quat -> [pitch yaw roll] in let quatInverse SO3MathsEulerPYRToQuat (let SO3MathsQuatToEulerPYR quat -> [_ ydir _] in [0.0 ydir 0.0]) -> dirquat in ( if ((quat == nil || pos == nil) || !obstr.POPENVR_bCtrlState) then nil else ( let SO3ObjectGetGlobalPosition dcam -> [spx spy spz] in let [spx (spy -. camheight) spz] -> spos in let SO3ObjectGetGlobalOrientation dcam -> bodyquat in let SO3MathsQuatToEulerPYR quat -> [_ ryaw _ ] in let SO3MathsEulerPYRToQuat [0.0 ryaw 0.0] -> hquat in let SO3MathsQuatDiff bodyquat hquat -> qdiff in let SO3MathsQuatGetDirection qdiff pos -> [hx hy hz] in let subVectorF spos [hx 0.0 hz] -> feetpos in let subVectorF [spx spy spz] [hx 0.0 hz] -> headpos in let if (obstr.POPENVR_tPrevHeadPos == nil) then [1 2.0] else let obstr.POPENVR_tPrevHeadPos -> [phpos phquat] in let getVectorLengthF (subVectorF headpos phpos) -> lm in let SO3MathsQuatDiff bodyquat phquat -> qrot in if ((lm >. 0.10) || ((getVector4LengthF qrot) >. 1.0)) then [1 lm] else [0 lm] -> [teleporting teleportlenght] in let nil -> cursorpos in ( set obstr.POPENVR_tPrevHeadPos = [headpos bodyquat]; let 0 -> i in //Hack to force left / right update concurrency. if left controller is linked to right one, force update order in that case let 0 -> doagain in let sizelist obstr.POPENVR_controllers -> size in while (i < size) do ( //OPENVR_CONTROLLER_LEFT OPENVR_CONTROLLER_RIGHT let nth_list obstr.POPENVR_controllers i -> ctrlstr in let strcatn obstr.POPENVR_inst.INST_sName::"ctrl_"::(itoa i)::nil -> evtid in ( let _GetOpenvrControllerVisibility obstr.POPENVR_device i -> cstate in let if (cstate == nil) then 0 else cstate -> cstate in ( if (cstate == ctrlstr.POBJCTL_bState) then nil else ( let if (cstate == 1) then strcat ctrlstr.POBJCTL_sName " found" else strcat ctrlstr.POBJCTL_sName " lost" -> ename in ( //addLogMessage ename; SendPluginEvent obstr.POPENVR_inst ename nil nil; ); set ctrlstr.POBJCTL_bState = cstate; ); if (!ctrlstr.POBJCTL_bState) then nil else let ctrlstr.POBJCTL_vOffset -> [offsetpos offsetquat] in let _GetOpenvrControllerPosition obstr.POPENVR_device i -> cpos in let _GetOpenvrControllerOrientation obstr.POPENVR_device i -> cquat in let SO3MathsQuatAdd qdiff cquat -> ctloquat in let addVectorF (SO3MathsQuatGetDirection ctloquat offsetpos) addVectorF addVectorF feetpos (SO3MathsQuatGetDirection qdiff cpos) [0.0 (camheight -. hmdheight) 0.0] -> ctlpos in let SO3MathsQuatAdd ctloquat offsetquat -> ctlquat in // apply offset let nil -> np3d in let nil -> nobflag in let SO3VirtualPointerGetId ctrlstr.POBJCTL_oPointer -> pid in ( let SO3MathsQuatGetDirection qdiff _GetOpenvrControllerVelocity obstr.POPENVR_device i -> vel in let SO3MathsQuatGetDirection qdiff _GetOpenvrControllerAngularVelocity obstr.POPENVR_device i -> omega in ( set ctrlstr.POBJCTL_fLastVel = vel; set ctrlstr.POBJCTL_fLastOmega = omega; ); if (ctrlstr.POBJCTL_obj == nil) then nil else ( //update defbody anyway if (ctrlstr.POBJCTL_obj == ctrlstr.POBJCTL_defObj) then nil else ( if (cpos == nil) then nil else SO3ObjectSetGlobalPosition ctrlstr.POBJCTL_defObj ctlpos; if (cquat == nil) then nil else SO3ObjectSetGlobalOrientation ctrlstr.POBJCTL_defObj ctlquat; ); //TODO get if left controller is linked to right one, force update order in that case and remove doagain thing let SO3SceneNodeGetBody ctrlstr.POBJCTL_obj -> curbody in let SO3BodyGetMassMatrix curbody -> [cmass _] in let (obstr.POPENVR_bIgnoreControllerPhysics && (ctrlstr.POBJCTL_pGrabbedBody == nil) && (ctrlstr.POBJCTL_obj == ctrlstr.POBJCTL_defObj)) -> defobstate in if (ctrlstr.POBJCTL_bObjChanged || !(V3DphysGetState c3dXsession) || (curbody == nil) || (cmass == 0.0) || (teleporting && (ctrlstr.POBJCTL_pGrabbedBody == nil)) || defobstate) then ( if (cpos == nil) then nil else SO3ObjectSetGlobalPosition ctrlstr.POBJCTL_obj ctlpos; if (cquat == nil) then nil else SO3ObjectSetGlobalOrientation ctrlstr.POBJCTL_obj ctlquat; //if (ctrlstr.POBJCTL_pGrabbedBody != nil) then nil else resetBodiesSimulation ctrlstr.POBJCTL_obj::nil; set ctrlstr.POBJCTL_bObjChanged = 0; if (i == 0) then nil else set doagain = doagain + 1; 0; ) else ( //Teleport grabbed obj let SO3BodyGetMassMatrix ctrlstr.POBJCTL_pGrabbedBody -> [gbmass _] in if (doagain || !teleporting || (ctrlstr.POBJCTL_pGrabbedBody == nil) || (gbmass >. (cmass *. 5.0))) then nil else ( SO3BodySetVelocity ctrlstr.POBJCTL_pGrabbedBody [0.0 0.0 0.0]; SO3BodySetOmega ctrlstr.POBJCTL_pGrabbedBody [0.0 0.0 0.0]; let SO3ObjectGetGlobalPosition ctrlstr.POBJCTL_obj -> gcpos in let SO3ObjectGetGlobalPosition (SO3BodyGetSceneNode ctrlstr.POBJCTL_pGrabbedBody) -> gbpos in let addVectorF ctlpos (subVectorF gbpos gcpos) -> nbpos in SO3BodyMoveTo ctrlstr.POBJCTL_pGrabbedBody nbpos 0.6; ); // if the body father have a body we limits the stiffness let SO3SceneNodeGetBody (SO3ObjectGetParent ctrlstr.POBJCTL_obj) -> pbody in let SO3BodyGetMassMatrix pbody -> [pmass _] in let if ((pbody != nil) && (pmass >. 0.0)) then [0.1 0.3] else [0.8 0.8] -> [stiffm stiffr] in ( SO3BodyMoveTo curbody ctlpos stiffm; SO3BodyRotateTo curbody ctlquat stiffr; ); 0; ); if (ctrlstr.POBJCTL_obj != ctrlstr.POBJCTL_defObj) then nil else setObjectVisibility ctrlstr.POBJCTL_obj::nil cstate 1; ); let if (i == 0) then obstr.POPENVR_bLeftOrientation else if (i == 1) then obstr.POPENVR_bRightOrientation else 1 -> oenable in let strcat ctrlstr.POBJCTL_sName " orientation" -> ename in if (!oenable) then nil else let SO3MathsQuatToEulerDegreePYR ctlquat -> [pitch yaw roll] in SendPluginEvent obstr.POPENVR_inst ename (strcatn (ftoa pitch)::" "::(ftoa yaw)::" "::(ftoa roll)::nil) evtid; let if (i == 0) then obstr.POPENVR_bLeftPosition else if (i == 1) then obstr.POPENVR_bRightPosition else 1 -> oenable in let strcat ctrlstr.POBJCTL_sName " position" -> ename in if (!oenable) then nil else let ctlpos -> [cx cy cz] in SendPluginEvent obstr.POPENVR_inst ename (strcatn (ftoa cx)::" "::(ftoa cy)::" "::(ftoa cz)::nil) evtid; let _GetOpenvrControllerAxis obstr.POPENVR_device i -> [padx pady triggerz] in let _GetOpenvrControllerButtons obstr.POPENVR_device i -> lbuttons in ( let nth_list ctrlstr.POBJCTL_lBtnState BtnTouch -> pBtn in let nth_list lbuttons BtnTouch -> nBtn in ( if (pBtn == nBtn) then nil else ( let if (nBtn == 1) then strcat ctrlstr.POBJCTL_sName " touch pad down" else strcat ctrlstr.POBJCTL_sName " touch pad up" -> ename in SendPluginEvent obstr.POPENVR_inst ename (strcatn (ftoa padx)::" "::(ftoa pady)::nil) evtid; //Teleport only for pad mode and current or both controller if ((obstr.POPENVR_iTeleportMode != 1) || ((obstr.POPENVR_iTeleportController > 0) && ((obstr.POPENVR_iTeleportController - 1) != i)) || ((obstr.POPENVR_iTeleportCur != nil) && (obstr.POPENVR_iTeleportCur != i))) then nil else ( set ctrlstr.POBJCTL_iTeleportState = if nBtn then 1 else 3; set obstr.POPENVR_iTeleportCur = i; ); ); if ((obstr.POPENVR_iTeleportMode != 2) || ((obstr.POPENVR_iTeleportController > 0) && ((obstr.POPENVR_iTeleportController - 1) != i)) || ((obstr.POPENVR_iTeleportCur != nil) && (obstr.POPENVR_iTeleportCur != i))) then nil else ( set ctrlstr.POBJCTL_iTeleportState = nBtn; set obstr.POPENVR_iTeleportCur = if nBtn then i else nil; ); let if (i == 0) then obstr.POPENVR_bLeftControl else if (i == 1) then obstr.POPENVR_bRightControl else 1 -> oenable in let nth_list lbuttons BtnTouch -> tBtn in let strcat ctrlstr.POBJCTL_sName " control" -> ename in if (!oenable || !tBtn) then ( if ((pBtn == nBtn) || nBtn) then nil else SendPluginEvent obstr.POPENVR_inst ename (strcatn (ftoa 0.0)::" "::(ftoa 0.0)::" "::(ftoa 0.0)::"\n"::(ftoa 0.0)::" "::(ftoa 0.0)::" "::(ftoa 0.0)::nil) evtid ) else ( if (i == 0) then ( if (absf padx) >. (absf pady) then SendPluginEvent obstr.POPENVR_inst ename (strcatn (ftoa 0.0)::" "::(ftoa 0.0)::" "::(ftoa 0.0)::"\n"::(ftoa 0.0)::" "::(ftoa (-.(padx *. 0.5)))::" "::(ftoa 0.0)::nil) evtid else SendPluginEvent obstr.POPENVR_inst ename (strcatn (ftoa 0.0)::" "::(ftoa 0.0)::" "::(ftoa (-.pady))::"\n"::(ftoa 0.0)::" "::(ftoa 0.0)::" "::(ftoa 0.0)::nil) evtid; ) else ( if (absf padx) >. (absf pady) then SendPluginEvent obstr.POPENVR_inst ename (strcatn (ftoa padx)::" "::(ftoa 0.0)::" "::(ftoa 0.0)::"\n"::(ftoa 0.0)::" "::(ftoa 0.0)::" "::(ftoa 0.0)::nil) evtid else SendPluginEvent obstr.POPENVR_inst ename (strcatn (ftoa 0.0)::" "::(ftoa 0.0)::" "::(ftoa (-.pady))::"\n"::(ftoa 0.0)::" "::(ftoa 0.0)::" "::(ftoa 0.0)::nil) evtid; ); ); //if (obstr.POPENVR_bCurrentMouseRay != i) then nil else ( if ((ctrlstr.POBJCTL_fLastWheel == nil) || (pady == 0.0) )then nil else SO3VirtualPointerSendWheel ctrlstr.POBJCTL_oPointer (ftoi ((pady -. ctrlstr.POBJCTL_fLastWheel) *. 60.0)); ); set ctrlstr.POBJCTL_fLastWheel = if (pady == 0.0) then nil else pady; ); let if (i == 0) then obstr.POPENVR_bLeftTouch else if (i == 1) then obstr.POPENVR_bRightTouch else 1 -> oenable in let strcat ctrlstr.POBJCTL_sName " touch pad" -> ename in if (!oenable) then nil else SendPluginEvent obstr.POPENVR_inst ename (strcatn (ftoa padx)::" "::(ftoa pady)::nil) evtid; let if (i == 0) then obstr.POPENVR_bLeftTrigger else if (i == 1) then obstr.POPENVR_bRightTrigger else 1 -> oenable in let strcat ctrlstr.POBJCTL_sName " trigger value" -> ename in if (!oenable) then nil else SendPluginEvent obstr.POPENVR_inst ename (ftoa triggerz) evtid; //update virtual pointer on widgets if (/*(obstr.POPENVR_bCurrentMouseRay != i) ||*/ (ctrlstr.POBJCTL_obj != ctrlstr.POBJCTL_defObj)) then ( SO3ObjectSetVisible ctrlstr.POBJCTL_oRayDummy 0 1; setObjectRenderQueue ctrlstr.POBJCTL_defObj::nil 66 1; 0; ) else ( SO3VirtualPointerUpdate ctrlstr.POBJCTL_oPointer; let SO3VirtualPointerHasWidgetUnder ctrlstr.POBJCTL_oPointer -> foundwidget in ( SO3ObjectSetVisible ctrlstr.POBJCTL_oRayDummy (cstate && (ctrlstr.POBJCTL_bRayState) && ((obstr.POPENVR_iShowRay == 1) || ctrlstr.POBJCTL_iTeleportState || ((obstr.POPENVR_iShowRay == 2) && foundwidget))) 1; SO3ObjectSetVisible ctrlstr.POBJCTL_oTarget 0 0; //update data for mouse let SO3VirtualPointerGetRayInfos ctrlstr.POBJCTL_oPointer -> [session obj mat subid p3d puv dist] in let dist -. 0.05 -> dist in let SO3ObjectGetFlags obj -> obflag in ( set np3d = p3d; set nobflag = obflag; set cursorpos = SO3ViewportGetPixelPositionFromWorldPos viewportstr.V3D_viewport p3d; let if (foundwidget) then 100 else 66 -> rdpriority in setObjectRenderQueue ctrlstr.POBJCTL_defObj::nil rdpriority 1; //scale laser SO3ObjectSetGlobalScale ctrlstr.POBJCTL_oRayDummy [1.0 1.0 (maxf 0.0 ((SO3VirtualPointerGetlength ctrlstr.POBJCTL_oPointer) -. 0.04))]; let cursorpos -> [cx cy] in let nth_list lbuttons BtnTrigger -> nBtn in ( cbV3DviewPointerUpdate viewstr pid [(SO3ObjectGetGlobalPosition ctrlstr.POBJCTL_oPointer) (SO3ObjectGetGlobalOrientation ctrlstr.POBJCTL_oPointer)] cx cy nBtn [obj mat subid p3d puv dist]; //control virtual pointer on widgets SO3VirtualPointerSendMove ctrlstr.POBJCTL_oPointer nBtn; cbV3DPointerMove viewstr pid [(SO3ObjectGetGlobalPosition ctrlstr.POBJCTL_oPointer) (SO3ObjectGetGlobalOrientation ctrlstr.POBJCTL_oPointer)] cx cy nBtn [obj mat subid p3d puv dist]; let ctrlstr.POBJCTL_iLastAutoClick -> lclick in if (!obstr.POPENVR_bAutoClick || (!(obflag & iNodeFlagClick) && !(obflag & iNodeFlagVUI) && !foundwidget)) then nil else if ((dist >. obstr.POPENVR_fAutoClickDist) || ((lclick != nil) && ((_tickcount - lclick) < 1000))) then ( if ((dist >. (obstr.POPENVR_fAutoClickDist +. 0.02)) && ((lclick != nil) && ((_tickcount - lclick) > 100))) then set ctrlstr.POBJCTL_iLastAutoClick = nil else nil; ) else ( SO3VirtualPointerSendClick ctrlstr.POBJCTL_oPointer 1; cbV3DviewPointerClick viewstr pid [(SO3ObjectGetGlobalPosition ctrlstr.POBJCTL_oPointer) (SO3ObjectGetGlobalOrientation ctrlstr.POBJCTL_oPointer)] cx cy 1 [obj mat subid p3d puv dist]; //vibrate _SetOpenvrControllerRumble obstr.POPENVR_device i 1.0; SO3VirtualPointerSendUnClick ctrlstr.POBJCTL_oPointer 1; cbV3DviewPointerUnClick viewstr pid cx cy 1 [obj mat subid p3d puv dist]; set ctrlstr.POBJCTL_iLastAutoClick = _tickcount; ); ); ); ); 0; ); //buttons if (lbuttons == nil) then nil else let ctrlstr.POBJCTL_lBtnState -> lpbtn in ( let nth_list ctrlstr.POBJCTL_lBtnState BtnMenu -> pBtn in let nth_list lbuttons BtnMenu -> nBtn in if (pBtn == nBtn) then nil else ( let if (nBtn == 1) then strcat ctrlstr.POBJCTL_sName " menu down" else strcat ctrlstr.POBJCTL_sName " menu up" -> ename in SendPluginEvent obstr.POPENVR_inst ename nil nil; ); let nth_list ctrlstr.POBJCTL_lBtnState BtnGrip -> pBtn in let nth_list lbuttons BtnGrip -> nBtn in if (pBtn == nBtn) then nil else ( //control virtual pointer on widgets //if (obstr.POPENVR_bCurrentMouseRay != i) then nil else let SO3VirtualPointerGetRayInfos ctrlstr.POBJCTL_oPointer -> [session obj mat subid p3d puv dist] in let dist -. 0.05 -> dist in ( let cursorpos -> [cx cy] in if (nBtn == 1) then ( SO3VirtualPointerSendClick ctrlstr.POBJCTL_oPointer 2; cbV3DviewPointerClick viewstr pid [(SO3ObjectGetGlobalPosition ctrlstr.POBJCTL_oPointer) (SO3ObjectGetGlobalOrientation ctrlstr.POBJCTL_oPointer)] cx cy 2 [obj mat subid p3d puv dist]; ) else ( SO3VirtualPointerSendUnClick ctrlstr.POBJCTL_oPointer 2; cbV3DviewPointerUnClick viewstr pid cx cy 2 [obj mat subid p3d puv dist]; ); ); let if (nBtn == 1) then strcat ctrlstr.POBJCTL_sName " grip down" else strcat ctrlstr.POBJCTL_sName " grip up" -> ename in SendPluginEvent obstr.POPENVR_inst ename nil nil; ); let nth_list ctrlstr.POBJCTL_lBtnState BtnA -> pBtn in let nth_list lbuttons BtnA -> nBtn in if (pBtn == nBtn) then nil else ( let if (nBtn == 1) then strcat ctrlstr.POBJCTL_sName " A down" else strcat ctrlstr.POBJCTL_sName " A up" -> ename in SendPluginEvent obstr.POPENVR_inst ename nil nil; ); let nth_list ctrlstr.POBJCTL_lBtnState BtnTrigger -> pBtn in let nth_list lbuttons BtnTrigger -> nBtn in if (pBtn == nBtn) then nil else ( //control virtual pointer on widgets //if (obstr.POPENVR_bCurrentMouseRay != i) then nil else ( let cursorpos -> [cx cy] in let SO3VirtualPointerGetRayInfos ctrlstr.POBJCTL_oPointer -> [session obj mat subid p3d puv dist] in let dist -. 0.05 -> dist in if (nBtn == 1) then ( SO3VirtualPointerSendClick ctrlstr.POBJCTL_oPointer 1; if (((obstr.POPENVR_iTeleportMode == 2) && ctrlstr.POBJCTL_iTeleportState) || ((obstr.POPENVR_iTeleportController > 0) && ((obstr.POPENVR_iTeleportController - 1) != i))) then nil else cbV3DviewPointerClick viewstr pid [(SO3ObjectGetGlobalPosition ctrlstr.POBJCTL_oPointer) (SO3ObjectGetGlobalOrientation ctrlstr.POBJCTL_oPointer)] cx cy 1 [obj mat subid p3d puv dist]; if ((obstr.POPENVR_iTeleportMode != 2) || ((obstr.POPENVR_iTeleportController > 0) && ((obstr.POPENVR_iTeleportController - 1) != i)) || ((obstr.POPENVR_iTeleportCur != nil) && (obstr.POPENVR_iTeleportCur != i))) then nil else ( set ctrlstr.POBJCTL_iTeleportState = ctrlstr.POBJCTL_iTeleportState + 2; set obstr.POPENVR_iTeleportCur = i; ); 0; ) else ( SO3VirtualPointerSendUnClick ctrlstr.POBJCTL_oPointer 1; if (((obstr.POPENVR_iTeleportMode == 2) && ctrlstr.POBJCTL_iTeleportState) || ((obstr.POPENVR_iTeleportController > 0) && ((obstr.POPENVR_iTeleportController - 1) != i))) then nil else cbV3DviewPointerUnClick viewstr pid cx cy 1 [obj mat subid p3d puv dist]; 0; ); ); if ((nBtn == 0) || (!ctrlstr.POBJCTL_bRayState) || (ctrlstr.POBJCTL_obj != ctrlstr.POBJCTL_defObj)) then nil else ( /*let 0 -> nc in let sizelist obstr.POPENVR_controllers -> nsize in while (nc < nsize) do ( let nth_list obstr.POPENVR_controllers nc -> sctrlstr2 in SO3VirtualPointerSetEnable sctrlstr2.POBJCTL_oPointer 0; set nc = nc + 1; );*/ set obstr.POPENVR_bCurrentMouseRay = i; SO3VirtualPointerSetEnable ctrlstr.POBJCTL_oPointer 1; ); let if (nBtn == 1) then ( //addLogMessage strcat ctrlstr.POBJCTL_sName " trigger down"; strcat ctrlstr.POBJCTL_sName " trigger down" ) else ( //addLogMessage strcat ctrlstr.POBJCTL_sName " trigger up"; strcat ctrlstr.POBJCTL_sName " trigger up" ) -> ename in SendPluginEvent obstr.POPENVR_inst ename nil nil; ); set ctrlstr.POBJCTL_lBtnState = lbuttons; ); if (ctrlstr.POBJCTL_objTrigger == nil) then nil else SO3ObjectSetOrientation ctrlstr.POBJCTL_objTrigger SO3MathsEulerPYRToQuat [(-.triggerz) *. 0.15 0.0 0.0]; if (ctrlstr.POBJCTL_objTrackPip == nil) then nil else SO3ObjectSetPosition ctrlstr.POBJCTL_objTrackPip [(padx *. 0.019) (pady *. 0.0019) (pady *. (-.0.019))]; ); //teleport if ((obstr.POPENVR_iTeleportMode == 0) || ((obstr.POPENVR_iTeleportController > 0) && ((obstr.POPENVR_iTeleportController - 1) != i))) then nil else ( //force ray on pad controller if (!ctrlstr.POBJCTL_iTeleportState || (!ctrlstr.POBJCTL_bRayState) || /*(obstr.POPENVR_bCurrentMouseRay == i) ||*/ (ctrlstr.POBJCTL_obj != ctrlstr.POBJCTL_defObj)) then nil else ( /*let 0 -> nc in let sizelist obstr.POPENVR_controllers -> nsize in while (nc < nsize) do ( let nth_list obstr.POPENVR_controllers nc -> sctrlstr2 in SO3VirtualPointerSetEnable sctrlstr2.POBJCTL_oPointer 0; set nc = nc + 1; ); */ set obstr.POPENVR_bCurrentMouseRay = i; SO3VirtualPointerSetEnable ctrlstr.POBJCTL_oPointer 1; ); if ((np3d == nil) || (ctrlstr.POBJCTL_iTeleportState == 2) || !ctrlstr.POBJCTL_iTeleportState) then ( SO3ObjectSetVisible ctrlstr.POBJCTL_oTarget 0 0; 0; ) else if ((nobflag & iNodeFlagController) || (nobflag & iNodeFlagVUI) || (nobflag & iNodeFlagTools)) then nil else ( if (V3DphysGetState c3dXsession) then ( if (ctrlstr.POBJCTL_pGrabbedBody != nil) then nil else let (getVectorDistanceF (SO3ObjectGetGlobalPosition ctrlstr.POBJCTL_oPointerSrc) np3d) +. 1.0 -> length in let normalizeVectorF (SO3MathsQuatGetDirection (SO3ObjectGetGlobalOrientation ctrlstr.POBJCTL_oPointerSrc) [0.0 0.0 (-.1.0)]) -> dest in let getValidRay (SO3PhysicsRayCastExt (V3DgetSession c3dXsession) (SO3ObjectGetGlobalPosition ctrlstr.POBJCTL_oPointerSrc) dest length) obstr ctrlstr i @isAnInvalidTeleportBody -> [tbody dist [nx ny nz]] in let addVectorF (SO3ObjectGetGlobalPosition ctrlstr.POBJCTL_oPointerSrc) (multiplyVectorF dest [dist dist dist]) -> [np3dx np3dy np3dz] in let (tbody == nil) || (ny <. 0.82) -> noray in ( SO3ObjectSetGlobalPosition ctrlstr.POBJCTL_oTarget [np3dx np3dy np3dz]; SO3ObjectSetGlobalOrientation ctrlstr.POBJCTL_oTarget (SO3MathsGetRotationToAxis [1.0 0.0 0.0] [nx ny nz]); SO3ObjectSetVisible ctrlstr.POBJCTL_oTarget !noray 0; if (noray || (ctrlstr.POBJCTL_iTeleportState != 3)) then nil else // not a plannar face ( SendPluginEvent obstr.POPENVR_inst "Teleport" strcatnSep (ftoa np3dx)::(ftoa np3dy)::(ftoa np3dz)::nil " " nil; set ctrlstr.POBJCTL_iTeleportState = 0; set obstr.POPENVR_iTeleportCur = nil; ); ); 0; ) else ( SO3ObjectSetGlobalPosition ctrlstr.POBJCTL_oTarget np3d; SO3ObjectSetVisible ctrlstr.POBJCTL_oTarget 1 0; SO3ObjectSetGlobalOrientation ctrlstr.POBJCTL_oTarget SO3MathsQuatAdd SO3ObjectGetGlobalOrientation camera [0.5 0.0 0.0 0.5]; if (ctrlstr.POBJCTL_iTeleportState != 3) then nil else let np3d -> [np3dx np3dy np3dz] in ( SendPluginEvent obstr.POPENVR_inst "Teleport" strcatnSep (ftoa np3dx)::(ftoa np3dy)::(ftoa np3dz)::nil " " nil; set ctrlstr.POBJCTL_iTeleportState = 0; set obstr.POPENVR_iTeleportCur = nil; ); 0; ); ); if (ctrlstr.POBJCTL_iTeleportState != 3) then nil else ( set ctrlstr.POBJCTL_iTeleportState = 0; set obstr.POPENVR_iTeleportCur = nil; ); ); //physic ray cast if (ctrlstr.POBJCTL_obj != ctrlstr.POBJCTL_defObj) then nil else ( if (ctrlstr.POBJCTL_bGrab && (ctrlstr.POBJCTL_pGrabbedBody == nil)) then let normalizeVectorF (SO3MathsQuatGetDirection SO3MathsQuatAdd ctloquat SO3MathsEulerPYRToQuat [SO3MathsDegreeToRadian 0.0 (if (i == 0) then (-.10.0) else 10.0) 0.0] [0.0 0.0 1.0]) -> dest in let addVectorF ctlpos (multiplyVectorF dest [0.01 0.01 0.01]) -> src in let getValidRay (SO3PhysicsRayCastExt (V3DgetSession c3dXsession) src dest 0.20) obstr ctrlstr i @isAnInvalidBody -> [rbody cdist rnormal] in let if rbody != nil then [rbody cdist rnormal] else //try again from hand ( set dest = normalizeVectorF (SO3MathsQuatGetDirection (SO3ObjectGetGlobalOrientation ctrlstr.POBJCTL_oPointerSrc) [0.0 0.0 (-.1.0)]); set src = addVectorF (SO3ObjectGetGlobalPosition ctrlstr.POBJCTL_oPointerSrc) (multiplyVectorF dest [0.01 0.01 0.01]); getValidRay (SO3PhysicsRayCastExt (V3DgetSession c3dXsession) src dest 0.10) obstr ctrlstr i @isAnInvalidBody; ) -> [rbody cdist rnormal] in ( if (rbody == nil) then nil else ( //check if the grabbed object can have a mass after it has been grabbed / otherwise ignore it let SO3BodyGetMassMatrix rbody -> [mass _] in if (mass <=. 0.0) then nil else ( if (ctrlstr.POBJCTL_body != nil) then nil else ( set ctrlstr.POBJCTL_pGrabBody = SO3BodyCreateEllipsoid ctrlstr.POBJCTL_obj [0.05 0.05 0.05]; SO3BodySetType ctrlstr.POBJCTL_pGrabBody 1; V3DphysSetBodyMaterial c3dXsession ctrlstr.POBJCTL_pGrabBody "avatar"; let SO3BodyGetMassMatrix rbody -> [mass _] in SO3BodySetMass ctrlstr.POBJCTL_pGrabBody minf 2.0 (mass *. 10.0); SO3BodySetAutoSleep ctrlstr.POBJCTL_pGrabBody 0; SO3BodySetGravityEnable ctrlstr.POBJCTL_pGrabBody 0; SO3BodySetIgnoreCollision ctrlstr.POBJCTL_pGrabBody 1; ); set ctrlstr.POBJCTL_pGrabJoint = SO3PhysicsContraintCreateSlider (V3DgetSession c3dXsession) (SO3SceneNodeGetBody ctrlstr.POBJCTL_obj) rbody ctlpos [0.0 1.0 0.0] 1 0; SO3PhysicsContraintSetSliderLimits ctrlstr.POBJCTL_pGrabJoint 0.0 0.0; SO3PhysicsContraintSetCollisionState ctrlstr.POBJCTL_pGrabJoint 0; // if the body father have a body we limits the joint stiffness let SO3SceneNodeGetBody (SO3ObjectGetParent SO3BodyGetSceneNode rbody) -> pbody in let SO3BodyGetMassMatrix pbody -> [pmass _] in let if ((pbody != nil) && (pmass >. 0.0)) then 0.8 else 1.0 -> stiff in SO3PhysicsContraintSetStiffness ctrlstr.POBJCTL_pGrabJoint stiff; SO3BodySetType rbody (SO3BodyGetType rbody) | 1 | 2; //set ctrlstr.POBJCTL_bGrab = 0; set ctrlstr.POBJCTL_pGrabbedBody = rbody; ); // grab the object let SO3ObjectGetName (SO3BodyGetSceneNode rbody) -> grabbedname in ( cbPlugGeneric 21 grabbedname nil; let strcat ctrlstr.POBJCTL_sName " grab" -> ename in SendPluginEvent obstr.POPENVR_inst ename grabbedname evtid; ); ); 0; ) else if (!ctrlstr.POBJCTL_bGrab && (ctrlstr.POBJCTL_pGrabbedBody != nil)) then ( SO3PhysicsContraintDestroy ctrlstr.POBJCTL_pGrabJoint; SO3BodyDestroy ctrlstr.POBJCTL_pGrabBody; set ctrlstr.POBJCTL_pGrabJoint = nil; set ctrlstr.POBJCTL_pGrabBody = nil; // ungrab the object let 0 -> nc in let sizelist obstr.POPENVR_controllers -> nsize in while (nc < nsize) do ( let nth_list obstr.POPENVR_controllers nc -> sctrlstr2 in if (sctrlstr2.POBJCTL_pGrabbedBody == ctrlstr.POBJCTL_pGrabbedBody) then nil else ( let SO3ObjectGetName (SO3BodyGetSceneNode ctrlstr.POBJCTL_pGrabbedBody) -> grabbedname in ( SO3BodySetType ctrlstr.POBJCTL_pGrabbedBody ((SO3BodyGetType ctrlstr.POBJCTL_pGrabbedBody) & ~(1)) & ~(2); cbPlugGeneric 22 grabbedname nil; let strcat ctrlstr.POBJCTL_sName " ungrab" -> ename in SendPluginEvent obstr.POPENVR_inst ename grabbedname evtid; ); ); set nc = nc + 1; ); SO3BodySetVelocity ctrlstr.POBJCTL_pGrabbedBody ctrlstr.POBJCTL_fLastVel; SO3BodySetOmega ctrlstr.POBJCTL_pGrabbedBody ctrlstr.POBJCTL_fLastOmega; set ctrlstr.POBJCTL_pGrabbedBody = nil; 0; ) else nil; ); //allow to grab only once if (ctrlstr.POBJCTL_bGrab && (ctrlstr.POBJCTL_pGrabbedBody != nil)) then set ctrlstr.POBJCTL_bGrab = 1 else set ctrlstr.POBJCTL_bGrab = max 0 (ctrlstr.POBJCTL_bGrab - 1); //rumble if (ctrlstr.POBJCTL_iRumbleDuration <= 0) then nil else ( let _tickcount -> crtime in let crtime - ctrlstr.POBJCTL_iRumbleTime -> sptime in let if sptime == 0 then 1 else sptime -> sptime in ( set ctrlstr.POBJCTL_iRumbleDuration = ctrlstr.POBJCTL_iRumbleDuration - sptime; set ctrlstr.POBJCTL_iRumbleTime = crtime; ); _SetOpenvrControllerRumble obstr.POPENVR_device i ctrlstr.POBJCTL_fRumbleVal; ); ); ); ); if (doagain == 1) then ( set doagain = doagain + 1; set i = 0; ) else set i = i + 1; ); ); ); ); //camera if ((!obstr.POPENVR_bInitCamera) || (!obstr.POPENVR_bCameraShow && !obstr.POPENVR_bDetectAR)) then nil else ( let _GetOpenvrCameraFrameBuffer obstr.POPENVR_device -> [buff bw bh bc] in if (buff == nil) then nil else ( let _GetOpenvrCameraStereoMode obstr.POPENVR_device -> stereomode in ( if (!obstr.POPENVR_bCameraShow) then nil else SO3BitmapWidgetBlitBuffer obstr.POPENVR_win buff bw bh bc; if (obstr.POPENVR_bCameraShow && obstr.POPENVR_bAdjustMatrix) then ( //update camera setting on current camera change let V3DgetViewportSize viewstr viewportstr -> [_ _ w h] in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in ( if (camera == obstr.POPENVR_lastCamera) then nil else ( //reset camera matrix SO3CameraSetProjectionMatrix obstr.POPENVR_lastCamera nil; set obstr.POPENVR_lastCamera = camera; updateCameraSize viewstr obstr; ); ); ); if (!obstr.POPENVR_bDetectAR) then nil else ( if ((obstr.POPENVR_DetectBuffer != nil) || (stereomode == 0))then nil else ( let obstr.POPENVR_tLastCamSize -> [cw ch] in set obstr.POPENVR_DetectBuffer = _FILLbitmap _CRbitmap _channel cw ch 0; ); if (stereomode == 0) then ( _UPDATEarMarkersBuff buff bw bh bc obstr.POPENVR_CamParam 0 0; 0; ) else ( let _GETbitmapSize obstr.POPENVR_DetectBuffer -> [dbw dbh] in let _BTGETbitmapBuffer obstr.POPENVR_DetectBuffer -> dbuff in let if (stereomode == 1) then [0 0 bw/2 bh] else [0 bh/2 bw bh/2] -> dstrect in ( _BTCPbitmapBufferRect dbuff dbw dbh 3 [0 0 dbw dbh] buff bw bh bc dstrect; _UPDATEarMarkersBuff dbuff dbw dbh 3 obstr.POPENVR_CamParam 0 0; //_BTSAVEbitmap obstr.POPENVR_DetectBuffer _getmodifypack strcatn "debug_mxar_"::(itoa time)::".jpg"::nil; 0; ); ); ); ); ); ); 0; ); 0;; fun cbOpenvrPostRender(inst, viewstr, obstr)= let SO3BufferGetStereoTextures viewstr.V3D_buffer -> [lptr rptr type] in _UpdateOpenvrTextures obstr.POPENVR_device lptr rptr type; 0;; fun startStereo(obstr)= let V3DgetSessionView c3dXsession -> viewstr in let (V3DgetDefaultViewport viewstr) -> viewportstr in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let SO3CameraGetNearClipDistance camera -> nearclip in let SO3CameraGetFarClipDistance camera -> farclip in let _GetOpenvrProjectionMatrix obstr.POPENVR_device nearclip farclip -> [lmat rmat] in let _GetOpenvrTextureSize obstr.POPENVR_device -> texsize in //let _GetOpenvrAspectRatio obstr.POPENVR_device -> aspect in let _GetOpenvrIPD obstr.POPENVR_device -> ipd in //let _GetOpenvrFovY obstr.POPENVR_device -> fov in let _GetOpenvrDeviceName obstr.POPENVR_device -> name in let c3dXsession -> sessionstr in ( let texsize -> [vw vh] in set tVRTEXTUREVIEW = [0 0 vw vh]; SO3BufferSetStereoMeshTextureSize viewstr.V3D_buffer texsize texsize; SO3BufferSetStereoEyeSpacing viewstr.V3D_buffer ipd; SO3BufferSetStereoProjectionMatrix viewstr.V3D_buffer lmat rmat 1; //SO3BufferSetStereoFOVy viewstr.V3D_buffer fov; SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_OPENVR; set obstr.POPENVR_lostTick = 0; set obstr.POPENVR_iFrameAcc = 0; set obstr.POPENVR_iNbFrame = 0; V3DsetVrMode viewstr 1; //force viewport size update V3DsetViewSizeDirty viewstr; ); 0;; fun stopStereo(obstr)= let V3DgetSessionView c3dXsession -> viewstr in ( SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_NONE; SO3BufferSetStereoMeshTextureSize viewstr.V3D_buffer [1 1] [1 1]; SO3BufferSetStereoProjectionMatrix viewstr.V3D_buffer nil nil 0; SO3BufferSetStereoAspectRatio viewstr.V3D_buffer 0.0; SO3BufferSetStereoFOVy viewstr.V3D_buffer 0.0; V3DsetVrMode viewstr 0; //force viewport size update V3DsetViewSizeDirty viewstr; ); 0;; fun cbChangeCamera(inst, viewstr, sessionstr, camera, obstr)= let SO3CameraGetNearClipDistance camera -> nearclip in let SO3CameraGetFarClipDistance camera -> farclip in let _GetOpenvrProjectionMatrix obstr.POPENVR_device nearclip farclip -> [lmat rmat] in SO3BufferSetStereoProjectionMatrix viewstr.V3D_buffer lmat rmat 1; //_ResetOpenvrDevice obstr.POPENVR_device; set obstr.POPENVR_tLastPos = nil; set obstr.POPENVR_tLastYPR = nil; 0;; fun cbReset(inst, from, action, param, reply, obstr)= _ResetOpenvrDevice obstr.POPENVR_device; set obstr.POPENVR_tLastPos = nil; set obstr.POPENVR_tLastYPR = nil; 0;; fun disableHmd(obstr)= setPluginInstanceCbPreRender obstr.POPENVR_inst nil; setPluginInstanceCbPostRender obstr.POPENVR_inst nil; stopStereo obstr; if (obstr.POPENVR_device == nil) then nil else ( set obstr.POPENVR_bConnected = 0; setPluginInstanceCbPreRender obstr.POPENVR_inst nil; setPluginInstanceCbPostRender obstr.POPENVR_inst nil; setPluginInstanceCbCameraChange obstr.POPENVR_inst nil; set obstr.POPENVR_tLastYPR = nil; stopStereo obstr; let sizelist obstr.POPENVR_controllers -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.POPENVR_controllers i -> ctrlstr in SO3VirtualPointerSetEnable ctrlstr.POBJCTL_oPointer 0; set i = i + 1; ); ); _DSopenvrDevice obstr.POPENVR_device; set obstr.POPENVR_device = nil; set obstr.POPENVR_iTeleportCur = nil; 0;; fun cbQuitRequest(ovrDevice, obstr)= disableHmd obstr; 0;; fun cbIpdChange(ovrDevice, obstr, value)= let V3DgetSessionView c3dXsession -> viewstr in SO3BufferSetStereoEyeSpacing viewstr.V3D_buffer value; 0;; fun cbEnable(inst, from, action, param, reply, obstr)= if (obstr.POPENVR_device != nil) then nil else let _CRopenvrDevice _channel @cbQuitRequest obstr @cbIpdChange obstr -> openvrobj in set obstr.POPENVR_device = openvrobj; if (obstr.POPENVR_device == nil) then ( SendPluginEvent obstr.POPENVR_inst "Device not found" nil nil; ) else ( set obstr.POPENVR_bConnected = 1; startStereo obstr; setPluginInstanceCbScenePreRender obstr.POPENVR_inst mkfun4 @cbOpenvrPreRenderCam obstr; setPluginInstanceCbPreRender obstr.POPENVR_inst mkfun3 @cbOpenvrPreRender obstr; setPluginInstanceCbPostRender obstr.POPENVR_inst mkfun3 @cbOpenvrPostRender obstr; setPluginInstanceCbCameraChange obstr.POPENVR_inst mkfun5 @cbChangeCamera obstr; if (!obstr.POPENVR_bInitCamera) then nil else cbStartCamera inst nil nil nil nil obstr; let sizelist obstr.POPENVR_controllers -> size in let 0 -> haspointer in ( let 0 -> i in while (i < size) do ( let nth_list obstr.POPENVR_controllers i -> ctrlstr in if ((ctrlstr.POBJCTL_oPointer == nil) || (!ctrlstr.POBJCTL_bRayState)) then nil else ( SO3VirtualPointerSetEnable ctrlstr.POBJCTL_oPointer 1; set haspointer = 1; ); set i = i + 1; ); if (!haspointer) then nil else let V3DgetSessionView c3dXsession -> viewstr in V3DsetVrPointerState viewstr 1; ); SendPluginEvent obstr.POPENVR_inst "Device found" nil nil; ); 0;; fun cbDisable(inst, from, action, param, reply, obstr)= disableHmd obstr; let V3DgetSessionView c3dXsession -> viewstr in V3DsetVrPointerState viewstr 0; 0;; fun cbLoaded(inst, obstr)= cbEnable inst nil nil nil nil obstr; 0;; fun cbRumble(inst, from, action, param, reply, obstr, ctrlstr)= let atoi param -> val in let if (val == nil) then 250 else val -> val in ( set ctrlstr.POBJCTL_fRumbleVal = 1.0; set ctrlstr.POBJCTL_iRumbleDuration = val; set ctrlstr.POBJCTL_iRumbleTime = _tickcount; ); 0;; fun cbGrab(inst, from, action, param, reply, obstr, ctrlstr)= set ctrlstr.POBJCTL_bGrab = 5; 0;; fun cbUnGrab(inst, from, action, param, reply, obstr, ctrlstr)= set ctrlstr.POBJCTL_bGrab = 0; 0;; fun cbSetControllerObject(inst, from, action, param, reply, obstr, ctrlstr)= let lineextr param -> lp in let V3DgetObjectByName c3dXsession hd lp -> father in let hd (strextr hd tl lp) -> lpos in let if (lpos == nil) then [0.0 0.0 0.0] else [(atof hd lpos) (atof hd tl lpos) (atof hd tl tl lpos)] -> offsetpos in let hd (strextr hd tl tl lp) -> lang in let if (lang == nil) then [0.0 0.0 0.0 1.0] else SO3MathsEulerYXZToQuat [SO3MathsDegreeToRadian (atof hd lang) SO3MathsDegreeToRadian (atof hd tl lang) SO3MathsDegreeToRadian (atof hd tl tl lang)] -> offsetquat in ( SO3PhysicsContraintDestroy ctrlstr.POBJCTL_pGrabJoint; SO3BodyDestroy ctrlstr.POBJCTL_pGrabBody; set ctrlstr.POBJCTL_pGrabJoint = nil; set ctrlstr.POBJCTL_pGrabBody = nil; if (ctrlstr.POBJCTL_pGrabbedBody == nil) then nil else let SO3ObjectGetName (SO3BodyGetSceneNode ctrlstr.POBJCTL_pGrabbedBody) -> grabbedname in let strcatn obstr.POPENVR_inst.INST_sName::"ctrl_"::ctrlstr.POBJCTL_sName::nil -> evtid in ( cbPlugGeneric 22 grabbedname nil; let strcat ctrlstr.POBJCTL_sName " ungrab" -> ename in SendPluginEvent obstr.POPENVR_inst ename grabbedname evtid; set ctrlstr.POBJCTL_pGrabbedBody = nil; ); // reset default controller obj if (father == nil) then ( if (ctrlstr.POBJCTL_obj == ctrlstr.POBJCTL_defObj) then nil else ( SO3BodySetVelocity ctrlstr.POBJCTL_body ctrlstr.POBJCTL_fLastVel; SO3BodySetOmega ctrlstr.POBJCTL_body ctrlstr.POBJCTL_fLastOmega; SO3BodySetGravityEnable ctrlstr.POBJCTL_body 1; SO3BodySetType ctrlstr.POBJCTL_body ((SO3BodyGetType ctrlstr.POBJCTL_body) & ~(1)) & ~(2); let SO3ObjectGetName (SO3BodyGetSceneNode ctrlstr.POBJCTL_body) -> bodyname in cbPlugGeneric 22 bodyname nil; set father = ctrlstr.POBJCTL_defObj; set ctrlstr.POBJCTL_vOffset = ctrlstr.POBJCTL_vDefOffset; let SO3SceneNodeGetBody father -> body in ( set ctrlstr.POBJCTL_obj = father; set ctrlstr.POBJCTL_body = body; set ctrlstr.POBJCTL_objTrigger = getControllerTrigger ctrlstr.POBJCTL_obj; set ctrlstr.POBJCTL_objTrackPip = getControllerTrack ctrlstr.POBJCTL_obj; setObjectVisibility ctrlstr.POBJCTL_obj::nil 1 1; SO3BodySetIgnoreCollision ctrlstr.POBJCTL_body 0; ); ); //Show or hide the laser /*if (obstr.POPENVR_bCurrentMouseRay == ctrlstr.POBJCTL_id) then (*/ if (!ctrlstr.POBJCTL_bRayState) then nil else ( SO3ObjectSetVisible ctrlstr.POBJCTL_oRayDummy (obstr.POPENVR_iShowRay == 1) 1; SO3VirtualPointerSetEnable ctrlstr.POBJCTL_oPointer 1; ); /*) else ( SO3ObjectSetVisible ctrlstr.POBJCTL_oRayDummy 0 1; SO3VirtualPointerSetEnable ctrlstr.POBJCTL_oPointer 0; );*/ SO3ObjectSetVisible ctrlstr.POBJCTL_oTarget 0 0; ) else ( if (ctrlstr.POBJCTL_obj != ctrlstr.POBJCTL_defObj) then ( SO3BodySetVelocity ctrlstr.POBJCTL_body ctrlstr.POBJCTL_fLastVel; SO3BodySetOmega ctrlstr.POBJCTL_body ctrlstr.POBJCTL_fLastOmega; SO3BodySetGravityEnable ctrlstr.POBJCTL_body 1; SO3BodySetType ctrlstr.POBJCTL_body ((SO3BodyGetType ctrlstr.POBJCTL_body) & ~(1)) & ~(2); let SO3ObjectGetName (SO3BodyGetSceneNode ctrlstr.POBJCTL_body) -> bodyname in cbPlugGeneric 22 bodyname nil; ) else ( setObjectVisibility ctrlstr.POBJCTL_obj::nil 0 1; SO3BodySetIgnoreCollision ctrlstr.POBJCTL_body 1; ); let SO3SceneNodeGetBody father -> body in let V3DgetAvatarMaterial c3dXsession -> mat2 in ( set ctrlstr.POBJCTL_vOffset = [offsetpos offsetquat]; set ctrlstr.POBJCTL_obj = father; set ctrlstr.POBJCTL_body = body; set ctrlstr.POBJCTL_objTrigger = getControllerTrigger ctrlstr.POBJCTL_obj; set ctrlstr.POBJCTL_objTrackPip = getControllerTrack ctrlstr.POBJCTL_obj; if (body == nil) then nil else ( let SO3BodyGetMaterial body -> mat1 in let if (mat1 == (V3DgetDefaultMaterial c3dXsession)) then mat2 else mat1 -> mat1 in SO3PhysicsMaterialSetDefaultCollidable mat1 mat2 0; SO3BodySetGravityEnable body 0; SO3BodySetType body (SO3BodyGetType body) | 1 | 2; ); ); set obstr.POPENVR_bCurrentMouseRay = !ctrlstr.POBJCTL_id; let 0 -> i in while (i < 2) do ( let nth_list obstr.POPENVR_controllers i -> nctrlstr in ( //Show or hide the laser //if (obstr.POPENVR_bCurrentMouseRay == i) then if (!nctrlstr.POBJCTL_bRayState) then nil else SO3VirtualPointerSetEnable nctrlstr.POBJCTL_oPointer 1 /*else SO3VirtualPointerSetEnable nctrlstr.POBJCTL_oPointer 0;*/ ); set i = i + 1; ); ); set ctrlstr.POBJCTL_bObjChanged = 1; ); 0;; fun setSliceFlagOnNode(l, state, sons)= if l == nil then nil else let hd l -> obj in ( if (!sons) then nil else setSliceFlagOnNode (SO3ObjectGetChildren obj) state sons; let SO3EntityMaterialList obj -> lmat in while (lmat != nil) do ( SO3MaterialSetIgnoreSlicePlane hd lmat state; set lmat = tl lmat; ); setSliceFlagOnNode (tl l) state sons; ); 0;; fun cbSetControllerRayState(inst, from, action, param, reply, p)= let p -> [obstr ctrlstr state] in ( set ctrlstr.POBJCTL_bRayState = state; if (state) then ( SO3ObjectSetVisible ctrlstr.POBJCTL_oRayDummy (obstr.POPENVR_iShowRay == 1) 1; SO3ObjectSetVisible ctrlstr.POBJCTL_oTarget 0 0; SO3VirtualPointerSetEnable ctrlstr.POBJCTL_oPointer 1; ) else ( SO3ObjectSetVisible ctrlstr.POBJCTL_oRayDummy 0 1; SO3ObjectSetVisible ctrlstr.POBJCTL_oTarget 0 0; SO3VirtualPointerSetEnable ctrlstr.POBJCTL_oPointer 0; ); ); 0;; fun loadController(inst, obstr, ctrlname, objname, offset, offsetquat, raysrc, raystate)= let sizelist obstr.POPENVR_controllers -> id in let V3DgetObjectByName c3dXsession objname -> father in let if ((objname == nil) || (!strcmp objname "")) then strcatn "vrctl."::(itoa (sizelist obstr.POPENVR_controllers))::"."::nil else objname -> objname in let V3DgetObjectByName c3dXsession raysrc -> raysrcobj in let if (raysrcobj == nil) then father else raysrcobj -> raysrcobj in let SO3SceneNodeGetBody father -> body in let V3DgetObjectTypeByName objname -> iobjmode in let SO3ObjectGetPosition father -> clpos in let SO3ObjectGetOrientation father -> clquat in let if (father == nil) then nil else SO3VirtualPointerCreate (V3DgetSession c3dXsession) strcat objname "pointer" -> lvpointer in let if (father == nil) then nil else SO3MaterialCreate (V3DgetSession c3dXsession) (strcat objname "ray.material") obstr.POPENVR_sGroupName -> lmatray in let if (father == nil) then nil else SO3SceneNodeCreate (V3DgetSession c3dXsession) (strcat objname ".shell") -> lray in let if (father == nil) then nil else SO3PlaneCreate (V3DgetSession c3dXsession) obstr.POPENVR_sGroupName (strcat objname ".ray1") [0.005 1.0] nil nil -> lobray1 in let if (father == nil) then nil else SO3PlaneCreate (V3DgetSession c3dXsession) obstr.POPENVR_sGroupName (strcat objname ".ray2") [0.005 1.0] nil nil -> lobray2 in let mkObjCtlStr[id ctrlname father father body nil nil 0::0::0::0::0::nil iobjmode [clpos clquat] 0 raystate 0.0 0 0 nil nil nil 0 raysrcobj lvpointer lray lobray1 lobray2 nil lmatray 1 nil [0.0 0.0 0.0] [0.0 0.0 0.0] [offset offsetquat] [offset offsetquat] 1 0 nil] -> sctrlstr in let V3DgetAvatarMaterial c3dXsession -> mat2 in let strcatn (getPluginDirectory (getInstancePlugin inst))::"/res/"::"raybase.mesh"::nil -> meshpath in let strcatn (getPluginDirectory (getInstancePlugin inst))::"/res/"::"raybase.material"::nil -> matpath in ( if (sctrlstr.POBJCTL_oPointer == nil) then nil else ( V3DaddResource c3dXsession matpath obstr.POPENVR_sGroupName SO3_RESOURCE_MATERIAL; V3DaddResource c3dXsession meshpath obstr.POPENVR_sGroupName SO3_RESOURCE_MESH; SO3VirtualPointerSetMaxLength sctrlstr.POBJCTL_oPointer 10.0; SO3VirtualPointerSetEnable sctrlstr.POBJCTL_oPointer raystate; ); set sctrlstr.POBJCTL_objTrigger = getControllerTrigger sctrlstr.POBJCTL_obj; set sctrlstr.POBJCTL_objTrackPip = getControllerTrack sctrlstr.POBJCTL_obj; setObjectControlerFlags sctrlstr.POBJCTL_defObj::nil iNodeFlagController 1 1; if (body == nil) then nil else ( let SO3BodyGetMaterial body -> mat1 in let if (mat1 == (V3DgetDefaultMaterial c3dXsession)) then mat2 else mat1 -> mat1 in SO3PhysicsMaterialSetDefaultCollidable mat1 mat2 0; SO3BodySetGravityEnable body 0; SO3BodySetType body (SO3BodyGetType body) | 1 | 2; ); //Ignore slice on all controller materials setSliceFlagOnNode father::nil 1 1; //link virtual pointer to objects if (sctrlstr.POBJCTL_oPointer == nil) then ( if (father == nil) then nil else addLogMessage strcat "Virtual pointer creation failed on controller " ctrlname; 0; ) else ( set sctrlstr.POBJCTL_oTarget = SO3SceneLoadEntity (V3DgetSession c3dXsession) obstr.POPENVR_sGroupName (strcat objname ".raybase") (_checkpack meshpath); SO3ObjectSetMouseClick sctrlstr.POBJCTL_oPointerSrc 0; SO3ObjectSetMouseClick sctrlstr.POBJCTL_obj 0; SO3ObjectSetVisible sctrlstr.POBJCTL_oTarget 0 0; SO3ObjectSetRenderQueue sctrlstr.POBJCTL_oTarget 65; SO3ObjectSetCastShadows sctrlstr.POBJCTL_oTarget 0; SO3ObjectLink sctrlstr.POBJCTL_oPointer sctrlstr.POBJCTL_oPointerSrc; SO3ObjectSetPosition sctrlstr.POBJCTL_oPointer if (sctrlstr.POBJCTL_oPointerSrc != father) then [0.0 0.0 0.05] else SO3MathsQuatGetDirection offsetquat [0.0 0.0 0.05]; if (sctrlstr.POBJCTL_oPointerSrc != father) then nil else SO3ObjectSetOrientation sctrlstr.POBJCTL_oPointer offsetquat; SO3MaterialSetReceiveShadows lmatray 0; SO3MaterialSetAmbient lmatray make_rgba 255 0 0 96; SO3MaterialSetDiffuse lmatray make_rgba 255 0 0 96; SO3MaterialSetSelfIllumination lmatray make_rgba 255 0 0 96; SO3MaterialSetIgnoreSlicePlane lmatray 1; SO3MaterialSetPassCullingEnable lmatray 0 0 0; SO3MaterialSetPassDepthFunction lmatray 0 0 SO3_COMPARE_FUNCTION_ALWAYS_PASS; SO3EntitySetMaterial lobray1 lmatray 0; SO3EntitySetMaterial lobray2 lmatray 0; SO3ObjectSetCastShadows lobray1 0; SO3ObjectSetCastShadows lobray2 0; SO3ObjectSetMouseClick lobray1 0; SO3ObjectSetMouseClick lobray2 0; SO3ObjectLink lobray1 lray; SO3ObjectLink lobray2 lray; SO3ObjectLink lray sctrlstr.POBJCTL_oPointerSrc; if (sctrlstr.POBJCTL_oPointerSrc != father) then nil else SO3ObjectSetOrientation lray offsetquat; SO3ObjectSetOrientation lobray1 [1.0 0.0 0.0 0.0]; //90° on X SO3ObjectSetOrientation lobray2 SO3MathsQuatAdd [1.0 0.0 0.0 0.0] [0.0 0.0 0.5 0.5]; //90° on X and Z SO3ObjectSetPosition lobray1 [0.0 0.0 (-.0.5)]; SO3ObjectSetPosition lobray2 [0.0 0.0 (-.0.5)]; setObjectVisibility father::nil 0 1; setObjectRenderQueue sctrlstr.POBJCTL_defObj::nil 66 1; 0; ); let strextr sctrlstr.POBJCTL_sName -> ln in let strlowercase hd hd ln -> fw in let strcatnSep fw::(tl hd ln) " " -> cname in ( PluginRegisterAction inst strcat sctrlstr.POBJCTL_sName " rumble" mkfun6 mkfun7 @cbRumble sctrlstr obstr; PluginRegisterAction inst strcatn "Set "::cname:: " object"::nil mkfun6 mkfun7 @cbSetControllerObject sctrlstr obstr; PluginRegisterAction inst strcat "Grab " cname mkfun6 mkfun7 @cbGrab sctrlstr obstr; PluginRegisterAction inst strcat "UnGrab " cname mkfun6 mkfun7 @cbUnGrab sctrlstr obstr; ); set obstr.POPENVR_controllers = lcat obstr.POPENVR_controllers sctrlstr::nil; sctrlstr; );; fun loadControllers(inst, obstr)= set obstr.POPENVR_controllers = nil; let getPluginInstanceParam inst "leftController" -> objlname in let atof (getPluginInstanceParam inst "loffposx") -> loffposx in let if loffposx == nil then 0.0 else loffposx -> loffposx in let atof (getPluginInstanceParam inst "loffposy") -> loffposy in let if loffposy == nil then 0.0 else loffposy -> loffposy in let atof (getPluginInstanceParam inst "loffposz") -> loffposz in let if loffposz == nil then 0.0 else loffposz -> loffposz in let atof (getPluginInstanceParam inst "loffangx") -> loffangx in let if loffangx == nil then 0.0 else loffangx -> loffangx in let atof (getPluginInstanceParam inst "loffangy") -> loffangy in let if loffangy == nil then 0.0 else loffangy -> loffangy in let atof (getPluginInstanceParam inst "loffangz") -> loffangz in let if loffangz == nil then 0.0 else loffangz -> loffangz in let getPluginInstanceParam inst "rightController" -> objrname in let atof (getPluginInstanceParam inst "roffposx") -> roffposx in let if roffposx == nil then 0.0 else roffposx -> roffposx in let atof (getPluginInstanceParam inst "roffposy") -> roffposy in let if roffposy == nil then 0.0 else roffposy -> roffposy in let atof (getPluginInstanceParam inst "roffposz") -> roffposz in let if roffposz == nil then 0.0 else roffposz -> roffposz in let atof (getPluginInstanceParam inst "roffangx") -> roffangx in let if roffangx == nil then 0.0 else roffangx -> roffangx in let atof (getPluginInstanceParam inst "roffangy") -> roffangy in let if roffangy == nil then 0.0 else roffangy -> roffangy in let atof (getPluginInstanceParam inst "roffangz") -> roffangz in let if roffangz == nil then 0.0 else roffangz -> roffangz in let atoi (getPluginInstanceParam inst "lraystate") -> lraystate in let if (lraystate == nil) then 1 else lraystate -> lraystate in let atoi (getPluginInstanceParam inst "rraystate") -> rraystate in let if (rraystate == nil) then 1 else rraystate -> rraystate in let getPluginInstanceParam inst "raysrcl" -> raysrcl in let getPluginInstanceParam inst "raysrcr" -> raysrcr in ( let SO3MathsEulerYXZToQuat [(SO3MathsDegreeToRadian loffangx) (SO3MathsDegreeToRadian loffangy) (SO3MathsDegreeToRadian loffangz)] -> lquat in let loadController inst obstr "Left controller" objlname [loffposx loffposy loffposz] lquat raysrcl lraystate -> ctrlstr in ( PluginRegisterAction inst "Left controller enable ray" mkfun6 @cbSetControllerRayState [obstr ctrlstr 1]; PluginRegisterAction inst "Left controller disable ray" mkfun6 @cbSetControllerRayState [obstr ctrlstr 0]; ); let SO3MathsEulerYXZToQuat [(SO3MathsDegreeToRadian roffangx) (SO3MathsDegreeToRadian roffangy) (SO3MathsDegreeToRadian roffangz)] -> rquat in let loadController inst obstr "Right controller" objrname [roffposx roffposy roffposz] rquat raysrcr rraystate -> ctrlstr in ( PluginRegisterAction inst "Right controller enable ray" mkfun6 @cbSetControllerRayState [obstr ctrlstr 1]; PluginRegisterAction inst "Right controller disable ray" mkfun6 @cbSetControllerRayState [obstr ctrlstr 0]; ); let nil -> l in let nil -> trackername in let 0 -> i in ( while ((set trackername = getPluginInstanceParam inst (strcat "trackerName_" (itoa i))) != nil) do ( let getPluginInstanceParam inst (strcat "trackerObj_" (itoa i)) -> trackerobj in let atoi (getPluginInstanceParam inst (strcat "trackerRayState_" (itoa i))) -> raystate in let atof (getPluginInstanceParam inst (strcat "trackerOffsetpx_" (itoa i))) -> offposx in let atof (getPluginInstanceParam inst (strcat "trackerOffsetpy_" (itoa i))) -> offposy in let atof (getPluginInstanceParam inst (strcat "trackerOffsetpz_" (itoa i))) -> offposz in let atof (getPluginInstanceParam inst (strcat "trackerOffsetax_" (itoa i))) -> offangx in let atof (getPluginInstanceParam inst (strcat "trackerOffsetay_" (itoa i))) -> offangy in let atof (getPluginInstanceParam inst (strcat "trackerOffsetaz_" (itoa i))) -> offangz in let SO3MathsEulerYXZToQuat [(SO3MathsDegreeToRadian offangx) (SO3MathsDegreeToRadian offangy) (SO3MathsDegreeToRadian offangz)] -> rquat in let loadController inst obstr trackername trackerobj [offposx offposy offposz] rquat nil raystate -> ctrlstr in ( PluginRegisterAction inst (strcat trackername " enable ray") mkfun6 @cbSetControllerRayState [obstr ctrlstr 1]; PluginRegisterAction inst (strcat trackername " disable ray") mkfun6 @cbSetControllerRayState [obstr ctrlstr 0]; ); set i = i + 1; ); ); ); 0;; fun deleteOb(inst, obstr)= setPluginInstanceCbPreRender inst nil; setPluginInstanceCbPostRender inst nil; cbStopCamera inst nil nil nil nil obstr; _DSopenvrDevice obstr.POPENVR_device; stopStereo obstr; while (obstr.POPENVR_controllers != nil) do ( let hd obstr.POPENVR_controllers -> ctrlstr in let ctrlstr.POBJCTL_initPos -> [pos quat] in ( SO3ObjectSetPosition ctrlstr.POBJCTL_obj pos; SO3ObjectSetOrientation ctrlstr.POBJCTL_obj quat; SO3ObjectSetVisible ctrlstr.POBJCTL_obj 1 1; SO3PhysicsContraintDestroy ctrlstr.POBJCTL_pGrabJoint; SO3BodyDestroy ctrlstr.POBJCTL_pGrabBody; SO3BodySetGravityEnable ctrlstr.POBJCTL_body 1; SO3BodySetIgnoreCollision ctrlstr.POBJCTL_body 0; SO3BodySetType ctrlstr.POBJCTL_body ((SO3BodyGetType ctrlstr.POBJCTL_body) & ~(1)) & ~(2); SO3ObjectDestroy ctrlstr.POBJCTL_oPointer; SO3ObjectDestroy ctrlstr.POBJCTL_oRay1; SO3ObjectDestroy ctrlstr.POBJCTL_oRay2; SO3ObjectDestroy ctrlstr.POBJCTL_oRayDummy; SO3ObjectDestroy ctrlstr.POBJCTL_oTarget; SO3MaterialDestroy ctrlstr.POBJCTL_matRay; SO3ObjectSetMouseClick ctrlstr.POBJCTL_oPointerSrc 1; SO3ObjectSetMouseClick ctrlstr.POBJCTL_obj 1; setObjectControlerFlags ctrlstr.POBJCTL_defObj::nil iNodeFlagController 0 1; ); set obstr.POPENVR_controllers = tl obstr.POPENVR_controllers; ); SO3GroupDelete (V3DgetSession c3dXsession) obstr.POPENVR_sGroupName; let V3DgetSessionView c3dXsession -> viewstr in V3DsetVrPointerState viewstr 0; 0;; fun cbEnableControllers(inst, from, action, param, reply, obstr)= if (!obstr.POPENVR_bConnected) then nil else ( set obstr.POPENVR_bCtrlState = 1; let 0 -> i in let sizelist obstr.POPENVR_controllers -> size in while (i < size) do ( let nth_list obstr.POPENVR_controllers i -> ctrlstr in ( if (ctrlstr.POBJCTL_obj != ctrlstr.POBJCTL_defObj) then nil else setObjectVisibility ctrlstr.POBJCTL_obj::nil 1 1; //Show or hide the laser //if (obstr.POPENVR_bCurrentMouseRay == i) then ( if (!ctrlstr.POBJCTL_bRayState) then nil else ( SO3ObjectSetVisible ctrlstr.POBJCTL_oRayDummy (obstr.POPENVR_iShowRay == 1) 1; SO3ObjectSetVisible ctrlstr.POBJCTL_oTarget 0 0; SO3VirtualPointerSetEnable ctrlstr.POBJCTL_oPointer 1; ); ) /*else ( SO3ObjectSetVisible ctrlstr.POBJCTL_oRayDummy 0 1; SO3VirtualPointerSetEnable ctrlstr.POBJCTL_oPointer 0; );*/ ); set i = i + 1; ); ); 0;; fun cbDisableControllers(inst, from, action, param, reply, obstr)= if (!obstr.POPENVR_bConnected) then nil else ( set obstr.POPENVR_bCtrlState = 0; set obstr.POPENVR_iTeleportCur = nil; let 0 -> i in let sizelist obstr.POPENVR_controllers -> size in while (i < size) do ( let nth_list obstr.POPENVR_controllers i -> ctrlstr in ( if (ctrlstr.POBJCTL_obj != ctrlstr.POBJCTL_defObj) then nil else setObjectVisibility ctrlstr.POBJCTL_obj::nil 0 1; SO3ObjectSetVisible ctrlstr.POBJCTL_oRayDummy 0 1; ); set i = i + 1; ); ); 0;; fun newOb(inst)= let atoi(getPluginInstanceParam inst "init") -> init in let (getPluginInstanceParam inst "object") -> objname in let (getPluginInstanceParam inst "material") -> matname in let atoi (getPluginInstanceParam inst "technique") -> technique in let if technique == nil then 0 else technique -> technique in let atoi (getPluginInstanceParam inst "pass") -> pass in let if pass == nil then 0 else pass -> pass in let atoi (getPluginInstanceParam inst "texture") -> texture in let if texture == nil then 0 else texture -> texture in let atoi (getPluginInstanceParam inst "istexture") -> istexture in let if istexture == nil then 0 else istexture -> istexture in let atoi (getPluginInstanceParam inst "xpercent") -> xpercent in let if xpercent == nil then 0 else xpercent -> xpercent in let atoi (getPluginInstanceParam inst "xalign") -> xalign in let if xalign == nil then 0 else xalign -> xalign in let atoi (getPluginInstanceParam inst "posx") -> posx in let if posx == nil then 0 else posx -> posx in let atoi (getPluginInstanceParam inst "ypercent") -> ypercent in let if ypercent == nil then 0 else ypercent -> ypercent in let atoi (getPluginInstanceParam inst "yalign") -> yalign in let if yalign == nil then 0 else yalign -> yalign in let atoi (getPluginInstanceParam inst "posy") -> posy in let if posy == nil then 0 else posy -> posy in let atoi (getPluginInstanceParam inst "wpercent") -> wpercent in let if wpercent == nil then 1 else wpercent -> wpercent in let atoi (getPluginInstanceParam inst "width") -> width in let if width == nil then 100 else width -> width in let atoi (getPluginInstanceParam inst "hpercent") -> hpercent in let if hpercent == nil then 1 else hpercent -> hpercent in let atoi (getPluginInstanceParam inst "height") -> height in let if height == nil then 100 else height -> height in let atoi (getPluginInstanceParam inst "xoffset") -> xoffset in let if xoffset == nil then 0 else xoffset -> xoffset in let atoi (getPluginInstanceParam inst "yoffset") -> yoffset in let if yoffset == nil then 0 else yoffset -> yoffset in let atoi (getPluginInstanceParam inst "woffset") -> woffset in let if woffset == nil then 0 else woffset -> woffset in let atoi (getPluginInstanceParam inst "hoffset") -> hoffset in let if hoffset == nil then 0 else hoffset -> hoffset in let atoi (getPluginInstanceParam inst "background") -> background in let if (background == nil) then 1 else background -> background in let atoi (getPluginInstanceParam inst "opacity") -> opacity in let if opacity == nil then 100 else opacity -> opacity in let atoi (getPluginInstanceParam inst "showcamera") -> showcamera in let if (showcamera == nil) then 0 else showcamera -> showcamera in let atoi (getPluginInstanceParam inst "initcamera") -> initcamera in let if (initcamera == nil) then 0 else initcamera -> initcamera in let atoi (getPluginInstanceParam inst "detectar") -> detectar in let if (detectar == nil) then 0 else detectar -> detectar in let atoi (getPluginInstanceParam inst "ignorecontrphys") -> ignorecontrphys in let if (ignorecontrphys == nil) then 1 else ignorecontrphys -> ignorecontrphys in let atoi (getPluginInstanceParam inst "showray") -> showray in let if (showray == nil) then 1 else showray -> showray in let atoi (getPluginInstanceParam inst "teleportmode") -> teleportmode in let if (teleportmode == nil) then 2 else teleportmode -> teleportmode in let atoi (getPluginInstanceParam inst "teleportcontroller") -> teleportcontroller in let if (teleportcontroller == nil) then 0 else teleportcontroller -> teleportcontroller in let atoi (getPluginInstanceParam inst "autoclick") -> autoclick in let if (autoclick == nil) then 0 else autoclick -> autoclick in let atof (getPluginInstanceParam inst "autoclickdist") -> autoclickdist in let if (autoclickdist == nil) then 0.05 else autoclickdist -> autoclickdist in let (IsInEditor inst) || IsEventLinked inst "Control" -> bcontrol in let (IsInEditor inst) || IsEventLinked inst "Orientation" -> borientation in let (IsInEditor inst) || IsEventLinked inst "Position" -> bposition in let (IsInEditor inst) || IsEventLinked inst "Left controller control" -> blccontrol in let (IsInEditor inst) || IsEventLinked inst "Left controller orientation" -> blcorientation in let (IsInEditor inst) || IsEventLinked inst "Left controller position" -> blcposition in let (IsInEditor inst) || IsEventLinked inst "Left controller trigger value" -> blctriggervalue in let (IsInEditor inst) || IsEventLinked inst "Left controller touch pad" -> blctouchvalue in let (IsInEditor inst) || IsEventLinked inst "Right controller control" -> brccontrol in let (IsInEditor inst) || IsEventLinked inst "Right controller orientation" -> brcorientation in let (IsInEditor inst) || IsEventLinked inst "Right controller position" -> brcposition in let (IsInEditor inst) || IsEventLinked inst "Right controller trigger value" -> brctriggervalue in let (IsInEditor inst) || IsEventLinked inst "Right controller touch pad" -> brctouchvalue in let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let if !istexture then nil else SO3SceneGetMaterial (V3DgetSession c3dXsession) (SO3EntityGetResourceGroup obj) matname -> mat in let mkObjOpenvrStr [inst (strcat (getPluginInstanceName inst) "_Group") nil nil nil nil nil 0 0 0 0 nil bcontrol borientation bposition blccontrol blcorientation blcposition blctriggervalue blctouchvalue brccontrol brcorientation brcposition brctriggervalue brctouchvalue istexture mat technique pass texture nil posx posy width height [xpercent ypercent wpercent hpercent xoffset yoffset woffset hoffset] [xalign yalign] opacity nil background nil 0 showcamera initcamera detectar nil nil ignorecontrphys 0 0 1 showray showray teleportmode teleportcontroller nil autoclick autoclickdist] -> obstr in ( SO3GroupCreate (V3DgetSession c3dXsession) obstr.POPENVR_sGroupName; loadControllers inst obstr; if (!init) then nil else ( if inst.INST_groupstr.GRP_project.PRJ_bPluginsLoaded then ( cbEnable inst nil nil nil nil obstr; 0; ) else ( setPluginInstanceCbAllPluginsLoaded inst mkfun2 @cbLoaded obstr; 0; ); ); if obstr.POPENVR_bOnMaterial then nil else setPluginInstanceCbResizeView inst mkfun5 @cbResizeCtrl obstr; PluginRegisterAction inst "Reset" mkfun6 @cbReset obstr; PluginRegisterAction inst "Enable" mkfun6 @cbEnable obstr; PluginRegisterAction inst "Disable" mkfun6 @cbDisable obstr; PluginRegisterAction inst "Start camera" mkfun6 @cbStartCamera obstr; PluginRegisterAction inst "Stop camera" mkfun6 @cbStopCamera obstr; PluginRegisterAction inst "Show camera" mkfun6 @cbHideCamera obstr; PluginRegisterAction inst "Hide camera" mkfun6 @cbShowCamera obstr; PluginRegisterAction inst "Show ray" mkfun6 @cbShowRay obstr; PluginRegisterAction inst "Hide ray" mkfun6 @cbHideRay obstr; PluginRegisterAction inst "Set teleport mode" mkfun6 @cbSetTeleportMode obstr; PluginRegisterAction inst "Enable controllers" mkfun6 @cbEnableControllers obstr; PluginRegisterAction inst "Disable controllers" mkfun6 @cbDisableControllers obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;