diff -r 9eb71e76c7fd -r 2a853d284a6a src/raytracermodule.cc --- a/src/raytracermodule.cc Thu May 15 00:07:25 2008 +0200 +++ b/src/raytracermodule.cc Thu May 15 19:15:57 2008 +0200 @@ -914,10 +914,37 @@ } +//=========================== Vertex Object (abstract) =========================== + +static void Vertex_Destructor(PyObject* self); + +static PyMethodDef VertexMethods[] = { + {NULL, NULL} +}; + +static PyTypeObject VertexType = +TYPE_OBJECT( + "Vertex", /* tp_name */ + sizeof(VertexObject), /* tp_basicsize */ + Vertex_Destructor, /* tp_dealloc */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Vertex type (abstract)", /* tp_doc */ + VertexMethods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_base */ + 0 /* tp_init */ +); + +static void Vertex_Destructor(PyObject* self) +{ + delete ((VertexObject *)self)->vertex; + self->ob_type->tp_free(self); +} + + //=========================== NormalVertex Object =========================== static PyObject *NormalVertex_Constructor(PyObject* self, PyObject* args, PyObject *kwd); -static void NormalVertex_Destructor(PyObject* self); static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args); static PyMethodDef NormalVertexMethods[] = { @@ -929,12 +956,12 @@ TYPE_OBJECT( "NormalVertex", /* tp_name */ sizeof(NormalVertexObject), /* tp_basicsize */ - NormalVertex_Destructor, /* tp_dealloc */ + 0, /* tp_dealloc */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ "NormalVertex type", /* tp_doc */ NormalVertexMethods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_base */ + &VertexType, /* tp_base */ 0 /* tp_init */ ); @@ -953,7 +980,7 @@ if (!TNor && TVer->ob_type == &NormalVertexType) { v = PyObject_New(NormalVertexObject, &NormalVertexType); - v->nvertex = new NormalVertex(((NormalVertexObject*)TVer)->nvertex); + v->vertex.vertex = new NormalVertex((NormalVertex*)((NormalVertexObject*)TVer)->vertex.vertex); } else { @@ -965,17 +992,11 @@ return NULL; v = PyObject_New(NormalVertexObject, &NormalVertexType); - v->nvertex = new NormalVertex(Vector(vx, vy, vz), Vector(nx, ny, nz)); + v->vertex.vertex = new NormalVertex(Vector(vx, vy, vz), Vector(nx, ny, nz)); } return (PyObject*)v; } -static void NormalVertex_Destructor(PyObject* self) -{ - delete ((NormalVertexObject *)self)->nvertex; - self->ob_type->tp_free(self); -} - static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args) { PyObject *TNor = NULL; @@ -987,7 +1008,7 @@ if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz)) return NULL; - ((NormalVertexObject *)self)->nvertex->setNormal(Vector(nx,ny,nz).normalize()); + ((NormalVertex*)((VertexObject *)self)->vertex)->setNormal(Vector(nx,ny,nz).normalize()); Py_INCREF(Py_None); return Py_None; @@ -1048,15 +1069,15 @@ TriangleObject *v; MaterialObject *material; static char *kwdlist[] = {"A", "B", "C", "material", NULL}; - NormalVertexObject *A, *B, *C; + VertexObject *A, *B, *C; if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!O!O!O!", kwdlist, - &NormalVertexType, &A, &NormalVertexType, &B, &NormalVertexType, &C, + &VertexType, &A, &VertexType, &B, &VertexType, &C, &MaterialType, &material)) return NULL; v = PyObject_New(TriangleObject, &TriangleType); - v->shape.shape = new Triangle(A->nvertex, B->nvertex, C->nvertex, material->material); + v->shape.shape = new Triangle(A->vertex, B->vertex, C->vertex, material->material); Py_INCREF(material); Py_INCREF(A); Py_INCREF(B); @@ -1605,6 +1626,7 @@ || PyType_Ready(&LightType) < 0 || PyType_Ready(&CameraType) < 0 || PyType_Ready(&MaterialType) < 0 + || PyType_Ready(&VertexType) < 0 || PyType_Ready(&NormalVertexType) < 0 || PyType_Ready(&ShapeType) < 0 || PyType_Ready(&TriangleType) < 0