246 static void Material_Destructor(PyObject* self); |
246 static void Material_Destructor(PyObject* self); |
247 static PyObject *Material_Getattr(PyObject *self, char *name); |
247 static PyObject *Material_Getattr(PyObject *self, char *name); |
248 static PyObject *Material_setPhong(PyObject* self, PyObject* args); |
248 static PyObject *Material_setPhong(PyObject* self, PyObject* args); |
249 static PyObject *Material_setReflectivity(PyObject* self, PyObject* args); |
249 static PyObject *Material_setReflectivity(PyObject* self, PyObject* args); |
250 static PyObject *Material_setTransmissivity(PyObject* self, PyObject* args); |
250 static PyObject *Material_setTransmissivity(PyObject* self, PyObject* args); |
|
251 static PyObject *Material_setSmooth(PyObject* self, PyObject* args); |
251 |
252 |
252 static PyTypeObject MaterialType = { |
253 static PyTypeObject MaterialType = { |
253 PyObject_HEAD_INIT(NULL) |
254 PyObject_HEAD_INIT(NULL) |
254 0, /*ob_size*/ |
255 0, /*ob_size*/ |
255 "Material", /*tp_name*/ |
256 "Material", /*tp_name*/ |
270 |
271 |
271 static PyMethodDef MaterialMethods[] = { |
272 static PyMethodDef MaterialMethods[] = { |
272 {"setPhong", (PyCFunction)Material_setPhong, METH_VARARGS, "Set ambient, diffuse, specular and shininess Phong model constants."}, |
273 {"setPhong", (PyCFunction)Material_setPhong, METH_VARARGS, "Set ambient, diffuse, specular and shininess Phong model constants."}, |
273 {"setReflectivity", (PyCFunction)Material_setReflectivity, METH_VARARGS, "Set reflectivity."}, |
274 {"setReflectivity", (PyCFunction)Material_setReflectivity, METH_VARARGS, "Set reflectivity."}, |
274 {"setTransmissivity", (PyCFunction)Material_setTransmissivity, METH_VARARGS, "Set transmissivity and refraction index."}, |
275 {"setTransmissivity", (PyCFunction)Material_setTransmissivity, METH_VARARGS, "Set transmissivity and refraction index."}, |
|
276 {"setSmooth", (PyCFunction)Material_setSmooth, METH_VARARGS, "Set triangle smoothing."}, |
275 {NULL, NULL} |
277 {NULL, NULL} |
276 }; |
278 }; |
277 |
279 |
278 static PyObject* Material_Constructor(PyObject* self, PyObject* args, PyObject *kwd) |
280 static PyObject* Material_Constructor(PyObject* self, PyObject* args, PyObject *kwd) |
279 { |
281 { |
387 static char *kwdlist[] = {"vector", "normal", NULL}; |
403 static char *kwdlist[] = {"vector", "normal", NULL}; |
388 PyObject *TVer = NULL; |
404 PyObject *TVer = NULL; |
389 PyObject *TNor = NULL; |
405 PyObject *TNor = NULL; |
390 Float vx, vy, vz, nx=0, ny=0, nz=0; |
406 Float vx, vy, vz, nx=0, ny=0, nz=0; |
391 |
407 |
392 if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!|O!", kwdlist, |
408 if (!PyArg_ParseTupleAndKeywords(args, kwd, "O|O!", kwdlist, |
393 &PyTuple_Type, &TVer, &PyTuple_Type, &TNor)) |
409 &TVer, &PyTuple_Type, &TNor)) |
394 return NULL; |
410 return NULL; |
395 |
411 |
396 if (!PyArg_ParseTuple(TVer, "fff", &vx, &vy, &vz)) |
412 if (!TNor && TVer->ob_type == &NormalVertexType) |
397 return NULL; |
413 { |
398 |
414 v = PyObject_New(NormalVertexObject, &NormalVertexType); |
399 if (TNor) |
415 v->nvertex = new NormalVertex(((NormalVertexObject*)TVer)->nvertex); |
400 if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz)) |
416 } |
|
417 else |
|
418 { |
|
419 if (!PyArg_ParseTuple(TVer, "fff", &vx, &vy, &vz)) |
401 return NULL; |
420 return NULL; |
402 |
421 |
403 v = PyObject_New(NormalVertexObject, &NormalVertexType); |
422 if (TNor) |
404 v->nvertex = new NormalVertex(Vector3(vx, vy, vz), Vector3(nx, ny, nz)); |
423 if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz)) |
|
424 return NULL; |
|
425 |
|
426 v = PyObject_New(NormalVertexObject, &NormalVertexType); |
|
427 v->nvertex = new NormalVertex(Vector3(vx, vy, vz), Vector3(nx, ny, nz)); |
|
428 } |
405 return (PyObject*)v; |
429 return (PyObject*)v; |
406 } |
430 } |
407 |
431 |
408 static void NormalVertex_Destructor(PyObject* self) |
432 static void NormalVertex_Destructor(PyObject* self) |
409 { |
433 { |
578 |
602 |
579 static PyObject *Triangle_Constructor(PyObject* self, PyObject* args, PyObject *kwd); |
603 static PyObject *Triangle_Constructor(PyObject* self, PyObject* args, PyObject *kwd); |
580 static void Triangle_Destructor(PyObject* self); |
604 static void Triangle_Destructor(PyObject* self); |
581 static PyObject *Triangle_Getattr(PyObject *self, char *name); |
605 static PyObject *Triangle_Getattr(PyObject *self, char *name); |
582 static PyObject *Triangle_getNormal(PyObject* self, PyObject* args); |
606 static PyObject *Triangle_getNormal(PyObject* self, PyObject* args); |
583 static PyObject *Triangle_setSmooth(PyObject* self, PyObject* args); |
|
584 |
607 |
585 static PyTypeObject TriangleType = { |
608 static PyTypeObject TriangleType = { |
586 PyObject_HEAD_INIT(NULL) |
609 PyObject_HEAD_INIT(NULL) |
587 0, /*ob_size*/ |
610 0, /*ob_size*/ |
588 "Triangle", /*tp_name*/ |
611 "Triangle", /*tp_name*/ |
601 0, /*tp_hash */ |
624 0, /*tp_hash */ |
602 }; |
625 }; |
603 |
626 |
604 static PyMethodDef TriangleMethods[] = { |
627 static PyMethodDef TriangleMethods[] = { |
605 {"getNormal", (PyCFunction)Triangle_getNormal, METH_NOARGS, "Get normal of whole triangle."}, |
628 {"getNormal", (PyCFunction)Triangle_getNormal, METH_NOARGS, "Get normal of whole triangle."}, |
606 {"setSmooth", (PyCFunction)Triangle_setSmooth, METH_NOARGS, "Set the triangle smooth."}, |
|
607 {NULL, NULL} |
629 {NULL, NULL} |
608 }; |
630 }; |
609 |
631 |
610 static PyObject* Triangle_Constructor(PyObject* self, PyObject* args, PyObject *kwd) |
632 static PyObject* Triangle_Constructor(PyObject* self, PyObject* args, PyObject *kwd) |
611 { |
633 { |
645 |
667 |
646 Vector3 N = ((TriangleObject *)self)->triangle->getNormal(); |
668 Vector3 N = ((TriangleObject *)self)->triangle->getNormal(); |
647 |
669 |
648 obj = Py_BuildValue("(fff)", N.x, N.y, N.z); |
670 obj = Py_BuildValue("(fff)", N.x, N.y, N.z); |
649 return obj; |
671 return obj; |
650 } |
|
651 |
|
652 static PyObject* Triangle_setSmooth(PyObject* self, PyObject* args) |
|
653 { |
|
654 ((TriangleObject *)self)->triangle->setSmooth(); |
|
655 Py_INCREF(Py_None); |
|
656 return Py_None; |
|
657 } |
672 } |
658 |
673 |
659 //=========================== Raytracer Object =========================== |
674 //=========================== Raytracer Object =========================== |
660 |
675 |
661 typedef struct { |
676 typedef struct { |