Repository navigation
Expand file tree
/
Copy pathUEPyController.cpp
More file actions
112 lines (82 loc) · 2.81 KB
/
Copy pathUEPyController.cpp
File metadata and controls
112 lines (82 loc) · 2.81 KB
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
#include "UnrealEnginePythonPrivatePCH.h"
PyObject *py_ue_controller_posses(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
if (!PyArg_ParseTuple(args, "O:posses", &obj))
{
return NULL;
}
AController *controller = ue_py_check_type<AController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "uobject is not an AController");
APawn *pawn = ue_py_check_type<APawn>(obj);
if (!pawn)
return PyErr_Format(PyExc_Exception, "uobject is not an APawn");
controller->Possess(pawn);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_controller_get_hud(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
APlayerController *controller = ue_py_check_type<APlayerController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "uobject is not an AController");
ue_PyUObject *ret = ue_get_python_wrapper((UObject *)controller->GetHUD());
if (!ret)
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
Py_INCREF(ret);
return (PyObject *)ret;
}
PyObject *py_ue_controller_unposses(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AController *controller = ue_py_check_type<AController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "uobject is not an AController");
controller->UnPossess();
Py_RETURN_NONE;
}
PyObject *py_ue_get_controlled_pawn(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AController *controller = ue_py_check_type<AController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "uobject is not an AController");
#if ENGINE_MINOR_VERSION >= 15
APawn *pawn = controller->GetPawn();
#else
APawn *pawn = controller->GetControlledPawn();
#endif
if (!pawn)
{
Py_RETURN_NONE;
}
ue_PyUObject *ret = ue_get_python_wrapper(pawn);
if (!ret)
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
Py_INCREF(ret);
return (PyObject *)ret;
}
PyObject *py_ue_controller_project_world_location_to_screen(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj_point;
PyObject *py_relative = nullptr;
if (!PyArg_ParseTuple(args, "O|O:project_world_location_to_screen", &py_obj_point, &py_relative))
return nullptr;
APlayerController *controller = ue_py_check_type<APlayerController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "uobject is not an AController");
ue_PyFVector *point = py_ue_is_fvector(py_obj_point);
if (!point)
return PyErr_Format(PyExc_Exception, "argument is not a FVector");
// TODO: Check return value:
FVector2D screenLocation;
if (!controller->ProjectWorldLocationToScreen(point->vec, screenLocation, (py_relative && PyObject_IsTrue(py_relative))))
{
return PyErr_Format(PyExc_Exception, "unable to project coordinates");
}
return Py_BuildValue("(ff)", screenLocation.X, screenLocation.Y);
}