[INSTANCE] Update instances
This commit is contained in:
parent
ba226db6e5
commit
d9e8b96754
1 changed files with 20 additions and 1 deletions
|
@ -35,6 +35,9 @@ const INSTANCE_DISPLACEMENT: cgmath::Vector3<f32> = cgmath::Vector3::new(
|
|||
NUM_INSTANCES_PER_ROW as f32 * 0.5,
|
||||
);
|
||||
|
||||
const FRAME_TIME: f32 = 1.0 / 60.0;
|
||||
const ROTATION_SPEED: f32 = std::f32::consts::PI * FRAME_TIME * 0.5;
|
||||
|
||||
pub struct State {
|
||||
pub surface: wgpu::Surface,
|
||||
pub device: wgpu::Device,
|
||||
|
@ -310,7 +313,7 @@ impl State {
|
|||
let instance_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Instance Buffer"),
|
||||
contents: bytemuck::cast_slice(&instance_data),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
|
||||
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
|
@ -418,6 +421,22 @@ impl State {
|
|||
0,
|
||||
bytemuck::cast_slice(&[self.camera_uniform]),
|
||||
);
|
||||
|
||||
for instance in &mut self.instances {
|
||||
let amount = cgmath::Quaternion::from_angle_y(cgmath::Rad(ROTATION_SPEED));
|
||||
let current = instance.rotation;
|
||||
instance.rotation = amount * current;
|
||||
}
|
||||
let instance_data = self
|
||||
.instances
|
||||
.iter()
|
||||
.map(super::instance::Instance::to_raw)
|
||||
.collect::<Vec<_>>();
|
||||
self.queue.write_buffer(
|
||||
&self.instance_buffer,
|
||||
0,
|
||||
bytemuck::cast_slice(&instance_data),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn render(&mut self) -> Result<(), wgpu::SurfaceError> {
|
||||
|
|
Loading…
Reference in a new issue