mirror of https://github.com/bjornbytes/lovr.git
lovr.math.noise;
This commit is contained in:
parent
9208474203
commit
fedab9e46f
|
@ -67,6 +67,19 @@ int l_lovrMathOrientationToDirection(lua_State* L) {
|
|||
return 3;
|
||||
}
|
||||
|
||||
int l_lovrMathNoise(lua_State* L) {
|
||||
switch (lua_gettop(L)) {
|
||||
case 0:
|
||||
case 1: lua_pushnumber(L, lovrMathNoise1(luaL_checknumber(L, 1))); return 1;
|
||||
case 2: lua_pushnumber(L, lovrMathNoise2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); return 1;
|
||||
case 3: lua_pushnumber(L, lovrMathNoise3(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3))); return 1;
|
||||
case 4:
|
||||
default:
|
||||
lua_pushnumber(L, lovrMathNoise4(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4)));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int l_lovrMathRandom(lua_State* L) {
|
||||
luax_pushtype(L, RandomGenerator, lovrMathGetRandomGenerator());
|
||||
lua_insert(L, 1);
|
||||
|
@ -130,6 +143,7 @@ const luaL_Reg lovrMath[] = {
|
|||
{ "newTransform", l_lovrMathNewTransform },
|
||||
{ "orientationToDirection", l_lovrMathOrientationToDirection },
|
||||
{ "lookAt", l_lovrMathLookAt },
|
||||
{ "noise", l_lovrMathNoise },
|
||||
{ "random", l_lovrMathRandom },
|
||||
{ "randomNormal", l_lovrMathRandomNormal },
|
||||
{ "getRandomSeed", l_lovrMathGetRandomSeed },
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "math.h"
|
||||
#include "lib/noise1234/noise1234.h"
|
||||
#include "util.h"
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
@ -47,3 +48,19 @@ float lovrMathLinearToGamma(float x) {
|
|||
return 1.055 * powf(x, 1. / 2.4) - .055;
|
||||
}
|
||||
}
|
||||
|
||||
float lovrMathNoise1(float x) {
|
||||
return noise1(x) * .5f + .5f;
|
||||
}
|
||||
|
||||
float lovrMathNoise2(float x, float y) {
|
||||
return noise2(x, y) * .5f + .5f;
|
||||
}
|
||||
|
||||
float lovrMathNoise3(float x, float y, float z) {
|
||||
return noise3(x, y, z) * .5f + .5f;
|
||||
}
|
||||
|
||||
float lovrMathNoise4(float x, float y, float z, float w) {
|
||||
return noise4(x, y, z, w) * .5f + .5f;
|
||||
}
|
||||
|
|
|
@ -24,3 +24,7 @@ RandomGenerator* lovrMathGetRandomGenerator();
|
|||
void lovrMathOrientationToDirection(float angle, float ax, float ay, float az, vec3 v);
|
||||
float lovrMathGammaToLinear(float x);
|
||||
float lovrMathLinearToGamma(float x);
|
||||
float lovrMathNoise1(float x);
|
||||
float lovrMathNoise2(float x, float y);
|
||||
float lovrMathNoise3(float x, float y, float z);
|
||||
float lovrMathNoise4(float x, float y, float z, float w);
|
||||
|
|
Loading…
Reference in New Issue