Fireworks Engine  v2.0
Lightweight Sandbox Game Engine using OpenGL for additional Customisation and Quick Prototyping
vec3.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <math.h>
5 
6 namespace fireworks { namespace maths {
7 
8  // TODO: Template the vec3 to take any data type and also it's operators
9  struct vec3
10  {
11  float x, y, z;
12 
13  vec3();
14  vec3(const float& x, const float& y, const float& z);
15 
16  static vec3 crossProduct(const vec3& a, const vec3& b);
17  static vec3 normalize(const vec3& v);
18 
19  vec3& add(const vec3& other);
20  vec3& subtract(const vec3& other);
21  vec3& mutiply(const vec3& other);
22  vec3& divide(const vec3& other);
23 
24  /*
25  * 'friend' because we are passing the left and right explicitly and not using
26  * this pointer we don't want to pass in the this pointer to the function hence
27  * we mark them as non-member friend and still give it access to the private members
28  */
29  friend vec3 operator+(vec3 left, const vec3& right);
30  friend vec3 operator-(vec3 left, const vec3& right);
31  friend vec3 operator*(vec3 left, const vec3& right);
32  friend vec3 operator/(vec3 left, const vec3& right);
33 
34  bool operator==(const vec3& other);
35  bool operator!=(const vec3& other);
36 
37  vec3& operator+=(const vec3& other);
38  vec3& operator-=(const vec3& other);
39  vec3& operator*=(const vec3& other);
40  vec3& operator/=(const vec3& other);
41 
42  // TODO: Template these to work with integers as well
43  friend vec3 operator+(vec3 left, const float& right);
44  friend vec3 operator-(vec3 left, const float& right);
45  friend vec3 operator*(vec3 left, const float& right);
46  friend vec3 operator/(vec3 left, const float& right);
47 
48  friend std::ostream& operator<<(std::ostream& stream, const vec3& vector);
49  };
50 
51 } }
friend vec3 operator/(vec3 left, const vec3 &right)
Definition: vec3.cpp:82
vec3 & add(const vec3 &other)
Definition: vec3.cpp:33
bool operator==(const vec3 &other)
Definition: vec3.cpp:110
friend std::ostream & operator<<(std::ostream &stream, const vec3 &vector)
Definition: vec3.cpp:140
float z
Definition: vec3.h:11
vec3 & subtract(const vec3 &other)
Definition: vec3.cpp:42
static vec3 normalize(const vec3 &v)
Definition: vec3.cpp:27
vec3 & divide(const vec3 &other)
Definition: vec3.cpp:58
friend vec3 operator*(vec3 left, const vec3 &right)
Definition: vec3.cpp:77
Definition: audioclip.cpp:3
float y
Definition: vec3.h:11
vec3 & mutiply(const vec3 &other)
Definition: vec3.cpp:50
Definition: vec3.h:9
bool operator!=(const vec3 &other)
Definition: vec3.cpp:115
vec3 & operator*=(const vec3 &other)
Definition: vec3.cpp:130
vec3 & operator+=(const vec3 &other)
Definition: vec3.cpp:120
vec3()
Definition: vec3.cpp:6
vec3 & operator/=(const vec3 &other)
Definition: vec3.cpp:135
friend vec3 operator+(vec3 left, const vec3 &right)
Definition: vec3.cpp:67
friend vec3 operator-(vec3 left, const vec3 &right)
Definition: vec3.cpp:72
vec3 & operator-=(const vec3 &other)
Definition: vec3.cpp:125
float x
Definition: vec3.h:11
static vec3 crossProduct(const vec3 &a, const vec3 &b)
Definition: vec3.cpp:20