Update transform
This commit is contained in:
parent
1a61aab218
commit
4f96a1e4b5
2 changed files with 99 additions and 26 deletions
|
@ -58,19 +58,16 @@ impl Scene for MainScene {
|
|||
let instance_spacing = 10.0;
|
||||
let num_instances_per_row = (num_instances as f32 / instance_spacing).ceil() as u32;
|
||||
let instances: Vec<Transform> = (0..num_instances)
|
||||
.map(|i| Transform {
|
||||
position: Vec3::new(
|
||||
(i % num_instances_per_row) as f32 * (instance_spacing + instance_size),
|
||||
0.0,
|
||||
(i / num_instances_per_row) as f32 * (instance_spacing + instance_size),
|
||||
),
|
||||
rotation: Quat::from_euler(
|
||||
EulerRot::XYZ,
|
||||
0.0,
|
||||
rand::random_range(0.0..=360.0),
|
||||
0.0,
|
||||
),
|
||||
scale: Vec3::new(instance_size, instance_size, instance_size),
|
||||
.map(|i| {
|
||||
Transform::new(
|
||||
Vec3::new(
|
||||
(i % num_instances_per_row) as f32 * (instance_spacing + instance_size),
|
||||
0.0,
|
||||
(i / num_instances_per_row) as f32 * (instance_spacing + instance_size),
|
||||
),
|
||||
Quat::from_euler(EulerRot::XYZ, 0.0, rand::random_range(0.0..=360.0), 0.0),
|
||||
Vec3::new(instance_size, instance_size, instance_size),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
@ -129,6 +126,14 @@ impl Scene for MainScene {
|
|||
});
|
||||
});
|
||||
|
||||
let delta_time = app_context.get_delta_time();
|
||||
for (i, instance) in state.instances.iter_mut().enumerate() {
|
||||
let rotation_speed = (i % 10) as f32;
|
||||
let rotation_delta = Quat::from_rotation_y(rotation_speed * delta_time);
|
||||
|
||||
instance.rotate(rotation_delta);
|
||||
}
|
||||
|
||||
if app_context
|
||||
.with_input_manager(|input_manager| input_manager.get_virtual_input_state("mouse_left"))
|
||||
> 0.0
|
||||
|
@ -167,7 +172,7 @@ impl Scene for MainScene {
|
|||
before_future: Box<dyn GpuFuture>,
|
||||
app_context: &mut WindowContext,
|
||||
) -> Result<Box<dyn GpuFuture>, Box<dyn Error>> {
|
||||
let state = self.state.as_ref().ok_or("State not loaded")?;
|
||||
let state = self.state.as_mut().ok_or("State not loaded")?;
|
||||
|
||||
let mut builder = AutoCommandBufferBuilder::primary(
|
||||
app_context.command_buffer_allocator.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue