Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
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
14
namespace
Kinoko::Field
{
15
16
class
ObjectBase {
17
public
:
18
enum class
eFlags {
19
Position = 0,
20
Rotation = 1,
21
Matrix = 2,
22
Scale = 3,
23
};
24
typedef
EGG::TBitFlag<u16, eFlags>
Flags;
25
26
ObjectBase(
const
System::MapdataGeoObj
¶ms);
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
void
setPos(
const
EGG::Vector3f
&pos) {
97
m_flags.setBit(eFlags::Position);
98
m_pos = pos;
99
}
100
101
void
addPos(
const
EGG::Vector3f
&v) {
102
m_flags.setBit(eFlags::Position);
103
m_pos += v;
104
}
105
106
void
subPos(
const
EGG::Vector3f
&v) {
107
m_flags.setBit(eFlags::Position);
108
m_pos -= v;
109
}
110
111
void
setScale(
const
EGG::Vector3f
&scale) {
112
m_flags.setBit(eFlags::Scale);
113
m_scale = scale;
114
}
115
116
void
setScale(f32 scale) {
117
m_flags.setBit(eFlags::Scale);
118
m_scale.set(scale);
119
}
120
121
void
setRot(
const
EGG::Vector3f
&rot) {
122
m_flags.setBit(eFlags::Rotation);
123
m_rot = rot;
124
}
125
126
void
setRotNoFlag(
const
EGG::Vector3f
&rot) {
127
m_rot = rot;
128
}
129
130
void
addRot(
const
EGG::Vector3f
&v) {
131
m_rotLock =
true
;
132
m_flags.setBit(eFlags::Rotation);
133
m_rot += v;
134
}
135
136
void
subRot(
const
EGG::Vector3f
&v) {
137
m_rotLock =
true
;
138
m_flags.setBit(eFlags::Rotation);
139
m_rot -= v;
140
}
141
143
void
setTransform(
const
EGG::Matrix34f
&mat) {
144
m_rotLock =
false
;
145
m_flags.setBit(eFlags::Matrix);
146
m_transform = mat;
147
m_pos = mat.
base
(3);
148
}
149
150
[[nodiscard]]
const
EGG::Vector3f
&pos()
const
{
151
return
m_pos;
152
}
153
154
[[nodiscard]]
const
EGG::Vector3f
&scale()
const
{
155
return
m_scale;
156
}
157
158
[[nodiscard]]
const
EGG::Vector3f
&rot()
const
{
159
return
m_rot;
160
}
161
162
[[nodiscard]]
const
EGG::Matrix34f
&transform()
const
{
163
return
m_transform;
164
}
165
166
protected
:
167
void
calcTransform();
168
void
calcRotLock();
169
void
linkAnims(
const
std::span<const char *> &names,
const
std::span<Render::AnmType> types);
170
void
setMatrixTangentTo(
const
EGG::Vector3f
&up,
const
EGG::Vector3f
&tangent);
171
void
setMatrixFromOrthonormalBasisAndPos(
const
EGG::Vector3f
&v);
172
173
[[nodiscard]]
static
f32
CheckPointAgainstLineSegment
(
const
EGG::Vector3f
&point,
174
const
EGG::Vector3f
&a,
const
EGG::Vector3f
&b);
175
[[nodiscard]]
static
EGG::Vector3f
RotateXZByYaw
(f32 angle,
const
EGG::Vector3f
&v);
176
[[nodiscard]]
static
EGG::Vector3f
RotateAxisAngle(f32 angle,
const
EGG::Vector3f
&axis,
177
const
EGG::Vector3f
&v1);
178
static
void
SetRotTangentHorizontal(
EGG::Matrix34f
&mat,
const
EGG::Vector3f
&up,
179
const
EGG::Vector3f
&tangent);
180
[[nodiscard]]
static
EGG::Matrix34f
OrthonormalBasis(
const
EGG::Vector3f
&v);
181
[[nodiscard]]
static
EGG::Matrix34f
RailOrthonormalBasis(
182
const
RailInterpolator
&railInterpolator);
183
[[nodiscard]]
static
EGG::Vector3f
AdjustVecForward(f32 sidewaysScalar, f32 forwardScalar,
184
f32 minSpeed,
const
EGG::Vector3f
&src,
EGG::Vector3f
forward);
185
188
[[nodiscard]]
static
f32
CalcParabolicDisplacement
(f32 initVel, f32 accel, u32 frame) {
189
f32 t =
static_cast<
f32
>
(frame);
190
return
initVel * t - t * (0.5f * accel * t);
191
}
192
194
[[nodiscard]]
static
EGG::Vector3f
Interpolate(f32 t,
const
EGG::Vector3f
&v0,
195
const
EGG::Vector3f
&v1) {
196
return
v0 + (v1 - v0) * t;
197
}
198
199
Render::DrawMdl
*m_drawMdl;
200
Abstract::g3d::ResFile
*m_resFile;
201
ObjectId m_id;
202
RailInterpolator *m_railInterpolator;
203
BoxColUnit *m_boxColUnit;
204
const
System::MapdataGeoObj
*m_mapObj;
205
206
private
:
207
Flags m_flags;
208
EGG::Vector3f
m_pos;
209
EGG::Vector3f
m_scale;
210
EGG::Vector3f
m_rot;
211
bool
m_rotLock;
212
EGG::Matrix34f
m_transform;
213
};
214
215
}
// namespace Kinoko::Field
Kinoko::Abstract::g3d::ResFile
Represents a binary resource file which contains object models, textures, and animations.
Definition
ResFile.hh:14
Kinoko::EGG::Matrix34f
A 3 x 4 matrix.
Definition
Matrix.hh:10
Kinoko::EGG::Matrix34f::base
constexpr Vector3f base(size_t col) const
Get a particular column from a matrix.
Definition
Matrix.hh:408
Kinoko::Field::ObjectBase::CheckPointAgainstLineSegment
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.
Definition
ObjectBase.cc:157
Kinoko::Field::ObjectBase::RotateXZByYaw
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.
Definition
ObjectBase.cc:164
Kinoko::Field::ObjectBase::CalcParabolicDisplacement
static f32 CalcParabolicDisplacement(f32 initVel, f32 accel, u32 frame)
Solves the standard kinematic equation .
Definition
ObjectBase.hh:188
Kinoko::Field::RailInterpolator
Definition
RailInterpolator.hh:13
Kinoko::Render::DrawMdl
Definition
DrawMdl.hh:7
Kinoko::System::MapdataGeoObj
Definition
MapdataGeoObj.hh:9
Kinoko::Field
Pertains to collision.
Definition
BoxColManager.cc:8
Kinoko::Field::eBoxColFlag::Intangible
@ Intangible
Ignore collision with the unit.
Definition
BoxColManager.hh:33
Kinoko::EGG::TBitFlag
Wrapper around an integral type with an enum corresponding to its bits.
Definition
BitFlag.hh:23
Kinoko::EGG::Vector3f
A 3D float vector.
Definition
Vector.hh:107
Kinoko::Field::BoxColUnit
A representation of the boundaries of an entity that has dynamic collision.
Definition
BoxColManager.hh:40
game
field
obj
ObjectBase.hh
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0