Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Swaney <sswaney@centurytel.net>2004-09-26 00:30:40 +0400
committerStephen Swaney <sswaney@centurytel.net>2004-09-26 00:30:40 +0400
commita509b8adc9b8952cdb395c69406e821f57a9a6c7 (patch)
tree7c0e3c7b81007acc6b3e268e59a6af5fcb4bd93f /source/blender/python/api2_2x/euler.c
parentbd371ddb9ff947d4e598ad04af9402d89fa80d5e (diff)
Another round in the Great BPy Cleanup:
Run everything thru indent to cleanup spaces vs tabs. Clean up some of the comments by hand. BGL.c was not touched due to all that macro wackyness. There are no functional changes to the code. Pre-indent versions of source are tagged with tag bpy-cleanup-20040925 , just in case.
Diffstat (limited to 'source/blender/python/api2_2x/euler.c')
-rw-r--r--source/blender/python/api2_2x/euler.c364
1 files changed, 187 insertions, 177 deletions
diff --git a/source/blender/python/api2_2x/euler.c b/source/blender/python/api2_2x/euler.c
index 09e6b01bffc..d55b5814270 100644
--- a/source/blender/python/api2_2x/euler.c
+++ b/source/blender/python/api2_2x/euler.c
@@ -32,25 +32,24 @@
#include "euler.h"
//doc strings
-char Euler_Zero_doc[] =
-"() - set all values in the euler to 0";
+char Euler_Zero_doc[] = "() - set all values in the euler to 0";
char Euler_Unique_doc[] =
-"() - sets the euler rotation a unique shortest arc rotation - tests for gimbal lock";
+ "() - sets the euler rotation a unique shortest arc rotation - tests for gimbal lock";
char Euler_ToMatrix_doc[] =
-"() - returns a rotation matrix representing the euler rotation";
+ "() - returns a rotation matrix representing the euler rotation";
char Euler_ToQuat_doc[] =
-"() - returns a quaternion representing the euler rotation";
+ "() - returns a quaternion representing the euler rotation";
//methods table
struct PyMethodDef Euler_methods[] = {
- {"zero",(PyCFunction)Euler_Zero, METH_NOARGS,
- Euler_Zero_doc},
- {"unique",(PyCFunction)Euler_Unique, METH_NOARGS,
- Euler_Unique_doc},
- {"toMatrix",(PyCFunction)Euler_ToMatrix, METH_NOARGS,
- Euler_ToMatrix_doc},
- {"toQuat",(PyCFunction)Euler_ToQuat, METH_NOARGS,
- Euler_ToQuat_doc},
+ {"zero", ( PyCFunction ) Euler_Zero, METH_NOARGS,
+ Euler_Zero_doc},
+ {"unique", ( PyCFunction ) Euler_Unique, METH_NOARGS,
+ Euler_Unique_doc},
+ {"toMatrix", ( PyCFunction ) Euler_ToMatrix, METH_NOARGS,
+ Euler_ToMatrix_doc},
+ {"toQuat", ( PyCFunction ) Euler_ToQuat, METH_NOARGS,
+ Euler_ToQuat_doc},
{NULL, NULL, 0, NULL}
};
@@ -59,274 +58,285 @@ struct PyMethodDef Euler_methods[] = {
/*****************************/
//euler methods
-PyObject *Euler_ToQuat(EulerObject *self)
+PyObject *Euler_ToQuat( EulerObject * self )
{
float *quat;
int x;
- for(x = 0; x < 3; x++){
- self->eul[x] *= (float)(Py_PI/180);
+ for( x = 0; x < 3; x++ ) {
+ self->eul[x] *= ( float ) ( Py_PI / 180 );
}
- quat = PyMem_Malloc(4*sizeof(float));
- EulToQuat(self->eul, quat);
- for(x = 0; x < 3; x++){
- self->eul[x] *= (float)(180/Py_PI);
+ quat = PyMem_Malloc( 4 * sizeof( float ) );
+ EulToQuat( self->eul, quat );
+ for( x = 0; x < 3; x++ ) {
+ self->eul[x] *= ( float ) ( 180 / Py_PI );
}
- return (PyObject*)newQuaternionObject(quat);
+ return ( PyObject * ) newQuaternionObject( quat );
}
-PyObject *Euler_ToMatrix(EulerObject *self)
+PyObject *Euler_ToMatrix( EulerObject * self )
{
float *mat;
int x;
- for(x = 0; x < 3; x++){
- self->eul[x] *= (float)(Py_PI/180);
+ for( x = 0; x < 3; x++ ) {
+ self->eul[x] *= ( float ) ( Py_PI / 180 );
}
- mat = PyMem_Malloc(3*3*sizeof(float));
- EulToMat3(self->eul, (float(*)[3])mat);
- for(x = 0; x < 3; x++){
- self->eul[x] *= (float)(180/Py_PI);
+ mat = PyMem_Malloc( 3 * 3 * sizeof( float ) );
+ EulToMat3( self->eul, ( float ( * )[3] ) mat );
+ for( x = 0; x < 3; x++ ) {
+ self->eul[x] *= ( float ) ( 180 / Py_PI );
}
- return (PyObject*)newMatrixObject(mat,3,3);
+ return ( PyObject * ) newMatrixObject( mat, 3, 3 );
}
-PyObject *Euler_Unique(EulerObject *self)
+PyObject *Euler_Unique( EulerObject * self )
{
float heading, pitch, bank;
- float pi2 = (float)Py_PI * 2.0f;
- float piO2 = (float)Py_PI / 2.0f;
+ float pi2 = ( float ) Py_PI * 2.0f;
+ float piO2 = ( float ) Py_PI / 2.0f;
float Opi2 = 1.0f / pi2;
//radians
- heading = self->eul[0] * (float)(Py_PI/180);
- pitch = self->eul[1] * (float)(Py_PI/180);
- bank = self->eul[2] * (float)(Py_PI/180);
-
+ heading = self->eul[0] * ( float ) ( Py_PI / 180 );
+ pitch = self->eul[1] * ( float ) ( Py_PI / 180 );
+ bank = self->eul[2] * ( float ) ( Py_PI / 180 );
+
//wrap heading in +180 / -180
- pitch += (float)Py_PI;
- pitch -= (float)floor(pitch * Opi2) * pi2;
- pitch -= (float)Py_PI;
-
-
- if(pitch < -piO2){
- pitch = (float)-Py_PI - pitch;
- heading += (float)Py_PI;
- bank += (float)Py_PI;
- }else if (pitch > piO2){
- pitch = (float)Py_PI - pitch;
- heading += (float)Py_PI;
- bank += (float)Py_PI;
+ pitch += ( float ) Py_PI;
+ pitch -= ( float ) floor( pitch * Opi2 ) * pi2;
+ pitch -= ( float ) Py_PI;
+
+
+ if( pitch < -piO2 ) {
+ pitch = ( float ) -Py_PI - pitch;
+ heading += ( float ) Py_PI;
+ bank += ( float ) Py_PI;
+ } else if( pitch > piO2 ) {
+ pitch = ( float ) Py_PI - pitch;
+ heading += ( float ) Py_PI;
+ bank += ( float ) Py_PI;
}
-
//gimbal lock test
- if(fabs(pitch) > piO2 - 1e-4){
+ if( fabs( pitch ) > piO2 - 1e-4 ) {
heading += bank;
bank = 0.0f;
- }else{
- bank += (float)Py_PI;
- bank -= (float)(floor(bank * Opi2)) * pi2;
- bank -= (float)Py_PI;
+ } else {
+ bank += ( float ) Py_PI;
+ bank -= ( float ) ( floor( bank * Opi2 ) ) * pi2;
+ bank -= ( float ) Py_PI;
}
- heading += (float)Py_PI;
- heading -= (float)(floor(heading * Opi2)) * pi2;
- heading -= (float)Py_PI;
-
+ heading += ( float ) Py_PI;
+ heading -= ( float ) ( floor( heading * Opi2 ) ) * pi2;
+ heading -= ( float ) Py_PI;
+
//back to degrees
- self->eul[0] = heading * (float)(180/Py_PI);
- self->eul[1] = pitch * (float)(180/Py_PI);
- self->eul[2] = bank * (float)(180/Py_PI);
+ self->eul[0] = heading * ( float ) ( 180 / Py_PI );
+ self->eul[1] = pitch * ( float ) ( 180 / Py_PI );
+ self->eul[2] = bank * ( float ) ( 180 / Py_PI );
- return EXPP_incr_ret(Py_None);
+ return EXPP_incr_ret( Py_None );
}
-PyObject *Euler_Zero(EulerObject *self)
+PyObject *Euler_Zero( EulerObject * self )
{
self->eul[0] = 0.0;
self->eul[1] = 0.0;
self->eul[2] = 0.0;
- return EXPP_incr_ret(Py_None);
+ return EXPP_incr_ret( Py_None );
}
-static void Euler_dealloc(EulerObject *self)
+static void Euler_dealloc( EulerObject * self )
{
- PyObject_DEL (self);
+ PyObject_DEL( self );
}
-static PyObject *Euler_getattr(EulerObject *self, char *name)
+static PyObject *Euler_getattr( EulerObject * self, char *name )
{
- if (ELEM3(name[0], 'x', 'y', 'z') && name[1]==0){
- return PyFloat_FromDouble(self->eul[name[0]-'x']);
+ if( ELEM3( name[0], 'x', 'y', 'z' ) && name[1] == 0 ) {
+ return PyFloat_FromDouble( self->eul[name[0] - 'x'] );
}
- return Py_FindMethod(Euler_methods, (PyObject*)self, name);
+ return Py_FindMethod( Euler_methods, ( PyObject * ) self, name );
}
-static int Euler_setattr(EulerObject *self, char *name, PyObject *e)
+static int Euler_setattr( EulerObject * self, char *name, PyObject * e )
{
float val;
- if (!PyArg_Parse(e, "f", &val))
- return EXPP_ReturnIntError(PyExc_TypeError,
- "unable to parse float argument\n");
+ if( !PyArg_Parse( e, "f", &val ) )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "unable to parse float argument\n" );
- if (ELEM3(name[0], 'x', 'y', 'z') && name[1]==0){
- self->eul[name[0]-'x']= val;
+ if( ELEM3( name[0], 'x', 'y', 'z' ) && name[1] == 0 ) {
+ self->eul[name[0] - 'x'] = val;
return 0;
- }
- else return -1;
+ } else
+ return -1;
}
/* Eulers Sequence methods */
-static PyObject *Euler_item(EulerObject *self, int i)
+static PyObject *Euler_item( EulerObject * self, int i )
{
- if (i < 0 || i >= 3)
- return EXPP_ReturnPyObjError (PyExc_IndexError, "array index out of range\n");
+ if( i < 0 || i >= 3 )
+ return EXPP_ReturnPyObjError( PyExc_IndexError,
+ "array index out of range\n" );
- return Py_BuildValue("f", self->eul[i]);
+ return Py_BuildValue( "f", self->eul[i] );
}
-static PyObject *Euler_slice(EulerObject *self, int begin, int end)
+static PyObject *Euler_slice( EulerObject * self, int begin, int end )
{
PyObject *list;
int count;
-
- if (begin < 0) begin= 0;
- if (end > 3) end= 3;
- if (begin > end) begin= end;
- list= PyList_New(end-begin);
+ if( begin < 0 )
+ begin = 0;
+ if( end > 3 )
+ end = 3;
+ if( begin > end )
+ begin = end;
+
+ list = PyList_New( end - begin );
- for (count = begin; count < end; count++){
- PyList_SetItem(list, count-begin, PyFloat_FromDouble(self->eul[count]));
+ for( count = begin; count < end; count++ ) {
+ PyList_SetItem( list, count - begin,
+ PyFloat_FromDouble( self->eul[count] ) );
}
return list;
}
-static int Euler_ass_item(EulerObject *self, int i, PyObject *ob)
+static int Euler_ass_item( EulerObject * self, int i, PyObject * ob )
{
- if (i < 0 || i >= 3)
- return EXPP_ReturnIntError(PyExc_IndexError,
- "array assignment index out of range\n");
-
- if (!PyNumber_Check(ob))
- return EXPP_ReturnIntError(PyExc_IndexError,
- "Euler member must be a number\n");
-
- if(!PyFloat_Check(ob) && !PyInt_Check(ob)){
- return EXPP_ReturnIntError(PyExc_TypeError,"int or float expected\n");
- }else{
- self->eul[i]= (float)PyFloat_AsDouble(ob);
+ if( i < 0 || i >= 3 )
+ return EXPP_ReturnIntError( PyExc_IndexError,
+ "array assignment index out of range\n" );
+
+ if( !PyNumber_Check( ob ) )
+ return EXPP_ReturnIntError( PyExc_IndexError,
+ "Euler member must be a number\n" );
+
+ if( !PyFloat_Check( ob ) && !PyInt_Check( ob ) ) {
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "int or float expected\n" );
+ } else {
+ self->eul[i] = ( float ) PyFloat_AsDouble( ob );
}
return 0;
}
-static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq)
+static int Euler_ass_slice( EulerObject * self, int begin, int end,
+ PyObject * seq )
{
int count, z;
- if (begin < 0) begin= 0;
- if (end > 3) end= 3;
- if (begin > end) begin= end;
+ if( begin < 0 )
+ begin = 0;
+ if( end > 3 )
+ end = 3;
+ if( begin > end )
+ begin = end;
- if (!PySequence_Check(seq))
- return EXPP_ReturnIntError(PyExc_TypeError,
- "illegal argument type for built-in operation\n");
- if (PySequence_Length(seq) != (end - begin))
- return EXPP_ReturnIntError(PyExc_TypeError,
- "size mismatch in slice assignment\n");
+ if( !PySequence_Check( seq ) )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "illegal argument type for built-in operation\n" );
+ if( PySequence_Length( seq ) != ( end - begin ) )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "size mismatch in slice assignment\n" );
z = 0;
- for (count = begin; count < end; count++) {
- PyObject *ob = PySequence_GetItem(seq, z); z++;
+ for( count = begin; count < end; count++ ) {
+ PyObject *ob = PySequence_GetItem( seq, z );
+ z++;
- if(!PyFloat_Check(ob) && !PyInt_Check(ob)){
- Py_DECREF(ob);
+ if( !PyFloat_Check( ob ) && !PyInt_Check( ob ) ) {
+ Py_DECREF( ob );
return -1;
- }else{
- if (!PyArg_Parse(ob, "f", &self->eul[count])) {
- Py_DECREF(ob);
+ } else {
+ if( !PyArg_Parse( ob, "f", &self->eul[count] ) ) {
+ Py_DECREF( ob );
return -1;
}
}
}
- return 0;
+ return 0;
}
-static PyObject *Euler_repr (EulerObject *self)
+static PyObject *Euler_repr( EulerObject * self )
{
int i, maxindex = 3 - 1;
char ftoa[24];
PyObject *str1, *str2;
- str1 = PyString_FromString ("[");
+ str1 = PyString_FromString( "[" );
- for (i = 0; i < maxindex; i++) {
- sprintf(ftoa, "%.4f, ", self->eul[i]);
- str2 = PyString_FromString (ftoa);
- if (!str1 || !str2) goto error;
- PyString_ConcatAndDel (&str1, str2);
+ for( i = 0; i < maxindex; i++ ) {
+ sprintf( ftoa, "%.4f, ", self->eul[i] );
+ str2 = PyString_FromString( ftoa );
+ if( !str1 || !str2 )
+ goto error;
+ PyString_ConcatAndDel( &str1, str2 );
}
- sprintf(ftoa, "%.4f]\n", self->eul[maxindex]);
- str2 = PyString_FromString (ftoa);
- if (!str1 || !str2) goto error;
- PyString_ConcatAndDel (&str1, str2);
+ sprintf( ftoa, "%.4f]\n", self->eul[maxindex] );
+ str2 = PyString_FromString( ftoa );
+ if( !str1 || !str2 )
+ goto error;
+ PyString_ConcatAndDel( &str1, str2 );
- if (str1) return str1;
+ if( str1 )
+ return str1;
-error:
- Py_XDECREF (str1);
- Py_XDECREF (str2);
- return EXPP_ReturnPyObjError (PyExc_MemoryError,
- "couldn't create PyString!\n");
+ error:
+ Py_XDECREF( str1 );
+ Py_XDECREF( str2 );
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create PyString!\n" );
}
-static PySequenceMethods Euler_SeqMethods =
-{
- (inquiry) 0, /* sq_length */
- (binaryfunc) 0, /* sq_concat */
- (intargfunc) 0, /* sq_repeat */
- (intargfunc) Euler_item, /* sq_item */
- (intintargfunc) Euler_slice, /* sq_slice */
- (intobjargproc) Euler_ass_item, /* sq_ass_item */
- (intintobjargproc) Euler_ass_slice, /* sq_ass_slice */
+static PySequenceMethods Euler_SeqMethods = {
+ ( inquiry ) 0, /* sq_length */
+ ( binaryfunc ) 0, /* sq_concat */
+ ( intargfunc ) 0, /* sq_repeat */
+ ( intargfunc ) Euler_item, /* sq_item */
+ ( intintargfunc ) Euler_slice, /* sq_slice */
+ ( intobjargproc ) Euler_ass_item, /* sq_ass_item */
+ ( intintobjargproc ) Euler_ass_slice, /* sq_ass_slice */
};
-PyTypeObject euler_Type =
-{
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "euler", /*tp_name*/
- sizeof(EulerObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor) Euler_dealloc, /*tp_dealloc*/
- (printfunc) 0, /*tp_print*/
- (getattrfunc) Euler_getattr, /*tp_getattr*/
- (setattrfunc) Euler_setattr, /*tp_setattr*/
- 0, /*tp_compare*/
- (reprfunc) Euler_repr, /*tp_repr*/
- 0, /*tp_as_number*/
- &Euler_SeqMethods, /*tp_as_sequence*/
+PyTypeObject euler_Type = {
+ PyObject_HEAD_INIT( NULL )
+ 0, /*ob_size */
+ "euler", /*tp_name */
+ sizeof( EulerObject ), /*tp_basicsize */
+ 0, /*tp_itemsize */
+ ( destructor ) Euler_dealloc, /*tp_dealloc */
+ ( printfunc ) 0, /*tp_print */
+ ( getattrfunc ) Euler_getattr, /*tp_getattr */
+ ( setattrfunc ) Euler_setattr, /*tp_setattr */
+ 0, /*tp_compare */
+ ( reprfunc ) Euler_repr, /*tp_repr */
+ 0, /*tp_as_number */
+ &Euler_SeqMethods, /*tp_as_sequence */
};
-PyObject *newEulerObject(float *eul)
+PyObject *newEulerObject( float *eul )
{
- EulerObject *self;
- int x;
+ EulerObject *self;
+ int x;
- euler_Type.ob_type = &PyType_Type;
+ euler_Type.ob_type = &PyType_Type;
- self = PyObject_NEW(EulerObject, &euler_Type);
+ self = PyObject_NEW( EulerObject, &euler_Type );
- if(!eul){
- self->eul = PyMem_Malloc (3*sizeof (float));
- for(x = 0; x < 3; x++){
- self->eul[x] = 0.0f;
- }
- }else self->eul = eul;
-
- return (PyObject*) self;
-}
+ if( !eul ) {
+ self->eul = PyMem_Malloc( 3 * sizeof( float ) );
+ for( x = 0; x < 3; x++ ) {
+ self->eul[x] = 0.0f;
+ }
+ } else
+ self->eul = eul;
+ return ( PyObject * ) self;
+}