/* ----------------------------------------------------------------------------- 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 PlugRotate = [ ROT_inst : PInstance, ROT_shell : SO3_OBJECT, ROT_iShellMode : I, ROT_initQuat : [F F F F], ROT_angLimit : [F F F F], ROT_from : [F F F F], ROT_dest : [F F F F], ROT_fSpeed : F, ROT_fCoef : F ]mkPlugRotate;; fun deleteOb(inst, rotstr)= setPluginInstanceCbCameraChange inst nil; setPluginInstanceCbScenePreRender inst nil; SO3ObjectSetOrientation rotstr.ROT_shell rotstr.ROT_initQuat; 0;; fun cbRotPreRender(inst, sessionstr, etime, rotstr)= let (itof etime) /. 1000000.0 -> ftime in let ftime *. 90.0 -> nbframe in let if ((rotstr.ROT_fCoef +. (rotstr.ROT_fSpeed *. nbframe)) >. 1.0) then 1.0 else if ((rotstr.ROT_fCoef +. (rotstr.ROT_fSpeed *. nbframe)) <. 0.0) then 0.0 else (rotstr.ROT_fCoef +. (rotstr.ROT_fSpeed *. nbframe)) -> coef in if (((coef -. rotstr.ROT_fCoef) == 0.0) && (nbframe >=. 0.0)) then ( SO3ObjectSetOrientation rotstr.ROT_shell rotstr.ROT_dest; setPluginInstanceCbScenePreRender inst nil; SendPluginEvent rotstr.ROT_inst "End" nil nil; 0; ) else ( let SO3MathsQuatInterpolate rotstr.ROT_from rotstr.ROT_dest coef 1 -> tang in SO3ObjectSetOrientation rotstr.ROT_shell tang; set rotstr.ROT_fCoef = coef; 0; ); 0;; fun enableRotate(inst, from, action, param, rep, rotstr) = setPluginInstanceCbScenePreRender inst nil; set rotstr.ROT_from = SO3ObjectGetOrientation rotstr.ROT_shell; let strextr param -> lp in let atof (nth_list (hd lp) 0) -> ax in let atof (nth_list (hd lp) 1) -> ay in let atof (nth_list (hd lp) 2) -> az in let if ay == nil then 0.0 else ay -> ay in let if az == nil then 0.0 else az -> az in if (lp != nil) && (ax != nil) then ( set rotstr.ROT_dest = SO3MathsEulerXYZToQuat [(SO3MathsDegreeToRadian ay) (SO3MathsDegreeToRadian ax) (SO3MathsDegreeToRadian az)]; ) else ( set rotstr.ROT_dest = rotstr.ROT_angLimit; ); set rotstr.ROT_fCoef = 0.0; setPluginInstanceCbScenePreRender inst mkfun4 @cbRotPreRender rotstr; 0;; fun disableRotate(inst, from, action, param, rep, rotstr) = setPluginInstanceCbScenePreRender inst nil; 0;; fun cbChangeCamera(inst, viewstr, sessionstr, camera, rotstr)= let V3DgetCameraByType sessionstr camera rotstr.ROT_iShellMode -> nfather in let SO3ObjectGetOrientation nfather -> cquat in ( SO3ObjectSetOrientation rotstr.ROT_shell rotstr.ROT_initQuat; set rotstr.ROT_shell = nfather; set rotstr.ROT_initQuat = cquat; ); 0;; fun newOb(inst)= let (getPluginInstanceParam inst "object") -> objname in let atoi (getPluginInstanceParam inst "enable") -> enable in let SO3MathsDegreeToRadian (atof (getPluginInstanceParam inst "rotx")) -> ax in let SO3MathsDegreeToRadian (atof (getPluginInstanceParam inst "roty")) -> ay in let SO3MathsDegreeToRadian (atof (getPluginInstanceParam inst "rotz")) -> az in let atof (getPluginInstanceParam inst "speed") -> speed in let if speed == nil then 0.1 else speed -> speed in let SO3MathsEulerXYZToQuat [ay ax az] -> anglimit in let V3DgetObjectByName c3dXsession objname -> obj in let V3DgetObjectTypeByName objname -> iobjmode in let SO3ObjectGetOrientation obj -> initquat in let mkPlugRotate [inst obj iobjmode initquat anglimit nil nil speed 0.0] -> rotstr in ( PluginRegisterAction inst "Go" mkfun6 @enableRotate rotstr; PluginRegisterAction inst "Stop" mkfun6 @disableRotate rotstr; if !iobjmode then nil else setPluginInstanceCbCameraChange inst mkfun5 @cbChangeCamera rotstr; setPluginInstanceCbDel inst mkfun2 @deleteOb rotstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;