mirror of https://github.com/bjornbytes/lovr.git
lovr.math.orientationToDirection;
This commit is contained in:
parent
e2f4d23842
commit
447b2da41a
|
@ -54,6 +54,19 @@ int l_lovrMathLookAt(lua_State* L) {
|
|||
return 4;
|
||||
}
|
||||
|
||||
int l_lovrMathOrientationToDirection(lua_State* L) {
|
||||
float angle = luaL_checknumber(L, 1);
|
||||
float ax = luaL_optnumber(L, 2, 0);
|
||||
float ay = luaL_optnumber(L, 3, 1);
|
||||
float az = luaL_optnumber(L, 4, 0);
|
||||
float v[3];
|
||||
lovrMathOrientationToDirection(angle, ax, ay, az, v);
|
||||
lua_pushnumber(L, v[0]);
|
||||
lua_pushnumber(L, v[1]);
|
||||
lua_pushnumber(L, v[2]);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int l_lovrMathRandom(lua_State* L) {
|
||||
luax_pushtype(L, RandomGenerator, lovrMathGetRandomGenerator());
|
||||
lua_insert(L, 1);
|
||||
|
@ -81,6 +94,7 @@ int l_lovrMathSetRandomSeed(lua_State* L) {
|
|||
const luaL_Reg lovrMath[] = {
|
||||
{ "newRandomGenerator", l_lovrMathNewRandomGenerator },
|
||||
{ "newTransform", l_lovrMathNewTransform },
|
||||
{ "orientationToDirection", l_lovrMathOrientationToDirection },
|
||||
{ "lookAt", l_lovrMathLookAt },
|
||||
{ "random", l_lovrMathRandom },
|
||||
{ "randomNormal", l_lovrMathRandomNormal },
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "math.h"
|
||||
#include "math/vec3.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
|
@ -18,3 +20,11 @@ void lovrMathDestroy() {
|
|||
RandomGenerator* lovrMathGetRandomGenerator() {
|
||||
return generator;
|
||||
}
|
||||
|
||||
void lovrMathOrientationToDirection(float angle, float ax, float ay, float az, vec3 v) {
|
||||
float sinTheta = sin(angle);
|
||||
float cosTheta = cos(angle);
|
||||
v[0] = sinTheta * -ay + (1 - cosTheta) * -az * ax;
|
||||
v[1] = sinTheta * ax + (1 - cosTheta) * -az * ay;
|
||||
v[2] = -cosTheta + (1 - cosTheta) * -az * az;
|
||||
}
|
||||
|
|
|
@ -14,3 +14,4 @@ typedef vec_t(mat4) vec_mat4_t;
|
|||
void lovrMathInit();
|
||||
void lovrMathDestroy();
|
||||
RandomGenerator* lovrMathGetRandomGenerator();
|
||||
void lovrMathOrientationToDirection(float angle, float ax, float ay, float az, vec3 v);
|
||||
|
|
Loading…
Reference in New Issue