-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
36 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,44 @@ | ||
extern crate nalgebra as na; | ||
mod common_macroquad2d; | ||
|
||
use na::Point2; | ||
use std::f32::consts::{FRAC_PI_2, FRAC_PI_4}; | ||
|
||
use common_macroquad2d::{draw_point, draw_polygon, lissajous_2d_with_params, na_from_mquad}; | ||
use macroquad::prelude::*; | ||
use nalgebra::Point2; | ||
use parry2d::transformation; | ||
|
||
fn main() { | ||
let points = vec![ | ||
Point2::new(0.77705324, 0.05374551), | ||
Point2::new(0.35096353, 0.9873069), | ||
Point2::new(0.09537989, 0.44411153), | ||
Point2::new(0.108208835, 0.72445065), | ||
Point2::new(0.7661844, 0.86163324), | ||
Point2::new(0.5185994, 0.66594696), | ||
Point2::new(0.768981, 0.23657233), | ||
Point2::new(0.058607936, 0.09037298), | ||
Point2::new(0.8818559, 0.3804205), | ||
Point2::new(0.9571466, 0.17664945), | ||
]; | ||
|
||
let _ = transformation::convex_hull(&points[..]); | ||
const RENDER_SCALE: f32 = 30.0; | ||
|
||
#[macroquad::main("parry2d::utils::point_in_poly2d")] | ||
async fn main() { | ||
let count = 9; | ||
let mut pts = vec![Point2::default(); count]; | ||
|
||
let render_pos = Point2::new(300.0, 300.0); | ||
|
||
loop { | ||
let elapsed_time = get_time() as f32; | ||
let elapsed_time_slow = elapsed_time * 0.2; | ||
clear_background(BLACK); | ||
|
||
for (i, pt) in pts.iter_mut().enumerate() { | ||
*pt = na_from_mquad(lissajous_2d_with_params( | ||
(i * i) as f32 + elapsed_time_slow, | ||
2.0 + i as f32 / 3.0, | ||
(i as f32 / count as f32) + elapsed_time_slow.cos() * 0.1, | ||
(elapsed_time_slow as f32 + i as f32).cos() * 0.1 + FRAC_PI_2, | ||
FRAC_PI_4, | ||
)) * 5f32; | ||
draw_point(*pt, RENDER_SCALE, render_pos, RED); | ||
} | ||
|
||
/* | ||
* | ||
* Compute the convex hull. | ||
* | ||
*/ | ||
let convex_hull = transformation::convex_hull(&pts); | ||
draw_polygon(&convex_hull, RENDER_SCALE, render_pos, WHITE); | ||
next_frame().await | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,52 @@ | ||
extern crate nalgebra as na; | ||
mod common_macroquad3d; | ||
|
||
use na::Point3; | ||
use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; | ||
|
||
use common_macroquad3d::{ | ||
lissajous_3d_with_params, mquad_from_na, mquad_mesh_from_points, na_from_mquad, | ||
}; | ||
use macroquad::prelude::*; | ||
use nalgebra::Point3; | ||
use parry3d::transformation; | ||
|
||
fn main() { | ||
let points = vec![ | ||
Point3::new(0.77705324, 0.05374551, 0.9822232), | ||
Point3::new(0.35096353, 0.9873069, 0.28922123), | ||
Point3::new(0.09537989, 0.44411153, 0.05486667), | ||
Point3::new(0.108208835, 0.72445065, 0.6669141), | ||
Point3::new(0.7661844, 0.86163324, 0.80507314), | ||
Point3::new(0.5185994, 0.66594696, 0.072779536), | ||
Point3::new(0.768981, 0.23657233, 0.44346774), | ||
Point3::new(0.058607936, 0.09037298, 0.017009139), | ||
Point3::new(0.8818559, 0.3804205, 0.25173646), | ||
Point3::new(0.9571466, 0.17664945, 0.6029223), | ||
]; | ||
#[macroquad::main("parry2d::utils::point_in_poly2d")] | ||
async fn main() { | ||
let count = 9; | ||
let mut pts = vec![Point3::default(); count]; | ||
|
||
let camera_pos = Vec3::new(8.0, 8.0, 8.0); | ||
loop { | ||
let elapsed_time = get_time() as f32; | ||
let elapsed_time_slow = elapsed_time * 0.2; | ||
clear_background(BLACK); | ||
|
||
let _ = transformation::convex_hull(&points[..]); | ||
for (i, pt) in pts.iter_mut().enumerate() { | ||
*pt = na_from_mquad(lissajous_3d_with_params( | ||
(i * i) as f32 + elapsed_time_slow, | ||
2.0 + i as f32 / 3.0, | ||
1f32 + (i as f32).sin() * 0.2, | ||
(i as f32 / count as f32) + elapsed_time_slow.cos() * 0.1, | ||
(elapsed_time_slow as f32 + i as f32).cos() * 0.1 + FRAC_PI_2, | ||
FRAC_PI_4, | ||
FRAC_PI_6, | ||
)) * 5f32; | ||
draw_sphere(mquad_from_na(*pt), 0.1f32, None, RED); | ||
} | ||
// Initialize 3D camera. | ||
set_camera(&Camera3D { | ||
position: camera_pos, | ||
up: Vec3::new(0f32, 1f32, 0f32), | ||
target: Vec3::new(0.5f32, 0f32, 0.5f32), | ||
..Default::default() | ||
}); | ||
/* | ||
* | ||
* Compute the convex hull. | ||
* | ||
*/ | ||
let convex_hull = transformation::convex_hull(&pts); | ||
let mesh = mquad_mesh_from_points(&convex_hull, Vec3::new(5.0, 10.0, 3.0), DARKGRAY); | ||
draw_mesh(&mesh); | ||
next_frame().await | ||
} | ||
} |