From 5c8333bc9ebcd37076d150afc77627aafea79d1a Mon Sep 17 00:00:00 2001 From: Fierelier Date: Fri, 11 Aug 2023 14:16:36 +0200 Subject: [PATCH] Separate Horizontal/Vertical FOV in engine_3d_project --- mods/main/script/game.lua | 2 +- src/3d.c | 6 +++--- src/lua_manual.c | 5 +++-- src/values/functions.toml | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/mods/main/script/game.lua b/mods/main/script/game.lua index 04ac1b7..a1bfe16 100644 --- a/mods/main/script/game.lua +++ b/mods/main/script/game.lua @@ -175,7 +175,7 @@ function draw3dpoint(x,y,z) x = px - x y = py - y z = pz - z - local sx,sy = engine_3d_project(x,y,z,prx,pry,0,90); + local sx,sy = engine_3d_project(x,y,z,prx,pry,0,fovHor,fovVert) sx = math.floor((width * 0.5) + (sx * (width * 0.5))) sy = math.floor((height * 0.5) + (sy * (height * 0.5))) diff --git a/src/3d.c b/src/3d.c index 84eb1f1..f451c41 100644 --- a/src/3d.c +++ b/src/3d.c @@ -22,7 +22,7 @@ void engine_3d_rotate_position(struct ENGINE_VECTOR_3D * pos,float x, float y, f pos->z = x * (-sinY) + y * (sinX * cosY) + z * (cosX * cosY); } -void engine_3d_project(struct ENGINE_VECTOR_2D * screen,float x, float y, float z, float rx, float ry, float rz, float fov) { +void engine_3d_project(struct ENGINE_VECTOR_2D * screen,float x, float y, float z, float rx, float ry, float rz, float fovHor, float fovVert) { struct ENGINE_VECTOR_3D pos; pos.x = x; pos.y = y; @@ -37,12 +37,12 @@ void engine_3d_project(struct ENGINE_VECTOR_2D * screen,float x, float y, float // rot.y (screen X) while (rot.y > 180.0) { rot.y -= 360.0; } while (rot.y < -180.0) { rot.y += 360.0; } - rot.y = rot.y / (fov * 0.5); + rot.y = rot.y / (fovHor * 0.5); // rot.x (screen Y) while (rot.x > 180.0) { rot.x -= 360.0; } while (rot.x < -180.0) { rot.x += 360.0; } - rot.x = rot.x / (fov * 0.5); + rot.x = rot.x / (fovVert * 0.5); screen->x = rot.y; screen->y = rot.x; diff --git a/src/lua_manual.c b/src/lua_manual.c index 5d988fd..35e1a87 100644 --- a/src/lua_manual.c +++ b/src/lua_manual.c @@ -72,9 +72,10 @@ int engine_luaf_3d_project(lua_State *L) { float rx = luaL_checknumber(L,4); float ry = luaL_checknumber(L,5); float rz = luaL_checknumber(L,6); - float fov = luaL_checknumber(L,7); + float fovHor = luaL_checknumber(L,7); + float fovVert = luaL_checknumber(L,8); struct ENGINE_VECTOR_2D pos; - engine_3d_project(&pos,x,y,z,rx,ry,rz,fov); + engine_3d_project(&pos,x,y,z,rx,ry,rz,fovHor,fovVert); lua_pushnumber(L,pos.x); lua_pushnumber(L,pos.y); return 2; diff --git a/src/values/functions.toml b/src/values/functions.toml index 8bfa9e9..fefbfbd 100644 --- a/src/values/functions.toml +++ b/src/values/functions.toml @@ -146,7 +146,7 @@ lua = "manual" [engine_3d_project] type = "void" -arguments = ["struct ENGINE_VECTOR_2D *","float","float","float","float","float","float","float"] -argNames = ["screen", "x", "y", "z", "rx", "ry", "rz", "fov"] +arguments = ["struct ENGINE_VECTOR_2D *","float","float","float","float","float","float","float", "float"] +argNames = ["screen", "x", "y", "z", "rx", "ry", "rz", "fovHor","fovVert"] description = "Project a 3D point onto a 2D surface. -1. = Top/Left, 1. = Bottom/Right. Output is put into screen pointer. Pointer not required in Lua." lua = "manual"