-
Notifications
You must be signed in to change notification settings - Fork 0
/
Line3D.cpp
137 lines (117 loc) · 3.03 KB
/
Line3D.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#pragma once
#include "Simulation.h"
#include "helpers.h"
#include "rand.h"
#include "3DPlanes.h"
const static int lines_per_thing = 10;
const static float box_size = 500;
enum which_type {Top=0, Left, Bottom, Right};
SIM(Line3D, "3d_surface")
{
typedef std::array<sf::Vertex, 2> line;
std::vector<line> bodies;
std::vector<sf::RectangleShape> rects;
std::string title() override {return "3D Line Surface";}
void initialize() override
{
auto window_center = windowHalfDimensions();
auto window_size = windowDimensions();
float left = 0;
float bottom = window_size.y;
float right = left + box_size;
float top = bottom - box_size;
sf::Vector2f vanish(window_center.x * 1.5, bottom - (box_size/2));
std::array<float, 2> depths;
depths.fill(0);
std::array<which_type, 5> whiches = {Left, Bottom, Left, Top, Right};
maxProgress(whiches.size() * lines_per_thing * 2);
for(unsigned which_i = 0; which_i < whiches.size(); ++which_i)
{
auto which = whiches[which_i];
VanishPlane plane = (which % 2 == 0) ?
VanishPlane::floorPlane(vanish, which == 0 ? top : bottom) :
VanishPlane::sidePlane(vanish, which == 1 ? left : right);
if(which_i != 3)
{
depths[0] = depths[1];
depths[1] += 800;
}
for(unsigned i = 0; i < lines_per_thing; ++i)
{
bodies.emplace_back();
if(which % 2 == 0)
{
float x;
switch(i)
{
case 0:
x = left; break;
case 1:
x = right; break;
default:
x = randuniform(left, right); break;
}
for(unsigned p = 0; p < 2; ++p)
{
float y = depths[p];
bodies.back()[p] = sf::Vertex(plane(sf::Vector2f(x, y)), sf::Color::Black);
addProgress(1);
}
}
else
{
float y;
switch(i)
{
case 0:
y = top; break;
case 1:
y = bottom; break;
default:
y = randuniform(top, bottom); break;
}
for(unsigned p = 0; p < 2; ++p)
{
float x = depths[p];
bodies.back()[p] = sf::Vertex(plane(sf::Vector2f(x, y)), sf::Color::Black);
addProgress(1);
}
}
}
}
auto final_plane = VanishPlane::backPlane(vanish, depths[1]);
sf::RectangleShape rect;
sf::Vector2f topLeft;
sf::Vector2f bottomRight;
auto add_rect = [&](float x1, float y1, float x2, float y2, float depth)
{
final_plane.intersect = depth;
topLeft = final_plane(sf::Vector2f(x1, y1));
bottomRight = final_plane(sf::Vector2f(x2, y2));
rect.setSize(bottomRight - topLeft);
rect.setPosition(topLeft);
rect.setFillColor(sf::Color::Black);
rect.setOutlineThickness(0);
rects.push_back(rect);
};
//RIGHT->
add_rect(right, top, right+200000, bottom, depths[1]);
//UP^
add_rect(left, top-200000, right, top, 1600);
//DOWN V
add_rect(left, bottom, right, bottom + 200000, 800);
//LEFT<-
add_rect(left - 200000, top, left, bottom, 1600);
}
void render() override
{
for(auto& rect : rects)
{
window().draw(rect);
}
for(auto& line : bodies)
{
window().draw(line.data(), line.size(), sf::PrimitiveType::Lines);
}
}
};