4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
/*****************************************
20
* Copyright (C) 2002 Bertrand 'blam' LAMY
21
*****************************************/
27
static PyObject* PyP3_PointsNormal (PyObject* module, PyObject* args) {
33
PyP3_GetPosition (PySequence_Fast_GET_ITEM (args, 0), &a, &csys);
34
PyP3_GetPositionInto (PySequence_Fast_GET_ITEM (args, 1), csys, b);
35
PyP3_GetPositionInto (PySequence_Fast_GET_ITEM (args, 2), csys, c);
36
if (PySequence_Size (args) == 4) {
37
v = (P3_vector*) PySequence_Fast_GET_ITEM (args, 3);
38
Py_XDECREF ((PyObject*) v->parent);
40
if (csys != NULL) Py_INCREF ((PyObject*) csys);
41
P3_face_normal (v->coord, a, b, c);
45
v = (P3_vector*) PyP3Vector_Type.tp_alloc (&PyP3Vector_Type, 0);
47
if (csys != NULL) Py_INCREF ((PyObject*) csys);
48
P3_face_normal (v->coord, a, b, c);
58
static PyObject* PyP3_ActivateMaterial (PyObject* module, P3_material* a) {
59
if ((PyObject*) a == Py_None) { a = NULL; }
60
P3_material_activate (a);
65
static PyObject* PyP3_GetScreenWidth (PyObject* module) {
66
return PyInt_FromLong ((long) screen_w);
69
static PyObject* PyP3_GetScreenHeight (PyObject* module) {
70
return PyInt_FromLong ((long) screen_h);
73
static PyObject* PyP3_GetCamera (PyObject* module) {
74
if (renderer->c_camera == NULL) {
78
Py_INCREF ((PyObject*) renderer->c_camera);
79
return (PyObject*) renderer->c_camera;
82
static PyObject* PyP3_RendererAdd (PyObject* module, PyObject* args) {
85
parent = (P3_instance*) PySequence_Fast_GET_ITEM (args, 1);
86
i = PyInt_AS_LONG (PySequence_Fast_GET_ITEM (args, 2));
88
P3_renderer_add (PySequence_Fast_GET_ITEM (args, 0), parent);
90
P3_renderer_add_alpha (PySequence_Fast_GET_ITEM (args, 0), parent);
93
o = PySequence_Fast_GET_ITEM (args, 0);
94
P3_renderer_add (o, parent);
95
P3_renderer_add_alpha (o, parent);
101
static PyObject* PyP3_SetQuality (PyObject* module, PyObject* arg) {
102
P3_set_quality ((int) PyInt_AS_LONG (arg));
107
static PyObject* PyP3_SetShadow (PyObject* module, PyObject* arg) {
108
if (PyObject_IsTrue (arg)) engine_option |= P3_SHADOWS;
109
else engine_option &= ~P3_SHADOWS;
114
static PyObject* PyP3_ToggleWireFrame (PyObject* module) {
115
P3_toggle_wireframe_mode ();
120
static PyObject* PyP3_MinimizeWindow (PyObject* module) {
122
SDL_WM_IconifyWindow ();
128
static PyObject* PyP3_ToggleFullscreen (PyObject* module) {
130
SDL_WM_ToggleFullScreen (screen);
136
static PyObject* PyP3_SetCursorVisibility (PyObject* module, PyObject* arg) {
139
static Cursor blank_cursor = 0;
141
if (blank_cursor == 0) {
142
blank_cursor = XCreateFontCursor (display, 0);
146
if (PyObject_IsTrue (arg) == 1) {
147
XUndefineCursor (display, window);
149
XDefineCursor (display, window, blank_cursor);
153
if (PyObject_IsTrue (arg) == 1) {
154
SDL_ShowCursor (SDL_ENABLE);
156
SDL_ShowCursor (SDL_DISABLE);
163
static PyObject* PyP3_SetCursorPosition (PyObject* module, PyObject* args) {
165
XWarpPointer (display, window, window, 0, 0, 0, 0, PyInt_AS_LONG (PySequence_Fast_GET_ITEM (args, 0)), PyInt_AS_LONG (PySequence_Fast_GET_ITEM (args, 1)));
168
SDL_WarpMouse ((Uint16) PyInt_AS_LONG (PySequence_Fast_GET_ITEM (args, 0)), (Uint16) PyInt_AS_LONG (PySequence_Fast_GET_ITEM (args, 1)));
174
static PyObject* PyP3_Init (PyObject* module, PyObject* args) {
178
if (args != NULL && args != Py_None) {
179
if (PySequence_Size (args) == 5) {
180
o = PySequence_Fast_GET_ITEM (args, 0);
181
if (o == NULL || o == Py_None) {
184
str = PyString_AsString (o);
187
(int) PyInt_AsLong (PySequence_Fast_GET_ITEM (args, 1)),
188
(int) PyInt_AsLong (PySequence_Fast_GET_ITEM (args, 2)),
189
PyObject_IsTrue (PySequence_Fast_GET_ITEM (args, 3)),
190
PyObject_IsTrue (PySequence_Fast_GET_ITEM (args, 4)));
191
} else if (PySequence_Size (args) == 2) {
192
screen_w = (int) PyInt_AsLong (PySequence_Fast_GET_ITEM (args, 0));
193
screen_h = (int) PyInt_AsLong (PySequence_Fast_GET_ITEM (args, 1));
201
static PyObject* PyP3_SetVideo (PyObject* module, PyObject* args) {
202
P3_set_video ((int) PyInt_AsLong (PySequence_Fast_GET_ITEM (args, 0)),
203
(int) PyInt_AsLong (PySequence_Fast_GET_ITEM (args, 1)),
204
PyObject_IsTrue (PySequence_Fast_GET_ITEM (args, 2)),
205
PyObject_IsTrue (PySequence_Fast_GET_ITEM (args, 3)));
210
static PyObject* PyP3_Quit (PyObject* module) {
216
static PyObject* PyP3_Display (PyObject* module) {
217
if (engine_option & P3_GL_INITED) {
220
glXSwapBuffers (display, window);
223
SDL_GL_SwapBuffers ();
230
static PyObject* PyP3_Screenshot (PyObject* module, PyObject* arg) {
231
P3_screenshot (PyString_AS_STRING (arg));
241
static PyObject* PyP3_GetModifier (PyObject* module) {
249
unsigned int mask_return;
250
if (XQueryPointer (display, window, &root_return, &child_return, &root_x_return, &root_y_return, &win_x_return, &win_y_return, &mask_return) == True) {
251
return PyInt_FromLong (mask_return);
253
return PyInt_FromLong (0);
257
return PyInt_FromLong (SDL_GetModState ());
261
static PyObject* PyP3_ProcessEvent (PyObject* module) {
267
static int last_pointer_x;
268
static int last_pointer_y;
269
list = PyList_New (0);
270
while (XCheckWindowEvent (display, window, ResizeRedirectMask | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &event) == True) {
271
switch (event.type) {
274
tuple = PyTuple_New (3);
275
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (event.type));
276
PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong (event.xkey.keycode));
277
PyTuple_SET_ITEM (tuple, 2, PyInt_FromLong (event.xkey.state));
278
PyList_Append (list, tuple);
283
tuple = PyTuple_New (4);
284
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (event.type));
285
PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong (event.xbutton.button));
286
PyTuple_SET_ITEM (tuple, 2, PyInt_FromLong (event.xbutton.x));
287
PyTuple_SET_ITEM (tuple, 3, PyInt_FromLong (event.xbutton.y));
288
PyList_Append (list, tuple);
292
tuple = PyTuple_New (6);
293
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (MotionNotify));
294
PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong (event.xmotion.x));
295
PyTuple_SET_ITEM (tuple, 2, PyInt_FromLong (event.xmotion.y));
296
PyTuple_SET_ITEM (tuple, 3, PyInt_FromLong (last_pointer_x - event.xmotion.x));
297
PyTuple_SET_ITEM (tuple, 4, PyInt_FromLong (last_pointer_y - event.xmotion.y));
298
PyTuple_SET_ITEM (tuple, 5, PyInt_FromLong (event.xmotion.state));
299
PyList_Append (list, tuple);
301
last_pointer_x = event.xmotion.x;
302
last_pointer_y = event.xmotion.y;
306
tuple = PyTuple_New (1);
307
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (GraphicsExpose));
308
PyList_Append (list, tuple);
312
if (engine_option & P3_FULLSCREEN) {
313
P3_set_video (event.xresizerequest.width, event.xresizerequest.height, P3_TRUE, P3_TRUE);
315
P3_set_video (event.xresizerequest.width, event.xresizerequest.height, P3_FALSE, P3_TRUE);
317
tuple = PyTuple_New (3);
318
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (ResizeRequest));
319
PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong (event.xresizerequest.width));
320
PyTuple_SET_ITEM (tuple, 2, PyInt_FromLong (event.xresizerequest.height));
321
PyList_Append (list, tuple);
330
list = PyList_New (0);
331
while (SDL_PollEvent (&event)) {
332
switch (event.type) {
335
tuple = PyTuple_New (3);
336
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (event.type));
337
PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong (event.key.keysym.sym));
338
PyTuple_SET_ITEM (tuple, 2, PyInt_FromLong (event.key.keysym.mod));
339
PyList_Append (list, tuple);
342
case SDL_MOUSEMOTION:
343
tuple = PyTuple_New (6);
344
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (SDL_MOUSEMOTION));
345
PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong (event.motion.x));
346
PyTuple_SET_ITEM (tuple, 2, PyInt_FromLong (event.motion.y));
347
PyTuple_SET_ITEM (tuple, 3, PyInt_FromLong (event.motion.xrel));
348
PyTuple_SET_ITEM (tuple, 4, PyInt_FromLong (event.motion.yrel));
349
PyTuple_SET_ITEM (tuple, 5, PyInt_FromLong (event.motion.state));
350
PyList_Append (list, tuple);
353
case SDL_MOUSEBUTTONDOWN:
354
case SDL_MOUSEBUTTONUP:
355
tuple = PyTuple_New (4);
356
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (event.type));
357
PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong (event.button.button));
358
PyTuple_SET_ITEM (tuple, 2, PyInt_FromLong (event.button.x));
359
PyTuple_SET_ITEM (tuple, 3, PyInt_FromLong (event.button.y));
360
PyList_Append (list, tuple);
364
case SDL_VIDEOEXPOSE:
365
tuple = PyTuple_New (1);
366
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (event.type));
367
PyList_Append (list, tuple);
370
case SDL_VIDEORESIZE:
371
if (engine_option & P3_FULLSCREEN)
372
P3_set_video (event.resize.w, event.resize.h, P3_TRUE, P3_TRUE);
374
P3_set_video (event.resize.w, event.resize.h, P3_FALSE, P3_TRUE);
375
tuple = PyTuple_New (3);
376
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (SDL_VIDEORESIZE));
377
PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong (event.resize.w));
378
PyTuple_SET_ITEM (tuple, 2, PyInt_FromLong (event.resize.h));
379
PyList_Append (list, tuple);
382
case SDL_JOYAXISMOTION:
383
tuple = PyTuple_New (3);
384
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (event.type));
385
PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong (event.jaxis.axis));
386
PyTuple_SET_ITEM (tuple, 2, PyInt_FromLong (event.jaxis.value));
387
PyList_Append (list, tuple);
390
case SDL_JOYBUTTONDOWN:
391
tuple = PyTuple_New (2);
392
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (event.type));
393
PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong (event.jbutton.button));
394
PyList_Append (list, tuple);
397
case SDL_JOYBUTTONUP:
398
tuple = PyTuple_New (2);
399
PyTuple_SET_ITEM (tuple, 0, PyInt_FromLong (event.type));
400
PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong (event.jbutton.button));
401
PyList_Append (list, tuple);
404
case SDL_JOYBALLMOTION:
405
printf ("joy ball %i motion x %i y %i\n", event.jball.ball, event.jball.xrel, event.jball.yrel);
407
case SDL_JOYHATMOTION:
408
printf ("joy hat %i motion %i\n", event.jhat.hat, event.jhat.value);
417
static PyObject* PyP3_AdvanceTime (PyObject* module, PyObject* arg) {
418
delta_time += (float) PyFloat_AS_DOUBLE (arg);