library AdvancedCameraControl
initializer Init
globals //Settings private real real_ZoomMinDistance = 0.00
//Min Zoom Distance private real real_ZoomMaxDistance = 3000.00
//Max Zoom Distance private real real_ZoomDistance = 1700.00
//Initial Zoom Distance private real real_ZoomDistanceChange = 256.00
//Step per wheel scroll step private real real_AoA = 304.00
//Initial Angle private real real_Rot = 90.00
//Initial Direction //System private constant trigger trig_OnMouseLeftDown = CreateTrigger
() private constant trigger trig_OnMouseLeftUp = CreateTrigger
() private constant trigger trig_OnMouseRightDown = CreateTrigger
() private constant trigger trig_OnMouseRightUp = CreateTrigger
() private boolean bool_MouseLeftState =
false private boolean bool_MouseRightState =
false private constant trigger trig_OnMouseWheel = CreateTrigger
() private constant trigger trig_AoAControl = CreateTrigger
() private boolean bool_AoAChanging =
false private integer int_AoAOffsetY = GetMouseY
() private integer int_AoAOffsetX = GetMouseX
() endglobals //=== Set Left Mouse Button Down State private function OnMouseLeftDown
takes nothing returns nothing set bool_MouseLeftState =
true endfunction //=== Set Left Mouse Button Up State private function OnMouseLeftUp
takes nothing returns nothing set bool_MouseLeftState =
false set bool_AoAChanging =
false endfunction //=== Set Right Mouse Button Down State private function OnMouseRightDown
takes nothing returns nothing set bool_MouseRightState =
true endfunction //=== Set Right Mouse Button Up State private function OnMouseRightUp
takes nothing returns nothing set bool_MouseRightState =
false set bool_AoAChanging =
false endfunction function GetMouseLeftState
takes nothing returns boolean return bool_MouseLeftState
endfunction function GetMouseRightState
takes nothing returns boolean return bool_MouseRightState
endfunction private function AoAControl
takes nothing returns nothing local boolean b = GetMouseRightState
() and GetMouseLeftState
() if(b
) then set bool_AoAChanging =
true set int_AoAOffsetY = GetMouseY
() set int_AoAOffsetX = GetMouseX
() endif endfunction //=== Zooming private function OnMouseWheel
takes nothing returns nothing local integer WheelDelta = GetTriggerWheelDelta
() local real zoomchange = real_ZoomDistanceChange *
(ISignBJ
(WheelDelta
) * -1
) set real_ZoomDistance = real_ZoomDistance + zoomchange
if(real_ZoomDistance < real_ZoomMinDistance
) then set real_ZoomDistance = real_ZoomMinDistance
endif if(real_ZoomDistance > real_ZoomMaxDistance
) then set real_ZoomDistance = real_ZoomMaxDistance
endif endfunction function CameraControl
takes nothing returns nothing local real offset = 0
call SetCameraField
(CAMERA_FIELD_TARGET_DISTANCE, real_ZoomDistance, 1.00
) if(bool_AoAChanging
) then set offset =
(int_AoAOffsetY - GetMouseY
()) set real_AoA = real_AoA + offset
set int_AoAOffsetY = GetMouseY
() endif if(real_AoA > 350
) then set real_AoA = 350
endif if(real_AoA < 270
) then set real_AoA = 270
endif call SetCameraField
(CAMERA_FIELD_ANGLE_OF_ATTACK, real_AoA, 0.00
) if(bool_AoAChanging
) then set offset =
(int_AoAOffsetX - GetMouseX
()) set real_Rot = real_Rot + offset
set int_AoAOffsetX = GetMouseX
() endif if(real_Rot > 360
) then set real_Rot = real_Rot - 360
endif if(real_Rot < 0
) then set real_Rot = real_Rot + 360
endif call SetCameraField
(CAMERA_FIELD_ROTATION, real_Rot, 0.00
) endfunction private function Init
takes nothing returns nothing local trigger t = CreateTrigger
() call TriggerRegisterTimerEvent
(t, 0.01,
true) call TriggerAddAction
(t,
function CameraControl
) call TriggerRegisterMouseEvent
(trig_OnMouseLeftDown, EVENT_LMOUSEDOWN
) call TriggerAddAction
(trig_OnMouseLeftDown,
function OnMouseLeftDown
) call TriggerRegisterMouseEvent
(trig_OnMouseLeftUp, EVENT_LMOUSEUP
) call TriggerAddAction
(trig_OnMouseLeftUp,
function OnMouseLeftUp
) call TriggerRegisterMouseEvent
(trig_OnMouseRightDown, EVENT_RMOUSEDOWN
) call TriggerAddAction
(trig_OnMouseRightDown,
function OnMouseRightDown
) call TriggerRegisterMouseEvent
(trig_OnMouseRightUp, EVENT_RMOUSEUP
) call TriggerAddAction
(trig_OnMouseRightUp,
function OnMouseRightUp
) call TriggerRegisterMouseEvent
(trig_OnMouseWheel, EVENT_MOUSEWHEEL
) call TriggerAddAction
(trig_OnMouseWheel,
function OnMouseWheel
) call TriggerRegisterMouseEvent
(trig_AoAControl, EVENT_LMOUSEDOWN
) call TriggerRegisterMouseEvent
(trig_AoAControl, EVENT_RMOUSEDOWN
) call TriggerAddAction
(trig_AoAControl,
function AoAControl
) endfunctionendlibrary