CMSC23700 Common Code Library
Support code for CS23700 programming projects
cs237-vec3.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_VEC3_HXX_
14 #define _CS237_VEC3_HXX_
15 
16 #ifndef _CS237_HXX_
17 #error "c237-vec3.hxx should not be included directly"
18 #endif
19 
20 namespace cs237 {
21 
22  namespace __detail {
23 
25  template <typename T>
26  struct vec3 {
27  T x, y, z;
28 
29  vec3 () : x(T(0)), y(T(0)), z(T(0)) { }
30  vec3 (vec3 const &v) : x(v.x), y(v.y), z(v.z) { }
31  explicit vec3 (T xx) : x(xx), y(T(0)), z(T(0)) { }
32  explicit vec3 (T xx, T yy) : x(xx), y(yy), z(T(0)) { }
33  explicit vec3 (T xx, T yy, T zz) : x(xx), y(yy), z(zz) { }
34  explicit vec3 (vec2<T> const &v) : x(v.x), y(v.y), z(T(0)) { }
35  explicit vec3 (vec2<T> const &v, T zz) : x(v.x), y(v.y), z(zz) { }
36  explicit vec3 (vec4<T> const &v); // first three components of a 4-vector
37 
40  T const & operator[] (unsigned int const &i) const;
41  T & operator[] (unsigned int const &i);
43 
44  vec3 & operator= (vec3 const &v);
45 
47  vec3 & operator+= (T const &s);
49  vec3 & operator+= (vec3 const &v);
50 
52  vec3 & operator-= (T const &s);
54  vec3 & operator-= (vec3 const &v);
55 
57  vec3 & operator*= (T const &s);
59  vec3 & operator*= (vec3 const &v);
60 
62  vec3 & operator/= (T const &s);
63 
65  T length () const;
67  vec3 & normalize ();
68  };
69 
73  template <typename T>
74  std::ostream& operator<< (std::ostream& s, vec3<T> const &v);
75 
76  } /* _namespace __detail */
77 
82 
83 } /* namespace cs237 */
84 
85 #endif /* !_CS237_VEC3_HXX_ */
vec3(vec2< T > const &v)
Definition: cs237-vec3.hxx:34
vec3(T xx, T yy, T zz)
Definition: cs237-vec3.hxx:33
T length() const
the length (magnitude) of the vector
Definition: cs237-vec3.inl:120
vec3(T xx)
Definition: cs237-vec3.hxx:31
__detail::vec3< double > vec3d
Three-element, double-precision floating-point vectors.
Definition: cs237-vec3.hxx:81
T y
Definition: cs237-vec3.hxx:27
vec3 & operator-=(T const &s)
subtract a scalar from this vector
Definition: cs237-vec3.inl:74
vec3(vec3 const &v)
Definition: cs237-vec3.hxx:30
vec3(T xx, T yy)
Definition: cs237-vec3.hxx:32
template class for four-element vectors
Definition: cs237-types.hxx:27
vec3 & operator*=(T const &s)
multiply this vector by a scalar
Definition: cs237-vec3.inl:92
T x
Definition: cs237-vec3.hxx:27
vec3 & normalize()
normalize the vector
Definition: cs237-vec3.inl:126
vec3 & operator+=(T const &s)
add a scalar to this vector
Definition: cs237-vec3.inl:56
Definition: cs237-aabb.hxx:18
vec3()
Definition: cs237-vec3.hxx:29
vec3(vec2< T > const &v, T zz)
Definition: cs237-vec3.hxx:35
template class for three-element vectors
Definition: cs237-types.hxx:26
vec3 & operator=(vec3 const &v)
Definition: cs237-vec3.inl:32
T const & operator[](unsigned int const &i) const
Definition: cs237-vec3.inl:42
template class for two-element vectors
Definition: cs237-types.hxx:25
__detail::vec3< float > vec3f
Three-element, single-precision floating-point vectors.
Definition: cs237-vec3.hxx:79
vec3 & operator/=(T const &s)
divide this vector by a scalar
Definition: cs237-vec3.inl:110
T z
Definition: cs237-vec3.hxx:27