added more code to render my first scene; STILL WITH ERRORS
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
use crate::engine::mesh::Mesh;
|
||||
use glow::Context;
|
||||
use nalgebra::Vector3;
|
||||
|
||||
pub struct OctaSphere {
|
||||
@ -20,7 +21,14 @@ impl OctaSphere {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_sphere(&mut self) {
|
||||
pub fn render(&mut self, gl: &Context) {
|
||||
match self.mesh.as_mut() {
|
||||
None => {self.generate_sphere(); self.render(gl)},
|
||||
Some(mut mesh) => {mesh.render(gl)}
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_sphere(&mut self) {
|
||||
let (vertices, indices) = self.generator.generate_sphere();
|
||||
self.mesh = Some(Mesh::new(vertices, indices))
|
||||
}
|
||||
@ -51,9 +59,10 @@ impl OctaSphereGenerator {
|
||||
let num_vertices = num_vertices_per_face * 8 - (num_divisions + 2) * 12 + 6;
|
||||
let num_tris_per_face = (num_divisions + 1) * (num_divisions + 1);
|
||||
|
||||
|
||||
let mut vertices = Vec::<Vector3<f32>>::with_capacity(num_vertices as usize);
|
||||
let mut indicies = Vec::<u32>::with_capacity((num_tris_per_face * 8 * 3) as usize);
|
||||
vertices.copy_from_slice(&base_vertices);
|
||||
vertices.extend_from_slice(&base_vertices);
|
||||
|
||||
// Create 12 edges, with n vertices added along them (n = numDivisions)
|
||||
let mut edges = Vec::<Edge>::with_capacity(12);
|
||||
|
Reference in New Issue
Block a user