Skip to content

Commit 1cbfb34

Browse files
authored
add findWorld / findObject for objects (scp-fs2open#7443)
1 parent 975ce27 commit 1cbfb34

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

code/scripting/api/objs/object.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,5 +766,37 @@ ADE_FUNC(getIFFColor, l_Object, "boolean ReturnType",
766766
}
767767
}
768768

769+
ADE_FUNC(findWorldPoint, l_Object, "vector", "Calculates the world coordinates of a point in the object's frame of reference", "vector", "Point, or empty vector if handle is not valid")
770+
{
771+
object_h *objh;
772+
vec3d pnt, outpnt;
773+
if (!ade_get_args(L, "oo", l_Object.GetPtr(&objh), l_Vector.Get(&pnt)))
774+
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
775+
776+
if (!objh->isValid())
777+
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
778+
779+
auto objp = objh->objp();
780+
vm_vec_unrotate(&outpnt, &pnt, &objp->orient);
781+
outpnt += objp->pos;
782+
return ade_set_args(L, "o", l_Vector.Set(outpnt));
783+
}
784+
785+
ADE_FUNC(findObjectPoint, l_Object, "vector", "Calculates the coordinates in an object's frame of reference, of a point in world coordinates", "vector", "Point, or empty vector if handle is not valid")
786+
{
787+
object_h *objh;
788+
vec3d pnt, outpnt;
789+
if (!ade_get_args(L, "oo", l_Object.GetPtr(&objh), l_Vector.Get(&pnt)))
790+
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
791+
792+
if (!objh->isValid())
793+
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
794+
795+
auto objp = objh->objp();
796+
pnt -= objp->pos;
797+
vm_vec_rotate(&outpnt, &pnt, &objp->orient);
798+
return ade_set_args(L, "o", l_Vector.Set(outpnt));
799+
}
800+
769801
} // namespace api
770802
} // namespace scripting

0 commit comments

Comments
 (0)