From: Bernie Innocenti Date: Tue, 11 Apr 2017 02:39:42 +0000 (-0400) Subject: Start using cgmath. X-Git-Tag: v0.6.0~11 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=70862a24f674f89190e392c0d1cb9f3dfe405059;p=mandelwow.git Start using cgmath. --- diff --git a/main.rs b/main.rs index 5507f4a..12a127b 100644 --- a/main.rs +++ b/main.rs @@ -1,13 +1,15 @@ // Wow. Such fractal. -#[macro_use] - +extern crate cgmath; +#[macro_use(uniform,program,implement_vertex)] extern crate glium; extern crate glutin; extern crate image; extern crate libxm; extern crate sdl2; +//use cgmath::prelude::*; +use cgmath::{Euler, Matrix4, Rad, Vector3}; use cube::Cube; use glium::{DisplayBuild, Surface}; use glutin::ElementState::Pressed; @@ -31,7 +33,7 @@ fn screenshot(display : &glium::Display) { fn main() { let _soundplayer = sound::start(); - let display = glium::glutin::WindowBuilder::new() + let display = glutin::WindowBuilder::new() //.with_dimensions(1024, 768) .with_fullscreen(glutin::get_primary_monitor()) .with_depth_buffer(24) @@ -78,13 +80,12 @@ fn main() { let mut frame = display.draw(); frame.clear_color_and_depth((0.0, 0.0, 0.0, 1.0), 1.0); + let rotation = cgmath::Matrix4::from( + Euler { x: Rad(t.sin() / 3.), y: Rad(t.sin() / 2.), z: Rad(t)}); let z_trans = -2.0; // Send the model back a little bit so it fits the screen. - let model = [ - [ t.cos(), t.sin(), 0.0, 0.0], - [-t.sin(), t.cos(), 0.0, 0.0], - [ 0.0, 0.0, 1.0, 0.0], - [ 0.0, 0.0, z_trans, 1.0f32] - ]; + let model2 = + Matrix4::from_translation(Vector3::unit_z() * z_trans) * rotation; + let model = cgmath::conv::array4x4(model2); // Draw the bounding box before the fractal, when the Z-buffer is still clear, // so the lines behind the semi-translucent areas will be drawn. @@ -102,7 +103,7 @@ fn main() { for ev in display.poll_events() { match ev { - glium::glutin::Event::Closed | + glutin::Event::Closed | KeyboardInput(Pressed, _, Some(VirtualKeyCode::Escape)) | KeyboardInput(Pressed, _, Some(VirtualKeyCode::Q)) => { return support::Action::Stop diff --git a/mandelwow.frag b/mandelwow.frag index 3795fd4..260e1bf 100644 --- a/mandelwow.frag +++ b/mandelwow.frag @@ -14,15 +14,15 @@ void main() { float zy2 = zy * zy; if (zx2 * zy2 > 4.0) { float index = float(iter) / float(maxiter); - f_color = vec4(index, 0.1, 0.5 - index / 2, 0.8 - index); + f_color = vec4(index, 0.1, 1.0 - index / 2, 0.8 - index); return; } zy = zx * zy * 2.0 + c.y; zx = zx2 - zy2 + c.x; iter -= 1; } - f_color = vec4((sin(z.y) + 1.0) / 2, - (sin(c.y) + 1.0) / 2, - (sin(c.x) + 1.0) / 2, + f_color = vec4((sin(z.y) + 1.0) / 4, + (sin(z.x) + 1.0) / 4, + (sin(c.x) + 1.0) / 4, 1.0); }