Creating a vector
Vectors will be implemented as structures, not classes. The vector struct will contain an anonymous union that allows the vector's components to be accessed as an array or as individual elements.
To declare the vec3
structure and the function headers, create a new file, vec3.h
. Declare the new vec3
structure in this file. The vec3
struct needs three constructors—a default constructor, one that takes each component as an element, and one that takes a pointer to a float array:
#ifndef _H_VEC3_ #define _H_VEC3_ struct vec3 { union { struct { float x; float y; float z; }; &...