6#include "models/makoto.hpp"
14 walkAnim = (int)MODEL_MAKOTO_PLAYER_ROOT_MODEL_MOTION_0002;
15 idleAnim = (int)MODEL_MAKOTO_PLAYER_ROOT_MODEL_MOTION;
25 ae::q20_12_t cameraAngle = CameraSystem::getInstance().getMovementAngle();
26 ae::q20_12_t forwardX;
27 ae::q20_12_t forwardZ;
31 ae::q20_12_t deltaX{0};
32 ae::q20_12_t deltaZ{0};
37 ae::q20_12_t angleRad;
39 const ae::q20_12_t sinVal = ae::q20_12_t{
math.sin(cameraAngle)};
40 const ae::q20_12_t cosVal = ae::q20_12_t{
math.cos(cameraAngle)};
42 forwardX = -sinVal *
config.speed;
43 forwardZ = cosVal *
config.speed;
44 rightX = cosVal *
config.speed;
45 rightZ = sinVal *
config.speed;
71 if (deltaX != ae::q20_12_t{0} || deltaZ != ae::q20_12_t{0})
80 if (deltaX != ae::q20_12_t{0} && deltaZ != ae::q20_12_t{0})
82 const ae::q20_12_t invSqrt2{0.707106781187};
97 nextX =
config.characterTranslate.x + deltaX;
98 nextZ =
config.characterTranslate.z + deltaZ;
103 config.characterTranslate.x = nextX;
104 config.characterTranslate.z = nextZ;
109 config.characterTranslate.x = nextX;
114 config.characterTranslate.z = nextZ;
117 if (deltaX != ae::q20_12_t{0} || deltaZ != ae::q20_12_t{0})
119 angleRad =
math.atan2(deltaX, deltaZ);
120 config.characterFacingAngle = angleRad *
math.div(ae::q20_12_t{180}, ae::q20_12_t{3.14159265});
146 charPos.
x =
config.characterTranslate.x;
147 charPos.
z =
config.characterTranslate.z;
166 if (
config.collisionMap ==
nullptr || tileX < 0 || tileX >=
config.mapWidth || tileZ < 0 ||
167 tileZ >=
config.mapHeight)
178 if (
config.tileSize <= ae::q20_12_t{0})
184 const ae::q20_12_t radiusX =
config.characterSize.x * ae::q20_12_t{0.5};
185 const ae::q20_12_t radiusZ =
config.characterSize.z * ae::q20_12_t{0.5};
186 const ae::q20_12_t minX = worldX - radiusX +
config.worldOffsetX;
187 const ae::q20_12_t maxX = worldX + radiusX +
config.worldOffsetX;
188 const ae::q20_12_t minZ = worldZ - radiusZ +
config.worldOffsetZ;
189 const ae::q20_12_t maxZ = worldZ + radiusZ +
config.worldOffsetZ;
190 if (minX < ae::q20_12_t{0} || minZ < ae::q20_12_t{0} || maxX >=
config.tileSize * ae::q20_12_t{
config.mapWidth} ||
191 maxZ >=
config.tileSize * ae::q20_12_t{
config.mapHeight})
195 const int tileMinX =
static_cast<int>(
math.div(minX,
config.tileSize));
196 const int tileMaxX =
static_cast<int>(
math.div(maxX,
config.tileSize));
197 const int tileMinZ =
static_cast<int>(
math.div(minZ,
config.tileSize));
198 const int tileMaxZ =
static_cast<int>(
math.div(maxZ,
config.tileSize));
199 for (
int z = tileMinZ; z <= tileMaxZ; z++)
201 for (
int x = tileMinX; x <= tileMaxX; x++)
215 const ae::q20_12_t maxStep = ae::q20_12_t{0.08};
216 if (heightChange > maxStep || heightChange < -maxStep)
227 for (
int i = 0; i <
config.stairCount; ++i)
229 const auto& s =
config.stairs[i];
231 const ae::q20_12_t dx = s.x1 - s.x0;
232 const ae::q20_12_t dz = s.z1 - s.z0;
233 const ae::q20_12_t len2 = dx * dx + dz * dz;
235 if (len2 == ae::q20_12_t{0})
240 const ae::q20_12_t px = x - s.x0;
241 const ae::q20_12_t pz = z - s.z0;
244 const ae::q20_12_t dot = px * dx + pz * dz;
246 if (dot < ae::q20_12_t{0} || dot > len2)
252 const ae::q20_12_t cross = px * dz - pz * dx;
254 if (cross * cross > s.halfWidth * s.halfWidth * len2)
259 const ae::q20_12_t t =
math.div(dot, len2);
260 return s.y0 + t * (s.y1 - s.y0);
263 for (
int i = 0; i <
config.landingCount; ++i)
265 const auto& f =
config.landings[i];
267 if (x >= f.minX && x <= f.maxX && z >= f.minZ && z <= f.maxZ)
Orchestrates the movement & view logic for a 3D environment view.
static bool enableCharacterAnim
void update(ae::q20_12_t) override
Core update loop that calculates the character & camera movement.
void start()
Start the update(ae::q20_12_t) loop by setting active to true.
TileType isTileAt()
Get the tile value at the current character position.
void configureMovement(const MovementConfig &config)
Configure the movement system.
void stop()
Stop the update(ae::q20_12_t) loop by setting active to false.
bool isTileWalkable(ae::q20_12_t worldX, ae::q20_12_t worldZ)
Checks for collision at the given position.
CharacterPosition isCharacterAt()
Get the current character position.
ae::q20_12_t getGroundHeight(ae::q20_12_t x, ae::q20_12_t z) const
AnimationController * animationCtrl
Holds global variables used game-wide.
volatile u32 systemKeysHeld
void logMessage(LogSeverity severity, std::string_view message, std::source_location location)
Logs a diagnostic message and halts only for fatal messages.
Util to handle error logging.
Event payload to set the character position data.
A struct that holds initial config values for the MovementComponent.