|
|
uint32_t bitReverse32(uint32_t x);
uint32_t reverseBits(uint32_t n, int len);
// prepare the pcg for use
void pcg_init(PCG* pcg, uint64_t seed);
// returns a random number in (-1, 1) uninclusive
float pcg_f(uint64_t* state, uint64_t stream);
// returns a random number in [0, UINT32_MAX] inclusive
uint32_t pcg_u32(uint64_t* state, uint64_t stream);
float frandPCG(float low, float high, PCG* pcg);
int32_t irandPCG(int32_t low, int32_t high, PCG* pcg);
#ifndef C3DLAS_NO_LIBC_RAND
static inline float frand(float low, float high) {
return low + ((high - low) * ((float)rand() / (float)RAND_MAX));
}
static inline float frandNorm(void) {
return ((float)rand() / (float)RAND_MAX);
}
static inline float frandNorm2(void) {
return ((float)rand() / (float)RAND_MAX) * 2.0 - 1.0;
}
static inline double drand(double low, double high) {
return low + ((high - low) * ((double)rand() / (double)RAND_MAX));
}
static inline double drandNorm(void) {
return ((double)rand() / (double)RAND_MAX);
}
#endif
static inline float fclamp(float val, float min, float max) {
return fminf(max, fmaxf(min, val));
}
static inline double dclamp(double val, double min, double max) {
return fmin(max, fmax(min, val));
}
static inline float fclampNorm(float val) {
return fclamp(val, 0.0f, 1.0f);
}
static inline double dclampNorm(double val) {
return dclamp(val, 0.0, 1.0);
}
static inline int iclamp(int val, int min, int max) {
return MIN(max, MAX(min, val));
}
static inline long lclamp(long val, long min, long max) {
return MIN(max, MAX(min, val));
}
static inline float flerp(float a, float b, float t) {
return a + ((b - a) * t);
}
static inline double dlerp(double a, double b, double t) {
return a + ((b - a) * t);
}
static inline float flerp2D(float xx, float xy, float yx, float yy, float xt, float yt) {
float a = xx + ((xy - xx) * yt);
float b = yx + ((yy - yx) * yt);
return a + ((b - a) * xt);
}
static inline double dlerp2D(double xx, double xy, double yx, double yy, double xt, double yt) {
double a = xx + ((xy - xx) * yt);
double b = yx + ((yy - yx) * yt);
return a + ((b - a) * xt);
}
static inline float fsmoothstep(float a, float b, float t) {
float x = (t - a) / (b - a);
x = fminf(fmaxf(0.f, x), 1.f);
return x * x * (3.f - 2.f * x);
}
static inline double dsmoothstep(double a, double b, double t) {
double x = (t - a) / (b - a);
x = fminf(fmaxf(0., x), 1.);
return x * x * (3. - 2. * x);
}
#define smoothstep(a, b, t) _Generic(t, \
float: fsmoothstep, \
double: dsmoothstep \
)(a, b, t)
static inline float fsmootherstep(float a, float b, float t) {
if(t < 0.f) return a;
if(t > 1.f) return b;
return (b - a) * ((t * (t * 6.0f - 15.0f) + 10.0f) * t * t * t) + a;
}
static inline double dsmootherstep(double a, double b, double t) {
if(t < 0.0) return a;
if(t > 1.0) return b;
return (b - a) * ((t * (t * 6.0 - 15.0) + 10.0) * t * t * t) + a;
}
void vRandomPCG3p(Vector3* end1, Vector3* end2, PCG* pcg, Vector3* out);
Vector3 vRandomPCG3(Vector3 end1, Vector3 end2, PCG* pcg);
void vRandomNormPCG3p(PCG* pcg, Vector3* out);
Vector3 vRandomNormPCG3(PCG* pcg);
void vRandomPCG2p(Vector2* end1, Vector2* end2, PCG* pcg, Vector2* out);
Vector2 vRandomPCG2(Vector2 end1, Vector2 end2, PCG* pcg);
void vRandomNormPCG2p(PCG* pcg, Vector2* out);
Vector2 vRandomNormPCG2(PCG* pcg);
void vRandom3p(Vector3* end1, Vector3* end2, Vector3* out);
Vector3 vRandom3(Vector3 end1, Vector3 end2);
void vRandomNorm3p(Vector3* out);
|