[Solved] Help Scaling (mouse origin)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[Solved] Help Scaling (mouse origin)
I'm trying to zoom in/out on a set of points - A Good Example, without using any graphics.* functions. I've got close - I can zoom in and out with the mouse acting as the origin of the scaling, but if I move the mouse to another location and try scaling there - it breaks. I've attached what I have so far - the main.lua file has the scaling code. Any help would be greatly appreciated - I've been chasing my tail all day, need to take a break
- Attachments
-
- PoissonDiskSampler.love
- (5.12 KiB) Downloaded 64 times
Last edited by SelfDotX on Wed Oct 12, 2022 10:51 am, edited 1 time in total.
Re: Help Scaling (mouse origin)
What do you mean without any graphics.* functions? Without love.graphics.* you can't output anything to the screen. Unless you mean something else?SelfDotX wrote: ↑Tue Oct 11, 2022 7:35 pm I'm trying to zoom in/out on a set of points - A Good Example, without using any graphics.* functions...
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Re: Help Scaling (mouse origin)
Without using graphics.transform or scale - I'm transforming data - points, displaying it is not a requirement. Put another way, I need the math behind it, not an api to do it for me.
Re: Help Scaling (mouse origin)
You have to use the last scale value to calculate the difference between the old and new scale origins for the new offset. Here's an updated drawOffscreen() and love.wheelmoved():
Code: Select all
local panX, panY = 0, 0
local function drawOffscreen()
local settings = PDS.GetSettings()
love.graphics.setCanvas(oScreen)
love.graphics.clear()
love.graphics.setColor(1, 0, 1, 1)
love.graphics.line(panX*scale,0, panX*scale,600) -- Updated.
love.graphics.line(0,panY*scale, 800,panY*scale) -- Updated.
for _, pos in ipairs(points) do
if pos.c then
love.graphics.setColor(1, 1, 1, 1)
end
love.graphics.points((pos.x+panX)*scale, (pos.y+panY)*scale) -- Updated.
love.graphics.setColor(1, 0, 1, 1)
end
love.graphics.setColor(1, 1, 1, 1)
love.graphics.print(
" Attempts/Sample " .. tostring(settings.maxAttemptsPerSample) ..
"\n" .. " minRadius " .. tostring(settings.minRadius) ..
"\n" .. " maxRadius " .. tostring(settings.maxRadius) ..
"\n" .. " stepRadius " .. tostring(settings.stepRadius) ..
"\n" .. " spawnRadFac " .. tostring(settings.spawnRadiusFactor) ..
"\n" .. " spawnType " .. tostring(settings.spawnType) ..
"\n" .. " scale " .. tostring(scale)
)
love.graphics.print(
" Attempts/Sample " .. tostring(settings.maxAttemptsPerSample) ..
"\n" .. " minRadius " .. tostring(settings.minRadius) ..
"\n" .. " maxRadius " .. tostring(settings.maxRadius) ..
"\n" .. " stepRadius " .. tostring(settings.stepRadius) ..
"\n" .. " spawnRadFac " .. tostring(settings.spawnRadiusFactor) ..
"\n" .. " spawnType " .. tostring(settings.spawnType) ..
"\n" .. " scale " .. tostring(scale)
)
love.graphics.setCanvas()
end
function love.wheelmoved(dx, dy)
local mX, mY = love.mouse.getPosition()
local oldMx = mX / scale -- Use old scale.
local oldMy = mY / scale
scale = scale * 1.3^dy -- Exponential zoom feels more natural.
local newMx = mX / scale -- Use new scale.
local newMy = mY / scale
panX = panX - oldMx + newMx -- Add to the old pan values.
panY = panY - oldMy + newMy
print(tonumber(string.format("%.1f", scale)))
drawOffscreen()
end
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
Re: Help Scaling (mouse origin)
Thank you again Refreezed. Part of my frustration was that I knew the math was dead simple - I just couldn't put the pieces together. Anyway, at least I can start my day off on the right foot - really appreciate that!
Re: [Solved] Help Scaling (mouse origin)
I know what you mean. I remember when I initially tried to figure out this very problem in one program. It took longer than it really should have.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
Who is online
Users browsing this forum: Google [Bot], Semrush [Bot] and 15 guests