Camera matrix problems in 2.26

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

jmerritt
Posts: 10
Joined: Sat Feb 15, 2003 2:37 am

Camera matrix problems in 2.26

Postby jmerritt » Sun May 04, 2003 7:30 am

Hi Everyone,

I've been trying to access the inverse camera transform matrix from within Blender 2.26. On both Linux and Windows platforms, the following script:

Code: Select all

from Blender import *

scene = Scene.getCurrent()
camera = scene.getCurrentCamera()
imatrix = camera.getInverseMatrix()

print imatrix
print imatrix[0]
print imatrix[1]
print imatrix[2]
print imatrix[3]


gives the following results (in the console):

Code: Select all

((9.9419775405734622e+033, 1.0065780829052295e+034, 1.0032974180071193e+034, -1.
#QNAN), (0.0, 0.0, 7.8967025252677283e+033, 1.9190860941642372e-038), (2.5783891
743576634e-043, 1.9273616023751538e-038, 7.834125275251872e+033, -1.#QNAN), (1.2
235017151712843e-040, 7.89685541086258e+033, 1.7433498142726476e-039, 7.89688202
65734247e+033))
[9.9419775405734622e+033, 1.9273548761425251e-038, 9.9419366885521658e+033, 1.60
73891110312251e-038]
[9.9419540197127158e+033, 1.6108531208350361e-038, 1.9273559971812965e-038, 4.20
38953929744512e-045]
[7.0064923216240854e-045, 5.6051938572992683e-044, 1.9273582392588395e-038, 1.92
73559971812965e-038]
[0.0, 0.0, 0.0, 4.2038953929744512e-045]


Sorry if that's a bit messy! :?

Anyway, as you can see, each row vector from the matrix appears different when accessed via the sequence operator than they do when dumped via print.

What's going on here? Is there something I'm doing wrong? The source code for this looks vaguely correct (I'm looking at the file: opy_matrix.c), so is there something subtle happening (perhaps a reference counting issue)?

Jonathan Merritt.

PS - Where do I find out about Python development within Blender. I'm finding it really difficult to locate anything!!! :(

alien-xmp
Posts: 217
Joined: Sun Apr 06, 2003 2:22 pm
Location: Wellington, New Zealand
Contact:

Postby alien-xmp » Mon May 05, 2003 1:41 am

Definately broken...

The returned matrix object contains a pointer to float inverse[4][4] which is only valid inside Object_getInverseMatrix.

inverse has to be allocated memory (and freed when finished) for this to work.

Code: Select all

static PyObject *Object_getInverseMatrix(PyObject *self, PyObject *args)
{
   Object *ob= PYBLOCK_AS_OBJECT(self);
   float inverse[4][4];                          // <- *******************
   Mat4Invert(inverse, ob->obmat);
   return newMatrixObject(inverse);
}


Code: Select all

PyObject *newMatrixObject(Matrix4Ptr mat) {
   MatrixObject *self;

   self= PyObject_NEW(MatrixObject, &Matrix_Type);
   self->mat= mat;              // <- **************************

   BPY_TRY(self->rows[0]= newVectorObject(GETROWVECTOR(self->mat, 0), 4));
   BPY_TRY(self->rows[1]= newVectorObject(GETROWVECTOR(self->mat, 1), 4));
   BPY_TRY(self->rows[2]= newVectorObject(GETROWVECTOR(self->mat, 2), 4));
   BPY_TRY(self->rows[3]= newVectorObject(GETROWVECTOR(self->mat, 3), 4));

   return (PyObject*) self;
}

jmerritt
Posts: 10
Joined: Sat Feb 15, 2003 2:37 am

Python Development

Postby jmerritt » Mon May 05, 2003 5:19 am

Thanks for confirming that issue (and the full explanation! 8) ). I have since evaded the problem by accessing the non-inverted matrix and inverting it myself.

Can somebody tell me where the current Python development is being discussed? Is there a website with bits-and-pieces, a mailing list, etc? I'm subscribed to bf-committers, but there doesn't seem to have been any Python discussion for the last week or so. Is that the right place? I'd be much more motivated to try to solve problems like this if I knew that my efforts were actually focused on "current" code, and were going to be committed...

Thanks, :)

Michel
Posts: 208
Joined: Wed Oct 16, 2002 7:27 pm
Location: Somewhere below the rivers in Holland (but not Limburg)

Re: Python Development

Postby Michel » Mon May 05, 2003 9:03 am

jmerritt wrote:Can somebody tell me where the current Python development is being discussed? Is there a website with bits-and-pieces, a mailing list, etc? I'm subscribed to bf-committers, but there doesn't seem to have been any Python discussion for the last week or so. Is that the right place? I'd be much more motivated to try to solve problems like this if I knew that my efforts were actually focused on "current" code, and were going to be committed...

Thanks, :)


Hi,

Python development is being discussed at the bf-committers list. And, if there's no discussion for a week, then that doesn't necessarilly mean that we're not active :twisted:

Anyway, our current work is in the new API implementation. Ofcourse, any bugs found in the current implementation - that will still be active for 2.27 - is important. So feel free to submit a patch or discuss this at the mailing list.

With regards,
Michel


Return to “Python”

Who is online

Users browsing this forum: No registered users and 0 guests