Exploring more vectors
At some point later on in this book, you will need to utilize two- and four-component vectors as well. The two- and four-component vectors don't need any mathematical functions defined as they will be used exclusively as containers used to pass data to the GPU.
Unlike the three-component vector you have implemented, the two- and four-component vectors need to exist as both integer and floating point vectors. To avoid duplicating code, both structures will be implemented using a template:
- Create a new file,
vec2.h
, and add the definition of thevec2
struct. All thevec2
constructors are inline; there is no need for acpp
file. TheTVec2
struct is templated andtypedef
is used to declarevec2
andivec2
:template<typename T> struct TVec2 { union { struct { T x; ...