Commit 561f75cd4a080608a94c26319ffaf2eee9cac095
1 parent
3e231c24
Vector code now works with Fractions .. but slower
Showing
1 changed file
with
24 additions
and
12 deletions
@@ -344,8 +344,13 @@ fn main() { | @@ -344,8 +344,13 @@ fn main() { | ||
344 | 344 | ||
345 | let tetrahedron = Polyeder::tetrahedron(60.0); | 345 | let tetrahedron = Polyeder::tetrahedron(60.0); |
346 | let cube = Polyeder::cube(60.0); | 346 | let cube = Polyeder::cube(60.0); |
347 | - let camera = Camera::<f64>::new(&canvas, 40); // the orig. view angle | 347 | + let camera = Camera::<f64>::new(&canvas, 45); // the orig. view angle |
348 | // was 50. | 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 | + */ | ||
349 | 354 | ||
350 | canvas.start_events(tx); | 355 | canvas.start_events(tx); |
351 | 356 | ||
@@ -355,21 +360,28 @@ fn main() { | @@ -355,21 +360,28 @@ fn main() { | ||
355 | thread::spawn(move || { | 360 | thread::spawn(move || { |
356 | loop { | 361 | loop { |
357 | let deg = ((start.elapsed() / 25).as_millis() % 360) as i32; | 362 | let deg = ((start.elapsed() / 25).as_millis() % 360) as i32; |
358 | - let rot1 :TMatrix<f64> = rotate_z(deg) | ||
359 | - * rotate_x(-deg*2) | ||
360 | - * translate(Vector(0.0, 0.0, 150.0)); | ||
361 | 363 | ||
362 | - let rot2 :TMatrix<f64> = rotate_z(-deg*2) | ||
363 | - * rotate_y(deg) | ||
364 | - * translate(Vector(0.0, 0.0, 150.0)); | 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 | + */ | ||
372 | + | ||
373 | + let rot1 = TMatrix::combine(vec!(rz, rotate_x(-deg*2), t)); | ||
374 | + let rot2 = TMatrix::combine(vec!(rz, rotate_y(-deg*2), t)); | ||
375 | + | ||
376 | + let objects = vec!( (tetrahedron.transform(&rot1), 0xFFFF00) | ||
377 | + , ( cube.transform(&rot2), 0x0000FF) ); | ||
365 | 378 | ||
366 | canvas.clear(); | 379 | canvas.clear(); |
367 | 380 | ||
368 | - for pg in tetrahedron.transform(&rot1).project(&camera) { | ||
369 | - canvas.draw(&pg, Coordinate(0,0), 0xFFFF00); | ||
370 | - } | ||
371 | - for pg in cube.transform(&rot2).project(&camera) { | ||
372 | - canvas.draw(&pg, Coordinate(0,0), 0x0000FF); | 381 | + for (o, color) in objects { |
382 | + for pg in o.project(&camera) { | ||
383 | + canvas.draw(&pg, Coordinate(0,0), color); | ||
384 | + } | ||
373 | } | 385 | } |
374 | 386 | ||
375 | let passed = Instant::now() - last; | 387 | let passed = Instant::now() - last; |
Please
register
or
login
to post a comment