mirror of https://github.com/bjornbytes/lovr.git
Split mat4_getTransform;
This commit is contained in:
parent
801f997b0a
commit
c2fc7daf2d
|
@ -54,7 +54,9 @@ ffi.cdef [[
|
|||
mat4* mat4_rotate(mat4* m, float angle, float x, float y, float z);
|
||||
mat4* mat4_rotateQuat(mat4* m, quat* q);
|
||||
mat4* mat4_scale(mat4* m, float x, float y, float z);
|
||||
void mat4_getTransform(mat4* m, float* x, float* y, float* z, float* sx, float* sy, float* sz, float* angle, float* ax, float* ay, float* az);
|
||||
mat4* mat4_getPosition(mat4* m, float* position);
|
||||
mat4* mat4_getOrientation(mat4* m, float* orientation);
|
||||
mat4* mat4_getScale(mat4* m, float* scale);
|
||||
mat4* mat4_orthographic(mat4* m, float left, float right, float top, float bottom, float near, float far);
|
||||
mat4* mat4_perspective(mat4* m, float near, float far, float fov, float aspect);
|
||||
void mat4_transform(mat4* m, float* x, float* y, float* z);
|
||||
|
@ -375,9 +377,12 @@ local mat4 = {
|
|||
m.m[8], m.m[9], m.m[10], m.m[11],
|
||||
m.m[12], m.m[13], m.m[14], m.m[15]
|
||||
else
|
||||
local f = new('float[10]')
|
||||
C.mat4_getTransform(m, f + 0, f + 1, f + 2, f + 3, f + 4, f + 5, f + 6, f + 7, f + 8, f + 9)
|
||||
return f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8], f[9]
|
||||
local f = new('float[14]')
|
||||
C.mat4_getPosition(m, f + 0)
|
||||
C.mat4_getScale(m, f + 3)
|
||||
C.mat4_getOrientation(m, f + 6)
|
||||
C.quat_getAngleAxis(f + 6, f + 10, f + 11, f + 12, f + 13)
|
||||
return f[0], f[1], f[2], f[3], f[4], f[5], f[10], f[11], f[12], f[13]
|
||||
end
|
||||
end,
|
||||
|
||||
|
|
1699
src/api/math.lua.h
1699
src/api/math.lua.h
File diff suppressed because it is too large
Load Diff
|
@ -43,14 +43,18 @@ static int l_lovrMat4Unpack(lua_State* L) {
|
|||
}
|
||||
return 16;
|
||||
} else {
|
||||
float x, y, z, sx, sy, sz, angle, ax, ay, az;
|
||||
mat4_getTransform(m, &x, &y, &z, &sx, &sy, &sz, &angle, &ax, &ay, &az);
|
||||
lua_pushnumber(L, x);
|
||||
lua_pushnumber(L, y);
|
||||
lua_pushnumber(L, z);
|
||||
lua_pushnumber(L, sx);
|
||||
lua_pushnumber(L, sy);
|
||||
lua_pushnumber(L, sz);
|
||||
float angle, ax, ay, az;
|
||||
float position[3], orientation[4], scale[3];
|
||||
mat4_getPosition(m, position);
|
||||
mat4_getScale(m, scale);
|
||||
mat4_getOrientation(m, orientation);
|
||||
quat_getAngleAxis(orientation, &angle, &ax, &ay, &az);
|
||||
lua_pushnumber(L, position[0]);
|
||||
lua_pushnumber(L, position[1]);
|
||||
lua_pushnumber(L, position[2]);
|
||||
lua_pushnumber(L, scale[0]);
|
||||
lua_pushnumber(L, scale[1]);
|
||||
lua_pushnumber(L, scale[2]);
|
||||
lua_pushnumber(L, angle);
|
||||
lua_pushnumber(L, ax);
|
||||
lua_pushnumber(L, ay);
|
||||
|
|
|
@ -499,27 +499,8 @@ void mat4_getOrientation(mat4 m, quat orientation) {
|
|||
quat_fromMat4(orientation, m);
|
||||
}
|
||||
|
||||
void mat4_getTransform(mat4 m, float* x, float* y, float* z, float* sx, float* sy, float* sz, float* angle, float* ax, float* ay, float* az) {
|
||||
if (x) {
|
||||
*x = m[12];
|
||||
*y = m[13];
|
||||
*z = m[14];
|
||||
}
|
||||
|
||||
if (sx) {
|
||||
float a[3] = { m[0], m[1], m[2] };
|
||||
float b[3] = { m[4], m[5], m[6] };
|
||||
float c[3] = { m[8], m[9], m[10] };
|
||||
*sx = vec3_length(a);
|
||||
*sy = vec3_length(b);
|
||||
*sz = vec3_length(c);
|
||||
}
|
||||
|
||||
if (angle) {
|
||||
float quat[4];
|
||||
quat_fromMat4(quat, m);
|
||||
quat_getAngleAxis(quat, angle, ax, ay, az);
|
||||
}
|
||||
void mat4_getScale(mat4 m, vec3 scale) {
|
||||
vec3_set(scale, vec3_length(m + 0), vec3_length(m + 4), vec3_length(m + 8));
|
||||
}
|
||||
|
||||
mat4 mat4_orthographic(mat4 m, float left, float right, float top, float bottom, float clipNear, float clipFar) {
|
||||
|
|
|
@ -56,6 +56,7 @@ MAF_EXPORT mat4 mat4_rotateQuat(mat4 m, quat q);
|
|||
MAF_EXPORT mat4 mat4_scale(mat4 m, float x, float y, float z);
|
||||
MAF_EXPORT void mat4_getPosition(mat4 m, vec3 position);
|
||||
MAF_EXPORT void mat4_getOrientation(mat4 m, quat orientation);
|
||||
MAF_EXPORT void mat4_getScale(mat4 m, vec3 scale);
|
||||
MAF_EXPORT void mat4_getTransform(mat4 m, float* x, float* y, float* z, float* sx, float* sy, float* sz, float* angle, float* ax, float* ay, float* az);
|
||||
MAF_EXPORT mat4 mat4_orthographic(mat4 m, float left, float right, float top, float bottom, float near, float far);
|
||||
MAF_EXPORT mat4 mat4_perspective(mat4 m, float clipNear, float clipFar, float fov, float aspect);
|
||||
|
|
Loading…
Reference in New Issue