From 44c81cc34f6fe8b09cb67b0ec2e8e661d6cd3c89 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 31 Jul 2024 12:14:04 +0200 Subject: [PATCH 01/24] example for projection (+ bug detected) --- crates/parry3d/Cargo.toml | 17 +- crates/parry3d/examples/project3d_animated.rs | 157 ++++++++++++++++++ 2 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 crates/parry3d/examples/project3d_animated.rs diff --git a/crates/parry3d/Cargo.toml b/crates/parry3d/Cargo.toml index 62545af3..99c037f1 100644 --- a/crates/parry3d/Cargo.toml +++ b/crates/parry3d/Cargo.toml @@ -22,11 +22,23 @@ workspace = true [features] default = ["required-features", "std"] required-features = ["dim3", "f32"] -std = ["nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "spade", "thiserror"] +std = [ + "nalgebra/std", + "slab", + "rustc-hash", + "simba/std", + "arrayvec/std", + "spade", + "thiserror", +] dim3 = [] f32 = [] serde-serialize = ["serde", "nalgebra/serde-serialize", "bitflags/serde"] -rkyv-serialize = ["rkyv/validation", "nalgebra/rkyv-serialize", "simba/rkyv-serialize"] +rkyv-serialize = [ + "rkyv/validation", + "nalgebra/rkyv-serialize", + "simba/rkyv-serialize", +] bytemuck-serialize = ["bytemuck", "nalgebra/convert-bytemuck"] simd-stable = ["simba/wide", "simd-is-enabled"] @@ -76,3 +88,4 @@ obj = { version = "0.10.2", optional = true } oorandom = "11" ptree = "0.4.0" rand = { version = "0.8" } +macroquad = "*" diff --git a/crates/parry3d/examples/project3d_animated.rs b/crates/parry3d/examples/project3d_animated.rs new file mode 100644 index 00000000..6c64486c --- /dev/null +++ b/crates/parry3d/examples/project3d_animated.rs @@ -0,0 +1,157 @@ +use macroquad::models::Vertex; +use macroquad::prelude::*; +use nalgebra::{Point3, UnitVector3, Vector3}; +use parry3d::math::{Isometry, Real}; +use parry3d::query::{IntersectResult, PointQuery}; +use parry3d::shape::TriMesh; + +fn build_diamond(position: &Isometry) -> (Vec>, Vec<[u32; 3]>) { + // Two tetrahedrons sharing a face + let points = vec![ + position * Point3::new(0.0, 2.0, 0.0), + position * Point3::new(-2.0, -1.0, 0.0), + position * Point3::new(0.0, 0.0, 2.0), + position * Point3::new(2.0, -1.0, 0.0), + position * Point3::new(0.0, 0.0, -2.0), + ]; + + let indices = vec![ + [0u32, 1, 2], + [0, 2, 3], + [1, 2, 3], + [0, 1, 4], + [0, 4, 3], + [1, 4, 3], + ]; + + (points, indices) +} + +#[macroquad::main("parry3d::query::PlaneIntersection")] +async fn main() { + // + // This is useful to test for https://github.com/dimforge/parry/pull/248 + let _points = vec![ + Point3::from([0.0, 0.0, 0.0]), + Point3::from([0.0, 0.0, 1.0]), + Point3::from([1.0, 0.0, 0.0]), + Point3::from([1.0, 0.0, 1.0]), + ]; + let _indices: Vec<[u32; 3]> = vec![[0, 1, 2], [1, 3, 2]]; + // + // + + let (points, indices) = build_diamond(&Isometry::identity()); + + let mesh = Mesh { + vertices: points + .iter() + .map(|p| Vertex { + position: mquad_from_na(*p), + uv: Vec2::new(p.x, p.y), + color: Color::new(0.9, 0.9, 0.9, 0.7), + }) + .collect(), + indices: indices.iter().flatten().map(|v| *v as u16).collect(), + texture: None, + }; + let trimesh = TriMesh::new(points, indices); + + for _i in 1.. { + clear_background(BLACK); + + let elapsed_time = get_time() as f32; + let slow_elapsed_time = elapsed_time / 3.0; + + let sin = (elapsed_time / 3f32).sin(); + let bias = 1.5 * sin.abs(); + let rotation = Quat::from_axis_angle( + Vec3::new(slow_elapsed_time.sin(), slow_elapsed_time.cos(), 1f32), + (elapsed_time * 50f32).to_radians(), + ); + let up_plane_vector = rotation * Vec3::Y; + let point_to_project = up_plane_vector * bias; + let projected_point = trimesh.project_point( + &Isometry::identity(), + &na_from_mquad(point_to_project), + true, + ); + + let slow_elapsed_time = slow_elapsed_time / 2.0; + // Going 3d! + set_camera(&Camera3D { + position: Vec3::new( + slow_elapsed_time.sin() * 5.0, + slow_elapsed_time.sin(), + slow_elapsed_time.cos() * 5.0, + ), + up: Vec3::new(0f32, 1f32, 0f32), + target: Vec3::new(0.5f32, 0f32, 0.5f32), + ..Default::default() + }); + + /* + * + * Render the projection + * + */ + let color = if projected_point.is_inside { + RED + } else { + YELLOW + }; + + draw_line_3d( + point_to_project, + mquad_from_na(projected_point.point), + color, + ); + draw_sphere(point_to_project, 0.1, None, color); + + draw_line_3d( + point_to_project, + mquad_from_na(projected_point.point), + color, + ); + + // fixed point inside + let point_to_project = Vec3::ZERO; + let projected_point = trimesh.project_point( + &Isometry::identity(), + &na_from_mquad(point_to_project), + true, + ); + let color = if projected_point.is_inside { + RED + } else { + YELLOW + }; + draw_line_3d( + point_to_project, + mquad_from_na(projected_point.point), + color, + ); + draw_sphere(point_to_project, 0.1, None, color); + + // Mesh is rendered in the back. + draw_mesh(&mesh); + + next_frame().await + } +} + +fn draw_polyline(polygon: Vec<(Vec3, Vec3)>, color: Color) { + for i in 0..polygon.len() { + let a = polygon[i].0; + let b = polygon[i].1; + draw_line_3d(a, b, color); + } +} + +fn mquad_from_na(a: Point3) -> Vec3 { + Vec3::new(a.x, a.y, a.z) +} + +fn na_from_mquad(a: Vec3) -> Point3 { + Point3::new(a.x, a.y, a.z) +} From 9526e753eac701448961756acc152cb14523d6ef Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 31 Jul 2024 20:47:24 +0200 Subject: [PATCH 02/24] simpler project example --- crates/parry3d/examples/project3d_animated.rs | 66 +++++-------------- 1 file changed, 18 insertions(+), 48 deletions(-) diff --git a/crates/parry3d/examples/project3d_animated.rs b/crates/parry3d/examples/project3d_animated.rs index 6c64486c..f3e9e27b 100644 --- a/crates/parry3d/examples/project3d_animated.rs +++ b/crates/parry3d/examples/project3d_animated.rs @@ -1,31 +1,9 @@ use macroquad::models::Vertex; use macroquad::prelude::*; -use nalgebra::{Point3, UnitVector3, Vector3}; +use nalgebra::{Point3, Vector3}; use parry3d::math::{Isometry, Real}; -use parry3d::query::{IntersectResult, PointQuery}; -use parry3d::shape::TriMesh; - -fn build_diamond(position: &Isometry) -> (Vec>, Vec<[u32; 3]>) { - // Two tetrahedrons sharing a face - let points = vec![ - position * Point3::new(0.0, 2.0, 0.0), - position * Point3::new(-2.0, -1.0, 0.0), - position * Point3::new(0.0, 0.0, 2.0), - position * Point3::new(2.0, -1.0, 0.0), - position * Point3::new(0.0, 0.0, -2.0), - ]; - - let indices = vec![ - [0u32, 1, 2], - [0, 2, 3], - [1, 2, 3], - [0, 1, 4], - [0, 4, 3], - [1, 4, 3], - ]; - - (points, indices) -} +use parry3d::query::PointQuery; +use parry3d::shape::{Cuboid, TriMesh, TriMeshFlags}; #[macroquad::main("parry3d::query::PlaneIntersection")] async fn main() { @@ -38,10 +16,8 @@ async fn main() { Point3::from([1.0, 0.0, 1.0]), ]; let _indices: Vec<[u32; 3]> = vec![[0, 1, 2], [1, 3, 2]]; - // - // - let (points, indices) = build_diamond(&Isometry::identity()); + let (points, indices) = Cuboid::new(Vector3::new(0.2, 0.5, 1.0)).to_trimesh(); let mesh = Mesh { vertices: points @@ -55,22 +31,24 @@ async fn main() { indices: indices.iter().flatten().map(|v| *v as u16).collect(), texture: None, }; - let trimesh = TriMesh::new(points, indices); - + let trimesh = TriMesh::with_flags( + points.clone(), + indices.clone(), + TriMeshFlags::ORIENTED + | TriMeshFlags::DELETE_BAD_TOPOLOGY_TRIANGLES + | TriMeshFlags::FIX_INTERNAL_EDGES, + ); for _i in 1.. { clear_background(BLACK); let elapsed_time = get_time() as f32; let slow_elapsed_time = elapsed_time / 3.0; - let sin = (elapsed_time / 3f32).sin(); - let bias = 1.5 * sin.abs(); - let rotation = Quat::from_axis_angle( - Vec3::new(slow_elapsed_time.sin(), slow_elapsed_time.cos(), 1f32), - (elapsed_time * 50f32).to_radians(), - ); - let up_plane_vector = rotation * Vec3::Y; - let point_to_project = up_plane_vector * bias; + let point_to_project = Vec3::new( + slow_elapsed_time.sin(), + slow_elapsed_time.cos() * 1.5, + (elapsed_time - slow_elapsed_time).cos(), + ) * slow_elapsed_time.sin().abs(); let projected_point = trimesh.project_point( &Isometry::identity(), &na_from_mquad(point_to_project), @@ -126,13 +104,13 @@ async fn main() { } else { YELLOW }; + draw_sphere(point_to_project, 0.1, None, color); + draw_line_3d( point_to_project, mquad_from_na(projected_point.point), color, ); - draw_sphere(point_to_project, 0.1, None, color); - // Mesh is rendered in the back. draw_mesh(&mesh); @@ -140,14 +118,6 @@ async fn main() { } } -fn draw_polyline(polygon: Vec<(Vec3, Vec3)>, color: Color) { - for i in 0..polygon.len() { - let a = polygon[i].0; - let b = polygon[i].1; - draw_line_3d(a, b, color); - } -} - fn mquad_from_na(a: Point3) -> Vec3 { Vec3::new(a.x, a.y, a.z) } From 113046d3637974b2419e8e75abb69a5d40be8acb Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 31 Jul 2024 21:08:45 +0200 Subject: [PATCH 03/24] use lissajous trajectory + small polish pass --- crates/parry3d/examples/project3d_animated.rs | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/crates/parry3d/examples/project3d_animated.rs b/crates/parry3d/examples/project3d_animated.rs index f3e9e27b..be8260fd 100644 --- a/crates/parry3d/examples/project3d_animated.rs +++ b/crates/parry3d/examples/project3d_animated.rs @@ -1,3 +1,5 @@ +use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; + use macroquad::models::Vertex; use macroquad::prelude::*; use nalgebra::{Point3, Vector3}; @@ -5,6 +7,16 @@ use parry3d::math::{Isometry, Real}; use parry3d::query::PointQuery; use parry3d::shape::{Cuboid, TriMesh, TriMeshFlags}; +fn lissajous_3d(t: f32) -> Vec3 { + // Some hardcoded parameters to have a pleasing lissajous trajectory. + let (a, b, c, delta_x, delta_y, delta_z) = (3.0, 2.0, 1.0, FRAC_PI_2, FRAC_PI_4, FRAC_PI_6); + + let x = (a * t + delta_x).sin(); + let y = (b * t + delta_y).sin(); + let z = (c * t + delta_z).sin(); + Vec3::new(x, y, z) * 0.75f32 +} + #[macroquad::main("parry3d::query::PlaneIntersection")] async fn main() { // @@ -31,31 +43,20 @@ async fn main() { indices: indices.iter().flatten().map(|v| *v as u16).collect(), texture: None, }; - let trimesh = TriMesh::with_flags( - points.clone(), - indices.clone(), - TriMeshFlags::ORIENTED - | TriMeshFlags::DELETE_BAD_TOPOLOGY_TRIANGLES - | TriMeshFlags::FIX_INTERNAL_EDGES, - ); + let trimesh = TriMesh::with_flags(points, indices, TriMeshFlags::ORIENTED); for _i in 1.. { clear_background(BLACK); let elapsed_time = get_time() as f32; let slow_elapsed_time = elapsed_time / 3.0; - let point_to_project = Vec3::new( - slow_elapsed_time.sin(), - slow_elapsed_time.cos() * 1.5, - (elapsed_time - slow_elapsed_time).cos(), - ) * slow_elapsed_time.sin().abs(); + let point_to_project = lissajous_3d(slow_elapsed_time); let projected_point = trimesh.project_point( &Isometry::identity(), &na_from_mquad(point_to_project), true, ); - let slow_elapsed_time = slow_elapsed_time / 2.0; // Going 3d! set_camera(&Camera3D { position: Vec3::new( @@ -63,8 +64,8 @@ async fn main() { slow_elapsed_time.sin(), slow_elapsed_time.cos() * 5.0, ), - up: Vec3::new(0f32, 1f32, 0f32), - target: Vec3::new(0.5f32, 0f32, 0.5f32), + up: Vec3::Y, + target: Vec3::ZERO, ..Default::default() }); @@ -111,7 +112,7 @@ async fn main() { mquad_from_na(projected_point.point), color, ); - // Mesh is rendered in the back. + // Mesh is rendered in the back, so we can see the other graphics elements draw_mesh(&mesh); next_frame().await From ed6a11299769ad4224ed52e769e9bd79ee87fcfd Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 14 Aug 2024 09:47:07 +0200 Subject: [PATCH 04/24] zoom in --- crates/parry3d/examples/project3d_animated.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/parry3d/examples/project3d_animated.rs b/crates/parry3d/examples/project3d_animated.rs index be8260fd..4c967596 100644 --- a/crates/parry3d/examples/project3d_animated.rs +++ b/crates/parry3d/examples/project3d_animated.rs @@ -37,7 +37,8 @@ async fn main() { .map(|p| Vertex { position: mquad_from_na(*p), uv: Vec2::new(p.x, p.y), - color: Color::new(0.9, 0.9, 0.9, 0.7), + color: [210, 210, 210, 150], + normal: vec4(0.0, 0.0, 0.0, 0.0), }) .collect(), indices: indices.iter().flatten().map(|v| *v as u16).collect(), @@ -57,12 +58,13 @@ async fn main() { true, ); + let slow_elapsed_time = slow_elapsed_time * 0.7; // Going 3d! set_camera(&Camera3D { position: Vec3::new( - slow_elapsed_time.sin() * 5.0, + slow_elapsed_time.sin() * 3.0, slow_elapsed_time.sin(), - slow_elapsed_time.cos() * 5.0, + slow_elapsed_time.cos() * 3.0, ), up: Vec3::Y, target: Vec3::ZERO, From b181c652df157b2713e32b112991a3086423332a Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 14 Aug 2024 09:49:08 +0200 Subject: [PATCH 05/24] scrape plane intersection --- crates/parry3d/Cargo.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/parry3d/Cargo.toml b/crates/parry3d/Cargo.toml index c4afd5c0..9685da66 100644 --- a/crates/parry3d/Cargo.toml +++ b/crates/parry3d/Cargo.toml @@ -173,6 +173,11 @@ name = "plane3d" path = "examples/plane3d.rs" doc-scrape-examples = true +[[example]] +name = "plane_intersection" +path = "examples/plane_intersection.rs" +doc-scrape-examples = true + [[example]] name = "polyline3d" path = "examples/polyline3d.rs" From 2a685142803212d17607d57e26aae491f5797fd5 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 14 Aug 2024 10:44:49 +0200 Subject: [PATCH 06/24] expose cuboid::to_trimesh for parry2d + add 2d example for projectpoint --- crates/parry2d/examples/project_point2d.rs | 126 ++++++++++++++++++ ...oject3d_animated.rs => project_point3d.rs} | 8 +- src/transformation/mod.rs | 1 - .../to_trimesh/cuboid_to_trimesh.rs | 79 +++++++---- src/transformation/to_trimesh/mod.rs | 6 + 5 files changed, 187 insertions(+), 33 deletions(-) create mode 100644 crates/parry2d/examples/project_point2d.rs rename crates/parry3d/examples/{project3d_animated.rs => project_point3d.rs} (94%) diff --git a/crates/parry2d/examples/project_point2d.rs b/crates/parry2d/examples/project_point2d.rs new file mode 100644 index 00000000..06db2c4c --- /dev/null +++ b/crates/parry2d/examples/project_point2d.rs @@ -0,0 +1,126 @@ +use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; + +use macroquad::models::Vertex; +use macroquad::prelude::*; +use nalgebra::{Point2, Point3, UnitComplex, UnitQuaternion, Vector2}; +use parry2d::math::{Isometry, Real, Translation}; +use parry2d::query::PointQuery; +use parry2d::shape::{Cuboid, TriMesh, TriMeshFlags}; + +fn lissajous_2d(t: f32) -> Vec2 { + // Some hardcoded parameters to have a pleasing lissajous trajectory. + let (a, b, delta_x, delta_y) = (3.0, 2.0, FRAC_PI_2, FRAC_PI_4); + + let x = (a * t + delta_x).sin(); + let y = (b * t + delta_y).sin(); + Vec2::new(x, y) * 0.75f32 +} + +const VIRTUAL_WIDTH: f32 = 1280.0; +const VIRTUAL_HEIGHT: f32 = 720.0; + +#[macroquad::main("parry3d::query::PlaneIntersection")] +async fn main() { + // + // This is useful to test for https://github.com/dimforge/parry/pull/248 + let _points = vec![ + Point3::from([0.0, 0.0, 0.0]), + Point3::from([0.0, 0.0, 1.0]), + Point3::from([1.0, 0.0, 0.0]), + Point3::from([1.0, 0.0, 1.0]), + ]; + let _indices: Vec<[u32; 3]> = vec![[0, 1, 2], [1, 3, 2]]; + + let scale = 200f32; + let (points, indices) = Cuboid::new(Vector2::new(0.2 * scale, 0.5 * scale)).to_trimesh(); + + let trimesh = TriMesh::with_flags(points, indices, TriMeshFlags::ORIENTED); + for _i in 1.. { + clear_background(BLACK); + + let elapsed_time = get_time() as f32; + let slow_elapsed_time = elapsed_time / 3.0; + + let offset = Vec2::new(screen_width() / 2f32, screen_height() / 2f32); + + let point_to_project = lissajous_2d(slow_elapsed_time) * scale + offset; + let translation = Translation::new(offset.x, offset.y); + let rot = UnitComplex::identity(); + let projected_point = trimesh.project_point( + &Isometry::from_parts(translation, rot), + &na_from_mquad(point_to_project), + true, + ); + + let slow_elapsed_time = slow_elapsed_time * 0.7; + + /* + * + * Render the projection + * + */ + let color = if projected_point.is_inside { + RED + } else { + YELLOW + }; + + draw_line_2d( + point_to_project, + mquad_from_na(projected_point.point), + color, + ); + draw_circle(point_to_project.x, point_to_project.y, 10f32, color); + + draw_line_2d( + point_to_project, + mquad_from_na(projected_point.point), + color, + ); + + // fixed point inside the shape + let point_to_project = Vec2::ZERO; + let projected_point = trimesh.project_local_point(&na_from_mquad(point_to_project), true); + let color = if projected_point.is_inside { + RED + } else { + YELLOW + }; + draw_circle(point_to_project.x, point_to_project.y, 2f32, color); + + draw_line_2d( + point_to_project, + mquad_from_na(projected_point.point), + color, + ); + // Mesh is rendered in the back, so we can see the other graphics elements + draw_trimesh2(&trimesh, offset); + + next_frame().await + } +} + +fn mquad_from_na(a: Point2) -> Vec2 { + Vec2::new(a.x, a.y) +} + +fn na_from_mquad(a: Vec2) -> Point2 { + Point2::new(a.x, a.y) +} + +fn draw_line_2d(a: Vec2, b: Vec2, color: Color) { + draw_line(a.x, a.y, b.x, b.y, 2f32, color); +} + +fn draw_trimesh2(trimesh: &TriMesh, offset: Vec2) { + let vertices = trimesh.vertices(); + for v in trimesh.indices() { + let v0 = mquad_from_na(vertices[v[0] as usize]) + offset; + let v1 = mquad_from_na(vertices[v[1] as usize]) + offset; + let v2 = mquad_from_na(vertices[v[2] as usize]) + offset; + + draw_line(v0.x, v0.y, v1.x, v1.y, 2f32, WHITE); + draw_line(v0.x, v0.y, v2.x, v2.y, 2f32, WHITE); + draw_line(v2.x, v2.y, v1.x, v1.y, 2f32, WHITE); + } +} diff --git a/crates/parry3d/examples/project3d_animated.rs b/crates/parry3d/examples/project_point3d.rs similarity index 94% rename from crates/parry3d/examples/project3d_animated.rs rename to crates/parry3d/examples/project_point3d.rs index 4c967596..efa849c9 100644 --- a/crates/parry3d/examples/project3d_animated.rs +++ b/crates/parry3d/examples/project_point3d.rs @@ -95,13 +95,9 @@ async fn main() { color, ); - // fixed point inside + // fixed point inside the shape let point_to_project = Vec3::ZERO; - let projected_point = trimesh.project_point( - &Isometry::identity(), - &na_from_mquad(point_to_project), - true, - ); + let projected_point = trimesh.project_local_point(&na_from_mquad(point_to_project), true); let color = if projected_point.is_inside { RED } else { diff --git a/src/transformation/mod.rs b/src/transformation/mod.rs index be7e8348..7b29e427 100644 --- a/src/transformation/mod.rs +++ b/src/transformation/mod.rs @@ -36,7 +36,6 @@ mod mesh_intersection; mod to_outline; #[cfg(feature = "dim2")] mod to_polyline; -#[cfg(feature = "dim3")] mod to_trimesh; pub mod utils; diff --git a/src/transformation/to_trimesh/cuboid_to_trimesh.rs b/src/transformation/to_trimesh/cuboid_to_trimesh.rs index 1c763a22..3e1dcd35 100644 --- a/src/transformation/to_trimesh/cuboid_to_trimesh.rs +++ b/src/transformation/to_trimesh/cuboid_to_trimesh.rs @@ -2,11 +2,20 @@ use crate::bounding_volume::Aabb; use crate::math::Real; use crate::shape::Cuboid; use crate::transformation::utils; + +#[cfg(feature = "dim3")] +use na::Point3 as PointDim; +#[cfg(feature = "dim3")] use na::{self, Point3}; +#[cfg(feature = "dim2")] +use na::Point2 as PointDim; +#[cfg(feature = "dim2")] +use na::{self, Point2}; + impl Aabb { /// Discretize the boundary of this Aabb as a triangle-mesh. - pub fn to_trimesh(&self) -> (Vec>, Vec<[u32; 3]>) { + pub fn to_trimesh(&self) -> (Vec>, Vec<[u32; 3]>) { let center = self.center(); let half_extents = self.half_extents(); let mut cube_mesh = Cuboid::new(half_extents).to_trimesh(); @@ -17,7 +26,7 @@ impl Aabb { impl Cuboid { /// Discretize the boundary of this cuboid as a triangle-mesh. - pub fn to_trimesh(&self) -> (Vec>, Vec<[u32; 3]>) { + pub fn to_trimesh(&self) -> (Vec>, Vec<[u32; 3]>) { let (vtx, idx) = unit_cuboid(); (utils::scaled(vtx, self.half_extents * 2.0), idx) } @@ -28,36 +37,54 @@ impl Cuboid { * * The cuboid is centered at the origin, and has its half extents set to 0.5. */ -fn unit_cuboid() -> (Vec>, Vec<[u32; 3]>) { - let mut coords = Vec::with_capacity(8); - let mut faces = Vec::with_capacity(12); +fn unit_cuboid() -> (Vec>, Vec<[u32; 3]>) { + #[cfg(feature = "dim3")] + return { + let mut coords = Vec::with_capacity(8); + let mut faces = Vec::with_capacity(12); + + coords.push(Point3::new(-0.5, -0.5, 0.5)); + coords.push(Point3::new(-0.5, -0.5, -0.5)); + coords.push(Point3::new(0.5, -0.5, -0.5)); + coords.push(Point3::new(0.5, -0.5, 0.5)); + coords.push(Point3::new(-0.5, 0.5, 0.5)); + coords.push(Point3::new(-0.5, 0.5, -0.5)); + coords.push(Point3::new(0.5, 0.5, -0.5)); + coords.push(Point3::new(0.5, 0.5, 0.5)); + + faces.push([4, 5, 0]); + faces.push([5, 1, 0]); + + faces.push([5, 6, 1]); + faces.push([6, 2, 1]); - coords.push(Point3::new(-0.5, -0.5, 0.5)); - coords.push(Point3::new(-0.5, -0.5, -0.5)); - coords.push(Point3::new(0.5, -0.5, -0.5)); - coords.push(Point3::new(0.5, -0.5, 0.5)); - coords.push(Point3::new(-0.5, 0.5, 0.5)); - coords.push(Point3::new(-0.5, 0.5, -0.5)); - coords.push(Point3::new(0.5, 0.5, -0.5)); - coords.push(Point3::new(0.5, 0.5, 0.5)); + faces.push([6, 7, 3]); + faces.push([2, 6, 3]); - faces.push([4, 5, 0]); - faces.push([5, 1, 0]); + faces.push([7, 4, 0]); + faces.push([3, 7, 0]); - faces.push([5, 6, 1]); - faces.push([6, 2, 1]); + faces.push([0, 1, 2]); + faces.push([3, 0, 2]); - faces.push([6, 7, 3]); - faces.push([2, 6, 3]); + faces.push([7, 6, 5]); + faces.push([4, 7, 5]); - faces.push([7, 4, 0]); - faces.push([3, 7, 0]); + (coords, faces) + }; + #[cfg(feature = "dim2")] + return { + let mut coords = Vec::with_capacity(8); + let mut faces = Vec::with_capacity(12); - faces.push([0, 1, 2]); - faces.push([3, 0, 2]); + coords.push(Point2::new(-0.5, -0.5)); + coords.push(Point2::new(0.5, -0.5)); + coords.push(Point2::new(-0.5, 0.5)); + coords.push(Point2::new(0.5, 0.5)); - faces.push([7, 6, 5]); - faces.push([4, 7, 5]); + faces.push([0, 1, 2]); + faces.push([2, 1, 3]); - (coords, faces) + (coords, faces) + }; } diff --git a/src/transformation/to_trimesh/mod.rs b/src/transformation/to_trimesh/mod.rs index 6c730f12..60dc33a7 100644 --- a/src/transformation/to_trimesh/mod.rs +++ b/src/transformation/to_trimesh/mod.rs @@ -1,7 +1,13 @@ +#[cfg(feature = "dim3")] mod ball_to_trimesh; +#[cfg(feature = "dim3")] mod capsule_to_trimesh; +#[cfg(feature = "dim3")] mod cone_to_trimesh; +#[cfg(feature = "dim3")] mod convex_polyhedron_to_trimesh; mod cuboid_to_trimesh; +#[cfg(feature = "dim3")] mod cylinder_to_trimesh; +#[cfg(feature = "dim3")] mod heightfield_to_trimesh; From 065f6b69c6e6567451eba5937ead3816c936aab3 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 14 Aug 2024 10:48:14 +0200 Subject: [PATCH 07/24] fix local point inside the shape --- crates/parry2d/examples/project_point2d.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/parry2d/examples/project_point2d.rs b/crates/parry2d/examples/project_point2d.rs index 06db2c4c..1e205aa1 100644 --- a/crates/parry2d/examples/project_point2d.rs +++ b/crates/parry2d/examples/project_point2d.rs @@ -78,7 +78,7 @@ async fn main() { color, ); - // fixed point inside the shape + // fixed local point inside the shape let point_to_project = Vec2::ZERO; let projected_point = trimesh.project_local_point(&na_from_mquad(point_to_project), true); let color = if projected_point.is_inside { @@ -86,11 +86,13 @@ async fn main() { } else { YELLOW }; - draw_circle(point_to_project.x, point_to_project.y, 2f32, color); + // convert to "world" space + let point_to_project = point_to_project * scale + offset; + draw_circle(point_to_project.x, point_to_project.y, 10f32, color); draw_line_2d( point_to_project, - mquad_from_na(projected_point.point), + mquad_from_na(projected_point.point) * scale + offset, color, ); // Mesh is rendered in the back, so we can see the other graphics elements From 174f0121f5a848e89df7c12e4b25ea86cf58a73e Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 14 Aug 2024 11:05:38 +0200 Subject: [PATCH 08/24] common macroquad code in their example --- crates/parry3d/examples/common_macroquad.rs | 46 +++++++++++++++++++ crates/parry3d/examples/plane_intersection.rs | 28 ++++------- crates/parry3d/examples/project_point3d.rs | 35 ++------------ 3 files changed, 58 insertions(+), 51 deletions(-) create mode 100644 crates/parry3d/examples/common_macroquad.rs diff --git a/crates/parry3d/examples/common_macroquad.rs b/crates/parry3d/examples/common_macroquad.rs new file mode 100644 index 00000000..1371127d --- /dev/null +++ b/crates/parry3d/examples/common_macroquad.rs @@ -0,0 +1,46 @@ +use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; + +use macroquad::{ + color::{Color, WHITE}, + math::Vec3, + models::draw_line_3d, +}; +use nalgebra::Point3; +use parry3d::math::Real; + +fn main() { + println!( + "This module contains helper fubnctions to use macroquad, + isolated from the rest of the examples for the sake of simplicity." + ); +} + +pub fn mquad_from_na(a: Point3) -> Vec3 { + Vec3::new(a.x, a.y, a.z) +} + +pub fn na_from_mquad(a: Vec3) -> Point3 { + Point3::new(a.x, a.y, a.z) +} + +pub fn lissajous_3d(t: f32) -> Vec3 { + // Some hardcoded parameters to have a pleasing lissajous trajectory. + let (a, b, c, delta_x, delta_y, delta_z) = (3.0, 2.0, 1.0, FRAC_PI_2, FRAC_PI_4, FRAC_PI_6); + + let x = (a * t + delta_x).sin(); + let y = (b * t + delta_y).sin(); + let z = (c * t + delta_z).sin(); + Vec3::new(x, y, z) * 0.75f32 +} + +pub fn draw_polyline(polygon: Vec<(Vec3, Vec3)>, color: Color) { + for i in 0..polygon.len() { + let a = polygon[i].0; + let b = polygon[i].1; + draw_line_3d(a, b, color); + } +} + +pub fn easy_draw_text(text: &str) { + macroquad::text::draw_text(text, 10.0, 48.0 + 18.0, 30.0, WHITE); +} diff --git a/crates/parry3d/examples/plane_intersection.rs b/crates/parry3d/examples/plane_intersection.rs index c80fc0e5..97d1d3b5 100644 --- a/crates/parry3d/examples/plane_intersection.rs +++ b/crates/parry3d/examples/plane_intersection.rs @@ -5,6 +5,9 @@ use parry3d::math::Real; use parry3d::query::IntersectResult; use parry3d::shape::{Cuboid, TriMesh}; +mod common_macroquad; +use common_macroquad::*; + #[macroquad::main("parry3d::query::PlaneIntersection")] async fn main() { let trimesh = Cuboid::new(Vector3::repeat(1.0)).to_trimesh(); @@ -64,15 +67,15 @@ async fn main() { Color::new(0f32, 1f32, 0f32, 1f32), ); set_default_camera(); - draw_text("Intersection found!"); + easy_draw_text("Intersection found!"); } IntersectResult::Negative => { set_default_camera(); - draw_text("No intersection found, the shape is below the plane."); + easy_draw_text("No intersection found, the shape is below the plane."); } IntersectResult::Positive => { set_default_camera(); - draw_text("No intersection found, the shape is above the plane."); + easy_draw_text("No intersection found, the shape is above the plane."); } } next_frame().await @@ -95,7 +98,8 @@ fn mquad_mesh_from_points(trimesh: &(Vec>, Vec<[u32; 3]>), camera_p indices.iter().flatten().map(|v| *v as u16).collect(), ); - // Macroquad doesn´t support adding normals to vertices, so we'll bake a color into these vertices. + // Macroquad does support adding normals to vertices, but we´d have to provide shaders for them. + // so we're baking a color into these vertices. // See https://github.com/not-fl3/macroquad/issues/321. // Compute the normal of each vertex, making them unique @@ -140,19 +144,3 @@ fn mquad_compute_normals(points: &Vec, indices: &Vec, cam_pos: Vec3 } vertices } - -fn draw_polyline(polygon: Vec<(Vec3, Vec3)>, color: Color) { - for i in 0..polygon.len() { - let a = polygon[i].0; - let b = polygon[i].1; - draw_line_3d(a, b, color); - } -} - -fn mquad_from_na(a: Point3) -> Vec3 { - Vec3::new(a.x, a.y, a.z) -} - -fn draw_text(text: &str) { - macroquad::text::draw_text(text, 10.0, 48.0 + 18.0, 30.0, WHITE); -} diff --git a/crates/parry3d/examples/project_point3d.rs b/crates/parry3d/examples/project_point3d.rs index efa849c9..f08b1eb5 100644 --- a/crates/parry3d/examples/project_point3d.rs +++ b/crates/parry3d/examples/project_point3d.rs @@ -1,34 +1,15 @@ -use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; - use macroquad::models::Vertex; use macroquad::prelude::*; -use nalgebra::{Point3, Vector3}; -use parry3d::math::{Isometry, Real}; +use nalgebra::Vector3; +use parry3d::math::Isometry; use parry3d::query::PointQuery; use parry3d::shape::{Cuboid, TriMesh, TriMeshFlags}; -fn lissajous_3d(t: f32) -> Vec3 { - // Some hardcoded parameters to have a pleasing lissajous trajectory. - let (a, b, c, delta_x, delta_y, delta_z) = (3.0, 2.0, 1.0, FRAC_PI_2, FRAC_PI_4, FRAC_PI_6); - - let x = (a * t + delta_x).sin(); - let y = (b * t + delta_y).sin(); - let z = (c * t + delta_z).sin(); - Vec3::new(x, y, z) * 0.75f32 -} +mod common_macroquad; +use common_macroquad::*; #[macroquad::main("parry3d::query::PlaneIntersection")] async fn main() { - // - // This is useful to test for https://github.com/dimforge/parry/pull/248 - let _points = vec![ - Point3::from([0.0, 0.0, 0.0]), - Point3::from([0.0, 0.0, 1.0]), - Point3::from([1.0, 0.0, 0.0]), - Point3::from([1.0, 0.0, 1.0]), - ]; - let _indices: Vec<[u32; 3]> = vec![[0, 1, 2], [1, 3, 2]]; - let (points, indices) = Cuboid::new(Vector3::new(0.2, 0.5, 1.0)).to_trimesh(); let mesh = Mesh { @@ -116,11 +97,3 @@ async fn main() { next_frame().await } } - -fn mquad_from_na(a: Point3) -> Vec3 { - Vec3::new(a.x, a.y, a.z) -} - -fn na_from_mquad(a: Vec3) -> Point3 { - Point3::new(a.x, a.y, a.z) -} From 3955d443f2b78626be4d480d65c7ec26285728bb Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 14 Aug 2024 11:13:14 +0200 Subject: [PATCH 09/24] use a shaded cube for project_point2d too. --- crates/parry3d/examples/common_macroquad.rs | 79 ++++++++++++++++++- crates/parry3d/examples/plane_intersection.rs | 67 +--------------- crates/parry3d/examples/project_point3d.rs | 21 ++--- 3 files changed, 84 insertions(+), 83 deletions(-) diff --git a/crates/parry3d/examples/common_macroquad.rs b/crates/parry3d/examples/common_macroquad.rs index 1371127d..a326e65c 100644 --- a/crates/parry3d/examples/common_macroquad.rs +++ b/crates/parry3d/examples/common_macroquad.rs @@ -1,9 +1,10 @@ use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; use macroquad::{ - color::{Color, WHITE}, - math::Vec3, - models::draw_line_3d, + color::{Color, DARKGRAY, WHITE}, + math::{Vec2, Vec3, Vec4}, + models::{draw_line_3d, Mesh}, + ui::Vertex, }; use nalgebra::Point3; use parry3d::math::Real; @@ -44,3 +45,75 @@ pub fn draw_polyline(polygon: Vec<(Vec3, Vec3)>, color: Color) { pub fn easy_draw_text(text: &str) { macroquad::text::draw_text(text, 10.0, 48.0 + 18.0, 30.0, WHITE); } + +pub fn mquad_mesh_from_points( + trimesh: &(Vec>, Vec<[u32; 3]>), + light_pos: Vec3, + color: Color, +) -> Mesh { + let (points, indices) = trimesh; + // Transform the parry mesh into a mquad Mesh + let (mquad_points, mquad_indices) = ( + points + .iter() + .map(|p| Vertex { + position: mquad_from_na(*p), + uv: Vec2::new(p.x, p.y), + color: color.into(), + normal: Vec4::ZERO, + }) + .collect(), + indices.iter().flatten().map(|v| *v as u16).collect(), + ); + + // Macroquad does support adding normals to vertices, but we´d have to provide shaders for them. + // so we're baking a color into these vertices. + // See https://github.com/not-fl3/macroquad/issues/321. + + // Compute the normal of each vertex, making them unique + let vertices: Vec = + mquad_compute_normals_and_bake_light(&mquad_points, &mquad_indices, light_pos); + // Regenerate the index for each vertex. + let indices: Vec = (0..vertices.len() * 3) + .into_iter() + .map(|i| i as u16) + .collect(); + let mesh = Mesh { + vertices, + indices, + texture: None, + }; + mesh +} + +pub fn mquad_compute_normals_and_bake_light( + points: &Vec, + indices: &Vec, + light_pos: Vec3, +) -> Vec { + let mut vertices: Vec = Vec::::new(); + for indices in indices.chunks(3) { + let v0 = &points[indices[0] as usize]; + let v1 = &points[indices[1] as usize]; + let v2 = &points[indices[2] as usize]; + let normal = (v0.position - v2.position) + .cross(v1.position - v2.position) + .normalize(); + let brightness_mod = 0.2 + (0.8 / 2.) * (normal.dot(light_pos) + 1.); + + for &i in indices.iter() { + let mut color = points[i as usize].color; + color[0] = (color[0] as f32 * brightness_mod) as u8; + color[1] = (color[1] as f32 * brightness_mod) as u8; + color[2] = (color[2] as f32 * brightness_mod) as u8; + + vertices.push(Vertex { + position: points[i as usize].position, + uv: Vec2::ZERO, + color: color, + normal: Vec4::ZERO, + }); + } + } + vertices +} diff --git a/crates/parry3d/examples/plane_intersection.rs b/crates/parry3d/examples/plane_intersection.rs index 97d1d3b5..05ef54ef 100644 --- a/crates/parry3d/examples/plane_intersection.rs +++ b/crates/parry3d/examples/plane_intersection.rs @@ -1,7 +1,5 @@ -use macroquad::models::Vertex; use macroquad::prelude::*; -use nalgebra::{Point3, UnitVector3, Vector3}; -use parry3d::math::Real; +use nalgebra::{UnitVector3, Vector3}; use parry3d::query::IntersectResult; use parry3d::shape::{Cuboid, TriMesh}; @@ -81,66 +79,3 @@ async fn main() { next_frame().await } } - -fn mquad_mesh_from_points(trimesh: &(Vec>, Vec<[u32; 3]>), camera_pos: Vec3) -> Mesh { - let (points, indices) = trimesh; - // Transform the parry mesh into a mquad Mesh - let (mquad_points, mquad_indices) = ( - points - .iter() - .map(|p| Vertex { - position: mquad_from_na(*p), - uv: Vec2::new(p.x, p.y), - color: DARKGRAY.into(), - normal: Vec4::ZERO, - }) - .collect(), - indices.iter().flatten().map(|v| *v as u16).collect(), - ); - - // Macroquad does support adding normals to vertices, but we´d have to provide shaders for them. - // so we're baking a color into these vertices. - // See https://github.com/not-fl3/macroquad/issues/321. - - // Compute the normal of each vertex, making them unique - let vertices: Vec = mquad_compute_normals(&mquad_points, &mquad_indices, camera_pos); - // Regenerate the index for each vertex. - let indices: Vec = (0..vertices.len() * 3) - .into_iter() - .map(|i| i as u16) - .collect(); - let mesh = Mesh { - vertices, - indices, - texture: None, - }; - mesh -} - -fn mquad_compute_normals(points: &Vec, indices: &Vec, cam_pos: Vec3) -> Vec { - let mut vertices: Vec = Vec::::new(); - for indices in indices.chunks(3) { - let v0 = &points[indices[0] as usize]; - let v1 = &points[indices[1] as usize]; - let v2 = &points[indices[2] as usize]; - let normal = (v0.position - v2.position) - .cross(v1.position - v2.position) - .normalize(); - let brightness_mod = 0.2 + (0.8 / 2.) * (normal.dot(cam_pos) + 1.); - - for &i in indices.iter() { - let mut color = points[i as usize].color; - color[0] = (color[0] as f32 * brightness_mod) as u8; - color[1] = (color[1] as f32 * brightness_mod) as u8; - color[2] = (color[2] as f32 * brightness_mod) as u8; - - vertices.push(Vertex { - position: points[i as usize].position, - uv: Vec2::ZERO, - color: color, - normal: Vec4::ZERO, - }); - } - } - vertices -} diff --git a/crates/parry3d/examples/project_point3d.rs b/crates/parry3d/examples/project_point3d.rs index f08b1eb5..b1b56e94 100644 --- a/crates/parry3d/examples/project_point3d.rs +++ b/crates/parry3d/examples/project_point3d.rs @@ -10,21 +10,14 @@ use common_macroquad::*; #[macroquad::main("parry3d::query::PlaneIntersection")] async fn main() { - let (points, indices) = Cuboid::new(Vector3::new(0.2, 0.5, 1.0)).to_trimesh(); + let trimesh = Cuboid::new(Vector3::new(0.2, 0.5, 1.0)).to_trimesh(); - let mesh = Mesh { - vertices: points - .iter() - .map(|p| Vertex { - position: mquad_from_na(*p), - uv: Vec2::new(p.x, p.y), - color: [210, 210, 210, 150], - normal: vec4(0.0, 0.0, 0.0, 0.0), - }) - .collect(), - indices: indices.iter().flatten().map(|v| *v as u16).collect(), - texture: None, - }; + let mesh = mquad_mesh_from_points( + &trimesh, + Vec3::new(1f32, 3f32, 3f32), + Color::from_rgba(200, 200, 200, 150), + ); + let (points, indices) = trimesh; let trimesh = TriMesh::with_flags(points, indices, TriMeshFlags::ORIENTED); for _i in 1.. { clear_background(BLACK); From 4bbe2984d2f59f591a727f75e75d98bc457840e3 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 3 Sep 2024 11:37:11 +0200 Subject: [PATCH 10/24] lighter cube --- crates/parry3d/examples/common_macroquad.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/parry3d/examples/common_macroquad.rs b/crates/parry3d/examples/common_macroquad.rs index a326e65c..0bd37202 100644 --- a/crates/parry3d/examples/common_macroquad.rs +++ b/crates/parry3d/examples/common_macroquad.rs @@ -1,7 +1,8 @@ +#[allow(unused, dead_code)] use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; use macroquad::{ - color::{Color, DARKGRAY, WHITE}, + color::{Color, WHITE}, math::{Vec2, Vec3, Vec4}, models::{draw_line_3d, Mesh}, ui::Vertex, @@ -99,7 +100,7 @@ pub fn mquad_compute_normals_and_bake_light( let normal = (v0.position - v2.position) .cross(v1.position - v2.position) .normalize(); - let brightness_mod = 0.2 + (0.8 / 2.) * (normal.dot(light_pos) + 1.); + let brightness_mod = 0.4 + (0.6 / 2.) * (normal.dot(light_pos) + 1.); for &i in indices.iter() { let mut color = points[i as usize].color; From 2dcadc92eca2bc328d779d9d830a0dd3120aec3f Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 3 Sep 2024 12:09:16 +0200 Subject: [PATCH 11/24] fix plane intersection code with common code --- crates/parry3d/examples/plane_intersection.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/parry3d/examples/plane_intersection.rs b/crates/parry3d/examples/plane_intersection.rs index 05ef54ef..567d4dfc 100644 --- a/crates/parry3d/examples/plane_intersection.rs +++ b/crates/parry3d/examples/plane_intersection.rs @@ -10,9 +10,10 @@ use common_macroquad::*; async fn main() { let trimesh = Cuboid::new(Vector3::repeat(1.0)).to_trimesh(); + let light_pos = Vec3::new(-1f32, 3.5f32, -3f32); let camera_pos = Vec3::new(-1.5f32, 2.5f32, -3f32); - let mesh = mquad_mesh_from_points(&trimesh, camera_pos); + let mesh = mquad_mesh_from_points(&trimesh, light_pos, DARKGRAY); let trimesh = TriMesh::new(trimesh.0, trimesh.1); for _ in 1.. { From d61b05b76c3e613fea36ef6d5e74bd8c213ae47f Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 3 Sep 2024 12:13:21 +0200 Subject: [PATCH 12/24] removed a few unused variables --- crates/parry2d/examples/project_point2d.rs | 10 ++-------- crates/parry3d/examples/project_point3d.rs | 1 - 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/parry2d/examples/project_point2d.rs b/crates/parry2d/examples/project_point2d.rs index 1e205aa1..d5cc8b90 100644 --- a/crates/parry2d/examples/project_point2d.rs +++ b/crates/parry2d/examples/project_point2d.rs @@ -1,8 +1,7 @@ -use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; +use std::f32::consts::{FRAC_PI_2, FRAC_PI_4}; -use macroquad::models::Vertex; use macroquad::prelude::*; -use nalgebra::{Point2, Point3, UnitComplex, UnitQuaternion, Vector2}; +use nalgebra::{Point2, Point3, UnitComplex, Vector2}; use parry2d::math::{Isometry, Real, Translation}; use parry2d::query::PointQuery; use parry2d::shape::{Cuboid, TriMesh, TriMeshFlags}; @@ -16,9 +15,6 @@ fn lissajous_2d(t: f32) -> Vec2 { Vec2::new(x, y) * 0.75f32 } -const VIRTUAL_WIDTH: f32 = 1280.0; -const VIRTUAL_HEIGHT: f32 = 720.0; - #[macroquad::main("parry3d::query::PlaneIntersection")] async fn main() { // @@ -52,8 +48,6 @@ async fn main() { true, ); - let slow_elapsed_time = slow_elapsed_time * 0.7; - /* * * Render the projection diff --git a/crates/parry3d/examples/project_point3d.rs b/crates/parry3d/examples/project_point3d.rs index b1b56e94..408ac3fb 100644 --- a/crates/parry3d/examples/project_point3d.rs +++ b/crates/parry3d/examples/project_point3d.rs @@ -1,4 +1,3 @@ -use macroquad::models::Vertex; use macroquad::prelude::*; use nalgebra::Vector3; use parry3d::math::Isometry; From 8ab7b5c995d6c4eb50db59391771f714c29a0d5c Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 3 Sep 2024 14:42:22 +0200 Subject: [PATCH 13/24] 2d examples use common macroquad code --- crates/parry2d/examples/common_macroquad.rs | 100 ++++++++++++++++++ crates/parry2d/examples/point_in_poly2d.rs | 44 ++------ .../examples/polygons_intersection2d.rs | 18 +--- crates/parry2d/examples/project_point2d.rs | 41 +------ crates/parry2d/examples/raycasts_animated.rs | 23 +--- crates/parry3d/examples/common_macroquad.rs | 2 +- 6 files changed, 117 insertions(+), 111 deletions(-) create mode 100644 crates/parry2d/examples/common_macroquad.rs diff --git a/crates/parry2d/examples/common_macroquad.rs b/crates/parry2d/examples/common_macroquad.rs new file mode 100644 index 00000000..6326afe2 --- /dev/null +++ b/crates/parry2d/examples/common_macroquad.rs @@ -0,0 +1,100 @@ +#[allow(unused, dead_code)] +use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; + +use macroquad::prelude::*; +use macroquad::{ + color::{Color, WHITE}, + math::Vec2, + shapes::draw_line, +}; +use nalgebra::Point2; +use parry2d::math::Real; +use parry2d::shape::TriMesh; + +fn main() { + println!( + "This module contains helper functions to use macroquad, + isolated from the rest of the examples for the sake of simplicity." + ); +} + +pub fn mquad_from_na(a: Point2) -> Vec2 { + Vec2::new(a.x, a.y) +} + +pub fn na_from_mquad(a: Vec2) -> Point2 { + Point2::new(a.x, a.y) +} + +pub fn draw_polyline(polygon: Vec<(Vec2, Vec2)>, color: Color) { + for i in 0..polygon.len() { + let a = polygon[i].0; + let b = polygon[i].1; + draw_line_2d(a, b, color); + } +} + +pub fn easy_draw_text(text: &str) { + macroquad::text::draw_text(text, 10.0, 48.0 + 18.0, 30.0, WHITE); +} + +pub fn lissajous_2d(t: f32) -> Vec2 { + // Some hardcoded parameters to have a pleasing lissajous trajectory. + let (a, b, delta_x, delta_y) = (3.0, 2.0, FRAC_PI_2, FRAC_PI_4); + + let x = (a * t + delta_x).sin(); + let y = (b * t + delta_y).sin(); + Vec2::new(x, y) * 0.75f32 +} + +pub fn draw_line_2d(a: Vec2, b: Vec2, color: Color) { + draw_line(a.x, a.y, b.x, b.y, 2f32, color); +} + +pub fn draw_trimesh2(trimesh: &TriMesh, offset: Vec2) { + let vertices = trimesh.vertices(); + for v in trimesh.indices() { + let v0 = mquad_from_na(vertices[v[0] as usize]) + offset; + let v1 = mquad_from_na(vertices[v[1] as usize]) + offset; + let v2 = mquad_from_na(vertices[v[2] as usize]) + offset; + + draw_line(v0.x, v0.y, v1.x, v1.y, 2f32, WHITE); + draw_line(v0.x, v0.y, v2.x, v2.y, 2f32, WHITE); + draw_line(v2.x, v2.y, v1.x, v1.y, 2f32, WHITE); + } +} + +pub fn draw_polygon(polygon: &[Point2], scale: f32, shift: Point2, color: Color) { + for i in 0..polygon.len() { + let a = polygon[i]; + let b = polygon[(i + 1) % polygon.len()]; + draw_line( + a.x * scale + shift.x, + a.y * scale + shift.y, + b.x * scale + shift.x, + b.y * scale + shift.y, + 2.0, + color, + ); + } +} + +pub fn draw_point(point: Point2, scale: f32, shift: Point2, color: Color) { + let edge_len = 0.15; + draw_line( + (point.x - edge_len) * scale + shift.x, + point.y * scale + shift.y, + (point.x + edge_len) * scale + shift.x, + point.y * scale + shift.y, + 2.0, + color, + ); + draw_line( + point.x * scale + shift.x, + (point.y - edge_len) * scale + shift.y, + point.x * scale + shift.x, + (point.y + edge_len) * scale + shift.y, + 2.0, + color, + ); +} diff --git a/crates/parry2d/examples/point_in_poly2d.rs b/crates/parry2d/examples/point_in_poly2d.rs index 6933c21e..fd85e046 100644 --- a/crates/parry2d/examples/point_in_poly2d.rs +++ b/crates/parry2d/examples/point_in_poly2d.rs @@ -1,3 +1,6 @@ +mod common_macroquad; + +use common_macroquad::{draw_point, draw_polygon}; use macroquad::prelude::*; use nalgebra::{Point2, UnitComplex, Vector2}; use parry2d::utils::point_in_poly2d; @@ -15,14 +18,14 @@ async fn main() { loop { clear_background(BLACK); - /* - * Compute polygon intersections. - */ spikes .iter_mut() .for_each(|pt| *pt = animation_rotation * *pt); draw_polygon(&spikes, RENDER_SCALE, spikes_render_pos, BLUE); + /* + * Compute polygon intersections. + */ for point in &test_points { if point_in_poly2d(point, &spikes) { draw_point(*point, RENDER_SCALE, spikes_render_pos, RED); @@ -71,38 +74,3 @@ fn grid_points() -> Vec> { } pts } - -fn draw_polygon(polygon: &[Point2], scale: f32, shift: Point2, color: Color) { - for i in 0..polygon.len() { - let a = polygon[i]; - let b = polygon[(i + 1) % polygon.len()]; - draw_line( - a.x * scale + shift.x, - a.y * scale + shift.y, - b.x * scale + shift.x, - b.y * scale + shift.y, - 2.0, - color, - ); - } -} - -fn draw_point(point: Point2, scale: f32, shift: Point2, color: Color) { - let edge_len = 0.15; - draw_line( - (point.x - edge_len) * scale + shift.x, - point.y * scale + shift.y, - (point.x + edge_len) * scale + shift.x, - point.y * scale + shift.y, - 2.0, - color, - ); - draw_line( - point.x * scale + shift.x, - (point.y - edge_len) * scale + shift.y, - point.x * scale + shift.x, - (point.y + edge_len) * scale + shift.y, - 2.0, - color, - ); -} diff --git a/crates/parry2d/examples/polygons_intersection2d.rs b/crates/parry2d/examples/polygons_intersection2d.rs index 51d03079..6c3164b3 100644 --- a/crates/parry2d/examples/polygons_intersection2d.rs +++ b/crates/parry2d/examples/polygons_intersection2d.rs @@ -1,3 +1,6 @@ +mod common_macroquad; + +use common_macroquad::draw_polygon; use macroquad::prelude::*; use nalgebra::{Point2, UnitComplex, Vector2}; use parry2d::shape::Ball; @@ -111,18 +114,3 @@ fn spikes_polygon() -> Vec> { polygon } - -fn draw_polygon(polygon: &[Point2], scale: f32, shift: Point2, color: Color) { - for i in 0..polygon.len() { - let a = polygon[i]; - let b = polygon[(i + 1) % polygon.len()]; - draw_line( - a.x * scale + shift.x, - a.y * scale + shift.y, - b.x * scale + shift.x, - b.y * scale + shift.y, - 2.0, - color, - ); - } -} diff --git a/crates/parry2d/examples/project_point2d.rs b/crates/parry2d/examples/project_point2d.rs index d5cc8b90..ca484eef 100644 --- a/crates/parry2d/examples/project_point2d.rs +++ b/crates/parry2d/examples/project_point2d.rs @@ -1,20 +1,12 @@ -use std::f32::consts::{FRAC_PI_2, FRAC_PI_4}; +mod common_macroquad; +use common_macroquad::{draw_line_2d, draw_trimesh2, lissajous_2d, mquad_from_na, na_from_mquad}; use macroquad::prelude::*; -use nalgebra::{Point2, Point3, UnitComplex, Vector2}; -use parry2d::math::{Isometry, Real, Translation}; +use nalgebra::{Point3, UnitComplex, Vector2}; +use parry2d::math::{Isometry, Translation}; use parry2d::query::PointQuery; use parry2d::shape::{Cuboid, TriMesh, TriMeshFlags}; -fn lissajous_2d(t: f32) -> Vec2 { - // Some hardcoded parameters to have a pleasing lissajous trajectory. - let (a, b, delta_x, delta_y) = (3.0, 2.0, FRAC_PI_2, FRAC_PI_4); - - let x = (a * t + delta_x).sin(); - let y = (b * t + delta_y).sin(); - Vec2::new(x, y) * 0.75f32 -} - #[macroquad::main("parry3d::query::PlaneIntersection")] async fn main() { // @@ -95,28 +87,3 @@ async fn main() { next_frame().await } } - -fn mquad_from_na(a: Point2) -> Vec2 { - Vec2::new(a.x, a.y) -} - -fn na_from_mquad(a: Vec2) -> Point2 { - Point2::new(a.x, a.y) -} - -fn draw_line_2d(a: Vec2, b: Vec2, color: Color) { - draw_line(a.x, a.y, b.x, b.y, 2f32, color); -} - -fn draw_trimesh2(trimesh: &TriMesh, offset: Vec2) { - let vertices = trimesh.vertices(); - for v in trimesh.indices() { - let v0 = mquad_from_na(vertices[v[0] as usize]) + offset; - let v1 = mquad_from_na(vertices[v[1] as usize]) + offset; - let v2 = mquad_from_na(vertices[v[2] as usize]) + offset; - - draw_line(v0.x, v0.y, v1.x, v1.y, 2f32, WHITE); - draw_line(v0.x, v0.y, v2.x, v2.y, 2f32, WHITE); - draw_line(v2.x, v2.y, v1.x, v1.y, 2f32, WHITE); - } -} diff --git a/crates/parry2d/examples/raycasts_animated.rs b/crates/parry2d/examples/raycasts_animated.rs index 09aa4bd4..76ed094f 100644 --- a/crates/parry2d/examples/raycasts_animated.rs +++ b/crates/parry2d/examples/raycasts_animated.rs @@ -1,3 +1,6 @@ +mod common_macroquad; + +use common_macroquad::draw_point; use macroquad::prelude::*; use nalgebra::{Isometry2, Point2, UnitComplex, Vector2}; use parry2d::math::Isometry; @@ -99,26 +102,6 @@ fn draw_polygon( } } -fn draw_point(point: Point2, scale: f32, shift: Point2, color: Color) { - let edge_len = 0.15; - draw_line( - (point.x - edge_len) * scale + shift.x, - point.y * scale + shift.y, - (point.x + edge_len) * scale + shift.x, - point.y * scale + shift.y, - 2.0, - color, - ); - draw_line( - point.x * scale + shift.x, - (point.y - edge_len) * scale + shift.y, - point.x * scale + shift.x, - (point.y + edge_len) * scale + shift.y, - 2.0, - color, - ); -} - fn drawline_from_to( from: Point2, to: Point2, diff --git a/crates/parry3d/examples/common_macroquad.rs b/crates/parry3d/examples/common_macroquad.rs index 0bd37202..0e97a1c2 100644 --- a/crates/parry3d/examples/common_macroquad.rs +++ b/crates/parry3d/examples/common_macroquad.rs @@ -12,7 +12,7 @@ use parry3d::math::Real; fn main() { println!( - "This module contains helper fubnctions to use macroquad, + "This module contains helper functions to use macroquad, isolated from the rest of the examples for the sake of simplicity." ); } From 8057422e8f72b862abaaa1536f33cac51820197e Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 3 Sep 2024 15:23:17 +0200 Subject: [PATCH 14/24] add example for convex hull --- crates/parry2d/examples/common_macroquad.rs | 5 +- crates/parry2d/examples/convex_hull2d.rs | 57 +++++++++++++++------ 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/crates/parry2d/examples/common_macroquad.rs b/crates/parry2d/examples/common_macroquad.rs index 6326afe2..bdfc8281 100644 --- a/crates/parry2d/examples/common_macroquad.rs +++ b/crates/parry2d/examples/common_macroquad.rs @@ -40,7 +40,10 @@ pub fn easy_draw_text(text: &str) { pub fn lissajous_2d(t: f32) -> Vec2 { // Some hardcoded parameters to have a pleasing lissajous trajectory. - let (a, b, delta_x, delta_y) = (3.0, 2.0, FRAC_PI_2, FRAC_PI_4); + lissajous_2d_with_params(t, 3.0, 2.0, FRAC_PI_2, FRAC_PI_4) +} +pub fn lissajous_2d_with_params(t: f32, a: f32, b: f32, delta_x: f32, delta_y: f32) -> Vec2 { + // Some hardcoded parameters to have a pleasing lissajous trajectory. let x = (a * t + delta_x).sin(); let y = (b * t + delta_y).sin(); diff --git a/crates/parry2d/examples/convex_hull2d.rs b/crates/parry2d/examples/convex_hull2d.rs index 9d7e1b5e..ac477e72 100644 --- a/crates/parry2d/examples/convex_hull2d.rs +++ b/crates/parry2d/examples/convex_hull2d.rs @@ -1,21 +1,44 @@ -extern crate nalgebra as na; +mod common_macroquad; -use na::Point2; +use std::f32::consts::{FRAC_PI_2, FRAC_PI_4}; + +use common_macroquad::{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 + } } From feda1a6bb3c6cd3da7c79dee86bea6ad6275e92f Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 3 Sep 2024 15:58:46 +0200 Subject: [PATCH 15/24] 3d example for convex hull --- crates/parry3d/examples/common_macroquad.rs | 12 +++- crates/parry3d/examples/convex_hull3d.rs | 65 ++++++++++++++++----- 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/crates/parry3d/examples/common_macroquad.rs b/crates/parry3d/examples/common_macroquad.rs index 0e97a1c2..5b5411f7 100644 --- a/crates/parry3d/examples/common_macroquad.rs +++ b/crates/parry3d/examples/common_macroquad.rs @@ -27,8 +27,18 @@ pub fn na_from_mquad(a: Vec3) -> Point3 { pub fn lissajous_3d(t: f32) -> Vec3 { // Some hardcoded parameters to have a pleasing lissajous trajectory. - let (a, b, c, delta_x, delta_y, delta_z) = (3.0, 2.0, 1.0, FRAC_PI_2, FRAC_PI_4, FRAC_PI_6); + lissajous_3d_with_params(t, 3.0, 2.0, 1.0, FRAC_PI_2, FRAC_PI_4, FRAC_PI_6) +} +pub fn lissajous_3d_with_params( + t: f32, + a: f32, + b: f32, + c: f32, + delta_x: f32, + delta_y: f32, + delta_z: f32, +) -> Vec3 { let x = (a * t + delta_x).sin(); let y = (b * t + delta_y).sin(); let z = (c * t + delta_z).sin(); diff --git a/crates/parry3d/examples/convex_hull3d.rs b/crates/parry3d/examples/convex_hull3d.rs index c75fb956..3ba40ea1 100644 --- a/crates/parry3d/examples/convex_hull3d.rs +++ b/crates/parry3d/examples/convex_hull3d.rs @@ -1,21 +1,54 @@ -extern crate nalgebra as na; +mod common_macroquad; -use na::Point3; +use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; + +use common_macroquad::{ + 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), - ]; +const RENDER_SCALE: f32 = 30.0; + +#[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 + } } From 39d7f8e0a25f18e5e4e708d553b2377dabc4b74e Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 3 Sep 2024 15:58:52 +0200 Subject: [PATCH 16/24] 3d example for convex hull --- crates/parry3d/examples/convex_hull3d.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/parry3d/examples/convex_hull3d.rs b/crates/parry3d/examples/convex_hull3d.rs index 3ba40ea1..f0ad7051 100644 --- a/crates/parry3d/examples/convex_hull3d.rs +++ b/crates/parry3d/examples/convex_hull3d.rs @@ -9,8 +9,6 @@ use macroquad::prelude::*; use nalgebra::Point3; use parry3d::transformation; -const RENDER_SCALE: f32 = 30.0; - #[macroquad::main("parry2d::utils::point_in_poly2d")] async fn main() { let count = 9; From aa711e6118d2933736d56d3d34e5b06843e72937 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 3 Sep 2024 17:09:40 +0200 Subject: [PATCH 17/24] add example for aabb2d --- crates/parry2d/examples/aabb2d.rs | 132 +++++++++++++++++++++++------- 1 file changed, 101 insertions(+), 31 deletions(-) diff --git a/crates/parry2d/examples/aabb2d.rs b/crates/parry2d/examples/aabb2d.rs index 29af24ce..097adf47 100644 --- a/crates/parry2d/examples/aabb2d.rs +++ b/crates/parry2d/examples/aabb2d.rs @@ -1,36 +1,106 @@ +mod common_macroquad; + extern crate nalgebra as na; -use na::Isometry2; -use parry2d::bounding_volume::BoundingVolume; +use common_macroquad::{ + draw_point, draw_polygon, draw_polyline, lissajous_2d, lissajous_2d_with_params, mquad_from_na, + na_from_mquad, +}; +use macroquad::prelude::*; +use na::{iter, Isometry2}; +use nalgebra::Point2; +use parry2d::bounding_volume::{Aabb, BoundingVolume}; use parry2d::shape::Ball; +use parry2d::transformation; +use std::f32::consts::{FRAC_PI_2, FRAC_PI_4}; + +const RENDER_SCALE: f32 = 30.0; + +#[macroquad::main("parry2d::utils::point_in_poly2d")] +async fn main() { + let render_pos = Vec2::new(300.0, 300.0); + + loop { + let elapsed_time = get_time() as f32; + let elapsed_time_slow = elapsed_time * 0.2; + clear_background(BLACK); + + /* + * Initialize the shapes. + */ + let ball1 = Ball::new(0.5); + let ball2 = Ball::new(1.0); + + let ball1_pos = na_from_mquad(lissajous_2d(elapsed_time)) * 3f32; + let ball2_pos = Isometry2::identity(); + + /* + * Compute their axis-aligned bounding boxes. + */ + let aabb_ball1 = ball1.aabb(&ball1_pos.into()); + let aabb_ball2 = ball2.aabb(&ball2_pos); + + // Merge the two boxes. + let bounding_aabb = aabb_ball1.merged(&aabb_ball2); + + // Enlarge the ball2 aabb. + let loose_aabb_ball2 = aabb_ball2.loosened(1.0); + + // Intersection and inclusion tests. + let color = if aabb_ball1.intersects(&aabb_ball2) { + RED + } else { + GREEN + }; + + assert!(bounding_aabb.contains(&aabb_ball1)); + assert!(bounding_aabb.contains(&aabb_ball2)); + assert!(loose_aabb_ball2.contains(&aabb_ball2)); + + let ball1_translation = + Vec2::new(ball1_pos.coords.x, ball1_pos.coords.y) * RENDER_SCALE + render_pos; + draw_circle( + ball1_translation.x, + ball1_translation.y, + ball1.radius * RENDER_SCALE, + color, + ); + let ball2_translation = Vec2::new( + ball2_pos.translation.vector.x, + ball2_pos.translation.vector.y, + ) * RENDER_SCALE + + render_pos; + draw_circle( + ball2_translation.x, + ball2_translation.y, + ball2.radius * RENDER_SCALE, + color, + ); + + draw_aabb(aabb_ball1, render_pos, color); + draw_aabb(aabb_ball2, render_pos, color); + draw_aabb(bounding_aabb, render_pos, BLUE); + draw_aabb(loose_aabb_ball2, render_pos, YELLOW); + next_frame().await + } +} + +fn draw_aabb(aabb: Aabb, offset: Vec2, color: Color) { + let mins = mquad_from_na(aabb.mins) * RENDER_SCALE + offset; + let maxs = mquad_from_na(aabb.maxs) * RENDER_SCALE + offset; + let size = maxs - mins; -fn main() { - /* - * Initialize the shapes. - */ - let ball1 = Ball::new(0.5); - let ball2 = Ball::new(1.0); - - let ball1_pos = Isometry2::translation(0.0, 1.0); - let ball2_pos = Isometry2::identity(); - - /* - * Compute their axis-aligned bounding boxes. - */ - let aabb_ball1 = ball1.aabb(&ball1_pos); - let aabb_ball2 = ball2.aabb(&ball2_pos); - - // Merge the two boxes. - let bounding_aabb = aabb_ball1.merged(&aabb_ball2); - - // Enlarge the ball2 aabb. - let loose_aabb_ball2 = aabb_ball2.loosened(1.0); - - // Intersection and inclusion tests. - assert!(aabb_ball1.intersects(&aabb_ball2)); - assert!(bounding_aabb.contains(&aabb_ball1)); - assert!(bounding_aabb.contains(&aabb_ball2)); - assert!(!aabb_ball2.contains(&bounding_aabb)); - assert!(!aabb_ball1.contains(&bounding_aabb)); - assert!(loose_aabb_ball2.contains(&aabb_ball2)); + let line = vec![ + Vec2::new(mins.x, mins.y), + Vec2::new(mins.x, maxs.y), + Vec2::new(maxs.x, maxs.y), + Vec2::new(maxs.x, mins.y), + Vec2::new(mins.x, mins.y), + ]; + let drawable_line = line + .iter() + .zip(line.iter().cycle().skip(1).take(line.len())) + .map(|item| (item.0.clone(), item.1.clone())) + .collect(); + draw_polyline(drawable_line, color); } From 335639f7cd4d70c24f07466351e94d6bb005f674 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 3 Sep 2024 17:50:21 +0200 Subject: [PATCH 18/24] example for aabb in 3d --- crates/parry2d/examples/aabb2d.rs | 41 ++++---- crates/parry3d/examples/aabb3d.rs | 161 ++++++++++++++++++++++++------ 2 files changed, 149 insertions(+), 53 deletions(-) diff --git a/crates/parry2d/examples/aabb2d.rs b/crates/parry2d/examples/aabb2d.rs index 097adf47..421496f7 100644 --- a/crates/parry2d/examples/aabb2d.rs +++ b/crates/parry2d/examples/aabb2d.rs @@ -2,17 +2,11 @@ mod common_macroquad; extern crate nalgebra as na; -use common_macroquad::{ - draw_point, draw_polygon, draw_polyline, lissajous_2d, lissajous_2d_with_params, mquad_from_na, - na_from_mquad, -}; +use common_macroquad::{draw_polyline, lissajous_2d, mquad_from_na, na_from_mquad}; use macroquad::prelude::*; -use na::{iter, Isometry2}; -use nalgebra::Point2; +use na::Isometry2; use parry2d::bounding_volume::{Aabb, BoundingVolume}; use parry2d::shape::Ball; -use parry2d::transformation; -use std::f32::consts::{FRAC_PI_2, FRAC_PI_4}; const RENDER_SCALE: f32 = 30.0; @@ -21,8 +15,7 @@ async fn main() { let render_pos = Vec2::new(300.0, 300.0); loop { - let elapsed_time = get_time() as f32; - let elapsed_time_slow = elapsed_time * 0.2; + let elapsed_time = get_time() as f32 * 0.7; clear_background(BLACK); /* @@ -31,7 +24,7 @@ async fn main() { let ball1 = Ball::new(0.5); let ball2 = Ball::new(1.0); - let ball1_pos = na_from_mquad(lissajous_2d(elapsed_time)) * 3f32; + let ball1_pos = na_from_mquad(lissajous_2d(elapsed_time)) * 5f32; let ball2_pos = Isometry2::identity(); /* @@ -44,9 +37,9 @@ async fn main() { let bounding_aabb = aabb_ball1.merged(&aabb_ball2); // Enlarge the ball2 aabb. - let loose_aabb_ball2 = aabb_ball2.loosened(1.0); + let loose_aabb_ball2 = aabb_ball2.loosened(2f32); - // Intersection and inclusion tests. + // Intersection test let color = if aabb_ball1.intersects(&aabb_ball2) { RED } else { @@ -57,19 +50,15 @@ async fn main() { assert!(bounding_aabb.contains(&aabb_ball2)); assert!(loose_aabb_ball2.contains(&aabb_ball2)); - let ball1_translation = - Vec2::new(ball1_pos.coords.x, ball1_pos.coords.y) * RENDER_SCALE + render_pos; + let ball1_translation = mquad_from_na(ball1_pos.coords.into()) * RENDER_SCALE + render_pos; draw_circle( ball1_translation.x, ball1_translation.y, ball1.radius * RENDER_SCALE, color, ); - let ball2_translation = Vec2::new( - ball2_pos.translation.vector.x, - ball2_pos.translation.vector.y, - ) * RENDER_SCALE - + render_pos; + let ball2_translation = + mquad_from_na(ball2_pos.translation.vector.into()) * RENDER_SCALE + render_pos; draw_circle( ball2_translation.x, ball2_translation.y, @@ -79,8 +68,15 @@ async fn main() { draw_aabb(aabb_ball1, render_pos, color); draw_aabb(aabb_ball2, render_pos, color); - draw_aabb(bounding_aabb, render_pos, BLUE); - draw_aabb(loose_aabb_ball2, render_pos, YELLOW); + draw_aabb(bounding_aabb, render_pos, YELLOW); + + // Inclusion test + let color_included: Color = if loose_aabb_ball2.contains(&aabb_ball1) { + BLUE + } else { + MAGENTA + }; + draw_aabb(loose_aabb_ball2, render_pos, color_included); next_frame().await } } @@ -88,7 +84,6 @@ async fn main() { fn draw_aabb(aabb: Aabb, offset: Vec2, color: Color) { let mins = mquad_from_na(aabb.mins) * RENDER_SCALE + offset; let maxs = mquad_from_na(aabb.maxs) * RENDER_SCALE + offset; - let size = maxs - mins; let line = vec![ Vec2::new(mins.x, mins.y), diff --git a/crates/parry3d/examples/aabb3d.rs b/crates/parry3d/examples/aabb3d.rs index 171111a8..9b74bccc 100644 --- a/crates/parry3d/examples/aabb3d.rs +++ b/crates/parry3d/examples/aabb3d.rs @@ -1,36 +1,137 @@ +mod common_macroquad; + extern crate nalgebra as na; +use common_macroquad::{draw_polyline, lissajous_3d, mquad_from_na, na_from_mquad}; +use macroquad::prelude::*; use na::Isometry3; -use parry3d::bounding_volume::BoundingVolume; +use parry3d::bounding_volume::{Aabb, BoundingVolume}; use parry3d::shape::Ball; +use std::f32::consts::{FRAC_PI_2, FRAC_PI_4}; + +const RENDER_SCALE: f32 = 30.0; + +#[macroquad::main("parry2d::utils::point_in_poly2d")] +async fn main() { + let render_pos = Vec2::new(300.0, 300.0); + let camera_pos = Vec3::new(8f32, 8f32, 12f32); + + loop { + let elapsed_time = get_time() as f32 * 0.7; + clear_background(BLACK); + // 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() + }); + + /* + * Initialize the shapes. + */ + let ball1 = Ball::new(0.5); + let ball2 = Ball::new(1.0); + + let ball1_pos = na_from_mquad(lissajous_3d(elapsed_time)) * 4f32; + let ball2_pos = Isometry3::identity(); + + /* + * Compute their axis-aligned bounding boxes. + */ + let aabb_ball1 = ball1.aabb(&ball1_pos.into()); + let aabb_ball2 = ball2.aabb(&ball2_pos); + + // Merge the two boxes. + let bounding_aabb = aabb_ball1.merged(&aabb_ball2); + + // Enlarge the ball2 aabb. + let loose_aabb_ball2 = aabb_ball2.loosened(2.25f32); + + // Intersection and inclusion tests. + let color = if aabb_ball1.intersects(&aabb_ball2) { + RED + } else { + GREEN + }; + + assert!(bounding_aabb.contains(&aabb_ball1)); + assert!(bounding_aabb.contains(&aabb_ball2)); + assert!(loose_aabb_ball2.contains(&aabb_ball2)); + + let ball1_translation = mquad_from_na(ball1_pos.coords.into()); + draw_sphere(ball1_translation, ball1.radius, None, color); + let ball2_translation = mquad_from_na(ball2_pos.translation.vector.into()); + draw_sphere(ball2_translation, ball2.radius, None, color); + + draw_aabb(aabb_ball1, color); + draw_aabb(aabb_ball2, color); + draw_aabb(bounding_aabb, YELLOW); + + let color_included: Color = if loose_aabb_ball2.contains(&aabb_ball1) { + BLUE + } else { + MAGENTA + }; + draw_aabb(loose_aabb_ball2, color_included); + next_frame().await + } +} + +fn draw_aabb(aabb: Aabb, color: Color) { + let mins = mquad_from_na(aabb.mins); + let maxs = mquad_from_na(aabb.maxs); + + let lines = vec![ + ( + Vec3::new(mins.x, mins.y, mins.z), // A -> B + Vec3::new(maxs.x, mins.y, mins.z), + ), + ( + Vec3::new(maxs.x, mins.y, mins.z), // B -> F + Vec3::new(maxs.x, mins.y, maxs.z), + ), + ( + Vec3::new(maxs.x, mins.y, maxs.z), // F -> E + Vec3::new(mins.x, mins.y, maxs.z), + ), + ( + Vec3::new(mins.x, mins.y, maxs.z), // E -> A + Vec3::new(mins.x, mins.y, mins.z), + ), + ( + Vec3::new(mins.x, mins.y, mins.z), // A -> D + Vec3::new(mins.x, maxs.y, mins.z), + ), + ( + Vec3::new(mins.x, maxs.y, mins.z), // D -> H + Vec3::new(mins.x, maxs.y, maxs.z), + ), + ( + Vec3::new(mins.x, maxs.y, maxs.z), // H -> E + Vec3::new(mins.x, mins.y, maxs.z), + ), + ( + Vec3::new(mins.x, maxs.y, maxs.z), // H -> G + Vec3::new(maxs.x, maxs.y, maxs.z), + ), + ( + Vec3::new(maxs.x, maxs.y, maxs.z), // G -> F + Vec3::new(maxs.x, mins.y, maxs.z), + ), + ( + Vec3::new(maxs.x, maxs.y, maxs.z), // G -> C + Vec3::new(maxs.x, maxs.y, mins.z), + ), + ( + Vec3::new(maxs.x, maxs.y, mins.z), // C -> B + Vec3::new(maxs.x, mins.y, mins.z), + ), + ( + Vec3::new(mins.x, maxs.y, mins.z), // D -> C + Vec3::new(maxs.x, maxs.y, mins.z), + ), + ]; -fn main() { - /* - * Initialize the shapes. - */ - let ball1 = Ball::new(0.5); - let ball2 = Ball::new(1.0); - - let ball1_pos = Isometry3::translation(0.0, 1.0, 0.0); - let ball2_pos = Isometry3::identity(); // Identity matrix. - - /* - * Compute their axis-aligned bounding boxes. - */ - let aabb_ball1 = ball1.aabb(&ball1_pos); - let aabb_ball2 = ball2.aabb(&ball2_pos); - - // Merge the two boxes. - let bounding_aabb = aabb_ball1.merged(&aabb_ball2); - - // Enlarge the ball2 aabb. - let loose_aabb_ball2 = aabb_ball2.loosened(1.0); - - // Intersection and inclusion tests. - assert!(aabb_ball1.intersects(&aabb_ball2)); - assert!(bounding_aabb.contains(&aabb_ball1)); - assert!(bounding_aabb.contains(&aabb_ball2)); - assert!(!aabb_ball2.contains(&bounding_aabb)); - assert!(!aabb_ball1.contains(&bounding_aabb)); - assert!(loose_aabb_ball2.contains(&aabb_ball2)); + draw_polyline(lines, color); } From 35c557fc767d229cea31b4137f9a671a0e870a83 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 3 Sep 2024 17:54:34 +0200 Subject: [PATCH 19/24] remove a few unused code --- crates/parry3d/examples/aabb3d.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/parry3d/examples/aabb3d.rs b/crates/parry3d/examples/aabb3d.rs index 9b74bccc..b7ae0a30 100644 --- a/crates/parry3d/examples/aabb3d.rs +++ b/crates/parry3d/examples/aabb3d.rs @@ -7,13 +7,9 @@ use macroquad::prelude::*; use na::Isometry3; use parry3d::bounding_volume::{Aabb, BoundingVolume}; use parry3d::shape::Ball; -use std::f32::consts::{FRAC_PI_2, FRAC_PI_4}; - -const RENDER_SCALE: f32 = 30.0; #[macroquad::main("parry2d::utils::point_in_poly2d")] async fn main() { - let render_pos = Vec2::new(300.0, 300.0); let camera_pos = Vec3::new(8f32, 8f32, 12f32); loop { From 607ac1f0e3fa6d8dab591214e2073b0b0a7d7a21 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 4 Sep 2024 11:48:40 +0200 Subject: [PATCH 20/24] simpler aabb 3d function --- crates/parry3d/examples/aabb3d.rs | 63 ++++--------------------------- 1 file changed, 7 insertions(+), 56 deletions(-) diff --git a/crates/parry3d/examples/aabb3d.rs b/crates/parry3d/examples/aabb3d.rs index b7ae0a30..844c4347 100644 --- a/crates/parry3d/examples/aabb3d.rs +++ b/crates/parry3d/examples/aabb3d.rs @@ -2,7 +2,7 @@ mod common_macroquad; extern crate nalgebra as na; -use common_macroquad::{draw_polyline, lissajous_3d, mquad_from_na, na_from_mquad}; +use common_macroquad::{lissajous_3d, mquad_from_na, na_from_mquad}; use macroquad::prelude::*; use na::Isometry3; use parry3d::bounding_volume::{Aabb, BoundingVolume}; @@ -75,59 +75,10 @@ async fn main() { } fn draw_aabb(aabb: Aabb, color: Color) { - let mins = mquad_from_na(aabb.mins); - let maxs = mquad_from_na(aabb.maxs); - - let lines = vec![ - ( - Vec3::new(mins.x, mins.y, mins.z), // A -> B - Vec3::new(maxs.x, mins.y, mins.z), - ), - ( - Vec3::new(maxs.x, mins.y, mins.z), // B -> F - Vec3::new(maxs.x, mins.y, maxs.z), - ), - ( - Vec3::new(maxs.x, mins.y, maxs.z), // F -> E - Vec3::new(mins.x, mins.y, maxs.z), - ), - ( - Vec3::new(mins.x, mins.y, maxs.z), // E -> A - Vec3::new(mins.x, mins.y, mins.z), - ), - ( - Vec3::new(mins.x, mins.y, mins.z), // A -> D - Vec3::new(mins.x, maxs.y, mins.z), - ), - ( - Vec3::new(mins.x, maxs.y, mins.z), // D -> H - Vec3::new(mins.x, maxs.y, maxs.z), - ), - ( - Vec3::new(mins.x, maxs.y, maxs.z), // H -> E - Vec3::new(mins.x, mins.y, maxs.z), - ), - ( - Vec3::new(mins.x, maxs.y, maxs.z), // H -> G - Vec3::new(maxs.x, maxs.y, maxs.z), - ), - ( - Vec3::new(maxs.x, maxs.y, maxs.z), // G -> F - Vec3::new(maxs.x, mins.y, maxs.z), - ), - ( - Vec3::new(maxs.x, maxs.y, maxs.z), // G -> C - Vec3::new(maxs.x, maxs.y, mins.z), - ), - ( - Vec3::new(maxs.x, maxs.y, mins.z), // C -> B - Vec3::new(maxs.x, mins.y, mins.z), - ), - ( - Vec3::new(mins.x, maxs.y, mins.z), // D -> C - Vec3::new(maxs.x, maxs.y, mins.z), - ), - ]; - - draw_polyline(lines, color); + let size = aabb.maxs - aabb.mins; + draw_cube_wires( + mquad_from_na(aabb.maxs - size / 2f32), + mquad_from_na(size.into()), + color, + ); } From 5e1b424e93703d3ccadd1075660d1eb3279fcadd Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Fri, 13 Sep 2024 11:26:10 +0200 Subject: [PATCH 21/24] add back a space for diff --- crates/parry2d/examples/point_in_poly2d.rs | 1 + crates/parry2d/examples/polygons_intersection2d.rs | 1 + crates/parry2d/examples/project_point2d.rs | 1 + crates/parry2d/examples/raycasts_animated.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/crates/parry2d/examples/point_in_poly2d.rs b/crates/parry2d/examples/point_in_poly2d.rs index 65f9ed58..99f28770 100644 --- a/crates/parry2d/examples/point_in_poly2d.rs +++ b/crates/parry2d/examples/point_in_poly2d.rs @@ -1,4 +1,5 @@ mod common_macroquad2d; + use common_macroquad2d::{draw_point, draw_polygon}; use macroquad::prelude::*; use nalgebra::{Point2, UnitComplex, Vector2}; diff --git a/crates/parry2d/examples/polygons_intersection2d.rs b/crates/parry2d/examples/polygons_intersection2d.rs index b7598003..604f86c5 100644 --- a/crates/parry2d/examples/polygons_intersection2d.rs +++ b/crates/parry2d/examples/polygons_intersection2d.rs @@ -1,4 +1,5 @@ mod common_macroquad2d; + use common_macroquad2d::draw_polygon; use macroquad::prelude::*; use nalgebra::{Point2, UnitComplex, Vector2}; diff --git a/crates/parry2d/examples/project_point2d.rs b/crates/parry2d/examples/project_point2d.rs index d9bdbe50..fc2a9884 100644 --- a/crates/parry2d/examples/project_point2d.rs +++ b/crates/parry2d/examples/project_point2d.rs @@ -1,4 +1,5 @@ mod common_macroquad2d; + use common_macroquad2d::{draw_line_2d, draw_trimesh2, lissajous_2d, mquad_from_na, na_from_mquad}; use macroquad::prelude::*; use nalgebra::{Point3, UnitComplex, Vector2}; diff --git a/crates/parry2d/examples/raycasts_animated.rs b/crates/parry2d/examples/raycasts_animated.rs index dfb7eebf..ddd8fcb4 100644 --- a/crates/parry2d/examples/raycasts_animated.rs +++ b/crates/parry2d/examples/raycasts_animated.rs @@ -1,4 +1,5 @@ mod common_macroquad2d; + use common_macroquad2d::draw_point; use macroquad::prelude::*; use nalgebra::{Isometry2, Point2, UnitComplex, Vector2}; From c1b65024edca3222bcb66d3953497614961aa66d Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Fri, 13 Sep 2024 11:26:50 +0200 Subject: [PATCH 22/24] removed a wrong file --- crates/parry3d/examples/common_macroquad.rs | 130 -------------------- 1 file changed, 130 deletions(-) delete mode 100644 crates/parry3d/examples/common_macroquad.rs diff --git a/crates/parry3d/examples/common_macroquad.rs b/crates/parry3d/examples/common_macroquad.rs deleted file mode 100644 index 5b5411f7..00000000 --- a/crates/parry3d/examples/common_macroquad.rs +++ /dev/null @@ -1,130 +0,0 @@ -#[allow(unused, dead_code)] -use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6}; - -use macroquad::{ - color::{Color, WHITE}, - math::{Vec2, Vec3, Vec4}, - models::{draw_line_3d, Mesh}, - ui::Vertex, -}; -use nalgebra::Point3; -use parry3d::math::Real; - -fn main() { - println!( - "This module contains helper functions to use macroquad, - isolated from the rest of the examples for the sake of simplicity." - ); -} - -pub fn mquad_from_na(a: Point3) -> Vec3 { - Vec3::new(a.x, a.y, a.z) -} - -pub fn na_from_mquad(a: Vec3) -> Point3 { - Point3::new(a.x, a.y, a.z) -} - -pub fn lissajous_3d(t: f32) -> Vec3 { - // Some hardcoded parameters to have a pleasing lissajous trajectory. - lissajous_3d_with_params(t, 3.0, 2.0, 1.0, FRAC_PI_2, FRAC_PI_4, FRAC_PI_6) -} - -pub fn lissajous_3d_with_params( - t: f32, - a: f32, - b: f32, - c: f32, - delta_x: f32, - delta_y: f32, - delta_z: f32, -) -> Vec3 { - let x = (a * t + delta_x).sin(); - let y = (b * t + delta_y).sin(); - let z = (c * t + delta_z).sin(); - Vec3::new(x, y, z) * 0.75f32 -} - -pub fn draw_polyline(polygon: Vec<(Vec3, Vec3)>, color: Color) { - for i in 0..polygon.len() { - let a = polygon[i].0; - let b = polygon[i].1; - draw_line_3d(a, b, color); - } -} - -pub fn easy_draw_text(text: &str) { - macroquad::text::draw_text(text, 10.0, 48.0 + 18.0, 30.0, WHITE); -} - -pub fn mquad_mesh_from_points( - trimesh: &(Vec>, Vec<[u32; 3]>), - light_pos: Vec3, - color: Color, -) -> Mesh { - let (points, indices) = trimesh; - // Transform the parry mesh into a mquad Mesh - let (mquad_points, mquad_indices) = ( - points - .iter() - .map(|p| Vertex { - position: mquad_from_na(*p), - uv: Vec2::new(p.x, p.y), - color: color.into(), - normal: Vec4::ZERO, - }) - .collect(), - indices.iter().flatten().map(|v| *v as u16).collect(), - ); - - // Macroquad does support adding normals to vertices, but we´d have to provide shaders for them. - // so we're baking a color into these vertices. - // See https://github.com/not-fl3/macroquad/issues/321. - - // Compute the normal of each vertex, making them unique - let vertices: Vec = - mquad_compute_normals_and_bake_light(&mquad_points, &mquad_indices, light_pos); - // Regenerate the index for each vertex. - let indices: Vec = (0..vertices.len() * 3) - .into_iter() - .map(|i| i as u16) - .collect(); - let mesh = Mesh { - vertices, - indices, - texture: None, - }; - mesh -} - -pub fn mquad_compute_normals_and_bake_light( - points: &Vec, - indices: &Vec, - light_pos: Vec3, -) -> Vec { - let mut vertices: Vec = Vec::::new(); - for indices in indices.chunks(3) { - let v0 = &points[indices[0] as usize]; - let v1 = &points[indices[1] as usize]; - let v2 = &points[indices[2] as usize]; - let normal = (v0.position - v2.position) - .cross(v1.position - v2.position) - .normalize(); - let brightness_mod = 0.4 + (0.6 / 2.) * (normal.dot(light_pos) + 1.); - - for &i in indices.iter() { - let mut color = points[i as usize].color; - color[0] = (color[0] as f32 * brightness_mod) as u8; - color[1] = (color[1] as f32 * brightness_mod) as u8; - color[2] = (color[2] as f32 * brightness_mod) as u8; - - vertices.push(Vertex { - position: points[i as usize].position, - uv: Vec2::ZERO, - color: color, - normal: Vec4::ZERO, - }); - } - } - vertices -} From 211d7243168db984be82b0947eb6110c8eeb6c0b Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Fri, 13 Sep 2024 11:27:19 +0200 Subject: [PATCH 23/24] fix conflict again --- src/transformation/to_trimesh/cuboid_to_trimesh.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/transformation/to_trimesh/cuboid_to_trimesh.rs b/src/transformation/to_trimesh/cuboid_to_trimesh.rs index 148ec6ac..5132cf17 100644 --- a/src/transformation/to_trimesh/cuboid_to_trimesh.rs +++ b/src/transformation/to_trimesh/cuboid_to_trimesh.rs @@ -3,11 +3,6 @@ use crate::math::{Point, Real}; use crate::shape::Cuboid; use crate::transformation::utils; -#[cfg(feature = "dim2")] -use na::Point2 as PointDim; -#[cfg(feature = "dim2")] -use na::{self, Point2}; - impl Aabb { /// Discretize the boundary of this Aabb as a triangle-mesh. pub fn to_trimesh(&self) -> (Vec>, Vec<[u32; 3]>) { From d9d5865a6024d7ebac29c2f377d1d83407d97424 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Fri, 13 Sep 2024 15:25:12 +0200 Subject: [PATCH 24/24] fixed use of common_macroquad --- crates/parry2d/examples/aabb2d.rs | 4 ++-- crates/parry3d/examples/aabb3d.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/parry2d/examples/aabb2d.rs b/crates/parry2d/examples/aabb2d.rs index 421496f7..9223f6e5 100644 --- a/crates/parry2d/examples/aabb2d.rs +++ b/crates/parry2d/examples/aabb2d.rs @@ -1,8 +1,8 @@ -mod common_macroquad; +mod common_macroquad2d; extern crate nalgebra as na; -use common_macroquad::{draw_polyline, lissajous_2d, mquad_from_na, na_from_mquad}; +use common_macroquad2d::{draw_polyline, lissajous_2d, mquad_from_na, na_from_mquad}; use macroquad::prelude::*; use na::Isometry2; use parry2d::bounding_volume::{Aabb, BoundingVolume}; diff --git a/crates/parry3d/examples/aabb3d.rs b/crates/parry3d/examples/aabb3d.rs index 844c4347..87101e6b 100644 --- a/crates/parry3d/examples/aabb3d.rs +++ b/crates/parry3d/examples/aabb3d.rs @@ -1,8 +1,8 @@ -mod common_macroquad; +mod common_macroquad3d; extern crate nalgebra as na; -use common_macroquad::{lissajous_3d, mquad_from_na, na_from_mquad}; +use common_macroquad3d::{lissajous_3d, mquad_from_na, na_from_mquad}; use macroquad::prelude::*; use na::Isometry3; use parry3d::bounding_volume::{Aabb, BoundingVolume};