Question: Using C++ Create a vec3 class that implements a 3-dimensional vector. It also implements basic vector functionality: addition, subtraction, scaling, negation, dot product, cross product,

Using C++

Create a vec3 class that implements a 3-dimensional vector. It also implements basic vector functionality: addition, subtraction, scaling, negation, dot product, cross product, etc.

Task

Provide the vec3.cpp file that contains the body for the vec3 class declared in the header file vec3.h provided below.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// vec3.h #ifndef __vec3_h__ #define __vec3_h__  #include  using namespace std; class vec3 { private: float m[3]; public: // constructors  vec3(); vec3(const vec3& v); vec3(float x, float y, float z); // indexing  float& operator[](int i); const float& operator[](int i) const; // assignment  const vec3& operator=(const vec3& v); // multiplication with a scalar  void operator*=(float s); friend vec3 operator*(const vec3& v, float s); // addition  void operator+=(const vec3& v); friend vec3 operator+(const vec3& v1, const vec3& v2); // subtraction  void operator-=(const vec3& v); friend vec3 operator-(const vec3& v1, const vec3& v2); // negation  vec3 operator-(); // dot product  friend float operator*(const vec3& v1, const vec3& v2); // cross product  friend vec3 operator^(const vec3& v1, const vec3& v2); // length  float length(); // io  friend ostream& operator<<(ostream& o, const vec3& v); friend istream& operator>>(istream& o, vec3& v); }; #endif 

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!