@@ -51,6 +51,7 @@ void LuaCamera::create(lua_State *L, Camera *m)
51
51
lua_setfield (L, objectstable, " camera" );
52
52
}
53
53
54
+ // set_camera_mode(self, mode)
54
55
int LuaCamera::l_set_camera_mode (lua_State *L)
55
56
{
56
57
Camera *camera = getobject (L, 1 );
@@ -67,27 +68,29 @@ int LuaCamera::l_set_camera_mode(lua_State *L)
67
68
return 0 ;
68
69
}
69
70
71
+ // get_camera_mode(self)
70
72
int LuaCamera::l_get_camera_mode (lua_State *L)
71
73
{
72
74
Camera *camera = getobject (L, 1 );
73
75
if (!camera)
74
76
return 0 ;
75
77
76
- lua_pushnumber (L, (int )camera->getCameraMode ());
78
+ lua_pushinteger (L, (int )camera->getCameraMode ());
77
79
78
80
return 1 ;
79
81
}
80
82
83
+ // get_fov(self)
81
84
int LuaCamera::l_get_fov (lua_State *L)
82
85
{
83
86
Camera *camera = getobject (L, 1 );
84
87
if (!camera)
85
88
return 0 ;
86
89
87
90
lua_newtable (L);
88
- lua_pushnumber (L, camera->getFovX () * core::DEGTORAD );
91
+ lua_pushnumber (L, camera->getFovX () * core::RADTODEG );
89
92
lua_setfield (L, -2 , " x" );
90
- lua_pushnumber (L, camera->getFovY () * core::DEGTORAD );
93
+ lua_pushnumber (L, camera->getFovY () * core::RADTODEG );
91
94
lua_setfield (L, -2 , " y" );
92
95
lua_pushnumber (L, camera->getCameraNode ()->getFOV () * core::RADTODEG);
93
96
lua_setfield (L, -2 , " actual" );
@@ -96,16 +99,18 @@ int LuaCamera::l_get_fov(lua_State *L)
96
99
return 1 ;
97
100
}
98
101
102
+ // get_pos(self)
99
103
int LuaCamera::l_get_pos (lua_State *L)
100
104
{
101
105
Camera *camera = getobject (L, 1 );
102
106
if (!camera)
103
107
return 0 ;
104
108
105
- push_v3f (L, camera->getPosition ());
109
+ push_v3f (L, camera->getPosition () / BS );
106
110
return 1 ;
107
111
}
108
112
113
+ // get_offset(self)
109
114
int LuaCamera::l_get_offset (lua_State *L)
110
115
{
111
116
LocalPlayer *player = getClient (L)->getEnv ().getLocalPlayer ();
@@ -115,38 +120,40 @@ int LuaCamera::l_get_offset(lua_State *L)
115
120
return 1 ;
116
121
}
117
122
123
+ // get_look_dir(self)
118
124
int LuaCamera::l_get_look_dir (lua_State *L)
119
125
{
120
- LocalPlayer *player = getClient (L)->getEnv ().getLocalPlayer ();
121
- sanity_check (player);
122
-
123
- float pitch = -1.0 * player->getPitch () * core::DEGTORAD;
124
- float yaw = (player->getYaw () + 90 .) * core::DEGTORAD;
125
- v3f v (std::cos (pitch) * std::cos (yaw), std::sin (pitch),
126
- std::cos (pitch) * std::sin (yaw));
126
+ Camera *camera = getobject (L, 1 );
127
+ if (!camera)
128
+ return 0 ;
127
129
128
- push_v3f (L, v );
130
+ push_v3f (L, camera-> getDirection () );
129
131
return 1 ;
130
132
}
131
133
134
+ // get_look_horizontal(self)
135
+ // FIXME: wouldn't localplayer be a better place for this?
132
136
int LuaCamera::l_get_look_horizontal (lua_State *L)
133
137
{
134
138
LocalPlayer *player = getClient (L)->getEnv ().getLocalPlayer ();
135
139
sanity_check (player);
136
140
137
- lua_pushnumber (L, (player->getYaw () + 90 .) * core::DEGTORAD);
141
+ lua_pushnumber (L, (player->getYaw () + 90 .f ) * core::DEGTORAD);
138
142
return 1 ;
139
143
}
140
144
145
+ // get_look_vertical(self)
146
+ // FIXME: wouldn't localplayer be a better place for this?
141
147
int LuaCamera::l_get_look_vertical (lua_State *L)
142
148
{
143
149
LocalPlayer *player = getClient (L)->getEnv ().getLocalPlayer ();
144
150
sanity_check (player);
145
151
146
- lua_pushnumber (L, -1.0 * player->getPitch () * core::DEGTORAD);
152
+ lua_pushnumber (L, -1 .0f * player->getPitch () * core::DEGTORAD);
147
153
return 1 ;
148
154
}
149
155
156
+ // get_aspect_ratio(self)
150
157
int LuaCamera::l_get_aspect_ratio (lua_State *L)
151
158
{
152
159
Camera *camera = getobject (L, 1 );
@@ -215,13 +222,19 @@ void LuaCamera::Register(lua_State *L)
215
222
lua_pop (L, 1 );
216
223
}
217
224
225
+ // clang-format off
218
226
const char LuaCamera::className[] = " Camera" ;
219
- const luaL_Reg LuaCamera::methods[] = {luamethod (LuaCamera, set_camera_mode),
220
- luamethod (LuaCamera, get_camera_mode), luamethod (LuaCamera, get_fov),
221
- luamethod (LuaCamera, get_pos), luamethod (LuaCamera, get_offset),
222
- luamethod (LuaCamera, get_look_dir),
223
- luamethod (LuaCamera, get_look_vertical),
224
- luamethod (LuaCamera, get_look_horizontal),
225
- luamethod (LuaCamera, get_aspect_ratio),
226
-
227
- {0 , 0 }};
227
+ const luaL_Reg LuaCamera::methods[] = {
228
+ luamethod (LuaCamera, set_camera_mode),
229
+ luamethod (LuaCamera, get_camera_mode),
230
+ luamethod (LuaCamera, get_fov),
231
+ luamethod (LuaCamera, get_pos),
232
+ luamethod (LuaCamera, get_offset),
233
+ luamethod (LuaCamera, get_look_dir),
234
+ luamethod (LuaCamera, get_look_vertical),
235
+ luamethod (LuaCamera, get_look_horizontal),
236
+ luamethod (LuaCamera, get_aspect_ratio),
237
+
238
+ {0 , 0 }
239
+ };
240
+ // clang-format on
0 commit comments