Merge branch 'main' into physics-upgrade

This commit is contained in:
MihailRis 2026-03-05 12:16:23 +03:00
commit 1d4fb9bc07
9 changed files with 79 additions and 21 deletions

View file

@ -78,14 +78,14 @@ Returns the id of all base packages (non-removeable)
```lua ```lua
pack.get_info(packid: str) -> { pack.get_info(packid: str) -> {
id: str, id: str,
title: str, title: str,
creator: str, creator: str,
description: str, description: str,
version: str, version: str,
path: str, path: str,
icon: str, -- not available in headless mode icon: str, -- not available in headless mode
dependencies: optional strings array dependencies: optional strings array
} }
``` ```
@ -95,6 +95,7 @@ Returns information about the pack (not necessarily installed).
- `!` - required - `!` - required
- `?` - optional - `?` - optional
- `~` - weak - `~` - weak
for example `!teal` for example `!teal`
To obtain information about multiple packs, use table of ids to avoid re-scanning:one To obtain information about multiple packs, use table of ids to avoid re-scanning:one

View file

@ -213,9 +213,6 @@ Element must be in direct sub-element of *inventory*.
## *slots-grid* ## *slots-grid*
- `start-index` - inventory slot index of the first slot. Type: integer - `start-index` - inventory slot index of the first slot. Type: integer
- `rows` - number of grid rows (unnecessary if *cols* and *count* specified). Type: integer
- `cols` - number of grid columns (unnecessary if *rows* and *count* specified). Type: integer
- `count` - total number of slots in grid (unnecessary if *rows* and *cols* specified). Type: integer
- `interval` - visual slots interval. Type: number - `interval` - visual slots interval. Type: number
- `padding` - grid padding (not slots interval). Type: number. (*deprecated*) - `padding` - grid padding (not slots interval). Type: number. (*deprecated*)
- `sharefunc` - Lua event called on <btn>LMB</btn> + <btn>Shift</btn>. Inventory id and slot index passed as arguments. - `sharefunc` - Lua event called on <btn>LMB</btn> + <btn>Shift</btn>. Inventory id and slot index passed as arguments.
@ -223,3 +220,8 @@ Element must be in direct sub-element of *inventory*.
- `onrightclick` - Lua event called on <btn>RMB</btn> click. Inventory id and slot index passed as arguments. - `onrightclick` - Lua event called on <btn>RMB</btn> click. Inventory id and slot index passed as arguments.
- `taking` - the ability to take an item from a slot. - `taking` - the ability to take an item from a slot.
- `placing` - the ability to put an item in a slot. - `placing` - the ability to put an item in a slot.
Slots configuration (just specify two attributes):
- `rows` - ​​number of rows. Type: integer
- `cols` - number of columns. Type: integer
- `count` - total number of slots. Type: integer

View file

@ -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

View file

@ -82,6 +82,7 @@ pack.get_info(packid: string) -> {
- `!` - required - `!` - required
- `?` - optional - `?` - optional
- `~` - weak - `~` - weak
например `!teal` например `!teal`
Для получения информации о нескольких паках используйте таблицу id, чтобы не Для получения информации о нескольких паках используйте таблицу id, чтобы не

View file

@ -2,22 +2,34 @@
Библиотека для работы с кватернионами. Библиотека для работы с кватернионами.
## Кватернион из матрицы - *mat4.from_quat(...)* ## Кватернион из матрицы - *quat.from_mat4(...)*
```lua ```lua
-- создает кватернион на основе матрицы вращения -- создаёт кватернион на основе матрицы вращения
quat.from_mat4(m: matrix) -> quat quat.from_mat4(m: matrix) -> quat
-- записывает кватернион по матрице вращения в dst -- записывает кватернион по матрице вращения в dst
quat.from_mat4(m: matrix, dst: quat) quat.from_mat4(m: matrix, dst: quat)
``` ```
## Кватернион из углов Эйлера - *quat.from_euler(...)*
```lua
-- создаёт кватернион на основе вектора, содержащего углы Эйлера в порядке XYZ (pitch, yaw, roll)
-- (значения углов строго в градусах)
quat.from_euler(euler: vec3) -> quat
-- записывает кватернион в dst на основе вектора, содержащего углы Эйлера в порядке XYZ (pitch, yaw, roll)
-- (значения углов строго в градусах)
quat.from_euler(euler: vec3, dst: quat)
```
## Сферическая линейная интерполяция - *quat.slerp(...)* ## Сферическая линейная интерполяция - *quat.slerp(...)*
Интерполяция всегда выполняется по короткому пути, а вращение выполняется с постоянной скоростью. Интерполяция всегда выполняется по короткому пути, а вращение выполняется с постоянной скоростью.
```lua ```lua
-- создает кватернион как интерполяцию между a и b, -- создаёт кватернион как интерполяцию между a и b,
-- где t - фактор интерполяции -- где t - фактор интерполяции
quat.slerp(a: quat, b: quat, t: number) -> quat quat.slerp(a: quat, b: quat, t: number) -> quat
@ -29,6 +41,6 @@ quat.slerp(a: quat, b: quat, t: number, dst: quat)
## Перевод в строку - *quat.tostring(...)* ## Перевод в строку - *quat.tostring(...)*
```lua ```lua
-- возвращает строку представляющую содержимое кватерниона -- возвращает строку, представляющую содержимое кватерниона
quat.tostring(q: quat) -> string quat.tostring(q: quat) -> string
``` ```

View file

@ -214,10 +214,8 @@
## Сетка слотов - *slots-grid* ## Сетка слотов - *slots-grid*
Элемент должен находиться внутри `inventory` элемента, без посредников. Элемент должен находиться внутри `inventory` элемента, без посредников.
- `start-index` - индекс первого слота - `start-index` - индекс первого слота
- `rows` - число рядов (не указывается, если указано cols).
- `cols` - число столбцов (не указывается, если указано rows).
- `count` - общее число слотов (не указывается, если указаны rows и cols).
- `interval` - интервал между слотами. Тип: число. - `interval` - интервал между слотами. Тип: число.
- `padding` - отступ вокруг решетки слотов. Тип: число. (*атрибут будет удален*) - `padding` - отступ вокруг решетки слотов. Тип: число. (*атрибут будет удален*)
- `sharefunc` - lua событие вызываемое при использовании ЛКМ + Shift. Передается id инвентаря и индекс слота - `sharefunc` - lua событие вызываемое при использовании ЛКМ + Shift. Передается id инвентаря и индекс слота
@ -225,3 +223,8 @@
- `onrightclick` - lua событие вызываемое при использовании ПКМ. Передается id инвентаря и индекс слота - `onrightclick` - lua событие вызываемое при использовании ПКМ. Передается id инвентаря и индекс слота
- `taking` - возможность взять предмет из слота. - `taking` - возможность взять предмет из слота.
- `placing` - возможность положить предмет в слот. - `placing` - возможность положить предмет в слот.
Конфигурация слотов (достаточно указать два атрибута):
- `rows` - число рядов. Тип: число.
- `cols` - число столбцов. Тип: число.
- `count` - общее число слотов. Тип: число.

View file

@ -3,6 +3,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <cstdint>
class Engine; class Engine;
class World; class World;

View file

@ -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}

View file

@ -44,8 +44,17 @@ static int l_tostring(lua::State* L) {
return lua::pushstring(L, ss.str()); return lua::pushstring(L, ss.str());
} }
static int l_from_euler(lua::State *L) {
uint argc = lua::check_argc(L, 1, 2);
glm::vec3 euler = glm::radians(lua::tovec3(L, 1));
if (argc == 2) return lua::setquat(L, 2, glm::quat(euler));
return lua::pushquat(L, glm::quat(euler));
}
const luaL_Reg quatlib[] = { const luaL_Reg quatlib[] = {
{"from_mat4", lua::wrap<l_from_mat4>}, {"from_mat4", lua::wrap<l_from_mat4>},
{"from_euler", lua::wrap<l_from_euler>},
{"slerp", lua::wrap<l_slerp>}, {"slerp", lua::wrap<l_slerp>},
{"tostring", lua::wrap<l_tostring>}, {"tostring", lua::wrap<l_tostring>},
{nullptr, nullptr} {nullptr, nullptr}