-
-
Notifications
You must be signed in to change notification settings - Fork 141
add an example for intersection plane #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ThierryBerger
merged 8 commits into
dimforge:master
from
ThierryBerger:intersection_plane_example
Aug 9, 2024
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b34ccb
add an example for intersection plane
ThierryBerger ec13983
fix flattened
ThierryBerger 358e6b1
helper function + removed an indirection
ThierryBerger d06491b
better looking shape (shadows), simpler geometry.
ThierryBerger 4a7f833
Merge remote-tracking branch 'upstream' into intersection_plane_example
ThierryBerger 8ac9df1
Merge remote-tracking branch 'upstream' into intersection_plane_example
ThierryBerger b7128e5
pr feedbacks
ThierryBerger d88dd24
Merge branch 'master' into intersection_plane_example
ThierryBerger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,141 @@ | ||||||
| use macroquad::models::Vertex; | ||||||
| use macroquad::prelude::*; | ||||||
| use nalgebra::{Point3, UnitVector3, Vector3}; | ||||||
| use parry3d::math::{Isometry, Real}; | ||||||
| use parry3d::query::IntersectResult; | ||||||
| use parry3d::shape::TriMesh; | ||||||
|
|
||||||
| fn build_diamond(position: &Isometry<Real>) -> (Vec<Point3<Real>>, 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: WHITE, | ||||||
| }) | ||||||
| .collect(), | ||||||
| indices: indices.iter().flatten().map(|v| *v as u16).collect(), | ||||||
| texture: None, | ||||||
| }; | ||||||
| let trimesh = TriMesh::new(points, indices); | ||||||
|
|
||||||
| for _i in 1.. { | ||||||
ThierryBerger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| clear_background(BLACK); | ||||||
|
|
||||||
| let elapsed_time = get_time(); | ||||||
|
|
||||||
| let bias = -2.0 * (elapsed_time as f32 / 3f32).sin(); | ||||||
| let rotation = Quat::from_axis_angle(Vec3::Z, (elapsed_time as f32 * 50f32).to_radians()); | ||||||
| let up_plane_vector = rotation * Vec3::Y; | ||||||
| let intersection_result = trimesh.intersection_with_local_plane( | ||||||
| &UnitVector3::new_normalize(Vector3::<Real>::new( | ||||||
|
||||||
| &UnitVector3::new_normalize(Vector3::<Real>::new( | |
| &UnitVector3::new_normalize(Vector3::new( |
ThierryBerger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ThierryBerger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.