From aad80b73fd69ae2fb9d3fcded4235c217f7d2cac Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sun, 8 Dec 2013 19:22:21 -0600 Subject: [PATCH] Made ViewController's launch animation to add current view's position to center point. Fixed clipping with a scaled camera matrix. --- src/views/ViewController.cpp | 18 ++++++++++-------- src/views/ViewController.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/views/ViewController.cpp b/src/views/ViewController.cpp index 526a6e018..84444885f 100644 --- a/src/views/ViewController.cpp +++ b/src/views/ViewController.cpp @@ -87,7 +87,7 @@ void ViewController::onFileChanged(FileData* file, FileChangeType change) } } -void ViewController::launch(FileData* game, const Eigen::Vector3f& center) +void ViewController::launch(FileData* game, Eigen::Vector3f center) { if(game->getType() != GAME) { @@ -99,6 +99,7 @@ void ViewController::launch(FileData* game, const Eigen::Vector3f& center) game->getSystem()->getTheme()->playSound("gameSelectSound"); Eigen::Affine3f origCamera = mCamera; + center += mCurrentView->getPosition(); setAnimation(new LaunchAnimation(mCamera, mFadeOpacity, center, 1500), [this, origCamera, center, game] { game->getSystem()->launchGame(mWindow, game); @@ -175,18 +176,19 @@ void ViewController::render(const Eigen::Affine3f& parentTrans) { Eigen::Affine3f trans = mCamera * parentTrans; + // camera position, position + size + Eigen::Vector3f viewStart = trans.inverse().translation(); + Eigen::Vector3f viewEnd = trans.inverse() * Eigen::Vector3f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight(), 0); + // draw systems for(auto it = mSystemViews.begin(); it != mSystemViews.end(); it++) { // clipping - Eigen::Vector3f pos = it->second->getPosition(); - Eigen::Vector2f size = it->second->getSize(); + Eigen::Vector3f guiStart = it->second->getPosition(); + Eigen::Vector3f guiEnd = it->second->getPosition() + Eigen::Vector3f(it->second->getSize().x(), it->second->getSize().y(), 0); - Eigen::Vector3f camPos = -trans.translation(); - Eigen::Vector2f camSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); - - if(pos.x() + size.x() >= camPos.x() && pos.y() + size.y() >= camPos.y() && - pos.x() <= camPos.x() + camSize.x() && pos.y() <= camPos.y() + camSize.y()) + if(guiEnd.x() >= viewStart.x() && guiEnd.y() >= viewStart.y() && + guiStart.x() <= viewEnd.x() && guiStart.y() <= viewEnd.y()) it->second->render(trans); } diff --git a/src/views/ViewController.h b/src/views/ViewController.h index 33b109a56..45a5bb49f 100644 --- a/src/views/ViewController.h +++ b/src/views/ViewController.h @@ -19,7 +19,7 @@ public: // Plays a nice launch effect and launches the game at the end of it. // Once the game terminates, plays a return effect. - void launch(FileData* game, const Eigen::Vector3f& centerCameraOn = Eigen::Vector3f(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0)); + void launch(FileData* game, Eigen::Vector3f centerCameraOn = Eigen::Vector3f(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0)); bool input(InputConfig* config, Input input) override; void update(int deltaTime) override;