Lua脚本实现界面-自定义的控制键

在易景地球上实现按钮等效果
lua代码如下:

=========================================================
--创建一个基本大小的框
ctrl = evGUI.Create("Base", evGUIRoot)
ctrl:SetSize(240,64)

evGUIRoot:AddEvent("onFrame",function ( )
             --ctrl:AlignBottom()
   
         ctrl:SetPos( ctrl.Bounds.x , evGUIRoot.Bounds.h - ctrl.Bounds.h - 20);
             ctrl:AlignCenterH()
end)

function createBtn(href, szx,szy, x,y, tp,onclick)
      local   btn = evGUI.Create("Button",ctrl)
    btn.Background=false
    btn:SetImage(href,true)
    btn:SetSize(szx,szy)
    btn:SetPos(x,y)
        btn.Tooltip = tp
    btn:AddEvent("onPress",onclick)
    return btn;
end





local cam = evControl.CameraControl



left = 10
top = 0
createBtn("D:\\data\\图标\\view-pan-64x64.png",64,64, left,top, '平移', function(obj)
    lon = cam:GetLongitude()
    lat = cam:GetLatitude()
    alt = cam:GetAltitude()
    head = cam:GetHeading()
    tilt = cam:GetTilt()
     
  --判断落在哪个区域
   local mp = evGUI.MousePosition()

  local cx = mp.x - obj.Bounds.x - 32 - ctrl.Bounds.x
  local cy = mp.y- obj.Bounds.y -32 - ctrl.Bounds.y

     evprint(cx,cy)
   
      evCamInner:Slip(cx * 1.0 / 32)
      evCamInner:Walk(cy * 1.0 / 32)
      
   
end
)

left  = left+ 64 + 4

createBtn("D:\\data\\图标\\view-zoom-in-32x32.png",32, 32,left, top,  '前进', function(obj)
    evCamInner:Walk(1)
end
)

createBtn("D:\\data\\图标\\view-zoom-out-32x32.png",32,32, left, top + 32,'后退',  function(obj)
      evCamInner:Walk(-1)
end
)


left  = left+ 32 + 4

createBtn("D:\\data\\图标\\view-heading-left-32x32.png",32,32, left, top, '左转', function(obj)

      lon = cam:GetLongitude()
    lat = cam:GetLatitude()
    alt = cam:GetAltitude()
    head = cam:GetHeading()
    tilt = cam:GetTilt()
     
    --左转
    head = head  - 10
     cam:SetDirection(tilt,head)

end
)

createBtn("D:\\data\\图标\\view-heading-right-32x32.png",32,32, left, top + 32, '右转', function(obj)

  lon = cam:GetLongitude()
    lat = cam:GetLatitude()
    alt = cam:GetAltitude()
    head = cam:GetHeading()
    tilt = cam:GetTilt()
     
    --左转
    head = head  + 10
     cam:SetDirection(tilt,head)

end
)

left  = left+ 32 + 4

createBtn("D:\\data\\图标\\view-pitch-up-32x32.png",32,32, left, top, '抬头', function(obj)

  lon = cam:GetLongitude()
    lat = cam:GetLatitude()
    alt = cam:GetAltitude()
    head = cam:GetHeading()
    tilt = cam:GetTilt()
     
    --左转
    tilt = tilt  + 10
     cam:SetDirection(tilt,head)


end
)

createBtn("D:\\data\\图标\\view-pitch-down-32x32.png",32, 32,left, top + 32, '低头', function(obj)

lon = cam:GetLongitude()
    lat = cam:GetLatitude()
    alt = cam:GetAltitude()
    head = cam:GetHeading()
    tilt = cam:GetTilt()
     
    --左转
    tilt = tilt  - 10
     cam:SetDirection(tilt,head)

end
)

left  = left+ 32 + 4

createBtn("D:\\data\\图标\\view-elevation-up-32x32.png",32,32, left, top, '抬升', function(obj)

     lon = cam:GetLongitude()
    lat = cam:GetLatitude()
    alt = cam:GetAltitude()
    head = cam:GetHeading()
    tilt = cam:GetTilt()
     
    --抬升
    alt = alt * 1.2
     cam:FlyToDirect(lon, lat, alt, 0.5)

end
)

createBtn("D:\\data\\图标\\view-elevation-down-32x32.png",32, 32,left, top + 32,'降低', function(obj)
  
     lon = cam:GetLongitude()
    lat = cam:GetLatitude()
    alt = cam:GetAltitude()
    head = cam:GetHeading()
    tilt = cam:GetTilt()
     
    --降低
    alt = alt * 0.8
     cam:FlyToDirect(lon, lat, alt, 0.5)

end
)

======================================================

实现的效果如下图:



红框显示为按钮的效果




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值