Jump to content

Recommended Posts

Posted

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
Posted

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
Posted

Does clamp get a proper result when negative values are used?
Since in that case the self.maxZoom would be the smallest value of the 2.
maiby flip them around ?

During optimisation i did at one point use clamp but got a bad result so reverted it back and never looked at it again. :D

Posted

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. 

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.

×
×
  • Create New...