Separate Horizontal/Vertical FOV in engine_3d_project
This commit is contained in:
parent
40b8cab88e
commit
5c8333bc9e
@ -175,7 +175,7 @@ function draw3dpoint(x,y,z)
|
|||||||
x = px - x
|
x = px - x
|
||||||
y = py - y
|
y = py - y
|
||||||
z = pz - z
|
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)))
|
sx = math.floor((width * 0.5) + (sx * (width * 0.5)))
|
||||||
sy = math.floor((height * 0.5) + (sy * (height * 0.5)))
|
sy = math.floor((height * 0.5) + (sy * (height * 0.5)))
|
||||||
|
|
||||||
|
6
src/3d.c
6
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);
|
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;
|
struct ENGINE_VECTOR_3D pos;
|
||||||
pos.x = x;
|
pos.x = x;
|
||||||
pos.y = y;
|
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)
|
// rot.y (screen X)
|
||||||
while (rot.y > 180.0) { rot.y -= 360.0; }
|
while (rot.y > 180.0) { rot.y -= 360.0; }
|
||||||
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)
|
// rot.x (screen Y)
|
||||||
while (rot.x > 180.0) { rot.x -= 360.0; }
|
while (rot.x > 180.0) { rot.x -= 360.0; }
|
||||||
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->x = rot.y;
|
||||||
screen->y = rot.x;
|
screen->y = rot.x;
|
||||||
|
@ -72,9 +72,10 @@ int engine_luaf_3d_project(lua_State *L) {
|
|||||||
float rx = luaL_checknumber(L,4);
|
float rx = luaL_checknumber(L,4);
|
||||||
float ry = luaL_checknumber(L,5);
|
float ry = luaL_checknumber(L,5);
|
||||||
float rz = luaL_checknumber(L,6);
|
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;
|
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.x);
|
||||||
lua_pushnumber(L,pos.y);
|
lua_pushnumber(L,pos.y);
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -146,7 +146,7 @@ lua = "manual"
|
|||||||
|
|
||||||
[engine_3d_project]
|
[engine_3d_project]
|
||||||
type = "void"
|
type = "void"
|
||||||
arguments = ["struct ENGINE_VECTOR_2D *","float","float","float","float","float","float","float"]
|
arguments = ["struct ENGINE_VECTOR_2D *","float","float","float","float","float","float","float", "float"]
|
||||||
argNames = ["screen", "x", "y", "z", "rx", "ry", "rz", "fov"]
|
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."
|
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"
|
lua = "manual"
|
||||||
|
Loading…
Reference in New Issue
Block a user