Skip to content

Commit 63b7d46

Browse files
author
Matthew Russo
committed
adds cgmath
1 parent 41192a4 commit 63b7d46

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/bin/22_descriptor_pools_and_sets.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
extern crate vulkano;
33
extern crate vulkano_win;
44
extern crate winit;
5+
extern crate cgmath;
56

67
use std::sync::{Arc, Mutex};
78
use std::collections::HashSet;
@@ -61,6 +62,13 @@ use vulkano::descriptor::descriptor_set::{
6162
FixedSizeDescriptorSetsPool,
6263
FixedSizeDescriptorSet
6364
};
65+
use cgmath::{
66+
Rad,
67+
Deg,
68+
Matrix4,
69+
Vector3,
70+
Point3
71+
};
6472

6573
const WIDTH: u32 = 800;
6674
const HEIGHT: u32 = 600;
@@ -111,9 +119,9 @@ impl_vertex!(Vertex, pos, color);
111119
#[allow(dead_code)]
112120
#[derive(Copy, Clone)]
113121
struct UniformBufferObject {
114-
model: glm::Mat4,
115-
view: glm::Mat4,
116-
proj: glm::Mat4,
122+
model: Matrix4<f32>,
123+
view: Matrix4<f32>,
124+
proj: Matrix4<f32>,
117125
}
118126

119127
fn vertices() -> [Vertex; 4] {
@@ -727,28 +735,22 @@ impl HelloTriangleApplication {
727735
let duration = Instant::now().duration_since(start_time);
728736
let elapsed = (duration.as_secs() * 1000) + u64::from(duration.subsec_millis());
729737

730-
let identity_matrix = glm::mat4(
731-
1.0, 0.0, 0.0, 0.0,
732-
0.0, 1.0, 0.0, 0.0,
733-
0.0, 0.0, 1.0, 0.0,
734-
0.0, 0.0, 0.0, 1.0,
735-
);
736-
737-
let model = glm::ext::rotate(&identity_matrix, (elapsed as f32) * glm::radians(0.180), glm::vec3(0.0, 0.0, 1.00));
738+
let model = Matrix4::from_angle_z(Rad::from(Deg(elapsed as f32 * 0.180)));
738739

739-
let view = glm::ext::look_at(
740-
glm::vec3(2.0, 2.0, 2.0),
741-
glm::vec3(0.0, 0.0, 0.0),
742-
glm::vec3(0.0, 0.0, 1.0)
740+
let view = Matrix4::look_at(
741+
Point3::new(2.0, 2.0, 2.0),
742+
Point3::new(0.0, 0.0, 0.0),
743+
Vector3::new(0.0, 0.0, 1.0)
743744
);
744-
let mut proj = glm::ext::perspective(
745-
glm::radians(45.0,),
745+
746+
let mut proj = cgmath::perspective(
747+
Rad::from(Deg(45.0)),
746748
dimensions[0] as f32 / dimensions[1] as f32,
747749
0.1,
748750
10.0
749751
);
750752

751-
proj.c1.y *= -1.0;
753+
proj.y.y *= -1.0;
752754

753755
UniformBufferObject { model, view, proj }
754756
}

0 commit comments

Comments
 (0)