#Rotating a cube seems to make it change shape...

2 messages · Page 1 of 1 (latest)

summer lava
#

If I try to rotate a mesh at some angle that is not inline with the coordinate axies, the mesh starts to distort.

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .add_system(spin_cube)
        .run();
}

#[derive(Component)]
struct Cube;

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..Default::default()
    });
    commands.spawn(PointLightBundle {
        transform: Transform::from_xyz(4.0, 8.0, 4.0),
        ..Default::default()
    });

    // spawn a cube
    commands
        .spawn(PbrBundle {
            mesh: meshes.add(shape::Cube::default().into()),
            material: materials.add(Color::rgb(0., 0.5, 1.0).into()),
            transform: Transform::from_xyz(0.0, 0.5, 0.0),
            ..Default::default()
        })
        .insert(Cube);
}

// spin the cube at an angle
fn spin_cube(time: Res<Time>, mut query: Query<&mut Transform, With<Cube>>) {
    for mut transform in query.iter_mut() {
        transform.rotate_axis(Vec3::new(0., 1., 1.), 0.03);
    }
}

wispy iron
#

rotate_axis expects a normalized vector