-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloat4.cpp
More file actions
68 lines (68 loc) · 1.85 KB
/
float4.cpp
File metadata and controls
68 lines (68 loc) · 1.85 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
#include "float4.h"
#include<stdio.h>
#include<string.h>
#include<math.h>
void float4::operator=(const float4& inV) {
memcpy(v,inV.v,sizeof(v));
}
void float4::operator*=(float inScalar) {
x *= inScalar;
y *= inScalar;
z *= inScalar;
}
void float4::operator-=(float inScalar) {
x -= inScalar;
y -= inScalar;
z -= inScalar;
}
void float4::operator/=(float inScalar) {
x /= inScalar;
y /= inScalar;
z /= inScalar;
}
void float4::operator+=(float inScalar) {
x += inScalar;
y += inScalar;
z += inScalar;
}
float4 float4::operator+(const float4& inV)const {
return float4(x + inV.x, y + inV.y, z + inV.z, w);//
}
float4 float4::operator-(const float4& inV)const {
return float4(x - inV.x, y - inV.y, z - inV.z, w);//
}
float4 float4::operator*(const float inScalar)const {
return float4(x* inScalar, y* inScalar, z* inScalar, w);//
}
void float4::Normalize() {
float magnitude = sqrtf(x*x+y*y+z*z);
if (magnitude < 0.000001f) {
return;
}
x /= magnitude;
y /= magnitude;
z /= magnitude;
}
float MinValue(float inA, float inB) {
return inA < inB ? inA : inB;
}
float MaxValue(float inA, float inB) {
return inA > inB ? inA : inB;
}
float4 Min(const float4& inA, const float4& inB) {//component wise
return float4(MinValue(inA.x, inB.x), MinValue(inA.y, inB.y),
MinValue(inA.z, inB.z), MinValue(inA.w, inB.w));
}
float4 Max(const float4& inA, const float4& inB) {//component wise
return float4(MaxValue(inA.x, inB.x), MaxValue(inA.y, inB.y),
MaxValue(inA.z, inB.z), MaxValue(inA.w, inB.w));
}
float4 cross(const float4& inA, const float4& inB) {
return float4(inA.y*inB.z-inA.z*inB.y,inA.z*inB.x-inA.x*inB.z,inA.x*inB.y-inA.y*inB.x,inA.w);
}
float dot3(const float4& inA, const float4& inB) {
return inA.x * inB.x + inA.y * inB.y + inA.z * inB.z;
}
float dot4(const float4& inA, const float4& inB) {
return inA.x * inB.x + inA.y * inB.y + inA.z * inB.z + inA.w*inB.w;
}