include/shapes.h
author Radek Brich <radek.brich@devl.cz>
Tue, 06 May 2008 09:39:58 +0200
branchpyrit
changeset 93 96d65f841791
parent 92 9af5c039b678
child 94 4c8abb8977dc
permissions -rw-r--r--
more build script tuning make all float constants single precision solve many warnings from msvc and gcc with various -W... flags add common.cc file for dbgmsg() function witch apparently cannot be inlined fix python module building with msvc, add manifest file handling remove forgotten RenderrowData class add stanford models download script for windows (.bat)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
/*
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
 * shapes.h: shape classes
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
 *
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
 * This file is part of Pyrit Ray Tracer.
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
 *
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
 * Copyright 2006, 2007, 2008  Radek Brich
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
 *
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
 * of this software and associated documentation files (the "Software"), to deal
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
 * in the Software without restriction, including without limitation the rights
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
 * copies of the Software, and to permit persons to whom the Software is
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
 * furnished to do so, subject to the following conditions:
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
 *
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
 * The above copyright notice and this permission notice shall be included in
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
 * all copies or substantial portions of the Software.
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
 *
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
 * THE SOFTWARE.
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
 */
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
#ifndef SHAPES_H
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
#define SHAPES_H
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
#include "common.h"
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
#include "scene.h"
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents: 78
diff changeset
    32
#include "material.h"
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
/*
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
triangle intersection alghoritm
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
options are:
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
TRI_PLUCKER
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
TRI_BARI
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
TRI_BARI_PRE
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
*/
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
#if !defined(TRI_PLUCKER) && !defined(TRI_BARI) && !defined(TRI_BARI_PRE)
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
#	define TRI_BARI_PRE
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
#endif
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
/**
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
 * shape
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
 */
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
class Shape
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
{
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
public:
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    51
	Material *material;
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
    52
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
	Shape() {};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
	virtual ~Shape() {};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
	// first intersection point
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
	virtual bool intersect(const Ray &ray, Float &dist) const = 0;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    59
#ifndef NO_SIMD
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    60
	virtual mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const
84
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 82
diff changeset
    61
	{
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    62
		mfloat4 results;
85
907a634e5c02 implement triangle packet intersection
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    63
		((int*)&results)[0] = intersect(rays[0], ((float*)&dists)[0]) ? -1 : 0;
907a634e5c02 implement triangle packet intersection
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    64
		((int*)&results)[1] = intersect(rays[1], ((float*)&dists)[1]) ? -1 : 0;
907a634e5c02 implement triangle packet intersection
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    65
		((int*)&results)[2] = intersect(rays[2], ((float*)&dists)[2]) ? -1 : 0;
907a634e5c02 implement triangle packet intersection
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    66
		((int*)&results)[3] = intersect(rays[3], ((float*)&dists)[3]) ? -1 : 0;
907a634e5c02 implement triangle packet intersection
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    67
		return results;
84
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 82
diff changeset
    68
	};
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
    69
#endif
84
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 82
diff changeset
    70
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    71
	// all intersections (only for CSG)
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    72
	virtual bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const = 0;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    73
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    74
	// intersection with AABB
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    75
	virtual bool intersect_bbox(const BBox &bbox) const = 0;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    76
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    77
	// normal at point P
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
    78
	virtual const Vector normal(const Vector &P) const = 0;
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    79
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    80
	virtual BBox get_bbox() const = 0;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    81
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    82
	virtual ostream & dump(ostream &st) const = 0;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    83
};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    84
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    85
/**
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    86
 * list of shapes
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    87
 */
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    88
typedef vector<Shape*> ShapeList;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    89
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    90
/**
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    91
 * sphere shape
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    92
 */
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    93
class Sphere: public Shape
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    94
{
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
    95
	Vector center;
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    96
	Float radius;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    97
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    98
	Float sqr_radius;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    99
	Float inv_radius;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   100
public:
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   101
	Sphere(const Vector &acenter, const Float aradius, Material *amaterial):
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   102
		center(acenter), radius(aradius),
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   103
		sqr_radius(aradius*aradius), inv_radius(1.0f/aradius)
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   104
		{ material = amaterial; }
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   105
	bool intersect(const Ray &ray, Float &dist) const;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   106
	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   107
	bool intersect_bbox(const BBox &bbox) const;
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   108
	const Vector normal(const Vector &P) const { return (P - center) * inv_radius; };
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   109
	BBox get_bbox() const;
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   110
	const Vector getCenter() const { return center; };
84
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 82
diff changeset
   111
	Float getRadius() const { return radius; };
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   112
	ostream & dump(ostream &st) const;
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   113
#ifndef NO_SIMD
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   114
	mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const;
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   115
#endif
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   116
};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   117
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   118
/**
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   119
 * box shape
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   120
 */
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   121
class Box: public Shape
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   122
{
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   123
	Vector L;
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   124
	Vector H;
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   125
public:
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   126
	Box(const Vector &aL, const Vector &aH, Material *amaterial): L(aL), H(aH)
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   127
	{
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   128
		for (int i = 0; i < 3; i++)
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   129
			if (L[i] > H[i])
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   130
				swap(L[i], H[i]);
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   131
		material = amaterial;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   132
	};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   133
	bool intersect(const Ray &ray, Float &dist) const;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   134
	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const { return false; };
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   135
	bool intersect_bbox(const BBox &bbox) const;
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   136
	const Vector normal(const Vector &P) const;
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   137
	BBox get_bbox() const { return BBox(L, H); };
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   138
	const Vector getL() const { return L; };
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   139
	const Vector getH() const { return H; };
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   140
	ostream & dump(ostream &st) const;
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   141
#ifndef NO_SIMD
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   142
	mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const;
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   143
#endif
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   144
};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   145
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   146
/**
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   147
 * triangle vertex
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   148
 */
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   149
class Vertex
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   150
{
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   151
public:
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   152
	Vector P;
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   153
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   154
	Vertex(const Vector &aP): P(aP) {};
82
930a2d3ecaed prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents: 79
diff changeset
   155
	virtual ~Vertex() {};
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   156
	virtual ostream & dump(ostream &st) const;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   157
};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   158
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   159
/**
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   160
 * triangle vertex with normal
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   161
 */
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   162
class NormalVertex: public Vertex
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   163
{
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   164
public:
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   165
	Vector N;
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   166
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   167
	NormalVertex(const NormalVertex *v): Vertex(v->P), N(v->N) {};
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   168
	NormalVertex(const Vector &aP): Vertex(aP) {};
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   169
	NormalVertex(const Vector &aP, const Vector &aN): Vertex(aP), N(aN) {};
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   170
	const Vector &getNormal() { return N; };
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   171
	void setNormal(const Vector &aN) { N = aN; };
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   172
	ostream & dump(ostream &st) const;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   173
};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   174
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   175
/**
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   176
 * triangle shape
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   177
 */
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   178
class Triangle: public Shape
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   179
{
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   180
	Vector N;
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   181
#ifdef TRI_BARI_PRE
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   182
	Float nu, nv, nd;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   183
	Float bnu, bnv;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   184
	Float cnu, cnv;
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   185
	int k; // dominant axis
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   186
#endif
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   187
#ifdef TRI_BARI
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   188
	int k; // dominant axis
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   189
#endif
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   190
#ifdef TRI_PLUCKER
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   191
	Float pla[6], plb[6], plc[6];
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   192
#endif
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   193
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   194
	const Vector smooth_normal(const Vector &P) const
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   195
	{
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   196
#ifdef TRI_BARI_PRE
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   197
		const Vector &NA = static_cast<NormalVertex*>(A)->N;
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   198
		const Vector &NB = static_cast<NormalVertex*>(B)->N;
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   199
		const Vector &NC = static_cast<NormalVertex*>(C)->N;
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   200
		static const int modulo3[5] = {0,1,2,0,1};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   201
		register const int ku = modulo3[k+1];
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   202
		register const int kv = modulo3[k+2];
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   203
		const Float pu = P[ku] - A->P[ku];
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   204
		const Float pv = P[kv] - A->P[kv];
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   205
		const Float u = pv * bnu + pu * bnv;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   206
		const Float v = pu * cnv + pv * cnu;
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   207
		Vector n = NA + u * (NB - NA) + v * (NC - NA);
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   208
		n.normalize();
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   209
		return n;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   210
#else
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   211
		return N; // not implemented for other algorithms
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   212
#endif
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   213
	};
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   214
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   215
public:
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   216
	Vertex *A, *B, *C;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   217
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   218
	Triangle() {};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   219
	Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial);
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   220
	bool intersect(const Ray &ray, Float &dist) const;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   221
	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const {return false;};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   222
	bool intersect_bbox(const BBox &bbox) const;
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   223
	const Vector normal(const Vector &P) const { return (material->smooth ? smooth_normal(P) : N); };
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   224
	const Vector getNormal() const { return N; };
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   225
	BBox get_bbox() const;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   226
	ostream & dump(ostream &st) const;
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   227
#if !defined(NO_SIMD) && defined(TRI_BARI_PRE)
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   228
	mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const;
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 87
diff changeset
   229
#endif
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   230
};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   231
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   232
template <class T> class Array
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   233
{
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   234
	T *array;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   235
public:
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   236
	Array(int n) { array = new T[n]; };
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   237
	~Array() { delete[] array; };
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   238
	const T &operator[](int i) const { return array[i]; };
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   239
};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   240
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   241
typedef Array<Vertex> VertexArray;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   242
typedef Array<NormalVertex> NormalVertexArray;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   243
typedef Array<Triangle> TriangleArray;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   244
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   245
#endif