1#include "ObjectCrab.hh"
3#include "game/field/CollisionDirector.hh"
4#include "game/field/ObjectDirector.hh"
6#include "game/system/RaceManager.hh"
11ObjectCrab::ObjectCrab(
const System::MapdataGeoObj ¶ms)
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 setPos(m_railInterpolator->curPos());
26 calcTransMat(m_curRot);
31 m_state = State::Walking;
32 m_statePhase = StatePhase::Start;
36void ObjectCrab::calc() {
37 if (System::RaceManager::Instance()->timer() == 0 && m_introCalc) {
47 StateResult res = calcState();
49 if (res == StateResult::Middle) {
53 if (res == StateResult::Walking) {
54 if (m_statePhase == StatePhase::Start) {
55 m_statePhase = StatePhase::Middle;
59 if (m_statePhase == StatePhase::Middle) {
60 setPos(m_railInterpolator->curPos());
63 m_statePhase = StatePhase::End;
68 m_state = State::Still;
69 m_statePhase = StatePhase::Start;
75bool ObjectCrab::calcRail() {
77 if (m_stillDuration <= ++m_stillFrame) {
78 m_railInterpolator->setCurrVel(m_vel);
86 auto status = m_railInterpolator->calc();
87 if (status == RailInterpolator::Status::SegmentEnd ||
88 status == RailInterpolator::Status::ChangingDirection) {
89 u16 duration = m_railInterpolator->curPoint().setting[0];
91 m_railInterpolator->setCurrVel(0.0f);
92 m_stillDuration = duration;
101ObjectCrab::StateResult ObjectCrab::calcState() {
102 if (m_state != State::Still) {
103 return StateResult::Walking;
106 if (m_statePhase == StatePhase::Start) {
107 setPos(m_railInterpolator->curPos());
108 calcCurRot(INIT_ROT);
109 calcTransMat(m_curRot);
110 m_statePhase = StatePhase::Middle;
113 if (m_statePhase == StatePhase::Middle) {
115 m_statePhase = StatePhase::End;
118 return StateResult::Middle;
120 m_state = State::Walking;
121 m_statePhase = StatePhase::Start;
124 return StateResult::BeginWalking;
127void ObjectCrab::calcCurRot(
const EGG::Vector3f &rot) {
129 m_curRot = m_backwards ? -m_curRot : m_curRot;
130 m_curRot.y = m_railInterpolator->isMovementDirectionForward() ? m_curRot.y : -m_curRot.y;
133void ObjectCrab::calcTransMat(
const EGG::Vector3f &rot) {
134 EGG::Matrix34f rotMat;
136 rotMat = rotMat.multiplyTo(EGG::Matrix34f::ident);
139 mat.makeOrthonormalBasisLocal(m_railInterpolator->curTangentDir(), EGG::Vector3f::ey);
140 mat = mat.multiplyTo(rotMat);
141 mat.setBase(3, pos());