/* ----------------------------------------------------------------------------- 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 Obj3dRudderStr = [ P3DRUDDER_inst : PInstance, P3DRUDDER_device : Obj3dRudder, P3DRUDDER_iMode : I, P3DRUDDER_iCurve : I, P3DRUDDER_iStatus : I, P3DRUDDER_bConnected : I, P3DRUDDER_bControl : I, P3DRUDDER_bOrientation : I, P3DRUDDER_bAngles : I, P3DRUDDER_bWeightDirection : I ]mkObj3dRudderStr;; fun deleteOb(inst, obstr)= setPluginInstanceCbPreRender inst nil; _DS3dRudderDevice obstr.P3DRUDDER_device; 0;; fun sendStatusEvent(inst, status, prevstatus)= let nil -> text in ( if (status == RUDDER3D_NOFOOTSTAYSTILL) then ( SendPluginEvent inst "Status: No foot stay still" nil nil; set text = loc "OS3D3DRUDDER_C0001"; ) else if (status == RUDDER3D_INITIALISATION) then ( SendPluginEvent inst "Status: Initialization" nil nil; set text = loc "OS3D3DRUDDER_C0002"; ) else if ((status == RUDDER3D_PUTYOURFEET && prevstatus != RUDDER3D_PUTSECONDFOOT) || (status == RUDDER3D_PUTSECONDFOOT && prevstatus != RUDDER3D_PUTYOURFEET)) then ( SendPluginEvent inst "Status: Put your feet" nil nil; set text = loc "OS3D3DRUDDER_C0003"; ) else if (status == RUDDER3D_STAYSTILL) then ( SendPluginEvent inst "Status: Stay still" nil nil; set text = loc "OS3D3DRUDDER_C0004"; ) else if ((status == RUDDER3D_INUSE && prevstatus != RUDDER3D_EXTENDEDMODE) || (status == RUDDER3D_EXTENDEDMODE && prevstatus != RUDDER3D_INUSE)) then ( SendPluginEvent inst "Status: In use" nil nil; set text = loc "OS3D3DRUDDER_C0005"; ) else nil; if text == nil then nil else SendPluginEvent inst "Status text" text nil; ); 0;; fun cb3dRudderPreRender(inst, viewstr, obstr)= let _Get3dRudderStatus obstr.P3DRUDDER_device -> status in if (status == obstr.P3DRUDDER_iStatus) then nil else ( sendStatusEvent inst status obstr.P3DRUDDER_iStatus; // necessary so the controlled plugIT will stop when the user remove its feet if (status >= RUDDER3D_INUSE || obstr.P3DRUDDER_iStatus < RUDDER3D_INUSE) then nil else SendPluginEvent obstr.P3DRUDDER_inst "Control" "0 0 0\n0 0 0" obstr.P3DRUDDER_inst.INST_sName; set obstr.P3DRUDDER_iStatus = status; ); if (!obstr.P3DRUDDER_bConnected || obstr.P3DRUDDER_iStatus < RUDDER3D_INUSE ) then nil else ( let _Get3dRudderOrientation obstr.P3DRUDDER_device obstr.P3DRUDDER_iMode obstr.P3DRUDDER_iCurve -> tuple in if (tuple == nil) then nil else let tuple -> [sax say saz rz] in ( if (!obstr.P3DRUDDER_bControl) then nil else SendPluginEvent obstr.P3DRUDDER_inst "Control" (strbuild ((ftoa saz)::(ftoa rz)::(ftoa -.sax)::nil)::("0"::(ftoa (say *. 0.9))::"0"::nil)::nil) obstr.P3DRUDDER_inst.INST_sName; if (!obstr.P3DRUDDER_bOrientation) then nil else SendPluginEvent obstr.P3DRUDDER_inst "Orientation" (strcatn (ftoa sax)::" "::(ftoa say)::" "::(ftoa saz)::" "::(ftoa rz)::nil) obstr.P3DRUDDER_inst.INST_sName; if (!obstr.P3DRUDDER_bAngles) then nil else let _Get3dRudderOrientation obstr.P3DRUDDER_device RUDDER3D_ANGLE nil -> [ax ay az rz] in SendPluginEvent obstr.P3DRUDDER_inst "Angles" (strcatn (ftoa ax)::" "::(ftoa ay)::" "::(ftoa az)::" "::(ftoa rz)::nil) obstr.P3DRUDDER_inst.INST_sName; if (!obstr.P3DRUDDER_bWeightDirection) then nil else let _Get3dRudderWeightDirection obstr.P3DRUDDER_device -> [dx dz] in SendPluginEvent obstr.P3DRUDDER_inst "Weight direction" (strcatn (ftoa dx)::" "::(ftoa dz)::nil) obstr.P3DRUDDER_inst.INST_sName; ); ); 0;; fun cbPlaySound(inst, from, action, param, reply, obstr)= if (param == nil || (strcmp param "") == 0) then _Play3dRudderSound obstr.P3DRUDDER_device "C5(200,100)" else _Play3dRudderSound obstr.P3DRUDDER_device param; 0;; fun cbConnected(rudderobj, obstr)= set obstr.P3DRUDDER_bConnected = 1; setPluginInstanceCbPreRender obstr.P3DRUDDER_inst mkfun3 @cb3dRudderPreRender obstr; SendPluginEvent obstr.P3DRUDDER_inst "Connected" nil nil; 0;; fun cbDisconnected(rudderobj, obstr)= set obstr.P3DRUDDER_bConnected = 0; set obstr.P3DRUDDER_iStatus = 0; setPluginInstanceCbPreRender obstr.P3DRUDDER_inst nil; SendPluginEvent obstr.P3DRUDDER_inst "Disconnected" nil nil; 0;; fun cbEnable(inst, from, action, param, reply, obstr)= if (obstr.P3DRUDDER_device != nil) then nil else ( let _CR3dRudderDevice _channel @cbConnected obstr @cbDisconnected obstr -> rudderobj in set obstr.P3DRUDDER_device = rudderobj; ); if ((_Is3dRudderConnected obstr.P3DRUDDER_device) != 1) then nil else ( set obstr.P3DRUDDER_bConnected = 1; setPluginInstanceCbPreRender obstr.P3DRUDDER_inst mkfun3 @cb3dRudderPreRender obstr; SendPluginEvent obstr.P3DRUDDER_inst "Connected" nil nil; ); 0;; fun cbDisable(inst, from, action, param, reply, obstr)= setPluginInstanceCbPreRender obstr.P3DRUDDER_inst nil; _DS3dRudderDevice obstr.P3DRUDDER_device; 0;; fun cbLoaded(inst, obstr)= cbEnable inst nil nil nil nil obstr; 0;; fun cbFreeze(inst, from, action, param, reply, obstr)= _Set3dRudderFreeze obstr.P3DRUDDER_device 1; 0;; fun cbUnfreeze(inst, from, action, param, reply, obstr)= _Set3dRudderFreeze obstr.P3DRUDDER_device 0; 0;; fun getOrientationMode(i)= let RUDDER3D_NORMALIZED::RUDDER3D_CURVE::RUDDER3D_NORMALIZED_NS_PITCH::RUDDER3D_CURVE_NS_PITCH::nil -> modes in nth_list modes i;; fun newOb(inst)= let atoi(getPluginInstanceParam inst "mode") -> mode in let if mode == nil then 4 else mode -> mode in let atoi(getPluginInstanceParam inst "curve") -> curve in let if curve == nil then 1 else curve -> curve in let atoi(getPluginInstanceParam inst "init") -> init in let if init == nil then 0 else init -> init in let (IsInEditor inst) || IsEventLinked inst "Control" -> bcontrol in let (IsInEditor inst) || IsEventLinked inst "Orientation" -> borientation in let (IsInEditor inst) || IsEventLinked inst "Angles" -> bangles in let (IsInEditor inst) || IsEventLinked inst "Weight direction" -> bweightdirection in let mkObj3dRudderStr[inst nil (getOrientationMode mode) curve 0 0 bcontrol borientation bangles bweightdirection] -> obstr in ( 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; ); ); PluginRegisterAction inst "Play sound" mkfun6 @cbPlaySound obstr; PluginRegisterAction inst "Enable" mkfun6 @cbEnable obstr; PluginRegisterAction inst "Disable" mkfun6 @cbDisable obstr; PluginRegisterAction inst "Freeze" mkfun6 @cbFreeze obstr; PluginRegisterAction inst "Unfreeze" mkfun6 @cbUnfreeze obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= VUIsetEnable c3dXsession 1; PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;