-
Notifications
You must be signed in to change notification settings - Fork 1
/
vector4.h
53 lines (43 loc) · 1.18 KB
/
vector4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Vector.h
*
* Created on: 18/09/2014
* Author: mathe_000
*/
#ifndef VECTOR_H_
#define VECTOR_H_
using namespace std;
class Vector4 {
public:
double x;
double y;
double z;
double w;
Vector4 ()
{
x=0;
y=0;
z=0;
w=0;
}
Vector4( double x, double y, double z, double w ):
x(x), y(y), z(z), w(w) {}
//Sobrecarga dos principais operadores
Vector4 operator + (const Vector4& vec) const //sobrecarga do operador + para somar dois vetores
{
return Vector4(x+vec.x,y+vec.y,z+vec.z,w+vec.w);
}
Vector4 operator - (const Vector4& vec) const
{
return Vector4(x-vec.x,y-vec.y,z-vec.z,w-vec.w);
}
//sobrecarga de operadores de indexação
double& operator [] ( int i ) { return *(&x + i); }
const double operator [] ( int i ) const { return *(&x + i); }
Vector4 operator * ( const double s ) const
{ return Vector4( s*x, s*y, s*z, s*w ); }
friend Vector4 operator * ( const double s, const Vector4& v )
{ return v * s; }
//sobrecarga do operador = para copiar valores
};
#endif /* VECTOR_H_ */