Logo
Vector3.h
1#pragma once
2
3#include "MathHelper.h"
4
5namespace SharpKmyMath{
6
7 public value struct Vector3{
8
9 public:
10 float x, y, z;
11
12 Vector3(float v)
13 {
14 x = y = z = v;
15 }
16
17 Vector3(float _x, float _y, float _z)
18 {
19 x = _x;
20 y = _y;
21 z = _z;
22 }
23
24 float length()
25 {
26 return sqrt(x*x + y*y + z*z);
27 }
28
30 {
31 float l = sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
32 Vector3 ret;
33 ret.x = v.x / l;
34 ret.y = v.y / l;
35 ret.z = v.z / l;
36 return ret;
37 }
38
40 {
41 Vector3 ret;
42 ret.x = v1.x - v2.x;
43 ret.y = v1.y - v2.y;
44 ret.z = v1.z - v2.z;
45 return ret;
46 }
47
49 {
50 Vector3 ret;
51 ret.x = v1.x + v2.x;
52 ret.y = v1.y + v2.y;
53 ret.z = v1.z + v2.z;
54 return ret;
55 }
56
57 static Vector3 operator*(Vector3 v, float f)
58 {
59 Vector3 ret;
60 ret.x = v.x * f;
61 ret.y = v.y * f;
62 ret.z = v.z * f;
63 return ret;
64 }
65
67 {
68 Vector3 ret;
69 ret.x = v1.x * v2.x;
70 ret.y = v1.y * v2.y;
71 ret.z = v1.z * v2.z;
72 return ret;
73 }
74
75 static Vector3 operator/(Vector3 v, float f)
76 {
77 Vector3 ret;
78 ret.x = v.x / f;
79 ret.y = v.y / f;
80 ret.z = v.z / f;
81 return ret;
82 }
83
85 {
86 Vector3 ret;
87 ret.x = -v.x;
88 ret.y = -v.y;
89 ret.z = -v.z;
90 return ret;
91 }
92
93 static float dotProduct(Vector3 v1, Vector3 v2)
94 {
95 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
96 }
97
99 {
100 Vector3 tmp;
101 tmp.x = v1.y * v2.z - v1.z * v2.y;
102 tmp.y = v1.z * v2.x - v1.x * v2.z;
103 tmp.z = v1.x * v2.y - v1.y * v2.x;
104 return tmp;
105 }
106
107 static Vector3 one = Vector3(1, 1, 1);
108 static Vector3 zero = Vector3(0, 0, 0);
109 };
110}
Definition: RefCapture.h:3
Definition: Vector3.h:7
float y
Definition: Vector3.h:10
float z
Definition: Vector3.h:10
static Vector3 operator*(Vector3 v, float f)
Definition: Vector3.h:57
static Vector3 crossProduct(Vector3 v1, Vector3 v2)
Definition: Vector3.h:98
static Vector3 one
Definition: Vector3.h:107
float x
Definition: Vector3.h:10
static Vector3 zero
Definition: Vector3.h:108
Vector3(float v)
Definition: Vector3.h:12
static Vector3 operator/(Vector3 v, float f)
Definition: Vector3.h:75
static float dotProduct(Vector3 v1, Vector3 v2)
Definition: Vector3.h:93
static Vector3 normalize(Vector3 v)
Definition: Vector3.h:29
static Vector3 operator*(Vector3 v1, Vector3 v2)
Definition: Vector3.h:66
Vector3(float _x, float _y, float _z)
Definition: Vector3.h:17
static Vector3 operator+(Vector3 v1, Vector3 v2)
Definition: Vector3.h:48
static Vector3 operator-(Vector3 v1, Vector3 v2)
Definition: Vector3.h:39
float length()
Definition: Vector3.h:24