bugfix: #1206 Object.getBoundBox() was returning obdata coordinates.

fix memory leak in vector module.  Memory allocated by vector constructor
was not being freed.
This commit is contained in:
Stephen Swaney
2004-05-15 23:10:37 +00:00
parent 7b78a57c03
commit ae20f7a95e
3 changed files with 83 additions and 10 deletions

View File

@@ -914,6 +914,7 @@ static PyObject *Object_getType (BPy_Object *self)
}
}
static PyObject *Object_getBoundBox (BPy_Object *self)
{
int i;
@@ -924,7 +925,7 @@ static PyObject *Object_getBoundBox (BPy_Object *self)
return EXPP_ReturnPyObjError (PyExc_AttributeError,
"This object isn't linked to any object data (mesh, curve, etc) yet");
if (!self->object->bb) {
if (!self->object->bb) { /* if no ob bbox, we look in obdata */
Mesh *me;
Curve *curve;
switch (self->object->type) {
@@ -944,28 +945,84 @@ static PyObject *Object_getBoundBox (BPy_Object *self)
Py_INCREF (Py_None);
return Py_None;
}
{ /* transform our obdata bbox by the obmat.
the obmat is 4x4 homogeneous coords matrix.
each bbox coord is xyz, so we make it homogenous
by padding it with w=1.0 and doing the matrix mult.
afterwards we divide by w to get back to xyz.
*/
/* printmatrix4( "obmat", self->object->obmat); */
float tmpvec[4]; /* tmp vector for homogenous coords math */
int i;
float *from;
float *to;
bbox = PyList_New(8);
if (!bbox)
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create pylist");
for( i = 0, from = vec;
i < 8;
i++, from += 3 ) {
memcpy( tmpvec, from, 3*sizeof(float));
tmpvec[3]=1.0f; /* set w coord */
Mat4MulVec4fl( self->object->obmat, tmpvec );
/* divide x,y,z by w */
tmpvec[0] /= tmpvec[3];
tmpvec[1] /= tmpvec[3];
tmpvec[2] /= tmpvec[3];
#if 0
{ /* debug print stuff */
int i;
printf("\nobj bbox transformed\n");
for( i=0; i<4; ++i)
printf( "%f ", tmpvec[i]);
printf("\n");
}
#endif
/* because our bounding box is calculated and
does not have its own memory,
we must create vectors that allocate space */
vector = newVectorObject( NULL, 3);
memcpy( ((VectorObject*)vector)->vec,
tmpvec,
3*sizeof(float));
PyList_SET_ITEM(bbox, i, vector);
}
}
}
else vec = (float *)self->object->bb->vec;
else{ /* the ob bbox exists */
vec = (float *)self->object->bb->vec;
if (!vec)
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't retrieve bounding box data");
if (!vec)
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't retrieve bounding box data");
bbox = PyList_New(8);
bbox = PyList_New(8);
if (!bbox)
return EXPP_ReturnPyObjError (PyExc_MemoryError,
if (!bbox)
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create pylist");
for (i = 0; i < 8; i++) {
/* create vectors referencing object bounding box coords */
for (i = 0; i < 8; i++) {
vector = newVectorObject(vec, 3);
PyList_SET_ITEM(bbox, i, vector);
vec += 3;
}
}
return bbox;
}
static PyObject *Object_makeDisplayList (BPy_Object *self)
{
Object *ob = self->object;