15#include "nlua_transform.h"
74 return (
mat4*) lua_touserdata(L,ind);
87 luaL_typerror(L, ind, TRANSFORM_METATABLE);
101 luaL_getmetatable(L, TRANSFORM_METATABLE);
102 lua_setmetatable(L, -2);
116 if (lua_getmetatable(L,ind)==0)
118 lua_getfield(L, LUA_REGISTRYINDEX, TRANSFORM_METATABLE);
121 if (lua_rawequal(L, -1, -2))
140 lua_pushboolean( L, (memcmp( t1, t2,
sizeof(
mat4) )==0) );
192 for (
int i=0; i<4; i++) {
194 for (
int j=0; j<4; j++) {
195 lua_pushnumber(L,M->m[j][i]);
196 lua_rawseti(L,-2,j+1);
198 lua_rawseti(L,-2,i+1);
215 int i = luaL_checkinteger(L, 2)-1;
216 int j = luaL_checkinteger(L, 3)-1;
217 double v = luaL_checknumber(L, 4);
219 if (i < 0 || i > 3) {
220 WARN(_(
"Matrix column value not in range: %d"),i);
223 if (j < 0 || j > 3) {
224 WARN(_(
"Matrix row value not in range: %d"),j);
245 double x = luaL_checknumber(L,2);
246 double y = luaL_checknumber(L,3);
247 double z = luaL_optnumber(L,4,1.);
267 double x = luaL_checknumber(L,2);
268 double y = luaL_checknumber(L,3);
269 double z = luaL_optnumber(L,4,0.);
286 double a = luaL_checknumber(L,2);
307 double left = luaL_checknumber(L,1);
308 double right = luaL_checknumber(L,2);
309 double bottom = luaL_checknumber(L,3);
310 double top = luaL_checknumber(L,4);
311 double nearVal = luaL_checknumber(L,5);
312 double farVal = luaL_checknumber(L,6);
333 gp[0] = luaL_checknumber(L,2);
334 gp[1] = luaL_checknumber(L,3);
335 gp[2] = luaL_checknumber(L,4);
337 for (
int i=0; i<3; i++)
338 p[i] = M->m[0][i]*gp[0] + M->m[1][i]*gp[1] + M->m[2][i]*gp[2] + M->m[3][i];
340 lua_pushnumber(L, p[0]);
341 lua_pushnumber(L, p[1]);
342 lua_pushnumber(L, p[2]);
364 gp[0] = luaL_checknumber(L,2);
365 gp[1] = luaL_checknumber(L,3);
366 gp[2] = luaL_checknumber(L,4);
368 for (
int i=0; i<3; i++)
369 p[i] = M->m[0][i]*gp[0] + M->m[1][i]*gp[1] + M->m[2][i]*gp[2];
371 lua_pushnumber(L, p[0]);
372 lua_pushnumber(L, p[1]);
373 lua_pushnumber(L, p[2]);
void mat4_translate(mat4 *m, double x, double y, double z)
Translates a homogenous transformation matrix.
mat4 mat4_identity(void)
Creates an identity matrix.
void mat4_scale(mat4 *m, double x, double y, double z)
Scales a homogeneous transformation matrix.
void mat4_mul(mat4 *out, const mat4 *m1, const mat4 *m2)
Multiplies two matrices (out = m1 * m2).
mat4 mat4_ortho(double left, double right, double bottom, double top, double nearVal, double farVal)
Creates an orthographic projection matrix.
void mat4_rotate2d(mat4 *m, double angle)
Rotates an angle, in radians, around the z axis.
Header file with generic functions and naev-specifics.