예제 #1
0
//----------------------------------mathutils.Euler() -------------------
//makes a new euler for you to play with
static PyObject *Euler_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
	PyObject *seq= NULL;
	const char *order_str= NULL;

	float eul[EULER_SIZE]= {0.0f, 0.0f, 0.0f};
	short order= EULER_ORDER_XYZ;

	if(kwds && PyDict_Size(kwds)) {
		PyErr_SetString(PyExc_TypeError, "mathutils.Euler(): takes no keyword args");
		return NULL;
	}

	if(!PyArg_ParseTuple(args, "|Os:mathutils.Euler", &seq, &order_str))
		return NULL;

	switch(PyTuple_GET_SIZE(args)) {
	case 0:
		break;
	case 2:
		if((order=euler_order_from_string(order_str, "mathutils.Euler()")) == -1)
			return NULL;
		/* intentionally pass through */
	case 1:
		if (mathutils_array_parse(eul, EULER_SIZE, EULER_SIZE, seq, "mathutils.Euler()") == -1)
			return NULL;
		break;
	}
	return newEulerObject(eul, order, Py_NEW, type);
}
예제 #2
0
static int Euler_setOrder(EulerObject *self, PyObject *value, void *UNUSED(closure))
{
	const char *order_str= _PyUnicode_AsString(value);
	short order= euler_order_from_string(order_str, "euler.order");

	if(order == -1)
		return -1;

	self->order= order;
	(void)BaseMath_WriteCallback(self); /* order can be written back */
	return 0;
}
예제 #3
0
static PyObject *Quaternion_to_euler(QuaternionObject *self, PyObject *args)
{
	float tquat[4];
	float eul[3];
	const char *order_str = NULL;
	short order = EULER_ORDER_XYZ;
	EulerObject *eul_compat = NULL;

	if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat))
		return NULL;

	if (BaseMath_ReadCallback(self) == -1)
		return NULL;

	if (order_str) {
		order = euler_order_from_string(order_str, "Matrix.to_euler()");

		if (order == -1)
			return NULL;
	}

	normalize_qt_qt(tquat, self->quat);

	if (eul_compat) {
		float mat[3][3];

		if (BaseMath_ReadCallback(eul_compat) == -1)
			return NULL;

		quat_to_mat3(mat, tquat);

		if (order == EULER_ORDER_XYZ)  mat3_to_compatible_eul(eul, eul_compat->eul, mat);
		else                           mat3_to_compatible_eulO(eul, eul_compat->eul, order, mat);
	}
	else {
		if (order == EULER_ORDER_XYZ)  quat_to_eul(eul, tquat);
		else                           quat_to_eulO(eul, order, tquat);
	}

	return Euler_CreatePyObject(eul, order, Py_NEW, NULL);
}