1#include "KartPhysics.hh"
3#include <egg/math/Quat.hh>
8KartPhysics::KartPhysics(
bool isBike) {
9 m_pose = EGG::Matrix34f::ident;
10 m_dynamics = isBike ?
static_cast<KartDynamics *
>(EGG::egg_new<KartDynamicsBike>()) :
11 EGG::egg_new<KartDynamics>();
12 m_hitboxGroup = EGG::egg_new<CollisionGroup>();
17KartPhysics::~KartPhysics() {
18 EGG::egg_delete(m_dynamics);
19 EGG::egg_delete(m_hitboxGroup);
23void KartPhysics::reset() {
25 m_hitboxGroup->reset();
26 m_decayingStuntRot = EGG::Quatf::ident;
27 m_instantaneousStuntRot = EGG::Quatf::ident;
28 m_specialRot = EGG::Quatf::ident;
30 m_instantaneousExtraRot = EGG::Quatf::ident;
31 m_extraRot = EGG::Quatf::ident;
32 m_movingObjVel.setZero();
33 m_movingRoadVel.setZero();
34 m_pose = EGG::Matrix34f::ident;
38 m_pos = m_dynamics->pos();
45 m_pose.makeQT(m_dynamics->fullRot(), m_dynamics->pos());
57 m_specialRot = m_instantaneousStuntRot * m_decayingStuntRot;
60 m_dynamics->setSpecialRot(m_specialRot);
61 m_dynamics->setExtraRot(m_extraRot);
62 m_dynamics->setScale(scale);
64 m_dynamics->calc(dt, maxSpeed, air);
66 m_decayingStuntRot = m_decayingStuntRot.slerpTo(EGG::Quatf::ident, 0.1f);
69 m_instantaneousStuntRot = EGG::Quatf::ident;
70 m_instantaneousExtraRot = EGG::Quatf::ident;
74void KartPhysics::shiftDecayMovingRoadVel(
const EGG::Vector3f &v, f32 maxPullSpeed) {
77 if (m_movingRoadVel.
squaredLength() > std::numeric_limits<f32>::epsilon()) {
78 f32 speed = std::min(maxPullSpeed, m_movingRoadVel.
normalise());
79 m_movingRoadVel *= speed;
80 m_dynamics->setMovingRoadVel(m_movingRoadVel);
85KartPhysics *KartPhysics::Create(
const KartParam ¶m) {
86 KartPhysics *physics = EGG::egg_new<KartPhysics>(param.isBike());
88 const BSP &bsp = param.bsp();
90 physics->set_fc(physics->hitboxGroup()->initHitboxes(bsp.hitboxes));
92 physics->dynamics()->setBspParams(bsp.angVel0Factor, bsp.cuboids[0], bsp.cuboids[1],
false);
EGG::Vector3f m_zAxis
The third column of the pose.
EGG::Vector3f m_velocity
Copied from KartDynamics.
EGG::Vector3f m_yAxis
The second column of the pose.
EGG::Matrix34f m_pose
The kart's current rotation and position.
void calc(f32 dt, f32 maxSpeed, const EGG::Vector3f &scale, bool air)
Computes trick rotation and calls to KartDynamics::calc().
EGG::Quatf m_decayingExtraRot
Rotation that occurs when landing from a trick.
EGG::Vector3f m_xAxis
The first column of the pose.
void updatePose()
Constructs a transformation matrix from rotation and position.
Pertains to kart-related functionality.
constexpr f32 normalise()
Normalizes the vector and returns the original length.
constexpr f32 squaredLength() const
The dot product between the vector and itself.