1#include "ObjectCarA.hh"
3#include "game/field/ObjectCollisionCylinder.hh"
5#include "game/kart/KartCollide.hh"
6#include "game/kart/KartObject.hh"
12 : ObjectCollidable(params), StateManager(this, STATE_ENTRIES),
13 m_finalVel(static_cast<f32>(params.setting(0))),
14 m_accel(static_cast<f32>(params.setting(1)) / 10.0f),
15 m_stopTime(static_cast<u32>(params.setting(2))) {}
18ObjectCarA::~ObjectCarA() =
default;
21void ObjectCarA::init() {
22 constexpr f32 RADIUS = 400.0f;
24 m_railInterpolator->init(0, 0);
27 f32 finalTime = m_finalVel / m_accel;
29 (m_railInterpolator->railLength() - finalTime * m_accel * finalTime) / m_finalVel;
31 setMatrixFromOrthonormalBasisAndPos(m_railInterpolator->curTangentDir());
33 m_flags.setBit(eFlags::Position);
34 m_pos = m_railInterpolator->curPos();
36 m_motionState = MotionState::Accelerating;
37 m_changingDir =
false;
38 m_currUp = EGG::Vector3f::ey;
39 m_currTangent = m_railInterpolator->curTangentDir();
45void ObjectCarA::calc() {
48 m_railInterpolator->setCurrVel(m_currVel);
50 auto status = m_railInterpolator->calc();
51 m_changingDir = (status == RailInterpolator::Status::ChangingDirection);
57void ObjectCarA::createCollision() {
58 constexpr f32 RADIUS = 210.0f;
59 constexpr f32 HEIGHT = 200.0f;
61 m_collision =
new ObjectCollisionCylinder(RADIUS, HEIGHT, collisionCenter());
65void ObjectCarA::calcCollisionTransform() {
66 ObjectCollisionBase *objCol = collision();
74 SetRotTangentHorizontal(mat, m_transform.base(2), EGG::Vector3f::ey);
75 mat.
setBase(3, m_transform.base(3) + 50.0f * m_transform.base(1));
77 objCol->transform(mat, m_scale,
78 -m_railInterpolator->curTangentDir() * m_railInterpolator->getCurrVel());
82Kart::Reaction ObjectCarA::onCollision(
Kart::KartObject *kartObj, Kart::Reaction reactionOnKart,
84 return kartObj->speedRatioCapped() < 0.5f ? Kart::Reaction::WallAllSpeed : reactionOnKart;
88void ObjectCarA::enterStop() {
93void ObjectCarA::enterCruising() {
94 m_currVel = m_finalVel;
98void ObjectCarA::calcStop() {
99 if (m_currentFrame > m_stopTime) {
100 m_motionState = MotionState::Accelerating;
101 m_currentStateId = 1;
106void ObjectCarA::calcAccel() {
107 if (m_motionState == MotionState::Accelerating) {
108 m_currVel += m_accel;
110 if (m_currVel > m_finalVel) {
111 m_currVel = m_finalVel;
112 m_motionState = MotionState::Cruising;
115 }
else if (m_motionState == MotionState::Decelerating) {
118 m_currVel = std::max(0.01f, m_currVel - m_accel);
123 if (m_railInterpolator->isMovementDirectionForward()) {
124 m_railInterpolator->init(0.0f, 0);
127 m_motionState = MotionState::Cruising;
134void ObjectCarA::calcCruising() {
136 if (
static_cast<f32
>(m_currentFrame) > m_cruiseTime - 1.0f) {
137 m_motionState = MotionState::Decelerating;
143void ObjectCarA::calcPos() {
144 m_currUp = Interpolate(0.1f, m_currUp, EGG::Vector3f::ey);
145 m_currUp.normalise2();
147 setMatrixTangentTo(m_currUp, m_currTangent);
149 m_pos = m_railInterpolator->curPos();
150 m_flags.setBit(eFlags::Position);
void setBase(size_t col, const Vector3f &base)
Sets one column of a matrix.
The highest level abstraction for a kart.