Skip to content

Commit

Permalink
Merge pull request #24 from pjanck/transitionDuration
Browse files Browse the repository at this point in the history
allowed for the duration of the camera transition to be specified
  • Loading branch information
pjanck authored Feb 20, 2021
2 parents ca91e7f + 8fe4470 commit 9e89e5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 10 additions & 6 deletions Engine/src/BlueFramework/Engine/Camera/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,14 @@ void CameraController::tick(const float delta) {
}

void CameraController::setViewDirection(const buw::Vector3f &dir) {
setViewDirection(dir, 0.5f);
}

void CameraController::setViewDirection(const buw::Vector3f &dir, const float duration) {
auto target = camera_->transformation();
target.setViewDirection(dir);

startInterpolation(0.5f, target);
startInterpolation(duration, target);
}

buw::Vector3f CameraController::getViewDirectionVector(const buw::eViewDirection &direction) {
Expand All @@ -521,20 +525,20 @@ buw::Vector3f CameraController::getViewDirectionVector(const buw::eViewDirection
}


void CameraController::fitToView(const buw::Vector3f &min, const buw::Vector3f &max) {
void CameraController::fitToView(const buw::Vector3f &min, const buw::Vector3f &max, const float duration /*= 1.0f*/) {
CameraTransformation target = camera_->transformation();
target.fitToView(min, max, camera_->frustum().fieldOfView());

state_ = eState::Orbiting;
startInterpolation(1, target);
startInterpolation(duration, target);
}

void CameraController::lookAt(const buw::Vector3f &target, const buw::Vector3f &origin) {
void CameraController::lookAt(const buw::Vector3f &target, const buw::Vector3f &origin, const float duration /*= 1.0f*/) {
CameraTransformation targetTransformation = camera_->transformation();
targetTransformation.lookAt(target, origin);

state_ = eState::Orbiting;
startInterpolation(1, targetTransformation);
startInterpolation(duration, targetTransformation);
}

void CameraController::startInterpolation(float duration, const CameraTransformation &target) {
Expand Down Expand Up @@ -587,4 +591,4 @@ const bool CameraController::isCameraMoving() const {
return camera_->velocity().length() > 0.0f;
}

BLUEFRAMEWORK_ENGINE_NAMESPACE_END
BLUEFRAMEWORK_ENGINE_NAMESPACE_END
5 changes: 3 additions & 2 deletions Engine/src/BlueFramework/Engine/Camera/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ class CameraController {
void tick(const float delta);

void setViewDirection(const buw::Vector3f &dir);
void setViewDirection(const buw::Vector3f &dir, const float duration);

void fitToView(const buw::Vector3f &min, const buw::Vector3f &max);
void lookAt(const buw::Vector3f &target, const buw::Vector3f &origin);
void fitToView(const buw::Vector3f &min, const buw::Vector3f &max, const float duration = 1.0f);
void lookAt(const buw::Vector3f &target, const buw::Vector3f &origin, const float duration = 1.0f);

void handleKeyDown(eKey key);
void handleKeyUp(eKey key);
Expand Down

0 comments on commit 9e89e5e

Please sign in to comment.