src/raytracermodule.cc
author Radek Brich <radek.brich@devl.cz>
Wed, 23 Apr 2008 10:38:33 +0200
branchpyrit
changeset 78 9569e9f35374
parent 75 20dee9819b17
child 84 6f7fe14782c2
permissions -rw-r--r--
move shapes to extra source file add serialize header and source file with common serialization functions dump/load feature for shapes and kd-tree fix few minor bugs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
/*
44
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
     2
 * raytracermodule.cc: Python module
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
     3
 *
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
     4
 * This file is part of Pyrit Ray Tracer.
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
     5
 *
48
a4913301c626 begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
     6
 * Copyright 2006, 2007, 2008  Radek Brich
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
 *
44
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
     8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
     9
 * of this software and associated documentation files (the "Software"), to deal
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    10
 * in the Software without restriction, including without limitation the rights
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    12
 * copies of the Software, and to permit persons to whom the Software is
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    13
 * furnished to do so, subject to the following conditions:
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    14
 *
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    15
 * The above copyright notice and this permission notice shall be included in
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    16
 * all copies or substantial portions of the Software.
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    17
 *
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    24
 * THE SOFTWARE.
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
 */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
#include <Python.h>
1
e74bf781067e use python-config, strip python version from demos, change [PyRit] to [pyrit] -- should use unix name everywhere
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    28
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
#include <vector>
35
fb170fccb19f new space partitioning structure: octree
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
    30
#include "raytracer.h"
36
b490093b0ac3 new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents: 35
diff changeset
    31
#include "octree.h"
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
//=========================== Light Source Object ===========================
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
typedef struct {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
	PyObject_HEAD
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
	Light *light;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
} LightObject;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
static PyObject *Light_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
static void Light_Destructor(PyObject* self);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
static PyObject *Light_Getattr(PyObject *self, char *name);
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
    43
static PyObject *Light_castShadows(PyObject* self, PyObject* args);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
static PyTypeObject LightType = {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
	PyObject_HEAD_INIT(NULL)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
	0,				/*ob_size*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
	"Light",			/*tp_name*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
	sizeof(LightObject),		/*tp_basicsize*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
	0,				/*tp_itemsize*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    51
	/* methods */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
	Light_Destructor,		/*tp_dealloc*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
	0,				/*tp_print*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
	Light_Getattr,			/*tp_getattr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
	0,				/*tp_setattr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
	0,				/*tp_compare*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
	0,				/*tp_repr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
	0,				/*tp_as_number*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
	0,				/*tp_as_sequence*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60
	0,				/*tp_as_mapping*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
	0,				/*tp_hash */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    63
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    64
static PyMethodDef LightMethods[] = {
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
    65
	{"castShadows", (PyCFunction)Light_castShadows, METH_VARARGS, "Enable or disable shadows from this light."},
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    66
	{NULL, NULL}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    67
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    68
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    69
static PyObject* Light_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    70
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    71
	LightObject *v;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    72
	static char *kwdlist[] = {"position", "colour", NULL};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    73
	PyObject *TPos, *TCol = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
    74
	Float px, py, pz;
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
    75
	Float cr = 0.9, cg = 0.9, cb = 0.9;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    76
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    77
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!|O!", kwdlist,
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    78
		&PyTuple_Type, &TPos, &PyTuple_Type, &TCol))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    79
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    80
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    81
	if (!PyArg_ParseTuple(TPos, "fff", &px, &py, &pz))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    82
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    83
	if (TCol && !PyArg_ParseTuple(TCol, "fff", &cr, &cg, &cb))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    84
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    85
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    86
	v = PyObject_New(LightObject, &LightType);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    87
	v->light = new Light(Vector3(px, py, pz), Colour(cr, cg, cb));
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    88
	return (PyObject*)v;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    89
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    90
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    91
static void Light_Destructor(PyObject* self)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    92
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    93
	delete ((LightObject *)self)->light;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    94
	PyObject_Del(self);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    95
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    96
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    97
static PyObject *Light_Getattr(PyObject *self, char *name)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    98
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    99
	return Py_FindMethod(LightMethods, self, name);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   100
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   101
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   102
static PyObject *Light_castShadows(PyObject* self, PyObject* args)
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   103
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   104
	int shadows = 1;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   105
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   106
	if (!PyArg_ParseTuple(args, "i", &shadows))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   107
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   108
21
79b516a3803d naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
   109
	((LightObject *)self)->light->castShadows(shadows);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   110
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   111
	Py_INCREF(Py_None);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   112
	return Py_None;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   113
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   114
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   115
//=========================== Camera Object ===========================
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   116
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   117
typedef struct {
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   118
	PyObject_HEAD
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   119
	Camera *camera;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   120
} CameraObject;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   121
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   122
static PyObject *Camera_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   123
static void Camera_Destructor(PyObject* self);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   124
static PyObject *Camera_Getattr(PyObject *self, char *name);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   125
static PyObject *Camera_setEye(PyObject* self, PyObject* args);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   126
static PyObject *Camera_setAngle(PyObject* self, PyObject* args);
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   127
static PyObject *Camera_rotate(PyObject* self, PyObject* args);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   128
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   129
static PyTypeObject CameraType = {
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   130
	PyObject_HEAD_INIT(NULL)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   131
	0,				/*ob_size*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   132
	"Camera",			/*tp_name*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   133
	sizeof(CameraObject),		/*tp_basicsize*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   134
	0,				/*tp_itemsize*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   135
	/* methods */
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   136
	Camera_Destructor,		/*tp_dealloc*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   137
	0,				/*tp_print*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   138
	Camera_Getattr,			/*tp_getattr*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   139
	0,				/*tp_setattr*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   140
	0,				/*tp_compare*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   141
	0,				/*tp_repr*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   142
	0,				/*tp_as_number*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   143
	0,				/*tp_as_sequence*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   144
	0,				/*tp_as_mapping*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   145
	0,				/*tp_hash */
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   146
};
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   147
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   148
static PyMethodDef CameraMethods[] = {
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   149
	{"setEye", (PyCFunction)Camera_setEye, METH_VARARGS, "Set eye of the camera."},
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   150
	{"setAngle", (PyCFunction)Camera_setAngle, METH_VARARGS, "Set vertical angle of view."},
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   151
	{"rotate", (PyCFunction)Camera_rotate, METH_VARARGS, "Rotate camera with a quaternion."},
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   152
	{NULL, NULL}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   153
};
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   154
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   155
static PyObject* Camera_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   156
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   157
	CameraObject *v;
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   158
	static char *kwdlist[] = {"eye", "lookat", "up", "p", "u", "v", NULL};
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   159
	PyObject *TEye = NULL, *TLookAt = NULL, *TUp = NULL,
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   160
		*Tp = NULL, *Tu = NULL, *Tv = NULL;
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   161
	Float ex=0.0,  ey=0.0, ez=10.0;
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   162
	Float lax=0.0, lay=0.0, laz=0.0;
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   163
	Float upx=0.0, upy=1.0, upz=0.0;
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   164
	Float px=0.0,  py=0.0, pz=-1.0;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   165
	Float ux=-1.0, uy=0.0, uz=0.0;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   166
	Float vx=0.0,  vy=1.0, vz=0.0;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   167
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   168
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "|O!O!O!O!O!O!", kwdlist,
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   169
		&PyTuple_Type, &TEye, &PyTuple_Type, &TLookAt, &PyTuple_Type, &TUp,
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   170
		&PyTuple_Type, &Tp, &PyTuple_Type, &Tu, &PyTuple_Type, &Tv))
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   171
		return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   172
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   173
	if (TEye)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   174
		if (!PyArg_ParseTuple(TEye, "fff", &ex, &ey, &ez))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   175
			return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   176
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   177
	if (TLookAt)
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   178
		if (!PyArg_ParseTuple(TLookAt, "fff", &lax, &lay, &laz))
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   179
			return NULL;
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   180
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   181
	if (TUp)
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   182
		if (!PyArg_ParseTuple(TUp, "fff", &upx, &upy, &upz))
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   183
			return NULL;
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   184
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   185
	if (Tp)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   186
		if (!PyArg_ParseTuple(Tp, "fff", &px, &py, &pz))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   187
			return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   188
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   189
	if (Tu)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   190
		if (!PyArg_ParseTuple(Tu, "fff", &ux, &uy, &uz))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   191
			return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   192
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   193
	if (Tv)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   194
		if (!PyArg_ParseTuple(Tv, "fff", &vx, &vy, &vz))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   195
			return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   196
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   197
	v = PyObject_New(CameraObject, &CameraType);
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   198
	if (TLookAt)
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   199
		v->camera = new Camera(Vector3(ex, ey, ez),
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   200
			Vector3(lax, lay, laz), Vector3(upx, upy, upz));
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   201
	else
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   202
		v->camera = new Camera(Vector3(ex, ey, ez),
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   203
			Vector3(px, py, pz), Vector3(ux, uy, uz), Vector3(vx, vy, vz));
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   204
	return (PyObject*)v;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   205
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   206
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   207
static void Camera_Destructor(PyObject* self)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   208
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   209
	delete ((CameraObject *)self)->camera;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   210
	PyObject_Del(self);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   211
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   212
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   213
static PyObject *Camera_Getattr(PyObject *self, char *name)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   214
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   215
	return Py_FindMethod(CameraMethods, self, name);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   216
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   217
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   218
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   219
static PyObject *Camera_setEye(PyObject* self, PyObject* args)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   220
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   221
	PyObject *TEye = NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   222
	Float ex=0.0,  ey=0.0, ez=10.0;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   223
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   224
	if (!PyArg_ParseTuple(args, "O!", &PyTuple_Type, &TEye))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   225
		return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   226
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   227
	if (TEye)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   228
		if (!PyArg_ParseTuple(TEye, "fff", &ex, &ey, &ez))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   229
			return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   230
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   231
	((CameraObject *)self)->camera->setEye(Vector3(ex, ey, ez));
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   232
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   233
	Py_INCREF(Py_None);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   234
	return Py_None;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   235
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   236
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   237
static PyObject *Camera_setAngle(PyObject* self, PyObject* args)
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   238
{
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   239
	Float angle;
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   240
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   241
	if (!PyArg_ParseTuple(args, "f", &angle))
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   242
		return NULL;
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   243
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   244
	((CameraObject *)self)->camera->setAngle(angle);
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   245
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   246
	Py_INCREF(Py_None);
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   247
	return Py_None;
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   248
}
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   249
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   250
static PyObject *Camera_rotate(PyObject* self, PyObject* args)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   251
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   252
	PyObject *Tq = NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   253
	Float qa, qb, qc, qd;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   254
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   255
	if (!PyArg_ParseTuple(args, "O!", &PyTuple_Type, &Tq))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   256
		return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   257
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   258
	if (!PyArg_ParseTuple(Tq, "ffff", &qa, &qb, &qc, &qd))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   259
		return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   260
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   261
	((CameraObject *)self)->camera->rotate(Quaternion(qa, qb, qc, qd).normalize());
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   262
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   263
	Py_INCREF(Py_None);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   264
	return Py_None;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   265
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   266
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   267
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   268
//=========================== Material Object ===========================
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   269
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   270
typedef struct {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   271
	PyObject_HEAD
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   272
	Material *material;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   273
} MaterialObject;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   274
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   275
static PyObject *Material_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   276
static void Material_Destructor(PyObject* self);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   277
static PyObject *Material_Getattr(PyObject *self, char *name);
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   278
static PyObject *Material_setPhong(PyObject* self, PyObject* args);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   279
static PyObject *Material_setReflectivity(PyObject* self, PyObject* args);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   280
static PyObject *Material_setTransmissivity(PyObject* self, PyObject* args);
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   281
static PyObject *Material_setSmooth(PyObject* self, PyObject* args);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   282
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   283
static PyTypeObject MaterialType = {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   284
	PyObject_HEAD_INIT(NULL)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   285
	0,				/*ob_size*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   286
	"Material",			/*tp_name*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   287
	sizeof(MaterialObject),		/*tp_basicsize*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   288
	0,				/*tp_itemsize*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   289
	/* methods */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   290
	Material_Destructor,		/*tp_dealloc*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   291
	0,				/*tp_print*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   292
	Material_Getattr,			/*tp_getattr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   293
	0,				/*tp_setattr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   294
	0,				/*tp_compare*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   295
	0,				/*tp_repr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   296
	0,				/*tp_as_number*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   297
	0,				/*tp_as_sequence*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   298
	0,				/*tp_as_mapping*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   299
	0,				/*tp_hash */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   300
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   301
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   302
static PyMethodDef MaterialMethods[] = {
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   303
	{"setPhong", (PyCFunction)Material_setPhong, METH_VARARGS, "Set ambient, diffuse, specular and shininess Phong model constants."},
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   304
	{"setReflectivity", (PyCFunction)Material_setReflectivity, METH_VARARGS, "Set reflectivity."},
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   305
	{"setTransmissivity", (PyCFunction)Material_setTransmissivity, METH_VARARGS, "Set transmissivity and refraction index."},
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   306
	{"setSmooth", (PyCFunction)Material_setSmooth, METH_VARARGS, "Set triangle smoothing."},
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   307
	{NULL, NULL}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   308
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   309
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   310
static PyObject* Material_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   311
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   312
	MaterialObject *v;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   313
	static char *kwdlist[] = {"colour", NULL};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   314
	PyObject *TCol = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   315
	Float cr=1.0, cg=1.0, cb=1.0;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   316
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   317
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "|O!", kwdlist,
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   318
		&PyTuple_Type, &TCol))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   319
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   320
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   321
	if (TCol)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   322
		if (!PyArg_ParseTuple(TCol, "fff", &cr, &cg, &cb))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   323
			return NULL;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   324
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   325
	v = PyObject_New(MaterialObject, &MaterialType);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   326
	v->material = new Material(Colour(cr, cg, cb));
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   327
	return (PyObject*)v;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   328
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   329
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   330
static void Material_Destructor(PyObject* self)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   331
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   332
	delete ((MaterialObject *)self)->material;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   333
	PyObject_Del(self);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   334
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   335
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   336
static PyObject *Material_Getattr(PyObject *self, char *name)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   337
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   338
	return Py_FindMethod(MaterialMethods, self, name);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   339
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   340
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   341
static PyObject *Material_setPhong(PyObject* self, PyObject* args)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   342
{
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   343
	Float amb, dif, spec, shin = 0.5;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   344
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   345
	if (!PyArg_ParseTuple(args, "fff|f", &amb, &dif, &spec, &shin))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   346
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   347
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   348
	((MaterialObject *)self)->material->setPhong(amb, dif, spec, shin);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   349
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   350
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   351
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   352
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   353
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   354
static PyObject *Material_setReflectivity(PyObject* self, PyObject* args)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   355
{
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   356
	Float refl;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   357
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   358
	if (!PyArg_ParseTuple(args, "f", &refl))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   359
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   360
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   361
	((MaterialObject *)self)->material->setReflectivity(refl);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   362
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   363
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   364
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   365
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   366
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   367
static PyObject *Material_setTransmissivity(PyObject* self, PyObject* args)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   368
{
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   369
	Float trans, rindex = 1.3;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   370
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   371
	if (!PyArg_ParseTuple(args, "f|f", &trans, &rindex))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   372
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   373
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   374
	((MaterialObject *)self)->material->setTransmissivity(trans, rindex);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   375
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   376
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   377
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   378
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   379
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   380
static PyObject* Material_setSmooth(PyObject* self, PyObject* args)
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   381
{
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   382
	int smooth;
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   383
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   384
	if (!PyArg_ParseTuple(args, "i", &smooth))
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   385
		return NULL;
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   386
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   387
	((MaterialObject *)self)->material->setSmooth(smooth);
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   388
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   389
	Py_INCREF(Py_None);
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   390
	return Py_None;
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   391
}
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   392
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   393
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   394
//=========================== NormalVertex Object ===========================
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   395
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   396
typedef struct {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   397
	PyObject_HEAD
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   398
	NormalVertex *nvertex;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   399
} NormalVertexObject;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   400
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   401
static PyObject *NormalVertex_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   402
static void NormalVertex_Destructor(PyObject* self);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   403
static PyObject *NormalVertex_Getattr(PyObject *self, char *name);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   404
static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   405
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   406
static PyTypeObject NormalVertexType = {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   407
	PyObject_HEAD_INIT(NULL)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   408
	0,				/*ob_size*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   409
	"NormalVertex",			/*tp_name*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   410
	sizeof(NormalVertexObject),		/*tp_basicsize*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   411
	0,				/*tp_itemsize*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   412
	/* methods */
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   413
	NormalVertex_Destructor,		/*tp_dealloc*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   414
	0,				/*tp_print*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   415
	NormalVertex_Getattr,			/*tp_getattr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   416
	0,				/*tp_setattr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   417
	0,				/*tp_compare*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   418
	0,				/*tp_repr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   419
	0,				/*tp_as_number*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   420
	0,				/*tp_as_sequence*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   421
	0,				/*tp_as_mapping*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   422
	0,				/*tp_hash */
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   423
};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   424
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   425
static PyMethodDef NormalVertexMethods[] = {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   426
	{"setNormal", (PyCFunction)NormalVertex_setNormal, METH_VARARGS, "Set normal of this vertex."},
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   427
	{NULL, NULL}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   428
};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   429
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   430
static PyObject* NormalVertex_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   431
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   432
	NormalVertexObject *v;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   433
	static char *kwdlist[] = {"vector", "normal", NULL};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   434
	PyObject *TVer = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   435
	PyObject *TNor = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   436
	Float vx, vy, vz, nx=0, ny=0, nz=0;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   437
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   438
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "O|O!", kwdlist,
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   439
		&TVer, &PyTuple_Type, &TNor))
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   440
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   441
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   442
	if (!TNor && TVer->ob_type == &NormalVertexType)
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   443
	{
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   444
		v = PyObject_New(NormalVertexObject, &NormalVertexType);
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   445
		v->nvertex = new NormalVertex(((NormalVertexObject*)TVer)->nvertex);
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   446
	}
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   447
	else
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   448
	{
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   449
		if (!PyArg_ParseTuple(TVer, "fff", &vx, &vy, &vz))
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   450
			return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   451
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   452
		if (TNor)
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   453
			if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   454
				return NULL;
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   455
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   456
		v = PyObject_New(NormalVertexObject, &NormalVertexType);
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   457
		v->nvertex = new NormalVertex(Vector3(vx, vy, vz), Vector3(nx, ny, nz));
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   458
	}
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   459
	return (PyObject*)v;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   460
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   461
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   462
static void NormalVertex_Destructor(PyObject* self)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   463
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   464
	delete ((NormalVertexObject *)self)->nvertex;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   465
	PyObject_Del(self);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   466
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   467
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   468
static PyObject *NormalVertex_Getattr(PyObject *self, char *name)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   469
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   470
	return Py_FindMethod(NormalVertexMethods, self, name);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   471
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   472
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   473
static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   474
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   475
	PyObject *TNor = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   476
	Float nx, ny, nz;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   477
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   478
	if (!PyArg_ParseTuple(args, "O!", &PyTuple_Type, &TNor))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   479
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   480
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   481
	if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   482
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   483
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   484
	((NormalVertexObject *)self)->nvertex->setNormal(Vector3(nx,ny,nz).normalize());
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   485
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   486
	Py_INCREF(Py_None);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   487
	return Py_None;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   488
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   489
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   490
//=========================== Sphere Object ===========================
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   491
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   492
typedef struct {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   493
	PyObject_HEAD
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   494
	Sphere *shape;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   495
} SphereObject;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   496
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   497
static PyObject *Sphere_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   498
static void Sphere_Destructor(PyObject* self);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   499
static PyObject *Sphere_Getattr(PyObject *self, char *name);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   500
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   501
static PyTypeObject SphereType = {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   502
	PyObject_HEAD_INIT(NULL)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   503
	0,				/*ob_size*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   504
	"Sphere",			/*tp_name*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   505
	sizeof(SphereObject),		/*tp_basicsize*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   506
	0,				/*tp_itemsize*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   507
	/* methods */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   508
	Sphere_Destructor,		/*tp_dealloc*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   509
	0,				/*tp_print*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   510
	Sphere_Getattr,			/*tp_getattr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   511
	0,				/*tp_setattr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   512
	0,				/*tp_compare*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   513
	0,				/*tp_repr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   514
	0,				/*tp_as_number*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   515
	0,				/*tp_as_sequence*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   516
	0,				/*tp_as_mapping*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   517
	0,				/*tp_hash */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   518
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   519
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   520
static PyMethodDef SphereMethods[] = {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   521
	{NULL, NULL}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   522
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   523
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   524
static PyObject* Sphere_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   525
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   526
	SphereObject *v;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   527
	MaterialObject *material;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   528
	static char *kwdlist[] = {"centre", "radius", "material", NULL};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   529
	PyObject *TCentre = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   530
	Float cx, cy, cz, radius;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   531
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   532
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!fO!", kwdlist,
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   533
		&PyTuple_Type, &TCentre, &radius, &MaterialType, &material))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   534
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   535
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   536
	if (!PyArg_ParseTuple(TCentre, "fff", &cx, &cy, &cz))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   537
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   538
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   539
	v = PyObject_New(SphereObject, &SphereType);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   540
	v->shape = new Sphere(Vector3(cx, cy, cz), radius, material->material);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   541
	Py_INCREF(material);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   542
	return (PyObject*)v;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   543
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   544
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   545
static void Sphere_Destructor(PyObject* self)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   546
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   547
	delete ((SphereObject *)self)->shape;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   548
	PyObject_Del(self);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   549
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   550
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   551
static PyObject *Sphere_Getattr(PyObject *self, char *name)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   552
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   553
	return Py_FindMethod(SphereMethods, self, name);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   554
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   555
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   556
//=========================== Box Object ===========================
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   557
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   558
typedef struct {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   559
	PyObject_HEAD
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   560
	Box *shape;
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   561
} BoxObject;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   562
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   563
static PyObject *Box_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   564
static void Box_Destructor(PyObject* self);
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   565
static PyObject *Box_Getattr(PyObject *self, char *name);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   566
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   567
static PyTypeObject BoxType = {
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   568
	PyObject_HEAD_INIT(NULL)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   569
	0,				/*ob_size*/
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   570
	"Box",			/*tp_name*/
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   571
	sizeof(BoxObject),		/*tp_basicsize*/
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   572
	0,				/*tp_itemsize*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   573
	/* methods */
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   574
	Box_Destructor,		/*tp_dealloc*/
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   575
	0,				/*tp_print*/
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   576
	Box_Getattr,			/*tp_getattr*/
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   577
	0,				/*tp_setattr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   578
	0,				/*tp_compare*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   579
	0,				/*tp_repr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   580
	0,				/*tp_as_number*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   581
	0,				/*tp_as_sequence*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   582
	0,				/*tp_as_mapping*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   583
	0,				/*tp_hash */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   584
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   585
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   586
static PyMethodDef BoxMethods[] = {
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   587
	{NULL, NULL}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   588
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   589
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   590
static PyObject* Box_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   591
{
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   592
	BoxObject *v;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   593
	MaterialObject *material;
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   594
	static char *kwdlist[] = {"L", "H", "material", NULL};
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   595
	PyObject *TL = NULL;
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   596
	PyObject *TH = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   597
	Float lx, ly, lz, hx, hy, hz;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   598
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   599
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!O!O!", kwdlist,
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   600
		&PyTuple_Type, &TL, &PyTuple_Type, &TH, &MaterialType, &material))
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   601
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   602
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   603
	if (!PyArg_ParseTuple(TL, "fff", &lx, &ly, &lz))
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   604
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   605
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   606
	if (!PyArg_ParseTuple(TH, "fff", &hx, &hy, &hz))
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   607
		return NULL;
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   608
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   609
	v = PyObject_New(BoxObject, &BoxType);
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   610
	v->shape = new Box(Vector3(lx, ly, lz), Vector3(hx, hy, hz), material->material);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   611
	Py_INCREF(material);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   612
	return (PyObject*)v;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   613
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   614
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   615
static void Box_Destructor(PyObject* self)
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   616
{
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   617
	delete ((BoxObject *)self)->shape;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   618
	PyObject_Del(self);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   619
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   620
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   621
static PyObject *Box_Getattr(PyObject *self, char *name)
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   622
{
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   623
	return Py_FindMethod(BoxMethods, self, name);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   624
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   625
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   626
//=========================== Triangle Object ===========================
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   627
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   628
typedef struct {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   629
	PyObject_HEAD
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   630
	Triangle *triangle;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   631
} TriangleObject;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   632
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   633
static PyObject *Triangle_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   634
static void Triangle_Destructor(PyObject* self);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   635
static PyObject *Triangle_Getattr(PyObject *self, char *name);
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   636
static PyObject *Triangle_getNormal(PyObject* self, PyObject* args);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   637
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   638
static PyTypeObject TriangleType = {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   639
	PyObject_HEAD_INIT(NULL)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   640
	0,				/*ob_size*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   641
	"Triangle",			/*tp_name*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   642
	sizeof(TriangleObject),		/*tp_basicsize*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   643
	0,				/*tp_itemsize*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   644
	/* methods */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   645
	Triangle_Destructor,		/*tp_dealloc*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   646
	0,				/*tp_print*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   647
	Triangle_Getattr,			/*tp_getattr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   648
	0,				/*tp_setattr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   649
	0,				/*tp_compare*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   650
	0,				/*tp_repr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   651
	0,				/*tp_as_number*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   652
	0,				/*tp_as_sequence*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   653
	0,				/*tp_as_mapping*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   654
	0,				/*tp_hash */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   655
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   656
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   657
static PyMethodDef TriangleMethods[] = {
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   658
	{"getNormal", (PyCFunction)Triangle_getNormal, METH_NOARGS, "Get normal of whole triangle."},
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   659
	{NULL, NULL}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   660
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   661
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   662
static PyObject* Triangle_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   663
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   664
	TriangleObject *v;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   665
	MaterialObject *material;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   666
	static char *kwdlist[] = {"A", "B", "C", "material", NULL};
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   667
	NormalVertexObject *A, *B, *C;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   668
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   669
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!O!O!O!", kwdlist,
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   670
		&NormalVertexType, &A, &NormalVertexType, &B, &NormalVertexType, &C,
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   671
		&MaterialType, &material))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   672
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   673
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   674
	v = PyObject_New(TriangleObject, &TriangleType);
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   675
	v->triangle = new Triangle(A->nvertex, B->nvertex, C->nvertex, material->material);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   676
	Py_INCREF(material);
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   677
	Py_INCREF(A);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   678
	Py_INCREF(B);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   679
	Py_INCREF(C);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   680
	return (PyObject*)v;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   681
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   682
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   683
static void Triangle_Destructor(PyObject* self)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   684
{
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   685
	delete ((TriangleObject *)self)->triangle;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   686
	PyObject_Del(self);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   687
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   688
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   689
static PyObject *Triangle_Getattr(PyObject *self, char *name)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   690
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   691
	return Py_FindMethod(TriangleMethods, self, name);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   692
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   693
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   694
static PyObject* Triangle_getNormal(PyObject* self, PyObject* args)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   695
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   696
	PyObject *obj;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   697
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   698
	Vector3 N = ((TriangleObject *)self)->triangle->getNormal();
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   699
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   700
	obj = Py_BuildValue("(fff)", N.x, N.y, N.z);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   701
	return obj;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   702
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   703
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   704
//=========================== Raytracer Object ===========================
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   705
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   706
typedef struct {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   707
	PyObject_HEAD
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   708
	Raytracer *raytracer;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   709
	vector<PyObject*> *children;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   710
} RaytracerObject;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   711
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   712
static PyObject *Raytracer_Constructor(PyObject* self, PyObject* args);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   713
static void Raytracer_Destructor(PyObject* self);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   714
static PyObject *Raytracer_Getattr(PyObject *self, char *name);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   715
static PyObject *Raytracer_render(PyObject* self, PyObject* args);
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   716
static PyObject *Raytracer_setCamera(PyObject* self, PyObject* args);
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   717
static PyObject *Raytracer_setBgColour(PyObject* self, PyObject* args);
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   718
static PyObject *Raytracer_addShape(PyObject* self, PyObject* args);
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   719
static PyObject *Raytracer_addLight(PyObject* self, PyObject* args);
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   720
static PyObject *Raytracer_ambientOcclusion(PyObject* self, PyObject* args, PyObject *kwd);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   721
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   722
static PyTypeObject RaytracerType = {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   723
	PyObject_HEAD_INIT(NULL)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   724
	0,				/*ob_size*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   725
	"Raytracer",			/*tp_name*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   726
	sizeof(RaytracerObject),	/*tp_basicsize*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   727
	0,				/*tp_itemsize*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   728
	/* methods */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   729
	Raytracer_Destructor,		/*tp_dealloc*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   730
	0,				/*tp_print*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   731
	Raytracer_Getattr,		/*tp_getattr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   732
	0,				/*tp_setattr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   733
	0,				/*tp_compare*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   734
	0,				/*tp_repr*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   735
	0,				/*tp_as_number*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   736
	0,				/*tp_as_sequence*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   737
	0,				/*tp_as_mapping*/
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   738
	0,				/*tp_hash */
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   739
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   740
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   741
static PyMethodDef RaytracerMethods[] = {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   742
	{"render", (PyCFunction)Raytracer_render, METH_VARARGS, "Render scene and return image data."},
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   743
	{"setCamera", (PyCFunction)Raytracer_setCamera, METH_VARARGS, "Set camera for the scene."},
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   744
	{"setBgColour", (PyCFunction)Raytracer_setBgColour, METH_VARARGS, "Set background colour."},
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   745
	{"addShape", (PyCFunction)Raytracer_addShape, METH_VARARGS, "Add new shape to scene."},
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   746
	{"addLight", (PyCFunction)Raytracer_addLight, METH_VARARGS, "Add new light source to scene."},
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   747
	{"ambientOcclusion", (PyCFunction)Raytracer_ambientOcclusion, METH_VARARGS | METH_KEYWORDS,
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   748
		"Set ambient occlusion parametrs - samples: int (0 = disable), distance: float, angle: float."},
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   749
	{NULL, NULL}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   750
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   751
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   752
static PyObject* Raytracer_Constructor(PyObject* self, PyObject* args)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   753
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   754
	RaytracerObject *v;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   755
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   756
	if(!PyArg_ParseTuple(args, ""))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   757
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   758
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   759
	v = PyObject_New(RaytracerObject, &RaytracerType);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   760
	v->raytracer = new Raytracer();
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   761
	v->children = new vector<PyObject*>();
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 14
diff changeset
   762
	v->raytracer->setCamera(new Camera());
36
b490093b0ac3 new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents: 35
diff changeset
   763
	v->raytracer->setTop(new Octree());
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   764
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   765
	return (PyObject*)v;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   766
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   767
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   768
static void Raytracer_Destructor(PyObject* self)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   769
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   770
	vector<PyObject*>::iterator o;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   771
	for (o = ((RaytracerObject *)self)->children->begin();
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   772
		o != ((RaytracerObject *)self)->children->end(); o++)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   773
		Py_DECREF(*o);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   774
	delete ((RaytracerObject *)self)->raytracer;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   775
	PyObject_Del(self);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   776
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   777
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   778
static PyObject *Raytracer_Getattr(PyObject *self, char *name)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   779
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   780
	return Py_FindMethod(RaytracerMethods, self, name);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   781
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   782
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   783
static PyObject* Raytracer_render(PyObject* self, PyObject* args)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   784
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   785
	int w = 0, h = 0;
60
a23b5089b9c3 moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents: 59
diff changeset
   786
	unsigned char *chardata;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   787
	Float *data;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   788
	PyObject *o;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   789
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   790
	if (!PyArg_ParseTuple(args, "(ii)", &w, &h))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   791
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   792
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   793
	printf("[pyrit] Running ray tracer\n");
20
f22952603f29 new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents: 19
diff changeset
   794
	((RaytracerObject *)self)->raytracer->getTop()->optimize();
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   795
	data = (Float *) malloc(w*h*3*sizeof(Float));
47
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
   796
	DefaultSampler sampler(data, w, h);
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
   797
	((RaytracerObject *)self)->raytracer->setSampler(&sampler);
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
   798
	((RaytracerObject *)self)->raytracer->render();
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   799
	if (!data) {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   800
		Py_INCREF(Py_None);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   801
		return Py_None;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   802
	}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   803
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   804
	// convert data to char
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   805
	printf("[pyrit] Converting image data (float to char)\n");
60
a23b5089b9c3 moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents: 59
diff changeset
   806
	chardata = (unsigned char *) malloc(w*h*3);
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   807
	Float *d = data;
60
a23b5089b9c3 moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents: 59
diff changeset
   808
	for (unsigned char *c = chardata; c != chardata + w*h*3; c++, d++) {
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   809
		if (*d > 1.0)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   810
			*c = 255;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   811
		else
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   812
			*c = (unsigned char)(*d * 255.0);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   813
	}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   814
	free(data);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   815
	o = Py_BuildValue("s#", chardata, w*h*3);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   816
	free(chardata);
1
e74bf781067e use python-config, strip python version from demos, change [PyRit] to [pyrit] -- should use unix name everywhere
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
   817
	printf("[pyrit] Done.\n");
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   818
	return o;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   819
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   820
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   821
static PyObject* Raytracer_setCamera(PyObject* self, PyObject* args)
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   822
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   823
	CameraObject *cam;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   824
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   825
	if (!PyArg_ParseTuple(args, "O!", &CameraType, &cam))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   826
		return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   827
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   828
	((RaytracerObject *)self)->raytracer->setCamera(cam->camera);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   829
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   830
	Py_INCREF(cam);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   831
	Py_INCREF(Py_None);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   832
	return Py_None;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   833
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   834
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   835
static PyObject* Raytracer_setBgColour(PyObject* self, PyObject* args)
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   836
{
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   837
	Float r,g,b;
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   838
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   839
	if (!PyArg_ParseTuple(args, "(fff)", &r, &g, &b))
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   840
		return NULL;
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   841
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   842
	((RaytracerObject *)self)->raytracer->setBgColour(Colour(r,g,b));
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   843
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   844
	Py_INCREF(Py_None);
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   845
	return Py_None;
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   846
}
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   847
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   848
static PyObject* Raytracer_addShape(PyObject* self, PyObject* args)
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   849
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   850
	PyObject *obj;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   851
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   852
	if (!PyArg_ParseTuple(args, "O", &obj))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   853
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   854
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   855
	((RaytracerObject *)self)->raytracer->addShape(
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   856
		((BoxObject*)obj)->shape);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   857
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   858
	((RaytracerObject *)self)->children->push_back(obj);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   859
	Py_INCREF(obj);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   860
	Py_INCREF(Py_None);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   861
	return Py_None;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   862
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   863
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   864
static PyObject* Raytracer_addLight(PyObject* self, PyObject* args)
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   865
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   866
	LightObject *lightobj;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   867
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   868
	if (!PyArg_ParseTuple(args, "O!", &LightType, &lightobj))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   869
		return NULL;
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
   870
	((RaytracerObject *)self)->raytracer->addLight(lightobj->light);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   871
	((RaytracerObject *)self)->children->push_back((PyObject*)lightobj);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   872
	Py_INCREF(lightobj);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   873
	Py_INCREF(Py_None);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   874
	return Py_None;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   875
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   876
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   877
static PyObject* Raytracer_ambientOcclusion(PyObject* self, PyObject* args, PyObject *kwd)
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   878
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   879
	int samples = 0;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   880
	Float distance = 0.0, angle = 0.0;
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   881
	static char *kwdlist[] = {"samples", "distance", "angle", NULL};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   882
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   883
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "iff", kwdlist,
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   884
		&samples, &distance, &angle))
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   885
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   886
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 72
diff changeset
   887
	((RaytracerObject *)self)->raytracer->ambientOcclusion(samples, distance, angle);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   888
	Py_INCREF(Py_None);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   889
	return Py_None;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   890
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   891
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   892
//=========================== Module Methods ===========================
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   893
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   894
static PyMethodDef ModuleMethods[] = {
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   895
	{"Raytracer", (PyCFunction) Raytracer_Constructor,
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   896
		METH_VARARGS, "Raytracer object constructor."},
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   897
	{"Light", (PyCFunction) Light_Constructor,
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   898
		METH_VARARGS | METH_KEYWORDS, "Light source object constructor."},
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   899
	{"Camera", (PyCFunction) Camera_Constructor,
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   900
		METH_VARARGS | METH_KEYWORDS, "Camera object constructor."},
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   901
	{"Material", (PyCFunction) Material_Constructor,
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   902
		METH_VARARGS | METH_KEYWORDS, "Material object constructor."},
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   903
	{"NormalVertex", (PyCFunction) NormalVertex_Constructor,
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   904
		METH_VARARGS | METH_KEYWORDS, "NormalVertex object constructor."},
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   905
	{"Sphere", (PyCFunction) Sphere_Constructor,
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   906
		METH_VARARGS | METH_KEYWORDS, "Sphere object constructor."},
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   907
	{"Box", (PyCFunction) Box_Constructor,
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   908
		METH_VARARGS | METH_KEYWORDS, "Box object constructor."},
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   909
	{"Triangle", (PyCFunction) Triangle_Constructor,
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   910
		METH_VARARGS | METH_KEYWORDS, "Triangle object constructor."},
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   911
	{NULL, NULL}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   912
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   913
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   914
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   915
extern "C" void initraytracer(void)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   916
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   917
	Py_InitModule("raytracer", ModuleMethods);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   918
}