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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
|
//
//
#include <camera/camera.h>
#include "camera.h"
#include "vecmath.h"
#include "object.h"
#include "subsystem.h"
namespace scripting {
namespace api {
//**********HANDLE: Camera
ADE_OBJ(l_Camera, camid, "camera", "Camera handle");
ADE_FUNC(__tostring, l_Camera, NULL, "Camera name", "string", "Camera name, or an empty string if handle is invalid")
{
camid cid;
if(!ade_get_args(L, "o", l_Camera.Get(&cid)))
return ade_set_error(L, "s", "");
if(!cid.isValid())
return ade_set_error(L, "s", "");
return ade_set_args(L, "s", cid.getCamera()->get_name());
}
ADE_FUNC(isValid, l_Camera, NULL, "True if valid, false or nil if not", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
{
camid cid;
if(!ade_get_args(L, "o", l_Camera.Get(&cid)))
return ADE_RETURN_NIL;
if(!cid.isValid())
return ADE_RETURN_FALSE;
return ADE_RETURN_TRUE;
}
ADE_VIRTVAR(Name, l_Camera, "string", "New camera name", "string", "Camera name")
{
camid cid;
const char* s = nullptr;
if(!ade_get_args(L, "o|s", l_Camera.Get(&cid), &s))
return ade_set_error(L, "s", "");
if(!cid.isValid())
return ade_set_error(L, "s", "");
if(ADE_SETTING_VAR && s != NULL) {
cid.getCamera()->set_name(s);
}
return ade_set_args(L, "s", cid.getCamera()->get_name());
}
ADE_VIRTVAR(FOV, l_Camera, "number", "New camera FOV (in radians)", "number", "Camera FOV (in radians)")
{
camid cid;
float f = g3_get_hfov(VIEWER_ZOOM_DEFAULT);
if(!ade_get_args(L, "o|f", l_Camera.Get(&cid), &f))
return ade_set_error(L, "f", 0.0f);
if(!cid.isValid())
return ade_set_error(L, "f", 0.0f);
if(ADE_SETTING_VAR) {
cid.getCamera()->set_fov(f);
}
return ade_set_args(L, "f", g3_get_hfov(cid.getCamera()->get_fov()));
}
ADE_VIRTVAR(Orientation, l_Camera, "orientation", "New camera orientation", "orientation", "Camera orientation")
{
camid cid;
matrix_h *mh = NULL;
if(!ade_get_args(L, "o|o", l_Camera.Get(&cid), l_Matrix.GetPtr(&mh)))
return ade_set_error(L, "f", 0.0f);
if(!cid.isValid())
return ade_set_error(L, "f", 0.0f);
if(ADE_SETTING_VAR && mh != NULL) {
cid.getCamera()->set_rotation(mh->GetMatrix());
}
matrix mtx;
cid.getCamera()->get_info(NULL, &mtx);
return ade_set_args(L, "o", l_Matrix.Set(matrix_h(&mtx)));
}
ADE_VIRTVAR(Position, l_Camera, "vector", "New camera position", "vector", "Camera position")
{
camid cid;
vec3d *pos = NULL;
if(!ade_get_args(L, "o|o", l_Camera.Get(&cid), l_Vector.GetPtr(&pos)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if(!cid.isValid())
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if(ADE_SETTING_VAR && pos) {
cid.getCamera()->set_position(pos);
}
vec3d v = vmd_zero_vector;
cid.getCamera()->get_info(&v, NULL);
return ade_set_args(L, "o", l_Vector.Set(v));
}
ADE_VIRTVAR(Self, l_Camera, "object", "New mount object", "object", "Camera object")
{
camid cid;
object_h *oh = NULL;
if(!ade_get_args(L, "o|o", l_Camera.Get(&cid), l_Object.GetPtr(&oh)))
return ade_set_error(L, "o", l_Object.Set(object_h()));
if(!cid.isValid())
return ade_set_error(L, "o", l_Object.Set(object_h()));
if(ADE_SETTING_VAR && oh && oh->isValid()) {
cid.getCamera()->set_object_host(oh->objp());
}
return ade_set_object_with_breed(L, OBJ_INDEX(cid.getCamera()->get_object_host()));
}
ADE_VIRTVAR(SelfSubsystem, l_Camera, "subsystem", "New mount object subsystem", "subsystem", "Subsystem that the camera is mounted on")
{
camid cid;
ship_subsys_h *sso = NULL;
if(!ade_get_args(L, "o|o", l_Camera.Get(&cid), l_Subsystem.GetPtr(&sso)))
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
if(!cid.isValid())
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
if(ADE_SETTING_VAR && sso && sso->isValid()) {
cid.getCamera()->set_object_host(sso->objh.objp(), sso->ss->system_info->subobj_num);
}
object *objp = cid.getCamera()->get_object_host();
if(objp == NULL || objp->type != OBJ_SHIP)
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
int submodel = cid.getCamera()->get_object_host_submodel();
if(submodel < 0)
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
ship *shipp = &Ships[objp->instance];
polymodel *pm = model_get(Ship_info[shipp->ship_info_index].model_num);
if(pm == NULL)
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
bsp_info *sm = &pm->submodel[submodel];
ship_subsys *ss = ship_get_subsys(shipp, sm->name);
if(ss == NULL)
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
return ade_set_args(L, "o", l_Subsystem.Set(ship_subsys_h(objp, ss)));
}
ADE_VIRTVAR(Target, l_Camera, "object", "New target object", "object", "Camera target object")
{
camid cid;
object_h *oh = NULL;
if(!ade_get_args(L, "o|o", l_Camera.Get(&cid), l_Object.GetPtr(&oh)))
return ade_set_error(L, "o", l_Object.Set(object_h()));
if(!cid.isValid())
return ade_set_error(L, "o", l_Object.Set(object_h()));
if(ADE_SETTING_VAR && oh && oh->isValid()) {
cid.getCamera()->set_object_target(oh->objp());
}
return ade_set_object_with_breed(L, OBJ_INDEX(cid.getCamera()->get_object_target()));
}
ADE_VIRTVAR(TargetSubsystem, l_Camera, "subsystem", "New target subsystem", "subsystem", "Subsystem that the camera is pointed at")
{
camid cid;
ship_subsys_h *sso = NULL;
if(!ade_get_args(L, "o|o", l_Camera.Get(&cid), l_Subsystem.GetPtr(&sso)))
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
if(!cid.isValid())
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
if(ADE_SETTING_VAR && sso && sso->isValid()) {
cid.getCamera()->set_object_target(sso->objh.objp(), sso->ss->system_info->subobj_num);
}
object *objp = cid.getCamera()->get_object_target();
if(objp == NULL || objp->type != OBJ_SHIP)
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
int submodel = cid.getCamera()->get_object_target_submodel();
if(submodel < 0)
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
ship *shipp = &Ships[objp->instance];
polymodel *pm = model_get(Ship_info[shipp->ship_info_index].model_num);
if(pm == NULL)
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
bsp_info *sm = &pm->submodel[submodel];
ship_subsys *ss = ship_get_subsys(shipp, sm->name);
if(ss == NULL)
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
return ade_set_args(L, "o", l_Subsystem.Set(ship_subsys_h(objp, ss)));
}
ADE_FUNC(setFOV, l_Camera, "[number FOV, number ZoomTime, number ZoomAccelerationTime, number ZoomDecelerationTime]",
"Sets camera FOV"
"<br>FOV is the final field of view, in radians, of the camera."
"<br>Zoom Time is the total time to take zooming in or out."
"<br>Acceleration Time is the total time it should take the camera to get up to full zoom speed."
"<br>Deceleration Time is the total time it should take the camera to slow down from full zoom speed.",
"boolean", "true if successful, false or nil otherwise")
{
camid cid;
float n_fov = g3_get_hfov(VIEWER_ZOOM_DEFAULT);
float time=0.0f;
float acc_time=0.0f;
float dec_time=0.0f;
if(!ade_get_args(L, "o|ffff", l_Camera.Get(&cid), &n_fov, &time, &acc_time, &dec_time))
return ADE_RETURN_NIL;
if(!cid.isValid())
return ADE_RETURN_NIL;
cid.getCamera()->set_fov(n_fov, time, acc_time, dec_time);
return ADE_RETURN_TRUE;
}
ADE_FUNC(setOrientation, l_Camera, "[orientation WorldOrientation, number RotationTime, number AccelerationTime, number DecelerationTime]",
"Sets camera orientation and velocity data."
"<br>Orientation is the final orientation for the camera, after it has finished moving. If not specified, the camera will simply stop at its current orientation."
"<br>Rotation time (seconds) is how long total, including acceleration, the camera should take to rotate. If it is not specified, the camera will jump to the specified orientation."
"<br>Acceleration time (seconds) is how long it should take the camera to get 'up to speed'. If not specified, the camera will instantly start moving."
"<br>Deceleration time (seconds) is how long it should take the camera to slow down. If not specified, the camera will instantly stop moving.",
"boolean", "true if successful, false or nil otherwise")
{
camid cid;
matrix_h *mh=NULL;
float time=0.0f;
float acc_time=0.0f;
float dec_time=0.0f;
if(!ade_get_args(L, "o|offf", l_Camera.Get(&cid), l_Matrix.GetPtr(&mh), &time, &acc_time, &dec_time))
return ADE_RETURN_NIL;
if(!cid.isValid())
return ADE_RETURN_NIL;
camera *cam = cid.getCamera();
if(mh != NULL)
{
cam->set_rotation(mh->GetMatrix(), time, acc_time, dec_time);
}
else
{
cam->set_rotation();
}
return ADE_RETURN_TRUE;
}
ADE_FUNC(setPosition, l_Camera, "[vector Position, number TranslationTime, number AccelerationTime, number DecelerationTime]",
"Sets camera position and velocity data."
"<br>Position is the final position for the camera. If not specified, the camera will simply stop at its current position."
"<br>Translation time (seconds) is how long total, including acceleration, the camera should take to move. If it is not specified, the camera will jump to the specified position."
"<br>Acceleration time (seconds) is how long it should take the camera to get 'up to speed'. If not specified, the camera will instantly start moving."
"<br>Deceleration time (seconds) is how long it should take the camera to slow down. If not specified, the camera will instantly stop moving.",
"boolean", "true if successful, false or nil otherwise")
{
camid cid;
vec3d *pos=NULL;
float time=0.0f;
float acc_time=0.0f;
float dec_time=0.0f;
if(!ade_get_args(L, "o|offf", l_Camera.Get(&cid), l_Vector.GetPtr(&pos), &time, &acc_time, &dec_time))
return ADE_RETURN_NIL;
if(!cid.isValid())
return ADE_RETURN_NIL;
cid.getCamera()->set_position(pos, time, acc_time, dec_time);
return ADE_RETURN_TRUE;
}
}
}
|