Jump to content

Limits wheel mouse Move Camera?


Yue
 Share

Go to solution Solved by havenphillip,

Recommended Posts

        self.GetWheelMouse = self.window:GetMousePosition().z

            if self.GetWheelMouse ~= self.sWheel then 
                    
                
                    self.sWheel = self.window:GetMousePosition().z -3.0
            
                
                self.pivotCamera:SetPosition(0,0,self.sWheel,false )
    
            end

I'm trying to implement a limit by zooming the camera in and out with the mouse wheel, but my logic doesn't work. 

Any suggestions?
 

 

 

Link to comment
Share on other sites

5 minutes ago, havenphillip said:

Puede probar Math: Clamp (número para sujetar, zoom mínimo, zoom máximo)

https://www.leadwerks.com/learn?page=API-Reference_Object_Math_Clamp

Thanks for the information, but that doesn't have an example. I can deduce that it sets a number as a minimum and a maximum, but I have no idea how to implement it, the translator does not help much without an example. 
 

 

 

Link to comment
Share on other sites

On 10/24/2019 at 12:32 PM, ?Yue? said:

Thanks for the information, but that doesn't have an example. I can deduce that it sets a number as a minimum and a maximum, but I have no idea how to implement it, the translator does not help much without an example. 
 

In your code you will want to "clamp" the self.sWheel variable.

Math:Clamp(self.sWheel,0,30)

You will need to alter the 0 to whatever minimum value you wish to set your zoom to.

The 30 value will be your maximum zoom value.

  • Like 2
Link to comment
Share on other sites

You know what I just assumed there was something like a "mouse.back." I made it up as a dummy command because I thought you already had something there.

I sort of got it working from this post. I've never bothered with the mouse wheel:
 

This sort of works:

function Script:UpdateWorld()

    self.maxZoom = 10
    self.minZoom = 0

    local oldWheelPos = 0.0
    if self.currentMousePos ~= nil then
        oldWheelPos = self.currentMousePos.z
    end

    self.currentMousePos = window:GetMousePosition()
    self.currentMousePos.x = Math:Round(self.currentMousePos.x)
    self.currentMousePos.y = Math:Round(self.currentMousePos.y)

    local newWheelPos = (self.currentMousePos.z - oldWheelPos) * 0.1
    if newWheelPos > 0.0 or newWheelPos < 0.0 then
        self.curZoom = oldWheelPos + newWheelPos
        self.camera:Move(0,0,self.curZoom)

        self.curZoom = Math:Clamp(self.curZoom, self.minZoom, self.maxZoom) -- limits the zoom to stay between min and max zoom
    end

  • Like 2
Link to comment
Share on other sites

			function this:ZoomCamera()


					self.wheel = self.window:GetMousePosition().z

					if self.wheel ~= self.sWheel then 
							
						
							self.sWheel =  self.window:GetMousePosition().z
					
						
						
			
					end
				
			self.pivotCamera:SetPosition(0,0,self.sWheel,false )

				
			end

I only have this, I've tried several things with Clamp, but it doesn't work. Sometimes it jumps and stays in some limit, and doesn't come back.

 

 

Link to comment
Share on other sites

This is the closest, but it turns out that if you continued to turn the wheel of the mouse when you reach the limit, continues to gain value, then when I want to go forward it takes quite some time, because the value of the wheel continues to increase beyond the limit established with Clamp.

 

self.pivotCamera:SetPosition(0,0,Math:Clamp(self.sWheel,0,10),false )

 

 

 

Link to comment
Share on other sites

  • Solution

This appears to be doing it. It's limiting the zoom but the wheel is cumulative I don't know how to fix that. Once you reach the limit, if you keep rolling the wheel it keeps counting it...

 

Script.minZoom = 0
Script.maxZoom = 30
Script.curZoom = 0


function Script:Zoom()

    local oldWheelPos = 0.0

    if self.currentMousePos ~= nil then
        oldWheelPos = self.currentMousePos.z
    end

    self.currentMousePos = window:GetMousePosition()
    self.currentMousePos.x = Math:Round(self.currentMousePos.x)
    self.currentMousePos.y = Math:Round(self.currentMousePos.y)

    local newWheelPos = (self.currentMousePos.z - oldWheelPos)
    if oldWheelPos < 0.0 then
        self.entity:Move(0,0,self.curZoom)
        self.curZoom = 0 - newWheelPos
        System:Print("Zoom in")
        if self.currentMousePos.z < self.minZoom then --limits max in zoom
            self.curZoom = 0
        end
    elseif oldWheelPos > 0.0 then
        self.entity:Move(0,0,-self.curZoom)
        self.curZoom = 0 + newWheelPos
        System:Print("Zoom out")
        if self.currentMousePos.z > self.maxZoom then -- limits max out zoom
            self.curZoom = 0
        end
    end
end

  • Thanks 1
Link to comment
Share on other sites

On 10/29/2019 at 7:53 AM, havenphillip said:

This appears to be doing it. It's limiting the zoom but the wheel is cumulative I don't know how to fix that. Once you reach the limit, if you keep rolling the wheel it keeps counting it...

 

Script.minZoom = 0
Script.maxZoom = 30
Script.curZoom = 0


function Script:Zoom()

    local oldWheelPos = 0.0

    if self.currentMousePos ~= nil then
        oldWheelPos = self.currentMousePos.z
    end

    self.currentMousePos = window:GetMousePosition()
    self.currentMousePos.x = Math:Round(self.currentMousePos.x)
    self.currentMousePos.y = Math:Round(self.currentMousePos.y)

    local newWheelPos = (self.currentMousePos.z - oldWheelPos)
    if oldWheelPos < 0.0 then
        self.entity:Move(0,0,self.curZoom)
        self.curZoom = 0 - newWheelPos
        System:Print("Zoom in")
        if self.currentMousePos.z < self.minZoom then --limits max in zoom
            self.curZoom = 0
        end
    elseif oldWheelPos > 0.0 then
        self.entity:Move(0,0,-self.curZoom)
        self.curZoom = 0 + newWheelPos
        System:Print("Zoom out")
        if self.currentMousePos.z > self.maxZoom then -- limits max out zoom
            self.curZoom = 0
        end
    end
end

Thanks, I've managed to get my own script here. Always something new to learn from more advanced users like you.  Thank you very much. :D

			function this:ZoomCamera()


				self.w = self.window:GetMousePosition().z
			
				
				if self.w ~=  self.sW then



					if self.w > 0 then

						self.pC = self.pC  -1 

						if self.pC < -10 then
							self.pC = -10
						end


					end
					if self.w < 1 then
						self.pC = self.pC  +1 

						if self.pC > 0 then
							self.pC = 0
						end
				
					end


				

					self.w = self.window:FlushMouse()
				end
				
				self.pivotCamera:SetPosition(0,0,self.pC-3,false)	
						
			
			
				
			end

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...