Skip to content

Instantly share code, notes, and snippets.

@russmack
Created July 21, 2018 16:39
Show Gist options
  • Save russmack/c1395fb3fbd6b16ea27dda722c582853 to your computer and use it in GitHub Desktop.
Save russmack/c1395fb3fbd6b16ea27dda722c582853 to your computer and use it in GitHub Desktop.
This demonstrates the difference in point rendering between Kiss3d v0.13.0 and v0.14.0
extern crate glfw;
extern crate kiss3d;
extern crate nalgebra as na;
use na::Point3;
use kiss3d::window::Window;
use kiss3d::light::Light;
/*
Good Cargo.toml
[dependencies]
kiss3d = "0.13.0"
gl = "0.6.5"
glfw = "0.19.0"
image = "0.17.0"
libc = "0.2.42"
nalgebra = "0.14.4"
ncollide_procedural = "0.9.0"
num-traits = "0.2.5"
Bad Cargo.toml
[dependencies]
kiss3d = "0.14.0"
gl = "0.6.5"
glfw = "0.19.0"
image = "0.17.0"
libc = "0.2.42"
nalgebra = "0.14.4"
ncollide_procedural = "0.9.0"
num-traits = "0.2.5"
*/
fn main() {
// Setup the window.
let mut window = Window::new_with_size("Kiss3d: points", 1200, 800);
// Setup the camera.
window.set_light(Light::StickToCamera);
// Constants.
let max = 100.0;
while window.render() {
// Bounding box.
draw_bounding_box(&mut window, max);
// Draw points
let ubound = 100.0;
let step = 1.0;
// Blue side.
let (mut x, y, mut z) = (0.0, 0.0, 0.0);
let (red, green, blue) = (0.6, 0.8, 1.0);
while x < ubound {
while z < ubound {
window.draw_point(
&Point3::new(x, y, z),
&Point3::new(red, green, blue));
z += step;
}
z = 0.0;
x += step;
}
// Green side
let (x, mut y, mut z) = (0.0, 0.0, 0.0);
let (red, green, blue) = (0.0, 1.0, 0.0);
while y < ubound {
while z < ubound {
window.draw_point(
&Point3::new(x, y, z),
&Point3::new(red, green, blue));
z += step;
}
z = 0.0;
y += step;
}
// Red side
let (mut x, mut y, z) = (0.0, 0.0, 0.0);
let (red, green, blue) = (1.0, 0.0, 0.0);
while x < ubound {
while y < ubound {
window.draw_point(
&Point3::new(x, y, z),
&Point3::new(red, green, blue));
y += step;
}
y = 0.0;
x += step;
}
}
}
fn draw_bounding_box(window: &mut kiss3d::window::Window, max: f32) {
let a = Point3::new(0.0, 0.0, 0.0);
let b = Point3::new(0.0, 0.0, max);
let c = Point3::new(max, 0.0, max);
let d = Point3::new(max, 0.0, 0.0);
let e = Point3::new(0.0, max, 0.0);
let f = Point3::new(0.0, max, max);
let g = Point3::new(max, max, max);
let h = Point3::new(max, max, 0.0);
let colour = &Point3::new(0.3, 0.3, 0.3);
window.draw_line(&a, &b, &colour);
window.draw_line(&b, &c, &colour);
window.draw_line(&c, &d, &colour);
window.draw_line(&d, &a, &colour);
window.draw_line(&e, &f, &colour);
window.draw_line(&f, &g, &colour);
window.draw_line(&g, &h, &colour);
window.draw_line(&h, &e, &colour);
window.draw_line(&a, &e, &colour);
window.draw_line(&b, &f, &colour);
window.draw_line(&c, &g, &colour);
window.draw_line(&d, &h, &colour);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment