mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 22:11:51 +00:00
Merge pull request #810 from RomanDonw/main
added mat4.perspective function
This commit is contained in:
commit
24b4877551
2 changed files with 31 additions and 2 deletions
|
|
@ -114,15 +114,29 @@ mat4.decompose(m: matrix)
|
||||||
} или nil
|
} или nil
|
||||||
```
|
```
|
||||||
|
|
||||||
## Отслеживание точки *mat4.look_at(...)*
|
## Отслеживание точки - *mat4.look_at(...)*
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- cоздает матрицу вида с точки 'eye' на точку 'center', где вектор 'up' определяет верх.
|
-- cоздаёт матрицу вида с точки 'eye' на точку 'center', где вектор 'up' определяет верх.
|
||||||
mat4.look_at(eye: vec3, center: vec3, up: vec3)
|
mat4.look_at(eye: vec3, center: vec3, up: vec3)
|
||||||
-- записывает матрицу вида в dst
|
-- записывает матрицу вида в dst
|
||||||
mat4.look_at(eye: vec3, center: vec3, up: vec3, dst: matrix)
|
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(...)*
|
## Перевод в строку - *mat4.tostring(...)*
|
||||||
|
|
||||||
```lua
|
```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) {
|
static int l_from_quat(lua::State* L) {
|
||||||
uint argc = lua::check_argc(L, 1, 2);
|
uint argc = lua::check_argc(L, 1, 2);
|
||||||
auto quat = lua::toquat(L, 1);
|
auto quat = lua::toquat(L, 1);
|
||||||
|
|
@ -280,6 +294,7 @@ const luaL_Reg mat4lib[] = {
|
||||||
{"determinant", lua::wrap<l_determinant>},
|
{"determinant", lua::wrap<l_determinant>},
|
||||||
{"decompose", lua::wrap<l_decompose>},
|
{"decompose", lua::wrap<l_decompose>},
|
||||||
{"look_at", lua::wrap<l_look_at>},
|
{"look_at", lua::wrap<l_look_at>},
|
||||||
|
{"perspective", lua::wrap<l_perspective>},
|
||||||
{"from_quat", lua::wrap<l_from_quat>},
|
{"from_quat", lua::wrap<l_from_quat>},
|
||||||
{"tostring", lua::wrap<l_tostring>},
|
{"tostring", lua::wrap<l_tostring>},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue