1use std::f32::consts::PI;
4
5use glam::{vec2, vec3};
6use vert::{
7 elements::{Color, Transform},
8 modules::{
9 batteries::{FlyCam, GraphicsSettingsController},
10 renderer::main_pass_renderer::text_renderer::DrawText,
11 DefaultDependencies, DefaultModules,
12 },
13 utils::Timing,
14 Module,
15};
16
17pub struct MyState {
18 blue_cubes: Vec<Transform>,
19 black_cubes: Vec<Transform>,
20 camera_orthographic: bool,
21 deps: DefaultDependencies,
22}
23
24impl Module for MyState {
25 type Config = ();
26
27 type Dependencies = DefaultDependencies;
28
29 fn new(_config: Self::Config, mut deps: Self::Dependencies) -> anyhow::Result<Self> {
30 let mut blue_cubes: Vec<Transform> = vec![];
31 let mut black_cubes: Vec<Transform> = vec![];
32
33 for x in 0..30 {
34 for y in 0..30 {
35 for z in 0..30 {
36 let pos = vec3(
37 x as f32 * 2.0 + 20.0 + (z as f32 * 0.1).sin() * 2.0,
38 y as f32 * 2.0 - 30.0 + (z as f32).sin() * 2.0,
39 z as f32 * 2.0 - 30.0 + ((x + y) % 2) as f32,
40 );
41 if (x + y) % 2 == 0 {
42 blue_cubes.push(pos.into());
43 } else {
44 black_cubes.push(pos.into());
45 };
46 }
47 }
48 }
49
50 deps.renderer.settings_mut().clear_color = Color::new(2.0, 8.0, 2.0);
52
53 Ok(MyState {
54 black_cubes,
55 blue_cubes,
56 camera_orthographic: false,
57 deps,
58 })
59 }
60
61 fn intialize(handle: vert::Handle<Self>) -> anyhow::Result<()> {
62 let mut scheduler = handle.deps.scheduler;
63 scheduler.register_update(handle, Timing::DEFAULT, Self::update);
64 Ok(())
65 }
66}
67
68impl MyState {
69 fn update(&mut self) {
70 let oscillator = ((self.deps.time.total().as_secs_f32() * 10.0).sin() + 1.0) / 2.0;
75 let oscillator2 = self.deps.time.total().as_secs_f32().sin() * 0.3;
76
77 let text_rotation = {
79 let mut t = Transform::default();
80 t.rotate_y(-PI / 2.0);
81 t.position.y += 0.5;
82 t
83 };
84
85 self.deps.text.draw_world_text(
86 DrawText {
87 text: "Vert".into(),
88 font_layout_size: 100.0,
89 font_texture_size: 200.0,
90 max_width: Some(400.0),
91 color: Color::new(
92 3.0 + oscillator * 10.0,
93 3.0 + (1.0 - oscillator) * 10.0,
94 3.0,
95 ),
96 ..Default::default()
97 },
98 text_rotation,
99 );
100
101 self.deps.text.draw_world_text(
102 DrawText {
103 text: "Game Engine".into(),
104 font_layout_size: 64.0,
105 font_texture_size: 200.0,
106 pos: vec2(0.0, 100.0),
107 max_width: Some(400.0),
108 color: Color::new(10.0, 1.0, 1.0),
109 ..Default::default()
110 },
111 text_rotation,
112 );
113
114 for c in self.blue_cubes.iter_mut() {
115 c.rotation.x = oscillator2;
116 }
117
118 self.deps
119 .color_mesh
120 .draw_cubes(&self.blue_cubes, Some(Color::from_hex("#02050d")));
121 self.deps
122 .color_mesh
123 .draw_cubes(&self.black_cubes, Some(Color::from_hex("#000000")));
124 }
125}
126
127fn main() {
128 let mut app = vert::AppBuilder::new();
129 app.add_plugin(DefaultModules);
130 app.add::<GraphicsSettingsController>();
131 app.add::<FlyCam>();
132 app.add::<MyState>();
133 _ = app.run();
134}