/* ----------------------------------------------------------------------------- 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 PlugMiniMap = [ PMM_instance : PInstance, PMM_Camera : SO3_OBJECT, PMM_Shell : SO3_OBJECT, PMM_Cursor : SO3_OBJECT, PMM_AvShell : SO3_OBJECT, PMM_AvCam : SO3_OBJECT, PMM_viewport : V3Dviewport, PMM_iPosX : I, PMM_iPosY : I, PMM_iWidth : I, PMM_iHeight : I, PMM_tPercent : [I I I I], PMM_tAlign : [I I], PMM_fDistance : F, PMM_fLevel : F, PMM_bTransparent : I ]mkPlugMiniMap;; fun deleteOb(inst, constr)= setPluginInstanceCbResizeView inst nil; let (V3DgetSessionView c3dXsession) -> viewstr in V3DdelViewport viewstr constr.PMM_viewport; SO3ObjectDestroy constr.PMM_Camera; SO3ObjectDestroy constr.PMM_Shell; set constr.PMM_Camera = nil; set constr.PMM_Shell = nil; set constr.PMM_viewport = nil; SO3GroupDelete (V3DgetSession c3dXsession) strcat (getPluginInstanceName inst) "_Group"; 0;; fun cbGetPreRender(inst, viewstr, constr)= let SO3ObjectGetGlobalPosition constr.PMM_AvShell -> avpos in SO3ObjectSetPosition constr.PMM_Shell avpos; let SO3MathsQuatToEulerPYR SO3ObjectGetGlobalOrientation constr.PMM_AvCam -> [_ yaw _] in SO3ObjectSetOrientation constr.PMM_Shell SO3MathsEulerPYRToQuat [0.0 yaw 0.0]; 0;; fun cbCreate(inst, from, action, param, reply, constr)= if constr.PMM_viewport != nil then nil else ( let (V3DgetSessionView c3dXsession) -> viewstr in let constr.PMM_tPercent -> [px py pw ph] in let constr.PMM_tAlign -> [ax ay] in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let if pw then ftoi (((itof constr.PMM_iWidth) /. 100.0) *. (itof vw)) else constr.PMM_iWidth -> pw in let if ph then ftoi (((itof constr.PMM_iHeight) /. 100.0) *. (itof vh)) else constr.PMM_iHeight -> ph in let if px then ftoi (((itof constr.PMM_iPosX) /. 100.0) *. (itof vw)) else constr.PMM_iPosX -> px in let if (ax == 1) then ((vw / 2) - (pw / 2)) + px else if (ax == 2) then (vw - pw) - px else px -> px in let if py then ftoi (((itof constr.PMM_iPosY) /. 100.0) *. (itof vh)) else constr.PMM_iPosY -> py in let if (ay == 1) then ((vh / 2) - (ph / 2)) + py else if (ay == 2) then (vh - ph) - py else py -> py in ( SO3CameraSetFOVy constr.PMM_Camera 0.8; SO3ObjectLink constr.PMM_Camera constr.PMM_Shell; SO3ObjectSetPosition constr.PMM_Camera [0.0 constr.PMM_fDistance 0.0]; SO3ObjectSetOrientation constr.PMM_Camera SO3MathsEulerXYZToQuat [0.0 (SO3MathsDegreeToRadian -.90.0) 0.0]; SO3CameraSetNearClipDistance constr.PMM_Camera (constr.PMM_fDistance -. constr.PMM_fLevel); SO3ObjectLink constr.PMM_Cursor constr.PMM_Shell; SO3ObjectSetVisible constr.PMM_Cursor 1 1; SO3ObjectSetPosition constr.PMM_Cursor [0.0 1.0 0.0]; let constr.PMM_fDistance *. 0.1 -> scale in SO3ObjectSetScale constr.PMM_Cursor [scale scale scale]; set constr.PMM_viewport = V3DaddViewport viewstr ((itof px) /. (itof vw)) ((itof py) /. (itof vh)) ((itof pw) /. (itof vw)) ((itof ph) /. (itof vh)) 0; V3DsetViewport viewstr constr.PMM_viewport constr.PMM_Camera; SO3ViewportSetOverlayEnable constr.PMM_viewport.V3D_viewport 0; //if !(V3DgetOrthographicMode constr.PMM_Camera) then nil else // let if constr.PMM_fDistance <. 0.1 then 0.1 else constr.PMM_fDistance -> scale in // let if (ph <= 0) then 1 else ph -> ph in // let ((itof pw) /. (itof ph)) *. scale -> wscale in // SO3CameraSetOrthoWindow constr.PMM_Camera wscale scale; if (!constr.PMM_bTransparent) then nil else SO3ViewportSetSkyEnable constr.PMM_viewport.V3D_viewport 0; SO3ViewportSetClearDepth constr.PMM_viewport.V3D_viewport constr.PMM_bTransparent; SO3ViewportSetClearColor constr.PMM_viewport.V3D_viewport 0; SO3ViewportSetVisibilityMask constr.PMM_viewport.V3D_viewport 0xFFFFFFFE; SO3ViewportSetVisibilityMask viewportstr.V3D_viewport 0xFFFFFFEF; SO3EntitySetVisibilityFlags constr.PMM_Cursor 0x00000010; setPluginInstanceCbPreRender inst mkfun3 @cbGetPreRender constr; ); ); 0;; fun cbDestroy(inst, from, action, param, reply, constr)= setPluginInstanceCbPreRender inst nil; let (V3DgetSessionView c3dXsession) -> viewstr in V3DdelViewport viewstr constr.PMM_viewport; set constr.PMM_viewport = nil; 0;; fun cbResizeCtrl(inst, viewstr, vw, vh, constr)= if constr.PMM_viewport == nil then nil else ( let (V3DgetSessionView c3dXsession) -> viewstr in let constr.PMM_tPercent -> [px py pw ph] in let constr.PMM_tAlign -> [ax ay] in let if pw then ftoi (((itof constr.PMM_iWidth) /. 100.0) *. (itof vw)) else constr.PMM_iWidth -> pw in let if ph then ftoi (((itof constr.PMM_iHeight) /. 100.0) *. (itof vh)) else constr.PMM_iHeight -> ph in let if px then ftoi (((itof constr.PMM_iPosX) /. 100.0) *. (itof vw)) else constr.PMM_iPosX -> px in let if (ax == 1) then ((vw / 2) - (pw / 2)) + px else if (ax == 2) then (vw - pw) - px else px -> px in let if py then ftoi (((itof constr.PMM_iPosY) /. 100.0) *. (itof vh)) else constr.PMM_iPosY -> py in let if (ay == 1) then ((vh / 2) - (ph / 2)) + py else if (ay == 2) then (vh - ph) - py else py -> py in ( V3DsetViewportPositionSize constr.PMM_viewport ((itof px) /. (itof vw)) ((itof py) /. (itof vh)) ((itof pw) /. (itof vw)) ((itof ph) /. (itof vh)); //if !(V3DgetOrthographicMode constr.PMM_Camera) then nil else // let if constr.PMM_fDistance <. 0.1 then 0.1 else constr.PMM_fDistance -> scale in // let if (ph <= 0) then 1 else ph -> ph in // let ((itof pw) /. (itof ph)) *. scale -> wscale in // SO3CameraSetOrthoWindow constr.PMM_Camera wscale scale; ); ); 0;; fun cbChangeCamera(inst, viewstr, sessionstr, camera, constr)= if (camera != V3DgetDefaultCamera c3dXsession) then nil else ( set constr.PMM_AvCam = V3DgetObjectByName c3dXsession "Current camera"; set constr.PMM_AvShell = V3DgetObjectByName c3dXsession "Current camera shell"; ); 0;; fun newOb(inst)= let atoi (getPluginInstanceParam inst "posx") -> posx in let atoi (getPluginInstanceParam inst "posy") -> posy in let atoi (getPluginInstanceParam inst "width") -> width in let atoi (getPluginInstanceParam inst "height") -> height in let atoi (getPluginInstanceParam inst "xpercent") -> xpercent in let atoi (getPluginInstanceParam inst "ypercent") -> ypercent in let atoi (getPluginInstanceParam inst "wpercent") -> wpercent in let atoi (getPluginInstanceParam inst "hpercent") -> hpercent in let atoi (getPluginInstanceParam inst "xalign") -> xalign in let atoi (getPluginInstanceParam inst "yalign") -> yalign in let atof (getPluginInstanceParam inst "distance") -> distance in let atof (getPluginInstanceParam inst "level") -> level in let atoi (getPluginInstanceParam inst "transparent") -> transparent in let if transparent == nil then 1 else transparent -> transparent in let atoi (getPluginInstanceParam inst "init") -> oninit in let SO3CameraCreate (V3DgetSession c3dXsession) strcat (getPluginInstanceName inst) "_minimap_cam" -> newcam in let V3DaddShell c3dXsession strcat (getPluginInstanceName inst) "_minimap_dummy" nil nil [0.0 0.0 0.0] [0.0 0.0 0.0 1.0] -> shell in let V3DgetObjectByName c3dXsession "Current camera shell" -> avshell in let V3DgetObjectByName c3dXsession "Current camera" -> avcam in let mkPlugMiniMap [inst newcam shell nil avshell avcam nil posx posy width height [xpercent ypercent wpercent hpercent] [xalign yalign] distance level transparent] -> constr in ( //SO3CameraSetProjectionType newcam SO3_PROJECTION_ORTHOGRAPHIC; SO3GroupCreate (V3DgetSession c3dXsession) strcat (getPluginInstanceName inst) "_Group"; V3DaddResource c3dXsession (strcat (getPluginDirectory (getInstancePlugin inst)) "/res/cursor.material") (strcat (getPluginInstanceName inst) "_Group") SO3_RESOURCE_MATERIAL; set constr.PMM_Cursor = SO3SceneLoadEntity (V3DgetSession c3dXsession) (strcat (getPluginInstanceName inst) "_Group") (strcat (getPluginInstanceName inst) "_cursor_mesh") _checkpack (strcat (getPluginDirectory (getInstancePlugin inst)) "/res/cursor.mesh"); SO3ObjectSetVisible constr.PMM_Cursor 0 1; SO3ObjectSetMouseClick constr.PMM_Cursor 0; //SO3EntitySetVisibilityFlags constr.PMM_Cursor 16; if !oninit then nil else cbCreate inst nil nil nil nil constr; setPluginInstanceCbResizeView inst mkfun5 @cbResizeCtrl constr; setPluginInstanceCbCameraChange inst mkfun5 @cbChangeCamera constr; PluginRegisterAction inst "Create" mkfun6 @cbCreate constr; PluginRegisterAction inst "Destroy" mkfun6 @cbDestroy constr; setPluginInstanceCbDel inst mkfun2 @deleteOb constr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;