A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectShip64.cc
1#include "ObjectShip64.hh"
2
3namespace Kinoko::Field {
4
6ObjectShip64::ObjectShip64(const System::MapdataGeoObj &params) : ObjectCollidable(params) {}
7
9ObjectShip64::~ObjectShip64() {
10 EGG::egg_delete(m_auxCollision);
11}
12
14void ObjectShip64::init() {
15 m_railInterpolator->init(0, 0);
16
17 m_tangent = m_railInterpolator->curTangentDir();
18 m_railInterpolator->setPerPointVelocities(true);
19
20 calc();
21 calcModel();
22}
23
25void ObjectShip64::calc() {
26 m_railInterpolator->calc();
27
28 setPos(m_railInterpolator->curPos());
29
30 m_tangent = Interpolate(0.2f, m_tangent, m_railInterpolator->curTangentDir());
31 m_tangent.normalise();
32
33 setMatrixFromOrthonormalBasisAndPos(m_tangent);
34}
35
37void ObjectShip64::createCollision() {
38 constexpr f32 RADIUS = 1500.0f;
39 constexpr f32 HEIGHT = 3500.0f;
40
41 ObjectCollidable::createCollision();
42 m_auxCollision = EGG::egg_new<ObjectCollisionCylinder>(RADIUS, HEIGHT, EGG::Vector3f::zero);
43}
44
46void ObjectShip64::calcCollisionTransform() {
47 ObjectCollidable::calcCollisionTransform();
48 calcTransform();
49 EGG::Matrix34f mat = transform();
50
51 EGG::Vector3f v;
52 v = mat.base(0);
53 v.normalise();
54
55 mat.setAxisRotation(F_PI / 2.0f, v);
56 mat.setBase(3, v);
57 m_auxCollision->transform(mat, scale());
58}
59
61bool ObjectShip64::checkCollision(ObjectCollisionBase *lhs, EGG::Vector3f &dist) {
62 EGG::Vector3f colDist = EGG::Vector3f::zero;
63 EGG::Vector3f auxDist = EGG::Vector3f::zero;
64
65 bool has_col = lhs->check(*m_collision, colDist) || lhs->check(*m_auxCollision, auxDist);
66 dist = colDist + auxDist;
67
68 return has_col;
69}
70
71} // namespace Kinoko::Field
Pertains to collision.