Browse Source

Animate ants walking and forceps pinching

master
C. J. Howard 7 years ago
parent
commit
f9d35bef14
6 changed files with 65 additions and 6 deletions
  1. +1
    -1
      data
  2. +4
    -0
      src/application.cpp
  3. +1
    -0
      src/application.hpp
  4. +14
    -4
      src/game/ant.cpp
  5. +42
    -1
      src/states/play-state.cpp
  6. +3
    -0
      src/states/play-state.hpp

+ 1
- 1
data

@ -1 +1 @@
Subproject commit 11f999abf6d47962610f6c9696a8d4d4ee2a1bcb
Subproject commit ce902f8e1c8ad4b204689711ea9bdb3fe7f3b585

+ 4
- 0
src/application.cpp View File

@ -1169,6 +1169,10 @@ bool Application::loadUI()
tweener->addTween(previewLevelTweens[i]); tweener->addTween(previewLevelTweens[i]);
} }
// Tool tweens
forcepsSwoopTween = new Tween<float>(EaseFunction::OUT_CUBIC, 0.0f, 1.0f, 0.0f, 0.5f);
tweener->addTween(forcepsSwoopTween);
// Build menu system // Build menu system
selectedMenuItemIndex = 0; selectedMenuItemIndex = 0;
mainMenu = new Menu(); mainMenu = new Menu();

+ 1
- 0
src/application.hpp View File

@ -340,6 +340,7 @@ public:
Tween<Vector3>* cameraTranslationTween; Tween<Vector3>* cameraTranslationTween;
Tween<Vector3>* previewLevelTweens[5]; Tween<Vector3>* previewLevelTweens[5];
Tween<float>* forcepsSwoopTween;
// Menus // Menus
std::size_t menuCount; std::size_t menuCount;

+ 14
- 4
src/game/ant.cpp View File

@ -20,6 +20,12 @@
#include "ant.hpp" #include "ant.hpp"
#include "colony.hpp" #include "colony.hpp"
#include "pheromone.hpp" #include "pheromone.hpp"
#include <cmath>
inline float fwrap(float angle, float limit)
{
return angle - std::floor(angle / limit) * limit;
}
Ant::Ant(Colony* colony): Ant::Ant(Colony* colony):
colony(colony), colony(colony),
@ -37,7 +43,7 @@ Ant::Ant(Colony* colony):
modelInstance.setModel(colony->getAntModel()); modelInstance.setModel(colony->getAntModel());
modelInstance.setPose(pose); modelInstance.setPose(pose);
animationTime = 0.0f;
animationTime = frand(0.0f, 60.0f);
} }
Ant::~Ant() 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) if (animation != nullptr)
{ {
for (std::size_t i = 0; i < animation->getChannelCount(); ++i) for (std::size_t i = 0; i < animation->getChannelCount(); ++i)
@ -75,11 +81,13 @@ void Ant::rotateHead()
} }
pose->concatenate(); pose->concatenate();
animationTime += 0.5f;
animationTime = fwrap(animationTime + 2.0f, animation->getEndTime());
/*
if (animationTime > animation->getEndTime()) if (animationTime > animation->getEndTime())
{ {
animationTime = animation->getStartTime(); animationTime = animation->getStartTime();
}
}*/
} }
} }
@ -119,6 +127,8 @@ void Ant::update(float dt)
float probeLateralOffset = 0.1f; float probeLateralOffset = 0.1f;
float probeForwardOffset = 0.3f; float probeForwardOffset = 0.3f;
rotateHead();
// Steering // Steering
if (state == Ant::State::WANDER) if (state == Ant::State::WANDER)
{ {

+ 42
- 1
src/states/play-state.cpp View File

@ -55,6 +55,15 @@ void PlayState::enter()
// Add forceps to scene // Add forceps to scene
application->defaultLayer->addObject(&application->forcepsModelInstance); 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 // Spawn ants
Navmesh* navmesh = application->currentLevel->terrain.getSurfaceNavmesh(); Navmesh* navmesh = application->currentLevel->terrain.getSurfaceNavmesh();
@ -179,7 +188,7 @@ void PlayState::execute()
std::size_t triangleIndex = std::get<3>(result); std::size_t triangleIndex = std::get<3>(result);
pickTriangle = (*application->currentLevel->terrain.getSurfaceNavmesh()->getTriangles())[triangleIndex]; 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::rotation(Vector3(0, 1, 0), triangle->normal);
Quaternion rotation = glm::angleAxis(application->surfaceCam->getAzimuth(), Vector3(0, 1, 0)) * Quaternion rotation = glm::angleAxis(application->surfaceCam->getAzimuth(), Vector3(0, 1, 0)) *
@ -192,6 +201,22 @@ void PlayState::execute()
application->forcepsModelInstance.setRotation(rotation); 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) if (pickAnt != nullptr)
{ {
pickAnt->getModelInstance()->setTranslation(pick); pickAnt->getModelInstance()->setTranslation(pick);
@ -253,6 +278,14 @@ void PlayState::mouseButtonPressed(int button, int x, int y)
if (button == 1) if (button == 1)
{ {
application->forcepsClosed = true; 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); Sphere forcepsSphere = Sphere(pick, 0.35f);
@ -286,6 +319,14 @@ void PlayState::mouseButtonReleased(int button, int x, int y)
if (button == 1) if (button == 1)
{ {
application->forcepsClosed = false; 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) if (pickAnt != nullptr)
{ {

+ 3
- 0
src/states/play-state.hpp View File

@ -48,6 +48,9 @@ private:
Ray pickingRay; Ray pickingRay;
Navmesh::Triangle* pickTriangle; Navmesh::Triangle* pickTriangle;
Ant* pickAnt; Ant* pickAnt;
Pose* forcepsPose;
float forcepsAnimationTime;
const Animation* forcepsAnimation;
}; };
#endif // PLAY_STATE_HPP #endif // PLAY_STATE_HPP

Loading…
Cancel
Save