/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2015 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 PlugGPSloc = [ GPSLOC_inst : PInstance, GPSLOC_father : SO3_OBJECT, GPSLOC_vLocation : [F F], GPSLOC_initpos : [[F F F] [F F F F]], GPSLOC_lastpos : [[F F F] [F F F]], GPSLOC_fScale : F, GPSLOC_fDist : F, GPSLOC_bDistState : I, GPSLOC_bEdistance : I, GPSLOC_bElocation : I ]mkPlugGPSloc;; /*------------------ Delete PlugIT instance -------------------*/ fun deleteOb(inst, obstr)= _StopDeviceLocation; setPluginInstanceCbScenePreRender inst nil; let obstr.GPSLOC_initpos -> [pos quat] in ( SO3ObjectSetPosition obstr.GPSLOC_father pos; SO3ObjectSetOrientation obstr.GPSLOC_father quat; ); 0;; fun cbPreRender(inst, sessionstr, etime, obstr)= let _GetDeviceLocation -> [long lat alt] in let obstr.GPSLOC_vLocation -> [olong olat] in if (lat == nil || alt == nil || lat == 0.0 || alt == 0.0) then nil else ( let _GetLocationOffset (SO3MathsDegreeToRadian long) (SO3MathsDegreeToRadian lat) (SO3MathsDegreeToRadian olong) (SO3MathsDegreeToRadian olat) -> [ox oy] in let getVectorDistanceF [0.0 0.0 0.0] [ox 0.0 oy] -> dist in let (V3DgetDefaultViewport (V3DgetSessionView sessionstr)) -> viewportstr in let SO3ViewportGetCamera viewportstr.V3D_viewport -> cam in let SO3ObjectGetGlobalPosition cam -> campos in let obstr.GPSLOC_initpos -> [opos oquat] in let SO3ObjectGetParent cam -> camshell in let if ((camshell == nil) || (camshell == SO3ObjectGetSceneRoot (V3DgetSession sessionstr))) then campos else let SO3ObjectGetPosition cam -> [cx cy cz] in subVectorF campos [0.0 cy 0.0] -> campos in ( SO3ObjectSetGlobalPosition obstr.GPSLOC_father (addVectorF campos addVectorF opos [ox 0.0 (-.oy)]); if (!obstr.GPSLOC_bElocation) then nil else SendPluginEvent inst "Location" strcatnSep (ftoa lat)::(ftoa long)::nil " " inst.INST_sName; if ((dist == nil) || !obstr.GPSLOC_bEdistance) then nil else SendPluginEvent inst "Distance" (ftoa dist) inst.INST_sName; if (dist != nil && !obstr.GPSLOC_bDistState && dist <. obstr.GPSLOC_fDist) then ( SendPluginEvent inst "In" nil inst.INST_sName; set obstr.GPSLOC_bDistState = 1; ) else if (dist != nil && obstr.GPSLOC_bDistState && dist >=. obstr.GPSLOC_fDist) then ( SendPluginEvent inst "Out" nil inst.INST_sName; set obstr.GPSLOC_bDistState = 0; ) else nil; ); ); 0;; /*----------------------- Callbacks ------------------------*/ fun cbEnable(inst, from, action, param, rep, obstr)= _StartDeviceLocation; setPluginInstanceCbScenePreRender inst mkfun4 @cbPreRender obstr; 0;; fun cbDisable(inst, from, action, param, rep, obstr)= _StopDeviceLocation; setPluginInstanceCbScenePreRender inst nil; 0;; fun cbSetLocation(inst, from, action, param, rep, obstr)= if ((!strcmp "" (strtrim param)) || (param == nil)) then nil else let strextr param -> lp in set obstr.GPSLOC_vLocation = [(atof (nth_list (hd lp) 0)) (atof (nth_list (hd lp) 1))]; if (!obstr.GPSLOC_bDistState) then nil else ( SendPluginEvent inst "Out" nil inst.INST_sName; set obstr.GPSLOC_bDistState = 0; ); 0;; /*--------------- Create new PlugIT instance ----------------*/ fun newOb(inst)= let atof (getPluginInstanceParam inst "long") -> long in let if (long == nil) then (-.1.548131) else long -> long in let atof (getPluginInstanceParam inst "lat") -> lat in let if (lat == nil) then 47.21357 else lat -> lat in let atof (getPluginInstanceParam inst "alt") -> alt in let if (alt == nil) then 8.0 else alt -> alt in let (getPluginInstanceParam inst "object") -> objname in let V3DgetObjectByName c3dXsession objname -> father in let SO3ObjectGetPosition father -> cpos in let SO3ObjectGetOrientation father -> cquat in let atof (getPluginInstanceParam inst "scale") -> scale in let if (scale == nil) then 1.0 else scale -> scale in let atof (getPluginInstanceParam inst "dist") -> dist in let if (dist == nil) then 10.0 else dist -> dist in let atoi (getPluginInstanceParam inst "enable") -> enable in let if enable == nil then 1 else enable -> enable in let (IsInEditor inst) || IsEventLinked inst "Distance" -> bdistance in let (IsInEditor inst) || IsEventLinked inst "Location" -> blocation in let mkPlugGPSloc [inst father [long lat] [cpos cquat] nil scale dist 0 bdistance blocation] -> obstr in ( if (!enable) then nil else cbEnable inst nil nil nil nil obstr; PluginRegisterAction inst "Enable" mkfun6 @cbEnable obstr; PluginRegisterAction inst "Disable" mkfun6 @cbDisable obstr; PluginRegisterAction inst "Set target location" mkfun6 @cbSetLocation obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; /*------------------- Initialize PlugIT --------------------*/ fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;