A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectBase.hh
1#pragma once
2
3#include "game/field/BoxColManager.hh"
4#include "game/field/RailInterpolator.hh"
5#include "game/field/obj/ObjectId.hh"
6
7#include "game/render/DrawMdl.hh"
8
9#include "game/system/map/MapdataGeoObj.hh"
10
11#include <egg/core/BitFlag.hh>
12#include <egg/math/Matrix.hh>
13
14namespace Field {
15
17public:
18 enum class eFlags {
19 Position = 0,
20 Rotation = 1,
21 Matrix = 2,
22 Scale = 3,
23 };
25
26 ObjectBase(const System::MapdataGeoObj &params);
27 ObjectBase(const char *name, const EGG::Vector3f &pos, const EGG::Vector3f &rot,
28 const EGG::Vector3f &scale);
29 virtual ~ObjectBase();
30
31 virtual void init() {}
32 virtual void calc() {}
33 virtual void calcModel();
34 virtual void load() = 0;
35 [[nodiscard]] virtual const char *getResources() const;
36 virtual void loadGraphics();
37 virtual void loadAnims() {}
38 virtual void createCollision() = 0;
39 virtual void loadRail();
40 virtual void calcCollisionTransform() = 0;
41
42 [[nodiscard]] virtual const char *getName() const;
43
45 [[nodiscard]] virtual u32 loadFlags() const {
46 // TODO: This references LOD to determine load flags
47 return 0;
48 }
49
50 [[nodiscard]] virtual const char *getKclName() const;
51
53 virtual void resize(f32 radius, f32 maxSpeed) {
54 m_boxColUnit->resize(radius, maxSpeed);
55 }
56
58 virtual void unregisterCollision() {
59 BoxColManager::Instance()->remove(m_boxColUnit);
60 }
61
63 virtual void disableCollision() const {
64 m_boxColUnit->m_flag.setBit(eBoxColFlag::Intangible);
65 }
66
68 virtual void enableCollision() const {
69 m_boxColUnit->m_flag.resetBit(eBoxColFlag::Intangible);
70 }
71
73 virtual const BoxColUnit *getUnit() const {
74 return m_boxColUnit;
75 }
76
77 [[nodiscard]] const RailInterpolator *railInterpolator() const {
78 return m_railInterpolator;
79 }
80
82 [[nodiscard]] virtual const EGG::Vector3f &getPosition() const {
83 return m_pos;
84 }
85
87 [[nodiscard]] virtual f32 getCollisionRadius() const {
88 return 100.0f;
89 }
90
92 [[nodiscard]] virtual ObjectId id() const {
93 return m_id;
94 }
95
96 [[nodiscard]] const EGG::Vector3f &pos() const {
97 return m_pos;
98 }
99
100 void setPos(const EGG::Vector3f &pos) {
101 m_flags.setBit(eFlags::Position);
102 m_pos = pos;
103 }
104
105 void setScale(const EGG::Vector3f &scale) {
106 m_flags.setBit(eFlags::Scale);
107 m_scale = scale;
108 }
109
110 void setTransform(const EGG::Matrix34f &mat) {
111 m_flags.setBit(eFlags::Matrix);
112 m_transform = mat;
113 }
114
115 [[nodiscard]] const EGG::Vector3f &scale() const {
116 return m_scale;
117 }
118
119protected:
120 void calcTransform();
121 void linkAnims(const std::span<const char *> &names, const std::span<Render::AnmType> types);
122 void setMatrixTangentTo(const EGG::Vector3f &up, const EGG::Vector3f &tangent);
123 void setMatrixFromOrthonormalBasisAndPos(const EGG::Vector3f &v);
124
125 [[nodiscard]] static f32 CheckPointAgainstLineSegment(const EGG::Vector3f &point,
126 const EGG::Vector3f &a, const EGG::Vector3f &b);
127 [[nodiscard]] static EGG::Vector3f RotateXZByYaw(f32 angle, const EGG::Vector3f &v);
128 [[nodiscard]] static EGG::Vector3f RotateAxisAngle(f32 angle, const EGG::Vector3f &axis,
129 const EGG::Vector3f &v1);
130 static void SetRotTangentHorizontal(EGG::Matrix34f &mat, const EGG::Vector3f &up,
131 const EGG::Vector3f &tangent);
132 [[nodiscard]] static EGG::Matrix34f OrthonormalBasis(const EGG::Vector3f &v);
133 [[nodiscard]] static EGG::Matrix34f RailOrthonormalBasis(
134 const RailInterpolator &railInterpolator);
135
137 [[nodiscard]] static EGG::Vector3f Interpolate(f32 t, const EGG::Vector3f &v0,
138 const EGG::Vector3f &v1) {
139 return v0 + (v1 - v0) * t;
140 }
141
142 Render::DrawMdl *m_drawMdl;
143 Abstract::g3d::ResFile *m_resFile;
144 ObjectId m_id;
145 RailInterpolator *m_railInterpolator;
146 BoxColUnit *m_boxColUnit;
147 Flags m_flags;
148 EGG::Vector3f m_pos;
149 EGG::Vector3f m_rot;
150 EGG::Vector3f m_scale;
151 EGG::Matrix34f m_transform;
152 const System::MapdataGeoObj *m_mapObj;
153};
154
155} // namespace Field
Represents a binary resource file which contains object models, textures, and animations.
Definition ResFile.hh:15
A 3 x 4 matrix.
Definition Matrix.hh:8
static EGG::Vector3f RotateXZByYaw(f32 angle, const EGG::Vector3f &v)
Rotates a vector around the Y-axis and returns the XZ-plane portion of the vector.
static f32 CheckPointAgainstLineSegment(const EGG::Vector3f &point, const EGG::Vector3f &a, const EGG::Vector3f &b)
Calculates on what side of line segment ab point lies.
Pertains to collision.
@ Intangible
Ignore collision with the unit.
Wrapper around an integral type with an enum corresponding to its bits.
Definition BitFlag.hh:16
constexpr TBitFlag< T, E > & resetBit(Es... es)
Resets the corresponding bits for the provided enum values.
Definition BitFlag.hh:68
constexpr TBitFlag< T, E > & setBit(Es... es)
Sets the corresponding bits for the provided enum values.
Definition BitFlag.hh:57
A 3D float vector.
Definition Vector.hh:88
A representation of the boundaries of an entity that has dynamic collision.