-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloat3.h
More file actions
51 lines (35 loc) · 1.29 KB
/
Copy pathfloat3.h
File metadata and controls
51 lines (35 loc) · 1.29 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
#pragma once
#include <cmath>
struct float3
{
float x, y, z;
};
inline float3 operator + (const float3 &a, const float3 &b)
{ return {a.x+b.x, a.y+b.y, a.z+b.z}; }
inline float3 operator - (const float3 &a, const float3 &b)
{ return {a.x-b.x, a.y-b.y, a.z-b.z}; }
inline float3 operator * (const float3 &a, const float &b)
{ return {a.x*b, a.y*b, a.z*b}; }
inline float3 operator * (const float &a, const float3 &b)
{ return {a*b.x, a*b.y, a*b.z}; }
inline float3 operator * (const float3 &a, const float3 &b)
{ return {a.x*b.x, a.y*b.y, a.z*b.z}; }
inline float3 operator / (const float3 &a, const float &b)
{ return {a.x/b, a.y/b, a.z/b}; }
inline float3 operator / (const float &a, const float3 &b)
{ return {a/b.x, a/b.y, a/b.z}; }
inline float3 operator / (const float3 &a, const float3 &b)
{ return {a.x/b.x, a.y/b.y, a.z/b.z}; }
inline float dot (const float3 &a, const float3 &b)
{ return a.x*b.x + a.y*b.y + a.z*b.z; }
inline float length2 (const float3 &a)
{ return dot (a,a); }
inline float length (const float3 &a)
{ return std::sqrt (dot (a,a)); }
inline float3 normalize (const float3 &a)
{
float n = length (a);
return n > 0.0f ? a/n : float3 {0.0f,0.0f,0.0f};
}
inline float3 cross (const float3 &a, const float3 &b)
{ return { a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x }; }