NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
c_lib.hpp
1#pragma once
2#include <types.h>
3#include <game/mLib/m_vec.hpp>
4
5/// @brief Provides common utilities.
6/// @ingroup clib
7namespace cLib {
8 void memSet(void *dst, int val, ulong size); ///< See memset.
9
10 /// @brief Checks if a floating-point value is effectively zero within epsilon tolerance.
11 /// @param val The float value to evaluate.
12 /// @return @p true if the absolute value is less than FLT_EPSILON, @p false otherwise.
13 inline bool isZero(float val) {
14 return (std::fabs(val) < FLT_EPSILON);
15 }
16
17 /// @brief Calculates the yaw (Y-axis) orientation angle from an origin position to a target position.
18 /// @param vec1 The origin position vector.
19 /// @param vec2 The target position vector.
20 /// @return The calculated yaw value.
21 s16 targetAngleY(const mVec3_c &vec1, const mVec3_c &vec2);
22
23 /// @brief Calculates the pitch (X-axis) orientation angle from an origin position to a target position.
24 /// @param vec1 The origin position vector.
25 /// @param vec2 The target position vector.
26 /// @return The calculated pitch value.
27 s16 targetAngleX(const mVec3_c &vec1, const mVec3_c &vec2);
28
29 /**
30 * @brief Smoothly moves @p currentPos towards @p targetPos using proportional scaling.
31 * @details If the applied step overshoots the target, the position is snapped exactly to the target.
32 * @param currentPos The position to be updated.
33 * @param targetPos The target position.
34 * @param ratio The smoothing ratio (between @p 0.0f and @p 1.0f). Higher value means snappier movement.
35 * @param maxStep The maximum step for a single update.
36 * @param minStep The minimum step to prevent jittering.
37 * @return The absolute remaining distance to the target position.
38 */
39 float addCalcPos(mVec3_c *currentPos, const mVec3_c &targetPos, float ratio, float maxStep, float minStep);
40
41 /** @brief Moves @p currentPos towards @p targetPos by a fixed @p step amount.
42 * @details If the applied step overshoots the target, the position is snapped exactly to the target.
43 * @param currentPos The position to be updated.
44 * @param targetPos The target position.
45 * @param step The step value.
46 * @return @p true if the position reached the target, @p false otherwise.
47 */
48 bool chasePos(mVec3_c *currentPos, const mVec3_c &targetPos, float step);
49
50} // namespace cLib
A three-dimensional floating point vector.
Definition m_vec.hpp:122
Provides common utilities.
Definition c_lib.cpp:13
float addCalcPos(mVec3_c *currPos, const mVec3_c &targetPos, float ratio, float maxStep, float minStep)
Smoothly moves currentPos towards targetPos using proportional scaling.
Definition c_lib.cpp:19
bool isZero(float val)
Checks if a floating-point value is effectively zero within epsilon tolerance.
Definition c_lib.hpp:13
void memSet(void *dst, int val, ulong size)
See memset.
Definition c_lib.cpp:15
bool chasePos(mVec3_c *currentPos, const mVec3_c &targetPos, float step)
Moves currentPos towards targetPos by a fixed step amount.
Definition c_lib.cpp:45
s16 targetAngleY(const mVec3_c &vec1, const mVec3_c &vec2)
Calculates the yaw (Y-axis) orientation angle from an origin position to a target position.
Definition c_lib.cpp:60
s16 targetAngleX(const mVec3_c &vec1, const mVec3_c &vec2)
Calculates the pitch (X-axis) orientation angle from an origin position to a target position.
Definition c_lib.cpp:64