src/raytracermodule.cc
branchpyrit
changeset 97 2a853d284a6a
parent 96 9eb71e76c7fd
child 98 64638385798a
equal deleted inserted replaced
96:9eb71e76c7fd 97:2a853d284a6a
   912 	Py_INCREF(Py_None);
   912 	Py_INCREF(Py_None);
   913 	return Py_None;
   913 	return Py_None;
   914 }
   914 }
   915 
   915 
   916 
   916 
       
   917 //=========================== Vertex Object (abstract) ===========================
       
   918 
       
   919 static void Vertex_Destructor(PyObject* self);
       
   920 
       
   921 static PyMethodDef VertexMethods[] = {
       
   922 	{NULL, NULL}
       
   923 };
       
   924 
       
   925 static PyTypeObject VertexType =
       
   926 TYPE_OBJECT(
       
   927 	"Vertex",                    /* tp_name */
       
   928 	sizeof(VertexObject),        /* tp_basicsize */
       
   929 	Vertex_Destructor,           /* tp_dealloc */
       
   930 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,  /* tp_flags */
       
   931 	"Vertex type (abstract)",    /* tp_doc */
       
   932 	VertexMethods,               /* tp_methods */
       
   933 	0,                           /* tp_members */
       
   934 	0,                           /* tp_base */
       
   935 	0                            /* tp_init */
       
   936 );
       
   937 
       
   938 static void Vertex_Destructor(PyObject* self)
       
   939 {
       
   940 	delete ((VertexObject *)self)->vertex;
       
   941 	self->ob_type->tp_free(self);
       
   942 }
       
   943 
       
   944 
   917 //=========================== NormalVertex Object ===========================
   945 //=========================== NormalVertex Object ===========================
   918 
   946 
   919 static PyObject *NormalVertex_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
   947 static PyObject *NormalVertex_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
   920 static void NormalVertex_Destructor(PyObject* self);
       
   921 static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args);
   948 static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args);
   922 
   949 
   923 static PyMethodDef NormalVertexMethods[] = {
   950 static PyMethodDef NormalVertexMethods[] = {
   924 	{"setNormal", (PyCFunction)NormalVertex_setNormal, METH_VARARGS, "Set normal of this vertex."},
   951 	{"setNormal", (PyCFunction)NormalVertex_setNormal, METH_VARARGS, "Set normal of this vertex."},
   925 	{NULL, NULL}
   952 	{NULL, NULL}
   927 
   954 
   928 static PyTypeObject NormalVertexType =
   955 static PyTypeObject NormalVertexType =
   929 TYPE_OBJECT(
   956 TYPE_OBJECT(
   930 	"NormalVertex",                    /* tp_name */
   957 	"NormalVertex",                    /* tp_name */
   931 	sizeof(NormalVertexObject),        /* tp_basicsize */
   958 	sizeof(NormalVertexObject),        /* tp_basicsize */
   932 	NormalVertex_Destructor,           /* tp_dealloc */
   959 	0,                                 /* tp_dealloc */
   933 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,  /* tp_flags */
   960 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,  /* tp_flags */
   934 	"NormalVertex type",               /* tp_doc */
   961 	"NormalVertex type",               /* tp_doc */
   935 	NormalVertexMethods,               /* tp_methods */
   962 	NormalVertexMethods,               /* tp_methods */
   936 	0,                                 /* tp_members */
   963 	0,                                 /* tp_members */
   937 	0,                                 /* tp_base */
   964 	&VertexType,                       /* tp_base */
   938 	0                                  /* tp_init */
   965 	0                                  /* tp_init */
   939 );
   966 );
   940 
   967 
   941 static PyObject* NormalVertex_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
   968 static PyObject* NormalVertex_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
   942 {
   969 {
   951 		return NULL;
   978 		return NULL;
   952 
   979 
   953 	if (!TNor && TVer->ob_type == &NormalVertexType)
   980 	if (!TNor && TVer->ob_type == &NormalVertexType)
   954 	{
   981 	{
   955 		v = PyObject_New(NormalVertexObject, &NormalVertexType);
   982 		v = PyObject_New(NormalVertexObject, &NormalVertexType);
   956 		v->nvertex = new NormalVertex(((NormalVertexObject*)TVer)->nvertex);
   983 		v->vertex.vertex = new NormalVertex((NormalVertex*)((NormalVertexObject*)TVer)->vertex.vertex);
   957 	}
   984 	}
   958 	else
   985 	else
   959 	{
   986 	{
   960 		if (!PyArg_ParseTuple(TVer, "fff", &vx, &vy, &vz))
   987 		if (!PyArg_ParseTuple(TVer, "fff", &vx, &vy, &vz))
   961 			return NULL;
   988 			return NULL;
   963 		if (TNor)
   990 		if (TNor)
   964 			if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
   991 			if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
   965 				return NULL;
   992 				return NULL;
   966 
   993 
   967 		v = PyObject_New(NormalVertexObject, &NormalVertexType);
   994 		v = PyObject_New(NormalVertexObject, &NormalVertexType);
   968 		v->nvertex = new NormalVertex(Vector(vx, vy, vz), Vector(nx, ny, nz));
   995 		v->vertex.vertex = new NormalVertex(Vector(vx, vy, vz), Vector(nx, ny, nz));
   969 	}
   996 	}
   970 	return (PyObject*)v;
   997 	return (PyObject*)v;
   971 }
       
   972 
       
   973 static void NormalVertex_Destructor(PyObject* self)
       
   974 {
       
   975 	delete ((NormalVertexObject *)self)->nvertex;
       
   976 	self->ob_type->tp_free(self);
       
   977 }
   998 }
   978 
   999 
   979 static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args)
  1000 static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args)
   980 {
  1001 {
   981 	PyObject *TNor = NULL;
  1002 	PyObject *TNor = NULL;
   985 		return NULL;
  1006 		return NULL;
   986 
  1007 
   987 	if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
  1008 	if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
   988 		return NULL;
  1009 		return NULL;
   989 
  1010 
   990 	((NormalVertexObject *)self)->nvertex->setNormal(Vector(nx,ny,nz).normalize());
  1011 	((NormalVertex*)((VertexObject *)self)->vertex)->setNormal(Vector(nx,ny,nz).normalize());
   991 
  1012 
   992 	Py_INCREF(Py_None);
  1013 	Py_INCREF(Py_None);
   993 	return Py_None;
  1014 	return Py_None;
   994 }
  1015 }
   995 
  1016 
  1046 static PyObject* Triangle_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
  1067 static PyObject* Triangle_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
  1047 {
  1068 {
  1048 	TriangleObject *v;
  1069 	TriangleObject *v;
  1049 	MaterialObject *material;
  1070 	MaterialObject *material;
  1050 	static char *kwdlist[] = {"A", "B", "C", "material", NULL};
  1071 	static char *kwdlist[] = {"A", "B", "C", "material", NULL};
  1051 	NormalVertexObject *A, *B, *C;
  1072 	VertexObject *A, *B, *C;
  1052 
  1073 
  1053 	if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!O!O!O!", kwdlist,
  1074 	if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!O!O!O!", kwdlist,
  1054 		&NormalVertexType, &A, &NormalVertexType, &B, &NormalVertexType, &C,
  1075 		&VertexType, &A, &VertexType, &B, &VertexType, &C,
  1055 		&MaterialType, &material))
  1076 		&MaterialType, &material))
  1056 		return NULL;
  1077 		return NULL;
  1057 
  1078 
  1058 	v = PyObject_New(TriangleObject, &TriangleType);
  1079 	v = PyObject_New(TriangleObject, &TriangleType);
  1059 	v->shape.shape = new Triangle(A->nvertex, B->nvertex, C->nvertex, material->material);
  1080 	v->shape.shape = new Triangle(A->vertex, B->vertex, C->vertex, material->material);
  1060 	Py_INCREF(material);
  1081 	Py_INCREF(material);
  1061 	Py_INCREF(A);
  1082 	Py_INCREF(A);
  1062 	Py_INCREF(B);
  1083 	Py_INCREF(B);
  1063 	Py_INCREF(C);
  1084 	Py_INCREF(C);
  1064 	return (PyObject*)v;
  1085 	return (PyObject*)v;
  1603 
  1624 
  1604 	if (PyType_Ready(&RaytracerType) < 0
  1625 	if (PyType_Ready(&RaytracerType) < 0
  1605 	|| PyType_Ready(&LightType) < 0
  1626 	|| PyType_Ready(&LightType) < 0
  1606 	|| PyType_Ready(&CameraType) < 0
  1627 	|| PyType_Ready(&CameraType) < 0
  1607 	|| PyType_Ready(&MaterialType) < 0
  1628 	|| PyType_Ready(&MaterialType) < 0
       
  1629 	|| PyType_Ready(&VertexType) < 0
  1608 	|| PyType_Ready(&NormalVertexType) < 0
  1630 	|| PyType_Ready(&NormalVertexType) < 0
  1609 	|| PyType_Ready(&ShapeType) < 0
  1631 	|| PyType_Ready(&ShapeType) < 0
  1610 	|| PyType_Ready(&TriangleType) < 0
  1632 	|| PyType_Ready(&TriangleType) < 0
  1611 	|| PyType_Ready(&SphereType) < 0
  1633 	|| PyType_Ready(&SphereType) < 0
  1612 	|| PyType_Ready(&BoxType) < 0
  1634 	|| PyType_Ready(&BoxType) < 0