• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Camera Zoom Limits with Mouse Wheel Scrolling

Status
Not open for further replies.
Level 9
Joined
Sep 11, 2020
Messages
52
Does anyone know if it's possible to adjust the range of camera 'distance from target' that you get by scrolling the mouse wheel in-game? It seems to be set to a minimum of around 1200 and a maximum of 1650 by default.

I want to have the minimum remain the same while raising the maximum to something like 2500. A flat increase in camera distance will therefore not work, because it will change the minimum value as well. Any suggestions?
 
Level 19
Joined
Aug 16, 2007
Messages
881
It's probably only doable with triggers; but the only way to detect a mouse wheel scroll event is by using the frame natives. I made a script below that allows you to adjust the camera distance between 1200 and 2500 with the scroll wheel; but it'll never work in normal gameplay. The reason is that the created frame to detect a scroll wheel event almost cover the entire screen and blocks normal mouse clicks, etc.

JASS:
scope CameraScrollDistance initializer onInit
  globals
    // Config
    // Default camera distance value
    private constant real CAMERA_DISTANCE_DEFAULT = 1650.0
    // Time to set the new camera distance value.
    private constant real CAMERA_UPDATE_DURATION = 1.0
    // Default camera zoom value is set at 120/-120 (see BlzGetTriggerFrameValue() below).
    // This multiplier will increase/decrease the amount of camera distance on scroll.
    private constant real CAMERA_DISTANCE_MULTIPLIER = 1.0
    // Min/Max Camera distance values
    private constant real CAMERA_DISTANCE_MIN = 1200.0
    private constant real CAMERA_DISTANCE_MAX = 2500.0
 
    // System Variables
    private real array CSDPlayerCameraDistance
  endglobals

  private function Clamp takes real r, real min, real max returns real
    if (r < min) then
      return min
    elseif (r > max) then
      return max
    endif
    return r
  endfunction

  private function OnMouseWheelScroll takes nothing returns boolean
    local integer playerIndex = GetPlayerId(GetTriggerPlayer())
    // BlzGetTriggerFrameValue() returns +120.0 on scroll up and -120.0 on scroll down
    set CSDPlayerCameraDistance[playerIndex] = Clamp(CSDPlayerCameraDistance[playerIndex] - (BlzGetTriggerFrameValue() * CAMERA_DISTANCE_MULTIPLIER), CAMERA_DISTANCE_MIN, CAMERA_DISTANCE_MAX)
    if (GetLocalPlayer() == GetTriggerPlayer()) then
      // Use only local code (no net traffic) within this block to avoid desyncs.
      call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, CSDPlayerCameraDistance[playerIndex], CAMERA_UPDATE_DURATION)
    endif
    return false
  endfunction

  private function onInit takes nothing returns nothing
    local integer i = 0
    local trigger t = CreateTrigger()
    local framehandle fh1 = BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0)
    local framehandle fh2 = BlzCreateFrameByType("TEXT", "frameScrollArea", fh1, "", 0)
    call BlzFrameSetAllPoints(fh2, fh1)
  
    call BlzTriggerRegisterFrameEvent(t, fh2, FRAMEEVENT_MOUSE_WHEEL)
    call TriggerAddCondition(t, Filter(function OnMouseWheelScroll))
  
    loop
      set CSDPlayerCameraDistance[i] = CAMERA_DISTANCE_DEFAULT
      set i = i + 1
      exitwhen (i >= bj_MAX_PLAYERS)
    endloop
  
    set t = null
    set fh1 = null
    set fh2 = null
  endfunction
endscope
Maybe someone can expand on the script and solve the problems as I'm not sure how to proceed from here.
  • The frame must ignore mouse clicks, etc, but not the scroll wheel.
  • The frame should cover the entire screen (currently the widescreen area is unaffected).
 
Level 9
Joined
Sep 11, 2020
Messages
52
Thanks for taking the time to work on this. I only know GUI, but in terms of detecting mouse wheel scrolling, what about looking for changes in the camera's distance? Is there a way to get that as an event?

This will probably lead to imprecision, but you could have a periodic event with a 0.01 sec interval that's constantly saving the current camera distance value and then comparing it with the camera distance after 0.01 sec.
 
Status
Not open for further replies.
Top