feature/animateTo #21

Merged
PeaAshMeter merged 5 commits from feature/animateTo into main 2025-11-11 17:45:16 +03:00
2 changed files with 21 additions and 4 deletions
Showing only changes of commit 331aefb0f6 - Show all commits

View File

@ -9,6 +9,9 @@ local EPSILON = 0.001
--- @field speed number
--- @field pixelsPerMeter integer
--- @field scale number
--- @field animationNode AnimationNode?
--- @field animationEndPosition Vec3
--- @field animationBeginPosition Vec3
local camera = {
position = Vec3 {},
velocity = Vec3 {},
@ -41,6 +44,12 @@ local controlMap = {
}
function camera:update(dt)
if self.animationNode and not (self.animationNode.t >= 1) then
self.animationNode:update(dt) -- тик анимации
self.position = utils.lerp(self.animationBeginPosition, self.animationEndPosition, self.animationNode:getValue())
return
end
local ps = Tree.panning
if ps.delta:length() > 0 then
local worldDelta = ps.delta:scale(1 / (self.pixelsPerMeter * self.scale)):scale(dt):scale(self.speed)
@ -88,8 +97,12 @@ function camera:detach()
end
--- @param position Vec3
function camera:animateTo(position)
self.position = position
--- @param animationNode AnimationNode
function camera:animateTo(position, animationNode)
if self.animationNode then self.animationNode:finish() end
self.animationNode = animationNode
self.animationEndPosition = position
self.animationBeginPosition = self.position
end
--- @return Camera

View File

@ -40,11 +40,15 @@ function love.update(dt)
Tree.level.turnOrder:toggleTurns()
end
-- для тестов camera:attachTo
-- для тестов camera:animateTo
-- удалить как только потребность в тестах исчезнет
if Tree.controls:isJustPressed("cameraAnimateTo") then
local mousePosition = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() })
Tree.level.camera:animateTo(mousePosition)
require('lib.animation_node') {
function(animationNode) Tree.level.camera:animateTo(mousePosition, animationNode) end,
onEnd = function() print('completed') end,
easing = require("lib.utils.easing").easeInOutCubic
}:run()
end
Tree.controls:cache()