/
vec4.h
127 lines (113 loc) · 2.97 KB
/
vec4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* \file vec4.h
* \brief Defines the base vector type
*
* Defines the single-precision 128 bit vector struct. This structure
* is used to hold 4 floats, and is used to take advantage of SSE instructions.
* Support functions are defined in vec_func.h
*
* \author Byron Heads <bheads@emich.edu>
* \date July 14, 2011
*/
#ifndef VECT4_H
#define VECT4_H
/**
* \struct vec4
* \brief Ray-tracers four float vector.
*
* Used in vec_func, and other parts if the ray-tracer.
* Only has constructors, operators defined in vec_func.h
*
*/
struct vec4
{
float x, ///< x componant of vector.
y, ///< y componant of vector.
z, ///< z componant of vector.
w; ///< w componant of vector, normally this should be zero.
/**
* \brief Default constructor
*
* Default constructor, all values are zero
*/
vec4()
: x(0), y(0), z(0), w(0) {}
/**
* \brief Destructor
*
* Destructor, does nothing here.
*/
~vec4() {}
/**
* \brief Four float constructor
*
* Constructor taking 4 flosting point numbers. Defaults to 0.
*/
vec4( float _x, float _y=0, float _z=0, float _w=0 )
: x(_x), y(_y), z(_z), w(_w) {}
/**
* \brief Array constructor
*
* Constructor taking an array of 4 floats.
*/
vec4( float f[4] )
: x(f[0]), y(f[1]), z(f[2]), w(f[3]) {}
/**
* \brief Scalar constructor.
*
* Constructor taking a float, all elements except get set. If w2
* is true then w gets set as well, else it is set to zero.
*
* \param f Values to set x, y, z, and w if w2 is true.
* \param w2 If true w is set to the value of f.
*/
vec4( float f, bool w2 = false )
: x(f), y(f), z(f), w( w2 ? f: 0 ) {}
/**
* \brief Copy Constructor
*
* Constructor that copies the value of v.
*
* \param v Vector refrence to copy from.
*/
vec4( const vec4 &v )
: x(v.x), y(v.y), z(v.z), w(v.w) {}
/**
* \brief Assignment operator.
*
* Assignment operator. Copies another vec4 object.
*
* \param o Object to copy;
* \return Refrence to self, is a copy of o
*/
vec4 &operator=( const vec4 &o )
{
if( this != &o )
{
x = o.x;
y = o.y;
z = o.z;
w = o.w;
}
return *this;
}
/**
* \brief Scalar assignment operator.
*
* Scalar assignment operator. Copies a scalar value. W is copied.
*
* \param v Scalar value to set vector to.
* \return Refrence to self, is set to v.
*/
vec4 &operator=( const float v )
{
x = y = z = w = v;
return *this;
}
}__attribute__((aligned(16))); ///< Make sure this is 16 byte aligned. Can use movaps
/**
* \typedef vec4 color
* rtrt Colors are also vectors
*/
typedef vec4 color;
#endif