1 %{
2 static void
convert_SbMat_array(PyObject * input,SbMat temp)3 convert_SbMat_array(PyObject * input, SbMat temp)
4 {
5 if (PySequence_Check(input) && (PySequence_Size(input) == 4) &&
6 (PySequence_Size(PySequence_GetItem(input, 0)) == 4) &&
7 (PySequence_Size(PySequence_GetItem(input, 1)) == 4) &&
8 (PySequence_Size(PySequence_GetItem(input, 2)) == 4) &&
9 (PySequence_Size(PySequence_GetItem(input, 3)) == 4)) {
10 int i,j;
11 for (i=0; i < 4; i++) {
12 for (j=0; j < 4; j++) {
13 PyObject * oij = PySequence_GetItem(PySequence_GetItem(input, i), j);
14 if (!PyNumber_Check(oij)) {
15 PyErr_SetString(PyExc_TypeError,
16 "sequence must contain 4 sequences where every sequence contains 4 floats");
17 PyErr_Print();
18 return;
19 }
20 temp[i][j] = PyFloat_AsDouble(oij);
21 Py_DECREF(oij);
22 }
23 }
24 } else {
25 PyErr_SetString(PyExc_TypeError,
26 "sequence must contain 4 sequences where every sequence contains 4 floats");
27 PyErr_Print();
28 }
29 }
30 %}
31
32 %typemap(in) SbMat & (SbMat temp) {
33 convert_SbMat_array($input, temp);
34 $1 = &temp;
35 }
36
37 %typemap(typecheck) SbMat & {
38 $1 = PySequence_Check($input) ? 1 : 0;
39 }
40
41 %typemap(out) SbMat & {
42 $result = Py_BuildValue("([ffff][ffff][ffff][ffff])",
43 (double)(*$1)[0][0],
44 (double)(*$1)[0][1],
45 (double)(*$1)[0][2],
46 (double)(*$1)[0][3],
47
48 (double)(*$1)[1][0],
49 (double)(*$1)[1][1],
50 (double)(*$1)[1][2],
51 (double)(*$1)[1][3],
52
53 (double)(*$1)[2][0],
54 (double)(*$1)[2][1],
55 (double)(*$1)[2][2],
56 (double)(*$1)[2][3],
57
58 (double)(*$1)[3][0],
59 (double)(*$1)[3][1],
60 (double)(*$1)[3][2],
61 (double)(*$1)[3][3]);
62 }
63
64 %ignore SbMatrix::getTransform(SbVec3f & translation, SbRotation & rotation,
65 SbVec3f & scaleFactor, SbRotation & scaleOrientation,
66 const SbVec3f & center) const;
67
68 %ignore SbMatrix::getTransform(SbVec3f & t, SbRotation & r, SbVec3f & s, SbRotation & so);
69
70 /* the next 2 typemaps handle the return value for e.g. multMatrixVec() */
71 %typemap(argout) SbVec3f & dst, SbVec4f & dst {
72 $result = SWIG_NewPointerObj((void *) $1, $1_descriptor, 1);
73 }
74 %typemap(in,numinputs=0) SbVec3f & dst, SbVec4f & dst {
75 $1 = new $1_basetype();
76 }
77
78 %extend SbMatrix {
getTransform()79 PyObject * getTransform() {
80 SbVec3f * t = new SbVec3f;
81 SbVec3f * s = new SbVec3f;
82 SbRotation * r = new SbRotation;
83 SbRotation * so = new SbRotation;
84
85 self->getTransform(*t, *r, *s, *so);
86
87 return Py_BuildValue("(OOOO)",
88 SWIG_NewPointerObj((void *)t, SWIGTYPE_p_SbVec3f, 1),
89 SWIG_NewPointerObj((void *)r, SWIGTYPE_p_SbRotation, 1),
90 SWIG_NewPointerObj((void *)s, SWIGTYPE_p_SbVec3f, 1),
91 SWIG_NewPointerObj((void *)so, SWIGTYPE_p_SbRotation, 1));
92 }
93
getTransform(SbVec3f & center)94 PyObject * getTransform(SbVec3f & center) {
95 SbVec3f * t = new SbVec3f;
96 SbVec3f * s = new SbVec3f;
97 SbRotation * r = new SbRotation;
98 SbRotation * so = new SbRotation;
99
100 self->getTransform(*t, *r, *s, *so, center);
101
102 return Py_BuildValue("(OOOO)",
103 SWIG_NewPointerObj((void *)t, SWIGTYPE_p_SbVec3f, 1),
104 SWIG_NewPointerObj((void *)r, SWIGTYPE_p_SbRotation, 1),
105 SWIG_NewPointerObj((void *)s, SWIGTYPE_p_SbVec3f, 1),
106 SWIG_NewPointerObj((void *)so, SWIGTYPE_p_SbRotation, 1));
107 }
108
109 /* add operator overloading methods instead of the global functions */
__mul__(const SbMatrix & u)110 SbMatrix __mul__(const SbMatrix & u) { return *self * u; }
__mul__(const SbVec3f & u)111 SbVec3f __mul__(const SbVec3f & u) { SbVec3f res; self->multMatrixVec(u, res); return res; }
__rmul__(const SbVec3f & u)112 SbVec3f __rmul__(const SbVec3f & u) { SbVec3f res; self->multVecMatrix(u, res); return res; }
__eq__(const SbMatrix & u)113 int __eq__(const SbMatrix & u) { return *self == u; }
__ne__(const SbMatrix & u)114 int __ne__(const SbMatrix & u) { return *self != u; }
__getitem__(int i)115 const float *__getitem__(int i) { return (self->getValue())[i]; }
116 }
117