Scriptable near and far planes

This commit is contained in:
mid 2025-09-30 11:05:33 +03:00
parent 462412c31a
commit 2e730baf33
3 changed files with 14 additions and 2 deletions

View File

@ -385,7 +385,9 @@ static int game_addentity(lua_State *L) {
}
double LuaapiStartTime;
float LuaapiFov = 75;
float LuaapiFov = 75.0f;
float LuaapiNear = 0.01f;
float LuaapiFar = 80.0f;
static int gametriggersref;
static int luaapi_triggerfunc(size_t id, uint16_t ethis, uint16_t ethat, uint8_t event) {
@ -1276,6 +1278,10 @@ static int game_get(lua_State *L) {
}
} else if(!strcmp(i, "fov")) {
lua_pushnumber(L, LuaapiFov);
} else if(!strcmp(i, "near")) {
lua_pushnumber(L, LuaapiNear);
} else if(!strcmp(i, "far")) {
lua_pushnumber(L, LuaapiFar);
} else if(!strcmp(i, "rate")) {
lua_pushinteger(L, GAME_TPS);
} else if(!strcmp(i, "camera")) {
@ -1305,6 +1311,10 @@ static int game_set(lua_State *L) {
Game.spectated = lua_isnil(L, 3) ? ENT_ID_INVALID : lua_tointeger(L, 3);
} else if(!strcmp(i, "fov")) {
LuaapiFov = lua_tonumber(L, 3);
} else if(!strcmp(i, "near")) {
LuaapiNear = lua_tonumber(L, 3);
} else if(!strcmp(i, "far")) {
LuaapiFar = lua_tonumber(L, 3);
} else if(!strcmp(i, "menu")) {
struct menuitem *item = lua_touserdata(L, 3);
UiActive = item ? item->ptr : NULL;

View File

@ -14,6 +14,8 @@ extern int LuaapiFirstPerson;
extern double LuaapiStartTime;
extern float LuaapiFov;
extern float LuaapiNear;
extern float LuaapiFar;
extern struct k3Tex *LuaapiSkybox;
extern vec4 LuaapiSkyboxRotation;

View File

@ -505,7 +505,7 @@ int main(int argc_, char **argv_) {
glfwGetFramebufferSize(GameWnd, &width, &height);
mat4 proj;
glm_perspective(glm_rad(LuaapiFov), (float) width / height, 0.1f, 80.f, proj);
glm_perspective(glm_rad(LuaapiFov), (float) width / height, LuaapiNear, LuaapiFar, proj);
/* Third-person camera movement */
struct LocalRay camray = {};