src/raytracermodule.cc
author Radek Brich <radek.brich@devl.cz>
Fri, 28 Mar 2008 21:47:32 +0100
branchpyrit
changeset 51 89fec8668768
parent 48 a4913301c626
child 59 64e456ab823d
permissions -rw-r--r--
remove debug messages - algorithm seems stable, but it's slow
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"
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
    31
#include "scene.h"
36
b490093b0ac3 new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents: 35
diff changeset
    32
#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
    33
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
//=========================== 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
    35
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
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
    37
	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
    38
	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
    39
} 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
    40
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 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
    42
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
    43
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
    44
static PyObject *Light_castshadows(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
    45
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
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
    47
	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
    48
	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
    49
	"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
    50
	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
    51
	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
    52
	/* 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
    53
	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
    54
	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
    55
	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
    56
	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
    57
	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
    58
	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
    59
	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
    60
	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
    61
	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
    62
	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
    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
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    65
static PyMethodDef LightMethods[] = {
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
	{"castshadows", (PyCFunction)Light_castshadows, METH_VARARGS, "Enable or disable shadows from this 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
    67
	{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
    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
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
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
    71
{
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
	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
    73
	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
    74
	PyObject *TPos, *TCol = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
    75
	Float px, py, pz;
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
    76
	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
    77
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
	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
    79
		&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
    80
		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
    81
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
	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
    83
		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
    84
	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
    85
		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
    86
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 = 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
    88
	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
    89
	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
    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
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
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
    93
{
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
	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
    95
	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
    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
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
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
    99
{
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
	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
   101
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   102
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
static PyObject *Light_castshadows(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
   104
{
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
	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
   106
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
	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
   108
		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
   109
21
79b516a3803d naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
   110
	((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
   111
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
	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
   113
	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
   114
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   115
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   116
//=========================== 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
   117
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   118
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
   119
	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
   120
	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
   121
} 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
   122
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   123
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
   124
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
   125
static PyObject *Material_Getattr(PyObject *self, char *name);
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   126
static PyObject *Material_setPhong(PyObject* self, PyObject* args);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   127
static PyObject *Material_setReflectivity(PyObject* self, PyObject* args);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   128
static PyObject *Material_setTransmissivity(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
   129
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   130
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
   131
	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
   132
	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
   133
	"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
   134
	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
   135
	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
   136
	/* 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
   137
	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
   138
	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
   139
	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
   140
	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
   141
	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
   142
	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
   143
	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
   144
	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
   145
	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
   146
	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
   147
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   148
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   149
static PyMethodDef MaterialMethods[] = {
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   150
	{"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
   151
	{"setReflectivity", (PyCFunction)Material_setReflectivity, METH_VARARGS, "Set reflectivity."},
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   152
	{"setTransmissivity", (PyCFunction)Material_setTransmissivity, METH_VARARGS, "Set transmissivity and refraction index."},
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
   153
	{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
   154
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   155
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   156
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
   157
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   158
	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
   159
	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
   160
	PyObject *TCol = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   161
	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
   162
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   163
	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
   164
		&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
   165
		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
   166
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   167
	if (TCol)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   168
		if (!PyArg_ParseTuple(TCol, "fff", &cr, &cg, &cb))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   169
			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
   170
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   171
	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
   172
	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
   173
	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
   174
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   175
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   176
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
   177
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   178
	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
   179
	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
   180
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   181
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   182
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
   183
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   184
	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
   185
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   186
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   187
static PyObject *Material_setPhong(PyObject* self, PyObject* args)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   188
{
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   189
	Float amb, dif, spec, shin = 0.5;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   190
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   191
	if (!PyArg_ParseTuple(args, "fff|f", &amb, &dif, &spec, &shin))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   192
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   193
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   194
	((MaterialObject *)self)->material->setPhong(amb, dif, spec, shin);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   195
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   196
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   197
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   198
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   199
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   200
static PyObject *Material_setReflectivity(PyObject* self, PyObject* args)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   201
{
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   202
	Float refl;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   203
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   204
	if (!PyArg_ParseTuple(args, "f", &refl))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   205
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   206
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   207
	((MaterialObject *)self)->material->setReflectivity(refl);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   208
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   209
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   210
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   211
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   212
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   213
static PyObject *Material_setTransmissivity(PyObject* self, PyObject* args)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   214
{
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   215
	Float trans, rindex = 1.3;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   216
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   217
	if (!PyArg_ParseTuple(args, "f|f", &trans, &rindex))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   218
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   219
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   220
	((MaterialObject *)self)->material->setTransmissivity(trans, rindex);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   221
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   222
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   223
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   224
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   225
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   226
//=========================== NormalVertex Object ===========================
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   227
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   228
typedef struct {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   229
	PyObject_HEAD
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   230
	NormalVertex *nvertex;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   231
} NormalVertexObject;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   232
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   233
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
   234
static void NormalVertex_Destructor(PyObject* self);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   235
static PyObject *NormalVertex_Getattr(PyObject *self, char *name);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   236
static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   237
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   238
static PyTypeObject NormalVertexType = {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   239
	PyObject_HEAD_INIT(NULL)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   240
	0,				/*ob_size*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   241
	"NormalVertex",			/*tp_name*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   242
	sizeof(NormalVertexObject),		/*tp_basicsize*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   243
	0,				/*tp_itemsize*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   244
	/* methods */
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   245
	NormalVertex_Destructor,		/*tp_dealloc*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   246
	0,				/*tp_print*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   247
	NormalVertex_Getattr,			/*tp_getattr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   248
	0,				/*tp_setattr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   249
	0,				/*tp_compare*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   250
	0,				/*tp_repr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   251
	0,				/*tp_as_number*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   252
	0,				/*tp_as_sequence*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   253
	0,				/*tp_as_mapping*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   254
	0,				/*tp_hash */
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   255
};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   256
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   257
static PyMethodDef NormalVertexMethods[] = {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   258
	{"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
   259
	{NULL, NULL}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   260
};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   261
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   262
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
   263
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   264
	NormalVertexObject *v;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   265
	static char *kwdlist[] = {"vector", "normal", NULL};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   266
	PyObject *TVer = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   267
	PyObject *TNor = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   268
	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
   269
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   270
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!|O!", kwdlist,
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   271
		&PyTuple_Type, &TVer, &PyTuple_Type, &TNor))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   272
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   273
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   274
	if (!PyArg_ParseTuple(TVer, "fff", &vx, &vy, &vz))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   275
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   276
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   277
	if (TNor)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   278
		if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   279
			return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   280
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   281
	v = PyObject_New(NormalVertexObject, &NormalVertexType);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   282
	v->nvertex = new NormalVertex(Vector3(vx, vy, vz), Vector3(nx, ny, nz));
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   283
	return (PyObject*)v;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   284
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   285
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   286
static void NormalVertex_Destructor(PyObject* self)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   287
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   288
	delete ((NormalVertexObject *)self)->nvertex;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   289
	PyObject_Del(self);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   290
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   291
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   292
static PyObject *NormalVertex_Getattr(PyObject *self, char *name)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   293
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   294
	return Py_FindMethod(NormalVertexMethods, self, name);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   295
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   296
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   297
static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   298
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   299
	PyObject *TNor = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   300
	Float nx, ny, nz;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   301
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   302
	if (!PyArg_ParseTuple(args, "O!", &PyTuple_Type, &TNor))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   303
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   304
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   305
	if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   306
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   307
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   308
	((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
   309
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   310
	Py_INCREF(Py_None);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   311
	return Py_None;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   312
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   313
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
   314
//=========================== 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
   315
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
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
   317
	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
   318
	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
   319
} 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
   320
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   321
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
   322
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
   323
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
   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
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
   326
	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
   327
	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
   328
	"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
   329
	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
   330
	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
   331
	/* 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
   332
	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
   333
	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
   334
	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
   335
	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
   336
	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
   337
	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
   338
	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
   339
	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
   340
	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
   341
	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
   342
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   343
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   344
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
   345
	{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
   346
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   347
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   348
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
   349
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   350
	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
   351
	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
   352
	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
   353
	PyObject *TCentre = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   354
	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
   355
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   356
	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
   357
		&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
   358
		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
   359
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   360
	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
   361
		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
   362
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   363
	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
   364
	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
   365
	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
   366
	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
   367
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   368
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   369
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
   370
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   371
	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
   372
	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
   373
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   374
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   375
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
   376
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   377
	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
   378
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   379
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
   380
//=========================== 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
   381
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   382
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
   383
	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
   384
	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
   385
} 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
   386
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
   387
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
   388
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
   389
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
   390
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
   391
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
   392
	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
   393
	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
   394
	"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
   395
	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
   396
	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
   397
	/* 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
   398
	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
   399
	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
   400
	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
   401
	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
   402
	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
   403
	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
   404
	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
   405
	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
   406
	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
   407
	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
   408
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   409
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
   410
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
   411
	{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
   412
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   413
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
   414
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
   415
{
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
   416
	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
   417
	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
   418
	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
   419
	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
   420
	PyObject *TH = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   421
	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
   422
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
   423
	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
   424
		&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
   425
		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
   426
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
   427
	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
   428
		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
   429
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
   430
	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
   431
		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
   432
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
   433
	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
   434
	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
   435
	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
   436
	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
   437
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   438
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
   439
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
   440
{
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
   441
	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
   442
	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
   443
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   444
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
   445
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
   446
{
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
   447
	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
   448
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   449
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   450
//=========================== 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
   451
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   452
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
   453
	PyObject_HEAD
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   454
	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
   455
} 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
   456
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   457
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
   458
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
   459
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
   460
static PyObject *Triangle_getNormal(PyObject* self, PyObject* args);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   461
static PyObject *Triangle_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
   462
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   463
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
   464
	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
   465
	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
   466
	"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
   467
	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
   468
	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
   469
	/* 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
   470
	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
   471
	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
   472
	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
   473
	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
   474
	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
   475
	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
   476
	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
   477
	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
   478
	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
   479
	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
   480
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   481
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   482
static PyMethodDef TriangleMethods[] = {
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   483
	{"getNormal", (PyCFunction)Triangle_getNormal, METH_NOARGS, "Get normal of whole triangle."},
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   484
	{"setSmooth", (PyCFunction)Triangle_setSmooth, METH_NOARGS, "Set the triangle smooth."},
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
   485
	{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
   486
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   487
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   488
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
   489
{
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
	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
   491
	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
   492
	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
   493
	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
   494
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
	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
   496
		&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
   497
		&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
   498
		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
   499
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
	v = PyObject_New(TriangleObject, &TriangleType);
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   501
	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
   502
	Py_INCREF(material);
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   503
	Py_INCREF(A);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   504
	Py_INCREF(B);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   505
	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
   506
	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
   507
}
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
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
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
   510
{
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   511
	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
   512
	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
   513
}
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
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
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
   516
{
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
	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
   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
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   520
static PyObject* Triangle_getNormal(PyObject* self, PyObject* args)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   521
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   522
	PyObject *obj;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   523
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   524
	Vector3 N = ((TriangleObject *)self)->triangle->getNormal();
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   525
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   526
	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
   527
	return obj;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   528
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   529
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   530
static PyObject* Triangle_setSmooth(PyObject* self, PyObject* args)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   531
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   532
	((TriangleObject *)self)->triangle->setSmooth();
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   533
	Py_INCREF(Py_None);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   534
	return Py_None;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   535
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   536
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
   537
//=========================== 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
   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
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
   540
	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
   541
	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
   542
	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
   543
} 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
   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 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
   546
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
   547
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
   548
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
   549
static PyObject *Raytracer_addshape(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
   550
static PyObject *Raytracer_addlight(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
   551
static PyObject *Raytracer_ambientocclusion(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
   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
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
   554
	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
   555
	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
   556
	"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
   557
	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
   558
	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
   559
	/* 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
   560
	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
   561
	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
   562
	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
   563
	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
   564
	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
   565
	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
   566
	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
   567
	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
   568
	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
   569
	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
   570
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   571
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
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
   573
	{"render", (PyCFunction)Raytracer_render, METH_VARARGS, "Render scene and return image 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
   574
	{"addshape", (PyCFunction)Raytracer_addshape, METH_VARARGS, "Add new shape to scene."},
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
	{"addlight", (PyCFunction)Raytracer_addlight, METH_VARARGS, "Add new light source to scene."},
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   576
	{"ambientocclusion", (PyCFunction)Raytracer_ambientocclusion, METH_VARARGS | METH_KEYWORDS,
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
		"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
   578
	{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
   579
};
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
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
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
   582
{
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
	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
   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
	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
   586
		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
   587
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
	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
   589
	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
   590
	v->children = new vector<PyObject*>();
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 14
diff changeset
   591
	v->raytracer->setCamera(new Camera());
36
b490093b0ac3 new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents: 35
diff changeset
   592
	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
   593
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   594
	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
   595
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   596
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   597
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
   598
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   599
	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
   600
	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
   601
		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
   602
		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
   603
	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
   604
	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
   605
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   606
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   607
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
   608
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   609
	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
   610
}
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
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
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
   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
	int w = 0, 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
   615
	char *chardata;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   616
	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
   617
	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
   618
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
	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
   620
		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
   621
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   622
	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
   623
	((RaytracerObject *)self)->raytracer->getTop()->optimize();
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   624
	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
   625
	DefaultSampler sampler(data, w, h);
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
   626
	((RaytracerObject *)self)->raytracer->setSampler(&sampler);
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
   627
	((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
   628
	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
   629
		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
   630
		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
   631
	}
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
	// convert data to char
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   634
	printf("[pyrit] Converting image data (float to char)\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
   635
	chardata = (char *) malloc(w*h*3);
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   636
	Float *d = 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
   637
	for (char *c = chardata; c != chardata + w*h*3; c++, d++) {
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
		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
   639
			*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
   640
		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
   641
			*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
   642
	}
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
	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
   644
	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
   645
	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
   646
	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
   647
	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
   648
}
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
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
static PyObject* Raytracer_addshape(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
   651
{
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
	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
   653
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
	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
   655
		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
   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
	((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
   658
		((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
   659
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
	((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
   661
	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
   662
	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
   663
	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
   664
}
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
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 PyObject* Raytracer_addlight(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
   667
{
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
	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
   669
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   670
	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
   671
		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
   672
	((RaytracerObject *)self)->raytracer->addlight(lightobj->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
   673
	((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
   674
	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
   675
	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
   676
	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
   677
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   678
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   679
static PyObject* Raytracer_ambientocclusion(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
   680
{
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
	int samples = 0;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   682
	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
   683
	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
   684
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   685
	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
   686
		&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
   687
		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
   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
	((RaytracerObject *)self)->raytracer->ambientocclusion(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
   690
	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
   691
	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
   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
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   694
//=========================== 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
   695
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   696
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
   697
	{"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
   698
		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
   699
	{"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
   700
		METH_VARARGS | METH_KEYWORDS, "Light source 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
   701
	{"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
   702
		METH_VARARGS | METH_KEYWORDS, "Material object constructor."},
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   703
	{"NormalVertex", (PyCFunction) NormalVertex_Constructor,
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   704
		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
   705
	{"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
   706
		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
   707
	{"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
   708
		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
   709
	{"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
   710
		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
   711
	{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
   712
};
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
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
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
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
   716
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   717
	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
   718
}