Roll back changes from Big Mathutils Commit on 2005/05/20.
This commit is contained in:
@@ -1523,7 +1523,7 @@ PyObject *CreateGlobalDictionary( void )
|
|||||||
PyDict_SetItemString( dict, "__name__",
|
PyDict_SetItemString( dict, "__name__",
|
||||||
PyString_FromString( "__main__" ) );
|
PyString_FromString( "__main__" ) );
|
||||||
|
|
||||||
return EXPP_incr_ret(dict);
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
|||||||
@@ -46,14 +46,12 @@
|
|||||||
#include <BSE_editaction.h>
|
#include <BSE_editaction.h>
|
||||||
#include <BKE_constraint.h>
|
#include <BKE_constraint.h>
|
||||||
#include <MEM_guardedalloc.h>
|
#include <MEM_guardedalloc.h>
|
||||||
#include <BKE_utildefines.h>
|
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
#include "gen_utils.h"
|
#include "gen_utils.h"
|
||||||
#include "NLA.h"
|
#include "NLA.h"
|
||||||
#include "quat.h"
|
#include "quat.h"
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "Types.h"
|
|
||||||
|
|
||||||
//--------------------Python API function prototypes for the Bone module----
|
//--------------------Python API function prototypes for the Bone module----
|
||||||
static PyObject *M_Bone_New( PyObject * self, PyObject * args );
|
static PyObject *M_Bone_New( PyObject * self, PyObject * args );
|
||||||
@@ -539,19 +537,45 @@ PyObject *Bone_CreatePyObject( struct Bone * bone )
|
|||||||
//allocate space for python vars
|
//allocate space for python vars
|
||||||
blen_bone->name = PyMem_Malloc( 32 + 1 );
|
blen_bone->name = PyMem_Malloc( 32 + 1 );
|
||||||
blen_bone->parent = PyMem_Malloc( 32 + 1 );
|
blen_bone->parent = PyMem_Malloc( 32 + 1 );
|
||||||
blen_bone->head = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
blen_bone->head =
|
||||||
blen_bone->tail = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
( VectorObject * )
|
||||||
blen_bone->loc = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
blen_bone->dloc = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
blen_bone->tail =
|
||||||
blen_bone->size = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
( VectorObject * )
|
||||||
blen_bone->dsize = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
blen_bone->quat = ( QuaternionObject *)newQuaternionObject( NULL, Py_NEW );
|
blen_bone->loc =
|
||||||
blen_bone->dquat = ( QuaternionObject *)newQuaternionObject( NULL, Py_NEW );
|
( VectorObject * )
|
||||||
blen_bone->obmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
blen_bone->parmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
|
blen_bone->dloc =
|
||||||
blen_bone->defmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
|
( VectorObject * )
|
||||||
blen_bone->irestmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
blen_bone->posemat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
|
blen_bone->size =
|
||||||
|
( VectorObject * )
|
||||||
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
|
blen_bone->dsize =
|
||||||
|
( VectorObject * )
|
||||||
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
|
blen_bone->quat =
|
||||||
|
( QuaternionObject * )
|
||||||
|
newQuaternionObject( PyMem_Malloc( 4 * sizeof( float ) ) );
|
||||||
|
blen_bone->dquat =
|
||||||
|
( QuaternionObject * )
|
||||||
|
newQuaternionObject( PyMem_Malloc( 4 * sizeof( float ) ) );
|
||||||
|
blen_bone->obmat =
|
||||||
|
( MatrixObject * )
|
||||||
|
newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
|
||||||
|
blen_bone->parmat =
|
||||||
|
( MatrixObject * )
|
||||||
|
newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
|
||||||
|
blen_bone->defmat =
|
||||||
|
( MatrixObject * )
|
||||||
|
newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
|
||||||
|
blen_bone->irestmat =
|
||||||
|
( MatrixObject * )
|
||||||
|
newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
|
||||||
|
blen_bone->posemat =
|
||||||
|
( MatrixObject * )
|
||||||
|
newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
|
||||||
|
|
||||||
if( !updatePyBone( blen_bone ) )
|
if( !updatePyBone( blen_bone ) )
|
||||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||||
@@ -600,19 +624,45 @@ static PyObject *M_Bone_New( PyObject * self, PyObject * args )
|
|||||||
//allocate space for python vars
|
//allocate space for python vars
|
||||||
py_bone->name = PyMem_Malloc( 32 + 1 );
|
py_bone->name = PyMem_Malloc( 32 + 1 );
|
||||||
py_bone->parent = PyMem_Malloc( 32 + 1 );
|
py_bone->parent = PyMem_Malloc( 32 + 1 );
|
||||||
py_bone->head = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
py_bone->head =
|
||||||
py_bone->tail = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
( VectorObject * )
|
||||||
py_bone->loc = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
py_bone->dloc = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
py_bone->tail =
|
||||||
py_bone->size = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
( VectorObject * )
|
||||||
py_bone->dsize = ( VectorObject *)newVectorObject( NULL, 3, Py_NEW );
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
py_bone->quat = ( QuaternionObject *)newQuaternionObject( NULL, Py_NEW );
|
py_bone->loc =
|
||||||
py_bone->dquat = ( QuaternionObject *)newQuaternionObject( NULL, Py_NEW );
|
( VectorObject * )
|
||||||
py_bone->obmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
py_bone->parmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
|
py_bone->dloc =
|
||||||
py_bone->defmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
|
( VectorObject * )
|
||||||
py_bone->irestmat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
py_bone->posemat = ( MatrixObject *)newMatrixObject( NULL, 4, 4 , Py_NEW);
|
py_bone->size =
|
||||||
|
( VectorObject * )
|
||||||
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
|
py_bone->dsize =
|
||||||
|
( VectorObject * )
|
||||||
|
newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ), 3 );
|
||||||
|
py_bone->quat =
|
||||||
|
( QuaternionObject * )
|
||||||
|
newQuaternionObject( PyMem_Malloc( 4 * sizeof( float ) ) );
|
||||||
|
py_bone->dquat =
|
||||||
|
( QuaternionObject * )
|
||||||
|
newQuaternionObject( PyMem_Malloc( 4 * sizeof( float ) ) );
|
||||||
|
py_bone->obmat =
|
||||||
|
( MatrixObject * )
|
||||||
|
newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
|
||||||
|
py_bone->parmat =
|
||||||
|
( MatrixObject * )
|
||||||
|
newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
|
||||||
|
py_bone->defmat =
|
||||||
|
( MatrixObject * )
|
||||||
|
newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
|
||||||
|
py_bone->irestmat =
|
||||||
|
( MatrixObject * )
|
||||||
|
newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
|
||||||
|
py_bone->posemat =
|
||||||
|
( MatrixObject * )
|
||||||
|
newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
|
||||||
|
|
||||||
//default py values
|
//default py values
|
||||||
BLI_strncpy( py_bone->name, name_str, strlen( name_str ) + 1 );
|
BLI_strncpy( py_bone->name, name_str, strlen( name_str ) + 1 );
|
||||||
@@ -709,17 +759,19 @@ static PyObject *Bone_getWeight( BPy_Bone * self )
|
|||||||
static PyObject *Bone_getHead( BPy_Bone * self )
|
static PyObject *Bone_getHead( BPy_Bone * self )
|
||||||
{
|
{
|
||||||
PyObject *attr = NULL;
|
PyObject *attr = NULL;
|
||||||
float vec[3];
|
float *vec;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
if( !self->bone ) { //test to see if linked to armature
|
if( !self->bone ) { //test to see if linked to armature
|
||||||
//use python vars
|
//use python vars
|
||||||
|
vec = PyMem_Malloc( 3 * sizeof( float ) );
|
||||||
for( x = 0; x < 3; x++ )
|
for( x = 0; x < 3; x++ )
|
||||||
vec[x] = self->head->vec[x];
|
vec[x] = self->head->vec[x];
|
||||||
attr = ( PyObject * ) newVectorObject( vec, 3, Py_NEW );
|
attr = ( PyObject * ) newVectorObject( vec, 3 );
|
||||||
} else {
|
} else {
|
||||||
//use bone datastruct
|
//use bone datastruct
|
||||||
attr = newVectorObject( NULL, 3, Py_NEW );
|
attr = newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ),
|
||||||
|
3 );
|
||||||
( ( VectorObject * ) attr )->vec[0] = self->bone->head[0];
|
( ( VectorObject * ) attr )->vec[0] = self->bone->head[0];
|
||||||
( ( VectorObject * ) attr )->vec[1] = self->bone->head[1];
|
( ( VectorObject * ) attr )->vec[1] = self->bone->head[1];
|
||||||
( ( VectorObject * ) attr )->vec[2] = self->bone->head[2];
|
( ( VectorObject * ) attr )->vec[2] = self->bone->head[2];
|
||||||
@@ -735,17 +787,19 @@ static PyObject *Bone_getHead( BPy_Bone * self )
|
|||||||
static PyObject *Bone_getTail( BPy_Bone * self )
|
static PyObject *Bone_getTail( BPy_Bone * self )
|
||||||
{
|
{
|
||||||
PyObject *attr = NULL;
|
PyObject *attr = NULL;
|
||||||
float vec[3];
|
float *vec;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
if( !self->bone ) { //test to see if linked to armature
|
if( !self->bone ) { //test to see if linked to armature
|
||||||
//use python vars
|
//use python vars
|
||||||
|
vec = PyMem_Malloc( 3 * sizeof( float ) );
|
||||||
for( x = 0; x < 3; x++ )
|
for( x = 0; x < 3; x++ )
|
||||||
vec[x] = self->tail->vec[x];
|
vec[x] = self->tail->vec[x];
|
||||||
attr = ( PyObject * ) newVectorObject( vec, 3, Py_NEW );
|
attr = ( PyObject * ) newVectorObject( vec, 3 );
|
||||||
} else {
|
} else {
|
||||||
//use bone datastruct
|
//use bone datastruct
|
||||||
attr = newVectorObject( NULL, 3, Py_NEW );
|
attr = newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ),
|
||||||
|
3 );
|
||||||
( ( VectorObject * ) attr )->vec[0] = self->bone->tail[0];
|
( ( VectorObject * ) attr )->vec[0] = self->bone->tail[0];
|
||||||
( ( VectorObject * ) attr )->vec[1] = self->bone->tail[1];
|
( ( VectorObject * ) attr )->vec[1] = self->bone->tail[1];
|
||||||
( ( VectorObject * ) attr )->vec[2] = self->bone->tail[2];
|
( ( VectorObject * ) attr )->vec[2] = self->bone->tail[2];
|
||||||
@@ -761,17 +815,19 @@ static PyObject *Bone_getTail( BPy_Bone * self )
|
|||||||
static PyObject *Bone_getLoc( BPy_Bone * self )
|
static PyObject *Bone_getLoc( BPy_Bone * self )
|
||||||
{
|
{
|
||||||
PyObject *attr = NULL;
|
PyObject *attr = NULL;
|
||||||
float vec[3];
|
float *vec;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
if( !self->bone ) { //test to see if linked to armature
|
if( !self->bone ) { //test to see if linked to armature
|
||||||
//use python vars
|
//use python vars
|
||||||
|
vec = PyMem_Malloc( 3 * sizeof( float ) );
|
||||||
for( x = 0; x < 3; x++ )
|
for( x = 0; x < 3; x++ )
|
||||||
vec[x] = self->loc->vec[x];
|
vec[x] = self->loc->vec[x];
|
||||||
attr = ( PyObject * ) newVectorObject( vec, 3, Py_NEW );
|
attr = ( PyObject * ) newVectorObject( vec, 3 );
|
||||||
} else {
|
} else {
|
||||||
//use bone datastruct
|
//use bone datastruct
|
||||||
attr = newVectorObject( vec, 3, Py_NEW );
|
attr = newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ),
|
||||||
|
3 );
|
||||||
( ( VectorObject * ) attr )->vec[0] = self->bone->loc[0];
|
( ( VectorObject * ) attr )->vec[0] = self->bone->loc[0];
|
||||||
( ( VectorObject * ) attr )->vec[1] = self->bone->loc[1];
|
( ( VectorObject * ) attr )->vec[1] = self->bone->loc[1];
|
||||||
( ( VectorObject * ) attr )->vec[2] = self->bone->loc[2];
|
( ( VectorObject * ) attr )->vec[2] = self->bone->loc[2];
|
||||||
@@ -787,17 +843,19 @@ static PyObject *Bone_getLoc( BPy_Bone * self )
|
|||||||
static PyObject *Bone_getSize( BPy_Bone * self )
|
static PyObject *Bone_getSize( BPy_Bone * self )
|
||||||
{
|
{
|
||||||
PyObject *attr = NULL;
|
PyObject *attr = NULL;
|
||||||
float vec[3];
|
float *vec;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
if( !self->bone ) { //test to see if linked to armature
|
if( !self->bone ) { //test to see if linked to armature
|
||||||
//use python vars
|
//use python vars
|
||||||
|
vec = PyMem_Malloc( 3 * sizeof( float ) );
|
||||||
for( x = 0; x < 3; x++ )
|
for( x = 0; x < 3; x++ )
|
||||||
vec[x] = self->size->vec[x];
|
vec[x] = self->size->vec[x];
|
||||||
attr = ( PyObject * ) newVectorObject( vec, 3, Py_NEW );
|
attr = ( PyObject * ) newVectorObject( vec, 3 );
|
||||||
} else {
|
} else {
|
||||||
//use bone datastruct
|
//use bone datastruct
|
||||||
attr = newVectorObject( vec, 3, Py_NEW );
|
attr = newVectorObject( PyMem_Malloc( 3 * sizeof( float ) ),
|
||||||
|
3 );
|
||||||
( ( VectorObject * ) attr )->vec[0] = self->bone->size[0];
|
( ( VectorObject * ) attr )->vec[0] = self->bone->size[0];
|
||||||
( ( VectorObject * ) attr )->vec[1] = self->bone->size[1];
|
( ( VectorObject * ) attr )->vec[1] = self->bone->size[1];
|
||||||
( ( VectorObject * ) attr )->vec[2] = self->bone->size[2];
|
( ( VectorObject * ) attr )->vec[2] = self->bone->size[2];
|
||||||
@@ -813,18 +871,20 @@ static PyObject *Bone_getSize( BPy_Bone * self )
|
|||||||
static PyObject *Bone_getQuat( BPy_Bone * self )
|
static PyObject *Bone_getQuat( BPy_Bone * self )
|
||||||
{
|
{
|
||||||
PyObject *attr = NULL;
|
PyObject *attr = NULL;
|
||||||
float quat[4];
|
float *quat;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
if( !self->bone ) { //test to see if linked to armature
|
if( !self->bone ) { //test to see if linked to armature
|
||||||
//use python vars - p.s. - you must return a copy or else
|
//use python vars - p.s. - you must return a copy or else
|
||||||
//python will trash the internal var
|
//python will trash the internal var
|
||||||
|
quat = PyMem_Malloc( 4 * sizeof( float ) );
|
||||||
for( x = 0; x < 4; x++ )
|
for( x = 0; x < 4; x++ )
|
||||||
quat[x] = self->quat->quat[x];
|
quat[x] = self->quat->quat[x];
|
||||||
attr = ( PyObject * ) newQuaternionObject( quat, Py_NEW );
|
attr = ( PyObject * ) newQuaternionObject( quat );
|
||||||
} else {
|
} else {
|
||||||
//use bone datastruct
|
//use bone datastruct
|
||||||
attr = newQuaternionObject( NULL, Py_NEW );
|
attr = newQuaternionObject( PyMem_Malloc
|
||||||
|
( 4 * sizeof( float ) ) );
|
||||||
( ( QuaternionObject * ) attr )->quat[0] = self->bone->quat[0];
|
( ( QuaternionObject * ) attr )->quat[0] = self->bone->quat[0];
|
||||||
( ( QuaternionObject * ) attr )->quat[1] = self->bone->quat[1];
|
( ( QuaternionObject * ) attr )->quat[1] = self->bone->quat[1];
|
||||||
( ( QuaternionObject * ) attr )->quat[2] = self->bone->quat[2];
|
( ( QuaternionObject * ) attr )->quat[2] = self->bone->quat[2];
|
||||||
@@ -1625,7 +1685,7 @@ static PyObject *Bone_getRestMatrix( BPy_Bone * self, PyObject * args )
|
|||||||
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||||
"expected 'bonespace' or 'worldspace'" ) );
|
"expected 'bonespace' or 'worldspace'" ) );
|
||||||
|
|
||||||
matrix = newMatrixObject( NULL, 4, 4 , Py_NEW);
|
matrix = newMatrixObject( PyMem_Malloc( 16 * sizeof( float ) ), 4, 4 );
|
||||||
|
|
||||||
if( !self->bone ) { //test to see if linked to armature
|
if( !self->bone ) { //test to see if linked to armature
|
||||||
//use python vars
|
//use python vars
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -29,48 +29,14 @@
|
|||||||
*
|
*
|
||||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
//Include this file for access to vector, quat, matrix, euler, etc...
|
|
||||||
|
|
||||||
#ifndef EXPP_Mathutils_H
|
#ifndef EXPP_Mathutils_H
|
||||||
#define EXPP_Mathutils_H
|
#define EXPP_Mathutils_H
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
#include "vector.h"
|
|
||||||
#include "matrix.h"
|
|
||||||
#include "quat.h"
|
|
||||||
#include "euler.h"
|
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
|
|
||||||
PyObject *Mathutils_Init( void );
|
PyObject *Mathutils_Init( void );
|
||||||
PyObject *row_vector_multiplication(VectorObject* vec, MatrixObject * mat);
|
|
||||||
PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec);
|
|
||||||
|
|
||||||
PyObject *M_Mathutils_Rand(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_Vector(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_CrossVecs(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_DotVecs(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_AngleBetweenVecs(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_MidpointVecs(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_ProjectVecs(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_Matrix(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_RotationMatrix(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_TranslationMatrix(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_ScaleMatrix(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_OrthoProjectionMatrix(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_ShearMatrix(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_Quaternion(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_CrossQuats(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_DotQuats(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_DifferenceQuats(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_Slerp(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_Euler(PyObject * self, PyObject * args);
|
|
||||||
//DEPRECATED
|
|
||||||
PyObject *M_Mathutils_CopyMat(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_CopyVec(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_CopyQuat(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_CopyEuler(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_RotateEuler(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_MatMultVec(PyObject * self, PyObject * args);
|
|
||||||
PyObject *M_Mathutils_VecMultMat(PyObject * self, PyObject * args);
|
|
||||||
|
|
||||||
#endif /* EXPP_Mathutils_H */
|
#endif /* EXPP_Mathutils_H */
|
||||||
|
|||||||
@@ -58,15 +58,14 @@
|
|||||||
#include "BLI_blenlib.h"
|
#include "BLI_blenlib.h"
|
||||||
#include "BLI_arithb.h"
|
#include "BLI_arithb.h"
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
#include "BKE_utildefines.h"
|
|
||||||
|
|
||||||
#include "blendef.h"
|
#include "blendef.h"
|
||||||
#include "mydevice.h"
|
#include "mydevice.h"
|
||||||
|
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
|
#include "vector.h"
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
#include "gen_utils.h"
|
#include "gen_utils.h"
|
||||||
#include "Mathutils.h"
|
|
||||||
|
|
||||||
/* only used for ob.oopsloc at the moment */
|
/* only used for ob.oopsloc at the moment */
|
||||||
#include "DNA_oops_types.h"
|
#include "DNA_oops_types.h"
|
||||||
@@ -760,11 +759,12 @@ static PyObject *NMVert_getattr( PyObject * self, char *name )
|
|||||||
BPy_NMVert *mv = ( BPy_NMVert * ) self;
|
BPy_NMVert *mv = ( BPy_NMVert * ) self;
|
||||||
|
|
||||||
if( !strcmp( name, "co" ) || !strcmp( name, "loc" ) )
|
if( !strcmp( name, "co" ) || !strcmp( name, "loc" ) )
|
||||||
return newVectorObject(mv->co,3,Py_WRAP);
|
return newVectorProxy( mv->co, 3 );
|
||||||
|
|
||||||
else if( strcmp( name, "no" ) == 0 )
|
else if( strcmp( name, "no" ) == 0 )
|
||||||
return newVectorObject(mv->no,3,Py_WRAP);
|
return newVectorProxy( mv->no, 3 );
|
||||||
else if( strcmp( name, "uvco" ) == 0 )
|
else if( strcmp( name, "uvco" ) == 0 )
|
||||||
return newVectorObject(mv->uvco,3,Py_WRAP);
|
return newVectorProxy( mv->uvco, 3 );
|
||||||
else if( strcmp( name, "index" ) == 0 )
|
else if( strcmp( name, "index" ) == 0 )
|
||||||
return PyInt_FromLong( mv->index );
|
return PyInt_FromLong( mv->index );
|
||||||
else if( strcmp( name, "sel" ) == 0 )
|
else if( strcmp( name, "sel" ) == 0 )
|
||||||
|
|||||||
@@ -59,7 +59,6 @@
|
|||||||
#include "Ipo.h"
|
#include "Ipo.h"
|
||||||
#include "Lattice.h"
|
#include "Lattice.h"
|
||||||
#include "modules.h"
|
#include "modules.h"
|
||||||
#include "Mathutils.h"
|
|
||||||
|
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
/* only used for oops location get/set at the moment */
|
/* only used for oops location get/set at the moment */
|
||||||
@@ -647,14 +646,14 @@ PyObject *M_Object_New( PyObject * self, PyObject * args )
|
|||||||
object->dupend = 100;
|
object->dupend = 100;
|
||||||
|
|
||||||
/* Gameengine defaults */
|
/* Gameengine defaults */
|
||||||
object->mass = 1.0f;
|
object->mass = 1.0;
|
||||||
object->inertia = 1.0f;
|
object->inertia = 1.0;
|
||||||
object->formfactor = 0.4f;
|
object->formfactor = 0.4;
|
||||||
object->damping = 0.04f;
|
object->damping = 0.04;
|
||||||
object->rdamping = 0.1f;
|
object->rdamping = 0.1;
|
||||||
object->anisotropicFriction[0] = 1.0f;
|
object->anisotropicFriction[0] = 1.0;
|
||||||
object->anisotropicFriction[1] = 1.0f;
|
object->anisotropicFriction[1] = 1.0;
|
||||||
object->anisotropicFriction[2] = 1.0f;
|
object->anisotropicFriction[2] = 1.0;
|
||||||
object->gameflag = OB_PROP;
|
object->gameflag = OB_PROP;
|
||||||
|
|
||||||
object->lay = 1; // Layer, by default visible
|
object->lay = 1; // Layer, by default visible
|
||||||
@@ -1115,20 +1114,21 @@ static PyObject *Object_getDrawType( BPy_Object * self )
|
|||||||
|
|
||||||
static PyObject *Object_getEuler( BPy_Object * self )
|
static PyObject *Object_getEuler( BPy_Object * self )
|
||||||
{
|
{
|
||||||
float eul[3];
|
EulerObject *eul;
|
||||||
|
|
||||||
eul[0] = self->object->rot[0];
|
eul = ( EulerObject * ) newEulerObject( NULL );
|
||||||
eul[1] = self->object->rot[1];
|
eul->eul[0] = self->object->rot[0];
|
||||||
eul[2] = self->object->rot[2];
|
eul->eul[1] = self->object->rot[1];
|
||||||
|
eul->eul[2] = self->object->rot[2];
|
||||||
|
|
||||||
return ( PyObject * ) newEulerObject( eul, Py_WRAP );
|
return ( PyObject * ) eul;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *Object_getInverseMatrix( BPy_Object * self )
|
static PyObject *Object_getInverseMatrix( BPy_Object * self )
|
||||||
{
|
{
|
||||||
MatrixObject *inverse =
|
MatrixObject *inverse =
|
||||||
( MatrixObject * ) newMatrixObject( NULL, 4, 4, Py_NEW);
|
( MatrixObject * ) newMatrixObject( NULL, 4, 4 );
|
||||||
Mat4Invert( (float ( * )[4])*inverse->matrix, self->object->obmat );
|
Mat4Invert( (float ( * )[4])*inverse->matrix, self->object->obmat );
|
||||||
|
|
||||||
return ( ( PyObject * ) inverse );
|
return ( ( PyObject * ) inverse );
|
||||||
@@ -1175,29 +1175,35 @@ static PyObject *Object_getMaterials( BPy_Object * self, PyObject * args )
|
|||||||
|
|
||||||
static PyObject *Object_getMatrix( BPy_Object * self, PyObject * args )
|
static PyObject *Object_getMatrix( BPy_Object * self, PyObject * args )
|
||||||
{
|
{
|
||||||
float matrix[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
PyObject *matrix;
|
||||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
|
||||||
char *space = "worldspace"; /* default to world */
|
char *space = "worldspace"; /* default to world */
|
||||||
|
|
||||||
if( !PyArg_ParseTuple( args, "|s", &space ) ) {
|
if( !PyArg_ParseTuple( args, "|s", &space ) ) {
|
||||||
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||||
"expected a string or nothing" ) );
|
"expected a string or nothing" ) );
|
||||||
}
|
}
|
||||||
|
//new matrix
|
||||||
|
matrix = newMatrixObject( NULL, 4, 4 );
|
||||||
|
|
||||||
if( BLI_streq( space, "worldspace" ) ) { /* Worldspace matrix */
|
if( BLI_streq( space, "worldspace" ) ) { /* Worldspace matrix */
|
||||||
disable_where_script( 1 );
|
disable_where_script( 1 );
|
||||||
where_is_object( self->object );
|
where_is_object( self->object );
|
||||||
disable_where_script( 0 );
|
disable_where_script( 0 );
|
||||||
|
Mat4CpyMat4((float ( * )[4]) *( ( MatrixObject * ) matrix )->matrix,
|
||||||
|
self->object->obmat );
|
||||||
} else if( BLI_streq( space, "localspace" ) ) { /* Localspace matrix */
|
} else if( BLI_streq( space, "localspace" ) ) { /* Localspace matrix */
|
||||||
object_to_mat4( self->object, (float (*)[4])matrix );
|
object_to_mat4( self->object,
|
||||||
return newMatrixObject(matrix,4,4,Py_NEW);
|
( float ( * )[4] ) *( ( MatrixObject * ) matrix )->matrix );
|
||||||
} else if( BLI_streq( space, "old_worldspace" ) ) {
|
|
||||||
/* old behavior, prior to 2.34, check this method's doc string: */
|
/* old behavior, prior to 2.34, check this method's doc string: */
|
||||||
|
} else if( BLI_streq( space, "old_worldspace" ) ) {
|
||||||
|
Mat4CpyMat4( (float ( * )[4]) *( ( MatrixObject * ) matrix )->matrix,
|
||||||
|
self->object->obmat );
|
||||||
} else {
|
} else {
|
||||||
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||||
"wrong parameter, expected nothing or either 'worldspace' (default),\n\
|
"wrong parameter, expected nothing or either 'worldspace' (default),\n\
|
||||||
'localspace' or 'old_worldspace'" ) );
|
'localspace' or 'old_worldspace'" ) );
|
||||||
}
|
}
|
||||||
return newMatrixObject((float*)self->object->obmat,4,4,Py_WRAP);
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *Object_getName( BPy_Object * self )
|
static PyObject *Object_getName( BPy_Object * self )
|
||||||
@@ -1379,7 +1385,7 @@ static PyObject *Object_getBoundBox( BPy_Object * self )
|
|||||||
does not have its own memory,
|
does not have its own memory,
|
||||||
we must create vectors that allocate space */
|
we must create vectors that allocate space */
|
||||||
|
|
||||||
vector = newVectorObject( NULL, 3, Py_NEW);
|
vector = newVectorObject( NULL, 3 );
|
||||||
memcpy( ( ( VectorObject * ) vector )->vec,
|
memcpy( ( ( VectorObject * ) vector )->vec,
|
||||||
tmpvec, 3 * sizeof( float ) );
|
tmpvec, 3 * sizeof( float ) );
|
||||||
PyList_SET_ITEM( bbox, i, vector );
|
PyList_SET_ITEM( bbox, i, vector );
|
||||||
@@ -1400,7 +1406,7 @@ static PyObject *Object_getBoundBox( BPy_Object * self )
|
|||||||
|
|
||||||
/* create vectors referencing object bounding box coords */
|
/* create vectors referencing object bounding box coords */
|
||||||
for( i = 0; i < 8; i++ ) {
|
for( i = 0; i < 8; i++ ) {
|
||||||
vector = newVectorObject( vec, 3, Py_WRAP );
|
vector = newVectorObject( vec, 3 );
|
||||||
PyList_SET_ITEM( bbox, i, vector );
|
PyList_SET_ITEM( bbox, i, vector );
|
||||||
vec += 3;
|
vec += 3;
|
||||||
}
|
}
|
||||||
@@ -3917,18 +3923,17 @@ int setupSB(Object* ob){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ob->soft){
|
if(ob->soft){
|
||||||
ob->soft->nodemass = 1.0f;
|
ob->soft->nodemass = 1.0;
|
||||||
ob->soft->grav = 0.0f;
|
ob->soft->grav = 0.0;
|
||||||
ob->soft->mediafrict = 0.5f;
|
ob->soft->mediafrict = 0.5;
|
||||||
ob->soft->rklimit = 0.1f;
|
ob->soft->rklimit = 0.1;
|
||||||
ob->soft->goalspring = 0.5f;
|
ob->soft->goalspring = 0.5;
|
||||||
ob->soft->goalfrict = 0.0f;
|
ob->soft->goalfrict = 0.0;
|
||||||
ob->soft->mingoal = 0.0f;
|
ob->soft->mingoal = 0.0;
|
||||||
ob->soft->maxgoal = 1.0f;
|
ob->soft->maxgoal = 1.0;
|
||||||
ob->soft->inspring = 0.5f;
|
ob->soft->inspring = 0.5;
|
||||||
ob->soft->infrict = 0.5f;
|
ob->soft->infrict = 0.5;
|
||||||
ob->soft->defgoal = 0.7f;
|
ob->soft->defgoal = 0.7;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#ifndef EXPP_OBJECT_H
|
#ifndef EXPP_OBJECT_H
|
||||||
#define EXPP_OBJECT_H
|
#define EXPP_OBJECT_H
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <BDR_editobject.h>
|
#include <BDR_editobject.h>
|
||||||
#include <BKE_armature.h>
|
#include <BKE_armature.h>
|
||||||
@@ -59,7 +60,10 @@
|
|||||||
#include <DNA_action_types.h>
|
#include <DNA_action_types.h>
|
||||||
|
|
||||||
#include "gen_utils.h"
|
#include "gen_utils.h"
|
||||||
|
#include "vector.h"
|
||||||
|
#include "matrix.h"
|
||||||
|
#include "euler.h"
|
||||||
|
#include "quat.h"
|
||||||
|
|
||||||
/* The Object PyType Object defined in Object.c */
|
/* The Object PyType Object defined in Object.c */
|
||||||
extern PyTypeObject Object_Type;
|
extern PyTypeObject Object_Type;
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ void types_InitAll( void )
|
|||||||
CurNurb_Type.ob_type = &PyType_Type;
|
CurNurb_Type.ob_type = &PyType_Type;
|
||||||
Curve_Type.ob_type = &PyType_Type;
|
Curve_Type.ob_type = &PyType_Type;
|
||||||
Effect_Type.ob_type = &PyType_Type;
|
Effect_Type.ob_type = &PyType_Type;
|
||||||
Font_Type.ob_type = &PyType_Type;
|
|
||||||
Image_Type.ob_type = &PyType_Type;
|
Image_Type.ob_type = &PyType_Type;
|
||||||
Ipo_Type.ob_type = &PyType_Type;
|
Ipo_Type.ob_type = &PyType_Type;
|
||||||
IpoCurve_Type.ob_type = &PyType_Type;
|
IpoCurve_Type.ob_type = &PyType_Type;
|
||||||
|
|||||||
@@ -830,7 +830,7 @@ static PyObject *M_Window_GetViewMatrix( PyObject * self )
|
|||||||
|
|
||||||
viewmat =
|
viewmat =
|
||||||
( PyObject * ) newMatrixObject( ( float * ) G.vd->viewmat, 4,
|
( PyObject * ) newMatrixObject( ( float * ) G.vd->viewmat, 4,
|
||||||
4, Py_WRAP );
|
4 );
|
||||||
|
|
||||||
if( !viewmat )
|
if( !viewmat )
|
||||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||||
@@ -854,7 +854,7 @@ static PyObject *M_Window_GetPerspMatrix( PyObject * self )
|
|||||||
|
|
||||||
perspmat =
|
perspmat =
|
||||||
( PyObject * ) newMatrixObject( ( float * ) G.vd->persmat, 4,
|
( PyObject * ) newMatrixObject( ( float * ) G.vd->persmat, 4,
|
||||||
4, Py_WRAP);
|
4 );
|
||||||
|
|
||||||
if( !perspmat )
|
if( !perspmat )
|
||||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||||
|
|||||||
@@ -29,385 +29,329 @@
|
|||||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <BLI_arithb.h>
|
#include "euler.h"
|
||||||
#include <BKE_utildefines.h>
|
|
||||||
#include "Mathutils.h"
|
|
||||||
#include "gen_utils.h"
|
|
||||||
|
|
||||||
//-------------------------DOC STRINGS ---------------------------
|
//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";
|
char Euler_Unique_doc[] =
|
||||||
char Euler_ToMatrix_doc[] = "() - returns a rotation matrix representing the euler rotation";
|
"() - sets the euler rotation a unique shortest arc rotation - tests for gimbal lock";
|
||||||
char Euler_ToQuat_doc[] = "() - returns a quaternion representing the euler rotation";
|
char Euler_ToMatrix_doc[] =
|
||||||
char Euler_Rotate_doc[] = "() - rotate a euler by certain amount around an axis of rotation";
|
"() - returns a rotation matrix representing the euler rotation";
|
||||||
//-----------------------METHOD DEFINITIONS ----------------------
|
char Euler_ToQuat_doc[] =
|
||||||
|
"() - returns a quaternion representing the euler rotation";
|
||||||
|
|
||||||
|
//methods table
|
||||||
struct PyMethodDef Euler_methods[] = {
|
struct PyMethodDef Euler_methods[] = {
|
||||||
{"zero", (PyCFunction) Euler_Zero, METH_NOARGS, Euler_Zero_doc},
|
{"zero", ( PyCFunction ) Euler_Zero, METH_NOARGS,
|
||||||
{"unique", (PyCFunction) Euler_Unique, METH_NOARGS, Euler_Unique_doc},
|
Euler_Zero_doc},
|
||||||
{"toMatrix", (PyCFunction) Euler_ToMatrix, METH_NOARGS, Euler_ToMatrix_doc},
|
{"unique", ( PyCFunction ) Euler_Unique, METH_NOARGS,
|
||||||
{"toQuat", (PyCFunction) Euler_ToQuat, METH_NOARGS, Euler_ToQuat_doc},
|
Euler_Unique_doc},
|
||||||
{"rotate", (PyCFunction) Euler_Rotate, METH_VARARGS, Euler_Rotate_doc},
|
{"toMatrix", ( PyCFunction ) Euler_ToMatrix, METH_NOARGS,
|
||||||
|
Euler_ToMatrix_doc},
|
||||||
|
{"toQuat", ( PyCFunction ) Euler_ToQuat, METH_NOARGS,
|
||||||
|
Euler_ToQuat_doc},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
//-----------------------------METHODS----------------------------
|
|
||||||
//----------------------------Euler.toQuat()----------------------
|
/*****************************/
|
||||||
//return a quaternion representation of the euler
|
// Euler Python Object
|
||||||
PyObject *Euler_ToQuat(EulerObject * self)
|
/*****************************/
|
||||||
|
|
||||||
|
//euler methods
|
||||||
|
PyObject *Euler_ToQuat( EulerObject * self )
|
||||||
{
|
{
|
||||||
float eul[3];
|
float *quat;
|
||||||
float quat[4];
|
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
for(x = 0; x < 3; x++) {
|
for( x = 0; x < 3; x++ ) {
|
||||||
eul[x] = self->eul[x] * ((float)Py_PI / 180);
|
self->eul[x] *= ( float ) ( Py_PI / 180 );
|
||||||
}
|
}
|
||||||
EulToQuat(eul, quat);
|
quat = PyMem_Malloc( 4 * sizeof( float ) );
|
||||||
if(self->data.blend_data)
|
EulToQuat( self->eul, quat );
|
||||||
return (PyObject *) newQuaternionObject(quat, Py_WRAP);
|
for( x = 0; x < 3; x++ ) {
|
||||||
else
|
self->eul[x] *= ( float ) ( 180 / Py_PI );
|
||||||
return (PyObject *) newQuaternionObject(quat, Py_NEW);
|
}
|
||||||
|
return ( PyObject * ) newQuaternionObject( quat );
|
||||||
}
|
}
|
||||||
//----------------------------Euler.toMatrix()---------------------
|
|
||||||
//return a matrix representation of the euler
|
PyObject *Euler_ToMatrix( EulerObject * self )
|
||||||
PyObject *Euler_ToMatrix(EulerObject * self)
|
|
||||||
{
|
{
|
||||||
float eul[3];
|
float *mat;
|
||||||
float mat[9] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
|
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
for(x = 0; x < 3; x++) {
|
for( x = 0; x < 3; x++ ) {
|
||||||
eul[x] = self->eul[x] * ((float)Py_PI / 180);
|
self->eul[x] *= ( float ) ( Py_PI / 180 );
|
||||||
}
|
}
|
||||||
EulToMat3(eul, (float (*)[3]) mat);
|
mat = PyMem_Malloc( 3 * 3 * sizeof( float ) );
|
||||||
if(self->data.blend_data)
|
EulToMat3( self->eul, ( float ( * )[3] ) mat );
|
||||||
return (PyObject *) newMatrixObject(mat, 3, 3 , Py_WRAP);
|
for( x = 0; x < 3; x++ ) {
|
||||||
else
|
self->eul[x] *= ( float ) ( 180 / Py_PI );
|
||||||
return (PyObject *) newMatrixObject(mat, 3, 3 , Py_NEW);
|
}
|
||||||
|
return ( PyObject * ) newMatrixObject( mat, 3, 3 );
|
||||||
}
|
}
|
||||||
//----------------------------Euler.unique()-----------------------
|
|
||||||
//sets the x,y,z values to a unique euler rotation
|
PyObject *Euler_Unique( EulerObject * self )
|
||||||
PyObject *Euler_Unique(EulerObject * self)
|
|
||||||
{
|
{
|
||||||
double heading, pitch, bank;
|
float heading, pitch, bank;
|
||||||
double pi2 = Py_PI * 2.0f;
|
float pi2 = ( float ) Py_PI * 2.0f;
|
||||||
double piO2 = Py_PI / 2.0f;
|
float piO2 = ( float ) Py_PI / 2.0f;
|
||||||
double Opi2 = 1.0f / pi2;
|
float Opi2 = 1.0f / pi2;
|
||||||
|
|
||||||
//radians
|
//radians
|
||||||
heading = self->eul[0] * (float)Py_PI / 180;
|
heading = self->eul[0] * ( float ) ( Py_PI / 180 );
|
||||||
pitch = self->eul[1] * (float)Py_PI / 180;
|
pitch = self->eul[1] * ( float ) ( Py_PI / 180 );
|
||||||
bank = self->eul[2] * (float)Py_PI / 180;
|
bank = self->eul[2] * ( float ) ( Py_PI / 180 );
|
||||||
|
|
||||||
//wrap heading in +180 / -180
|
//wrap heading in +180 / -180
|
||||||
pitch += Py_PI;
|
pitch += ( float ) Py_PI;
|
||||||
pitch -= floor(pitch * Opi2) * pi2;
|
pitch -= ( float ) floor( pitch * Opi2 ) * pi2;
|
||||||
pitch -= Py_PI;
|
pitch -= ( float ) Py_PI;
|
||||||
|
|
||||||
|
|
||||||
if(pitch < -piO2) {
|
if( pitch < -piO2 ) {
|
||||||
pitch = -Py_PI - pitch;
|
pitch = ( float ) -Py_PI - pitch;
|
||||||
heading += Py_PI;
|
heading += ( float ) Py_PI;
|
||||||
bank += Py_PI;
|
bank += ( float ) Py_PI;
|
||||||
} else if(pitch > piO2) {
|
} else if( pitch > piO2 ) {
|
||||||
pitch = Py_PI - pitch;
|
pitch = ( float ) Py_PI - pitch;
|
||||||
heading += Py_PI;
|
heading += ( float ) Py_PI;
|
||||||
bank += Py_PI;
|
bank += ( float ) Py_PI;
|
||||||
}
|
}
|
||||||
//gimbal lock test
|
//gimbal lock test
|
||||||
if(fabs(pitch) > piO2 - 1e-4) {
|
if( fabs( pitch ) > piO2 - 1e-4 ) {
|
||||||
heading += bank;
|
heading += bank;
|
||||||
bank = 0.0f;
|
bank = 0.0f;
|
||||||
} else {
|
} else {
|
||||||
bank += Py_PI;
|
bank += ( float ) Py_PI;
|
||||||
bank -= (floor(bank * Opi2)) * pi2;
|
bank -= ( float ) ( floor( bank * Opi2 ) ) * pi2;
|
||||||
bank -= Py_PI;
|
bank -= ( float ) Py_PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
heading += Py_PI;
|
heading += ( float ) Py_PI;
|
||||||
heading -= (floor(heading * Opi2)) * pi2;
|
heading -= ( float ) ( floor( heading * Opi2 ) ) * pi2;
|
||||||
heading -= Py_PI;
|
heading -= ( float ) Py_PI;
|
||||||
|
|
||||||
//back to degrees
|
//back to degrees
|
||||||
self->eul[0] = heading * 180 / (float)Py_PI;
|
self->eul[0] = heading * ( float ) ( 180 / Py_PI );
|
||||||
self->eul[1] = pitch * 180 / (float)Py_PI;
|
self->eul[1] = pitch * ( float ) ( 180 / Py_PI );
|
||||||
self->eul[2] = bank * 180 / (float)Py_PI;
|
self->eul[2] = bank * ( float ) ( 180 / Py_PI );
|
||||||
|
|
||||||
return (PyObject*)self;
|
return EXPP_incr_ret( Py_None );
|
||||||
}
|
}
|
||||||
//----------------------------Euler.zero()-------------------------
|
|
||||||
//sets the euler to 0,0,0
|
PyObject *Euler_Zero( EulerObject * self )
|
||||||
PyObject *Euler_Zero(EulerObject * self)
|
|
||||||
{
|
{
|
||||||
self->eul[0] = 0.0;
|
self->eul[0] = 0.0;
|
||||||
self->eul[1] = 0.0;
|
self->eul[1] = 0.0;
|
||||||
self->eul[2] = 0.0;
|
self->eul[2] = 0.0;
|
||||||
|
|
||||||
return (PyObject*)self;
|
return EXPP_incr_ret( Py_None );
|
||||||
}
|
}
|
||||||
//----------------------------Euler.rotate()-----------------------
|
|
||||||
//rotates a euler a certain amount and returns the result
|
static void Euler_dealloc( EulerObject * self )
|
||||||
//should return a unique euler rotation (i.e. no 720 degree pitches :)
|
|
||||||
PyObject *Euler_Rotate(EulerObject * self, PyObject *args)
|
|
||||||
{
|
{
|
||||||
float angle = 0.0f;
|
/* since we own this memory... */
|
||||||
char *axis;
|
PyMem_Free( self->eul );
|
||||||
int x;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "fs", &angle, &axis)){
|
PyObject_DEL( self );
|
||||||
return EXPP_ReturnPyObjError(PyExc_TypeError,
|
|
||||||
"euler.rotate():expected angle (float) and axis (x,y,z)");
|
|
||||||
}
|
|
||||||
if(!STREQ3(axis,"x","y","z")){
|
|
||||||
return EXPP_ReturnPyObjError(PyExc_TypeError,
|
|
||||||
"euler.rotate(): expected axis to be 'x', 'y' or 'z'");
|
|
||||||
}
|
|
||||||
|
|
||||||
//covert to radians
|
|
||||||
angle *= ((float)Py_PI / 180);
|
|
||||||
for(x = 0; x < 3; x++) {
|
|
||||||
self->eul[x] *= ((float)Py_PI / 180);
|
|
||||||
}
|
|
||||||
euler_rot(self->eul, angle, *axis);
|
|
||||||
//convert back from radians
|
|
||||||
for(x = 0; x < 3; x++) {
|
|
||||||
self->eul[x] *= (180 / (float)Py_PI);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject*)self;
|
|
||||||
}
|
}
|
||||||
//----------------------------dealloc()(internal) ------------------
|
|
||||||
//free the py_object
|
static PyObject *Euler_getattr( EulerObject * self, char *name )
|
||||||
static void Euler_dealloc(EulerObject * self)
|
|
||||||
{
|
{
|
||||||
//only free py_data
|
if( ELEM3( name[0], 'x', 'y', 'z' ) && name[1] == 0 ) {
|
||||||
if(self->data.py_data){
|
return PyFloat_FromDouble( self->eul[name[0] - 'x'] );
|
||||||
PyMem_Free(self->data.py_data);
|
|
||||||
}
|
}
|
||||||
PyObject_DEL(self);
|
return Py_FindMethod( Euler_methods, ( PyObject * ) self, name );
|
||||||
}
|
}
|
||||||
//----------------------------getattr()(internal) ------------------
|
|
||||||
//object.attribute access (get)
|
static int Euler_setattr( EulerObject * self, char *name, PyObject * e )
|
||||||
static PyObject *Euler_getattr(EulerObject * self, char *name)
|
|
||||||
{
|
{
|
||||||
int x;
|
float val;
|
||||||
|
|
||||||
if(STREQ(name,"x")){
|
if( !PyArg_Parse( e, "f", &val ) )
|
||||||
return PyFloat_FromDouble(self->eul[0]);
|
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||||
}else if(STREQ(name, "y")){
|
"unable to parse float argument\n" );
|
||||||
return PyFloat_FromDouble(self->eul[1]);
|
|
||||||
}else if(STREQ(name, "z")){
|
|
||||||
return PyFloat_FromDouble(self->eul[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Py_FindMethod(Euler_methods, (PyObject *) self, name);
|
if( ELEM3( name[0], 'x', 'y', 'z' ) && name[1] == 0 ) {
|
||||||
|
self->eul[name[0] - 'x'] = val;
|
||||||
|
return 0;
|
||||||
|
} else
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
//----------------------------setattr()(internal) ------------------
|
|
||||||
//object.attribute access (set)
|
/* Eulers Sequence methods */
|
||||||
static int Euler_setattr(EulerObject * self, char *name, PyObject * e)
|
static PyObject *Euler_item( EulerObject * self, int i )
|
||||||
{
|
{
|
||||||
PyObject *f = NULL;
|
if( i < 0 || i >= 3 )
|
||||||
|
return EXPP_ReturnPyObjError( PyExc_IndexError,
|
||||||
|
"array index out of range\n" );
|
||||||
|
|
||||||
f = PyNumber_Float(e);
|
return Py_BuildValue( "f", self->eul[i] );
|
||||||
if(f == NULL) { // parsed item not a number
|
|
||||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
|
||||||
"euler.attribute = x: argument not a number\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(STREQ(name,"x")){
|
|
||||||
self->eul[0] = PyFloat_AS_DOUBLE(f);
|
|
||||||
}else if(STREQ(name, "y")){
|
|
||||||
self->eul[1] = PyFloat_AS_DOUBLE(f);
|
|
||||||
}else if(STREQ(name, "z")){
|
|
||||||
self->eul[2] = PyFloat_AS_DOUBLE(f);
|
|
||||||
}else{
|
|
||||||
Py_DECREF(f);
|
|
||||||
return EXPP_ReturnIntError(PyExc_AttributeError,
|
|
||||||
"euler.attribute = x: unknown attribute\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_DECREF(f);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
//----------------------------print object (internal)--------------
|
|
||||||
//print the object to screen
|
static PyObject *Euler_slice( EulerObject * self, int begin, int end )
|
||||||
static PyObject *Euler_repr(EulerObject * self)
|
|
||||||
{
|
{
|
||||||
int i;
|
PyObject *list;
|
||||||
char buffer[48], str[1024];
|
|
||||||
|
|
||||||
BLI_strncpy(str,"[",1024);
|
|
||||||
for(i = 0; i < 3; i++){
|
|
||||||
if(i < (2)){
|
|
||||||
sprintf(buffer, "%.6f, ", self->eul[i]);
|
|
||||||
strcat(str,buffer);
|
|
||||||
}else{
|
|
||||||
sprintf(buffer, "%.6f", self->eul[i]);
|
|
||||||
strcat(str,buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
strcat(str, "](euler)");
|
|
||||||
|
|
||||||
return EXPP_incr_ret(PyString_FromString(str));
|
|
||||||
}
|
|
||||||
//---------------------SEQUENCE PROTOCOLS------------------------
|
|
||||||
//----------------------------len(object)------------------------
|
|
||||||
//sequence length
|
|
||||||
static int Euler_len(EulerObject * self)
|
|
||||||
{
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
//----------------------------object[]---------------------------
|
|
||||||
//sequence accessor (get)
|
|
||||||
static PyObject *Euler_item(EulerObject * self, int i)
|
|
||||||
{
|
|
||||||
if(i < 0 || i >= 3)
|
|
||||||
return EXPP_ReturnPyObjError(PyExc_IndexError,
|
|
||||||
"euler[attribute]: array index out of range\n");
|
|
||||||
|
|
||||||
return Py_BuildValue("f", self->eul[i]);
|
|
||||||
|
|
||||||
}
|
|
||||||
//----------------------------object[]-------------------------
|
|
||||||
//sequence accessor (set)
|
|
||||||
static int Euler_ass_item(EulerObject * self, int i, PyObject * ob)
|
|
||||||
{
|
|
||||||
PyObject *f = NULL;
|
|
||||||
|
|
||||||
f = PyNumber_Float(ob);
|
|
||||||
if(f == NULL) { // parsed item not a number
|
|
||||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
|
||||||
"euler[attribute] = x: argument not a number\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i < 0 || i >= 3){
|
|
||||||
Py_DECREF(f);
|
|
||||||
return EXPP_ReturnIntError(PyExc_IndexError,
|
|
||||||
"euler[attribute] = x: array assignment index out of range\n");
|
|
||||||
}
|
|
||||||
self->eul[i] = PyFloat_AS_DOUBLE(f);
|
|
||||||
Py_DECREF(f);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
//----------------------------object[z:y]------------------------
|
|
||||||
//sequence slice (get)
|
|
||||||
static PyObject *Euler_slice(EulerObject * self, int begin, int end)
|
|
||||||
{
|
|
||||||
PyObject *list = NULL;
|
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
CLAMP(begin, 0, 3);
|
if( begin < 0 )
|
||||||
CLAMP(end, 0, 3);
|
begin = 0;
|
||||||
begin = MIN2(begin,end);
|
if( end > 3 )
|
||||||
|
end = 3;
|
||||||
|
if( begin > end )
|
||||||
|
begin = end;
|
||||||
|
|
||||||
list = PyList_New(end - begin);
|
list = PyList_New( end - begin );
|
||||||
for(count = begin; count < end; count++) {
|
|
||||||
PyList_SetItem(list, count - begin,
|
for( count = begin; count < end; count++ ) {
|
||||||
PyFloat_FromDouble(self->eul[count]));
|
PyList_SetItem( list, count - begin,
|
||||||
|
PyFloat_FromDouble( self->eul[count] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
//----------------------------object[z:y]------------------------
|
|
||||||
//sequence slice (set)
|
static int Euler_ass_item( EulerObject * self, int i, PyObject * ob )
|
||||||
static int Euler_ass_slice(EulerObject * self, int begin, int end,
|
|
||||||
PyObject * seq)
|
|
||||||
{
|
{
|
||||||
int i, y, size = 0;
|
if( i < 0 || i >= 3 )
|
||||||
float eul[3];
|
return EXPP_ReturnIntError( PyExc_IndexError,
|
||||||
|
"array assignment index out of range\n" );
|
||||||
|
|
||||||
CLAMP(begin, 0, 3);
|
if( !PyNumber_Check( ob ) )
|
||||||
CLAMP(end, 0, 3);
|
return EXPP_ReturnIntError( PyExc_IndexError,
|
||||||
begin = MIN2(begin,end);
|
"Euler member must be a number\n" );
|
||||||
|
|
||||||
size = PySequence_Length(seq);
|
if( !PyFloat_Check( ob ) && !PyInt_Check( ob ) ) {
|
||||||
if(size != (end - begin)){
|
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
"int or float expected\n" );
|
||||||
"euler[begin:end] = []: size mismatch in slice assignment\n");
|
} else {
|
||||||
}
|
self->eul[i] = ( float ) PyFloat_AsDouble( ob );
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
|
||||||
PyObject *e, *f;
|
|
||||||
|
|
||||||
e = PySequence_GetItem(seq, i);
|
|
||||||
if (e == NULL) { // Failed to read sequence
|
|
||||||
return EXPP_ReturnIntError(PyExc_RuntimeError,
|
|
||||||
"euler[begin:end] = []: unable to read sequence\n");
|
|
||||||
}
|
|
||||||
f = PyNumber_Float(e);
|
|
||||||
if(f == NULL) { // parsed item not a number
|
|
||||||
Py_DECREF(e);
|
|
||||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
|
||||||
"euler[begin:end] = []: sequence argument not a number\n");
|
|
||||||
}
|
|
||||||
eul[i] = PyFloat_AS_DOUBLE(f);
|
|
||||||
EXPP_decr2(f,e);
|
|
||||||
}
|
|
||||||
//parsed well - now set in vector
|
|
||||||
for(y = 0; y < 3; y++){
|
|
||||||
self->eul[begin + y] = eul[y];
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//-----------------PROTCOL DECLARATIONS--------------------------
|
|
||||||
|
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( !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++;
|
||||||
|
|
||||||
|
if( !PyFloat_Check( ob ) && !PyInt_Check( ob ) ) {
|
||||||
|
Py_DECREF( ob );
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
if( !PyArg_Parse( ob, "f", &self->eul[count] ) ) {
|
||||||
|
Py_DECREF( ob );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *Euler_repr( EulerObject * self )
|
||||||
|
{
|
||||||
|
int i, maxindex = 3 - 1;
|
||||||
|
char ftoa[24];
|
||||||
|
PyObject *str1, *str2;
|
||||||
|
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf( ftoa, "%.4f]\n", self->eul[maxindex] );
|
||||||
|
str2 = PyString_FromString( ftoa );
|
||||||
|
if( !str1 || !str2 )
|
||||||
|
goto error;
|
||||||
|
PyString_ConcatAndDel( &str1, str2 );
|
||||||
|
|
||||||
|
if( str1 )
|
||||||
|
return str1;
|
||||||
|
|
||||||
|
error:
|
||||||
|
Py_XDECREF( str1 );
|
||||||
|
Py_XDECREF( str2 );
|
||||||
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||||
|
"couldn't create PyString!\n" );
|
||||||
|
}
|
||||||
|
|
||||||
static PySequenceMethods Euler_SeqMethods = {
|
static PySequenceMethods Euler_SeqMethods = {
|
||||||
(inquiry) Euler_len, /* sq_length */
|
( inquiry ) 0, /* sq_length */
|
||||||
(binaryfunc) 0, /* sq_concat */
|
( binaryfunc ) 0, /* sq_concat */
|
||||||
(intargfunc) 0, /* sq_repeat */
|
( intargfunc ) 0, /* sq_repeat */
|
||||||
(intargfunc) Euler_item, /* sq_item */
|
( intargfunc ) Euler_item, /* sq_item */
|
||||||
(intintargfunc) Euler_slice, /* sq_slice */
|
( intintargfunc ) Euler_slice, /* sq_slice */
|
||||||
(intobjargproc) Euler_ass_item, /* sq_ass_item */
|
( intobjargproc ) Euler_ass_item, /* sq_ass_item */
|
||||||
(intintobjargproc) Euler_ass_slice, /* sq_ass_slice */
|
( intintobjargproc ) Euler_ass_slice, /* sq_ass_slice */
|
||||||
};
|
};
|
||||||
//------------------PY_OBECT DEFINITION--------------------------
|
|
||||||
PyTypeObject euler_Type = {
|
PyTypeObject euler_Type = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT( NULL )
|
||||||
0, /*ob_size */
|
0, /*ob_size */
|
||||||
"euler", /*tp_name */
|
"euler", /*tp_name */
|
||||||
sizeof(EulerObject), /*tp_basicsize */
|
sizeof( EulerObject ), /*tp_basicsize */
|
||||||
0, /*tp_itemsize */
|
0, /*tp_itemsize */
|
||||||
(destructor) Euler_dealloc, /*tp_dealloc */
|
( destructor ) Euler_dealloc, /*tp_dealloc */
|
||||||
(printfunc) 0, /*tp_print */
|
( printfunc ) 0, /*tp_print */
|
||||||
(getattrfunc) Euler_getattr, /*tp_getattr */
|
( getattrfunc ) Euler_getattr, /*tp_getattr */
|
||||||
(setattrfunc) Euler_setattr, /*tp_setattr */
|
( setattrfunc ) Euler_setattr, /*tp_setattr */
|
||||||
0, /*tp_compare */
|
0, /*tp_compare */
|
||||||
(reprfunc) Euler_repr, /*tp_repr */
|
( reprfunc ) Euler_repr, /*tp_repr */
|
||||||
0, /*tp_as_number */
|
0, /*tp_as_number */
|
||||||
&Euler_SeqMethods, /*tp_as_sequence */
|
&Euler_SeqMethods, /*tp_as_sequence */
|
||||||
};
|
};
|
||||||
//------------------------newEulerObject (internal)-------------
|
|
||||||
//creates a new euler object
|
PyObject *newEulerObject( float *eul )
|
||||||
/*pass Py_WRAP - if vector is a WRAPPER for data allocated by BLENDER
|
|
||||||
(i.e. it was allocated elsewhere by MEM_mallocN())
|
|
||||||
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
|
||||||
(i.e. it must be created here with PyMEM_malloc())*/
|
|
||||||
PyObject *newEulerObject(float *eul, int type)
|
|
||||||
{
|
{
|
||||||
EulerObject *self;
|
EulerObject *self;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
euler_Type.ob_type = &PyType_Type;
|
euler_Type.ob_type = &PyType_Type;
|
||||||
self = PyObject_NEW(EulerObject, &euler_Type);
|
|
||||||
self->data.blend_data = NULL;
|
|
||||||
self->data.py_data = NULL;
|
|
||||||
|
|
||||||
if(type == Py_WRAP){
|
self = PyObject_NEW( EulerObject, &euler_Type );
|
||||||
self->data.blend_data = eul;
|
|
||||||
self->eul = self->data.blend_data;
|
/*
|
||||||
}else if (type == Py_NEW){
|
we own the self->eul memory and will free it later.
|
||||||
self->data.py_data = PyMem_Malloc(3 * sizeof(float));
|
if we received an input arg, copy to our internal array
|
||||||
self->eul = self->data.py_data;
|
*/
|
||||||
if(!eul) { //new empty
|
|
||||||
for(x = 0; x < 3; x++) {
|
self->eul = PyMem_Malloc( 3 * sizeof( float ) );
|
||||||
self->eul[x] = 0.0f;
|
if( ! self->eul )
|
||||||
}
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||||
}else{
|
"newEulerObject:PyMem_Malloc failed" );
|
||||||
for(x = 0; x < 3; x++){
|
|
||||||
self->eul[x] = eul[x];
|
if( !eul ) {
|
||||||
}
|
for( x = 0; x < 3; x++ ) {
|
||||||
|
self->eul[x] = 0.0f;
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
for( x = 0; x < 3; x++){
|
||||||
|
self->eul[x] = eul[x];
|
||||||
}
|
}
|
||||||
}else{ //bad type
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
return (PyObject *) EXPP_incr_ret((PyObject *)self);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return ( PyObject * ) self;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
@@ -34,28 +35,33 @@
|
|||||||
#ifndef EXPP_euler_h
|
#ifndef EXPP_euler_h
|
||||||
#define EXPP_euler_h
|
#define EXPP_euler_h
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
#include "gen_utils.h"
|
||||||
|
#include "Types.h"
|
||||||
|
#include <BLI_arithb.h>
|
||||||
|
#include "quat.h"
|
||||||
|
#include "matrix.h"
|
||||||
|
#include "BKE_utildefines.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*****************************/
|
||||||
|
// Euler Python Object
|
||||||
|
/*****************************/
|
||||||
|
|
||||||
#define EulerObject_Check(v) ((v)->ob_type == &euler_Type)
|
#define EulerObject_Check(v) ((v)->ob_type == &euler_Type)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_VAR_HEAD
|
PyObject_VAR_HEAD float *eul;
|
||||||
struct{
|
|
||||||
float *py_data; //python managed
|
|
||||||
float *blend_data; //blender managed
|
|
||||||
}data;
|
|
||||||
float *eul; //1D array of data (alias)
|
|
||||||
} EulerObject;
|
} EulerObject;
|
||||||
|
|
||||||
/*struct data contains a pointer to the actual data that the
|
|
||||||
object uses. It can use either PyMem allocated data (which will
|
|
||||||
be stored in py_data) or be a wrapper for data allocated through
|
|
||||||
blender (stored in blend_data). This is an either/or struct not both*/
|
|
||||||
|
|
||||||
//prototypes
|
//prototypes
|
||||||
|
PyObject *newEulerObject( float *eul );
|
||||||
PyObject *Euler_Zero( EulerObject * self );
|
PyObject *Euler_Zero( EulerObject * self );
|
||||||
PyObject *Euler_Unique( EulerObject * self );
|
PyObject *Euler_Unique( EulerObject * self );
|
||||||
PyObject *Euler_ToMatrix( EulerObject * self );
|
PyObject *Euler_ToMatrix( EulerObject * self );
|
||||||
PyObject *Euler_ToQuat( EulerObject * self );
|
PyObject *Euler_ToQuat( EulerObject * self );
|
||||||
PyObject *Euler_Rotate( EulerObject * self, PyObject *args );
|
|
||||||
PyObject *newEulerObject( float *eul, int type );
|
|
||||||
|
|
||||||
#endif /* EXPP_euler_h */
|
#endif /* EXPP_euler_h */
|
||||||
|
|||||||
@@ -120,31 +120,6 @@ int EXPP_ReturnIntError( PyObject * type, char *error_msg )
|
|||||||
/* Description: This function increments the reference count of the given */
|
/* Description: This function increments the reference count of the given */
|
||||||
/* Python object (usually Py_None) and returns it. */
|
/* Python object (usually Py_None) and returns it. */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void EXPP_incr2( PyObject * ob1, PyObject * ob2 )
|
|
||||||
{
|
|
||||||
Py_INCREF( ob1 );
|
|
||||||
Py_INCREF( ob2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
void EXPP_incr3( PyObject * ob1, PyObject * ob2, PyObject * ob3 )
|
|
||||||
{
|
|
||||||
Py_INCREF( ob1 );
|
|
||||||
Py_INCREF( ob2 );
|
|
||||||
Py_INCREF( ob3 );
|
|
||||||
}
|
|
||||||
|
|
||||||
void EXPP_decr2( PyObject * ob1, PyObject * ob2 )
|
|
||||||
{
|
|
||||||
Py_DECREF( ob1 );
|
|
||||||
Py_DECREF( ob2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
void EXPP_decr3( PyObject * ob1, PyObject * ob2, PyObject * ob3 )
|
|
||||||
{
|
|
||||||
Py_DECREF( ob1 );
|
|
||||||
Py_DECREF( ob2 );
|
|
||||||
Py_DECREF( ob3 );
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *EXPP_incr_ret( PyObject * object )
|
PyObject *EXPP_incr_ret( PyObject * object )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,8 +50,6 @@
|
|||||||
#include <DNA_listBase.h>
|
#include <DNA_listBase.h>
|
||||||
|
|
||||||
#define Py_PI 3.14159265358979323846
|
#define Py_PI 3.14159265358979323846
|
||||||
#define Py_WRAP 1024
|
|
||||||
#define Py_NEW 2048
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Py_RETURN_NONE
|
Py_RETURN_NONE
|
||||||
@@ -74,10 +72,6 @@ char *event_to_name( short event );
|
|||||||
float EXPP_ClampFloat( float value, float min, float max );
|
float EXPP_ClampFloat( float value, float min, float max );
|
||||||
int EXPP_ClampInt( int value, int min, int max );
|
int EXPP_ClampInt( int value, int min, int max );
|
||||||
|
|
||||||
void EXPP_incr2( PyObject * ob1, PyObject * ob2 );
|
|
||||||
void EXPP_incr3( PyObject * ob1, PyObject * ob2, PyObject * ob3 );
|
|
||||||
void EXPP_decr2( PyObject * ob1, PyObject * ob2 );
|
|
||||||
void EXPP_decr3( PyObject * ob1, PyObject * ob2, PyObject * ob3 );
|
|
||||||
PyObject *EXPP_incr_ret( PyObject * object );
|
PyObject *EXPP_incr_ret( PyObject * object );
|
||||||
PyObject *EXPP_incr_ret_True(void);
|
PyObject *EXPP_incr_ret_True(void);
|
||||||
PyObject *EXPP_incr_ret_False(void);
|
PyObject *EXPP_incr_ret_False(void);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -33,31 +33,37 @@
|
|||||||
#ifndef EXPP_matrix_h
|
#ifndef EXPP_matrix_h
|
||||||
#define EXPP_matrix_h
|
#define EXPP_matrix_h
|
||||||
|
|
||||||
#define MatrixObject_Check(v) ((v)->ob_type == &matrix_Type)
|
#include "Python.h"
|
||||||
|
#include "BLI_arithb.h"
|
||||||
|
#include "vector.h"
|
||||||
|
#include "gen_utils.h"
|
||||||
|
#include "Types.h"
|
||||||
|
#include "quat.h"
|
||||||
|
#include "euler.h"
|
||||||
|
|
||||||
|
#define Matrix_CheckPyObject(v) ((v)->ob_type == &matrix_Type)
|
||||||
|
|
||||||
|
/*****************************/
|
||||||
|
/* Matrix Python Object */
|
||||||
|
/*****************************/
|
||||||
typedef float **ptRow;
|
typedef float **ptRow;
|
||||||
|
|
||||||
typedef struct _Matrix {
|
typedef struct _Matrix {
|
||||||
PyObject_VAR_HEAD
|
PyObject_VAR_HEAD /* standard python macro */
|
||||||
struct{
|
ptRow matrix;
|
||||||
float *py_data; //python managed
|
float *contigPtr;
|
||||||
float *blend_data; //blender managed
|
|
||||||
}data;
|
|
||||||
ptRow matrix; //ptr to the contigPtr (accessor)
|
|
||||||
float *contigPtr; //1D array of data (alias)
|
|
||||||
int rowSize;
|
int rowSize;
|
||||||
int colSize;
|
int colSize;
|
||||||
PyObject *coerced_object;
|
int flag;
|
||||||
|
//0 - no coercion
|
||||||
|
//1 - coerced from int
|
||||||
|
//2 - coerced from float
|
||||||
} MatrixObject;
|
} MatrixObject;
|
||||||
/*coerced_object is a pointer to the object that it was
|
|
||||||
coerced from when a dummy vector needs to be created from
|
|
||||||
the coerce() function for numeric protocol operations*/
|
|
||||||
|
|
||||||
/*struct data contains a pointer to the actual data that the
|
/*****************************************************************************/
|
||||||
object uses. It can use either PyMem allocated data (which will
|
/* Python API function prototypes. */
|
||||||
be stored in py_data) or be a wrapper for data allocated through
|
/*****************************************************************************/
|
||||||
blender (stored in blend_data). This is an either/or struct not both*/
|
PyObject *newMatrixObject( float *mat, int rowSize, int colSize );
|
||||||
|
|
||||||
//prototypes
|
|
||||||
PyObject *Matrix_Zero( MatrixObject * self );
|
PyObject *Matrix_Zero( MatrixObject * self );
|
||||||
PyObject *Matrix_Identity( MatrixObject * self );
|
PyObject *Matrix_Identity( MatrixObject * self );
|
||||||
PyObject *Matrix_Transpose( MatrixObject * self );
|
PyObject *Matrix_Transpose( MatrixObject * self );
|
||||||
@@ -68,6 +74,5 @@ PyObject *Matrix_RotationPart( MatrixObject * self );
|
|||||||
PyObject *Matrix_Resize4x4( MatrixObject * self );
|
PyObject *Matrix_Resize4x4( MatrixObject * self );
|
||||||
PyObject *Matrix_toEuler( MatrixObject * self );
|
PyObject *Matrix_toEuler( MatrixObject * self );
|
||||||
PyObject *Matrix_toQuat( MatrixObject * self );
|
PyObject *Matrix_toQuat( MatrixObject * self );
|
||||||
PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type);
|
|
||||||
|
|
||||||
#endif /* EXPP_matrix_H */
|
#endif /* EXPP_matrix_H */
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -34,27 +34,34 @@
|
|||||||
#ifndef EXPP_quat_h
|
#ifndef EXPP_quat_h
|
||||||
#define EXPP_quat_h
|
#define EXPP_quat_h
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
#include "gen_utils.h"
|
||||||
|
#include "Types.h"
|
||||||
|
#include <BLI_arithb.h>
|
||||||
|
#include "euler.h"
|
||||||
|
#include "matrix.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*****************************/
|
||||||
|
// Quaternion Python Object
|
||||||
|
/*****************************/
|
||||||
|
|
||||||
#define QuaternionObject_Check(v) ((v)->ob_type == &quaternion_Type)
|
#define QuaternionObject_Check(v) ((v)->ob_type == &quaternion_Type)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_VAR_HEAD
|
PyObject_VAR_HEAD float *quat;
|
||||||
struct{
|
int flag;
|
||||||
float *py_data; //python managed
|
//0 - no coercion
|
||||||
float *blend_data; //blender managed
|
//1 - coerced from int
|
||||||
}data;
|
//2 - coerced from float
|
||||||
float *quat; //1D array of data (alias)
|
|
||||||
PyObject *coerced_object;
|
|
||||||
} QuaternionObject;
|
} QuaternionObject;
|
||||||
/*coerced_object is a pointer to the object that it was
|
|
||||||
coerced from when a dummy vector needs to be created from
|
|
||||||
the coerce() function for numeric protocol operations*/
|
|
||||||
|
|
||||||
/*struct data contains a pointer to the actual data that the
|
|
||||||
object uses. It can use either PyMem allocated data (which will
|
|
||||||
be stored in py_data) or be a wrapper for data allocated through
|
|
||||||
blender (stored in blend_data). This is an either/or struct not both*/
|
|
||||||
|
|
||||||
//prototypes
|
//prototypes
|
||||||
|
PyObject *newQuaternionObject( float *quat );
|
||||||
PyObject *Quaternion_Identity( QuaternionObject * self );
|
PyObject *Quaternion_Identity( QuaternionObject * self );
|
||||||
PyObject *Quaternion_Negate( QuaternionObject * self );
|
PyObject *Quaternion_Negate( QuaternionObject * self );
|
||||||
PyObject *Quaternion_Conjugate( QuaternionObject * self );
|
PyObject *Quaternion_Conjugate( QuaternionObject * self );
|
||||||
@@ -62,6 +69,5 @@ PyObject *Quaternion_Inverse( QuaternionObject * self );
|
|||||||
PyObject *Quaternion_Normalize( QuaternionObject * self );
|
PyObject *Quaternion_Normalize( QuaternionObject * self );
|
||||||
PyObject *Quaternion_ToEuler( QuaternionObject * self );
|
PyObject *Quaternion_ToEuler( QuaternionObject * self );
|
||||||
PyObject *Quaternion_ToMatrix( QuaternionObject * self );
|
PyObject *Quaternion_ToMatrix( QuaternionObject * self );
|
||||||
PyObject *newQuaternionObject( float *quat, int type );
|
|
||||||
|
|
||||||
#endif /* EXPP_quat_h */
|
#endif /* EXPP_quat_h */
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -33,34 +33,40 @@
|
|||||||
#ifndef EXPP_vector_h
|
#ifndef EXPP_vector_h
|
||||||
#define EXPP_vector_h
|
#define EXPP_vector_h
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
#include "gen_utils.h"
|
||||||
|
#include "Types.h"
|
||||||
|
#include "matrix.h"
|
||||||
|
#include "BKE_utildefines.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*****************************/
|
||||||
|
// Vector Python Object
|
||||||
|
/*****************************/
|
||||||
|
|
||||||
#define VectorObject_Check(v) ((v)->ob_type == &vector_Type)
|
#define VectorObject_Check(v) ((v)->ob_type == &vector_Type)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_VAR_HEAD
|
PyObject_VAR_HEAD float *vec;
|
||||||
struct{
|
|
||||||
float *py_data; //python managed
|
|
||||||
float *blend_data; //blender managed
|
|
||||||
}data;
|
|
||||||
float *vec; //1D array of data (alias)
|
|
||||||
int size;
|
int size;
|
||||||
PyObject *coerced_object;
|
int flag;
|
||||||
|
//0 - no coercion
|
||||||
|
//1 - coerced from int
|
||||||
|
//2 - coerced from float
|
||||||
|
int delete_pymem; /* flag to delete the memory vec points at */
|
||||||
} VectorObject;
|
} VectorObject;
|
||||||
/*coerced_object is a pointer to the object that it was
|
|
||||||
coerced from when a dummy vector needs to be created from
|
|
||||||
the coerce() function for numeric protocol operations*/
|
|
||||||
|
|
||||||
/*struct data contains a pointer to the actual data that the
|
|
||||||
object uses. It can use either PyMem allocated data (which will
|
|
||||||
be stored in py_data) or be a wrapper for data allocated through
|
|
||||||
blender (stored in blend_data). This is an either/or struct not both*/
|
|
||||||
|
|
||||||
//prototypes
|
//prototypes
|
||||||
|
PyObject *newVectorObject( float *vec, int size );
|
||||||
|
PyObject *newVectorProxy( float *vec, int size );
|
||||||
PyObject *Vector_Zero( VectorObject * self );
|
PyObject *Vector_Zero( VectorObject * self );
|
||||||
PyObject *Vector_Normalize( VectorObject * self );
|
PyObject *Vector_Normalize( VectorObject * self );
|
||||||
PyObject *Vector_Negate( VectorObject * self );
|
PyObject *Vector_Negate( VectorObject * self );
|
||||||
PyObject *Vector_Resize2D( VectorObject * self );
|
PyObject *Vector_Resize2D( VectorObject * self );
|
||||||
PyObject *Vector_Resize3D( VectorObject * self );
|
PyObject *Vector_Resize3D( VectorObject * self );
|
||||||
PyObject *Vector_Resize4D( VectorObject * self );
|
PyObject *Vector_Resize4D( VectorObject * self );
|
||||||
PyObject *newVectorObject(float *vec, int size, int type);
|
|
||||||
|
|
||||||
#endif /* EXPP_vector_h */
|
#endif /* EXPP_vector_h */
|
||||||
|
|||||||
Reference in New Issue
Block a user