/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2014 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 ObjERadarStr = [ ERADAR_child : SO3_OBJECT, ERADAR_lLines : [SO3_OBJECT r1], ERADAR_fDist : F, ERADAR_fxAng : F, ERADAR_fyAng : F, ERADAR_fPrecision : F ]mkObjERadarStr;; fun cbDestroyEdit(inst, edstr)= setPluginInstanceEditorCbPreRender inst nil; while (edstr.ERADAR_lLines != nil) do ( SO3ObjectDestroy hd edstr.ERADAR_lLines; set edstr.ERADAR_lLines = tl edstr.ERADAR_lLines; ); 0;; fun cbEditorPreRender(inst, sessionstr, etime, edstr)= if (edstr.ERADAR_child == nil) then nil else let SO3ObjectGetGlobalPosition edstr.ERADAR_child -> pos in let SO3ObjectGetGlobalOrientation edstr.ERADAR_child -> quat in let nil -> lpoints in let 0 -> i in ( let 10.0 -> angstep in let edstr.ERADAR_fDist -> dist in let maxf ((edstr.ERADAR_fxAng /. angstep) *. edstr.ERADAR_fPrecision) ((edstr.ERADAR_fyAng /. angstep) *. edstr.ERADAR_fPrecision) -> nbpoints in let dist *. (tan (SO3MathsDegreeToRadian edstr.ERADAR_fxAng /. 2.0)) -> rx in let dist *. (tan (SO3MathsDegreeToRadian edstr.ERADAR_fyAng /. 2.0)) -> ry in let ftoi nbpoints -> nb in let 1 -> n in while (n <= nb) do ( let rx *. (itof n) /. (itof nb) -> nrx in let ry *. (itof n) /. (itof nb) -> nry in let (2.0 *. PIf) /. (nbpoints *. (itof n)) -> nstep in let nstep -> pv in while (pv <=. (2.0 *. PIf)) do ( let [(nrx *. cos(pv)) (nry *. sin(pv)) dist] -> pt in let addVectorF (SO3MathsQuatGetDirection quat pt) pos -> pt in if ((nth_list edstr.ERADAR_lLines i) == nil) then ( set edstr.ERADAR_lLines = lcat edstr.ERADAR_lLines (SO3LineEntityCreate (V3DgetSession sessionstr) strcatn (getPluginInstanceName inst)::"_"::(itoa n)::"_"::(itoa i)::nil pos::pt::nil 0xffff0000)::nil; 0; ) else ( SO3LineEntitySetPoints (nth_list edstr.ERADAR_lLines i) pos::pt::nil; 0; ); set pv = pv +. nstep; set i = i + 1; ); set n = n + 1; ); ); 0;; fun cbCloseEdit(p)= let p -> [edstr ctrlobjname1 ctrlobjname2 ctrldist ctrlxang ctrlyang ctrlprecision ctrldebounce ctrlinit] in ( while (edstr.ERADAR_lLines != nil) do ( SO3ObjectDestroy hd edstr.ERADAR_lLines; set edstr.ERADAR_lLines = tl edstr.ERADAR_lLines; ); let getEdCtrlTextLineValue ctrlobjname1 -> objname1 in let getEdCtrlTextLineValue ctrlobjname2 -> objname2 in let getEdCtrlFloatValue ctrldist -> dist in let getEdCtrlFloatValue ctrlxang -> xang in let getEdCtrlFloatValue ctrlyang -> yang in let getEdCtrlFloatValue ctrlprecision -> precision in let ftoi getEdCtrlFloatValue ctrldebounce -> debounce in let getEdCtrlCheckState ctrlinit -> init in ["object" objname1]:: ["object2" objname2]:: ["distance" ftoa dist]:: ["xang" ftoa xang]:: ["yang" ftoa yang]:: ["precision" ftoa precision]:: ["debounce" itoa debounce]:: ["init" itoa init]:: nil; );; fun cbSelectObj(val, type, p)= let p -> [winstr edstr viewstr ctrlobjname] in let V3DgetDefaultSession viewstr -> sessionstr in let SO3SceneGetObject (V3DgetSession sessionstr) val -> obj in if (obj != nil) || (!strcmpi "Current camera" val) || (!strcmpi "Current camera shell" val) then ( setEdCtrlTextLineValue ctrlobjname val; if (edstr == nil) then nil else set edstr.ERADAR_child = V3DgetObjectByName sessionstr val; ) else nil; 0;; fun cbCloseRes(ctrlbtn)= setEdCtrlButtonEnable ctrlbtn 1; 0;; fun cbBtnPickObj(ctrlbtn, p)= let p -> [inst winstr edstr viewstr ctrlobjname objname] in ( setEdCtrlButtonEnable ctrlbtn 0; dlgSelectPluginInstanceResource inst winstr iTypeEntity|iTypeNode|iTypeLight|iTypeBone|iTypeCamera|iTypeParticle|iTypeCubeMap objname mkfun3 @cbSelectObj [winstr edstr viewstr ctrlobjname] mkfun1 @cbCloseRes ctrlbtn 0; ); 0;; fun cbRefreshBtn(pickbtn, p)= let p -> [ctrlobjname edstr] in ( setEdCtrlTextLineValue ctrlobjname ""; if (edstr == nil) then nil else ( set edstr.ERADAR_child = nil; while (edstr.ERADAR_lLines != nil) do ( SO3ObjectDestroy hd edstr.ERADAR_lLines; set edstr.ERADAR_lLines = tl edstr.ERADAR_lLines; ); ); ); 0;; fun cbEditDist(ctrl, value, edstr)= set edstr.ERADAR_fDist = value; 0;; fun cbEditXAng(ctrl, value, edstr)= set edstr.ERADAR_fxAng = value; while (edstr.ERADAR_lLines != nil) do ( SO3ObjectDestroy hd edstr.ERADAR_lLines; set edstr.ERADAR_lLines = tl edstr.ERADAR_lLines; ); 0;; fun cbEditYAng(ctrl, value, edstr)= set edstr.ERADAR_fyAng = value; while (edstr.ERADAR_lLines != nil) do ( SO3ObjectDestroy hd edstr.ERADAR_lLines; set edstr.ERADAR_lLines = tl edstr.ERADAR_lLines; ); 0;; fun cbEditPrecision(ctrl, value, edstr)= set edstr.ERADAR_fPrecision = value; while (edstr.ERADAR_lLines != nil) do ( SO3ObjectDestroy hd edstr.ERADAR_lLines; set edstr.ERADAR_lLines = tl edstr.ERADAR_lLines; ); 0;; fun dynamicedit(ewinstr, inst, viewstr, applybtn)= let [420 300] -> [iw ih] in let 10 -> ypos in let mkObjERadarStr [nil nil nil nil nil nil] -> edstr in ( setEdWindowSize ewinstr iw ih; setPluginInstanceEditorCbPreRender inst mkfun4 @cbEditorPreRender edstr; let V3DgetDefaultSession viewstr -> sessionstr in let (getPluginInstanceParam inst "object") -> objname1 in let (getPluginInstanceParam inst "object2") -> objname2 in //for compatibility let if (atoi (getPluginInstanceParam inst "iscamera")) == 1 then "Current camera" else objname2 -> objname2 in let atof (getPluginInstanceParam inst "distance") -> dist in let if dist == nil then 1.0 else dist -> dist in let atof (getPluginInstanceParam inst "xang") -> xang in let if xang == nil then 45.0 else xang -> xang in let atof (getPluginInstanceParam inst "yang") -> yang in let if yang == nil then 45.0 else yang -> yang in let atof (getPluginInstanceParam inst "precision") -> precision in let if precision == nil then 0.5 else precision -> precision in let atof (getPluginInstanceParam inst "debounce") -> debounce in let if debounce == nil then 0.0 else debounce -> debounce in let atoi (getPluginInstanceParam inst "init") -> init in let if init == nil then 1 else init -> init in let crEdFrameWindow _channel ewinstr 0 0 iw 80 EDWIN_RESIZE_MW nil (loc "OS3DPHYSICRADAR_0011") (loc "OS3DPHYSICRADAR_0009") -> winfrm in let crEdWindow _channel winfrm 0 18 iw 60 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlLabel winstr 10 (ypos + 2) 160 20 (loc "OS3DPHYSICRADAR_0008") nil -> labelobj in let crEdCtrlTextLine winstr 180 ypos 140 20 objname1 nil EDWIN_RESIZE_MW -> ctrlobjname1 in let crEdCtrlButton winstr 325 ypos 55 20 "..." nil -> pickbtn1 in let crEdCtrlButton winstr 385 ypos 35 20 "X" nil -> refreshobjname1 in let crEdCtrlLabel winstr 10 (set ypos = ypos + 25) + 2 160 20 (loc "OS3DPHYSICRADAR_0013") nil -> labelobj in let crEdCtrlTextLine winstr 180 ypos 140 20 objname2 nil EDWIN_RESIZE_MW -> ctrlobjname2 in let crEdCtrlButton winstr 325 ypos 55 20 "..." nil -> pickbtn2 in let crEdCtrlButton winstr 385 ypos 35 20 "X" nil -> refreshobjname2 in let crEdFrameWindow _channel ewinstr 0 0 iw 130 EDWIN_RESIZE_MW nil (loc "OS3DPHYSICRADAR_0014") (loc "OS3DPHYSICRADAR_0009") -> winfrm in let crEdWindow _channel winfrm 0 18 iw 110 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlLabel winstr 10 (set ypos = 10) + 2 160 20 (loc "OS3DPHYSICRADAR_0006") nil -> labeldist in let crEdCtrlFloat winstr 180 ypos 110 20 dist 0.1 1000000.0 0.01 5 nil EDWIN_RESIZE_MW -> ctrldist in let crEdCtrlLabel winstr 10 (set ypos = ypos + 25) + 2 160 20 (loc "OS3DPHYSICRADAR_0001") nil -> labelxang in let crEdCtrlFloat winstr 180 ypos 110 20 xang 1.0 170.0 1.0 4 nil EDWIN_RESIZE_MW -> ctrlxang in let crEdCtrlLabel winstr 10 (set ypos = ypos + 25) + 2 160 20 (loc "OS3DPHYSICRADAR_0002") nil -> labelyang in let crEdCtrlFloat winstr 180 ypos 110 20 yang 1.0 170.0 1.0 4 nil EDWIN_RESIZE_MW -> ctrlyang in let crEdCtrlLabel winstr 10 (set ypos = ypos + 25) + 2 160 20 (loc "OS3DPHYSICRADAR_0012") nil -> labelprec in let crEdCtrlFloat winstr 180 ypos 110 20 precision 0.1 1.0 0.1 4 nil EDWIN_RESIZE_MW -> ctrlprecision in let crEdFrameWindow _channel ewinstr 0 0 iw 90 EDWIN_RESIZE_MW nil (loc "OS3DPHYSICRADAR_0010") (loc "OS3DPHYSICRADAR_0009") -> winfrm in let crEdWindow _channel winfrm 0 18 iw 70 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlLabel winstr 10 (set ypos = 10) + 2 160 40 (loc "OS3DPHYSICRADAR_0005") nil -> labeldebounce in let crEdCtrlFloat winstr 180 ypos 110 20 debounce 0.0 100000.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrldebounce in let crEdCtrlCheck winstr 10 (set ypos = ypos + 35) + 2 280 20 (loc "OS3DPHYSICRADAR_0007") EDWIN_RESIZE_MW -> ctrlinit in ( set edstr.ERADAR_child = V3DgetObjectByName sessionstr objname1; set edstr.ERADAR_fDist = dist; set edstr.ERADAR_fxAng = xang; set edstr.ERADAR_fyAng = yang; set edstr.ERADAR_fPrecision = precision; setEdCtrlButtonCb pickbtn1 mkfun2 @cbBtnPickObj [inst winstr edstr viewstr ctrlobjname1 objname1]; setEdCtrlTextLineEnable ctrlobjname1 0; setEdCtrlButtonCb refreshobjname1 mkfun2 @cbRefreshBtn [ctrlobjname1 edstr]; setEdCtrlButtonCb pickbtn2 mkfun2 @cbBtnPickObj [inst winstr nil viewstr ctrlobjname2 objname2]; setEdCtrlTextLineEnable ctrlobjname2 0; setEdCtrlButtonCb refreshobjname2 mkfun2 @cbRefreshBtn [ctrlobjname2 nil]; setEdCtrlFloatCbChange ctrldist mkfun3 @cbEditDist edstr; setEdCtrlFloatCbChange ctrlxang mkfun3 @cbEditXAng edstr; setEdCtrlFloatCbChange ctrlyang mkfun3 @cbEditYAng edstr; setEdCtrlFloatCbChange ctrlprecision mkfun3 @cbEditPrecision edstr; setEdCtrlCheckState ctrlinit init; [mkfun1 @cbCloseEdit [edstr ctrlobjname1 ctrlobjname2 ctrldist ctrlxang ctrlyang ctrlprecision ctrldebounce ctrlinit] mkfun1 mkfun2 @cbDestroyEdit edstr inst]; ); );;