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-2003 Bertrand 'blam' LAMY
21
**********************************************/
23
/*====================*
24
* COORDSYS ANIMATION *
25
*====================*/
27
static int PyP3AnimCoordsys_Init (P3_anim_coordsys* self, PyObject* args, PyObject* kwds) {
28
P3_anim_coordsys_new (self);
32
static void PyP3AnimCoordsys_Dealloc (P3_anim_coordsys* d) {
34
d->ob_type->tp_free ((PyObject*) d);
37
static PyObject* PyP3AnimCoordsys_AddState (P3_anim_coordsys* a, PyObject* args) {
38
P3_anim_coordsys_add_state (a, (P3_coordsys*) PySequence_Fast_GET_ITEM (args, 0), PyFloat_AS_DOUBLE (PySequence_Fast_GET_ITEM (args, 1)));
43
static PyObject* PyP3AnimCoordsys_RemoveState (P3_anim_coordsys* a, PyObject* arg) {
44
if (PyFloat_Check (arg)) {
45
P3_anim_coordsys_remove_state (a, (float) PyFloat_AS_DOUBLE (arg));
46
} else if (PyInt_Check (arg)) {
47
P3_anim_coordsys_delete_state (a, (int) PyInt_AS_LONG (arg));
53
static PyObject* PyP3AnimCoordsys_GetTimeFor (P3_anim_coordsys* d, PyObject* arg) {
54
return PyFloat_FromDouble ((double) (d->states + PyInt_AS_LONG (arg))->time);
57
static PyObject* PyP3AnimCoordsys_SetTimeFor (P3_anim_coordsys* d, PyObject* args) {
58
(d->states + PyInt_AS_LONG (PySequence_Fast_GET_ITEM (args, 0)))->time = (float) PyFloat_AS_DOUBLE (PySequence_Fast_GET_ITEM (args, 1));
64
static PyObject* PyP3AnimCoordsys_GetState (P3_anim_coordsys* a) {
70
// P3_state_coordsys* state;
71
all_size = (3 + a->nb_states) * sizeof (float) + (19 + 4) * a->nb_states * sizeof (GLfloat) + sizeof (int);
72
buffer = (void*) malloc (all_size);
73
all_size /= (double) sizeof (char);
75
PUT_IN_BUFFER (buf, a->nb_states, int);
76
PUT_IN_BUFFER (buf, a->cyclic_lap, float);
77
PUT_IN_BUFFER (buf, a->time_min, float);
78
PUT_IN_BUFFER (buf, a->time_max, float);
79
PUT_ARRAY_IN_BUFFER (buf, a->states, a->nb_states, P3_state_coordsys);
80
// for (i = 0; i < a->nb_states; i++) {
81
// state = a->states + i;
82
// PUT_IN_BUFFER (buf, state->time, float);
83
// PUT_ARRAY_IN_BUFFER (buf, state->quaternion, 4, GLfloat);
84
// PUT_ARRAY_IN_BUFFER (buf, state->m, 19, GLfloat);
86
o = PyString_FromStringAndSize ((char*) buffer, all_size);
91
static PyObject* PyP3AnimCoordsys_SetState (P3_anim_coordsys* a, PyObject* arg) {
94
buf = (void*) PyString_AS_STRING (arg);
95
GET_FROM_BUFFER (buf, a->nb_states, int);
96
GET_FROM_BUFFER (buf, a->cyclic_lap, float);
97
GET_FROM_BUFFER (buf, a->time_min, float);
98
GET_FROM_BUFFER (buf, a->time_max, float);
99
GET_MALLOC_ARRAY_FROM_BUFFER (buf, a->states, a->nb_states, P3_state_coordsys);
100
// a->states = (P3_state_coordsys*) malloc (a->nb_states * sizeof (P3_coordsys_state));
101
// for (i = 0; i < a->nb_states; i++) {
102
// state = a->states + i;
103
// GET_FROM_BUFFER (buf, state->time, float);
104
// GET_ARRAY_FROM_BUFFER (buf, state->quaternion, 4, GLfloat);
105
// GET_ARRAY_FROM_BUFFER (buf, state->m, 19, GLfloat);
112
static PyMethodDef PyP3AnimCoordsys_Methods[] = {
113
{ "add", (PyCFunction) PyP3AnimCoordsys_AddState, METH_VARARGS },
114
{ "remove", (PyCFunction) PyP3AnimCoordsys_RemoveState, METH_O },
115
{ "get_time_for", (PyCFunction) PyP3AnimCoordsys_GetTimeFor, METH_O },
116
{ "set_time_for", (PyCFunction) PyP3AnimCoordsys_SetTimeFor, METH_VARARGS },
117
// { "_getstate", (PyCFunction) PyP3AnimCoordsys_GetState, METH_NOARGS },
118
// { "_setstate", (PyCFunction) PyP3AnimCoordsys_SetState, METH_O },
122
static PyObject* PyP3AnimCoordsys_GetNbStates (P3_anim_coordsys* d, void* context) {
123
return PyInt_FromLong ((long) d->nb_states);
126
PY_GET_SET_ON_FLOAT (AnimCoordsys, P3_anim_coordsys*, CyclicLap, cyclic_lap)
128
static PyGetSetDef PyP3AnimCoordsys_GetSets[] = {
129
{ "cyclic_lap", (getter) PyP3AnimCoordsys_GetCyclicLap, (setter) PyP3AnimCoordsys_SetCyclicLap, NULL },
130
{ "states_number", (getter) PyP3AnimCoordsys_GetNbStates, (setter) 0, NULL },
134
PyTypeObject PyP3AnimCoordsys_Type = {
135
PyObject_HEAD_INIT(NULL)
137
"_soya._AnimCoordsys",
138
sizeof(P3_anim_coordsys),
140
(destructor) PyP3AnimCoordsys_Dealloc,/* tp_dealloc */
147
0,/* tp_as_sequence */
148
0,/* tp_as_mapping */
152
PYP3_GENERIC_GETATTR,/* tp_getattro */
155
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
157
(traverseproc) 0,/* tp_traverse */
158
(inquiry) 0,/* tp_clear */
159
0,/* tp_richcompare */
160
0,/* tp_weaklistoffset */
163
(PyMethodDef*) PyP3AnimCoordsys_Methods,/* tp_methods */
165
(PyGetSetDef*) PyP3AnimCoordsys_GetSets,/* tp_getset */
170
0,/* tp_dictoffset */
171
(initproc) PyP3AnimCoordsys_Init,/* tp_init */
172
PYP3_GENERIC_ALLOC,/* tp_alloc */
173
(newfunc) PyP3Object_New,/* tp_new */
174
PYP3_GENERIC_FREE,/* tp_free */