1#include "ObjectCrab.hh"
3#include "game/field/CollisionDirector.hh"
4#include "game/field/ObjectDirector.hh"
6#include "game/system/RaceManager.hh"
12 : ObjectCollidable(params), m_vel(static_cast<f32>(static_cast<s16>(params.setting(0)))),
13 m_backwards(!!params.setting(1)), m_introCalc(false) {}
16ObjectCrab::~ObjectCrab() =
default;
19void ObjectCrab::init() {
20 m_railInterpolator->init(0.0f, 0);
24 m_railInterpolator->setCurrVel(m_vel);
25 m_pos = m_railInterpolator->curPos();
26 m_flags.setBit(eFlags::Position);
28 calcTransMat(m_curRot);
33 m_state = State::Walking;
34 m_statePhase = StatePhase::Start;
38void ObjectCrab::calc() {
39 if (System::RaceManager::Instance()->timer() == 0 && m_introCalc) {
49 StateResult res = calcState();
51 if (res == StateResult::Middle) {
55 if (res == StateResult::Walking) {
56 if (m_statePhase == StatePhase::Start) {
57 m_statePhase = StatePhase::Middle;
61 if (m_statePhase == StatePhase::Middle) {
62 m_pos = m_railInterpolator->curPos();
63 m_flags.setBit(eFlags::Position);
66 m_statePhase = StatePhase::End;
71 m_state = State::Still;
72 m_statePhase = StatePhase::Start;
78bool ObjectCrab::calcRail() {
80 if (m_stillDuration <= ++m_stillFrame) {
81 m_railInterpolator->setCurrVel(m_vel);
89 auto status = m_railInterpolator->calc();
90 if (status == RailInterpolator::Status::SegmentEnd ||
91 status == RailInterpolator::Status::ChangingDirection) {
92 u16 duration = m_railInterpolator->curPoint().setting[0];
94 m_railInterpolator->setCurrVel(0.0f);
95 m_stillDuration = duration;
104ObjectCrab::StateResult ObjectCrab::calcState() {
105 if (m_state != State::Still) {
106 return StateResult::Walking;
109 if (m_statePhase == StatePhase::Start) {
110 m_pos = m_railInterpolator->curPos();
111 m_flags.setBit(eFlags::Position);
113 calcCurRot(INIT_ROT);
114 calcTransMat(m_curRot);
115 m_statePhase = StatePhase::Middle;
118 if (m_statePhase == StatePhase::Middle) {
120 m_statePhase = StatePhase::End;
123 return StateResult::Middle;
125 m_state = State::Walking;
126 m_statePhase = StatePhase::Start;
129 return StateResult::BeginWalking;
134 m_curRot = m_backwards ? -m_curRot : m_curRot;
135 m_curRot.y = m_railInterpolator->isMovementDirectionForward() ? m_curRot.y : -m_curRot.y;
141 rotMat = rotMat.
multiplyTo(EGG::Matrix34f::ident);
144 basis.makeOrthonormalBasisLocal(m_railInterpolator->curTangentDir(), EGG::Vector3f::ey);
148 m_flags.setBit(eFlags::Matrix);
Matrix34f multiplyTo(const Matrix34f &rhs) const
Multiplies two matrices.
void setBase(size_t col, const Vector3f &base)
Sets one column of a matrix.
void makeR(const Vector3f &r)
Sets 3x3 rotation matrix from a vector of Euler angles.