src/raytracermodule.cc
branchpyrit
changeset 75 20dee9819b17
parent 72 7c3f38dff082
child 78 9569e9f35374
equal deleted inserted replaced
74:09aedbf5f95f 75:20dee9819b17
    39 } LightObject;
    39 } LightObject;
    40 
    40 
    41 static PyObject *Light_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
    41 static PyObject *Light_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
    42 static void Light_Destructor(PyObject* self);
    42 static void Light_Destructor(PyObject* self);
    43 static PyObject *Light_Getattr(PyObject *self, char *name);
    43 static PyObject *Light_Getattr(PyObject *self, char *name);
    44 static PyObject *Light_castshadows(PyObject* self, PyObject* args);
    44 static PyObject *Light_castShadows(PyObject* self, PyObject* args);
    45 
    45 
    46 static PyTypeObject LightType = {
    46 static PyTypeObject LightType = {
    47 	PyObject_HEAD_INIT(NULL)
    47 	PyObject_HEAD_INIT(NULL)
    48 	0,				/*ob_size*/
    48 	0,				/*ob_size*/
    49 	"Light",			/*tp_name*/
    49 	"Light",			/*tp_name*/
    61 	0,				/*tp_as_mapping*/
    61 	0,				/*tp_as_mapping*/
    62 	0,				/*tp_hash */
    62 	0,				/*tp_hash */
    63 };
    63 };
    64 
    64 
    65 static PyMethodDef LightMethods[] = {
    65 static PyMethodDef LightMethods[] = {
    66 	{"castshadows", (PyCFunction)Light_castshadows, METH_VARARGS, "Enable or disable shadows from this light."},
    66 	{"castShadows", (PyCFunction)Light_castShadows, METH_VARARGS, "Enable or disable shadows from this light."},
    67 	{NULL, NULL}
    67 	{NULL, NULL}
    68 };
    68 };
    69 
    69 
    70 static PyObject* Light_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
    70 static PyObject* Light_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
    71 {
    71 {
    98 static PyObject *Light_Getattr(PyObject *self, char *name)
    98 static PyObject *Light_Getattr(PyObject *self, char *name)
    99 {
    99 {
   100 	return Py_FindMethod(LightMethods, self, name);
   100 	return Py_FindMethod(LightMethods, self, name);
   101 }
   101 }
   102 
   102 
   103 static PyObject *Light_castshadows(PyObject* self, PyObject* args)
   103 static PyObject *Light_castShadows(PyObject* self, PyObject* args)
   104 {
   104 {
   105 	int shadows = 1;
   105 	int shadows = 1;
   106 
   106 
   107 	if (!PyArg_ParseTuple(args, "i", &shadows))
   107 	if (!PyArg_ParseTuple(args, "i", &shadows))
   108 		return NULL;
   108 		return NULL;
   712 
   712 
   713 static PyObject *Raytracer_Constructor(PyObject* self, PyObject* args);
   713 static PyObject *Raytracer_Constructor(PyObject* self, PyObject* args);
   714 static void Raytracer_Destructor(PyObject* self);
   714 static void Raytracer_Destructor(PyObject* self);
   715 static PyObject *Raytracer_Getattr(PyObject *self, char *name);
   715 static PyObject *Raytracer_Getattr(PyObject *self, char *name);
   716 static PyObject *Raytracer_render(PyObject* self, PyObject* args);
   716 static PyObject *Raytracer_render(PyObject* self, PyObject* args);
   717 static PyObject *Raytracer_setcamera(PyObject* self, PyObject* args);
   717 static PyObject *Raytracer_setCamera(PyObject* self, PyObject* args);
   718 static PyObject *Raytracer_setbgcolour(PyObject* self, PyObject* args);
   718 static PyObject *Raytracer_setBgColour(PyObject* self, PyObject* args);
   719 static PyObject *Raytracer_addshape(PyObject* self, PyObject* args);
   719 static PyObject *Raytracer_addShape(PyObject* self, PyObject* args);
   720 static PyObject *Raytracer_addlight(PyObject* self, PyObject* args);
   720 static PyObject *Raytracer_addLight(PyObject* self, PyObject* args);
   721 static PyObject *Raytracer_ambientocclusion(PyObject* self, PyObject* args, PyObject *kwd);
   721 static PyObject *Raytracer_ambientOcclusion(PyObject* self, PyObject* args, PyObject *kwd);
   722 
   722 
   723 static PyTypeObject RaytracerType = {
   723 static PyTypeObject RaytracerType = {
   724 	PyObject_HEAD_INIT(NULL)
   724 	PyObject_HEAD_INIT(NULL)
   725 	0,				/*ob_size*/
   725 	0,				/*ob_size*/
   726 	"Raytracer",			/*tp_name*/
   726 	"Raytracer",			/*tp_name*/
   739 	0,				/*tp_hash */
   739 	0,				/*tp_hash */
   740 };
   740 };
   741 
   741 
   742 static PyMethodDef RaytracerMethods[] = {
   742 static PyMethodDef RaytracerMethods[] = {
   743 	{"render", (PyCFunction)Raytracer_render, METH_VARARGS, "Render scene and return image data."},
   743 	{"render", (PyCFunction)Raytracer_render, METH_VARARGS, "Render scene and return image data."},
   744 	{"setcamera", (PyCFunction)Raytracer_setcamera, METH_VARARGS, "Set camera for the scene."},
   744 	{"setCamera", (PyCFunction)Raytracer_setCamera, METH_VARARGS, "Set camera for the scene."},
   745 	{"setbgcolour", (PyCFunction)Raytracer_setbgcolour, METH_VARARGS, "Set background colour."},
   745 	{"setBgColour", (PyCFunction)Raytracer_setBgColour, METH_VARARGS, "Set background colour."},
   746 	{"addshape", (PyCFunction)Raytracer_addshape, METH_VARARGS, "Add new shape to scene."},
   746 	{"addShape", (PyCFunction)Raytracer_addShape, METH_VARARGS, "Add new shape to scene."},
   747 	{"addlight", (PyCFunction)Raytracer_addlight, METH_VARARGS, "Add new light source to scene."},
   747 	{"addLight", (PyCFunction)Raytracer_addLight, METH_VARARGS, "Add new light source to scene."},
   748 	{"ambientocclusion", (PyCFunction)Raytracer_ambientocclusion, METH_VARARGS | METH_KEYWORDS,
   748 	{"ambientOcclusion", (PyCFunction)Raytracer_ambientOcclusion, METH_VARARGS | METH_KEYWORDS,
   749 		"Set ambient occlusion parametrs - samples: int (0 = disable), distance: float, angle: float."},
   749 		"Set ambient occlusion parametrs - samples: int (0 = disable), distance: float, angle: float."},
   750 	{NULL, NULL}
   750 	{NULL, NULL}
   751 };
   751 };
   752 
   752 
   753 static PyObject* Raytracer_Constructor(PyObject* self, PyObject* args)
   753 static PyObject* Raytracer_Constructor(PyObject* self, PyObject* args)
   817 	free(chardata);
   817 	free(chardata);
   818 	printf("[pyrit] Done.\n");
   818 	printf("[pyrit] Done.\n");
   819 	return o;
   819 	return o;
   820 }
   820 }
   821 
   821 
   822 static PyObject* Raytracer_setcamera(PyObject* self, PyObject* args)
   822 static PyObject* Raytracer_setCamera(PyObject* self, PyObject* args)
   823 {
   823 {
   824 	CameraObject *cam;
   824 	CameraObject *cam;
   825 
   825 
   826 	if (!PyArg_ParseTuple(args, "O!", &CameraType, &cam))
   826 	if (!PyArg_ParseTuple(args, "O!", &CameraType, &cam))
   827 		return NULL;
   827 		return NULL;
   831 	Py_INCREF(cam);
   831 	Py_INCREF(cam);
   832 	Py_INCREF(Py_None);
   832 	Py_INCREF(Py_None);
   833 	return Py_None;
   833 	return Py_None;
   834 }
   834 }
   835 
   835 
   836 static PyObject* Raytracer_setbgcolour(PyObject* self, PyObject* args)
   836 static PyObject* Raytracer_setBgColour(PyObject* self, PyObject* args)
   837 {
   837 {
   838 	Float r,g,b;
   838 	Float r,g,b;
   839 
   839 
   840 	if (!PyArg_ParseTuple(args, "(fff)", &r, &g, &b))
   840 	if (!PyArg_ParseTuple(args, "(fff)", &r, &g, &b))
   841 		return NULL;
   841 		return NULL;
   844 
   844 
   845 	Py_INCREF(Py_None);
   845 	Py_INCREF(Py_None);
   846 	return Py_None;
   846 	return Py_None;
   847 }
   847 }
   848 
   848 
   849 static PyObject* Raytracer_addshape(PyObject* self, PyObject* args)
   849 static PyObject* Raytracer_addShape(PyObject* self, PyObject* args)
   850 {
   850 {
   851 	PyObject *obj;
   851 	PyObject *obj;
   852 
   852 
   853 	if (!PyArg_ParseTuple(args, "O", &obj))
   853 	if (!PyArg_ParseTuple(args, "O", &obj))
   854 		return NULL;
   854 		return NULL;
   860 	Py_INCREF(obj);
   860 	Py_INCREF(obj);
   861 	Py_INCREF(Py_None);
   861 	Py_INCREF(Py_None);
   862 	return Py_None;
   862 	return Py_None;
   863 }
   863 }
   864 
   864 
   865 static PyObject* Raytracer_addlight(PyObject* self, PyObject* args)
   865 static PyObject* Raytracer_addLight(PyObject* self, PyObject* args)
   866 {
   866 {
   867 	LightObject *lightobj;
   867 	LightObject *lightobj;
   868 
   868 
   869 	if (!PyArg_ParseTuple(args, "O!", &LightType, &lightobj))
   869 	if (!PyArg_ParseTuple(args, "O!", &LightType, &lightobj))
   870 		return NULL;
   870 		return NULL;
   873 	Py_INCREF(lightobj);
   873 	Py_INCREF(lightobj);
   874 	Py_INCREF(Py_None);
   874 	Py_INCREF(Py_None);
   875 	return Py_None;
   875 	return Py_None;
   876 }
   876 }
   877 
   877 
   878 static PyObject* Raytracer_ambientocclusion(PyObject* self, PyObject* args, PyObject *kwd)
   878 static PyObject* Raytracer_ambientOcclusion(PyObject* self, PyObject* args, PyObject *kwd)
   879 {
   879 {
   880 	int samples = 0;
   880 	int samples = 0;
   881 	Float distance = 0.0, angle = 0.0;
   881 	Float distance = 0.0, angle = 0.0;
   882 	static char *kwdlist[] = {"samples", "distance", "angle", NULL};
   882 	static char *kwdlist[] = {"samples", "distance", "angle", NULL};
   883 
   883 
   884 	if (!PyArg_ParseTupleAndKeywords(args, kwd, "iff", kwdlist,
   884 	if (!PyArg_ParseTupleAndKeywords(args, kwd, "iff", kwdlist,
   885 		&samples, &distance, &angle))
   885 		&samples, &distance, &angle))
   886 		return NULL;
   886 		return NULL;
   887 
   887 
   888 	((RaytracerObject *)self)->raytracer->ambientocclusion(samples, distance, angle);
   888 	((RaytracerObject *)self)->raytracer->ambientOcclusion(samples, distance, angle);
   889 	Py_INCREF(Py_None);
   889 	Py_INCREF(Py_None);
   890 	return Py_None;
   890 	return Py_None;
   891 }
   891 }
   892 
   892 
   893 //=========================== Module Methods ===========================
   893 //=========================== Module Methods ===========================