BGE Python API
- initialize pythons sys.argv in the blenderplayer - ignore all arguments after a single " - " in the blenderplayer (like in blender), so args can be passed to the game. - add a utility function PyOrientationTo() - to take a Py euler, quat or 3x3 matrix and convert into a C++ MT_Matrix3x3. - add utility function ConvertPythonToMesh to get a RAS_MeshObject from a KX_MeshProxy or a name. - Added error prefix arguments to ConvertPythonToGameObject, ConvertPythonToMesh and PyOrientationTo so the error messages can include what function they came from. - deprecated brick.getOwner() for the "owner" attribute.
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
#include "ListValue.h"
|
||||
|
||||
#include "KX_Python.h"
|
||||
#include "KX_PyMath.h"
|
||||
|
||||
bool PyObject_IsMT_Matrix(PyObject *pymat, unsigned int rank)
|
||||
{
|
||||
@@ -74,6 +75,39 @@ bool PyObject_IsMT_Matrix(PyObject *pymat, unsigned int rank)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PyOrientationTo(PyObject* pyval, MT_Matrix3x3 &mat, const char *error_prefix)
|
||||
{
|
||||
MT_Matrix3x3 rot;
|
||||
int size= PySequence_Size(pyval);
|
||||
|
||||
if (size == 4)
|
||||
{
|
||||
MT_Quaternion qrot;
|
||||
if (PyVecTo(pyval, qrot))
|
||||
{
|
||||
rot.setRotation(qrot);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (size == 3) {
|
||||
/* 3x3 matrix or euler */
|
||||
MT_Vector3 erot;
|
||||
if (PyVecTo(pyval, erot))
|
||||
{
|
||||
rot.setEuler(erot);
|
||||
return true;
|
||||
}
|
||||
PyErr_Clear();
|
||||
|
||||
if (PyMatTo(pyval, rot))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "%s, could not set the orientation from a 3x3 matrix, quaternion or euler sequence", error_prefix);
|
||||
return false;
|
||||
}
|
||||
|
||||
PyObject* PyObjectFrom(const MT_Matrix4x4 &mat)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user