-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
43 lines (35 loc) · 1.13 KB
/
util.h
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
#pragma once
#include <iostream>
#include "matmul.h"
const double EPS = 1e-4;
struct vec3 {
double x, y, z;
vec3 operator+(const vec3& rhs) const;
vec3 operator-(const vec3& rhs) const;
vec3 operator*(double val) const;
vec3 operator/(double val) const;
vec3 operator-() const;
vec3& operator+=(const vec3& rhs);
vec3& operator-=(const vec3& rhs);
vec3& operator*=(double val);
vec3& operator/=(double val);
operator bool() const;
};
struct mat4 {
alignas(32) double data[16];
mat4();
mat4(const mat4& rhs);
mat4& operator=(const mat4& rhs);
mat4& operator*=(const mat4& rhs);
vec3 operator()(const vec3& vec) const;
static mat4 Perspective(double fov, double ratio, double near, double far);
static mat4 RotZ(double angle);
static mat4 RotX(double angle);
static mat4 Translate(const vec3& vec);
};
std::ostream& operator<<(std::ostream& os, const vec3& val);
std::ostream& operator<<(std::ostream& os, const mat4& val);
double NormU(double x);
double NormS(double x);
bool NormSegmentXY(vec3& a, vec3& b);
bool NormSegmentZ(vec3& a, vec3& b, double near, double far);