-
Notifications
You must be signed in to change notification settings - Fork 3
/
Shape.h
62 lines (46 loc) · 1.63 KB
/
Shape.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once
#include "vecmat.h"
#include <limits>
#include <cstdint>
struct File;
struct BoundingSphere {
Vector3 center;
float radius;
BoundingSphere() : center(Vector3(0, 0, 0)), radius(0) {}
BoundingSphere(const Vector3 ¢er, float radius) : center(center), radius(radius) {}
bool containsPoint(const Vector3& point) const;
bool intersectsWithSphere(const BoundingSphere& other) const;
float distanceToPoint(const Vector3& point) const;
float distanceToSphere(const BoundingSphere& other) const;
void merge(const BoundingSphere &other);
void mergePoint(const Vector3 &point);
void deserialize(File *file, bool withSquare = false);
void serialize(File *file, bool withSquare = false);
};
struct AABoundingBox {
Vector3 highCorner, lowCorner;
AABoundingBox() : highCorner(-vecinf), lowCorner(vecinf) {}
AABoundingBox(const Vector3 &point) : highCorner(point), lowCorner(point) {}
AABoundingBox(const Vector3 &highCorner, const Vector3 &lowCorner) : highCorner(highCorner), lowCorner(lowCorner) {}
void mergePoint(const Vector3 &point);
void merge(const AABoundingBox &box);
bool containsPoint(const Vector3& point) const;
void deserialize(File *file);
void serialize(File *file);
private:
static constexpr auto fltinf = std::numeric_limits<float>::infinity();
static constexpr auto vecinf = Vector3(fltinf, fltinf, fltinf);
};
struct AACylinder {
Vector3 center;
float radius, height;
void deserialize(File *file);
void serialize(File *file);
};
struct AARectangle {
Vector3 center;
float length1 = 1.0f, length2 = 1.0f;
uint8_t direction = 0;
AARectangle() = default;
AARectangle(Vector3 center) : center(center) {}
};