Как сделать, чтобы эта камера (смесь DGUI-системы и камеры на RtC) не проваливалась сквозь землю?
Code
function GameUpdate takes nothing returns nothing local integer mx = GetMouseX() local integer my = GetMouseY() local integer vx = GetWindowWidth()/2 local integer vy = GetWindowHeight()/2
local real tx = GetUnitX(GameUnit) local real ty = GetUnitY(GameUnit) local real tz = 150 local real dex = (tx-550)-GameCamera.Eye.x local real dey = (ty-550)-GameCamera.Eye.y local real dez = tz+100-GameCamera.Eye.z local real X2 = GameCamera.Eye.x+dex//*0.07 local real Y2 = GameCamera.Eye.y+dey//*0.07 local real Z2 = GameCamera.Eye.z+dez//*0.07
set vx = vx - mx set vy = vy - my
set facing = facing + (vx * sens) if(facing > 360) then set facing = facing - 360 endif if(facing < 0) then set facing = facing + 360 endif set aoa = aoa + (vy * sens) if(aoa > 10) then set aoa = 10 endif if(aoa < -30) then set aoa = -30 endif
Ну может поможете сделать так, чтобы камера не проваливалась сквозь землю?
Добавлено (28 Марта 2013, 09:41:25) --------------------------------------------- Хотя бы подскажите, почему не получается сделать ограничение поворота камеры? Здесь всё нормально:
Код
scope CameraControl globals real facing = 90.00 real sens = 0.05 real td = 300.00 real fz = 8000 real aoa = 0.00 real fov = 0.00 real roll = 0.00 real rot = 0.00 real zoff = 0.00 private real x = 0.00 private real y = 0.00 private real z = 0.00 endglobals
private function Actions takes nothing returns nothing local integer mx = GetMouseX() local integer my = GetMouseY() local integer vx = GetWindowWidth()/2 local integer vy = GetWindowHeight()/2 local location l = Location(GetUnitX(center), GetUnitY(center)) set vx = vx - mx set vy = vy - my set x = GetUnitX(center)// + td * Cos(facing * bj_DEGTORAD) set y = GetUnitY(center)// + td * Sin(facing * bj_DEGTORAD) set z = UnitZ + 150 // + td * Cos(aoa * bj_DEGTORAD) //call SetUnitX(target, x) //call SetUnitY(target, y) call SetCameraPosition(x, y) call SetCameraQuickPosition(x, y)
set roll = 0.00 call SetCameraField(CAMERA_FIELD_ROLL, roll, 0 )
set fov = 120.00 call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, fov, 0 )
call SetCameraField(CAMERA_FIELD_FARZ, fz, 0 )
call SetMouseX(GetWindowWidth()/2) //GetWindowWidth is part of WindowAPI call SetMouseY(GetWindowHeight()/2) //GetWindowHeight is part of WindowAPI endfunction
//=========================================================================== public function InitTrig takes nothing returns nothing set gg_trg_CameraControl = CreateTrigger() call TriggerAddAction(gg_trg_CameraControl, function Actions) call TriggerRegisterTimerEvent(gg_trg_CameraControl, 0.01, true) endfunction endscope
А здесь не получается:
Код
globals CAMERA GameCamera = NULL player GamePlayer = null unit GameUnit = null real facing = 90.00 real aoa = 0.00 real sens = 0.005 trigger GameTimer = null constant real GamePeriod = 0.01 endglobals
function GameUpdate takes nothing returns nothing local integer mx = GetMouseX() local integer my = GetMouseY() local integer vx = GetWindowWidth()/2 local integer vy = GetWindowHeight()/2 //===================== local real ang = GetUnitFacing(GameUnit)*bj_DEGTORAD local real tx = GetUnitX(GameUnit) local real ty = GetUnitY(GameUnit) local real tz = GetTerrainZ(tx, ty)+GetUnitDefaultFlyHeight(GameUnit)+150 local real dex = (tx-550*Cos(ang))-GameCamera.Eye.x //(tx-550*Cos(ang))- local real dey = (ty-550*Sin(ang))-GameCamera.Eye.y //(ty-550*Sin(ang))- local real dez = (tz+100)-GameCamera.Eye.z//(tz+100)- local real X2 = GameCamera.Eye.x+(dex*0.07) local real Y2 = GameCamera.Eye.y+(dey*0.07) local real Z2 = GameCamera.Eye.z+(dez*0.07) //===================== set vx = vx - mx set vy = vy - my //===================== set facing = facing + (vx * sens) if(facing > 360) then set facing = facing - 360 endif if(facing < 0) then set facing = facing + 360 endif set aoa = aoa + (vy * sens) if(aoa > 10) then set aoa = 10 endif if(aoa < -30) then set aoa = -30 endif //===================== call SetMouseX(GetWindowWidth()/2) call SetMouseY(GetWindowHeight()/2) call GameCamera.ApplyCameraForPlayer(GamePlayer, false) call GameCamera.SetEyeAndAt(X2, Y2, Z2, tx, ty, tz) call GameCamera.SetYawPitchRoll(facing,aoa,0,false) call ClearTextMessages() call DisplayTextToPlayer(Player(0),0,0," facing:"+R2S(facing)+" aoa:"+R2S(aoa)) endfunction
//=========================================================================== function StartGame takes nothing returns nothing set GameUnit = CreateUnit(GamePlayer, 'Hpal', 0, 0, 0) set GameCamera = CAMERA.New() set GameTimer = CreateTrigger() call TriggerRegisterTimerEvent(GameTimer, GamePeriod, true) call TriggerAddAction(GameTimer, function GameUpdate) call DestroyTimer(GetExpiredTimer()) endfunction
В первом случае всё правильно работает, а во втором переменные facing и aoa ведут себя не так. В первом случае к ним прибавляются целые числа, а во втором десятые, из - за этого камера останавливается только после того, как я прокручу её вверх или вниз на несколько кругов.
Добавлено (28 Марта 2013, 15:47:20) --------------------------------------------- Что я не так делаю?