-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplane.hpp
More file actions
64 lines (52 loc) · 2.15 KB
/
plane.hpp
File metadata and controls
64 lines (52 loc) · 2.15 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
//
// plane.hpp
// CompSci78
//
// Created by Michael Schuff on 10/3/20.
// Copyright © 2020 Michael Schuff. All rights reserved.
//
#ifndef plane_hpp
#define plane_hpp
#include "vector3.hpp"
#include <iostream>
class plane : public object {
public:
vector3 position, normal, up, right;
float width, height;
color c;
vector3 top_left, top_right, bottom_left, bottom_right;
plane() : object(false), position(vector3()), normal(vector3()), up(vector3()), width(0), height(0), c(color()) {set_corners();}
plane(vector3 _position, vector3 _normal, vector3 _up, float _width = 10, float _height = 10, color _c = color(), bool visable = true) : object(visable), position(_position), normal(_normal.normalized()), up(_up.normalized()), width(_width), height(_height), c(_c) {set_corners();}
plane(vector3 p1, vector3 p2, vector3 p3, vector3 _up, float _width = 10, float _height = 10, color _c = color(), bool visable = true) : object(visable), position(p1), normal(cross_product(p2-p1, p3-p1).normalized()), up(_up.normalized()), width(_width), height(_height), c(_c) {set_corners();}
plane &operator=(const plane &p);
void flip();
std::string to_string();
void print();
private:
void set_corners();
};
plane &plane::operator=(const plane &p) {
position = p.position;
normal = p.normal;
width = p.width;
height = p.height;
return *this;
}
void plane::set_corners() {
right = cross_product(normal, up).normalized();
top_left = position + up * height / 2 - right * width / 2;
top_right = position + up * height / 2 + right * width / 2;
bottom_left = position - up * height / 2 - right * width / 2;
bottom_right = position - up * height / 2 + right * width / 2;
}
void plane::flip() {
normal = -normal;
right = cross_product(normal, up).normalized();
}
std::string plane::to_string() {
return "Position: " + position.to_string() + " Normal: " + normal.to_string() + " Up: " + up.to_string() + "\nWidth: " + std::to_string(width) + " Height: " + std::to_string(height);
}
void plane::print() {
std::cout << (*this).to_string() << std::endl;
}
#endif /* plane_hpp */