Skip to content

Commit 311877f

Browse files
feat: add 3D drawing functions & required types
1 parent 124a612 commit 311877f

29 files changed

Lines changed: 3044 additions & 655 deletions

examples/example_basic_2.py

Lines changed: 522 additions & 0 deletions
Large diffs are not rendered by default.

extensions/pl_animation_ext_m.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ Index of this file:
1919
// [SECTION] implementations
2020
//-----------------------------------------------------------------------------
2121

22-
typedef struct _pyplAnimationI
23-
{
24-
PyObject_HEAD
25-
} pyplAnimationI;
26-
2722
PyObject*
2823
animation_register_ecs_system(PyObject* self)
2924
{
@@ -32,21 +27,10 @@ animation_register_ecs_system(PyObject* self)
3227
Py_RETURN_NONE;
3328
}
3429

35-
static PyMethodDef gatplAnimationICommands[] =
30+
static PyMethodDef gatCommandsplAnimationI[] =
3631
{
3732
{"register_ecs_system", (PyCFunction)animation_register_ecs_system, METH_NOARGS | METH_STATIC, NULL},
3833
{NULL, NULL, 0, NULL}
3934
};
4035

41-
static PyType_Slot gatplAnimationISlots[] = {
42-
{Py_tp_methods, (void*)gatplAnimationICommands},
43-
{0, 0}
44-
};
45-
46-
static PyType_Spec plAnimationISpec = {
47-
"pilotlight.plAnimationI",
48-
sizeof(pyplAnimationI),
49-
0,
50-
Py_TPFLAGS_DEFAULT,
51-
gatplAnimationISlots
52-
};
36+
PL_NEW_PYTHON_API(plAnimationI)

extensions/pl_camera_ext_m.c

Lines changed: 195 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,35 @@ Index of this file:
1919
// [SECTION] implementations
2020
//-----------------------------------------------------------------------------
2121

22-
typedef struct _pyplCameraI
22+
// typedef struct _pyplCameraEcsI
23+
// {
24+
// PyObject_HEAD
25+
// } pyplCameraEcsI;
26+
27+
typedef struct _plPyCamera
2328
{
2429
PyObject_HEAD
25-
} pyplCameraI;
30+
plCamera tCamera;
31+
} plPyCamera;
2632

2733
PyObject*
2834
camera_register_ecs_system(PyObject* self)
2935
{
3036

31-
gptCamera->register_ecs_system();
37+
gptCameraEcs->register_ecs_system();
3238
Py_RETURN_NONE;
3339
}
3440

3541
PyObject*
3642
camera_get_ecs_type_key(PyObject* self)
3743
{
3844

39-
plEcsTypeKey tKey = gptCamera->get_ecs_type_key();
45+
plEcsTypeKey tKey = gptCameraEcs->get_ecs_type_key();
4046
return PyLong_FromUInt32(tKey);
4147
}
4248

4349
PyObject*
44-
camera_create_perspective(PyObject* self, PyObject* args, PyObject* kwargs)
50+
camera_ecs_create_perspective(PyObject* self, PyObject* args, PyObject* kwargs)
4551
{
4652

4753
PyObject* ptPyLibrary = NULL;
@@ -71,7 +77,7 @@ camera_create_perspective(PyObject* self, PyObject* args, PyObject* kwargs)
7177

7278
plComponentLibrary* ptCompLibrary = PyCapsule_GetPointer(ptPyLibrary, "plComponentLibrary");
7379

74-
plEntity tCamera = gptCamera->create_perspective(
80+
plEntity tCamera = gptCameraEcs->create_perspective(
7581
ptCompLibrary,
7682
pcName,
7783
pl_get_dvec3_from_python(ptPyPos),
@@ -82,7 +88,75 @@ camera_create_perspective(PyObject* self, PyObject* args, PyObject* kwargs)
8288
bReverseZ,
8389
NULL);
8490

85-
return Py_BuildValue("(III)", gptCamera->get_ecs_type_key(), tCamera.uIndex, tCamera.uGeneration);
91+
return Py_BuildValue("(III)", gptCameraEcs->get_ecs_type_key(), tCamera.uIndex, tCamera.uGeneration);
92+
}
93+
94+
PyObject*
95+
camera_translate(PyObject* self, PyObject* args, PyObject* kwargs)
96+
{
97+
98+
PyObject* ptPyCamera = NULL;
99+
100+
static const char* apcKeywords[] = {
101+
"camera",
102+
"dX",
103+
"dY",
104+
"dZ",
105+
NULL,
106+
};
107+
108+
double dX = 0.0;
109+
double dY = 0.0;
110+
double dZ = 0.0;
111+
if (!pl_parse("Oddd", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
112+
&ptPyCamera, &dX, &dY, &dZ))
113+
return NULL;
114+
115+
plCamera* ptCamera = NULL;
116+
if(PyObject_TypeCheck(ptPyCamera, (PyTypeObject*)gptCameraType))
117+
{
118+
plPyCamera* ptPyTypeCamera = (plPyCamera*)ptPyCamera;
119+
ptCamera = &ptPyTypeCamera->tCamera;
120+
}
121+
else
122+
{
123+
ptCamera = PyCapsule_GetPointer(ptPyCamera, "plEntityComponent");
124+
}
125+
gptCamera->translate(ptCamera, dX, dY, dZ);
126+
Py_RETURN_NONE;
127+
}
128+
129+
PyObject*
130+
camera_rotate(PyObject* self, PyObject* args, PyObject* kwargs)
131+
{
132+
133+
PyObject* ptPyCamera = NULL;
134+
135+
static const char* apcKeywords[] = {
136+
"camera",
137+
"fPitch",
138+
"fYaw",
139+
NULL,
140+
};
141+
142+
float fPitch = 0.0f;
143+
float fYaw = 0.0f;
144+
if (!pl_parse("Off", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
145+
&ptPyCamera, &fPitch, &fYaw))
146+
return NULL;
147+
148+
plCamera* ptCamera = NULL;
149+
if(PyObject_TypeCheck(ptPyCamera, (PyTypeObject*)gptCameraType))
150+
{
151+
plPyCamera* ptPyTypeCamera = (plPyCamera*)ptPyCamera;
152+
ptCamera = &ptPyTypeCamera->tCamera;
153+
}
154+
else
155+
{
156+
ptCamera = PyCapsule_GetPointer(ptPyCamera, "plEntityComponent");
157+
}
158+
gptCamera->rotate(ptCamera, fPitch, fYaw);
159+
Py_RETURN_NONE;
86160
}
87161

88162
PyObject*
@@ -102,11 +176,51 @@ camera_set_fov(PyObject* self, PyObject* args, PyObject* kwargs)
102176
&ptPyCamera, &fYFov))
103177
return NULL;
104178

105-
plCamera* ptCamera = PyCapsule_GetPointer(ptPyCamera, "plEntityComponent");
179+
plCamera* ptCamera = NULL;
180+
if(PyObject_TypeCheck(ptPyCamera, (PyTypeObject*)gptCameraType))
181+
{
182+
plPyCamera* ptPyTypeCamera = (plPyCamera*)ptPyCamera;
183+
ptCamera = &ptPyTypeCamera->tCamera;
184+
}
185+
else
186+
{
187+
ptCamera = PyCapsule_GetPointer(ptPyCamera, "plEntityComponent");
188+
}
106189
gptCamera->set_fov(ptCamera, fYFov);
107190
Py_RETURN_NONE;
108191
}
109192

193+
PyObject*
194+
camera_set_aspect(PyObject* self, PyObject* args, PyObject* kwargs)
195+
{
196+
197+
PyObject* ptPyCamera = NULL;
198+
199+
static const char* apcKeywords[] = {
200+
"camera",
201+
"aspect",
202+
NULL,
203+
};
204+
205+
float fAspect = 0.0f;
206+
if (!pl_parse("Of", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
207+
&ptPyCamera, &fAspect))
208+
return NULL;
209+
210+
plCamera* ptCamera = NULL;
211+
if(PyObject_TypeCheck(ptPyCamera, (PyTypeObject*)gptCameraType))
212+
{
213+
plPyCamera* ptPyTypeCamera = (plPyCamera*)ptPyCamera;
214+
ptCamera = &ptPyTypeCamera->tCamera;
215+
}
216+
else
217+
{
218+
ptCamera = PyCapsule_GetPointer(ptPyCamera, "plEntityComponent");
219+
}
220+
gptCamera->set_aspect(ptCamera, fAspect);
221+
Py_RETURN_NONE;
222+
}
223+
110224
PyObject*
111225
camera_update(PyObject* self, PyObject* args, PyObject* kwargs)
112226
{
@@ -122,30 +236,88 @@ camera_update(PyObject* self, PyObject* args, PyObject* kwargs)
122236
&ptPyCamera))
123237
return NULL;
124238

125-
plCamera* ptCamera = PyCapsule_GetPointer(ptPyCamera, "plEntityComponent");
239+
plCamera* ptCamera = NULL;
240+
if(PyObject_TypeCheck(ptPyCamera, (PyTypeObject*)gptCameraType))
241+
{
242+
plPyCamera* ptPyTypeCamera = (plPyCamera*)ptPyCamera;
243+
ptCamera = &ptPyTypeCamera->tCamera;
244+
}
245+
else
246+
{
247+
ptCamera = PyCapsule_GetPointer(ptPyCamera, "plEntityComponent");
248+
}
126249
gptCamera->update(ptCamera);
127250
Py_RETURN_NONE;
128251
}
129252

130-
static PyMethodDef gatplCameraICommands[] =
253+
PyObject*
254+
camera_init_perspective(PyObject* self, PyObject* args, PyObject* kwargs)
131255
{
132-
{"register_ecs_system", (PyCFunction)camera_register_ecs_system, METH_NOARGS | METH_STATIC, NULL},
133-
{"create_perspective", (PyCFunction)camera_create_perspective, METH_VARARGS | METH_KEYWORDS | METH_STATIC, NULL},
256+
257+
PyObject* ptPyCamera = NULL;
258+
PyObject* ptPyPos = NULL;
259+
260+
static const char* apcKeywords[] = {
261+
"camera",
262+
"pos",
263+
"yfov",
264+
"aspect",
265+
"nearZ",
266+
"farZ",
267+
"reverseZ",
268+
NULL,
269+
};
270+
271+
float fYFov = 0.0f;
272+
float fAspect = 1.0f;
273+
float fNearZ = 0.0f;
274+
float fFarZ = 0.0f;
275+
int bReverseZ = false;
276+
if (!pl_parse("OOffffp", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
277+
&ptPyCamera, &ptPyPos, &fYFov, &fAspect, &fNearZ, &fFarZ, &bReverseZ))
278+
return NULL;
279+
280+
plCamera* ptCamera = NULL;
281+
if(PyObject_TypeCheck(ptPyCamera, (PyTypeObject*)gptCameraType))
282+
{
283+
plPyCamera* ptPyTypeCamera = (plPyCamera*)ptPyCamera;
284+
ptCamera = &ptPyTypeCamera->tCamera;
285+
}
286+
else
287+
{
288+
ptCamera = PyCapsule_GetPointer(ptPyCamera, "plEntityComponent");
289+
}
290+
291+
gptCamera->init_perspective(
292+
ptCamera,
293+
pl_get_dvec3_from_python(ptPyPos),
294+
fYFov,
295+
fAspect,
296+
fNearZ,
297+
fFarZ,
298+
bReverseZ);
299+
300+
Py_RETURN_NONE;
301+
}
302+
303+
static PyMethodDef gatCommandsplCameraI[] =
304+
{
305+
{"translate", (PyCFunction)camera_translate, METH_VARARGS | METH_KEYWORDS | METH_STATIC, NULL},
306+
{"rotate", (PyCFunction)camera_rotate, METH_VARARGS | METH_KEYWORDS | METH_STATIC, NULL},
134307
{"set_fov", (PyCFunction)camera_set_fov, METH_VARARGS | METH_KEYWORDS | METH_STATIC, NULL},
308+
{"set_aspect", (PyCFunction)camera_set_aspect, METH_VARARGS | METH_KEYWORDS | METH_STATIC, NULL},
135309
{"update", (PyCFunction)camera_update, METH_VARARGS | METH_KEYWORDS | METH_STATIC, NULL},
136-
{"get_ecs_type_key", (PyCFunction)camera_get_ecs_type_key, METH_NOARGS | METH_STATIC, NULL},
310+
{"init_perspective", (PyCFunction)camera_init_perspective, METH_VARARGS | METH_KEYWORDS | METH_STATIC, NULL},
137311
{NULL, NULL, 0, NULL}
138312
};
139313

140-
static PyType_Slot gatplCameraISlots[] = {
141-
{Py_tp_methods, (void*)gatplCameraICommands},
142-
{0, 0}
314+
static PyMethodDef gatCommandsplCameraEcsI[] =
315+
{
316+
{"register_ecs_system", (PyCFunction)camera_register_ecs_system, METH_NOARGS | METH_STATIC, NULL},
317+
{"create_perspective", (PyCFunction)camera_ecs_create_perspective, METH_VARARGS | METH_KEYWORDS | METH_STATIC, NULL},
318+
{"get_ecs_type_key", (PyCFunction)camera_get_ecs_type_key, METH_NOARGS | METH_STATIC, NULL},
319+
{NULL, NULL, 0, NULL}
143320
};
144321

145-
static PyType_Spec plCameraISpec = {
146-
"pilotlight.plCameraI",
147-
sizeof(pyplCameraI),
148-
0,
149-
Py_TPFLAGS_DEFAULT,
150-
gatplCameraISlots
151-
};
322+
PL_NEW_PYTHON_API(plCameraI)
323+
PL_NEW_PYTHON_API(plCameraEcsI)

0 commit comments

Comments
 (0)