src/raytracermodule.cc
author Radek Brich <radek.brich@devl.cz>
Sat, 12 Apr 2008 02:02:45 +0200
branchpyrit
changeset 68 2c154aad7f33
parent 60 a23b5089b9c3
child 69 303583d2fb97
permissions -rw-r--r--
added detection of optimal CPU flags for both GCC and IntelC
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);
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
   251
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
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
   253
	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
   254
	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
   255
	"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
   256
	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
   257
	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
   258
	/* 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
   259
	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
   260
	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
   261
	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
   262
	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
   263
	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
   264
	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
   265
	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
   266
	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
   267
	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
   268
	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
   269
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   270
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
static PyMethodDef MaterialMethods[] = {
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   272
	{"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
   273
	{"setReflectivity", (PyCFunction)Material_setReflectivity, METH_VARARGS, "Set reflectivity."},
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   274
	{"setTransmissivity", (PyCFunction)Material_setTransmissivity, METH_VARARGS, "Set transmissivity and refraction index."},
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   275
	{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
   276
};
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
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
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
   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
	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
   281
	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
   282
	PyObject *TCol = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   283
	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
   284
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   285
	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
   286
		&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
   287
		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
   288
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   289
	if (TCol)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   290
		if (!PyArg_ParseTuple(TCol, "fff", &cr, &cg, &cb))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   291
			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
   292
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   293
	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
   294
	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
   295
	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
   296
}
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
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
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
   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
	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
   301
	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
   302
}
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
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
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
   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
	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
   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
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   309
static PyObject *Material_setPhong(PyObject* self, PyObject* args)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   310
{
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   311
	Float amb, dif, spec, shin = 0.5;
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
	if (!PyArg_ParseTuple(args, "fff|f", &amb, &dif, &spec, &shin))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   314
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   315
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   316
	((MaterialObject *)self)->material->setPhong(amb, dif, spec, shin);
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
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   319
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   320
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   321
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   322
static PyObject *Material_setReflectivity(PyObject* self, PyObject* args)
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
	Float refl;
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
	if (!PyArg_ParseTuple(args, "f", &refl))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   327
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   328
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   329
	((MaterialObject *)self)->material->setReflectivity(refl);
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
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   332
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   333
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   334
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   335
static PyObject *Material_setTransmissivity(PyObject* self, PyObject* args)
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
	Float trans, rindex = 1.3;
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
	if (!PyArg_ParseTuple(args, "f|f", &trans, &rindex))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   340
		return NULL;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   341
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   342
	((MaterialObject *)self)->material->setTransmissivity(trans, rindex);
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
	Py_INCREF(Py_None);
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   345
	return Py_None;
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   346
}
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   347
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   348
//=========================== NormalVertex Object ===========================
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   349
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   350
typedef struct {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   351
	PyObject_HEAD
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   352
	NormalVertex *nvertex;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   353
} NormalVertexObject;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   354
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   355
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
   356
static void NormalVertex_Destructor(PyObject* self);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   357
static PyObject *NormalVertex_Getattr(PyObject *self, char *name);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   358
static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   359
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   360
static PyTypeObject NormalVertexType = {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   361
	PyObject_HEAD_INIT(NULL)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   362
	0,				/*ob_size*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   363
	"NormalVertex",			/*tp_name*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   364
	sizeof(NormalVertexObject),		/*tp_basicsize*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   365
	0,				/*tp_itemsize*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   366
	/* methods */
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   367
	NormalVertex_Destructor,		/*tp_dealloc*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   368
	0,				/*tp_print*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   369
	NormalVertex_Getattr,			/*tp_getattr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   370
	0,				/*tp_setattr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   371
	0,				/*tp_compare*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   372
	0,				/*tp_repr*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   373
	0,				/*tp_as_number*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   374
	0,				/*tp_as_sequence*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   375
	0,				/*tp_as_mapping*/
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   376
	0,				/*tp_hash */
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   377
};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   378
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   379
static PyMethodDef NormalVertexMethods[] = {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   380
	{"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
   381
	{NULL, NULL}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   382
};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   383
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   384
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
   385
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   386
	NormalVertexObject *v;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   387
	static char *kwdlist[] = {"vector", "normal", NULL};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   388
	PyObject *TVer = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   389
	PyObject *TNor = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   390
	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
   391
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   392
	if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!|O!", kwdlist,
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   393
		&PyTuple_Type, &TVer, &PyTuple_Type, &TNor))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   394
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   395
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   396
	if (!PyArg_ParseTuple(TVer, "fff", &vx, &vy, &vz))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   397
		return 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
	if (TNor)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   400
		if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   401
			return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   402
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   403
	v = PyObject_New(NormalVertexObject, &NormalVertexType);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   404
	v->nvertex = new NormalVertex(Vector3(vx, vy, vz), Vector3(nx, ny, nz));
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   405
	return (PyObject*)v;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   406
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   407
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   408
static void NormalVertex_Destructor(PyObject* self)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   409
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   410
	delete ((NormalVertexObject *)self)->nvertex;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   411
	PyObject_Del(self);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   412
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   413
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   414
static PyObject *NormalVertex_Getattr(PyObject *self, char *name)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   415
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   416
	return Py_FindMethod(NormalVertexMethods, self, name);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   417
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   418
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   419
static PyObject *NormalVertex_setNormal(PyObject* self, PyObject* args)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   420
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   421
	PyObject *TNor = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   422
	Float nx, ny, nz;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   423
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   424
	if (!PyArg_ParseTuple(args, "O!", &PyTuple_Type, &TNor))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   425
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   426
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   427
	if (!PyArg_ParseTuple(TNor, "fff", &nx, &ny, &nz))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   428
		return NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   429
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   430
	((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
   431
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   432
	Py_INCREF(Py_None);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   433
	return Py_None;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   434
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   435
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
   436
//=========================== 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
   437
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   438
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
   439
	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
   440
	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
   441
} 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
   442
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   443
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
   444
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
   445
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
   446
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   447
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
   448
	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
   449
	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
   450
	"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
   451
	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
   452
	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
   453
	/* 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
   454
	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
   455
	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
   456
	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
   457
	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
   458
	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
   459
	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
   460
	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
   461
	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
   462
	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
   463
	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
   464
};
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
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
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
   467
	{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
   468
};
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
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
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
   471
{
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
	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
   473
	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
   474
	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
   475
	PyObject *TCentre = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   476
	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
   477
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
	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
   479
		&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
   480
		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
   481
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   482
	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
   483
		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
   484
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
	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
   486
	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
   487
	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
   488
	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
   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
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
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
   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
	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
   494
	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
   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
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   497
static PyObject *Sphere_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
   498
{
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
	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
   500
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   501
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
   502
//=========================== 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
   503
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
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
   505
	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
   506
	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
   507
} 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
   508
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
   509
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
   510
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
   511
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
   512
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
   513
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
   514
	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
   515
	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
   516
	"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
   517
	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
   518
	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
   519
	/* 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
   520
	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
   521
	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
   522
	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
   523
	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
   524
	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
   525
	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
   526
	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
   527
	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
   528
	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
   529
	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
   530
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   531
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
   532
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
   533
	{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
   534
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   535
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
   536
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
   537
{
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
   538
	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
   539
	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
   540
	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
   541
	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
   542
	PyObject *TH = NULL;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   543
	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
   544
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
   545
	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
   546
		&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
   547
		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
   548
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
   549
	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
   550
		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
   551
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
   552
	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
   553
		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
   554
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
   555
	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
   556
	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
   557
	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
   558
	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
   559
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   560
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
   561
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
   562
{
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   563
	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
   564
	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
   565
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   566
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   567
static 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
   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
	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
   570
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   571
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   572
//=========================== 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
   573
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
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
   575
	PyObject_HEAD
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   576
	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
   577
} 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
   578
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   579
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
   580
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
   581
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
   582
static PyObject *Triangle_getNormal(PyObject* self, PyObject* args);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   583
static PyObject *Triangle_setSmooth(PyObject* self, PyObject* args);
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   584
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   585
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
   586
	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
   587
	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
   588
	"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
   589
	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
   590
	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
   591
	/* 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
   592
	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
   593
	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
   594
	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
   595
	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
   596
	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
   597
	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
   598
	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
   599
	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
   600
	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
   601
	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
   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
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 PyMethodDef TriangleMethods[] = {
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   605
	{"getNormal", (PyCFunction)Triangle_getNormal, METH_NOARGS, "Get normal of whole triangle."},
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   606
	{"setSmooth", (PyCFunction)Triangle_setSmooth, METH_NOARGS, "Set the triangle smooth."},
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   607
	{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
   608
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   609
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
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
   611
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   612
	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
   613
	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
   614
	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
   615
	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
   616
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
	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
   618
		&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
   619
		&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
   620
		return NULL;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   621
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
	v = PyObject_New(TriangleObject, &TriangleType);
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   623
	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
   624
	Py_INCREF(material);
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   625
	Py_INCREF(A);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   626
	Py_INCREF(B);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   627
	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
   628
	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
   629
}
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
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
   632
{
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   633
	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
   634
	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
   635
}
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
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   637
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
   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
	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
   640
}
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
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   642
static PyObject* Triangle_getNormal(PyObject* self, PyObject* args)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   643
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   644
	PyObject *obj;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   645
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   646
	Vector3 N = ((TriangleObject *)self)->triangle->getNormal();
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   647
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   648
	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
   649
	return obj;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   650
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   651
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   652
static PyObject* Triangle_setSmooth(PyObject* self, PyObject* args)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   653
{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   654
	((TriangleObject *)self)->triangle->setSmooth();
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   655
	Py_INCREF(Py_None);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   656
	return Py_None;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   657
}
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   658
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   659
//=========================== 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
   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
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
   662
	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
   663
	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
   664
	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
   665
} 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
   666
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   667
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
   668
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
   669
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
   670
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
   671
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
   672
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
   673
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
   674
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
   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
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
   677
	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
   678
	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
   679
	"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
   680
	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
   681
	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
   682
	/* 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
   683
	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
   684
	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
   685
	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
   686
	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
   687
	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
   688
	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
   689
	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
   690
	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
   691
	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
   692
	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
   693
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   694
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
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
   696
	{"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
   697
	{"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
   698
	{"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
   699
	{"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
   700
	{"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
   701
		"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
   702
	{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
   703
};
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
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
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
   706
{
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
	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
   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
	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
   710
		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
   711
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   712
	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
   713
	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
   714
	v->children = new vector<PyObject*>();
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 14
diff changeset
   715
	v->raytracer->setCamera(new Camera());
36
b490093b0ac3 new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents: 35
diff changeset
   716
	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
   717
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
	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
   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
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
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
   722
{
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
	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
   724
	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
   725
		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
   726
		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
   727
	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
   728
	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
   729
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   730
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   731
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
   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 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
   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 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
   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
	int w = 0, h = 0;
60
a23b5089b9c3 moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents: 59
diff changeset
   739
	unsigned char *chardata;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   740
	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
   741
	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
   742
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
	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
   744
		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
   745
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   746
	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
   747
	((RaytracerObject *)self)->raytracer->getTop()->optimize();
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   748
	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
   749
	DefaultSampler sampler(data, w, h);
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
   750
	((RaytracerObject *)self)->raytracer->setSampler(&sampler);
320d5d466864 move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
   751
	((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
   752
	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
   753
		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
   754
		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
   755
	}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   756
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
	// convert data to char
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
   758
	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
   759
	chardata = (unsigned char *) malloc(w*h*3);
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   760
	Float *d = data;
60
a23b5089b9c3 moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents: 59
diff changeset
   761
	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
   762
		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
   763
			*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
   764
		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
   765
			*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
   766
	}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   767
	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
   768
	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
   769
	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
   770
	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
   771
	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
   772
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   773
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   774
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
   775
{
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   776
	CameraObject *cam;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   777
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   778
	if (!PyArg_ParseTuple(args, "O!", &CameraType, &cam))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   779
		return NULL;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   780
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   781
	((RaytracerObject *)self)->raytracer->setCamera(cam->camera);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   782
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   783
	Py_INCREF(cam);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   784
	Py_INCREF(Py_None);
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   785
	return Py_None;
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   786
}
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   787
0
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   788
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
   789
{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   790
	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
   791
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   792
	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
   793
		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
   794
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   795
	((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
   796
		((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
   797
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   798
	((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
   799
	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
   800
	Py_INCREF(Py_None);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   801
	return Py_None;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   802
}
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   803
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   804
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
   805
{
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
	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
   807
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
	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
   809
		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
   810
	((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
   811
	((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
   812
	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
   813
	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
   814
	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
   815
}
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
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
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
   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
	int samples = 0;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   820
	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
   821
	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
   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_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
   824
		&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
   825
		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
   826
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
	((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
   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
//=========================== 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
   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
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
   835
	{"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
   836
		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
   837
	{"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
   838
		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
   839
	{"Camera", (PyCFunction) Camera_Constructor,
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   840
		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
   841
	{"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
   842
		METH_VARARGS | METH_KEYWORDS, "Material object constructor."},
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   843
	{"NormalVertex", (PyCFunction) NormalVertex_Constructor,
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
   844
		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
   845
	{"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
   846
		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
   847
	{"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
   848
		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
   849
	{"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
   850
		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
   851
	{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
   852
};
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
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   854
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   855
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
   856
{
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
	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
   858
}