@@ -749,20 +749,12 @@ impl<N, E> IndexMut<EdgeIndex> for Graph<N, E> {
|
|||||||
/// The walker does not borrow from the graph, so it lets you step through
|
/// The walker does not borrow from the graph, so it lets you step through
|
||||||
/// neighbors or incident edges while also mutating graph weights, as
|
/// neighbors or incident edges while also mutating graph weights, as
|
||||||
/// in the following example:
|
/// in the following example:
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct WalkNeighbors {
|
pub struct WalkNeighbors {
|
||||||
skip_start: NodeIndex,
|
skip_start: NodeIndex,
|
||||||
next: [EdgeIndex; 2],
|
next: [EdgeIndex; 2],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for WalkNeighbors {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
WalkNeighbors {
|
|
||||||
skip_start: self.skip_start,
|
|
||||||
next: self.next,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reference to a `Graph` edge.
|
/// Reference to a `Graph` edge.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EdgeReference<'a, E: 'a> {
|
pub struct EdgeReference<'a, E: 'a> {
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ impl From<PrismaticJoint> for JointParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
|
#[derive(Clone)]
|
||||||
/// A joint attached to two bodies.
|
/// A joint attached to two bodies.
|
||||||
pub struct Joint {
|
pub struct Joint {
|
||||||
/// Handle to the first body attached to this joint.
|
/// Handle to the first body attached to this joint.
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ pub enum BodyStatus {
|
|||||||
/// A rigid body.
|
/// A rigid body.
|
||||||
///
|
///
|
||||||
/// To create a new rigid-body, use the `RigidBodyBuilder` structure.
|
/// To create a new rigid-body, use the `RigidBodyBuilder` structure.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct RigidBody {
|
pub struct RigidBody {
|
||||||
/// The world-space position of the rigid-body.
|
/// The world-space position of the rigid-body.
|
||||||
pub position: Isometry<f32>,
|
pub position: Isometry<f32>,
|
||||||
@@ -58,20 +58,6 @@ pub struct RigidBody {
|
|||||||
pub user_data: u128,
|
pub user_data: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for RigidBody {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
Self {
|
|
||||||
colliders: Vec::new(),
|
|
||||||
joint_graph_index: RigidBodyGraphIndex::new(crate::INVALID_U32),
|
|
||||||
active_island_id: crate::INVALID_USIZE,
|
|
||||||
active_set_id: crate::INVALID_USIZE,
|
|
||||||
active_set_offset: crate::INVALID_USIZE,
|
|
||||||
active_set_timestamp: crate::INVALID_U32,
|
|
||||||
..*self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RigidBody {
|
impl RigidBody {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -96,6 +82,15 @@ impl RigidBody {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn reset_internal_links(&mut self) {
|
||||||
|
self.colliders = Vec::new();
|
||||||
|
self.joint_graph_index = RigidBodyGraphIndex::new(crate::INVALID_U32);
|
||||||
|
self.active_island_id = crate::INVALID_USIZE;
|
||||||
|
self.active_set_id = crate::INVALID_USIZE;
|
||||||
|
self.active_set_offset = crate::INVALID_USIZE;
|
||||||
|
self.active_set_timestamp = crate::INVALID_U32;
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn integrate_accelerations(&mut self, dt: f32, gravity: Vector<f32>) {
|
pub(crate) fn integrate_accelerations(&mut self, dt: f32, gravity: Vector<f32>) {
|
||||||
if self.mass_properties.inv_mass != 0.0 {
|
if self.mass_properties.inv_mass != 0.0 {
|
||||||
self.linvel += (gravity + self.linacc) * dt;
|
self.linvel += (gravity + self.linacc) * dt;
|
||||||
|
|||||||
@@ -154,7 +154,11 @@ impl RigidBodySet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a rigid body into this set and retrieve its handle.
|
/// Insert a rigid body into this set and retrieve its handle.
|
||||||
pub fn insert(&mut self, rb: RigidBody) -> RigidBodyHandle {
|
pub fn insert(&mut self, mut rb: RigidBody) -> RigidBodyHandle {
|
||||||
|
// Make sure the internal links are reset, they may not be
|
||||||
|
// if this rigid-body was obtained by cloning another one.
|
||||||
|
rb.reset_internal_links();
|
||||||
|
|
||||||
let handle = self.bodies.insert(rb);
|
let handle = self.bodies.insert(rb);
|
||||||
let rb = &mut self.bodies[handle];
|
let rb = &mut self.bodies[handle];
|
||||||
|
|
||||||
|
|||||||
@@ -188,6 +188,7 @@ impl<'de> serde::Deserialize<'de> for ColliderShape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
|
#[derive(Clone)]
|
||||||
/// A geometric entity that can be attached to a body so it can be affected by contacts and proximity queries.
|
/// A geometric entity that can be attached to a body so it can be affected by contacts and proximity queries.
|
||||||
///
|
///
|
||||||
/// To build a new collider, use the `ColliderBuilder` structure.
|
/// To build a new collider, use the `ColliderBuilder` structure.
|
||||||
@@ -212,20 +213,14 @@ pub struct Collider {
|
|||||||
pub user_data: u128,
|
pub user_data: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for Collider {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
Self {
|
|
||||||
shape: self.shape.clone(),
|
|
||||||
parent: RigidBodySet::invalid_handle(),
|
|
||||||
contact_graph_index: ColliderGraphIndex::new(crate::INVALID_U32),
|
|
||||||
proximity_graph_index: ColliderGraphIndex::new(crate::INVALID_U32),
|
|
||||||
proxy_index: crate::INVALID_USIZE,
|
|
||||||
..*self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Collider {
|
impl Collider {
|
||||||
|
pub(crate) fn reset_internal_links(&mut self) {
|
||||||
|
self.parent = RigidBodySet::invalid_handle();
|
||||||
|
self.contact_graph_index = ColliderGraphIndex::new(crate::INVALID_U32);
|
||||||
|
self.proximity_graph_index = ColliderGraphIndex::new(crate::INVALID_U32);
|
||||||
|
self.proxy_index = crate::INVALID_USIZE;
|
||||||
|
}
|
||||||
|
|
||||||
/// The rigid body this collider is attached to.
|
/// The rigid body this collider is attached to.
|
||||||
pub fn parent(&self) -> RigidBodyHandle {
|
pub fn parent(&self) -> RigidBodyHandle {
|
||||||
self.parent
|
self.parent
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ impl ColliderSet {
|
|||||||
parent_handle: RigidBodyHandle,
|
parent_handle: RigidBodyHandle,
|
||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
) -> ColliderHandle {
|
) -> ColliderHandle {
|
||||||
|
// Make sure the internal links are reset, they may not be
|
||||||
|
// if this rigid-body was obtained by cloning another one.
|
||||||
|
coll.reset_internal_links();
|
||||||
|
|
||||||
coll.parent = parent_handle;
|
coll.parent = parent_handle;
|
||||||
let parent = bodies
|
let parent = bodies
|
||||||
.get_mut_internal(parent_handle)
|
.get_mut_internal(parent_handle)
|
||||||
|
|||||||
Reference in New Issue
Block a user