diff --git a/data b/data index 11f999a..ce902f8 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 11f999abf6d47962610f6c9696a8d4d4ee2a1bcb +Subproject commit ce902f8e1c8ad4b204689711ea9bdb3fe7f3b585 diff --git a/src/application.cpp b/src/application.cpp index a83c558..fa1c0e8 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -1169,6 +1169,10 @@ bool Application::loadUI() tweener->addTween(previewLevelTweens[i]); } + // Tool tweens + forcepsSwoopTween = new Tween(EaseFunction::OUT_CUBIC, 0.0f, 1.0f, 0.0f, 0.5f); + tweener->addTween(forcepsSwoopTween); + // Build menu system selectedMenuItemIndex = 0; mainMenu = new Menu(); diff --git a/src/application.hpp b/src/application.hpp index 49e007b..47f1d44 100644 --- a/src/application.hpp +++ b/src/application.hpp @@ -340,6 +340,7 @@ public: Tween* cameraTranslationTween; Tween* previewLevelTweens[5]; + Tween* forcepsSwoopTween; // Menus std::size_t menuCount; diff --git a/src/game/ant.cpp b/src/game/ant.cpp index 06a5367..fc60e93 100644 --- a/src/game/ant.cpp +++ b/src/game/ant.cpp @@ -20,6 +20,12 @@ #include "ant.hpp" #include "colony.hpp" #include "pheromone.hpp" +#include + +inline float fwrap(float angle, float limit) +{ + return angle - std::floor(angle / limit) * limit; +} Ant::Ant(Colony* colony): colony(colony), @@ -37,7 +43,7 @@ Ant::Ant(Colony* colony): modelInstance.setModel(colony->getAntModel()); modelInstance.setPose(pose); - animationTime = 0.0f; + animationTime = frand(0.0f, 60.0f); } Ant::~Ant() @@ -61,7 +67,7 @@ void Ant::rotateHead() } */ - const Animation* animation = pose->getSkeleton()->getAnimation("eat"); + const Animation* animation = pose->getSkeleton()->getAnimation("tripod-gait"); if (animation != nullptr) { for (std::size_t i = 0; i < animation->getChannelCount(); ++i) @@ -75,11 +81,13 @@ void Ant::rotateHead() } pose->concatenate(); - animationTime += 0.5f; + animationTime = fwrap(animationTime + 2.0f, animation->getEndTime()); + + /* if (animationTime > animation->getEndTime()) { animationTime = animation->getStartTime(); - } + }*/ } } @@ -119,6 +127,8 @@ void Ant::update(float dt) float probeLateralOffset = 0.1f; float probeForwardOffset = 0.3f; + rotateHead(); + // Steering if (state == Ant::State::WANDER) { diff --git a/src/states/play-state.cpp b/src/states/play-state.cpp index c783bdd..e7465d3 100644 --- a/src/states/play-state.cpp +++ b/src/states/play-state.cpp @@ -55,6 +55,15 @@ void PlayState::enter() // Add forceps to scene application->defaultLayer->addObject(&application->forcepsModelInstance); + forcepsPose = new Pose(application->forcepsModelInstance.getModel()->getSkeleton()); + for (std::size_t i = 0; i < forcepsPose->getSkeleton()->getBoneCount(); ++i) + { + forcepsPose->setRelativeTransform(i, forcepsPose->getSkeleton()->getBindPose()->getRelativeTransform(i)); + } + forcepsPose->concatenate(); + application->forcepsModelInstance.setPose(forcepsPose); + forcepsAnimation = nullptr; + forcepsAnimationTime = 0.0f; // Spawn ants Navmesh* navmesh = application->currentLevel->terrain.getSurfaceNavmesh(); @@ -179,7 +188,7 @@ void PlayState::execute() std::size_t triangleIndex = std::get<3>(result); pickTriangle = (*application->currentLevel->terrain.getSurfaceNavmesh()->getTriangles())[triangleIndex]; - float forcepsDistance = (application->forcepsClosed) ? 0.0f : 0.5f; + float forcepsDistance = application->forcepsSwoopTween->getTweenValue(); //Quaternion rotation = glm::rotation(Vector3(0, 1, 0), triangle->normal); Quaternion rotation = glm::angleAxis(application->surfaceCam->getAzimuth(), Vector3(0, 1, 0)) * @@ -192,6 +201,22 @@ void PlayState::execute() application->forcepsModelInstance.setRotation(rotation); } + if (forcepsAnimation != nullptr) + { + for (std::size_t i = 0; i < forcepsAnimation->getChannelCount(); ++i) + { + const AnimationChannel* channel = forcepsAnimation->getChannel(i); + + std::size_t boneIndex = channel->getChannelID(); + Transform transform = channel->interpolateBoundingKeyFrames(forcepsAnimationTime); + + forcepsPose->setRelativeTransform(channel->getChannelID(), transform); + } + forcepsPose->concatenate(); + + forcepsAnimationTime += 2.5f; + } + if (pickAnt != nullptr) { pickAnt->getModelInstance()->setTranslation(pick); @@ -253,6 +278,14 @@ void PlayState::mouseButtonPressed(int button, int x, int y) if (button == 1) { application->forcepsClosed = true; + forcepsAnimation = forcepsPose->getSkeleton()->getAnimation("pinch"); + forcepsAnimationTime = 0.0f; + + application->forcepsSwoopTween->setDuration(0.10f); + application->forcepsSwoopTween->setStartValue(1.0f); + application->forcepsSwoopTween->setDeltaValue(-1.0f); + application->forcepsSwoopTween->reset(); + application->forcepsSwoopTween->start(); Sphere forcepsSphere = Sphere(pick, 0.35f); @@ -286,6 +319,14 @@ void PlayState::mouseButtonReleased(int button, int x, int y) if (button == 1) { application->forcepsClosed = false; + forcepsAnimation = forcepsPose->getSkeleton()->getAnimation("release"); + forcepsAnimationTime = 0.0f; + + application->forcepsSwoopTween->setDuration(0.10f); + application->forcepsSwoopTween->setStartValue(0.0f); + application->forcepsSwoopTween->setDeltaValue(1.0f); + application->forcepsSwoopTween->reset(); + application->forcepsSwoopTween->start(); if (pickAnt != nullptr) { diff --git a/src/states/play-state.hpp b/src/states/play-state.hpp index f60607f..ce94a64 100644 --- a/src/states/play-state.hpp +++ b/src/states/play-state.hpp @@ -48,6 +48,9 @@ private: Ray pickingRay; Navmesh::Triangle* pickTriangle; Ant* pickAnt; + Pose* forcepsPose; + float forcepsAnimationTime; + const Animation* forcepsAnimation; }; #endif // PLAY_STATE_HPP \ No newline at end of file