Merge branch 'main' into entities

This commit is contained in:
MihailRis 2024-07-11 03:32:05 +03:00
commit 30dd853044
3 changed files with 35 additions and 0 deletions

View File

@ -115,6 +115,15 @@ mat4.decompose(m: matrix)
}
```
## Look at point - *mat4.look_at(...)*
```lua
-- creates a view matrix from the 'eye' point to the 'center' point with up vector specified
mat4.look_at(eye: vec3, center: vec3, up: vec3)
-- writes the view matrix to dst
mat4.look_at(eye: vec3, center: vec3, up: vec3, dst: matrix)
```
## Casting to string - *mat4.tostring(...)*
```lua

View File

@ -115,6 +115,15 @@ mat4.decompose(m: matrix)
}
```
## Отслеживание точки *mat4.look_at(...)*
```lua
-- cоздает матрицу вида с точки 'eye' на точку 'center', где вектор 'up' определяет верх.
mat4.look_at(eye: vec3, center: vec3, up: vec3)
-- записывает матрицу вида в dst
mat4.look_at(eye: vec3, center: vec3, up: vec3, dst: matrix)
```
## Перевод в строку - *mat4.tostring(...)*
```lua

View File

@ -211,6 +211,22 @@ static int l_decompose(lua::State* L) {
return 1;
}
static int l_look_at(lua::State* L) {
int argc = lua::gettop(L);
if (argc != 3 && argc != 4) {
throw std::runtime_error("invalid arguments number (3 or 4 expected)");
}
auto eye = lua::tovec<3>(L, 1);
auto center = lua::tovec<3>(L, 2);
auto up = lua::tovec<3>(L, 3);
if (argc == 3) {
return lua::pushmat4(L, glm::lookAt(eye, center, up));
} else {
return lua::setmat4(L, 4, glm::lookAt(eye, center, up));
}
}
static int l_tostring(lua::State* L) {
auto matrix = lua::tomat4(L, 1);
bool multiline = lua::toboolean(L, 2);
@ -249,6 +265,7 @@ const luaL_Reg mat4lib [] = {
{"transpose", lua::wrap<l_transpose>},
{"determinant", lua::wrap<l_determinant>},
{"decompose", lua::wrap<l_decompose>},
{"look_at", lua::wrap<l_look_at>},
{"tostring", lua::wrap<l_tostring>},
{NULL, NULL}
};