Skip to content

Commit 9aae050

Browse files
author
Roberto De Ioris
committed
added support for quaternions in set_actor_rotation
1 parent fa53448 commit 9aae050

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

Source/UnrealEnginePython/Private/UObject/UEPyTransform.cpp

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ static bool check_vector_args(PyObject *args, FVector &vec, bool &sweep, bool &t
3535

3636
static bool check_rotation_args(PyObject *args, FQuat &quat, bool &sweep, bool &teleport_physics) {
3737
PyObject *py_rotation = nullptr;
38-
float pitch, yaw, roll;
38+
float roll, pitch, yaw;
3939
PyObject *py_sweep = nullptr;
4040
PyObject *py_teleport_physics = nullptr;
4141

4242
if (!PyArg_ParseTuple(args, "O|OO", &py_rotation, &py_sweep, &py_teleport_physics)) {
4343
PyErr_Clear();
44-
if (!PyArg_ParseTuple(args, "fff|OO", &roll, &pitch, &yaw, &py_teleport_physics)) {
44+
if (!PyArg_ParseTuple(args, "fff|OO", &roll, &pitch, &yaw, &py_sweep, &py_teleport_physics)) {
4545
return false;
4646
}
4747
}
@@ -70,6 +70,41 @@ static bool check_rotation_args(PyObject *args, FQuat &quat, bool &sweep, bool &
7070
return true;
7171
}
7272

73+
static bool check_rotation_args_no_sweep(PyObject *args, FQuat &quat, bool &teleport_physics) {
74+
PyObject *py_rotation = nullptr;
75+
float roll, pitch, yaw;
76+
PyObject *py_teleport_physics = nullptr;
77+
78+
if (!PyArg_ParseTuple(args, "O|O", &py_rotation, &py_teleport_physics)) {
79+
PyErr_Clear();
80+
if (!PyArg_ParseTuple(args, "fff|O", &roll, &pitch, &yaw, &py_teleport_physics)) {
81+
return false;
82+
}
83+
}
84+
85+
if (py_rotation) {
86+
ue_PyFQuat *ue_py_quat = py_ue_is_fquat(py_rotation);
87+
if (ue_py_quat) {
88+
quat = ue_py_quat->quat;
89+
}
90+
else {
91+
ue_PyFRotator *ue_py_rot = py_ue_is_frotator(py_rotation);
92+
if (!ue_py_rot) {
93+
PyErr_SetString(PyExc_Exception, "argument is not a FQuat or FRotator");
94+
return false;
95+
}
96+
quat = ue_py_rot->rot.Quaternion();
97+
}
98+
}
99+
else {
100+
quat = FQuat(FRotator(pitch, yaw, roll));
101+
}
102+
103+
teleport_physics = (py_teleport_physics && PyObject_IsTrue(py_teleport_physics));
104+
105+
return true;
106+
}
107+
73108
PyObject *py_ue_get_actor_location(ue_PyUObject *self, PyObject * args) {
74109

75110
ue_py_check(self);
@@ -302,17 +337,18 @@ PyObject *py_ue_set_actor_rotation(ue_PyUObject *self, PyObject * args) {
302337

303338
ue_py_check(self);
304339

305-
FRotator rot;
306-
if (!py_ue_rotator_arg(args, rot))
307-
return NULL;
340+
FQuat quat;
341+
bool teleport_physics;
342+
if (!check_rotation_args_no_sweep(args, quat, teleport_physics))
343+
return nullptr;
308344

309345
AActor *actor = ue_get_actor(self);
310346
if (!actor)
311347
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
312-
actor->SetActorRotation(rot);
313-
Py_INCREF(Py_None);
314-
return Py_None;
315-
348+
if (actor->SetActorRotation(quat, teleport_physics ? ETeleportType::TeleportPhysics : ETeleportType::None)) {
349+
Py_RETURN_TRUE;
350+
}
351+
Py_RETURN_FALSE;
316352
}
317353

318354

tests/test_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ def test_get_url_parameter(self):
4747

4848

4949
if __name__ == '__main__':
50-
unittest.main(exit=False)
50+
unittest.main(exit=False)

0 commit comments

Comments
 (0)