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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
use ::{std, glium};
use ::{graphics, Camera2d, Camera3d};
pub struct Viewport {
pub rect : glium::Rect,
pub camera2d : Camera2d,
pub camera3d : Camera3d
}
pub struct Builder {
rect : glium::Rect,
orthographic_3d : Option <f32>,
pose_3d : Option <graphics::Pose3d <f32>>,
zoom_2d : Option <f32>
}
impl Viewport {
pub fn new (rect : glium::Rect) -> Self {
assert!(rect.width <= std::u16::MAX as u32);
assert!(rect.height <= std::u16::MAX as u32);
Viewport {
rect,
camera2d: Camera2d::new (rect.width as u16, rect.height as u16),
camera3d: Camera3d::new (rect.width as u16, rect.height as u16)
}
}
pub fn with_pose_3d (
rect : glium::Rect,
pose : graphics::Pose3d <f32>
) -> Self {
assert!(rect.width <= std::u16::MAX as u32);
assert!(rect.height <= std::u16::MAX as u32);
Viewport {
rect,
camera2d: Camera2d::new (rect.width as u16, rect.height as u16),
camera3d: Camera3d::with_pose (
rect.width as u16, rect.height as u16,
pose
)
}
}
pub fn set_rect (&mut self, rect : glium::Rect) {
assert!(rect.width <= std::u16::MAX as u32);
assert!(rect.height <= std::u16::MAX as u32);
self.rect = rect;
self.camera2d
.set_viewport_dimensions (rect.width as u16, rect.height as u16);
self.camera3d
.set_viewport_dimensions (rect.width as u16, rect.height as u16);
}
}
impl Builder {
#[inline]
pub fn new (rect : glium::Rect) -> Self {
Builder {
rect,
orthographic_3d: None,
pose_3d: None,
zoom_2d: None
}
}
pub fn with_zoom_2d (self, zoom : f32) -> Self {
Builder { zoom_2d: Some (zoom), .. self }
}
pub fn orthographic_3d (self, zoom : f32) -> Self {
Builder { orthographic_3d: Some (zoom), .. self }
}
pub fn with_pose_3d (self, pose_3d : graphics::Pose3d <f32>) -> Self {
Builder { pose_3d: Some (pose_3d), .. self }
}
#[inline]
pub fn build (self) -> Viewport {
let mut viewport = if let Some (pose_3d) = self.pose_3d {
Viewport::with_pose_3d (self.rect, pose_3d)
} else {
Viewport::new (self.rect)
};
if let Some (zoom) = self.orthographic_3d {
viewport.camera3d.projection3d.to_orthographic (zoom);
}
if let Some (zoom) = self.zoom_2d {
viewport.camera2d.set_zoom (zoom);
}
viewport
}
}