mirror of
https://github.com/MonsterDruide1/OdysseyDecomp
synced 2026-05-13 02:38:11 +00:00
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
#include "Library/Math/MathRandomUtil.h"
|
|
|
|
#include <random/seadGlobalRandom.h>
|
|
|
|
namespace al {
|
|
|
|
float getRandom() {
|
|
unsigned int random = (sead::GlobalRandom::instance()->getU32() >> 9) | 0x3F800000;
|
|
return (*reinterpret_cast<float*>(&random)) - 1;
|
|
}
|
|
float getRandom(float factor) {
|
|
return getRandom(0.f, factor);
|
|
}
|
|
float getRandom(float min, float max) {
|
|
return (getRandom() * (max - min)) + min;
|
|
}
|
|
|
|
int getRandom(int factor) {
|
|
return getRandom(0, factor);
|
|
}
|
|
int getRandom(int min, int max) {
|
|
return (int)getRandom((float)min, (float)max);
|
|
}
|
|
|
|
float getRandomDegree() {
|
|
return getRandom(360.f);
|
|
}
|
|
float getRandomRadian() {
|
|
return getRandom(6.2832f);
|
|
}
|
|
|
|
void getRandomVector(sead::Vector3f* vec, float factor) {
|
|
float x = (getRandom() * (factor + factor)) - factor;
|
|
float y = (getRandom() * (factor + factor)) - factor;
|
|
float 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
|