1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
//
//
#include "eye.h"
#include "vecmath.h"
namespace scripting {
namespace api {
eye_h::eye_h() {
model = -1;
eye_idx = -1;
}
eye_h::eye_h(int n_m, int n_e) {
model = n_m;
eye_idx = n_e;
}
bool eye_h::isValid() const {
polymodel* pm = NULL;
return (model > -1
&& (pm = model_get(model)) != NULL
&& eye_idx > -1
&& eye_idx < pm->n_view_positions);
}
ADE_OBJ(l_Eyepoint, eye_h, "eyepoint", "Eyepoint handle");
ADE_VIRTVAR(Normal, l_Eyepoint, "vector", "Eyepoint normal", "vector", "Eyepoint normal, or null vector if handle is invalid")
{
eye_h *eh;
vec3d *v;
if(!ade_get_args(L, "o|o", l_Eyepoint.GetPtr(&eh), l_Vector.GetPtr(&v)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if(!eh->isValid())
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
polymodel *pm = model_get(eh->model);
if(ADE_SETTING_VAR && v != NULL)
{
pm->view_positions[eh->eye_idx].norm = *v;
}
return ade_set_args(L, "o", l_Vector.Set(pm->view_positions[eh->eye_idx].norm));
}
ADE_VIRTVAR(Position, l_Eyepoint, "vector", "Eyepoint location (Local vector)", "vector", "Eyepoint location, or null vector if handle is invalid")
{
eye_h *eh;
vec3d *v;
if(!ade_get_args(L, "o|o", l_Eyepoint.GetPtr(&eh), l_Vector.GetPtr(&v)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if(!eh->isValid())
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
polymodel *pm = model_get(eh->model);
if(ADE_SETTING_VAR && v != NULL)
{
pm->view_positions[eh->eye_idx].pnt = *v;
}
return ade_set_args(L, "o", l_Vector.Set(pm->view_positions[eh->eye_idx].pnt));
}
ADE_FUNC(isValid, l_Eyepoint, nullptr, "Detect whether this handle is valid", "boolean", "true if valid false otherwise")
{
eye_h* eh = nullptr;
if (!ade_get_args(L, "o", l_Eyepoint.GetPtr(&eh))) {
return ADE_RETURN_FALSE;
}
return ade_set_args(L, "b", eh->isValid());
}
ADE_FUNC_DEPRECATED(IsValid,
l_Eyepoint,
nullptr,
"Detect whether this handle is valid",
"boolean",
"true if valid false otherwise",
gameversion::version(24, 0),
"IsValid is named with the incorrect case. Use isValid instead.")
{
eye_h *eh = nullptr;
if (!ade_get_args(L, "o", l_Eyepoint.GetPtr(&eh)))
{
return ADE_RETURN_FALSE;
}
return ade_set_args(L, "b", eh->isValid());
}
}
}
|