summaryrefslogtreecommitdiffstats
path: root/libdimension-python/Scene.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-05-22 14:22:07 -0600
committerTavian Barnes <tavianator@gmail.com>2011-05-22 14:22:07 -0600
commit1bf306d4d93cc21c220a3f31835023e49e84dd2d (patch)
tree436959a8321100a3c36e8eef9a19279cb446e1fa /libdimension-python/Scene.c
parent0f0b704144bddc045657f7ed852b49d5e349b0bd (diff)
downloaddimension-1bf306d4d93cc21c220a3f31835023e49e84dd2d.tar.xz
Add cameras, objects, and spheres to Python module.
Diffstat (limited to 'libdimension-python/Scene.c')
-rw-r--r--libdimension-python/Scene.c59
1 files changed, 52 insertions, 7 deletions
diff --git a/libdimension-python/Scene.c b/libdimension-python/Scene.c
index 29a623a..0e43ec9 100644
--- a/libdimension-python/Scene.c
+++ b/libdimension-python/Scene.c
@@ -18,22 +18,57 @@
* <http://www.gnu.org/licenses/>. *
*************************************************************************/
-#include "Canvas.h"
-#include "Scene.h"
+#include "dimension-python.h"
static int
dmnsn_py_Scene_init(dmnsn_py_Scene *self, PyObject *args, PyObject *kwds)
{
- static char *kwlist[] = { "canvas", NULL };
+ dmnsn_delete_scene(self->scene);
+ self->scene = dmnsn_new_scene();
+
+ static char *kwlist[] = { "canvas", "camera", "objects", NULL };
dmnsn_py_Canvas *canvas;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", kwlist,
- &dmnsn_py_CanvasType, &canvas))
+ dmnsn_py_Camera *camera;
+ PyObject *objects;
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", kwlist,
+ &dmnsn_py_CanvasType, &canvas,
+ &dmnsn_py_CameraType, &camera,
+ &PyList_Type, &objects))
return -1;
- dmnsn_delete_scene(self->scene);
- self->scene = dmnsn_new_scene();
dmnsn_scene_set_canvas(self->scene, canvas->canvas);
+
+ if (!PyObject_CallMethod((PyObject *)camera, "initialize", ""))
+ return -1;
+
+ /* Account for image proportions in camera */
+ dmnsn_matrix stretch = dmnsn_scale_matrix(
+ dmnsn_new_vector(
+ (double)canvas->canvas->width/canvas->canvas->height,
+ 1.0,
+ 1.0
+ )
+ );
+ camera->camera->trans = dmnsn_matrix_mul(camera->camera->trans, stretch);
+ dmnsn_scene_set_camera(self->scene, camera->camera);
+ self->scene->background = dmnsn_white;
+
+ Py_ssize_t size = PyList_Size(objects);
+ for (Py_ssize_t i = 0; i < size; ++i) {
+ PyObject *obj = PyList_GetItem(objects, i);
+ if (!PyObject_TypeCheck(obj, &dmnsn_py_ObjectType)) {
+ PyErr_SetString(PyExc_TypeError, "Expected a list of objects");
+ return -1;
+ }
+
+ if (!PyObject_CallMethod(obj, "initialize", ""))
+ return -1;
+
+ dmnsn_py_Object *object = (dmnsn_py_Object *)obj;
+ dmnsn_scene_add_object(self->scene, object->object);
+ }
+
return 0;
}
@@ -44,7 +79,17 @@ dmnsn_py_Scene_dealloc(dmnsn_py_Scene *self)
Py_TYPE(self)->tp_free((PyObject *)self);
}
+static PyObject *
+dmnsn_py_Scene_raytrace(dmnsn_py_Scene *self)
+{
+ dmnsn_raytrace_scene(self->scene);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
static PyMethodDef dmnsn_py_Scene_methods[] = {
+ { "raytrace", (PyCFunction)dmnsn_py_Scene_raytrace, METH_NOARGS,
+ "Raytrace a scene" },
{ NULL }
};