My Project
Loading...
Searching...
No Matches
Vector3.h
1#ifndef __VECTOR3__
2#define __VECTOR3__
3
4#include <stdlib.h>
5#include <stdio.h>
6#include <math.h>
7//#include <GLUT/glut.h> /* Header File For The GLut Library*/
8
9//class Vector4{
10// float value[4];
11// public:
12// Vector4(){
13// value[0] = value[1] = value[2] = value[3] = 0.0f;
14// }
15// Vector4(const Vector4& other){
16// this->value[0] = other.value[0];
17// this->value[1] = other.value[1];
18// this->value[2] = other.value[2];
19// this->value[3] = other.value[3];
20// }
21// Vector4(float x, float y, float z, float w = 0.0f){
22// this->value[0] = x;
23// this->value[1] = y;
24// this->value[2] = z;
25// this->value[3] = w;
26// }
27// Vector4(float arr[4]){
28// this->value[0] = arr[0];
29// this->value[1] = arr[1];
30// this->value[2] = arr[2];
31// this->value[3] = arr[3];
32// }
33//
34// Vector4& operator=(const Vector4& rhs){
35// this->value[0] = rhs.value[0];
36// this->value[1] = rhs.value[1];
37// this->value[2] = rhs.value[2];
38// this->value[3] = rhs.value[3];
39// return *this;
40// }
41//
42// Vector4 operator+(Vector4& rhs){
43// Vector4 v;
44// v.value[0] = this->value[0] + rhs.value[0];
45// v.value[1] = this->value[1] + rhs.value[1];
46// v.value[2] = this->value[2] + rhs.value[2];
47// v.value[3] = this->value[3] + rhs.value[3];
48// return v;
49// }
50//
51// Vector4 operator-(Vector4& rhs){
52// Vector4 v;
53// v.value[0] = this->value[0] - rhs.value[0];
54// v.value[1] = this->value[1] - rhs.value[1];
55// v.value[2] = this->value[2] - rhs.value[2];
56// v.value[3] = this->value[3] - rhs.value[3];
57// return v;
58// }
59//};
60//
61//
62
63class Vector3{
64 public:
65 float v[3];
66 public:
67 Vector3(){ }
68 public:
69
70 Vector3(const Vector3& other){
71 this->v[0] = other.v[0];
72 this->v[1] = other.v[1];
73 this->v[2] = other.v[2];
74 }
75
76 Vector3(float x, float y, float z){
77 v[0] = x;
78 v[1] = y;
79 v[2] = z;
80 }
81
82 Vector3(float arr[3]){
83 v[0] = arr[0];
84 v[1] = arr[1];
85 v[2] = arr[2];
86 }
87
88 Vector3& operator=(const Vector3& rhs){
89 this->v[0] = rhs.v[0];
90 this->v[1] = rhs.v[1];
91 this->v[2] = rhs.v[2];
92 return *this;
93 }
94
95 Vector3 operator+(Vector3& rhs){
96 Vector3 v;
97 v.v[0] = this->v[0] + rhs.v[0];
98 v.v[1] = this->v[1] + rhs.v[1];
99 v.v[2] = this->v[2] + rhs.v[2];
100 return v;
101 }
102
103 Vector3 operator-(Vector3& rhs){
104 Vector3 v;
105 v.v[0] = this->v[0] - rhs.v[0];
106 v.v[1] = this->v[1] - rhs.v[1];
107 v.v[2] = this->v[2] - rhs.v[2];
108 return v;
109 }
110
111 Vector3 operator/(float n){
112 //Vector3* v = new Vector3();
113 Vector3 v;
114 v.v[0] = this->v[0]/n;
115 v.v[1] = this->v[1]/n;
116 v.v[2] = this->v[2]/n;
117 return v;
118 }
119
120 Vector3 dot(Vector3& rhs){
121 Vector3 v;
122 v.v[0] = this->v[0] * rhs.v[0];
123 v.v[1] = this->v[1] * rhs.v[1];
124 v.v[2] = this->v[2] * rhs.v[2];
125 return v;
126 }
127 void print(){
128 printf("x=[%f], y=[%f], z=[%f]\n", v[0], v[1], v[2]);
129 }
130};
131
132#endif
Definition: Vector3.h:63