~jtaylor/ubuntu/oneiric/soya/fix-780305

« back to all changes in this revision

Viewing changes to c_src/python/i_anim.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Dequènes (Duck)
  • Date: 2005-01-30 09:55:06 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050130095506-f21p6v6cgaobhn5j
Tags: 0.9.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * P3 python wrapper
3
 
 *
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.
8
 
 *
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.
13
 
 *
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
17
 
 */
18
 
 
19
 
/**********************************************
20
 
 * Copyright (C) 2002-2003 Bertrand 'blam' LAMY
21
 
 **********************************************/
22
 
 
23
 
/*====================*
24
 
 * COORDSYS ANIMATION *
25
 
 *====================*/
26
 
 
27
 
static int PyP3AnimCoordsys_Init (P3_anim_coordsys* self, PyObject* args, PyObject* kwds) {
28
 
  P3_anim_coordsys_new (self);
29
 
        return 0;
30
 
}
31
 
 
32
 
static void PyP3AnimCoordsys_Dealloc (P3_anim_coordsys* d) {
33
 
  free (d->states);
34
 
  d->ob_type->tp_free ((PyObject*) d);
35
 
}
36
 
 
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)));
39
 
  Py_INCREF (Py_None);
40
 
  return Py_None;
41
 
}
42
 
 
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));
48
 
  }
49
 
  Py_INCREF (Py_None);
50
 
  return Py_None;
51
 
}
52
 
 
53
 
static PyObject* PyP3AnimCoordsys_GetTimeFor (P3_anim_coordsys* d, PyObject* arg) {
54
 
  return PyFloat_FromDouble ((double) (d->states + PyInt_AS_LONG (arg))->time);
55
 
}
56
 
 
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));
59
 
  Py_INCREF (Py_None);
60
 
  return Py_None;
61
 
}
62
 
 
63
 
/*
64
 
static PyObject* PyP3AnimCoordsys_GetState (P3_anim_coordsys* a) {
65
 
  void* buffer;
66
 
  void* buf;
67
 
  int all_size;
68
 
//  int i;
69
 
  PyObject* o;
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);
74
 
  buf = buffer;
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);
85
 
//  }
86
 
  o = PyString_FromStringAndSize ((char*) buffer, all_size);
87
 
  free (buffer);
88
 
  return o;
89
 
}
90
 
 
91
 
static PyObject* PyP3AnimCoordsys_SetState (P3_anim_coordsys* a, PyObject* arg) {
92
 
  void* buf;
93
 
//  int i;
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);
106
 
//  }
107
 
  Py_INCREF (Py_None);
108
 
  return Py_None;
109
 
}
110
 
*/
111
 
 
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 },
119
 
  { NULL, NULL }
120
 
};
121
 
 
122
 
static PyObject* PyP3AnimCoordsys_GetNbStates (P3_anim_coordsys* d, void* context) {
123
 
  return PyInt_FromLong ((long) d->nb_states);
124
 
}
125
 
 
126
 
PY_GET_SET_ON_FLOAT (AnimCoordsys, P3_anim_coordsys*, CyclicLap, cyclic_lap)
127
 
 
128
 
static PyGetSetDef PyP3AnimCoordsys_GetSets[] = {
129
 
        { "cyclic_lap",    (getter) PyP3AnimCoordsys_GetCyclicLap, (setter) PyP3AnimCoordsys_SetCyclicLap, NULL },
130
 
        { "states_number", (getter) PyP3AnimCoordsys_GetNbStates,  (setter) 0,                             NULL },
131
 
  { NULL }
132
 
};
133
 
 
134
 
PyTypeObject PyP3AnimCoordsys_Type = {
135
 
  PyObject_HEAD_INIT(NULL)
136
 
  0,
137
 
  "_soya._AnimCoordsys",
138
 
  sizeof(P3_anim_coordsys),
139
 
  0,
140
 
  (destructor) PyP3AnimCoordsys_Dealloc,/* tp_dealloc */
141
 
  0,/* tp_print */
142
 
  0,/* tp_getattr */
143
 
  0,/* tp_setattr */
144
 
  0,/* tp_compare */
145
 
  0,/* tp_repr */
146
 
  0,/* tp_as_number */
147
 
  0,/* tp_as_sequence */
148
 
  0,/* tp_as_mapping */
149
 
  0,/* tp_hash */
150
 
  0,/* tp_call */
151
 
  0,/* tp_str */
152
 
  PYP3_GENERIC_GETATTR,/* tp_getattro */
153
 
  0,/* tp_setattro */
154
 
  0,/* tp_as_buffer */
155
 
  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,/* tp_flags */
156
 
  0,/* tp_doc */
157
 
  (traverseproc) 0,/* tp_traverse */
158
 
  (inquiry) 0,/* tp_clear */
159
 
  0,/* tp_richcompare */
160
 
  0,/* tp_weaklistoffset */
161
 
  0,/* tp_iter */
162
 
  0,/* tp_iternext */
163
 
  (PyMethodDef*) PyP3AnimCoordsys_Methods,/* tp_methods */
164
 
  0,/* tp_members */
165
 
  (PyGetSetDef*) PyP3AnimCoordsys_GetSets,/* tp_getset */
166
 
  0,/* tp_base */
167
 
  0,/* tp_dict */
168
 
  0,/* tp_descr_get */
169
 
  0,/* tp_descr_set */
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 */
175
 
};
176
 
 
177