diff options
author | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-05-21 13:18:42 +0400 |
---|---|---|
committer | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-05-21 13:18:42 +0400 |
commit | 1217928e662bd74980dc17c8d32797b0bc6f7002 (patch) | |
tree | 1d46e362c2e3e114ebc2f30f5a942646d0f3bfc4 /source/gameengine/Ketsji/KX_PyMath.cpp | |
parent | 22883f9232da3df2bcba995bb0d84d4cf95803e8 (diff) |
Fixes for Camera objects and python:
Normalise clip planes for sphere testing.
Do a frustum-sphere <-> sphere test
Reference count all python objects (!)
Diffstat (limited to 'source/gameengine/Ketsji/KX_PyMath.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_PyMath.cpp | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/source/gameengine/Ketsji/KX_PyMath.cpp b/source/gameengine/Ketsji/KX_PyMath.cpp index 3fd1b7be69b..287ae500ea5 100644 --- a/source/gameengine/Ketsji/KX_PyMath.cpp +++ b/source/gameengine/Ketsji/KX_PyMath.cpp @@ -69,12 +69,14 @@ MT_Vector3 MT_Vector3FromPyList(PyObject* pylist) } else { // assert the list is long enough... - unsigned int numitems = PyList_Size(pylist); + unsigned int numitems = PySequence_Size(pylist); if (numitems <= 3) { for (unsigned int index=0;index<numitems;index++) { - vec[index] = PyFloat_AsDouble(PyList_GetItem(pylist,index)); + PyObject *item = PySequence_GetItem(pylist,index); /* new ref */ + vec[index] = PyFloat_AsDouble(item); + Py_DECREF(item); } } else @@ -111,12 +113,14 @@ MT_Point3 MT_Point3FromPyList(PyObject* pylist) } else { // assert the list is long enough... - unsigned int numitems = PyList_Size(pylist); + unsigned int numitems = PySequence_Size(pylist); if (numitems <= 3) { for (unsigned int index=0;index<numitems;index++) { - point[index] = PyFloat_AsDouble(PyList_GetItem(pylist,index)); + PyObject *item = PySequence_GetItem(pylist,index); /* new ref */ + point[index] = PyFloat_AsDouble(item); + Py_DECREF(item); } } else @@ -153,12 +157,14 @@ MT_Vector4 MT_Vector4FromPyList(PyObject* pylist) } else { // assert the list is long enough... - unsigned int numitems = PyList_Size(pylist); + unsigned int numitems = PySequence_Size(pylist); if (numitems <= 4) { for (unsigned index=0;index<numitems;index++) { - vec[index] = PyFloat_AsDouble(PyList_GetItem(pylist,index)); + PyObject *item = PySequence_GetItem(pylist,index); /* new ref */ + vec[index] = PyFloat_AsDouble(item); + Py_DECREF(item); } } else @@ -181,15 +187,18 @@ MT_Matrix4x4 MT_Matrix4x4FromPyObject(PyObject *pymat) unsigned int rows = PySequence_Size(pymat); for (unsigned int y = 0; y < rows && y < 4; y++) { - PyObject *pyrow = PySequence_GetItem(pymat, y); + PyObject *pyrow = PySequence_GetItem(pymat, y); /* new ref */ if (PySequence_Check(pyrow)) { unsigned int cols = PySequence_Size(pyrow); for( unsigned int x = 0; x < cols && x < 4; x++) { - mat[y][x] = PyFloat_AsDouble(PySequence_GetItem(pyrow, x)); + PyObject *item = PySequence_GetItem(pyrow, x); /* new ref */ + mat[y][x] = PyFloat_AsDouble(item); + Py_DECREF(item); } } + Py_DECREF(pyrow); } } @@ -206,15 +215,18 @@ MT_Matrix3x3 MT_Matrix3x3FromPyObject(PyObject *pymat) unsigned int rows = PySequence_Size(pymat); for (unsigned int y = 0; y < rows && y < 3; y++) { - PyObject *pyrow = PySequence_GetItem(pymat, y); + PyObject *pyrow = PySequence_GetItem(pymat, y); /* new ref */ if (PySequence_Check(pyrow)) { unsigned int cols = PySequence_Size(pyrow); for( unsigned int x = 0; x < cols && x < 3; x++) { - mat[y][x] = PyFloat_AsDouble(PySequence_GetItem(pyrow, x)); + PyObject *pyitem = PySequence_GetItem(pyrow, x); /* new ref */ + mat[y][x] = PyFloat_AsDouble(pyitem); + Py_DECREF(pyitem); } } + Py_DECREF(pyrow); } } @@ -223,16 +235,10 @@ MT_Matrix3x3 MT_Matrix3x3FromPyObject(PyObject *pymat) PyObject* PyObjectFromMT_Matrix4x4(const MT_Matrix4x4 &mat) { - PyObject *pymat = PyList_New(0); - for (unsigned int y = 0; y < 4; y++) - { - PyObject *row = PyList_New(0); - for( unsigned int x = 0; x < 4; x++ ) - { - PyList_Append(row, PyFloat_FromDouble(mat[y][x])); - } - PyList_Append(pymat, row); - } - return pymat; + return Py_BuildValue("[[ffff][ffff][ffff][ffff]]", + PyFloat_FromDouble(mat[0][0]), PyFloat_FromDouble(mat[0][1]), PyFloat_FromDouble(mat[0][2]), PyFloat_FromDouble(mat[0][3]), + PyFloat_FromDouble(mat[1][0]), PyFloat_FromDouble(mat[1][1]), PyFloat_FromDouble(mat[1][2]), PyFloat_FromDouble(mat[1][3]), + PyFloat_FromDouble(mat[2][0]), PyFloat_FromDouble(mat[2][1]), PyFloat_FromDouble(mat[2][2]), PyFloat_FromDouble(mat[2][3]), + PyFloat_FromDouble(mat[3][0]), PyFloat_FromDouble(mat[3][1]), PyFloat_FromDouble(mat[3][2]), PyFloat_FromDouble(mat[3][3])); } |