Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/game/field/obj/ObjectAmi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ bool ObjectAmi::checkSphereImpl(f32 radius, const EGG::Vector3f &v0, const EGG::
return false;
}

EGG::Vector3f posDelta = v0 - m_pos;
EGG::Vector3f posDelta = v0 - pos();
posDelta.z *= -1.0f;

if (posDelta.z < 0.0f || posDelta.z > DIMS.z || EGG::Mathf::abs(posDelta.x) > DIMS.x) {
Expand Down
4 changes: 2 additions & 2 deletions source/game/field/obj/ObjectAurora.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bool ObjectAurora::checkSphereFullPushImpl(f32 radius, const EGG::Vector3f &v0,
bool ObjectAurora::checkSpherePartialImpl(f32 radius, const EGG::Vector3f &v0,
const EGG::Vector3f & /*v1*/, KCLTypeMask flags, CollisionInfoPartial *pInfo,
KCLTypeMask *pFlagsOut, u32 timeOffset, bool push) {
EGG::Vector3f vel = v0 - m_pos;
EGG::Vector3f vel = v0 - pos();

if (vel.z < 0.0f || vel.z > COLLISION_SIZE.z || EGG::Mathf::abs(vel.x) > COLLISION_SIZE.x) {
return false;
Expand Down Expand Up @@ -220,7 +220,7 @@ bool ObjectAurora::checkSpherePartialImpl(f32 radius, const EGG::Vector3f &v0,
bool ObjectAurora::checkSphereFullImpl(f32 radius, const EGG::Vector3f &v0,
const EGG::Vector3f & /*v1*/, KCLTypeMask flags, CollisionInfo *pInfo,
KCLTypeMask *pFlagsOut, u32 timeOffset, bool push) {
EGG::Vector3f vel = v0 - m_pos;
EGG::Vector3f vel = v0 - pos();

if (vel.z < 0.0f || vel.z > COLLISION_SIZE.z || EGG::Mathf::abs(vel.x) > COLLISION_SIZE.x) {
return false;
Expand Down
8 changes: 3 additions & 5 deletions source/game/field/obj/ObjectBasabasa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ ObjectBasabasaDummy::~ObjectBasabasaDummy() = default;
/// @addr{0x806B5E80}
void ObjectBasabasaDummy::init() {
m_railInterpolator->init(0.0f, 0);
m_pos = m_railInterpolator->curPos();
m_flags.setBit(eFlags::Position);
setPos(m_railInterpolator->curPos());

auto &rng = System::RaceManager::Instance()->random();
rng.next();
Expand Down Expand Up @@ -64,10 +63,9 @@ void ObjectBasabasaDummy::calcState0() {
setMatrixFromOrthonormalBasisAndPos(m_railInterpolator->curTangentDir());
calcTransform();

EGG::Matrix34f mat = m_transform;
EGG::Matrix34f mat = transform();
mat.setBase(3, EGG::Vector3f::zero);
m_pos = m_railInterpolator->curPos() + mat.ps_multVector(m_initialPos);
m_flags.setBit(eFlags::Position);
setPos(m_railInterpolator->curPos() + mat.ps_multVector(m_initialPos));
}
}

Expand Down
10 changes: 4 additions & 6 deletions source/game/field/obj/ObjectBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ namespace Field {
/// @addr{0x8081F828}
ObjectBase::ObjectBase(const System::MapdataGeoObj &params)
: m_drawMdl(nullptr), m_resFile(nullptr), m_id(static_cast<ObjectId>(params.id())),
m_railInterpolator(nullptr), m_pos(params.pos()), m_scale(params.scale()),
m_rot(params.rot() * DEG2RAD), m_rotLock(true), m_transform(EGG::Matrix34f::ident),
m_mapObj(&params) {
m_railInterpolator(nullptr), m_mapObj(&params), m_pos(params.pos()), m_scale(params.scale()),
m_rot(params.rot() * DEG2RAD), m_rotLock(true), m_transform(EGG::Matrix34f::ident) {
m_flags.setBit(eFlags::Position, eFlags::Rotation, eFlags::Scale);
}

/// @addr{0x8081FB04}
ObjectBase::ObjectBase(const char *name, const EGG::Vector3f &pos, const EGG::Vector3f &rot,
const EGG::Vector3f &scale)
: m_drawMdl(nullptr), m_resFile(nullptr), m_railInterpolator(nullptr), m_pos(pos),
m_scale(scale), m_rot(rot), m_rotLock(true), m_transform(EGG::Matrix34f::ident),
m_mapObj(nullptr) {
: m_drawMdl(nullptr), m_resFile(nullptr), m_railInterpolator(nullptr), m_mapObj(nullptr),
m_pos(pos), m_scale(scale), m_rot(rot), m_rotLock(true), m_transform(EGG::Matrix34f::ident) {
m_flags.setBit(eFlags::Position, eFlags::Rotation, eFlags::Scale);
m_id = ObjectDirector::Instance()->flowTable().getIdFromName(name);
}
Expand Down
59 changes: 54 additions & 5 deletions source/game/field/obj/ObjectBase.hh
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,76 @@ public:
return m_id;
}

[[nodiscard]] const EGG::Vector3f &pos() const {
return m_pos;
}

void setPos(const EGG::Vector3f &pos) {
m_flags.setBit(eFlags::Position);
m_pos = pos;
}

void addPos(const EGG::Vector3f &v) {
m_flags.setBit(eFlags::Position);
m_pos += v;
}

void subPos(const EGG::Vector3f &v) {
m_flags.setBit(eFlags::Position);
m_pos -= v;
}

void setScale(const EGG::Vector3f &scale) {
m_flags.setBit(eFlags::Scale);
m_scale = scale;
}

void setScale(f32 scale) {
m_flags.setBit(eFlags::Scale);
m_scale.set(scale);
}

void setRot(const EGG::Vector3f &rot) {
m_flags.setBit(eFlags::Rotation);
m_rot = rot;
}

void setRotNoFlag(const EGG::Vector3f &rot) {
m_rot = rot;
}

void addRot(const EGG::Vector3f &v) {
m_rotLock = true;
m_flags.setBit(eFlags::Rotation);
m_rot += v;
}

void subRot(const EGG::Vector3f &v) {
m_rotLock = true;
m_flags.setBit(eFlags::Rotation);
m_rot -= v;
}

/// @addr{0x806C296C}
void setTransform(const EGG::Matrix34f &mat) {
m_rotLock = false;
m_flags.setBit(eFlags::Matrix);
m_transform = mat;
m_pos = mat.base(3);
}

[[nodiscard]] const EGG::Vector3f &pos() const {
return m_pos;
}

[[nodiscard]] const EGG::Vector3f &scale() const {
return m_scale;
}

[[nodiscard]] const EGG::Vector3f &rot() const {
return m_rot;
}

[[nodiscard]] const EGG::Matrix34f &transform() const {
return m_transform;
}

protected:
void calcTransform();
void calcRotLock();
Expand Down Expand Up @@ -154,13 +201,15 @@ protected:
ObjectId m_id;
RailInterpolator *m_railInterpolator;
BoxColUnit *m_boxColUnit;
const System::MapdataGeoObj *m_mapObj;

private:
Flags m_flags;
EGG::Vector3f m_pos;
EGG::Vector3f m_scale;
EGG::Vector3f m_rot;
bool m_rotLock;
EGG::Matrix34f m_transform;
const System::MapdataGeoObj *m_mapObj;
};

} // namespace Field
2 changes: 1 addition & 1 deletion source/game/field/obj/ObjectBeltCurveA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ObjectBeltCurveA::~ObjectBeltCurveA() = default;
/// @addr{0x807FC9D4}
EGG::Vector3f ObjectBeltCurveA::calcRoadVelocity(u32 variant, const EGG::Vector3f &pos,
u32 timeOffset) const {
EGG::Vector3f posDelta = pos - m_pos;
EGG::Vector3f posDelta = pos - this->pos();
posDelta.y = 0.0f;

EGG::Vector3f dir = m_initMat.ps_multVector(posDelta);
Expand Down
23 changes: 9 additions & 14 deletions source/game/field/obj/ObjectBird.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,14 @@ void ObjectBirdLeader::init() {

m_railInterpolator->init(0.0f, 0);
m_railInterpolator->calc();
m_pos = m_railInterpolator->curPos();
m_flags.setBit(eFlags::Position);
setPos(m_railInterpolator->curPos());
m_railInterpolator->setCurrVel(static_cast<f32>(m_mapObj->setting(0)));
}

/// @addr{0x8077C504}
void ObjectBirdLeader::calc() {
m_railInterpolator->calc();
m_pos = m_railInterpolator->curPos();
m_flags.setBit(eFlags::Position);
setPos(m_railInterpolator->curPos());
}

/// @addr{0x8077CC78}
Expand Down Expand Up @@ -125,8 +123,7 @@ void ObjectBirdFollower::init() {
f32 x = rand.getF32(POS_DELTA_RANGE) - POS_DELTA_CENTER;
EGG::Vector3f delta = EGG::Vector3f(x, y, z);

m_pos = m_bird->leader()->pos() + delta;
m_flags.setBit(eFlags::Position);
setPos(m_bird->leader()->pos() + delta);
}

/// @addr{0x8077C7F0}
Expand All @@ -135,27 +132,26 @@ void ObjectBirdFollower::calc() {

CollisionInfo info;

if (CollisionDirector::Instance()->checkSphereFull(100.0f, m_pos, EGG::Vector3f::inf,
if (CollisionDirector::Instance()->checkSphereFull(100.0f, pos(), EGG::Vector3f::inf,
KCL_TYPE_FLOOR, &info, nullptr, 0)) {
m_pos += info.tangentOff;
m_flags.setBit(eFlags::Position);
addPos(info.tangentOff);
}
}

/// @addr{0x8077C8F4}
void ObjectBirdFollower::calcPos() {
constexpr f32 MAX_SPEED_FACTOR = 1.2f;

EGG::Vector3f pos = m_bird->leader()->pos();
EGG::Vector3f leaderPos = m_bird->leader()->pos();
const auto &follower = m_bird->followers();

for (u32 i = 0; i < follower.size(); ++i) {
if (i != m_idx) {
pos += follower[i]->pos();
leaderPos += follower[i]->pos();
}
}

EGG::Vector3f posDelta = pos * (1.0f / static_cast<f32>(follower.size())) - m_pos;
EGG::Vector3f posDelta = leaderPos * (1.0f / static_cast<f32>(follower.size())) - pos();
posDelta.normalise();
posDelta *= 0.5f;

Expand All @@ -166,8 +162,7 @@ void ObjectBirdFollower::calcPos() {
m_velocity *= m_baseSpeed * MAX_SPEED_FACTOR;
}

m_pos += m_velocity;
m_flags.setBit(eFlags::Position);
addPos(m_velocity);
}

} // namespace Field
7 changes: 2 additions & 5 deletions source/game/field/obj/ObjectBoble.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ void ObjectBoble::init() {
m_railInterpolator->init(0.0f, 0);
m_curTangentDir = m_railInterpolator->curTangentDir();
m_railInterpolator->setPerPointVelocities(true);
m_flags.setBit(eFlags::Scale);
m_scale = EGG::Vector3f(1.0f, 1.0f, 1.0f);
setScale(EGG::Vector3f::unit);
}

/// @addr{0x8075DCA0}
void ObjectBoble::calc() {
m_railInterpolator->calc();
m_pos = m_railInterpolator->curPos();
m_flags.setBit(eFlags::Position);

setPos(m_railInterpolator->curPos());
calcTangent();
}

Expand Down
16 changes: 7 additions & 9 deletions source/game/field/obj/ObjectBulldozer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Field {

/// @addr{0x807FD938}
ObjectBulldozer::ObjectBulldozer(const System::MapdataGeoObj &params)
: ObjectKCL(params), m_initialPos(m_pos), m_initialRot(m_rot) {
: ObjectKCL(params), m_initialPos(pos()), m_initialRot(rot()) {
m_timeOffset = params.setting(3) * 2;
m_periodDenom = std::max<u16>(2, params.setting(2));
m_restFrames = params.setting(4);
Expand All @@ -26,24 +26,22 @@ ObjectBulldozer::~ObjectBulldozer() = default;
void ObjectBulldozer::calc() {
u32 timer = System::RaceManager::Instance()->timer();
f32 posOffset = calcStateAndPosition(m_timeOffset + timer);
EGG::Vector3f prevPos = m_pos;

m_flags.setBit(eFlags::Position);
m_pos.x = m_left ? m_initialPos.x + posOffset : m_initialPos.x - posOffset;

setMovingObjVel(m_pos - prevPos);
EGG::Vector3f prevPos = pos();
f32 xPos = m_left ? m_initialPos.x + posOffset : m_initialPos.x - posOffset;
setPos(EGG::Vector3f(xPos, prevPos.y, prevPos.z));
setMovingObjVel(pos() - prevPos);
}

/// @addr{0x807FE364}
void ObjectBulldozer::initCollision() {
calcTransform();

EGG::Matrix34f matInv;
m_transform.ps_inverse(matInv);
transform().ps_inverse(matInv);

calcTransform();

m_objColMgr->setMtx(m_transform);
m_objColMgr->setMtx(transform());
m_objColMgr->setInvMtx(matInv);
m_objColMgr->setScale(getScaleY(0));

Expand Down
13 changes: 5 additions & 8 deletions source/game/field/obj/ObjectCarA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ void ObjectCarA::init() {

setMatrixFromOrthonormalBasisAndPos(m_railInterpolator->curTangentDir());

m_flags.setBit(eFlags::Position);
m_pos = m_railInterpolator->curPos();
setPos(m_railInterpolator->curPos());
m_currVel = 0.0f;
m_motionState = MotionState::Accelerating;
m_changingDir = false;
Expand Down Expand Up @@ -71,10 +70,10 @@ void ObjectCarA::calcCollisionTransform() {
calcTransform();

EGG::Matrix34f mat;
SetRotTangentHorizontal(mat, m_transform.base(2), EGG::Vector3f::ey);
mat.setBase(3, m_transform.base(3) + 50.0f * m_transform.base(1));
SetRotTangentHorizontal(mat, transform().base(2), EGG::Vector3f::ey);
mat.setBase(3, transform().base(3) + 50.0f * transform().base(1));

objCol->transform(mat, m_scale,
objCol->transform(mat, scale(),
-m_railInterpolator->curTangentDir() * m_railInterpolator->getCurrVel());
}

Expand Down Expand Up @@ -145,9 +144,7 @@ void ObjectCarA::calcPos() {
m_currUp.normalise2();

setMatrixTangentTo(m_currUp, m_currTangent);

m_pos = m_railInterpolator->curPos();
m_flags.setBit(eFlags::Position);
setPos(m_railInterpolator->curPos());
}

} // namespace Field
Loading