CMSC23700 Common Code Library
Support code for CS23700 programming projects
cs237-vec4.hxx
Go to the documentation of this file.
1 
8 /*
9  * COPYRIGHT (c) 2013 John Reppy (http://cs.uchicago.edu/~jhr)
10  * All rights reserved.
11  */
12 
13 #ifndef _CS237_VEC4_HXX_
14 #define _CS237_VEC4_HXX_
15 
16 #ifndef _CS237_HXX_
17 #error "c237-vec4.hxx should not be included directly"
18 #endif
19 
20 namespace cs237 {
21 
22  namespace __detail {
23 
25  template <typename T>
26  struct vec4 {
27  T x, y, z, w;
28 
29  vec4 () : x(T(0)), y(T(0)), z(T(0)), w(T(0)) { }
30  vec4 (vec4 const &v) : x(v.x), y(v.y), z(v.z), w(v.w) { }
31  explicit vec4 (T xx) : x(xx), y(T(0)), z(T(0)), w(T(0)) { }
32  explicit vec4 (T xx, T yy) : x(xx), y(yy), z(T(0)), w(T(0)) { }
33  explicit vec4 (T xx, T yy, T zz) : x(xx), y(yy), z(zz), w(T(0)) { }
34  explicit vec4 (T xx, T yy, T zz, T ww) : x(xx), y(yy), z(zz), w(ww) { }
35  explicit vec4 (vec2<T> const &v) : x(v.x), y(v.y), z(T(0)), w(T(0)) { }
36  explicit vec4 (vec2<T> const &v, T zz) : x(v.x), y(v.y), z(zz), w(T(0)) { }
37  explicit vec4 (vec2<T> const &v, T zz, T ww) : x(v.x), y(v.y), z(zz), w(ww) { }
38  explicit vec4 (vec3<T> const &v) : x(v.x), y(v.y), z(v.z), w(T(0)) { }
39  explicit vec4 (vec3<T> const &v, T ww) : x(v.x), y(v.y), z(v.z), w(ww) { }
40 
43  T & operator[] (unsigned int const &i);
44  T const & operator[] (unsigned int const &i) const;
46 
47  vec4 & operator= (vec4 const &v);
48 
50  vec4 & operator+= (T const &s);
52  vec4 & operator+= (vec4 const &v);
53 
55  vec4 & operator-= (T const &s);
57  vec4 & operator-= (vec4 const &v);
58 
60  vec4 & operator*= (T const &s);
62  vec4 & operator*= (vec4 const &v);
63 
65  vec4 & operator/= (T const &s);
66 
68  T length () const;
70  vec4 & normalize ();
71  };
72 
76  template <typename T>
77  std::ostream& operator<< (std::ostream& s, vec4<T> const &v);
78 
79  } /* _namespace __detail */
80 
85 
86 } /* namespace cs237 */
87 
88 #endif /* !_CS237_VEC4_HXX_ */
__detail::vec4< double > vec4d
Four-element, double-precision floating-point vectors.
Definition: cs237-vec4.hxx:84
vec4(T xx, T yy)
Definition: cs237-vec4.hxx:32
T y
Definition: cs237-vec4.hxx:27
vec4(vec3< T > const &v, T ww)
Definition: cs237-vec4.hxx:39
T x
Definition: cs237-vec4.hxx:27
vec4 & normalize()
normalize the vector
Definition: cs237-vec4.inl:130
vec4(T xx, T yy, T zz, T ww)
Definition: cs237-vec4.hxx:34
T & operator[](unsigned int const &i)
Definition: cs237-vec4.inl:39
vec4(vec3< T > const &v)
Definition: cs237-vec4.hxx:38
__detail::vec4< float > vec4f
Four-element, single-precision floating-point vectors.
Definition: cs237-vec4.hxx:82
vec4 & operator+=(T const &s)
add a scalar to this vector
Definition: cs237-vec4.inl:53
vec4 & operator=(vec4 const &v)
Definition: cs237-vec4.inl:28
vec4(vec4 const &v)
Definition: cs237-vec4.hxx:30
vec4 & operator-=(T const &s)
subtract a scalar from this vector
Definition: cs237-vec4.inl:73
T w
Definition: cs237-vec4.hxx:27
template class for four-element vectors
Definition: cs237-types.hxx:27
T z
Definition: cs237-vec4.hxx:27
vec4(vec2< T > const &v)
Definition: cs237-vec4.hxx:35
Definition: cs237-aabb.hxx:18
vec4 & operator*=(T const &s)
multiply this vector by a scalar
Definition: cs237-vec4.inl:93
template class for three-element vectors
Definition: cs237-types.hxx:26
vec4(T xx, T yy, T zz)
Definition: cs237-vec4.hxx:33
vec4(T xx)
Definition: cs237-vec4.hxx:31
vec4(vec2< T > const &v, T zz)
Definition: cs237-vec4.hxx:36
template class for two-element vectors
Definition: cs237-types.hxx:25
T length() const
the length (magnitude) of the vector
Definition: cs237-vec4.inl:124
vec4()
Definition: cs237-vec4.hxx:29
vec4 & operator/=(T const &s)
divide this vector by a scalar
Definition: cs237-vec4.inl:113
vec4(vec2< T > const &v, T zz, T ww)
Definition: cs237-vec4.hxx:37