1#include "KartPhysics.hh"
3#include <egg/math/Quat.hh>
8KartPhysics::KartPhysics(
bool isBike) {
9 m_pose = EGG::Matrix34f::ident;
10 m_dynamics = isBike ?
new KartDynamicsBike :
new KartDynamics;
11 m_hitboxGroup =
new CollisionGroup;
16KartPhysics::~KartPhysics() {
22void KartPhysics::reset() {
24 m_hitboxGroup->reset();
25 m_decayingStuntRot = EGG::Quatf::ident;
26 m_instantaneousStuntRot = EGG::Quatf::ident;
27 m_specialRot = EGG::Quatf::ident;
29 m_instantaneousExtraRot = EGG::Quatf::ident;
30 m_extraRot = EGG::Quatf::ident;
31 m_movingObjVel.setZero();
32 m_movingRoadVel.setZero();
33 m_pose = EGG::Matrix34f::ident;
37 m_pos = m_dynamics->pos();
56 m_specialRot = m_instantaneousStuntRot * m_decayingStuntRot;
59 m_dynamics->setSpecialRot(m_specialRot);
60 m_dynamics->setExtraRot(m_extraRot);
61 m_dynamics->setScale(scale);
63 m_dynamics->
calc(dt, maxSpeed, air);
65 m_decayingStuntRot = m_decayingStuntRot.slerpTo(EGG::Quatf::ident, 0.1f);
68 m_instantaneousStuntRot = EGG::Quatf::ident;
69 m_instantaneousExtraRot = EGG::Quatf::ident;
73void KartPhysics::shiftDecayMovingRoadVel(
const EGG::Vector3f &v, f32 maxPullSpeed) {
76 if (m_movingRoadVel.
squaredLength() > std::numeric_limits<f32>::epsilon()) {
77 f32 speed = std::min(maxPullSpeed, m_movingRoadVel.
normalise());
78 m_movingRoadVel *= speed;
79 m_dynamics->setMovingRoadVel(m_movingRoadVel);
84KartPhysics *KartPhysics::Create(
const KartParam ¶m) {
85 KartPhysics *physics =
new KartPhysics(param.isBike());
87 const BSP &bsp = param.bsp();
89 physics->set_fc(physics->hitboxGroup()->initHitboxes(bsp.hitboxes));
91 physics->dynamics()->setBspParams(bsp.angVel0Factor, bsp.cuboids[0], bsp.cuboids[1],
false);
void makeQT(const Quatf &q, const Vector3f &t)
Sets matrix from rotation and position.
void calc(f32 dt, f32 maxSpeed, bool air)
Every frame, computes acceleration, velocity, position and rotation of the kart.
void updatePose()
Constructs a transformation matrix from 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_zAxis
The third column of the pose.
EGG::Vector3f m_xAxis
The first 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.
Pertains to kart-related functionality.
Quatf slerpTo(const Quatf &q2, f32 t) const
Performs spherical linear interpolation.
f32 normalise()
Normalizes the vector and returns the original length.
f32 squaredLength() const
The dot product between the vector and itself.