mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
added mat4.perspective function
This commit is contained in:
parent
76bda98cce
commit
3ab11f9ef8
2 changed files with 31 additions and 2 deletions
|
|
@ -114,15 +114,29 @@ mat4.decompose(m: matrix)
|
|||
} или nil
|
||||
```
|
||||
|
||||
## Отслеживание точки *mat4.look_at(...)*
|
||||
## Отслеживание точки - *mat4.look_at(...)*
|
||||
|
||||
```lua
|
||||
-- cоздает матрицу вида с точки 'eye' на точку 'center', где вектор 'up' определяет верх.
|
||||
-- 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.perspective*
|
||||
|
||||
```lua
|
||||
-- возвращает расчитанную матрицу перспективы.
|
||||
-- параметр fov принимает значение вертикального поля зрения в градусах.
|
||||
-- параметр ratio задаёт отношение сторон (сторона X к стороне Y, пример: для монитора 800:600 отношение сторон равно 4 к 3, или 4 / 3).
|
||||
-- параметр near задаёт расстояние от камеры до плоскости Near.
|
||||
-- параметр far задаёт расстояние от камеры до плоскости Far.
|
||||
mat4.perspective(fov: number, ratio: number, near: number, far: number) -> mat4
|
||||
|
||||
-- расчитывает матрицу перспективы на основе переданных значений и записывает её в переменную dst.
|
||||
mat4.perspective(fov: number, ratio: number, near: number, far: number, dst: mat4) -> nil
|
||||
```
|
||||
|
||||
## Перевод в строку - *mat4.tostring(...)*
|
||||
|
||||
```lua
|
||||
|
|
|
|||
|
|
@ -229,6 +229,20 @@ static int l_look_at(lua::State* L) {
|
|||
}
|
||||
}
|
||||
|
||||
static int l_perspective(lua::State *L) {
|
||||
uint argc = lua::check_argc(L, 4, 5);
|
||||
|
||||
double fov = glm::radians(lua::tonumber(L, 1));
|
||||
double ratio = lua::tonumber(L, 2);
|
||||
double near = lua::tonumber(L, 3);
|
||||
double far = lua::tonumber(L, 4);
|
||||
|
||||
glm::mat4 mat = glm::perspective(fov, ratio, near, far);
|
||||
|
||||
if (argc == 5) return lua::setmat4(L, 5, mat);
|
||||
else return lua::pushmat4(L, mat);
|
||||
}
|
||||
|
||||
static int l_from_quat(lua::State* L) {
|
||||
uint argc = lua::check_argc(L, 1, 2);
|
||||
auto quat = lua::toquat(L, 1);
|
||||
|
|
@ -280,6 +294,7 @@ const luaL_Reg mat4lib[] = {
|
|||
{"determinant", lua::wrap<l_determinant>},
|
||||
{"decompose", lua::wrap<l_decompose>},
|
||||
{"look_at", lua::wrap<l_look_at>},
|
||||
{"perspective", lua::wrap<l_perspective>},
|
||||
{"from_quat", lua::wrap<l_from_quat>},
|
||||
{"tostring", lua::wrap<l_tostring>},
|
||||
{nullptr, nullptr}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue