src/raytracermodule.cc
author Radek Brich <radek.brich@devl.cz>
Tue, 15 Apr 2008 17:12:50 +0200
branchpyrit
changeset 70 4b84e90325c5
parent 69 303583d2fb97
child 72 7c3f38dff082
permissions -rw-r--r--
a fix for CPU and compiler detection
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
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   116
//=========================== Camera Object ===========================
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   117
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   118
typedef struct {
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   119
	PyObject_HEAD
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   120
	Camera *camera;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   121
} CameraObject;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   122
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   123
static PyObject *Camera_Constructor(PyObject* self, PyObject* args, PyObject *kwd);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   124
static void Camera_Destructor(PyObject* self);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   125
static PyObject *Camera_Getattr(PyObject *self, char *name);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   126
static PyObject *Camera_setEye(PyObject* self, PyObject* args);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   127
static PyObject *Camera_rotate(PyObject* self, PyObject* args);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   128
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   129
static PyTypeObject CameraType = {
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   130
	PyObject_HEAD_INIT(NULL)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   131
	0,				/*ob_size*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   132
	"Camera",			/*tp_name*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   133
	sizeof(CameraObject),		/*tp_basicsize*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   134
	0,				/*tp_itemsize*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   135
	/* methods */
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   136
	Camera_Destructor,		/*tp_dealloc*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   137
	0,				/*tp_print*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   138
	Camera_Getattr,			/*tp_getattr*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   139
	0,				/*tp_setattr*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   140
	0,				/*tp_compare*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   141
	0,				/*tp_repr*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   142
	0,				/*tp_as_number*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   143
	0,				/*tp_as_sequence*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   144
	0,				/*tp_as_mapping*/
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   145
	0,				/*tp_hash */
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   146
};
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   147
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   148
static PyMethodDef CameraMethods[] = {
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   149
	{"setEye", (PyCFunction)Camera_setEye, METH_VARARGS, "Set eye of the camera."},
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   150
	{"rotate", (PyCFunction)Camera_rotate, METH_VARARGS, "Rotate camera with a quaternion."},
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   151
	{NULL, NULL}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   152
};
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   153
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   154
static PyObject* Camera_Constructor(PyObject* self, PyObject* args, PyObject *kwd)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   155
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   156
	CameraObject *v;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   157
	static char *kwdlist[] = {"eye", "p", "u", "v", NULL};
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   158
	PyObject *TEye = NULL, *Tp = NULL, *Tu = NULL, *Tv = NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   159
	Float ex=0.0,  ey=0.0, ez=10.0;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   160
	Float px=0.0,  py=0.0, pz=-1.0;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   161
	Float ux=-1.0, uy=0.0, uz=0.0;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   162
	Float vx=0.0,  vy=1.0, vz=0.0;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   163
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   164
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "|O!O!O!O!", kwdlist,
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   165
		&PyTuple_Type, &TEye, &PyTuple_Type, &Tp, &PyTuple_Type, &Tu, &PyTuple_Type, &Tv))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   166
		return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   167
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   168
	if (TEye)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   169
		if (!PyArg_ParseTuple(TEye, "fff", &ex, &ey, &ez))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   170
			return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   171
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   172
	if (Tp)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   173
		if (!PyArg_ParseTuple(Tp, "fff", &px, &py, &pz))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   174
			return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   175
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   176
	if (Tu)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   177
		if (!PyArg_ParseTuple(Tu, "fff", &ux, &uy, &uz))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   178
			return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   179
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   180
	if (Tv)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   181
		if (!PyArg_ParseTuple(Tv, "fff", &vx, &vy, &vz))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   182
			return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   183
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   184
	v = PyObject_New(CameraObject, &CameraType);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   185
	v->camera = new Camera(Vector3(ex, ey, ez),
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   186
		Vector3(px, py, pz), Vector3(ux, uy, uz), Vector3(vx, vy, vz));
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   187
	return (PyObject*)v;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   188
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   189
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   190
static void Camera_Destructor(PyObject* self)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   191
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   192
	delete ((CameraObject *)self)->camera;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   193
	PyObject_Del(self);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   194
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   195
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   196
static PyObject *Camera_Getattr(PyObject *self, char *name)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   197
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   198
	return Py_FindMethod(CameraMethods, self, name);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   199
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   200
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   201
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   202
static PyObject *Camera_setEye(PyObject* self, PyObject* args)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   203
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   204
	PyObject *TEye = NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   205
	Float ex=0.0,  ey=0.0, ez=10.0;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   206
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   207
	if (!PyArg_ParseTuple(args, "O!", &PyTuple_Type, &TEye))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   208
		return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   209
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   210
	if (TEye)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   211
		if (!PyArg_ParseTuple(TEye, "fff", &ex, &ey, &ez))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   212
			return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   213
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   214
	((CameraObject *)self)->camera->setEye(Vector3(ex, ey, ez));
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   215
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   216
	Py_INCREF(Py_None);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   217
	return Py_None;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   218
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   219
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   220
static PyObject *Camera_rotate(PyObject* self, PyObject* args)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   221
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   222
	PyObject *Tq = NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   223
	Float qa, qb, qc, qd;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   224
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   225
	if (!PyArg_ParseTuple(args, "O!", &PyTuple_Type, &Tq))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   226
		return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   227
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   228
	if (!PyArg_ParseTuple(Tq, "ffff", &qa, &qb, &qc, &qd))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   229
		return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   230
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   231
	((CameraObject *)self)->camera->rotate(Quaternion(qa, qb, qc, qd).normalize());
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   232
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   233
	Py_INCREF(Py_None);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   234
	return Py_None;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   235
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   236
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   237
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
   238
//=========================== 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
   239
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   240
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
   241
	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
   242
	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
   243
} 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
   244
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   245
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
   246
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
   247
static PyObject *Material_Getattr(PyObject *self, char *name);
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   248
static PyObject *Material_setPhong(PyObject* self, PyObject* args);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   249
static PyObject *Material_setReflectivity(PyObject* self, PyObject* args);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   250
static PyObject *Material_setTransmissivity(PyObject* self, PyObject* args);
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   251
static PyObject *Material_setSmooth(PyObject* self, PyObject* args);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   252
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   253
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
   254
	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
   255
	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
   256
	"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
   257
	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
   258
	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
   259
	/* 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
   260
	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
   261
	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
   262
	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
   263
	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
   264
	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
   265
	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
   266
	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
   267
	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
   268
	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
   269
	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
   270
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   271
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   272
static PyMethodDef MaterialMethods[] = {
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   273
	{"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
   274
	{"setReflectivity", (PyCFunction)Material_setReflectivity, METH_VARARGS, "Set reflectivity."},
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   275
	{"setTransmissivity", (PyCFunction)Material_setTransmissivity, METH_VARARGS, "Set transmissivity and refraction index."},
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   276
	{"setSmooth", (PyCFunction)Material_setSmooth, METH_VARARGS, "Set triangle smoothing."},
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   277
	{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
   278
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   279
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   280
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
   281
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   282
	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
   283
	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
   284
	PyObject *TCol = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   285
	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
   286
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   287
	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
   288
		&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
   289
		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
   290
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   291
	if (TCol)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   292
		if (!PyArg_ParseTuple(TCol, "fff", &cr, &cg, &cb))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   293
			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
   294
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   295
	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
   296
	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
   297
	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
   298
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   299
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   300
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
   301
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   302
	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
   303
	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
   304
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   305
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   306
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
   307
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   308
	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
   309
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   310
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   311
static PyObject *Material_setPhong(PyObject* self, PyObject* args)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   312
{
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   313
	Float amb, dif, spec, shin = 0.5;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   314
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   315
	if (!PyArg_ParseTuple(args, "fff|f", &amb, &dif, &spec, &shin))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   316
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   317
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   318
	((MaterialObject *)self)->material->setPhong(amb, dif, spec, shin);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   319
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   320
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   321
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   322
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   323
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   324
static PyObject *Material_setReflectivity(PyObject* self, PyObject* args)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   325
{
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   326
	Float refl;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   327
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   328
	if (!PyArg_ParseTuple(args, "f", &refl))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   329
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   330
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   331
	((MaterialObject *)self)->material->setReflectivity(refl);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   332
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   333
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   334
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   335
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   336
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   337
static PyObject *Material_setTransmissivity(PyObject* self, PyObject* args)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   338
{
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   339
	Float trans, rindex = 1.3;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   340
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   341
	if (!PyArg_ParseTuple(args, "f|f", &trans, &rindex))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   342
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   343
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   344
	((MaterialObject *)self)->material->setTransmissivity(trans, rindex);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   345
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   346
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   347
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   348
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   349
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   350
static PyObject* Material_setSmooth(PyObject* self, PyObject* args)
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   351
{
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   352
	int smooth;
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   353
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   354
	if (!PyArg_ParseTuple(args, "i", &smooth))
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   355
		return NULL;
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   356
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   357
	((MaterialObject *)self)->material->setSmooth(smooth);
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   358
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   359
	Py_INCREF(Py_None);
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   360
	return Py_None;
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   361
}
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   362
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   363
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   364
//=========================== NormalVertex Object ===========================
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   365
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   366
typedef struct {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   367
	PyObject_HEAD
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   368
	NormalVertex *nvertex;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   369
} NormalVertexObject;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   370
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   371
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
   372
static void NormalVertex_Destructor(PyObject* self);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   373
static PyObject *NormalVertex_Getattr(PyObject *self, char *name);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   374
static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   375
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   376
static PyTypeObject NormalVertexType = {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   377
	PyObject_HEAD_INIT(NULL)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   378
	0,				/*ob_size*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   379
	"NormalVertex",			/*tp_name*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   380
	sizeof(NormalVertexObject),		/*tp_basicsize*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   381
	0,				/*tp_itemsize*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   382
	/* methods */
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   383
	NormalVertex_Destructor,		/*tp_dealloc*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   384
	0,				/*tp_print*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   385
	NormalVertex_Getattr,			/*tp_getattr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   386
	0,				/*tp_setattr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   387
	0,				/*tp_compare*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   388
	0,				/*tp_repr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   389
	0,				/*tp_as_number*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   390
	0,				/*tp_as_sequence*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   391
	0,				/*tp_as_mapping*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   392
	0,				/*tp_hash */
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   393
};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   394
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   395
static PyMethodDef NormalVertexMethods[] = {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   396
	{"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
   397
	{NULL, NULL}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   398
};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   399
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   400
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
   401
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   402
	NormalVertexObject *v;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   403
	static char *kwdlist[] = {"vector", "normal", NULL};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   404
	PyObject *TVer = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   405
	PyObject *TNor = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   406
	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
   407
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   408
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "O|O!", kwdlist,
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   409
		&TVer, &PyTuple_Type, &TNor))
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   410
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   411
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   412
	if (!TNor && TVer->ob_type == &NormalVertexType)
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   413
	{
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   414
		v = PyObject_New(NormalVertexObject, &NormalVertexType);
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   415
		v->nvertex = new NormalVertex(((NormalVertexObject*)TVer)->nvertex);
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   416
	}
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   417
	else
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   418
	{
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   419
		if (!PyArg_ParseTuple(TVer, "fff", &vx, &vy, &vz))
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   420
			return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   421
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   422
		if (TNor)
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   423
			if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   424
				return NULL;
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   425
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   426
		v = PyObject_New(NormalVertexObject, &NormalVertexType);
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   427
		v->nvertex = new NormalVertex(Vector3(vx, vy, vz), Vector3(nx, ny, nz));
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   428
	}
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   429
	return (PyObject*)v;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   430
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   431
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   432
static void NormalVertex_Destructor(PyObject* self)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   433
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   434
	delete ((NormalVertexObject *)self)->nvertex;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   435
	PyObject_Del(self);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   436
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   437
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   438
static PyObject *NormalVertex_Getattr(PyObject *self, char *name)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   439
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   440
	return Py_FindMethod(NormalVertexMethods, self, name);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   441
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   442
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   443
static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   444
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   445
	PyObject *TNor = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   446
	Float nx, ny, nz;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   447
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   448
	if (!PyArg_ParseTuple(args, "O!", &PyTuple_Type, &TNor))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   449
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   450
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   451
	if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   452
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   453
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   454
	((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
   455
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   456
	Py_INCREF(Py_None);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   457
	return Py_None;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   458
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   459
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
   460
//=========================== 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
   461
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
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
   463
	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
   464
	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
   465
} 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
   466
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
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
   468
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
   469
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
   470
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
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
   472
	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
   473
	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
   474
	"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
   475
	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
   476
	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
   477
	/* 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
   478
	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
   479
	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
   480
	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
   481
	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
   482
	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
   483
	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
   484
	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
   485
	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
   486
	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
   487
	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
   488
};
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
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
   491
	{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
   492
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   493
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
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
   495
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   496
	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
   497
	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
   498
	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
   499
	PyObject *TCentre = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   500
	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
   501
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
	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
   503
		&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
   504
		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
   505
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
	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
   507
		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
   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
	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
   510
	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
   511
	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
   512
	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
   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 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
   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
	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
   518
	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
   519
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   520
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   521
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
   522
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   523
	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
   524
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   525
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
   526
//=========================== 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
   527
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   528
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
   529
	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
   530
	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
   531
} 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
   532
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
   533
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
   534
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
   535
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
   536
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
   537
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
   538
	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
   539
	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
   540
	"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
   541
	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
   542
	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
   543
	/* 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
   544
	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
   545
	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
   546
	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
   547
	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
   548
	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
   549
	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
   550
	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
   551
	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
   552
	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
   553
	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
   554
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   555
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   556
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
   557
	{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
   558
};
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
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   560
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
   561
{
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
   562
	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
   563
	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
   564
	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
   565
	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
   566
	PyObject *TH = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   567
	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
   568
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
   569
	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
   570
		&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
   571
		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
   572
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
   573
	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
   574
		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
   575
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   576
	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
   577
		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
   578
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
   579
	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
   580
	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
   581
	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
   582
	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
   583
}
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
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
   585
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
   586
{
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
   587
	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
   588
	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
   589
}
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
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
   591
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
   592
{
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
   593
	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
   594
}
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
//=========================== 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
   597
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
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
   599
	PyObject_HEAD
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   600
	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
   601
} 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
   602
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
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
   604
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
   605
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
   606
static PyObject *Triangle_getNormal(PyObject* self, PyObject* args);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   607
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
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
   609
	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
   610
	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
   611
	"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
   612
	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
   613
	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
   614
	/* 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
   615
	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
   616
	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
   617
	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
   618
	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
   619
	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
   620
	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
   621
	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
   622
	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
   623
	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
   624
	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
   625
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   626
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   627
static PyMethodDef TriangleMethods[] = {
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   628
	{"getNormal", (PyCFunction)Triangle_getNormal, METH_NOARGS, "Get normal of whole triangle."},
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   629
	{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
   630
};
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
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
   633
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   634
	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
   635
	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
   636
	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
   637
	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
   638
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
	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
   640
		&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
   641
		&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
   642
		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
   643
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
	v = PyObject_New(TriangleObject, &TriangleType);
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   645
	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
   646
	Py_INCREF(material);
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   647
	Py_INCREF(A);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   648
	Py_INCREF(B);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   649
	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
   650
	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
   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
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
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
   654
{
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   655
	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
   656
	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
   657
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   658
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
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
   660
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   661
	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
   662
}
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
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   664
static PyObject* Triangle_getNormal(PyObject* self, PyObject* args)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   665
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   666
	PyObject *obj;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   667
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   668
	Vector3 N = ((TriangleObject *)self)->triangle->getNormal();
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   669
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   670
	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
   671
	return obj;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   672
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   673
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
   674
//=========================== 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
   675
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
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
   677
	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
   678
	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
   679
	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
   680
} 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
   681
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   682
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
   683
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
   684
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
   685
static PyObject *Raytracer_render(PyObject* self, PyObject* args);
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   686
static PyObject *Raytracer_setcamera(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
   687
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
   688
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
   689
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
   690
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   691
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
   692
	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
   693
	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
   694
	"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
   695
	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
   696
	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
   697
	/* 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
   698
	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
   699
	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
   700
	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
   701
	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
   702
	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
   703
	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
   704
	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
   705
	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
   706
	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
   707
	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
   708
};
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
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
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
   711
	{"render", (PyCFunction)Raytracer_render, METH_VARARGS, "Render scene and return image data."},
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   712
	{"setcamera", (PyCFunction)Raytracer_setcamera, METH_VARARGS, "Set camera for the scene."},
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
   713
	{"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
   714
	{"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
   715
	{"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
   716
		"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
   717
	{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
   718
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   719
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   720
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
   721
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   722
	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
   723
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   724
	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
   725
		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
   726
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   727
	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
   728
	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
   729
	v->children = new vector<PyObject*>();
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 14
diff changeset
   730
	v->raytracer->setCamera(new Camera());
36
b490093b0ac3 new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents: 35
diff changeset
   731
	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
   732
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   733
	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
   734
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   735
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   736
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
   737
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   738
	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
   739
	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
   740
		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
   741
		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
   742
	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
   743
	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
   744
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   745
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   746
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
   747
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   748
	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
   749
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   750
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   751
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
   752
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   753
	int w = 0, h = 0;
60
a23b5089b9c3 moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents: 59
diff changeset
   754
	unsigned char *chardata;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   755
	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
   756
	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
   757
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   758
	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
   759
		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
   760
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   761
	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
   762
	((RaytracerObject *)self)->raytracer->getTop()->optimize();
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   763
	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
   764
	DefaultSampler sampler(data, w, h);
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
   765
	((RaytracerObject *)self)->raytracer->setSampler(&sampler);
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
   766
	((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
   767
	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
   768
		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
   769
		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
   770
	}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   771
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   772
	// convert data to char
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   773
	printf("[pyrit] Converting image data (float to char)\n");
60
a23b5089b9c3 moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents: 59
diff changeset
   774
	chardata = (unsigned char *) malloc(w*h*3);
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   775
	Float *d = data;
60
a23b5089b9c3 moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents: 59
diff changeset
   776
	for (unsigned char *c = chardata; c != chardata + w*h*3; c++, d++) {
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   777
		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
   778
			*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
   779
		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
   780
			*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
   781
	}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   782
	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
   783
	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
   784
	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
   785
	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
   786
	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
   787
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   788
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   789
static PyObject* Raytracer_setcamera(PyObject* self, PyObject* args)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   790
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   791
	CameraObject *cam;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   792
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   793
	if (!PyArg_ParseTuple(args, "O!", &CameraType, &cam))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   794
		return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   795
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   796
	((RaytracerObject *)self)->raytracer->setCamera(cam->camera);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   797
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   798
	Py_INCREF(cam);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   799
	Py_INCREF(Py_None);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   800
	return Py_None;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   801
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   802
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
   803
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
   804
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   805
	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
   806
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   807
	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
   808
		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
   809
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   810
	((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
   811
		((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
   812
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   813
	((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
   814
	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
   815
	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
   816
	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
   817
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   818
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   819
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
   820
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   821
	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
   822
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   823
	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
   824
		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
   825
	((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
   826
	((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
   827
	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
   828
	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
   829
	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
   830
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   831
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   832
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
   833
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   834
	int samples = 0;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   835
	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
   836
	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
   837
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   838
	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
   839
		&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
   840
		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
   841
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   842
	((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
   843
	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
   844
	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
   845
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   846
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   847
//=========================== 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
   848
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   849
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
   850
	{"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
   851
		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
   852
	{"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
   853
		METH_VARARGS | METH_KEYWORDS, "Light source object constructor."},
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   854
	{"Camera", (PyCFunction) Camera_Constructor,
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   855
		METH_VARARGS | METH_KEYWORDS, "Camera object constructor."},
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   856
	{"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
   857
		METH_VARARGS | METH_KEYWORDS, "Material object constructor."},
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   858
	{"NormalVertex", (PyCFunction) NormalVertex_Constructor,
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   859
		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
   860
	{"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
   861
		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
   862
	{"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
   863
		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
   864
	{"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
   865
		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
   866
	{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
   867
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   868
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   869
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   870
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
   871
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   872
	Py_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
   873
}