Skip to content

Commit b804891

Browse files
authored
Merge pull request #451 from iverks/3d_transformation_queue
add transformation queue
2 parents 992e586 + 4eec72e commit b804891

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

plotters/src/coord/ranged3d/projection.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl ProjectionMatrix {
140140
}
141141

142142
/// The helper struct to build a projection matrix
143-
#[derive(Copy, Clone)]
143+
#[derive(Clone)]
144144
pub struct ProjectionMatrixBuilder {
145145
/// Specifies the yaw of the 3D coordinate system
146146
pub yaw: f64,
@@ -150,6 +150,7 @@ pub struct ProjectionMatrixBuilder {
150150
pub scale: f64,
151151
pivot_before: (i32, i32, i32),
152152
pivot_after: (i32, i32),
153+
transformation_queue: Vec<ProjectionMatrix>,
153154
}
154155

155156
impl Default for ProjectionMatrixBuilder {
@@ -160,6 +161,7 @@ impl Default for ProjectionMatrixBuilder {
160161
scale: 1.0,
161162
pivot_after: (0, 0),
162163
pivot_before: (0, 0, 0),
164+
transformation_queue: [].to_vec(),
163165
}
164166
}
165167
}
@@ -178,6 +180,12 @@ impl ProjectionMatrixBuilder {
178180
self
179181
}
180182

183+
/// Adds matrix to list of transformations to apply
184+
pub fn add_transform(&mut self, projection: ProjectionMatrix) -> &mut Self {
185+
self.transformation_queue.push(projection);
186+
self
187+
}
188+
181189
/// Build the matrix based on the configuration
182190
pub fn into_matrix(self) -> ProjectionMatrix {
183191
let mut ret = if self.pivot_before == (0, 0, 0) {
@@ -187,6 +195,10 @@ impl ProjectionMatrixBuilder {
187195
ProjectionMatrix::shift(-x as f64, -y as f64, -z as f64) * ProjectionMatrix::default()
188196
};
189197

198+
for transform in self.transformation_queue {
199+
ret = ret * transform;
200+
}
201+
190202
if self.yaw.abs() > 1e-20 {
191203
ret = ret * ProjectionMatrix::rotate(0.0, self.yaw, 0.0);
192204
}

0 commit comments

Comments
 (0)