Created
June 16, 2017 18:07
-
-
Save alexander-irbis/c460ba343f02b6f4e22baee1d151b919 to your computer and use it in GitHub Desktop.
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
extern crate cgmath; | |
//extern crate mint; | |
extern crate three; | |
use cgmath::prelude::*; | |
use three::*; | |
fn main() { | |
let mut win = three::Window::new("Colors", "assets/shaders"); | |
let mut cam = win.factory.perspective_camera(75.0, 0.0, 1.0, 50.0); | |
cam.set_position([0.0, 0.0, 10.0]); | |
let mut mbox: Mesh = { | |
let geometry = three::Geometry::new_box(3.0, 2.0, 1.0); | |
let material = three::Material::MeshBasic { color: 0x00ff00, map: None, wireframe: true }; | |
win.factory.mesh(geometry, material) | |
}; | |
mbox.set_position([-3.0, -3.0, 0.0]); | |
win.scene.add(&mbox); | |
let mut time: f32 = 0.0; | |
let mut angle = cgmath::Rad::zero(); | |
let speed = 1.5; | |
while let Some(events) = win.update() { | |
time += events.time_delta; | |
mbox.set_position([-3.0, -3.0 + time.sin(), 0.0]); | |
let old_angle = angle; | |
if events.keys.contains(&three::Key::Left) { | |
angle -= cgmath::Rad(speed * events.time_delta); | |
} | |
if events.keys.contains(&three::Key::Right) { | |
angle += cgmath::Rad(speed * events.time_delta); | |
} | |
if angle != old_angle { | |
let q = cgmath::Quaternion::from_angle_y(angle); | |
let rot = [q.v.x, q.v.y, q.v.z, q.s]; | |
mbox.set_orientation(rot); | |
} | |
win.render(&cam); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment