/* ----------------------------------------------------------------------------- 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 ObjImpulseStr = [ PTARGET_target : SO3_OBJECT, PTARGET_source : SO3_OBJECT, PTARGET_iTargetMode : I, PTARGET_iSourceMode : I, PTARGET_param : [F F F], PTARGET_state : I, PTARGET_fMul : F ]mkObjImpulseStr;; fun deleteOb(inst, obtargetstr)= setPluginInstanceCbCameraChange inst nil; 0;; fun cbChangeCamera(inst, viewstr, sessionstr, camera, obtargetstr)= if (!obtargetstr.PTARGET_iSourceMode) then nil else ( set obtargetstr.PTARGET_source = V3DgetCameraByType sessionstr camera obtargetstr.PTARGET_iSourceMode; ); if (!obtargetstr.PTARGET_iTargetMode) then nil else ( set obtargetstr.PTARGET_target = V3DgetCameraByType sessionstr camera obtargetstr.PTARGET_iTargetMode; ); 0;; fun cbImpulse(inst, from, action, param, reply, obtargetstr)= let if (!strcmp "" (strtrim param)) || param == nil then ( if obtargetstr.PTARGET_target == nil then nil else SO3ObjectGetGlobalPosition obtargetstr.PTARGET_target; ) else let strextr param -> lp in [(atof (nth_list (hd lp) 0)) (atof (nth_list (hd lp) 1)) (atof (nth_list (hd lp) 2))] -> tvec in if (tvec == nil) then nil else let tvec -> [tx ty tz] in let SO3ObjectGetGlobalPosition obtargetstr.PTARGET_source -> [px py pz] in let obtargetstr.PTARGET_param -> [ox oy oz] in let (px-.tx) -> dx in let (py-.ty) -> dy in let (pz-.tz) -> dz in ( SO3BodyAddImpulse (SO3SceneNodeGetBody obtargetstr.PTARGET_source) [(ox *. dx *. obtargetstr.PTARGET_fMul) (oy *. dy *. obtargetstr.PTARGET_fMul) (oz *. dz *. obtargetstr.PTARGET_fMul)] [px py pz]; 0; ); 0;; fun cbSetDirObject(inst, from, action, param, reply, obtargetstr)= let V3DgetObjectByName c3dXsession param -> target in let V3DgetObjectTypeByName param -> iobj1mode in if (target == nil) then nil else ( set obtargetstr.PTARGET_iTargetMode = iobj1mode; if !obtargetstr.PTARGET_iTargetMode && !obtargetstr.PTARGET_iSourceMode then setPluginInstanceCbCameraChange inst nil else setPluginInstanceCbCameraChange inst mkfun5 @cbChangeCamera obtargetstr; set obtargetstr.PTARGET_target = target; ); 0;; fun cbSetSrcObject(inst, from, action, param, reply, obtargetstr)= let V3DgetObjectByName c3dXsession param -> objsrc in let V3DgetObjectTypeByName param -> iobj2mode in if (objsrc == nil) then nil else ( set obtargetstr.PTARGET_iSourceMode = iobj2mode; if !obtargetstr.PTARGET_iTargetMode && !obtargetstr.PTARGET_iSourceMode then setPluginInstanceCbCameraChange inst nil else setPluginInstanceCbCameraChange inst mkfun5 @cbChangeCamera obtargetstr; set obtargetstr.PTARGET_source = objsrc; ); 0;; fun cbSetForceMultiply(inst, from, action, param, reply, obtargetstr)= if (!strcmp "" (strtrim param)) || param == nil then nil else let strextr param -> lp in let (atof (nth_list (hd lp) 0)) -> nf in if (nf == nil) then nil else set obtargetstr.PTARGET_fMul = nf; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "object") -> objsource in let (getPluginInstanceParam inst "target") -> objtarget in // for compatibility let if ((atoi (getPluginInstanceParam inst "iscamera")) == 1) then "Current camera" else objtarget -> objtarget in let atof (getPluginInstanceParam inst "offsetx") -> fx in let atof (getPluginInstanceParam inst "offsety") -> fy in let atof (getPluginInstanceParam inst "offsetz") -> fz in let [fx fy fz] -> offset in let V3DgetObjectByName c3dXsession objtarget -> target in let V3DgetObjectTypeByName objtarget -> iobj1mode in let V3DgetObjectByName c3dXsession objsource -> objsrc in let V3DgetObjectTypeByName objsource -> iobj2mode in let mkObjImpulseStr [target objsrc iobj1mode iobj2mode offset 0 1.0] -> obtargetstr in ( if !iobj1mode && !iobj2mode then nil else setPluginInstanceCbCameraChange inst mkfun5 @cbChangeCamera obtargetstr; PluginRegisterAction inst "Impulse" mkfun6 @cbImpulse obtargetstr; PluginRegisterAction inst "Set direction object" mkfun6 @cbSetDirObject obtargetstr; PluginRegisterAction inst "Set source object" mkfun6 @cbSetSrcObject obtargetstr; PluginRegisterAction inst "Set force multiplicator" mkfun6 @cbSetForceMultiply obtargetstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obtargetstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;