Skip to content

Commit

Permalink
Sync frame 2
Browse files Browse the repository at this point in the history
  • Loading branch information
malleoz committed Feb 8, 2024
1 parent 08311d2 commit 523a7fd
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 2 deletions.
12 changes: 12 additions & 0 deletions source/egg/math/Vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ Vector3f Vector3f::minimize(const Vector3f &rhs) const {
return out;
}

Vector3f Vector3f::proj(const Vector3f &rhs) const {
return rhs * rhs.dot(*this);
}

Vector3f Vector3f::rej(const Vector3f &rhs) const {
return *this - proj(rhs);
}

std::pair<Vector3f, Vector3f> Vector3f::projAndRej(const Vector3f &rhs) {
return std::pair(proj(rhs), rej(rhs));
}

void Vector3f::read(Stream &stream) {
x = stream.read_f32();
y = stream.read_f32();
Expand Down
3 changes: 3 additions & 0 deletions source/egg/math/Vector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ struct Vector3f {
f32 normalise();
Vector3f maximize(const Vector3f &rhs) const;
Vector3f minimize(const Vector3f &rhs) const;
Vector3f proj(const Vector3f &rhs) const;
Vector3f rej(const Vector3f &rhs) const;
std::pair<Vector3f, Vector3f> projAndRej(const Vector3f &rhs);

void read(Stream &stream);

Expand Down
10 changes: 10 additions & 0 deletions source/game/kart/KartDynamics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ void KartDynamics::calc(f32 dt, f32 maxSpeed, bool /*air*/) {

m_mainRot.normalise();
m_fullRot.normalise();

m_totalForce.setZero();
}

const EGG::Vector3f &KartDynamics::pos() const {
Expand All @@ -48,6 +50,10 @@ const EGG::Quatf &KartDynamics::fullRot() const {
return m_fullRot;
}

const EGG::Vector3f &KartDynamics::extVel() const {
return m_extVel;
}

void KartDynamics::setPos(const EGG::Vector3f &pos) {
m_pos = pos;
}
Expand All @@ -72,4 +78,8 @@ void KartDynamics::setExtraRot(const EGG::Quatf &q) {
m_extraRot = q;
}

void KartDynamics::setExtVel(const EGG::Vector3f &v) {
m_extVel = v;
}

} // namespace Kart
2 changes: 2 additions & 0 deletions source/game/kart/KartDynamics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ public:
const EGG::Vector3f &pos() const;
const EGG::Vector3f &velocity() const;
const EGG::Quatf &fullRot() const;
const EGG::Vector3f &extVel() const;

void setPos(const EGG::Vector3f &pos);
void setGravity(f32 gravity);
void setMainRot(const EGG::Quatf &q);
void setFullRot(const EGG::Quatf &q);
void setSpecialRot(const EGG::Quatf &q);
void setExtraRot(const EGG::Quatf &q);
void setExtVel(const EGG::Vector3f &v);

private:
// These are the only vars needed in setInitialPhysicsValues
Expand Down
6 changes: 5 additions & 1 deletion source/game/kart/KartMove.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Kart {

KartMove::KartMove() : m_scale(1.0f, 1.0f, 1.0f) {}
KartMove::KartMove() : m_smoothedUp(EGG::Vector3f::ey), m_scale(1.0f, 1.0f, 1.0f) {}

void KartMove::setInitialPhysicsValues(const EGG::Vector3f &pos, const EGG::Vector3f &angles) {
EGG::Quatf quaternion;
Expand Down Expand Up @@ -53,4 +53,8 @@ f32 KartMove::hardSpeedLimit() const {
return m_hardSpeedLimit;
}

const EGG::Vector3f &KartMove::smoothedUp() const {
return m_smoothedUp;
}

} // namespace Kart
2 changes: 2 additions & 0 deletions source/game/kart/KartMove.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ public:

const EGG::Vector3f &scale() const;
f32 hardSpeedLimit() const;
const EGG::Vector3f &smoothedUp() const;

private:
EGG::Vector3f m_smoothedUp;
EGG::Vector3f m_scale;
f32 m_hardSpeedLimit;
};
Expand Down
4 changes: 4 additions & 0 deletions source/game/kart/KartObjectProxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ const EGG::Quatf &KartObjectProxy::fullRot() const {
return dynamics()->fullRot();
}

bool KartObjectProxy::isBike() const {
return param()->isBike();
}

Abstract::List *KartObjectProxy::list() const {
return s_list;
}
Expand Down
1 change: 1 addition & 0 deletions source/game/kart/KartObjectProxy.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public:

const EGG::Vector3f &pos() const;
const EGG::Quatf &fullRot() const;
bool isBike() const;

Abstract::List *list() const;

Expand Down
10 changes: 10 additions & 0 deletions source/game/kart/KartSub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ void KartSub::calcPass0() {

move()->calc();

EGG::Vector3f local_38 = dynamics()->extVel();
if (isBike()) {
local_38 = local_38.rej(move()->smoothedUp());
} else {
local_38.x = 0.0f;
local_38.y = 0.0f;
}

dynamics()->setExtVel(local_38);

f32 maxSpeed = move()->hardSpeedLimit();
physics()->calc(DT, maxSpeed, scale(), !state()->isGround());
}
Expand Down
2 changes: 1 addition & 1 deletion source/test/TestDirector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool TestDirector::init() {

bool TestDirector::calc() {
// Check if we're out of frames
constexpr u16 TARGET_FRAME = 1;
constexpr u16 TARGET_FRAME = 2;
assert(TARGET_FRAME <= m_frameCount);
if (++m_currentFrame > TARGET_FRAME) {
return false;
Expand Down

0 comments on commit 523a7fd

Please sign in to comment.