mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
add mat4.scale mutating overload
This commit is contained in:
parent
c7a843bc63
commit
8f046b86b9
2 changed files with 19 additions and 0 deletions
|
|
@ -7,6 +7,8 @@ static int l_idt(lua::State* L) {
|
|||
return lua::pushmat4(L, glm::mat4(1.0f));
|
||||
}
|
||||
|
||||
/// @brief mat4.scale(matrix=idt: array[16], scale: array[3]) -> array[16]
|
||||
/// Modifies matrix
|
||||
static int l_scale(lua::State* L) {
|
||||
uint argc = lua::gettop(L);
|
||||
switch (argc) {
|
||||
|
|
@ -19,6 +21,11 @@ static int l_scale(lua::State* L) {
|
|||
auto scale = lua::tovec3(L, 2);
|
||||
return lua::pushmat4(L, glm::scale(matrix, scale));
|
||||
}
|
||||
case 3: {
|
||||
auto matrix = lua::tomat4(L, 1);
|
||||
auto scale = lua::tovec3(L, 2);
|
||||
return lua::setmat4(L, 3, glm::scale(matrix, scale));
|
||||
}
|
||||
default: {
|
||||
throw std::runtime_error("invalid number of arguments (1 or 2 expected)");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,6 +206,18 @@ namespace lua {
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
/// @brief pushes matrix table to the stack and updates it with glm matrix
|
||||
inline int setmat4(lua::State* L, int idx, glm::mat4 matrix) {
|
||||
pushvalue(L, idx);
|
||||
for (uint y = 0; y < 4; y++) {
|
||||
for (uint x = 0; x < 4; x++) {
|
||||
uint i = y * 4 + x;
|
||||
pushnumber(L, matrix[y][x]);
|
||||
rawseti(L, i+1);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
inline int pushcfunction(lua::State* L, lua_CFunction func) {
|
||||
lua_pushcfunction(L, func);
|
||||
return 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue