-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: instancing now works, with example. fix #40
- Loading branch information
1 parent
1dafadf
commit 8e5e2db
Showing
10 changed files
with
258 additions
and
139 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Blue Engine by Elham Aryanpur | ||
* | ||
* Triangle example using pre-defined shapes | ||
* | ||
* The license is same as the one on the root. | ||
*/ | ||
|
||
use blue_engine::{ | ||
header::{Engine, ObjectSettings}, | ||
primitive_shapes::triangle, | ||
Instance, | ||
}; | ||
|
||
pub fn main() { | ||
// start the engine | ||
let mut engine = Engine::new().expect("window not created"); | ||
|
||
// create a triangle | ||
triangle( | ||
"Triangle", | ||
ObjectSettings::default(), | ||
&mut engine.renderer, | ||
&mut engine.objects, | ||
) | ||
.unwrap(); | ||
|
||
// update the triangle | ||
engine.objects.update_object("Triangle", |object| { | ||
// set the position of the main triangle | ||
object.set_position(0f32, 0f32, -3f32); | ||
|
||
// a function to make instance creation easier | ||
let create_instance = |x: f32, y: f32, z: f32| { | ||
Instance::new( | ||
[x, y, z].into(), | ||
[0f32, 0f32, 0f32].into(), | ||
[1f32, 1f32, 1f32].into(), | ||
) | ||
}; | ||
|
||
// add an instance | ||
object.add_instance(create_instance(2f32, 1f32, -2f32)); | ||
object.add_instance(create_instance(2f32, -1f32, -2f32)); | ||
object.add_instance(create_instance(-2f32, 1f32, -2f32)); | ||
object.add_instance(create_instance(-2f32, -1f32, -2f32)); | ||
}); | ||
|
||
// we manually update the instance buffer before the next frame starts | ||
// this is due to the object updates happening after every frame, hence | ||
// for the first frame, we need to update it ourselves. | ||
engine | ||
.objects | ||
.get_mut("Triangle") | ||
.expect("Couldn't get the triangle") | ||
.update_instance_buffer(&mut engine.renderer) | ||
.expect("Couldn't update instance buffer"); | ||
|
||
// run the loop as normal | ||
engine | ||
.update_loop(move |_, _, _, _, _, _| {}) | ||
.expect("Error during update loop"); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.