-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvec4.h
More file actions
71 lines (71 loc) · 1.55 KB
/
vec4.h
File metadata and controls
71 lines (71 loc) · 1.55 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _VEC_4_
#define _VEC_4_
#include <cmath>
struct vec4{
vec4(){
x=y=z=w=0.0f;
}
vec4(float _x,float _y,float _z,float _w){
x=_x;
y=_y;
z=_z;
w=_w;
}
vec4 operator+(const vec4& v){
return vec4(x+v.x,
y+v.y,
z+v.z,
w+v.w);
}
vec4 operator-(const vec4& v){
return vec4(x-v.x,
y-v.y,
z-v.z,
w-v.w);
}
vec4 operator-(){
return vec4(-x,
-y,
-z,
-w);
}
vec4 operator*(const float v){
return vec4(x*v,
y*v,
z*v,
w*v);
}
vec4 operator*(const vec4 v){
return vec4(x*v.x,
y*v.y,
z*v.z,
w*v.w);
}
vec4 clamp(){
return vec4(x<0.0f?0.0f:(x>1.0f?1.0f:x),
y<0.0f?0.0f:(y>1.0f?1.0f:y),
z<0.0f?0.0f:(z>1.0f?1.0f:z),
w<0.0f?0.0f:(w>1.0f?1.0f:w));
}
vec4 pixelize(){
return vec4((int)x,
(int)y,
z,
w);
}
vec4 normalize(){
float d=sqrt(x*x+y*y+z*z);
return vec4(x/d,
y/d,
z/d,
0.0);
}
float operator^(const vec4& v){
return v.x*x+v.y*y+v.z*z;
}
float x;
float y;
float z;
float w;
};
#endif