Skip to content

Commit 7f1e01d

Browse files
committed
added GetCameraMatrix()
1 parent 8ff8ebc commit 7f1e01d

File tree

4 files changed

+107
-43
lines changed

4 files changed

+107
-43
lines changed

src/Camera.cpp

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,72 +18,55 @@
1818

1919
#include "Camera.h"
2020

21+
#include "LuaHelpers.h"
22+
2123
namespace ExtraUtilities::Lua::Camera
2224
{
23-
int GetZoom(lua_State* L)
25+
int GetMatrix(lua_State* L)
2426
{
25-
int camera = luaL_checkinteger(L, 1);
27+
BZR::BZR_Camera* cam = mainCam.Get();
28+
BZR::MAT_3D mat = cam->Matrix;
2629

27-
using enum BZR::Camera::View;
28-
switch (camera)
29-
{
30-
case FIRST_PERSON:
31-
lua_pushnumber(L, zoomFPP.Read());
32-
break;
33-
case THIRD_PERSON:
34-
lua_pushnumber(L, zoomTPP.Read());
35-
break;
36-
default:
37-
luaL_argerror(L, 1, "Extra Utilities Error: Invalid camera");
38-
return 0;
39-
}
40-
return 1;
41-
}
30+
// these fields need to be negated idk why probably
31+
// some 3d graphics stuff I don't understand lol
32+
mat.right_z = -mat.right_z;
33+
mat.up_z = -mat.up_z;
34+
mat.front_x = -mat.front_x;
35+
36+
// the matrix field has junk data in the position fields,
37+
// but the real position is in the first field of the view pyramid
38+
mat.posit_x = cam->View_Pyramid[0].x;
39+
mat.posit_y = cam->View_Pyramid[0].y;
40+
mat.posit_z = cam->View_Pyramid[0].z;
4241

43-
int SetZoom(lua_State* L)
44-
{
45-
int camera = luaL_checkinteger(L, 1);
46-
float zoom = static_cast<float>(luaL_checknumber(L, 2));
42+
PushMatrix(L, mat);
4743

48-
using enum BZR::Camera::View;
49-
switch (camera)
50-
{
51-
case FIRST_PERSON:
52-
zoomFPP.Write(zoom);
53-
break;
54-
case THIRD_PERSON:
55-
zoomTPP.Write(zoom);
56-
break;
57-
default:
58-
luaL_argerror(L, 1, "Extra Utilities Error: Invalid camera");
59-
return 0;
60-
}
61-
return 0;
44+
return 1;
6245
}
6346

64-
int GetMinZoom(lua_State* L)
47+
int GetMaxZoom(lua_State* L)
6548
{
66-
lua_pushnumber(L, minZoom.Read());
49+
lua_pushnumber(L, maxZoom.Read());
6750
return 1;
6851
}
6952

70-
int SetMinZoom(lua_State* L)
53+
int SetMaxZoom(lua_State* L)
7154
{
7255
float zoom = static_cast<float>(luaL_checknumber(L, 1));
73-
minZoom.Write(zoom);
56+
maxZoom.Write(zoom);
7457
return 0;
7558
}
7659

77-
int GetMaxZoom(lua_State* L)
60+
int GetMinZoom(lua_State* L)
7861
{
79-
lua_pushnumber(L, maxZoom.Read());
62+
lua_pushnumber(L, minZoom.Read());
8063
return 1;
8164
}
8265

83-
int SetMaxZoom(lua_State* L)
66+
int SetMinZoom(lua_State* L)
8467
{
8568
float zoom = static_cast<float>(luaL_checknumber(L, 1));
86-
maxZoom.Write(zoom);
69+
minZoom.Write(zoom);
8770
return 0;
8871
}
8972

@@ -121,4 +104,45 @@ namespace ExtraUtilities::Lua::Camera
121104

122105
return 0;
123106
}
107+
108+
int GetZoom(lua_State* L)
109+
{
110+
int camera = luaL_checkinteger(L, 1);
111+
112+
using enum BZR::Camera::View;
113+
switch (camera)
114+
{
115+
case FIRST_PERSON:
116+
lua_pushnumber(L, zoomFPP.Read());
117+
break;
118+
case THIRD_PERSON:
119+
lua_pushnumber(L, zoomTPP.Read());
120+
break;
121+
default:
122+
luaL_argerror(L, 1, "Extra Utilities Error: Invalid camera");
123+
return 0;
124+
}
125+
return 1;
126+
}
127+
128+
int SetZoom(lua_State* L)
129+
{
130+
int camera = luaL_checkinteger(L, 1);
131+
float zoom = static_cast<float>(luaL_checknumber(L, 2));
132+
133+
using enum BZR::Camera::View;
134+
switch (camera)
135+
{
136+
case FIRST_PERSON:
137+
zoomFPP.Write(zoom);
138+
break;
139+
case THIRD_PERSON:
140+
zoomTPP.Write(zoom);
141+
break;
142+
default:
143+
luaL_argerror(L, 1, "Extra Utilities Error: Invalid camera");
144+
return 0;
145+
}
146+
return 0;
147+
}
124148
}

src/Camera.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
namespace ExtraUtilities::Lua::Camera
2727
{
28+
inline Scanner mainCam(BZR::Camera::View_Record_MainCam, BasicScanner::Restore::DISABLED);
29+
2830
inline Scanner zoomFPP(BZR::Camera::zoomFactorFPP);
2931
inline Scanner zoomTPP(BZR::Camera::zoomFactorTPP);
3032
inline Scanner minZoom(BZR::Camera::minZoomFactor);
@@ -33,6 +35,8 @@ namespace ExtraUtilities::Lua::Camera
3335
// restore needs to be disabled to prevent camera state being saved after leaving a game
3436
inline Scanner currentView(BZR::Camera::currentView, BasicScanner::Restore::DISABLED);
3537

38+
int GetMatrix(lua_State* L);
39+
3640
int GetMaxZoom(lua_State* L);
3741
int SetMaxZoom(lua_State* L);
3842

src/bzr.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,43 @@ namespace BZR
7676
float x, y, z;
7777
};
7878

79+
struct VECTOR_3D_LONG
80+
{
81+
VECTOR_3D_LONG() : x(0), y(0), z(0) {}
82+
VECTOR_3D_LONG(double x, double y, double z) : x(x), y(y), z(z) {}
83+
double x, y, z;
84+
};
85+
86+
class BZR_Camera // todo merge camera namespaces
87+
{
88+
public:
89+
float Orig_x;
90+
float Orig_y;
91+
float Const_x;
92+
float Const_y;
93+
float Max_Depth;
94+
float Left;
95+
float Bottom;
96+
float Right;
97+
float Top;
98+
float View_Angle;
99+
float Tang;
100+
float Aspect;
101+
float Zoom_Factor;
102+
void (*Draw_Poly)(void);
103+
void* Buffer; // _GRAPHIC_BUFFER*
104+
MAT_3D Matrix;
105+
VECTOR_3D_LONG bSphere_Center;
106+
double bSphere_Radius;
107+
uint8_t View_Volume[0x60]; // plane class
108+
VECTOR_3D View_Frustum[8];
109+
VECTOR_3D_LONG View_Pyramid[5];
110+
};
111+
79112
namespace Camera
80113
{
114+
inline auto View_Record_MainCam = (BZR_Camera*)0x008EAAE0;
115+
81116
inline auto zoomFactorFPP = (float*)0x008EAD10;
82117
inline auto zoomFactorTPP = (float*)0x008EAB10;
83118
inline auto maxZoomFactor = (float*)0x008A2688;

src/luaexport.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ namespace ExtraUtilities::Lua
201201
{
202202
const luaL_Reg EXPORT[] = {
203203
// Camera
204+
{ "GetCameraMatrix", &Camera::GetMatrix },
204205
{ "GetCameraMaxZoom", &Camera::GetMaxZoom },
205206
{ "SetCameraMaxZoom", &Camera::SetMaxZoom },
206207
{ "GetCameraMinZoom", &Camera::GetMinZoom },

0 commit comments

Comments
 (0)