formatting edits & minor corrections
This commit is contained in:
@@ -198,7 +198,7 @@ static PyObject *Euler_rotate_axis(EulerObject *self, PyObject *args)
|
|||||||
float angle = 0.0f;
|
float angle = 0.0f;
|
||||||
int axis; /* actually a character */
|
int axis; /* actually a character */
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "Cf:rotate", &axis, &angle)) {
|
if (!PyArg_ParseTuple(args, "Cf:rotate_axis", &axis, &angle)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"Euler.rotate_axis(): "
|
"Euler.rotate_axis(): "
|
||||||
"expected an axis 'X', 'Y', 'Z' and an angle (float)");
|
"expected an axis 'X', 'Y', 'Z' and an angle (float)");
|
||||||
|
@@ -432,13 +432,12 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
|
|||||||
const char *axis = NULL;
|
const char *axis = NULL;
|
||||||
int matSize;
|
int matSize;
|
||||||
double angle; /* use double because of precision problems at high values */
|
double angle; /* use double because of precision problems at high values */
|
||||||
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "di|O", &angle, &matSize, &vec)) {
|
if (!PyArg_ParseTuple(args, "di|O:Matrix.Rotation", &angle, &matSize, &vec)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
|
||||||
"Matrix.Rotation(angle, size, axis): "
|
|
||||||
"expected float int and a string or vector");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,8 +551,10 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
|
|||||||
float tvec[3];
|
float tvec[3];
|
||||||
float factor;
|
float factor;
|
||||||
int matSize;
|
int matSize;
|
||||||
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "fi|O:Matrix.Scale", &factor, &matSize, &vec)) {
|
if (!PyArg_ParseTuple(args, "fi|O:Matrix.Scale", &factor, &matSize, &vec)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -566,7 +567,9 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
|
|||||||
}
|
}
|
||||||
if (vec) {
|
if (vec) {
|
||||||
vec_size = (matSize == 2 ? 2 : 3);
|
vec_size = (matSize == 2 ? 2 : 3);
|
||||||
if (mathutils_array_parse(tvec, vec_size, vec_size, vec, "Matrix.Scale(factor, size, axis), invalid 'axis' arg") == -1) {
|
if (mathutils_array_parse(tvec, vec_size, vec_size, vec,
|
||||||
|
"Matrix.Scale(factor, size, axis), invalid 'axis' arg") == -1)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -638,8 +641,10 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
|
|||||||
|
|
||||||
int matSize, x;
|
int matSize, x;
|
||||||
float norm = 0.0f;
|
float norm = 0.0f;
|
||||||
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "Oi:Matrix.OrthoProjection", &axis, &matSize)) {
|
if (!PyArg_ParseTuple(args, "Oi:Matrix.OrthoProjection", &axis, &matSize)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -757,8 +762,10 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
|
|||||||
int matSize;
|
int matSize;
|
||||||
const char *plane;
|
const char *plane;
|
||||||
PyObject *fac;
|
PyObject *fac;
|
||||||
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "siO:Matrix.Shear", &plane, &matSize, &fac)) {
|
if (!PyArg_ParseTuple(args, "siO:Matrix.Shear", &plane, &matSize, &fac)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -1751,8 +1758,11 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
|
|||||||
/* parse each sub sequence */
|
/* parse each sub sequence */
|
||||||
PyObject *item = PySequence_Fast_GET_ITEM(value_fast, row - begin);
|
PyObject *item = PySequence_Fast_GET_ITEM(value_fast, row - begin);
|
||||||
|
|
||||||
if (mathutils_array_parse(vec, self->num_col, self->num_col, item, "matrix[begin:end] = value assignment") < 0)
|
if (mathutils_array_parse(vec, self->num_col, self->num_col, item,
|
||||||
|
"matrix[begin:end] = value assignment") < 0)
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
for (col = 0; col < self->num_col; col++) {
|
for (col = 0; col < self->num_col; col++) {
|
||||||
mat[col * self->num_row + row] = vec[col];
|
mat[col * self->num_row + row] = vec[col];
|
||||||
@@ -1866,7 +1876,7 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
|
|||||||
0.0f, 0.0f, 0.0f, 0.0f,
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 0.0f,
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 1.0f};
|
0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
double dot = 0.0f;
|
|
||||||
int col, row, item;
|
int col, row, item;
|
||||||
|
|
||||||
if (mat1->num_col != mat2->num_row) {
|
if (mat1->num_col != mat2->num_row) {
|
||||||
@@ -1878,11 +1888,11 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
|
|||||||
|
|
||||||
for (col = 0; col < mat2->num_col; col++) {
|
for (col = 0; col < mat2->num_col; col++) {
|
||||||
for (row = 0; row < mat1->num_row; row++) {
|
for (row = 0; row < mat1->num_row; row++) {
|
||||||
|
double dot = 0.0f;
|
||||||
for (item = 0; item < mat1->num_col; item++) {
|
for (item = 0; item < mat1->num_col; item++) {
|
||||||
dot += MATRIX_ITEM(mat1, row, item) * MATRIX_ITEM(mat2, item, col);
|
dot += MATRIX_ITEM(mat1, row, item) * MATRIX_ITEM(mat2, item, col);
|
||||||
}
|
}
|
||||||
mat[(col * mat1->num_row) + row] = (float)dot;
|
mat[(col * mat1->num_row) + row] = (float)dot;
|
||||||
dot = 0.0f;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2119,8 +2129,9 @@ static int Matrix_translation_set(MatrixObject *self, PyObject *value, void *UNU
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mathutils_array_parse(tvec, 3, 3, value, "Matrix.translation")) == -1)
|
if ((mathutils_array_parse(tvec, 3, 3, value, "Matrix.translation")) == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
copy_v3_v3(((float (*)[4])self->matrix)[3], tvec);
|
copy_v3_v3(((float (*)[4])self->matrix)[3], tvec);
|
||||||
|
|
||||||
|
@@ -194,8 +194,10 @@ static PyObject *Quaternion_cross(QuaternionObject *self, PyObject *value)
|
|||||||
if (BaseMath_ReadCallback(self) == -1)
|
if (BaseMath_ReadCallback(self) == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value, "Quaternion.cross(other), invalid 'other' arg") == -1)
|
if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value,
|
||||||
|
"Quaternion.cross(other), invalid 'other' arg") == -1) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
mul_qt_qtqt(quat, self->quat, tquat);
|
mul_qt_qtqt(quat, self->quat, tquat);
|
||||||
return Quaternion_CreatePyObject(quat, Py_NEW, Py_TYPE(self));
|
return Quaternion_CreatePyObject(quat, Py_NEW, Py_TYPE(self));
|
||||||
|
@@ -279,7 +279,9 @@ static PyObject *C_Vector_Repeat(PyObject *cls, PyObject *args)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((value_size = mathutils_array_parse_alloc(&iter_vec, 2, value, "Vector.Repeat(vector, size), invalid 'vector' arg")) == -1) {
|
if ((value_size = mathutils_array_parse_alloc(&iter_vec, 2, value,
|
||||||
|
"Vector.Repeat(vector, size), invalid 'vector' arg")) == -1)
|
||||||
|
{
|
||||||
PyMem_Free(iter_vec);
|
PyMem_Free(iter_vec);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1489,7 +1491,6 @@ static PyObject *Vector_isub(PyObject *v1, PyObject *v2)
|
|||||||
int column_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat)
|
int column_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat)
|
||||||
{
|
{
|
||||||
float vec_cpy[MAX_DIMENSIONS];
|
float vec_cpy[MAX_DIMENSIONS];
|
||||||
double dot = 0.0f;
|
|
||||||
int row, col, z = 0;
|
int row, col, z = 0;
|
||||||
|
|
||||||
if (mat->num_col != vec->size) {
|
if (mat->num_col != vec->size) {
|
||||||
@@ -1510,11 +1511,11 @@ int column_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec,
|
|||||||
r_vec[3] = 1.0f;
|
r_vec[3] = 1.0f;
|
||||||
|
|
||||||
for (row = 0; row < mat->num_row; row++) {
|
for (row = 0; row < mat->num_row; row++) {
|
||||||
|
double dot = 0.0f;
|
||||||
for (col = 0; col < mat->num_col; col++) {
|
for (col = 0; col < mat->num_col; col++) {
|
||||||
dot += (double)(MATRIX_ITEM(mat, row, col) * vec_cpy[col]);
|
dot += (double)(MATRIX_ITEM(mat, row, col) * vec_cpy[col]);
|
||||||
}
|
}
|
||||||
r_vec[z++] = (float)dot;
|
r_vec[z++] = (float)dot;
|
||||||
dot = 0.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2625,7 +2626,7 @@ if len(unique) != len(items):
|
|||||||
* [2][5][8]
|
* [2][5][8]
|
||||||
* [3][6][9]
|
* [3][6][9]
|
||||||
* vector/matrix multiplication IS NOT COMMUTATIVE!!!! */
|
* vector/matrix multiplication IS NOT COMMUTATIVE!!!! */
|
||||||
static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat)
|
static int row_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat)
|
||||||
{
|
{
|
||||||
float vec_cpy[MAX_DIMENSIONS];
|
float vec_cpy[MAX_DIMENSIONS];
|
||||||
int row, col, z = 0, vec_size = vec->size;
|
int row, col, z = 0, vec_size = vec->size;
|
||||||
@@ -2647,14 +2648,14 @@ static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *v
|
|||||||
|
|
||||||
memcpy(vec_cpy, vec->vec, vec_size * sizeof(float));
|
memcpy(vec_cpy, vec->vec, vec_size * sizeof(float));
|
||||||
|
|
||||||
rvec[3] = 1.0f;
|
r_vec[3] = 1.0f;
|
||||||
//muliplication
|
//muliplication
|
||||||
for (col = 0; col < mat->num_col; col++) {
|
for (col = 0; col < mat->num_col; col++) {
|
||||||
double dot = 0.0;
|
double dot = 0.0;
|
||||||
for (row = 0; row < mat->num_row; row++) {
|
for (row = 0; row < mat->num_row; row++) {
|
||||||
dot += MATRIX_ITEM(mat, row, col) * vec_cpy[row];
|
dot += MATRIX_ITEM(mat, row, col) * vec_cpy[row];
|
||||||
}
|
}
|
||||||
rvec[z++] = (float)dot;
|
r_vec[z++] = (float)dot;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user