include/vector.h
author Radek Brich <radek.brich@devl.cz>
Tue, 29 Apr 2008 13:56:29 +0200
branchpyrit
changeset 89 fcf1487b398b
parent 87 1081e3dd3f3e
child 91 9d66d323c354
permissions -rw-r--r--
use SSE for float to char image buffer conversion
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: 34
diff changeset
     2
 * vector.h: Vector3 class with Colour alias
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
     3
 *
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
     4
 * This file is part of Pyrit Ray Tracer.
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
     5
 *
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
     6
 * Copyright 2006, 2007  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: 34
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: 34
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: 34
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: 34
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: 34
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: 34
diff changeset
    13
 * furnished to do so, subject to the following conditions:
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
    14
 *
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 34
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: 34
diff changeset
    16
 * all copies or substantial portions of the Software.
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
    17
 *
3763b26244f0 MIT license for sources
Radek Brich <radek.brich@devl.cz>
parents: 34
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: 34
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: 34
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: 34
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: 34
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: 34
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: 34
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
#ifndef VECTOR_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
    28
#define VECTOR_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
    29
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
#include <math.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
    31
#include <iostream>
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
    33
#include "common.h"
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
    34
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
    35
using namespace std;
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
46
6493fb65f0b1 Doxygen
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
    37
/**
6493fb65f0b1 Doxygen
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
    38
 * three cell vector
6493fb65f0b1 Doxygen
Radek Brich <radek.brich@devl.cz>
parents: 44
diff changeset
    39
 */
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
    40
class Vector3
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
{
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
public:
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
	// 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
    44
	union {
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
		struct {
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
    46
			Float x, y, z;
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
    47
		};
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
		struct {
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
    49
			Float r, g, b;
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
    50
		};
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
    51
		Float cell[3];
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
    52
	};
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
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
	// constructors
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
	Vector3(): x(0.0f), y(0.0f), z(0.0f) {};
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
    56
	Vector3(Float ax, Float ay, Float az): x(ax), y(ay), z(az) {};
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
    57
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
	// index operator
25
b8232edee786 tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    59
	const Float &operator[](int index) const { return cell[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
    60
25
b8232edee786 tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    61
	bool operator==(Vector3 &v) const { return x==v.x && y==v.y && z==v.z; };
21
79b516a3803d naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents: 14
diff changeset
    62
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
    63
	// normalize
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
	Vector3 normalize()
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
	{
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
    66
		Float f = 1.0f / mag();
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
    67
		x *= f;
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
		y *= f;
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
		z *= f;
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
		return *this;
74
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
    71
	};
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
    72
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
	// get normalized copy
83
e3a2a5b26abb vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents: 78
diff changeset
    74
	friend Vector3 normalize(Vector3 &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
    75
	{
83
e3a2a5b26abb vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents: 78
diff changeset
    76
		const Float f = 1.0f / v.mag();
e3a2a5b26abb vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents: 78
diff changeset
    77
		return v * f;
74
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
    78
	};
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
    79
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
	// square magnitude, magnitude
74
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
    81
	Float mag2() const	{ return x * x + y * y + z * z; };
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
    82
	Float mag() const	{ return sqrtf(mag2()); };
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
    83
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
	// negative
74
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
    85
	Vector3 operator-() const { return Vector3(-x, -y, -z); };
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
    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
	// accumulate
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
	Vector3 operator+=(const Vector3 &v)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    89
	{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    90
		x += v.x;
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
		y += v.y;
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
		z += v.z;
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
		return *this;
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
	};
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
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 25
diff changeset
    96
	// cut
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 25
diff changeset
    97
	Vector3 operator/=(const Float &f)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 25
diff changeset
    98
	{
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 25
diff changeset
    99
		x /= f;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 25
diff changeset
   100
		y /= f;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 25
diff changeset
   101
		z /= f;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 25
diff changeset
   102
		return *this;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 25
diff changeset
   103
	};
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 25
diff changeset
   104
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
   105
	// sum
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
	friend Vector3 operator+(const Vector3 &a, const Vector3 &b)
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
	{
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 Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
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
	};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   110
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   111
	// difference
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
	friend Vector3 operator-(const Vector3 &a, const Vector3 &b)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   113
	{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   114
		return Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   115
	};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   116
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   117
	// dot product
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   118
	friend Float dot(const Vector3 &a, const Vector3 &b)
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
   119
	{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   120
		return a.x * b.x + a.y * b.y + a.z * b.z;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   121
	};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   122
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   123
	// cross product
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   124
	friend Vector3 cross(const Vector3 &a, const Vector3 &b)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   125
	{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   126
		return Vector3(a.y * b.z - a.z * b.y,
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   127
			a.z * b.x - a.x * b.z,
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   128
			a.x * b.y - a.y * b.x);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   129
	};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   130
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   131
	// product of vector and scalar
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   132
	friend Vector3 operator*(const Vector3 &v, const Float &f)
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
   133
	{
12
f4fcabf05785 kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
   134
		return Vector3(f * v.x, f * v.y, f * v.z);
74
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   135
	};
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
   136
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   137
	friend Vector3 operator*(const Float &f, const Vector3 &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
   138
	{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   139
		return v * f;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   140
	};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   141
74
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   142
	// scalar division
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   143
	friend Vector3 operator/(const Vector3 &v, const Float &f)
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   144
	{
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   145
		return Vector3(v.x / f, v.y / f, v.z / f);
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   146
	};
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   147
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   148
	friend Vector3 operator/(const Float &f, const Vector3 &v)
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   149
	{
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   150
		return Vector3(f / v.x, f / v.y, f / v.z);
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   151
	};
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   152
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 12
diff changeset
   153
	// vector plus scalar
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   154
	friend Vector3 operator+(const Vector3 &v, const Float &f)
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 12
diff changeset
   155
	{
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 12
diff changeset
   156
		return Vector3(v.x + f, v.y + f, v.z + f);
74
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   157
	};
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 12
diff changeset
   158
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 12
diff changeset
   159
	// vector minus scalar
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
   160
	friend Vector3 operator-(const Vector3 &v, const Float &f)
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 12
diff changeset
   161
	{
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 12
diff changeset
   162
		return Vector3(v.x - f, v.y - f, v.z - f);
74
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   163
	};
14
fc18ac4833f2 replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents: 12
diff changeset
   164
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
   165
	// cell by cell product (only usable for colours)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   166
	friend Vector3 operator*(const Vector3 &a,  const Vector3 &b)
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   167
	{
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   168
		return Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   169
	};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   170
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   171
	// write
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
   172
	friend ostream & operator<<(ostream &st, const Vector3 &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
   173
	{
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   174
		return st << "(" << v.x << "," << v.y  << "," << v.z << ")";
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   175
	};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   176
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   177
	// read
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   178
	friend istream & operator>>(istream &st, Vector3 &v)
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   179
	{
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   180
		char s[10];
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   181
		st.getline(s, 10, '(');
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   182
		st >> v.x;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   183
		st.getline(s, 10, ',');
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   184
		st >> v.y;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   185
		st.getline(s, 10, ',');
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   186
		st >> v.z;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   187
		st.getline(s, 10, ')');
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents: 74
diff changeset
   188
		return st;
74
09aedbf5f95f kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   189
	};
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
   190
};
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   191
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   192
typedef Vector3 Colour;
3547b885df7e initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   193
84
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   194
class VectorPacket
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   195
{
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   196
public:
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   197
	union {
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   198
		__m128 ma[3];
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   199
		struct {
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   200
			__m128 mx;
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   201
			__m128 my;
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   202
			__m128 mz;
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   203
		};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   204
		struct {
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   205
			float x[4];
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   206
			float y[4];
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   207
			float z[4];
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   208
		};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   209
	};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   210
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   211
	VectorPacket() {};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   212
	VectorPacket(__m128 ax, __m128 ay, __m128 az):
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   213
		mx(ax), my(ay), mz(az) {};
87
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 86
diff changeset
   214
	VectorPacket(const Vector3 &v):
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 86
diff changeset
   215
		mx(_mm_set_ps1(v.x)), my(_mm_set_ps1(v.y)), mz(_mm_set_ps1(v.z)) {};
84
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   216
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   217
	Vector3 getVector(int i) const
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   218
	{
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   219
		return Vector3(x[i], y[i], z[i]);
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   220
	};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   221
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   222
	void normalize()
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   223
	{
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   224
		__m128 m,x,y,z;
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   225
		x = _mm_mul_ps(mx, mx); // x*x
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   226
		y = _mm_mul_ps(my, my); // y*y
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   227
		z = _mm_mul_ps(mz, mz); // z*z
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   228
		m = _mm_add_ps(x, y);
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   229
		m = _mm_add_ps(m, z);     // x*x + y*y + z*z
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   230
		m = _mm_sqrt_ps(m);
86
ce6abe0aeeae BBox - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
   231
		m = _mm_div_ps(mOne, m);   // m = 1/sqrt(m)
84
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   232
		mx = _mm_mul_ps(mx, m);
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   233
		my = _mm_mul_ps(my, m);
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   234
		mz = _mm_mul_ps(mz, m);
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   235
	};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   236
87
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 86
diff changeset
   237
	// dot product
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 86
diff changeset
   238
	friend __m128 dot(const VectorPacket &a, const VectorPacket &b)
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 86
diff changeset
   239
	{
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 86
diff changeset
   240
		return _mm_add_ps(_mm_add_ps(
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 86
diff changeset
   241
			_mm_mul_ps(a.mx, b.mx),
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 86
diff changeset
   242
			_mm_mul_ps(a.my, b.my)),
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 86
diff changeset
   243
			_mm_mul_ps(a.mz, b.mz));
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 86
diff changeset
   244
	};
1081e3dd3f3e Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 86
diff changeset
   245
84
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   246
	friend VectorPacket operator+(const VectorPacket &a, const VectorPacket &b)
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   247
	{
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   248
		return VectorPacket(
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   249
			_mm_add_ps(a.mx, b.mx),
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   250
			_mm_add_ps(a.my, b.my),
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   251
			_mm_add_ps(a.mz, b.mz));
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   252
	};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   253
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   254
	friend VectorPacket operator-(const VectorPacket &a, const VectorPacket &b)
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   255
	{
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   256
		return VectorPacket(
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   257
			_mm_sub_ps(a.mx, b.mx),
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   258
			_mm_sub_ps(a.my, b.my),
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   259
			_mm_sub_ps(a.mz, b.mz));
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   260
	};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   261
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   262
	friend VectorPacket operator*(const VectorPacket &v,  const __m128 &m)
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   263
	{
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   264
		return VectorPacket(
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   265
			_mm_mul_ps(v.mx, m),
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   266
			_mm_mul_ps(v.my, m),
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   267
			_mm_mul_ps(v.mz, m));
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   268
	};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   269
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   270
	friend VectorPacket operator/(const __m128 &m, const VectorPacket &v)
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   271
	{
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   272
		return VectorPacket(
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   273
			_mm_div_ps(m, v.mx),
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   274
			_mm_div_ps(m, v.my),
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   275
			_mm_div_ps(m, v.mz));
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   276
	};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   277
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   278
	// write to character stream
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   279
	friend ostream & operator<<(ostream &st, const VectorPacket &v)
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   280
	{
86
ce6abe0aeeae BBox - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
   281
		return st << "[" << v.getVector(0) << "," << v.getVector(1)
84
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   282
			<< "," << v.getVector(2) << "," << v.getVector(3) << ")";
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   283
	};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   284
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   285
};
6f7fe14782c2 prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
   286
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
   287
#endif