MCPcopy Create free account
hub / github.com/AryanpurTech/BlueEngine / main

Function main

examples/utils/instancing.rs:15–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13};
14
15pub fn main() -> Result<(), blue_engine::error::Error> {
16 // start the engine
17 let mut engine = Engine::new()?;
18
19 // create a triangle
20 triangle(
21 "Triangle",
22 ObjectSettings::default(),
23 &mut engine.renderer,
24 &mut engine.objects,
25 )?;
26
27 // update the triangle
28 let shape = engine
29 .objects
30 .get_mut("Triangle")
31 .expect("Couldn't get the triangle");
32
33 // set the position of the main triangle
34 shape.set_position(Vector3::new(0f32, 0f32, -3f32));
35
36 // add an instance
37 shape.add_instance(Instance {
38 position: Vector3::new(2f32, 1f32, -2f32),
39 ..Default::default()
40 });
41 shape.add_instance(Instance {
42 position: Vector3::new(2f32, -1f32, -2f32),
43 ..Default::default()
44 });
45 shape.add_instance(Instance {
46 position: Vector3::new(-2f32, 1f32, -2f32),
47 ..Default::default()
48 });
49 shape.add_instance(Instance {
50 position: Vector3::new(-2f32, -1f32, -2f32),
51 ..Default::default()
52 });
53
54 // we manually update the instance buffer before the next frame starts
55 // this is due to the object updates happening after every frame, hence
56 // for the first frame, we need to update it ourselves.
57 shape.update_instance_buffer(&mut engine.renderer);
58
59 // run the loop as normal
60 engine.update_loop(move |_| {})?;
61
62 Ok(())
63}

Callers

nothing calls this directly

Calls 5

triangleFunction · 0.85
add_instanceMethod · 0.80
update_loopMethod · 0.80
set_positionMethod · 0.45

Tested by

no test coverage detected