Skip to content

Commit

Permalink
Library/Math: Add complete MathUtil.h
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsterDruide1 committed Jan 2, 2025
1 parent 4b5cee7 commit 4b4ab84
Show file tree
Hide file tree
Showing 45 changed files with 521 additions and 331 deletions.
3 changes: 1 addition & 2 deletions lib/al/Library/Area/AreaShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include "Library/Area/AreaShapeCylinder.h"
#include "Library/Area/AreaShapeInfinite.h"
#include "Library/Area/AreaShapeSphere.h"
#include "Library/Math/MathAngleUtil.h"
#include "Library/Math/MathLengthUtil.h"
#include "Library/Math/MathUtil.h"
#include "Library/Matrix/MatrixUtil.h"

namespace al {
Expand Down
3 changes: 1 addition & 2 deletions lib/al/Library/Collision/CollisionPartsTriangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include "Library/Collision/CollisionParts.h"
#include "Library/Collision/KCollisionServer.h"
#include "Library/Math/MathAngleUtil.h"
#include "Library/Math/MathLengthUtil.h"
#include "Library/Math/MathUtil.h"

namespace al {

Expand Down
2 changes: 1 addition & 1 deletion lib/al/Library/Controller/SpinInputAnalyzer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Library/Controller/SpinInputAnalyzer.h"

#include "Library/Math/MathLengthUtil.h"
#include "Library/Math/MathUtil.h"

namespace al {

Expand Down
3 changes: 2 additions & 1 deletion lib/al/Library/LiveActor/ActorPoseKeeper.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "Library/LiveActor/ActorPoseKeeper.h"

#include "Library/LiveActor/LiveActorUtil.h"
#include "Library/Math/VectorUtil.h"
#include "Library/Math/MathUtil.h"
#include "Library/Math/MtxUtil.h"

namespace al {

Expand Down
2 changes: 0 additions & 2 deletions lib/al/Library/MapObj/BackHideParts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include "Library/LiveActor/ActorInitFunction.h"
#include "Library/LiveActor/ActorModelFunction.h"
#include "Library/LiveActor/ActorPoseKeeper.h"
#include "Library/Math/MathAngleUtil.h"
#include "Library/Math/MathLengthUtil.h"
#include "Library/Math/MathUtil.h"
#include "Library/Model/ModelKeeper.h"
#include "Library/Placement/PlacementFunction.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/al/Library/MapObj/BreakMapPartsBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "Library/LiveActor/ActorMovementFunction.h"
#include "Library/LiveActor/ActorResourceFunction.h"
#include "Library/LiveActor/SubActorKeeper.h"
#include "Library/Math/MathRandomUtil.h"
#include "Library/Math/MathUtil.h"
#include "Library/Nerve/NerveSetupUtil.h"
#include "Library/Obj/PartsFunction.h"
#include "Library/Placement/PlacementFunction.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/al/Library/MapObj/FloaterMapParts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "Library/LiveActor/ActorMovementFunction.h"
#include "Library/LiveActor/ActorPoseKeeper.h"
#include "Library/LiveActor/ActorSensorMsgFunction.h"
#include "Library/Math/MathLengthUtil.h"
#include "Library/Math/MathUtil.h"
#include "Library/Nerve/NerveSetupUtil.h"
#include "Library/Placement/PlacementFunction.h"

Expand Down
2 changes: 1 addition & 1 deletion lib/al/Library/MapObj/RollingCubeMapParts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Library/LiveActor/ActorPoseKeeper.h"
#include "Library/LiveActor/ActorResourceFunction.h"
#include "Library/LiveActor/ActorSensorMsgFunction.h"
#include "Library/Math/MathAngleUtil.h"
#include "Library/Math/MathUtil.h"
#include "Library/Nerve/NerveSetupUtil.h"
#include "Library/Obj/PartsModel.h"
#include "Library/Placement/PlacementFunction.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/al/Library/MapObj/SurfMapParts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "Library/LiveActor/ActorAreaFunction.h"
#include "Library/LiveActor/ActorInitFunction.h"
#include "Library/LiveActor/ActorPoseKeeper.h"
#include "Library/Math/VectorUtil.h"
#include "Library/Math/MathUtil.h"
#include "Library/Nerve/NerveSetupUtil.h"
#include "Library/Placement/PlacementFunction.h"

Expand Down
51 changes: 0 additions & 51 deletions lib/al/Library/Math/MathAngleUtil.h

This file was deleted.

55 changes: 0 additions & 55 deletions lib/al/Library/Math/MathLengthUtil.h

This file was deleted.

52 changes: 0 additions & 52 deletions lib/al/Library/Math/MathRandomUtil.cpp

This file was deleted.

37 changes: 0 additions & 37 deletions lib/al/Library/Math/MathRandomUtil.h

This file was deleted.

48 changes: 48 additions & 0 deletions lib/al/Library/Math/MathUtil.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Library/Math/MathUtil.h"

#include <math/seadMathCalcCommon.h>
#include <random/seadGlobalRandom.h>

namespace al {
f32 normalize(f32 var, f32 min, f32 max) {
Expand Down Expand Up @@ -109,4 +110,51 @@ void calcParabolicFunctionParam(f32* gravity, f32* initialVelY, f32 maxHeight,
*gravity = verticalDistance - *initialVelY;
}


f32 getRandom() {
u32 random = (sead::GlobalRandom::instance()->getU32() >> 9) | 0x3F800000;
return (*reinterpret_cast<f32*>(&random)) - 1;
}

f32 getRandom(f32 factor) {
return getRandom(0.f, factor);
}

f32 getRandom(f32 min, f32 max) {
return (getRandom() * (max - min)) + min;
}

s32 getRandom(s32 factor) {
return getRandom(0, factor);
}

s32 getRandom(s32 min, s32 max) {
return (s32)getRandom((f32)min, (f32)max);
}

f32 getRandomDegree() {
return getRandom(360.f);
}

f32 getRandomRadian() {
return getRandom(6.2832f);
}

void getRandomVector(sead::Vector3f* vec, f32 factor) {
f32 x = (getRandom() * (factor + factor)) - factor;
f32 y = (getRandom() * (factor + factor)) - factor;
f32 z = (getRandom() * (factor + factor)) - factor;
vec->x = x;
vec->y = y;
vec->z = z;
}

void getRandomDir(sead::Vector3f* vec) {
getRandomVector(vec, 10.f);
while (vec->dot(*vec) > 0.000001f)
getRandomVector(vec, 10.f);
vec->normalize();
}


} // namespace al
Loading

0 comments on commit 4b4ab84

Please sign in to comment.