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 disableCollision() const {
59 m_boxColUnit->m_flag.setBit(eBoxColFlag::Intangible);
60 }
61
63 virtual void enableCollision() const {
64 m_boxColUnit->m_flag.resetBit(eBoxColFlag::Intangible);
65 }
66
68 [[nodiscard]] virtual const EGG::Vector3f &getPosition() const {
69 return m_pos;
70 }
71
73 [[nodiscard]] virtual f32 getCollisionRadius() const {
74 return 100.0f;
75 }
76
78 [[nodiscard]] virtual ObjectId id() const {
79 return m_id;
80 }
81
82 [[nodiscard]] const EGG::Vector3f &pos() const {
83 return m_pos;
84 }
85
86 void setPos(const EGG::Vector3f &pos) {
87 m_flags.setBit(eFlags::Position);
88 m_pos = pos;
89 }
90
91 void setScale(const EGG::Vector3f &scale) {
92 m_flags.setBit(eFlags::Scale);
93 m_scale = scale;
94 }
95
96 void setTransform(const EGG::Matrix34f &mat) {
97 m_flags.setBit(eFlags::Matrix);
98 m_transform = mat;
99 }
100
101 [[nodiscard]] const EGG::Vector3f &scale() const {
102 return m_scale;
103 }
104
105protected:
106 void calcTransform();
107 void linkAnims(const std::span<const char *> &names, const std::span<Render::AnmType> types);
108 void setMatrixTangentTo(const EGG::Vector3f &up, const EGG::Vector3f &tangent);
109
110 [[nodiscard]] static f32 CheckPointAgainstLineSegment(const EGG::Vector3f &point,
111 const EGG::Vector3f &a, const EGG::Vector3f &b);
112 [[nodiscard]] static EGG::Vector3f RotateXZByYaw(f32 angle, const EGG::Vector3f &v);
113 [[nodiscard]] static EGG::Vector3f RotateAxisAngle(f32 angle, const EGG::Vector3f &axis,
114 const EGG::Vector3f &v1);
115 static void SetRotTangentHorizontal(EGG::Matrix34f &mat, const EGG::Vector3f &up,
116 const EGG::Vector3f &tangent);
117 [[nodiscard]] static EGG::Matrix34f OrthonormalBasis(const EGG::Vector3f &v);
118 [[nodiscard]] static EGG::Matrix34f RailOrthonormalBasis(
119 const RailInterpolator &railInterpolator);
120
122 [[nodiscard]] static EGG::Vector3f Interpolate(f32 t, const EGG::Vector3f &v0,
123 const EGG::Vector3f &v1) {
124 return v0 + (v1 - v0) * t;
125 }
126
127 Render::DrawMdl *m_drawMdl;
128 Abstract::g3d::ResFile *m_resFile;
129 ObjectId m_id;
130 RailInterpolator *m_railInterpolator;
131 BoxColUnit *m_boxColUnit;
132 Flags m_flags;
133 EGG::Vector3f m_pos;
134 EGG::Vector3f m_rot;
135 EGG::Vector3f m_scale;
136 EGG::Matrix34f m_transform;
137 const System::MapdataGeoObj *m_mapObj;
138};
139
140} // 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:87
A representation of the boundaries of an entity that has dynamic collision.