1#include "ObjectHwanwan.hh"
3#include "game/field/CollisionDirector.hh"
8ObjectHwanwan::ObjectHwanwan(
const System::MapdataGeoObj ¶ms)
12ObjectHwanwan::~ObjectHwanwan() =
default;
15void ObjectHwanwan::init() {
16 m_workPos = m_initPos + EGG::Vector3f::ey * DIAMETER;
18 m_bounceVel.setZero();
19 m_tangent = EGG::Vector3f::ez;
20 m_up = EGG::Vector3f::ey;
21 m_targetUp = EGG::Vector3f::ey;
22 m_touchingGround =
false;
24 m_targetY = m_workPos.y;
32void ObjectHwanwan::calc() {
35 m_extVel += m_bounceVel - GRAVITY;
36 m_workPos += m_extVel;
37 m_bounceVel.setZero();
39 checkFloorCollision();
42 SetRotTangentHorizontal(mat, m_up, m_tangent);
43 mat.setBase(3, m_workPos);
48void ObjectHwanwan::checkFloorCollision() {
49 constexpr f32 RADIUS = DIAMETER * 0.5f;
51 m_touchingGround =
false;
53 CollisionInfo colInfo;
55 EGG::Vector3f pos = m_workPos + EGG::Vector3f(0.0f, -DIAMETER, 0.0f);
57 bool hasCol = CollisionDirector::Instance()->checkSphereFullPush(RADIUS, pos,
60 if (!hasCol || pos.y - m_targetY >= 300.0f) {
64 m_touchingGround =
true;
66 f32 len = colInfo.tangentOff.length();
67 m_workPos += EGG::Vector3f::ey * len;
69 if (colInfo.floorDist > -std::numeric_limits<f32>::min()) {
70 m_targetUp = colInfo.floorNrm;
76void ObjectHwanwan::calcUp() {
77 m_up = Interpolate(0.1f, m_up, m_targetUp);
78 if (m_up.squaredLength() > std::numeric_limits<f32>::epsilon()) {
81 m_up = EGG::Vector3f::ey;
86ObjectHwanwanManager::ObjectHwanwanManager(
const System::MapdataGeoObj ¶ms)
87 : ObjectCollidable(params) {
88 m_hwanwan = EGG::egg_new<ObjectHwanwan>(params);
89 m_hwanwan->setScale(2.0f);
94ObjectHwanwanManager::~ObjectHwanwanManager() =
default;
97void ObjectHwanwanManager::init() {
98 m_railInterpolator->init(0.0f, 0);
99 m_hwanwan->m_tangent = m_railInterpolator->curTangentDir();
100 const auto &curPos = m_railInterpolator->curPos();
101 m_hwanwan->m_workPos.x = curPos.x;
102 m_hwanwan->m_workPos.z = curPos.z;
103 m_hwanwan->m_targetY = curPos.y;
109 m_railInterpolator->setCurrVel(
static_cast<f32
>(m_mapObj->setting(0)));
113void ObjectHwanwanManager::calc() {
116 const auto &curPos = m_railInterpolator->curPos();
117 m_hwanwan->m_workPos.x = curPos.x;
118 m_hwanwan->m_workPos.z = curPos.z;
119 m_hwanwan->m_targetY = curPos.y;
120 m_hwanwan->m_tangent = m_railInterpolator->curTangentDir();
124void ObjectHwanwanManager::calcState() {
125 if (m_railInterpolator->calc() == RailInterpolator::Status::SegmentEnd &&
126 m_railInterpolator->curPoint().setting[1] == 1 && m_hwanwan->m_currentStateId != 2) {
127 m_hwanwan->m_nextStateId = 1;
130 if (m_hwanwan->m_currentStateId == 1 && m_hwanwan->m_currentFrame >= 60) {
131 m_hwanwan->m_nextStateId = 0;
#define KCL_TYPE_FLOOR
0x20E80FFF - Any KCL that the player or items can drive/land on.
Base class that represents different "states" for an object.