/* ----------------------------------------------------------------------------- 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 ObjTargetStr = [ PTARGET_target : SO3_OBJECT, PTARGET_source : [SO3_OBJECT [[F F F] [F F F F] [F F F F]]], PTARGET_iSourceMode : I, PTARGET_iTargetMode : I, PTARGET_direction : [F F F], PTARGET_axis : [I I I], PTARGET_state : I ]mkObjTarget;; fun deleteOb(inst, obstr)= setPluginInstanceCbPreRender inst nil; setPluginInstanceCbCameraChange inst nil; let obstr.PTARGET_source -> [objsrc [pos quat offquat]] in ( SO3ObjectSetPosition objsrc pos; SO3ObjectSetOrientation objsrc quat; ); 0;; fun getViewDir(ovec, tvec, oang, axis, axisstate)= let ovec -> [vx vy vz] in let tvec -> [dx dy dz] in let normalizeVectorF (subVectorF [dx dy dz] ovec) -> dir in let normalizeVectorF (SO3MathsQuatGetDirection oang axis) -> src in let SO3MathsQuatToEulerPYR (SO3MathsGetRotationTo src dir) -> [pitch yaw roll] in let if ((1.0 +. dotVectorF src dir) <. 0.0001) then PIf *. 2.0 else yaw -> yaw in let axisstate -> [ex ey ez] in let multiplyVectorF [pitch yaw roll] [itof ex itof ey itof ez] -> rotaxis in let SO3MathsQuatAdd SO3MathsEulerPYRToQuat rotaxis oang -> nquat in ( nquat; );; fun cbGetPretRender(inst, viewstr, obstr)= let obstr.PTARGET_source -> [objsrc [pos quat offquat]] in let obstr.PTARGET_direction -> [dx dy dz] in let /*if (SO3ObjectGetType objsrc) == SO3_TYPE_CAMERA then [0.0 0.0 (-.1.0)] else*/ [dx dy dz] -> srcdir in let SO3ObjectGetGlobalPosition objsrc -> src in let SO3ObjectGetGlobalPosition obstr.PTARGET_target -> target in let getViewDir src target quat srcdir obstr.PTARGET_axis -> dirquat in ( SO3ObjectSetGlobalOrientation objsrc SO3MathsQuatAdd offquat dirquat; ); 0;; fun cbEnable(inst, from, action, param, reply, obstr)= setPluginInstanceCbPreRender inst mkfun3 @cbGetPretRender obstr; set obstr.PTARGET_state = 1; 0;; fun cbDisable(inst, from, action, param, reply, obstr)= let obstr.PTARGET_source -> [objsrc [pos quat offquat]] in ( setPluginInstanceCbPreRender inst nil; SO3ObjectSetPosition objsrc pos; SO3ObjectSetOrientation objsrc quat; set obstr.PTARGET_state = 0; ); 0;; fun cbChangeCamera(inst, viewstr, sessionstr, camera, obstr)= if (!obstr.PTARGET_iSourceMode) then nil else let V3DgetCameraByType sessionstr camera obstr.PTARGET_iSourceMode -> nsource in let SO3ObjectGetPosition nsource -> cpos in let SO3ObjectGetOrientation nsource -> cquat in let obstr.PTARGET_source -> [objsrc [pos quat offquat]] in ( SO3ObjectSetPosition objsrc pos; SO3ObjectSetOrientation objsrc quat; set obstr.PTARGET_source = [nsource [cpos cquat offquat]]; ); if (!obstr.PTARGET_iTargetMode) then nil else ( set obstr.PTARGET_target = V3DgetCameraByType sessionstr camera obstr.PTARGET_iTargetMode; ); 0;; fun newOb(inst)= let (getPluginInstanceParam inst "object") -> objname1 in let (getPluginInstanceParam inst "target") -> objname2 in // for compatibility let if ((atoi (getPluginInstanceParam inst "iscamera")) == 1) then "Current camera" else objname2 -> objname2 in let atof (getPluginInstanceParam inst "dirx") -> posx in let atof (getPluginInstanceParam inst "diry") -> posy in let atof (getPluginInstanceParam inst "dirz") -> posz in let if posx == nil then 0.0 else posx -> posx in let if posy == nil then 0.0 else posy -> posy in let if posz == nil then -.1.0 else posz -> posz in let atof (getPluginInstanceParam inst "offx") -> offx in let atof (getPluginInstanceParam inst "offy") -> offy in let atof (getPluginInstanceParam inst "offz") -> offz in let if offx == nil then 0.0 else offx -> offx in let if offy == nil then 0.0 else offy -> offy in let if offz == nil then 0.0 else offz -> offz in let atoi (getPluginInstanceParam inst "xaxis") -> xaxis in let atoi (getPluginInstanceParam inst "yaxis") -> yaxis in let atoi (getPluginInstanceParam inst "zaxis") -> zaxis in let if xaxis == nil then 1 else xaxis -> xaxis in let if yaxis == nil then 1 else yaxis -> yaxis in let if zaxis == nil then 1 else zaxis -> zaxis in let atoi (getPluginInstanceParam inst "init") -> init in let V3DgetObjectByName c3dXsession objname1 -> objsrc in let V3DgetObjectTypeByName objname1 -> iobj1mode in let V3DgetObjectByName c3dXsession objname2 -> target in let V3DgetObjectTypeByName objname2 -> iobj2mode in let SO3ObjectGetPosition objsrc -> cpos in let SO3ObjectGetOrientation objsrc -> cquat in let SO3MathsEulerPYRToQuat [SO3MathsDegreeToRadian offx SO3MathsDegreeToRadian offy SO3MathsDegreeToRadian offz] -> offquat in let mkObjTarget [target [objsrc [cpos cquat offquat]] iobj1mode iobj2mode [posx posy posz] [xaxis yaxis zaxis] 0] -> obstr in ( PluginRegisterAction inst "Enable" mkfun6 @cbEnable obstr; PluginRegisterAction inst "Disable" mkfun6 @cbDisable obstr; if !iobj1mode && !iobj2mode then nil else setPluginInstanceCbCameraChange inst mkfun5 @cbChangeCamera obstr; if (!init) then nil else cbEnable inst nil nil nil nil obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;