Clemsim 2 년 전
부모
커밋
944367d495
1개의 변경된 파일52개의 추가작업 그리고 1개의 파일을 삭제
  1. 52 1
      src/main.rs

+ 52 - 1
src/main.rs

@@ -1,5 +1,56 @@
 use bevy::prelude::*;
 
+struct Plane {
+    mesh: Mesh,
+    vertex_buffer: VertexBuffer,
+}
+
+impl Plane {
+    fn new(app: &mut App) -> Self {
+        let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
+        mesh.add_vertices(&[
+            Vertex::new(Position([0.0, 0.0, 0.0]), Normal([0.0, 0.0, 1.0]), Uv([0.0, 0.0])),
+            Vertex::new(Position([10.0, 0.0, 0.0]), Normal([0.0, 0.0, 1.0]), Uv([1.0, 0.0])),
+            Vertex::new(Position([10.0, 10.0, 0.0]), Normal([0.0, 0.0, 1.0]), Uv([1.0, 1.0])),
+        ]);
+        mesh.set_indices(&[0, 1, 2]);
+
+        let vertex_buffer = VertexBuffer::from_mesh(mesh);
+
+        Self { mesh, vertex_buffer }
+    }
+
+    fn update_vertex_positions(&self, time: f32) {
+        let amplitude = 1.0;
+        let frequency = 1.0;
+
+        for vertex in self.vertex_buffer.iter_mut() {
+            vertex.position[0] += amplitude * (f32::sin(frequency * time) - f32::sin(frequency * (time - 1.0)));
+        }
+    }
+}
+
 fn main() {
-    println!("Hello, world!");
+    let mut app = App::new();
+
+    app.add_startup_system(setup);
+    app.add_system(update);
+
+    app.run();
+}
+
+fn setup(mut commands: Commands) {
+    let plane = Plane::new(&mut commands);
+
+    commands.spawn_bundle((
+        plane.mesh,
+        plane.vertex_buffer,
+        GlobalTransform::identity(),
+    ));
+}
+
+fn update(time: Res<Time>, mut planes: Query<&mut Plane>) {
+    for mut plane in planes.iter_mut() {
+        plane.update_vertex_positions(time.seconds());
+    }
 }