src/raytracermodule.cc
branchpyrit
changeset 72 7c3f38dff082
parent 69 303583d2fb97
child 75 20dee9819b17
--- a/src/raytracermodule.cc	Sat Apr 19 18:00:27 2008 +0200
+++ b/src/raytracermodule.cc	Sun Apr 20 16:48:24 2008 +0200
@@ -73,7 +73,7 @@
 	static char *kwdlist[] = {"position", "colour", NULL};
 	PyObject *TPos, *TCol = NULL;
 	Float px, py, pz;
-	Float cr = 1.0, cg = 1.0, cb = 1.0;
+	Float cr = 0.9, cg = 0.9, cb = 0.9;
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!|O!", kwdlist,
 		&PyTuple_Type, &TPos, &PyTuple_Type, &TCol))
@@ -124,6 +124,7 @@
 static void Camera_Destructor(PyObject* self);
 static PyObject *Camera_Getattr(PyObject *self, char *name);
 static PyObject *Camera_setEye(PyObject* self, PyObject* args);
+static PyObject *Camera_setAngle(PyObject* self, PyObject* args);
 static PyObject *Camera_rotate(PyObject* self, PyObject* args);
 
 static PyTypeObject CameraType = {
@@ -147,6 +148,7 @@
 
 static PyMethodDef CameraMethods[] = {
 	{"setEye", (PyCFunction)Camera_setEye, METH_VARARGS, "Set eye of the camera."},
+	{"setAngle", (PyCFunction)Camera_setAngle, METH_VARARGS, "Set vertical angle of view."},
 	{"rotate", (PyCFunction)Camera_rotate, METH_VARARGS, "Rotate camera with a quaternion."},
 	{NULL, NULL}
 };
@@ -154,21 +156,33 @@
 static PyObject* Camera_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
 {
 	CameraObject *v;
-	static char *kwdlist[] = {"eye", "p", "u", "v", NULL};
-	PyObject *TEye = NULL, *Tp = NULL, *Tu = NULL, *Tv = NULL;
+	static char *kwdlist[] = {"eye", "lookat", "up", "p", "u", "v", NULL};
+	PyObject *TEye = NULL, *TLookAt = NULL, *TUp = NULL,
+		*Tp = NULL, *Tu = NULL, *Tv = NULL;
 	Float ex=0.0,  ey=0.0, ez=10.0;
+	Float lax=0.0, lay=0.0, laz=0.0;
+	Float upx=0.0, upy=1.0, upz=0.0;
 	Float px=0.0,  py=0.0, pz=-1.0;
 	Float ux=-1.0, uy=0.0, uz=0.0;
 	Float vx=0.0,  vy=1.0, vz=0.0;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwd, "|O!O!O!O!", kwdlist,
-		&PyTuple_Type, &TEye, &PyTuple_Type, &Tp, &PyTuple_Type, &Tu, &PyTuple_Type, &Tv))
+	if (!PyArg_ParseTupleAndKeywords(args, kwd, "|O!O!O!O!O!O!", kwdlist,
+		&PyTuple_Type, &TEye, &PyTuple_Type, &TLookAt, &PyTuple_Type, &TUp,
+		&PyTuple_Type, &Tp, &PyTuple_Type, &Tu, &PyTuple_Type, &Tv))
 		return NULL;
 
 	if (TEye)
 		if (!PyArg_ParseTuple(TEye, "fff", &ex, &ey, &ez))
 			return NULL;
 
+	if (TLookAt)
+		if (!PyArg_ParseTuple(TLookAt, "fff", &lax, &lay, &laz))
+			return NULL;
+
+	if (TUp)
+		if (!PyArg_ParseTuple(TUp, "fff", &upx, &upy, &upz))
+			return NULL;
+
 	if (Tp)
 		if (!PyArg_ParseTuple(Tp, "fff", &px, &py, &pz))
 			return NULL;
@@ -182,8 +196,12 @@
 			return NULL;
 
 	v = PyObject_New(CameraObject, &CameraType);
-	v->camera = new Camera(Vector3(ex, ey, ez),
-		Vector3(px, py, pz), Vector3(ux, uy, uz), Vector3(vx, vy, vz));
+	if (TLookAt)
+		v->camera = new Camera(Vector3(ex, ey, ez),
+			Vector3(lax, lay, laz), Vector3(upx, upy, upz));
+	else
+		v->camera = new Camera(Vector3(ex, ey, ez),
+			Vector3(px, py, pz), Vector3(ux, uy, uz), Vector3(vx, vy, vz));
 	return (PyObject*)v;
 }
 
@@ -217,6 +235,19 @@
 	return Py_None;
 }
 
+static PyObject *Camera_setAngle(PyObject* self, PyObject* args)
+{
+	Float angle;
+
+	if (!PyArg_ParseTuple(args, "f", &angle))
+		return NULL;
+
+	((CameraObject *)self)->camera->setAngle(angle);
+
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
 static PyObject *Camera_rotate(PyObject* self, PyObject* args)
 {
 	PyObject *Tq = NULL;
@@ -684,6 +715,7 @@
 static PyObject *Raytracer_Getattr(PyObject *self, char *name);
 static PyObject *Raytracer_render(PyObject* self, PyObject* args);
 static PyObject *Raytracer_setcamera(PyObject* self, PyObject* args);
+static PyObject *Raytracer_setbgcolour(PyObject* self, PyObject* args);
 static PyObject *Raytracer_addshape(PyObject* self, PyObject* args);
 static PyObject *Raytracer_addlight(PyObject* self, PyObject* args);
 static PyObject *Raytracer_ambientocclusion(PyObject* self, PyObject* args, PyObject *kwd);
@@ -710,6 +742,7 @@
 static PyMethodDef RaytracerMethods[] = {
 	{"render", (PyCFunction)Raytracer_render, METH_VARARGS, "Render scene and return image data."},
 	{"setcamera", (PyCFunction)Raytracer_setcamera, METH_VARARGS, "Set camera for the scene."},
+	{"setbgcolour", (PyCFunction)Raytracer_setbgcolour, METH_VARARGS, "Set background colour."},
 	{"addshape", (PyCFunction)Raytracer_addshape, METH_VARARGS, "Add new shape to scene."},
 	{"addlight", (PyCFunction)Raytracer_addlight, METH_VARARGS, "Add new light source to scene."},
 	{"ambientocclusion", (PyCFunction)Raytracer_ambientocclusion, METH_VARARGS | METH_KEYWORDS,
@@ -800,6 +833,19 @@
 	return Py_None;
 }
 
+static PyObject* Raytracer_setbgcolour(PyObject* self, PyObject* args)
+{
+	Float r,g,b;
+
+	if (!PyArg_ParseTuple(args, "(fff)", &r, &g, &b))
+		return NULL;
+
+	((RaytracerObject *)self)->raytracer->setBgColour(Colour(r,g,b));
+
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
 static PyObject* Raytracer_addshape(PyObject* self, PyObject* args)
 {
 	PyObject *obj;
@@ -807,7 +853,7 @@
 	if (!PyArg_ParseTuple(args, "O", &obj))
 		return NULL;
 
-	((RaytracerObject *)self)->raytracer->addshape(
+	((RaytracerObject *)self)->raytracer->addShape(
 		((BoxObject*)obj)->shape);
 
 	((RaytracerObject *)self)->children->push_back(obj);
@@ -822,7 +868,7 @@
 
 	if (!PyArg_ParseTuple(args, "O!", &LightType, &lightobj))
 		return NULL;
-	((RaytracerObject *)self)->raytracer->addlight(lightobj->light);
+	((RaytracerObject *)self)->raytracer->addLight(lightobj->light);
 	((RaytracerObject *)self)->children->push_back((PyObject*)lightobj);
 	Py_INCREF(lightobj);
 	Py_INCREF(Py_None);