src/raytracermodule.cc
branchpyrit
changeset 31 b4e09433934a
parent 28 ffe83ca074f3
child 34 28f6e8b9d5d1
--- a/src/raytracermodule.cc	Sat Dec 08 16:02:37 2007 +0100
+++ b/src/raytracermodule.cc	Sun Dec 09 10:45:26 2007 +0100
@@ -104,6 +104,9 @@
 static PyObject *Material_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
 static void Material_Destructor(PyObject* self);
 static PyObject *Material_Getattr(PyObject *self, char *name);
+static PyObject *Material_setPhong(PyObject* self, PyObject* args);
+static PyObject *Material_setReflectivity(PyObject* self, PyObject* args);
+static PyObject *Material_setTransmissivity(PyObject* self, PyObject* args);
 
 static PyTypeObject MaterialType = {
 	PyObject_HEAD_INIT(NULL)
@@ -125,6 +128,9 @@
 };
 
 static PyMethodDef MaterialMethods[] = {
+	{"setPhong", (PyCFunction)Material_setPhong, METH_VARARGS, "Set ambient, diffuse, specular and shininess Phong model constants."},
+	{"setReflectivity", (PyCFunction)Material_setReflectivity, METH_VARARGS, "Set reflectivity."},
+	{"setTransmissivity", (PyCFunction)Material_setTransmissivity, METH_VARARGS, "Set transmissivity and refraction index."},
 	{NULL, NULL}
 };
 
@@ -159,6 +165,45 @@
 	return Py_FindMethod(MaterialMethods, self, name);
 }
 
+static PyObject *Material_setPhong(PyObject* self, PyObject* args)
+{
+	Float amb, dif, spec, shin = 0.5;
+
+	if (!PyArg_ParseTuple(args, "fff|f", &amb, &dif, &spec, &shin))
+		return NULL;
+
+	((MaterialObject *)self)->material->setPhong(amb, dif, spec, shin);
+
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+static PyObject *Material_setReflectivity(PyObject* self, PyObject* args)
+{
+	Float refl;
+
+	if (!PyArg_ParseTuple(args, "f", &refl))
+		return NULL;
+
+	((MaterialObject *)self)->material->setReflectivity(refl);
+
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+static PyObject *Material_setTransmissivity(PyObject* self, PyObject* args)
+{
+	Float trans, rindex = 1.3;
+
+	if (!PyArg_ParseTuple(args, "f|f", &trans, &rindex))
+		return NULL;
+
+	((MaterialObject *)self)->material->setTransmissivity(trans, rindex);
+
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
 //=========================== NormalVertex Object ===========================
 
 typedef struct {
@@ -555,7 +600,7 @@
 	if (!PyArg_ParseTuple(args, "(ii)", &w, &h))
 		return NULL;
 
-	printf("[pyrit] Raytracing...\n");
+	printf("[pyrit] Running ray tracer\n");
 	((RaytracerObject *)self)->raytracer->getTop()->optimize();
 	data = (Float *) malloc(w*h*3*sizeof(Float));
 	((RaytracerObject *)self)->raytracer->render(w, h, data);
@@ -565,7 +610,7 @@
 	}
 
 	// convert data to char
-	printf("[pyrit] Converting image data (float to char)...\n");
+	printf("[pyrit] Converting image data (float to char)\n");
 	chardata = (char *) malloc(w*h*3);
 	Float *d = data;
 	for (char *c = chardata; c != chardata + w*h*3; c++, d++) {