Outsource the contact manifold, SAT, and some shapes.
This commit is contained in:
@@ -501,7 +501,7 @@ impl GraphicsManager {
|
||||
object: DefaultColliderHandle,
|
||||
colliders: &DefaultColliderSet<f32>,
|
||||
delta: Isometry<f32>,
|
||||
shape: &Cuboid<f32>,
|
||||
shape: &Cuboid,
|
||||
color: Point3<f32>,
|
||||
out: &mut Vec<Node>,
|
||||
) {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#[macro_use]
|
||||
extern crate kiss3d;
|
||||
#[cfg(feature = "dim2")]
|
||||
extern crate buckler2d as buckler;
|
||||
#[cfg(feature = "dim3")]
|
||||
extern crate buckler3d as buckler;
|
||||
extern crate nalgebra as na;
|
||||
#[cfg(feature = "dim2")]
|
||||
extern crate ncollide2d as ncollide;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use ncollide::shape::{Ball, Capsule, Cuboid, ShapeHandle};
|
||||
use ncollide::shape::{Ball, Capsule, Cuboid, HeightField, ShapeHandle};
|
||||
use nphysics::force_generator::DefaultForceGeneratorSet;
|
||||
use nphysics::joint::{
|
||||
DefaultJointConstraintSet, FixedConstraint, PrismaticConstraint, RevoluteConstraint,
|
||||
@@ -187,7 +187,10 @@ fn nphysics_collider_from_rapier_collider(
|
||||
pos *= capsule.transform_wrt_y();
|
||||
ShapeHandle::new(Capsule::new(capsule.half_height(), capsule.radius))
|
||||
} else if let Some(heightfield) = shape.as_heightfield() {
|
||||
ShapeHandle::new(heightfield.clone())
|
||||
let heights = heightfield.heights();
|
||||
let scale = heightfield.scale();
|
||||
let heightfield = HeightField::new(heights.clone(), *scale);
|
||||
ShapeHandle::new(heightfield)
|
||||
} else {
|
||||
#[cfg(feature = "dim3")]
|
||||
if let Some(trimesh) = shape.as_trimesh() {
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
#[cfg(feature = "dim3")]
|
||||
use crate::objects::node::{self, GraphicsNode};
|
||||
use buckler::shape;
|
||||
use kiss3d::resource::Mesh;
|
||||
use kiss3d::window::Window;
|
||||
use na::{self, Point3};
|
||||
use ncollide::shape;
|
||||
#[cfg(feature = "dim3")]
|
||||
use ncollide::transformation::ToTriMesh;
|
||||
use rapier::geometry::{ColliderHandle, ColliderSet};
|
||||
#[cfg(feature = "dim2")]
|
||||
use rapier::math::Point;
|
||||
#[cfg(feature = "dim3")]
|
||||
use rapier::math::Vector;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct HeightField {
|
||||
color: Point3<f32>,
|
||||
@@ -25,7 +26,7 @@ impl HeightField {
|
||||
#[cfg(feature = "dim2")]
|
||||
pub fn new(
|
||||
collider: ColliderHandle,
|
||||
heightfield: &shape::HeightField<f32>,
|
||||
heightfield: &shape::HeightField,
|
||||
color: Point3<f32>,
|
||||
_: &mut Window,
|
||||
) -> HeightField {
|
||||
@@ -47,16 +48,18 @@ impl HeightField {
|
||||
#[cfg(feature = "dim3")]
|
||||
pub fn new(
|
||||
collider: ColliderHandle,
|
||||
heightfield: &shape::HeightField<f32>,
|
||||
heightfield: &shape::HeightField,
|
||||
color: Point3<f32>,
|
||||
window: &mut Window,
|
||||
) -> HeightField {
|
||||
let mesh = heightfield.to_trimesh(());
|
||||
let (vertices, indices) = heightfield.to_trimesh();
|
||||
let indices = indices.into_iter().map(|i| na::convert(i)).collect();
|
||||
let mesh = Mesh::new(vertices, indices, None, None, false);
|
||||
|
||||
let mut res = HeightField {
|
||||
color,
|
||||
base_color: color,
|
||||
gfx: window.add_trimesh(mesh, Vector::repeat(1.0)),
|
||||
gfx: window.add_mesh(Rc::new(RefCell::new(mesh)), Vector::repeat(1.0)),
|
||||
collider: collider,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use buckler2d::shape;
|
||||
use kiss3d::window::Window;
|
||||
use na::{Isometry2, Point2, Point3};
|
||||
use ncollide2d::shape;
|
||||
use nphysics2d::object::{ColliderAnchor, DefaultColliderHandle, DefaultColliderSet};
|
||||
|
||||
pub struct Polyline {
|
||||
|
||||
@@ -1521,8 +1521,8 @@ fn draw_contacts(window: &mut Window, nf: &NarrowPhase, colliders: &ColliderSet)
|
||||
} else {
|
||||
Point3::new(1.0, 0.0, 0.0)
|
||||
};
|
||||
let pos1 = colliders[manifold.pair.collider1].position();
|
||||
let pos2 = colliders[manifold.pair.collider2].position();
|
||||
let pos1 = colliders[manifold.data.pair.collider1].position();
|
||||
let pos2 = colliders[manifold.data.pair.collider2].position();
|
||||
let start = pos1 * pt.local_p1;
|
||||
let end = pos2 * pt.local_p2;
|
||||
let n = pos1 * manifold.local_n1;
|
||||
|
||||
Reference in New Issue
Block a user