Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
ObjectCow.hh
1
#pragma once
2
3
#include "game/field/StateManager.hh"
4
#include "game/field/obj/ObjectCollidable.hh"
5
6
namespace
Kinoko::Field
{
7
8
class
RailInterpolator
;
9
11
class
ObjectCow :
public
ObjectCollidable {
12
public
:
13
ObjectCow(
const
System::MapdataGeoObj
¶ms);
14
~ObjectCow()
override
;
15
16
Kart::Reaction onCollision(
Kart::KartObject
*kartObj, Kart::Reaction reactionOnKart,
17
Kart::Reaction reactionOnObj,
EGG::Vector3f
&hitDepth)
override
;
18
19
protected
:
20
virtual
void
calcFloor();
21
22
void
setup();
23
void
calcPos();
24
f32 setTarget(
const
EGG::Vector3f
&v);
25
27
[[nodiscard]]
static
EGG::Vector3f
Interpolate(f32 t,
const
EGG::Vector3f
&v0,
28
const
EGG::Vector3f
&v1) {
29
return
v0 + (v1 - v0) * t;
30
}
31
32
u32
m_startFrame
;
33
EGG::Vector3f
m_tangent;
34
EGG::Vector3f
m_prevTangent;
35
EGG::Vector3f
m_up;
36
EGG::Vector3f
m_velocity;
37
f32
m_xzSpeed
;
38
f32 m_tangentFactor;
39
EGG::Vector3f
m_floorNrm;
40
EGG::Vector3f
m_state1TargetPos
;
41
EGG::Vector3f
m_targetDir;
42
EGG::Vector3f
m_upForce
;
43
f32 m_interpRate;
44
45
static
constexpr
EGG::Vector3f
GRAVITY_FORCE =
EGG::Vector3f
(0.0f, 2.0f, 0.0f);
46
};
47
49
class
ObjectCowLeader final :
public
ObjectCow,
public
StateManager {
50
friend
class
ObjectCowHerd;
51
52
public
:
53
ObjectCowLeader(
const
System::MapdataGeoObj
¶ms);
54
~ObjectCowLeader()
override
;
55
56
void
init()
override
;
57
void
calc()
override
;
58
60
[[nodiscard]] u32 loadFlags()
const override
{
61
return
1;
62
}
63
64
private
:
65
enum class
AnmType {
66
EatST = 0,
67
Eat = 1,
68
EatED = 2,
69
};
70
71
void
calcFloor()
override
;
72
73
void
enterWait();
74
void
enterEat();
75
void
enterRoam();
76
77
void
calcWait();
78
void
calcEat();
79
void
calcRoam();
80
81
f32 m_railSpeed;
82
bool
m_endedRailSegment;
83
AnmType m_state1AnmType;
84
u16
m_eatFrames
;
85
86
static
constexpr
std::array<StateManagerEntry, 3> STATE_ENTRIES = {{
87
{StateEntry<ObjectCowLeader, &ObjectCowLeader::enterWait, &ObjectCowLeader::calcWait>(
88
0)},
89
{StateEntry<ObjectCowLeader, &ObjectCowLeader::enterEat, &ObjectCowLeader::calcEat>(1)},
90
{StateEntry<ObjectCowLeader, &ObjectCowLeader::enterRoam, &ObjectCowLeader::calcRoam>(
91
2)},
92
}};
93
};
94
96
class
ObjectCowFollower final :
public
ObjectCow,
public
StateManager {
97
friend
class
ObjectCowHerd;
98
99
public
:
100
ObjectCowFollower(
const
System::MapdataGeoObj
¶ms,
const
EGG::Vector3f
&pos, f32 initRot);
101
~ObjectCowFollower()
override
;
102
103
void
init()
override
;
104
void
calc()
override
;
105
107
[[nodiscard]] u32 loadFlags()
const override
{
108
return
1;
109
}
110
112
void
loadRail()
override
{}
113
114
private
:
115
void
enterWait();
116
void
enterFreeRoam();
117
void
enterFollowLeader();
118
119
void
calcWait();
120
void
calcFreeRoam();
121
void
calcFollowLeader();
122
123
const
EGG::Vector3f
m_posOffset;
124
RailInterpolator
*m_rail;
125
u16
m_waitFrames
;
126
f32
m_topSpeed
;
127
bool
m_bStopping
;
128
f32
m_railSegThreshold
;
129
130
static
constexpr
f32 BASE_TOP_SPEED = 2.0f;
131
static
constexpr
f32 TOP_SPEED_VARIANCE = 4.0f - 2.0f;
132
134
static
constexpr
f32
DIST_THRESHOLD
= 200.0f;
135
136
static
constexpr
std::array<StateManagerEntry, 3> STATE_ENTRIES = {{
137
{StateEntry<ObjectCowFollower, &ObjectCowFollower::enterWait,
138
&ObjectCowFollower::calcWait>(0)},
139
{StateEntry<ObjectCowFollower, &ObjectCowFollower::enterFreeRoam,
140
&ObjectCowFollower::calcFreeRoam>(1)},
141
{StateEntry<ObjectCowFollower, &ObjectCowFollower::enterFollowLeader,
142
&ObjectCowFollower::calcFollowLeader>(2)},
143
}};
144
};
145
150
class
ObjectCowHerd final :
public
ObjectCollidable {
151
public
:
152
ObjectCowHerd(
const
System::MapdataGeoObj
¶ms);
153
~ObjectCowHerd()
override
;
154
155
void
init
()
override
;
156
void
calc
()
override
;
157
159
[[nodiscard]] u32 loadFlags()
const override
{
160
return
1;
161
}
162
164
void
createCollision()
override
{}
165
167
void
loadRail()
override
{}
168
169
private
:
170
void
checkIntraCollision
();
171
172
ObjectCowLeader
*m_leader;
173
owning_span<ObjectCowFollower *>
m_followers;
174
};
175
176
}
// namespace Kinoko::Field
Kinoko::Field::ObjectCowFollower::m_railSegThreshold
f32 m_railSegThreshold
The rail segmentT at which a cow will change to state 2.
Definition
ObjectCow.hh:128
Kinoko::Field::ObjectCowFollower::m_waitFrames
u16 m_waitFrames
Number of frames the cow will stand still for.
Definition
ObjectCow.hh:125
Kinoko::Field::ObjectCowFollower::m_bStopping
bool m_bStopping
Set when the cow is coming to a stop.
Definition
ObjectCow.hh:127
Kinoko::Field::ObjectCowFollower::DIST_THRESHOLD
static constexpr f32 DIST_THRESHOLD
Distance at which a cow is considered close enough to the rail to stop moving.
Definition
ObjectCow.hh:134
Kinoko::Field::ObjectCowFollower::m_topSpeed
f32 m_topSpeed
The speed the cow will accelerate up to.
Definition
ObjectCow.hh:126
Kinoko::Field::ObjectCowHerd::calc
void calc() override
Definition
ObjectCow.cc:462
Kinoko::Field::ObjectCowHerd::checkIntraCollision
void checkIntraCollision()
Prevents cows from walking into each other.
Definition
ObjectCow.cc:478
Kinoko::Field::ObjectCowHerd::init
void init() override
Assigns the herd's rail to each child.
Definition
ObjectCow.cc:455
Kinoko::Field::ObjectCowLeader
A cow who its own rail and whose position is not influenced by the path of the others.
Definition
ObjectCow.hh:49
Kinoko::Field::ObjectCowLeader::m_eatFrames
u16 m_eatFrames
Length of the state 1 eat animation.
Definition
ObjectCow.hh:84
Kinoko::Field::ObjectCow::m_xzSpeed
f32 m_xzSpeed
XZ plane length of m_velocity.
Definition
ObjectCow.hh:37
Kinoko::Field::ObjectCow::m_state1TargetPos
EGG::Vector3f m_state1TargetPos
Calculated in enterState1.
Definition
ObjectCow.hh:40
Kinoko::Field::ObjectCow::m_upForce
EGG::Vector3f m_upForce
Used by calcPos to counteract gravity.
Definition
ObjectCow.hh:42
Kinoko::Field::ObjectCow::m_startFrame
u32 m_startFrame
The frame the cow will start moving.
Definition
ObjectCow.hh:32
Kinoko::Field::RailInterpolator
Definition
RailInterpolator.hh:13
Kinoko::Kart::KartObject
The highest level abstraction for a kart.
Definition
KartObject.hh:11
Kinoko::System::MapdataGeoObj
Definition
MapdataGeoObj.hh:9
Kinoko::owning_span
A contiguous storage container that manages the lifecycle of a buffer of a given size.
Definition
Types.hh:31
Kinoko::Field
Pertains to collision.
Definition
BoxColManager.cc:10
Kinoko::EGG::Vector3f
A 3D float vector.
Definition
Vector.hh:107
game
field
obj
ObjectCow.hh
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0