Commit b06ee13bf7204350592c82fe8907f3a7bff0b233
1 parent
561f75cd
display both f64 and Fractional based polygons
Showing
1 changed file
with
57 additions
and
52 deletions
@@ -21,6 +21,7 @@ | @@ -21,6 +21,7 @@ | ||
21 | use std::convert::{TryFrom, TryInto, Into}; | 21 | use std::convert::{TryFrom, TryInto, Into}; |
22 | use std::f64::consts::PI as FPI; | 22 | use std::f64::consts::PI as FPI; |
23 | use std::fmt::Display; | 23 | use std::fmt::Display; |
24 | +use std::marker::Send; | ||
24 | use std::num::TryFromIntError; | 25 | use std::num::TryFromIntError; |
25 | use std::ops::{Add,Sub,Neg,Mul,Div}; | 26 | use std::ops::{Add,Sub,Neg,Mul,Div}; |
26 | use std::sync::mpsc; | 27 | use std::sync::mpsc; |
@@ -309,66 +310,34 @@ fn _line() { | @@ -309,66 +310,34 @@ fn _line() { | ||
309 | println!("{:>14} : {}", pg, pg.plot()); | 310 | println!("{:>14} : {}", pg, pg.plot()); |
310 | } | 311 | } |
311 | 312 | ||
312 | -fn main() { | ||
313 | - common_fractional(); | ||
314 | - println!(); | ||
315 | - continuous(); | ||
316 | - println!(); | ||
317 | - sqrt(); | ||
318 | - println!(); | ||
319 | - pi(); | ||
320 | - println!(); | ||
321 | - _sin(); | ||
322 | - println!(); | ||
323 | - _cos(); | ||
324 | - println!(); | ||
325 | - _tan(); | ||
326 | - println!(); | ||
327 | - _vector1(); | ||
328 | - println!(); | ||
329 | - _vector2(); | ||
330 | - println!(); | ||
331 | - _transform1(); | ||
332 | - println!(); | ||
333 | - _transform2(); | ||
334 | - println!(); | ||
335 | - _line(); | 313 | +fn _democanvas<T>( xcb :&XcbEasel |
314 | + , title :&'static str | ||
315 | + , tx :mpsc::Sender<i32> | ||
316 | + , tetrahedron :Polyeder<T> | ||
317 | + , cube :Polyeder<T> ) | ||
318 | + where T: 'static + Add<Output = T> + Sub<Output = T> + Neg<Output = T> | ||
319 | + + Mul<Output = T> + Div<Output = T> | ||
320 | + + Copy + Trig + Send + From<i32> { | ||
336 | 321 | ||
337 | - let xcb = XcbEasel::new().unwrap(); | ||
338 | let mut canvas = xcb.canvas(151, 151).unwrap(); | 322 | let mut canvas = xcb.canvas(151, 151).unwrap(); |
323 | + let camera = Camera::<T>::new(&canvas, 45); // the orig. view angle | ||
324 | + // was 50. | ||
339 | 325 | ||
340 | - canvas.set_title("Something..."); | 326 | + canvas.set_title(title); |
341 | canvas.init_events(); | 327 | canvas.init_events(); |
328 | + canvas.start_events(tx.clone()); | ||
342 | 329 | ||
343 | - let (tx, rx) = mpsc::channel(); | ||
344 | - | ||
345 | - let tetrahedron = Polyeder::tetrahedron(60.0); | ||
346 | - let cube = Polyeder::cube(60.0); | ||
347 | - let camera = Camera::<f64>::new(&canvas, 45); // the orig. view angle | ||
348 | - // was 50. | ||
349 | - /* | ||
350 | - let tetrahedron = Polyeder::tetrahedron(Fractional(60,1)); | ||
351 | - let cube = Polyeder::cube(Fractional(60,1)); | ||
352 | - let camera = Camera::<Fractional>::new(&canvas, 45); | ||
353 | - */ | ||
354 | - | ||
355 | - canvas.start_events(tx); | ||
356 | - | ||
357 | - let start = Instant::now(); | ||
358 | - let step = Duration::from_millis(25); | ||
359 | - let mut last = Instant::now(); | ||
360 | thread::spawn(move || { | 330 | thread::spawn(move || { |
331 | + let start = Instant::now(); | ||
332 | + let step = Duration::from_millis(25); | ||
333 | + let mut last = Instant::now(); | ||
334 | + | ||
335 | + let t :TMatrix<T> = translate(Vector(0.into(), 0.into(), 150.into())); | ||
336 | + | ||
361 | loop { | 337 | loop { |
362 | let deg = ((start.elapsed() / 25).as_millis() % 360) as i32; | 338 | let deg = ((start.elapsed() / 25).as_millis() % 360) as i32; |
363 | 339 | ||
364 | - let t = translate(Vector(0.0, 0.0, 150.0)); | ||
365 | - let rz :TMatrix<f64> = rotate_z(deg); | ||
366 | - /* | ||
367 | - let t = translate(Vector( Fractional(0,1) | ||
368 | - , Fractional(0,1) | ||
369 | - , Fractional(150,1) )); | ||
370 | - let rz :TMatrix<Fractional> = rotate_z(deg); | ||
371 | - */ | 340 | + let rz :TMatrix<T> = rotate_z(deg); |
372 | 341 | ||
373 | let rot1 = TMatrix::combine(vec!(rz, rotate_x(-deg*2), t)); | 342 | let rot1 = TMatrix::combine(vec!(rz, rotate_x(-deg*2), t)); |
374 | let rot2 = TMatrix::combine(vec!(rz, rotate_y(-deg*2), t)); | 343 | let rot2 = TMatrix::combine(vec!(rz, rotate_y(-deg*2), t)); |
@@ -388,7 +357,7 @@ fn main() { | @@ -388,7 +357,7 @@ fn main() { | ||
388 | let f = (passed.as_nanos() / step.as_nanos()) as u32; | 357 | let f = (passed.as_nanos() / step.as_nanos()) as u32; |
389 | 358 | ||
390 | if f > 1 { | 359 | if f > 1 { |
391 | - println!("!!! Detected frame drop"); | 360 | + println!("{} !!! Detected frame drop", title); |
392 | } | 361 | } |
393 | 362 | ||
394 | last = last + step*(f + 1); | 363 | last = last + step*(f + 1); |
@@ -399,6 +368,42 @@ fn main() { | @@ -399,6 +368,42 @@ fn main() { | ||
399 | thread::sleep(last - Instant::now()); | 368 | thread::sleep(last - Instant::now()); |
400 | } | 369 | } |
401 | }); | 370 | }); |
371 | +} | ||
372 | + | ||
373 | +fn main() { | ||
374 | + common_fractional(); | ||
375 | + println!(); | ||
376 | + continuous(); | ||
377 | + println!(); | ||
378 | + sqrt(); | ||
379 | + println!(); | ||
380 | + pi(); | ||
381 | + println!(); | ||
382 | + _sin(); | ||
383 | + println!(); | ||
384 | + _cos(); | ||
385 | + println!(); | ||
386 | + _tan(); | ||
387 | + println!(); | ||
388 | + _vector1(); | ||
389 | + println!(); | ||
390 | + _vector2(); | ||
391 | + println!(); | ||
392 | + _transform1(); | ||
393 | + println!(); | ||
394 | + _transform2(); | ||
395 | + println!(); | ||
396 | + _line(); | ||
397 | + | ||
398 | + let xcb = XcbEasel::new().unwrap(); | ||
399 | + let (tx, rx) = mpsc::channel(); | ||
400 | + | ||
401 | + _democanvas( &xcb, "Something...(f64)", tx.clone() | ||
402 | + , Polyeder::tetrahedron(60.0) | ||
403 | + , Polyeder::cube(60.0) ); | ||
404 | + _democanvas( &xcb, "Something...(Fractional)", tx.clone() | ||
405 | + , Polyeder::tetrahedron(Fractional(60,1)) | ||
406 | + , Polyeder::cube(Fractional(60,1)) ); | ||
402 | 407 | ||
403 | for x in rx { | 408 | for x in rx { |
404 | match x { | 409 | match x { |
Please
register
or
login
to post a comment