84360a76e61b6c351fb81e54bcc7bc898e25721d
[blender.git] / source / blender / python / generic / euler.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Joseph Gilbert
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include "Mathutils.h"
30
31 #include "BLI_math.h"
32 #include "BKE_utildefines.h"
33 #include "BLI_blenlib.h"
34
35 #include "BLO_sys_types.h"
36
37 //----------------------------------Mathutils.Euler() -------------------
38 //makes a new euler for you to play with
39 static PyObject *Euler_new(PyTypeObject * type, PyObject * args, PyObject * kwargs)
40 {
41         PyObject *listObject = NULL;
42         int size, i;
43         float eul[3];
44         PyObject *e;
45         short order= 0;  // TODO, add order option
46
47         size = PyTuple_GET_SIZE(args);
48         if (size == 1) {
49                 listObject = PyTuple_GET_ITEM(args, 0);
50                 if (PySequence_Check(listObject)) {
51                         size = PySequence_Length(listObject);
52                 } else { // Single argument was not a sequence
53                         PyErr_SetString(PyExc_TypeError, "Mathutils.Euler(): 3d numeric sequence expected\n");
54                         return NULL;
55                 }
56         } else if (size == 0) {
57                 //returns a new empty 3d euler
58                 return newEulerObject(NULL, order, Py_NEW, NULL);
59         } else {
60                 listObject = args;
61         }
62
63         if (size != 3) { // Invalid euler size
64                 PyErr_SetString(PyExc_AttributeError, "Mathutils.Euler(): 3d numeric sequence expected\n");
65                 return NULL;
66         }
67
68         for (i=0; i<size; i++) {
69                 e = PySequence_GetItem(listObject, i);
70                 if (e == NULL) { // Failed to read sequence
71                         Py_DECREF(listObject);
72                         PyErr_SetString(PyExc_RuntimeError, "Mathutils.Euler(): 3d numeric sequence expected\n");
73                         return NULL;
74                 }
75
76                 eul[i]= (float)PyFloat_AsDouble(e);
77                 Py_DECREF(e);
78                 
79                 if(eul[i]==-1 && PyErr_Occurred()) { // parsed item is not a number
80                         PyErr_SetString(PyExc_TypeError, "Mathutils.Euler(): 3d numeric sequence expected\n");
81                         return NULL;
82                 }
83         }
84         return newEulerObject(eul, order, Py_NEW, NULL);
85 }
86
87 short euler_order_from_string(const char *str, const char *error_prefix)
88 {
89         if((str[0] && str[1] && str[2] && str[3]=='\0')) {
90                 switch(*((int32_t *)str)) {
91                         case 'X'|'Y'<<8|'Z'<<16:        return 0;
92                         case 'X'|'Z'<<8|'Y'<<16:        return 1;
93                         case 'Y'|'X'<<8|'Z'<<16:        return 2;
94                         case 'Y'|'Z'<<8|'X'<<16:        return 3;
95                         case 'Z'|'X'<<8|'Y'<<16:        return 4;
96                         case 'Z'|'Y'<<8|'X'<<16:        return 5;
97                 }
98         }
99
100         PyErr_Format(PyExc_TypeError, "%s: invalid euler order '%s'", error_prefix, str);
101         return -1;
102 }
103
104 //-----------------------------METHODS----------------------------
105 //----------------------------Euler.toQuat()----------------------
106 //return a quaternion representation of the euler
107
108 static char Euler_ToQuat_doc[] =
109 ".. method:: to_quat()\n"
110 "\n"
111 "   Return a quaternion representation of the euler.\n"
112 "\n"
113 "   :return: Quaternion representation of the euler.\n"
114 "   :rtype: :class:`Quaternion`\n";
115
116 static PyObject *Euler_ToQuat(EulerObject * self)
117 {
118         float quat[4];
119
120         if(!BaseMath_ReadCallback(self))
121                 return NULL;
122
123         if(self->order==0)      eul_to_quat(quat, self->eul);
124         else                            eulO_to_quat(quat, self->eul, self->order);
125
126         return newQuaternionObject(quat, Py_NEW, NULL);
127 }
128 //----------------------------Euler.toMatrix()---------------------
129 //return a matrix representation of the euler
130 static char Euler_ToMatrix_doc[] =
131 ".. method:: to_matrix()\n"
132 "\n"
133 "   Return a matrix representation of the euler.\n"
134 "\n"
135 "   :return: A 3x3 roation matrix representation of the euler.\n"
136 "   :rtype: :class:`Matrix`\n";
137
138 static PyObject *Euler_ToMatrix(EulerObject * self)
139 {
140         float mat[9] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
141
142         if(!BaseMath_ReadCallback(self))
143                 return NULL;
144
145         if(self->order==0)      eul_to_mat3((float (*)[3])mat, self->eul);
146         else                            eulO_to_mat3((float (*)[3])mat, self->eul, self->order);
147
148         return newMatrixObject(mat, 3, 3 , Py_NEW, NULL);
149 }
150 //----------------------------Euler.unique()-----------------------
151 //sets the x,y,z values to a unique euler rotation
152 // TODO, check if this works with rotation order!!!
153 static char Euler_Unique_doc[] =
154 ".. method:: unique()\n"
155 "\n"
156 "   Calculate a unique rotation for this euler. Avoids gimble lock.\n"
157 "\n"
158 "   :return: an instance of itself\n"
159 "   :rtype: :class:`Euler`\n";
160
161 static PyObject *Euler_Unique(EulerObject * self)
162 {
163 #define PI_2            (Py_PI * 2.0)
164 #define PI_HALF         (Py_PI / 2.0)
165 #define PI_INV          (1.0 / Py_PI)
166
167         double heading, pitch, bank;
168
169         if(!BaseMath_ReadCallback(self))
170                 return NULL;
171
172         heading = self->eul[0];
173         pitch = self->eul[1];
174         bank = self->eul[2];
175
176         //wrap heading in +180 / -180
177         pitch += Py_PI;
178         pitch -= floor(pitch * PI_INV) * PI_2;
179         pitch -= Py_PI;
180
181
182         if(pitch < -PI_HALF) {
183                 pitch = -Py_PI - pitch;
184                 heading += Py_PI;
185                 bank += Py_PI;
186         } else if(pitch > PI_HALF) {
187                 pitch = Py_PI - pitch;
188                 heading += Py_PI;
189                 bank += Py_PI;
190         }
191         //gimbal lock test
192         if(fabs(pitch) > PI_HALF - 1e-4) {
193                 heading += bank;
194                 bank = 0.0f;
195         } else {
196                 bank += Py_PI;
197                 bank -= (floor(bank * PI_INV)) * PI_2;
198                 bank -= Py_PI;
199         }
200
201         heading += Py_PI;
202         heading -= (floor(heading * PI_INV)) * PI_2;
203         heading -= Py_PI;
204
205         BaseMath_WriteCallback(self);
206         Py_INCREF(self);
207         return (PyObject *)self;
208 }
209 //----------------------------Euler.zero()-------------------------
210 //sets the euler to 0,0,0
211 static char Euler_Zero_doc[] =
212 ".. method:: zero()\n"
213 "\n"
214 "   Set all values to zero.\n"
215 "\n"
216 "   :return: an instance of itself\n"
217 "   :rtype: :class:`Euler`\n";
218
219 static PyObject *Euler_Zero(EulerObject * self)
220 {
221         self->eul[0] = 0.0;
222         self->eul[1] = 0.0;
223         self->eul[2] = 0.0;
224
225         BaseMath_WriteCallback(self);
226         Py_INCREF(self);
227         return (PyObject *)self;
228 }
229 //----------------------------Euler.rotate()-----------------------
230 //rotates a euler a certain amount and returns the result
231 //should return a unique euler rotation (i.e. no 720 degree pitches :)
232 static PyObject *Euler_Rotate(EulerObject * self, PyObject *args)
233 {
234         float angle = 0.0f;
235         char *axis;
236
237         if(!PyArg_ParseTuple(args, "fs", &angle, &axis)){
238                 PyErr_SetString(PyExc_TypeError, "euler.rotate():expected angle (float) and axis (x,y,z)");
239                 return NULL;
240         }
241         if(ELEM3(*axis, 'x', 'y', 'z') && axis[1]=='\0'){
242                 PyErr_SetString(PyExc_TypeError, "euler.rotate(): expected axis to be 'x', 'y' or 'z'");
243                 return NULL;
244         }
245
246         if(!BaseMath_ReadCallback(self))
247                 return NULL;
248
249         if(self->order == 0)    rotate_eul(self->eul, *axis, angle);
250         else                                    rotate_eulO(self->eul, self->order, *axis, angle);
251
252         BaseMath_WriteCallback(self);
253         Py_INCREF(self);
254         return (PyObject *)self;
255 }
256
257 static char Euler_MakeCompatible_doc[] =
258 ".. method:: make_compatible(other)\n"
259 "\n"
260 "   Make this euler compatible with another, so interpolating between them works as intended.\n"
261 "\n"
262 "   :arg other: make compatible with this rotation.\n"
263 "   :type other: :class:`Euler`\n"
264 "   :return: an instance of itself.\n"
265 "   :rtype: :class:`Euler`\n"
266 "\n"
267 "   .. note:: the order of eulers must match or an exception is raised.\n";
268
269 static PyObject *Euler_MakeCompatible(EulerObject * self, EulerObject *value)
270 {
271         if(!EulerObject_Check(value)) {
272                 PyErr_SetString(PyExc_TypeError, "euler.make_compatible(euler): expected a single euler argument.");
273                 return NULL;
274         }
275         
276         if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(value))
277                 return NULL;
278
279         if(self->order != value->order) {
280                 PyErr_SetString(PyExc_ValueError, "euler.make_compatible(euler): rotation orders don't match\n");
281                 return NULL;
282         }
283
284         compatible_eul(self->eul, value->eul);
285
286         BaseMath_WriteCallback(self);
287         Py_INCREF(self);
288         return (PyObject *)self;
289 }
290
291 //----------------------------Euler.rotate()-----------------------
292 // return a copy of the euler
293
294 static char Euler_copy_doc[] =
295 ".. function:: copy()\n"
296 "\n"
297 "   Returns a copy of this euler.\n"
298 "\n"
299 "   :return: A copy of the euler.\n"
300 "   :rtype: :class:`Euler`\n"
301 "\n"
302 "   .. note:: use this to get a copy of a wrapped euler with no reference to the original data.\n";
303
304 static PyObject *Euler_copy(EulerObject * self, PyObject *args)
305 {
306         if(!BaseMath_ReadCallback(self))
307                 return NULL;
308
309         return newEulerObject(self->eul, self->order, Py_NEW, Py_TYPE(self));
310 }
311
312 //----------------------------print object (internal)--------------
313 //print the object to screen
314 static PyObject *Euler_repr(EulerObject * self)
315 {
316         char str[64];
317
318         if(!BaseMath_ReadCallback(self))
319                 return NULL;
320
321         sprintf(str, "[%.6f, %.6f, %.6f](euler)", self->eul[0], self->eul[1], self->eul[2]);
322         return PyUnicode_FromString(str);
323 }
324 //------------------------tp_richcmpr
325 //returns -1 execption, 0 false, 1 true
326 static PyObject* Euler_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type)
327 {
328         EulerObject *eulA = NULL, *eulB = NULL;
329         int result = 0;
330
331         if(EulerObject_Check(objectA)) {
332                 eulA = (EulerObject*)objectA;
333                 if(!BaseMath_ReadCallback(eulA))
334                         return NULL;
335         }
336         if(EulerObject_Check(objectB)) {
337                 eulB = (EulerObject*)objectB;
338                 if(!BaseMath_ReadCallback(eulB))
339                         return NULL;
340         }
341
342         if (!eulA || !eulB){
343                 if (comparison_type == Py_NE){
344                         Py_RETURN_TRUE;
345                 }else{
346                         Py_RETURN_FALSE;
347                 }
348         }
349         eulA = (EulerObject*)objectA;
350         eulB = (EulerObject*)objectB;
351
352         switch (comparison_type){
353                 case Py_EQ:
354                         result = EXPP_VectorsAreEqual(eulA->eul, eulB->eul, 3, 1);
355                         break;
356                 case Py_NE:
357                         result = !EXPP_VectorsAreEqual(eulA->eul, eulB->eul, 3, 1);
358                         break;
359                 default:
360                         printf("The result of the comparison could not be evaluated");
361                         break;
362         }
363         if (result == 1){
364                 Py_RETURN_TRUE;
365         }else{
366                 Py_RETURN_FALSE;
367         }
368 }
369
370 //---------------------SEQUENCE PROTOCOLS------------------------
371 //----------------------------len(object)------------------------
372 //sequence length
373 static int Euler_len(EulerObject * self)
374 {
375         return 3;
376 }
377 //----------------------------object[]---------------------------
378 //sequence accessor (get)
379 static PyObject *Euler_item(EulerObject * self, int i)
380 {
381         if(i<0) i= 3-i;
382         
383         if(i < 0 || i >= 3) {
384                 PyErr_SetString(PyExc_IndexError, "euler[attribute]: array index out of range");
385                 return NULL;
386         }
387
388         if(!BaseMath_ReadIndexCallback(self, i))
389                 return NULL;
390
391         return PyFloat_FromDouble(self->eul[i]);
392
393 }
394 //----------------------------object[]-------------------------
395 //sequence accessor (set)
396 static int Euler_ass_item(EulerObject * self, int i, PyObject * value)
397 {
398         float f = PyFloat_AsDouble(value);
399
400         if(f == -1 && PyErr_Occurred()) { // parsed item not a number
401                 PyErr_SetString(PyExc_TypeError, "euler[attribute] = x: argument not a number");
402                 return -1;
403         }
404
405         if(i<0) i= 3-i;
406         
407         if(i < 0 || i >= 3){
408                 PyErr_SetString(PyExc_IndexError, "euler[attribute] = x: array assignment index out of range\n");
409                 return -1;
410         }
411         
412         self->eul[i] = f;
413
414         if(!BaseMath_WriteIndexCallback(self, i))
415                 return -1;
416
417         return 0;
418 }
419 //----------------------------object[z:y]------------------------
420 //sequence slice (get)
421 static PyObject *Euler_slice(EulerObject * self, int begin, int end)
422 {
423         PyObject *list = NULL;
424         int count;
425
426         if(!BaseMath_ReadCallback(self))
427                 return NULL;
428
429         CLAMP(begin, 0, 3);
430         if (end<0) end= 4+end;
431         CLAMP(end, 0, 3);
432         begin = MIN2(begin,end);
433
434         list = PyList_New(end - begin);
435         for(count = begin; count < end; count++) {
436                 PyList_SetItem(list, count - begin,
437                                 PyFloat_FromDouble(self->eul[count]));
438         }
439
440         return list;
441 }
442 //----------------------------object[z:y]------------------------
443 //sequence slice (set)
444 static int Euler_ass_slice(EulerObject * self, int begin, int end,
445                              PyObject * seq)
446 {
447         int i, y, size = 0;
448         float eul[3];
449         PyObject *e;
450
451         if(!BaseMath_ReadCallback(self))
452                 return -1;
453
454         CLAMP(begin, 0, 3);
455         if (end<0) end= 4+end;
456         CLAMP(end, 0, 3);
457         begin = MIN2(begin,end);
458
459         size = PySequence_Length(seq);
460         if(size != (end - begin)){
461                 PyErr_SetString(PyExc_TypeError, "euler[begin:end] = []: size mismatch in slice assignment");
462                 return -1;
463         }
464
465         for (i = 0; i < size; i++) {
466                 e = PySequence_GetItem(seq, i);
467                 if (e == NULL) { // Failed to read sequence
468                         PyErr_SetString(PyExc_RuntimeError, "euler[begin:end] = []: unable to read sequence");
469                         return -1;
470                 }
471
472                 eul[i] = (float)PyFloat_AsDouble(e);
473                 Py_DECREF(e);
474
475                 if(eul[i]==-1 && PyErr_Occurred()) { // parsed item not a number
476                         PyErr_SetString(PyExc_TypeError, "euler[begin:end] = []: sequence argument not a number");
477                         return -1;
478                 }
479         }
480         //parsed well - now set in vector
481         for(y = 0; y < 3; y++){
482                 self->eul[begin + y] = eul[y];
483         }
484
485         BaseMath_WriteCallback(self);
486         return 0;
487 }
488 //-----------------PROTCOL DECLARATIONS--------------------------
489 static PySequenceMethods Euler_SeqMethods = {
490         (lenfunc) Euler_len,                                            /* sq_length */
491         (binaryfunc) 0,                                                         /* sq_concat */
492         (ssizeargfunc) 0,                                                               /* sq_repeat */
493         (ssizeargfunc) Euler_item,                                      /* sq_item */
494         (ssizessizeargfunc) Euler_slice,                                /* sq_slice */
495         (ssizeobjargproc) Euler_ass_item,                               /* sq_ass_item */
496         (ssizessizeobjargproc) Euler_ass_slice,                 /* sq_ass_slice */
497 };
498
499
500 /*
501  * vector axis, vector.x/y/z/w
502  */
503 static PyObject *Euler_getAxis( EulerObject * self, void *type )
504 {
505         return Euler_item(self, GET_INT_FROM_POINTER(type));
506 }
507
508 static int Euler_setAxis( EulerObject * self, PyObject * value, void * type )
509 {
510         return Euler_ass_item(self, GET_INT_FROM_POINTER(type), value);
511 }
512
513 /* rotation order */
514 static PyObject *Euler_getOrder(EulerObject *self, void *type)
515 {
516         static char order[][4] = {"XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"};
517         return PyUnicode_FromString(order[self->order]);
518 }
519
520 static int Euler_setOrder( EulerObject * self, PyObject * value, void * type )
521 {
522         char *order_str= _PyUnicode_AsString(value);
523         short order= euler_order_from_string(order_str, "euler.order");
524
525         if(order < 0)
526                 return -1;
527
528         if(self->cb_user) {
529                 PyErr_SetString(PyExc_TypeError, "euler.order: assignment is not allowed on eulers with an owner");
530                 return -1;
531         }
532
533         self->order= order;
534         return 0;
535 }
536
537 /*****************************************************************************/
538 /* Python attributes get/set structure:                                      */
539 /*****************************************************************************/
540 static PyGetSetDef Euler_getseters[] = {
541         {"x", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler X axis in radians. **type** float", (void *)0},
542         {"y", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler Y axis in radians. **type** float", (void *)1},
543         {"z", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler Z axis in radians. **type** float", (void *)2},
544         {"order", (getter)Euler_getOrder, (setter)Euler_setOrder, "Euler rotation order. **type** string in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']", (void *)NULL},
545
546         {"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, NULL},
547         {"_owner", (getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
548         {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
549 };
550
551
552 //-----------------------METHOD DEFINITIONS ----------------------
553 static struct PyMethodDef Euler_methods[] = {
554         {"zero", (PyCFunction) Euler_Zero, METH_NOARGS, Euler_Zero_doc},
555         {"unique", (PyCFunction) Euler_Unique, METH_NOARGS, Euler_Unique_doc},
556         {"to_matrix", (PyCFunction) Euler_ToMatrix, METH_NOARGS, Euler_ToMatrix_doc},
557         {"to_quat", (PyCFunction) Euler_ToQuat, METH_NOARGS, Euler_ToQuat_doc},
558         {"rotate", (PyCFunction) Euler_Rotate, METH_VARARGS, NULL},
559         {"make_compatible", (PyCFunction) Euler_MakeCompatible, METH_O, Euler_MakeCompatible_doc},
560         {"__copy__", (PyCFunction) Euler_copy, METH_VARARGS, Euler_copy_doc},
561         {"copy", (PyCFunction) Euler_copy, METH_VARARGS, Euler_copy_doc},
562         {NULL, NULL, 0, NULL}
563 };
564
565 //------------------PY_OBECT DEFINITION--------------------------
566 static char euler_doc[] =
567 "This object gives access to Eulers in Blender.";
568
569 PyTypeObject euler_Type = {
570         PyVarObject_HEAD_INIT(NULL, 0)
571         "euler",                                                //tp_name
572         sizeof(EulerObject),                    //tp_basicsize
573         0,                                                              //tp_itemsize
574         (destructor)BaseMathObject_dealloc,             //tp_dealloc
575         0,                                                              //tp_print
576         0,                                                              //tp_getattr
577         0,                                                              //tp_setattr
578         0,                                                              //tp_compare
579         (reprfunc) Euler_repr,                  //tp_repr
580         0,                              //tp_as_number
581         &Euler_SeqMethods,                              //tp_as_sequence
582         0,                                                              //tp_as_mapping
583         0,                                                              //tp_hash
584         0,                                                              //tp_call
585         0,                                                              //tp_str
586         0,                                                              //tp_getattro
587         0,                                                              //tp_setattro
588         0,                                                              //tp_as_buffer
589         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, //tp_flags
590         euler_doc, //tp_doc
591         0,                                                              //tp_traverse
592         0,                                                              //tp_clear
593         (richcmpfunc)Euler_richcmpr,    //tp_richcompare
594         0,                                                              //tp_weaklistoffset
595         0,                                                              //tp_iter
596         0,                                                              //tp_iternext
597         Euler_methods,                                  //tp_methods
598         0,                                                              //tp_members
599         Euler_getseters,                                //tp_getset
600         0,                                                              //tp_base
601         0,                                                              //tp_dict
602         0,                                                              //tp_descr_get
603         0,                                                              //tp_descr_set
604         0,                                                              //tp_dictoffset
605         0,                                                              //tp_init
606         0,                                                              //tp_alloc
607         Euler_new,                                              //tp_new
608         0,                                                              //tp_free
609         0,                                                              //tp_is_gc
610         0,                                                              //tp_bases
611         0,                                                              //tp_mro
612         0,                                                              //tp_cache
613         0,                                                              //tp_subclasses
614         0,                                                              //tp_weaklist
615         0                                                               //tp_del
616 };
617 //------------------------newEulerObject (internal)-------------
618 //creates a new euler object
619 /*pass Py_WRAP - if vector is a WRAPPER for data allocated by BLENDER
620  (i.e. it was allocated elsewhere by MEM_mallocN())
621   pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
622  (i.e. it must be created here with PyMEM_malloc())*/
623 PyObject *newEulerObject(float *eul, short order, int type, PyTypeObject *base_type)
624 {
625         EulerObject *self;
626         int x;
627
628         if(base_type)   self = (EulerObject *)base_type->tp_alloc(base_type, 0);
629         else                    self = PyObject_NEW(EulerObject, &euler_Type);
630
631         /* init callbacks as NULL */
632         self->cb_user= NULL;
633         self->cb_type= self->cb_subtype= 0;
634
635         if(type == Py_WRAP){
636                 self->eul = eul;
637                 self->wrapped = Py_WRAP;
638         }else if (type == Py_NEW){
639                 self->eul = PyMem_Malloc(3 * sizeof(float));
640                 if(!eul) { //new empty
641                         for(x = 0; x < 3; x++) {
642                                 self->eul[x] = 0.0f;
643                         }
644                 }else{
645                         VECCOPY(self->eul, eul);
646                 }
647                 self->wrapped = Py_NEW;
648         }else{ //bad type
649                 return NULL;
650         }
651
652         self->order= order;
653         return (PyObject *)self;
654 }
655
656 PyObject *newEulerObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype)
657 {
658         EulerObject *self= (EulerObject *)newEulerObject(NULL, order, Py_NEW, NULL);
659         if(self) {
660                 Py_INCREF(cb_user);
661                 self->cb_user=                  cb_user;
662                 self->cb_type=                  (unsigned char)cb_type;
663                 self->cb_subtype=               (unsigned char)cb_subtype;
664         }
665
666         return (PyObject *)self;
667 }