Skip to content

Commit e775286

Browse files
committed
adds cgmath
1 parent 7ba1207 commit e775286

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

src/bin/29_multisampling.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern crate vulkano_win;
44
extern crate winit;
55
extern crate image;
66
extern crate tobj;
7+
extern crate cgmath;
78

89
use std::sync::{Arc, Mutex};
910
use std::collections::HashSet;
@@ -86,8 +87,17 @@ use vulkano::sampler::{
8687
Sampler,
8788
Filter,
8889
};
90+
8991
use image::GenericImageView;
9092

93+
use cgmath::{
94+
Rad,
95+
Deg,
96+
Matrix4,
97+
Vector3,
98+
Point3
99+
};
100+
91101
const WIDTH: u32 = 800;
92102
const HEIGHT: u32 = 600;
93103

@@ -141,9 +151,9 @@ impl_vertex!(Vertex, pos, color, tex);
141151
#[allow(dead_code)]
142152
#[derive(Copy, Clone)]
143153
struct UniformBufferObject {
144-
model: glm::Mat4,
145-
view: glm::Mat4,
146-
proj: glm::Mat4,
154+
model: Matrix4<f32>,
155+
view: Matrix4<f32>,
156+
proj: Matrix4<f32>,
147157
}
148158

149159
type DescriptorSetUBO = PersistentDescriptorSetBuf<Arc<CpuAccessibleBuffer<UniformBufferObject>>>;
@@ -946,28 +956,22 @@ impl HelloTriangleApplication {
946956
let duration = Instant::now().duration_since(start_time);
947957
let elapsed = (duration.as_secs() * 1000) + u64::from(duration.subsec_millis());
948958

949-
let identity_matrix = glm::mat4(
950-
1.0, 0.0, 0.0, 0.0,
951-
0.0, 1.0, 0.0, 0.0,
952-
0.0, 0.0, 1.0, 0.0,
953-
0.0, 0.0, 0.0, 1.0,
954-
);
955-
956-
let model = glm::ext::rotate(&identity_matrix, (elapsed as f32) * glm::radians(0.180), glm::vec3(0.0, 0.0, 1.00));
959+
let model = Matrix4::from_angle_z(Rad::from(Deg(elapsed as f32 * 0.180)));
957960

958-
let view = glm::ext::look_at(
959-
glm::vec3(2.0, 2.0, 2.0),
960-
glm::vec3(0.0, 0.0, 0.0),
961-
glm::vec3(0.0, 0.0, 1.0)
961+
let view = Matrix4::look_at(
962+
Point3::new(2.0, 2.0, 2.0),
963+
Point3::new(0.0, 0.0, 0.0),
964+
Vector3::new(0.0, 0.0, 1.0)
962965
);
963-
let mut proj = glm::ext::perspective(
964-
glm::radians(45.0,),
966+
967+
let mut proj = cgmath::perspective(
968+
Rad::from(Deg(45.0)),
965969
dimensions[0] as f32 / dimensions[1] as f32,
966970
0.1,
967971
10.0
968972
);
969973

970-
proj.c1.y *= -1.0;
974+
proj.y.y *= -1.0;
971975

972976
UniformBufferObject { model, view, proj }
973977
}

src/bin/29_multisampling.rs.diff

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
--- a/28_generating_mipmaps.rs
22
+++ b/29_multisampling.rs
3-
@@ -85,8 +85,6 @@ use vulkano::descriptor::descriptor_set::{
3+
@@ -86,8 +86,6 @@ use vulkano::descriptor::descriptor_set::{
44
use vulkano::sampler::{
55
Sampler,
66
Filter,
77
- MipmapMode,
88
- SamplerAddressMode,
99
};
10-
use image::GenericImageView;
1110

12-
@@ -183,6 +181,7 @@ struct HelloTriangleApplication {
11+
use image::GenericImageView;
12+
@@ -193,6 +191,7 @@ struct HelloTriangleApplication {
1313
command_buffers: Vec<Arc<AutoCommandBuffer>>,
1414

1515
depth_format: Format,
1616
+ sample_count: u32,
1717

1818
previous_frame_end: Option<Box<GpuFuture>>,
1919
recreate_swap_chain: bool,
20-
@@ -203,14 +202,16 @@ impl HelloTriangleApplication {
20+
@@ -213,14 +212,16 @@ impl HelloTriangleApplication {
2121
let (swap_chain, swap_chain_images) = Self::create_swap_chain(&instance, &surface, physical_device_index,
2222
&device, &graphics_queue, &present_queue, None);
2323

@@ -37,15 +37,15 @@
3737

3838
let start_time = Instant::now();
3939

40-
@@ -258,6 +259,7 @@ impl HelloTriangleApplication {
40+
@@ -268,6 +269,7 @@ impl HelloTriangleApplication {
4141
command_buffers: vec![],
4242

4343
depth_format,
4444
+ sample_count,
4545

4646
previous_frame_end,
4747
recreate_swap_chain: false,
48-
@@ -444,42 +446,61 @@ impl HelloTriangleApplication {
48+
@@ -454,42 +456,61 @@ impl HelloTriangleApplication {
4949
(swap_chain, images)
5050
}
5151

@@ -118,7 +118,7 @@
118118
}
119119
).unwrap())
120120
}
121-
@@ -538,15 +559,21 @@ impl HelloTriangleApplication {
121+
@@ -548,15 +569,21 @@ impl HelloTriangleApplication {
122122
}
123123

124124
fn create_framebuffers(
@@ -142,7 +142,7 @@
142142
.build().unwrap());
143143
fba
144144
}
145-
@@ -642,25 +669,7 @@ impl HelloTriangleApplication {
145+
@@ -652,25 +679,7 @@ impl HelloTriangleApplication {
146146
}
147147

148148
fn create_image_sampler(device: &Arc<Device>) -> Arc<Sampler> {
@@ -169,7 +169,7 @@
169169
}
170170

171171
fn load_model() -> (Vec<Vertex>, Vec<u32>) {
172-
@@ -789,7 +798,7 @@ impl HelloTriangleApplication {
172+
@@ -799,7 +808,7 @@ impl HelloTriangleApplication {
173173
.unwrap()
174174
.update_buffer(self.uniform_buffers[i].clone(), Self::update_uniform_buffer(self.start_time, dimensions))
175175
.unwrap()
@@ -178,7 +178,7 @@
178178
.unwrap()
179179
.draw_indexed(
180180
self.graphics_pipeline.clone(),
181-
@@ -967,16 +976,16 @@ impl HelloTriangleApplication {
181+
@@ -971,16 +980,16 @@ impl HelloTriangleApplication {
182182
let (swap_chain, images) = Self::create_swap_chain(&self.instance, &self.surface, self.physical_device_index,
183183
&self.device, &self.graphics_queue, &self.present_queue, Some(self.swap_chain.clone()));
184184

0 commit comments

Comments
 (0)