Skip to content

Instantly share code, notes, and snippets.

@ChristopherBiscardi
Created June 28, 2025 22:24
Show Gist options
  • Select an option

  • Save ChristopherBiscardi/73bf6012f6bef6a4f1779d6b2b1f129a to your computer and use it in GitHub Desktop.

Select an option

Save ChristopherBiscardi/73bf6012f6bef6a4f1779d6b2b1f129a to your computer and use it in GitHub Desktop.

Revisions

  1. ChristopherBiscardi created this gist Jun 28, 2025.
    69 changes: 69 additions & 0 deletions main.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    use std::f32::consts::PI;

    use bevy::prelude::*;

    fn main() -> AppExit {
    App::new()
    .add_plugins(DefaultPlugins)
    .add_systems(Startup, startup)
    .add_systems(FixedUpdate, update)
    .run()
    }

    #[derive(Component)]
    struct Rotate;

    fn startup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
    ) {
    commands.spawn((
    Mesh3d(
    meshes.add(Plane3d::new(
    Vec3::Y,
    Vec2::splat(10.),
    )),
    ),
    MeshMaterial3d(materials.add(StandardMaterial {
    cull_mode: None,
    double_sided: true,
    ..default()
    })),
    Transform::from_rotation(Quat::from_rotation_x(
    -std::f32::consts::FRAC_PI_2,
    )),
    Rotate,
    ));
    // cube
    commands.spawn((
    Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
    MeshMaterial3d(
    materials.add(Color::srgb_u8(124, 144, 255)),
    ),
    Transform::from_xyz(0.0, 0.5, 0.0),
    ));
    // light
    commands.spawn((
    PointLight {
    shadows_enabled: true,
    ..default()
    },
    Transform::from_xyz(4.0, 8.0, 4.0),
    ));
    // camera
    commands.spawn((
    Camera3d::default(),
    Transform::from_xyz(-2.5, 4.5, 9.0)
    .looking_at(Vec3::ZERO, Vec3::Y),
    ));
    }

    fn update(
    mut query: Query<&mut Transform, With<Rotate>>,
    time: Res<Time>,
    ) {
    for mut transform in &mut query {
    transform.rotate_x(PI * time.delta_secs());
    }
    }