forked from processing/libprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.rs
More file actions
56 lines (44 loc) · 1.5 KB
/
box.rs
File metadata and controls
56 lines (44 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
mod glfw;
use glfw::GlfwContext;
use processing::prelude::*;
use processing_render::render::command::DrawCommand;
fn main() {
match sketch() {
Ok(_) => {
eprintln!("Sketch completed successfully");
exit(0).unwrap();
}
Err(e) => {
eprintln!("Sketch error: {:?}", e);
exit(1).unwrap();
}
};
}
fn sketch() -> error::Result<()> {
let mut glfw_ctx = GlfwContext::new(400, 400)?;
init(Config::default())?;
let width = 400;
let height = 400;
let scale_factor = 1.0;
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
let graphics = graphics_create(surface, width, height)?;
let box_geo = geometry_box(100.0, 100.0, 100.0)?;
graphics_mode_3d(graphics)?;
graphics_camera_position(graphics, 100.0, 100.0, 300.0)?;
graphics_camera_look_at(graphics, 0.0, 0.0, 0.0)?;
let mut angle = 0.0;
while glfw_ctx.poll_events() {
graphics_begin_draw(graphics)?;
graphics_record_command(
graphics,
DrawCommand::BackgroundColor(bevy::color::Color::srgb(0.1, 0.1, 0.15)),
)?;
graphics_record_command(graphics, DrawCommand::PushMatrix)?;
graphics_record_command(graphics, DrawCommand::Rotate { angle })?;
graphics_record_command(graphics, DrawCommand::Geometry(box_geo))?;
graphics_record_command(graphics, DrawCommand::PopMatrix)?;
graphics_end_draw(graphics)?;
angle += 0.02;
}
Ok(())
}