A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartCamera.hh
1#pragma once
2
3#include "game/kart/KartMove.hh"
4#include "game/kart/KartObjectManager.hh"
5
6namespace Kinoko::Render {
7
10 friend class KartCamera;
11
12public:
14 m_pos.setZero();
15 m_bigAirHeight = 0.0f;
16 m_1c = 0.0f;
17 m_prevPos.setZero();
18 m_dist = 0.0f;
19 m_bigAirFallPitch = 0.0f;
20 m_targetPos.setZero();
21 }
22
23 ~KartCameraState() = default;
24
26 void init() {
27 m_dist = 0.0f;
28 m_bigAirFallPitch = 0.0f;
29 }
30
31private:
32 EGG::Vector3f m_pos;
34 f32 m_1c;
35 EGG::Vector3f m_prevPos;
36 f32 m_dist;
39};
40
44 friend class Host::Context;
45
46public:
48 void init() {
49 auto *param = Kart::KartObjectManager::Instance()->object(0)->param();
50 m_camParams = &param->camera();
51
52 initPos();
53 }
54
55 void calc();
56
57 static KartCamera *CreateInstance();
58 static void DestroyInstance();
59
60 [[nodiscard]] static KartCamera *Instance() {
61 return s_instance;
62 }
63
64private:
65 KartCamera();
67
69 void calcForward(f32 t, const Kart::KartObjectProxy *proxy) {
70 m_forward = Interpolate(t, m_forward, proxy->move()->smoothedForward());
71 m_right = EGG::Vector3f::ey.perpInPlane(m_forward, true);
72 }
73
74 void calcDriftOffset(const Kart::KartObjectProxy *proxy);
75 void calcCamera(f32 param1, f32 param2, f32 param3, KartCameraState &state, bool isBackwards,
76 const Kart::KartObjectProxy *proxy, const EGG::Vector3f &targetPos) const;
77 void calcAirtimeHeight(KartCameraState &state, const Kart::KartObjectProxy *proxy) const;
78 void initPos();
79
80 void calcCollision(KartCameraState &state, bool isRear) const;
81
83 static EGG::Vector3f Interpolate(f32 t, const EGG::Vector3f &v0, const EGG::Vector3f &v1) {
84 return v0 + (v1 - v0) * t;
85 }
86
89 EGG::Vector3f m_forward;
90 EGG::Vector3f m_right;
91
99
102
103 static KartCamera *s_instance;
104};
105
106} // namespace Kinoko::Render
Contexts can be used to restore a previous memory state for the current session.
Definition Context.hh:70
Base class for most kart-related objects.
Tracks the current state of the front and backwards player cameras.
Definition KartCamera.hh:9
f32 m_bigAirFallPitch
Height applied once you start falling after 20 frames of airtime.
Definition KartCamera.hh:37
f32 m_bigAirHeight
Additional camera height applied after 20 frames of airtime.
Definition KartCamera.hh:33
f32 m_dist
Distance away from TODO.
Definition KartCamera.hh:36
EGG::Vector3f m_targetPos
The position the camera looks towards.
Definition KartCamera.hh:38
f32 m_1c
TODO: Seems to be related to boost-induced pitch.
Definition KartCamera.hh:34
Manager class for the forward and backwards cameras.
Definition KartCamera.hh:43
const Kart::KartParam::KartCameraParam * m_camParams
Definition KartCamera.hh:98
f32 m_hopPosY
Induces a downwards camera position offset.
Definition KartCamera.hh:88
f32 m_driftYaw
Rotation induced when drifting.
Definition KartCamera.hh:87
KartCameraState m_forwardCamera
Forward camera state.
KartCameraState m_backwardCamera
Rear camera state.
Pertains to rendering the kart model.
A 3D float vector.
Definition Vector.hh:107
constexpr Vector3f perpInPlane(const EGG::Vector3f &rhs, bool normalise) const
Calculates the orthogonal vector, based on the plane defined by this vector and rhs.
Definition Vector.hh:346