SimpleFastOpenAtomicVisualiser
Loading...
Searching...
No Matches
camera.h
Go to the documentation of this file.
1#ifndef LUA_CAMERA_H
2#define LUA_CAMERA_H
3
12inline int Camera::lua_cameraPosition(lua_State * lua)
13{
14 if (lua_gettop(lua) >= 1 && lua_isstring(lua, 1) && std::string(lua_tostring(lua, 1)) == "help")
15 {
16 lua_writestring("cameraPosition:\n Arguments:\n spherical [bool, optional]\n Get the position of the camera.\n By default in cartesian form.\n");
17 return 0;
18 };
19 int args = lua_gettop(lua);
20 bool spherical = false;
21 if (args == 1)
22 {
23 LuaBool b;
24 b.read(lua, 1);
25 spherical = b.bit;
26 }
27
28 glm::vec3 pos = position(spherical);
29
30 lua_pushnumber(lua, pos.x);
31 lua_pushnumber(lua, pos.y);
32 lua_pushnumber(lua, pos.z);
33
34 return 3;
35}
36
47inline int Camera::lua_setCameraPosition(lua_State * lua)
48{
49 if (lua_gettop(lua) >= 1 && lua_isstring(lua, 1) && std::string(lua_tostring(lua, 1)) == "help")
50 {
51 lua_writestring("setCameraPosition:\n Arguments:\n x [number],\b y [number],\n z[number]\n Set the position of the camera.\n");
52 return 0;
53 };
54 int args = lua_gettop(lua);
55 if (args != 3)
56 {
57 const std::string msg = "setCameraPosition expects r, theta, and phi as arguments.\n";
58 lua_pushlstring(lua, msg.c_str(), msg.length());
59 return lua_error(lua);
60 }
61
62 LuaNumber r, theta, phi;
63 r.read(lua, 1);
64 theta.read(lua, 2);
65 phi.read(lua, 3);
66 setPosition(glm::vec3(r.n, theta.n, phi.n));
67
68 return 0;
69}
70
79inline int Camera::lua_rotateCamera(lua_State * lua)
80{
81 if (lua_gettop(lua) >= 1 && lua_isstring(lua, 1) && std::string(lua_tostring(lua, 1)) == "help")
82 {
83 lua_writestring("rotateCamera:\n Arguments:\n phi [number]\n Rotate the camera by phi radians.\n");
84 return 0;
85 };
86 int args = lua_gettop(lua);
87 if (args != 1)
88 {
89 const std::string msg = "rotateCamera expects a number as argument.\n";
90 lua_pushlstring(lua, msg.c_str(), msg.length());
91 return lua_error(lua);
92 }
93
95 dphi.read(lua, 1);
96 rotate(-dphi.n);
97
98 return 0;
99}
100
109inline int Camera::lua_zoomCamera(lua_State * lua)
110{
111 if (lua_gettop(lua) >= 1 && lua_isstring(lua, 1) && std::string(lua_tostring(lua, 1)) == "help")
112 {
113 lua_writestring("zoomCamera:\n Arguments:\n r [number]\n Zoom the camera.\n");
114 return 0;
115 };
116 int args = lua_gettop(lua);
117 if (args != 1)
118 {
119 const std::string msg = "zoomCamera expects a number as argument.\n";
120 lua_pushlstring(lua, msg.c_str(), msg.length());
121 return lua_error(lua);
122 }
123
125 dr.read(lua, 1);
126 zoom(-dr.n);
127
128 return 0;
129}
130
139inline int Camera::lua_inclineCamera(lua_State * lua)
140{
141 if (lua_gettop(lua) >= 1 && lua_isstring(lua, 1) && std::string(lua_tostring(lua, 1)) == "help")
142 {
143 lua_writestring("inclineCamera:\n Arguments:\n theta [number]\n Incline the camera by theta radians.\n");
144 return 0;
145 };
146 int args = lua_gettop(lua);
147 if (args != 1)
148 {
149 const std::string msg = "inclineCamera expects a number as argument.\n";
150 lua_pushlstring(lua, msg.c_str(), msg.length());
151 return lua_error(lua);
152 }
153
155 dtheta.read(lua, 1);
156 incline(dtheta.n);
157
158 return 0;
159}
160
169inline int Camera::lua_setCameraFieldOfView(lua_State * lua)
170{
171 if (lua_gettop(lua) >= 1 && lua_isstring(lua, 1) && std::string(lua_tostring(lua, 1)) == "help")
172 {
173 lua_writestring("setCameraFieldOfView:\n Arguments:\n fov [number]\n Set the camera's fov in degrees.\n");
174 return 0;
175 };
176 int args = lua_gettop(lua);
177 if (args != 1)
178 {
179 const std::string msg = "setCameraFieldOfView expects a number as argument.\n";
180 lua_pushlstring(lua, msg.c_str(), msg.length());
181 return lua_error(lua);
182 }
183
184 LuaNumber fov;
185 fov.read(lua, 1);
186 fieldOfView = fov.n;
187 reset();
188
189 return 0;
190}
191
199inline int Camera::lua_getCameraFieldOfView(lua_State * lua)
200{
201 if (lua_gettop(lua) >= 1 && lua_isstring(lua, 1) && std::string(lua_tostring(lua, 1)) == "help")
202 {
203 lua_writestring("getCameraFieldOfView:\n Arguments: none\n Get the camera's fov in degrees.\n");
204 return 0;
205 };
206 lua_pushnumber(lua, fieldOfView);
207 return 1;
208}
209
210#endif /* LUA_CAMERA_H */
void reset()
Set the default view.
Definition camera.h:62
int lua_setCameraPosition(lua_State *lua)
Set Camera position.
Definition camera.h:47
void setPosition(glm::vec3 positionSpherical)
Set the camera's position.
Definition camera.h:151
int lua_cameraPosition(lua_State *lua)
Get the Camera position.
Definition camera.h:12
int lua_rotateCamera(lua_State *lua)
Rotate the Camera.
Definition camera.h:79
int lua_getCameraFieldOfView(lua_State *lua)
Set the field of view.
Definition camera.h:199
glm::vec3 position(bool spherical=false) const
Return the cartesian position vector.
Definition camera.h:164
int lua_inclineCamera(lua_State *lua)
Incline the camera.
Definition camera.h:139
void rotate(float increment)
Rotate about the y OpenGL axis.
Definition camera.h:137
int lua_setCameraFieldOfView(lua_State *lua)
Set the field of view.
Definition camera.h:169
void zoom(float increment)
Increment the zoom.
Definition camera.h:111
void incline(float increment)
Incline about the y OpenGL axis.
Definition camera.h:118
int lua_zoomCamera(lua_State *lua)
Zoom the Camera.
Definition camera.h:109
const float dr
Definition main.h:38
const float dphi
Definition main.h:40
const float dtheta
Definition main.h:39
const T phi
Golden ratio.
Definition meshes.h:12
Interop for booleans Lua.
Definition LuaBool.h:11
void read(lua_State *lua, int index)
Read the bool from stack index index.
Definition LuaBool.h:27
bool bit
Definition LuaBool.h:85
Interop for a number in Lua.
Definition LuaNumber.h:11
double n
Definition LuaNumber.h:84
void read(lua_State *lua, int index)
Read the number from stack index index.
Definition LuaNumber.h:26