/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
#include "twp/twp.h"
#include "twp/object.h"
#include "twp/room.h"
namespace Twp {
void Camera::clamp(const Math::Vector2d &at) {
if (_room) {
Math::Vector2d roomSize = _room->_roomSize;
Math::Vector2d screenSize = _room->getScreenSize();
// fix assertion when screen size is greater than room height
if (screenSize.getY() > roomSize.getY()) {
screenSize.setY(roomSize.getY());
}
_pos.setX(CLIP(at.getX(), screenSize.getX() / 2.f + _bounds.left(), screenSize.getX() / 2 + _bounds.right()));
_pos.setY(CLIP(at.getY(), _bounds.bottom(), _bounds.top() - screenSize.getY() / 2));
_pos.setX(CLIP(_pos.getX(), screenSize.getX() / 2.f, MAX(roomSize.getX() - screenSize.getX() / 2.f, 0.f)));
_pos.setY(CLIP(_pos.getY(), screenSize.getY() / 2, MAX(roomSize.getY() - screenSize.getY() / 2, 0.f)));
}
}
void Camera::setAtCore(const Math::Vector2d &at) {
Math::Vector2d screenSize = _room->getScreenSize();
_pos = at;
clamp(_pos);
g_twp->getGfx().cameraPos(_pos - screenSize / 2.f);
}
void Camera::setAt(const Math::Vector2d &at) {
setAtCore(at);
_target = _pos;
_time = 0;
_moving = false;
}
void Camera::panTo(const Math::Vector2d &target, float time, InterpolationKind interpolation) {
if (!_moving) {
_moving = true;
_init = _pos;
_elapsed = 0.f;
}
_function = easing(interpolation);
_target = target;
_time = time;
}
void Camera::update(Common::SharedPtr room, Common::SharedPtr