Jump to content

Mouse Scroll


M0lD
 Share

Recommended Posts

FYI the z index of mouseposition is cumulative.

To get proper values you could do something like:

	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 = self.curZoom + newWheelPos
		if self.curZoom < self.maxZoom then
			self.curZoom = self.maxZoom
		elseif self.curZoom > self.minZoom then
			self.curZoom = self.minZoom
		end
	end

 

  • Like 2
Link to comment
Share on other sites

Nice script GorzenDev. That would be a nice addition to the documentation samples.

Little side note:

if self.curZoom < self.maxZoom then
    self.curZoom = self.maxZoom
elseif self.curZoom > self.minZoom then
    self.curZoom = self.minZoom
end


could be shortened to

self.curZoom = Math:Clamp(self.curZoom, self.maxZoom, self.minZoom)

 

  • Like 1
Link to comment
Share on other sites

I have a similar situation with camera min/max angles where this works fine. For camera rotation the max angle is actually negative (although the name would suggest otherwise). Based on your if statements and the inversed use of max/min zoom, I figured that for the zooming something similar would be happening. 

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...