Merge pull request #67 from dimforge/determinism_apple_m1
Fix cross-platform determinism on the Apple M1 processor
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use na::{DMatrix, Point3, Vector3};
|
use na::{ComplexField, DMatrix, Point3, Vector3};
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
@@ -23,7 +23,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
} else {
|
} else {
|
||||||
let x = i as f32 * ground_size.x / (nsubdivs as f32);
|
let x = i as f32 * ground_size.x / (nsubdivs as f32);
|
||||||
let z = j as f32 * ground_size.z / (nsubdivs as f32);
|
let z = j as f32 * ground_size.z / (nsubdivs as f32);
|
||||||
x.sin() + z.cos()
|
|
||||||
|
// NOTE: make sure we use the sin/cos from simba to ensure
|
||||||
|
// cross-platform determinism of the example when the
|
||||||
|
// enhanced_determinism feature is enabled.
|
||||||
|
(<f32 as ComplexField>::sin(x) + <f32 as ComplexField>::cos(z))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use na::Point3;
|
use na::{ComplexField, Point3};
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
@@ -30,7 +30,10 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
// so we switch z and y here and set a random altitude at each point.
|
// so we switch z and y here and set a random altitude at each point.
|
||||||
for p in vertices.iter_mut() {
|
for p in vertices.iter_mut() {
|
||||||
p.z = p.y;
|
p.z = p.y;
|
||||||
p.y = (p.x.sin() + p.z.cos()) * ground_height;
|
// NOTE: make sure we use the sin/cos from simba to ensure
|
||||||
|
// cross-platform determinism of the example when the
|
||||||
|
// enhanced_determinism feature is enabled.
|
||||||
|
p.y = (<f32 as ComplexField>::sin(p.x) + <f32 as ComplexField>::cos(p.z)) * ground_height;
|
||||||
|
|
||||||
if p.x.abs() == ground_size / 2.0 || p.z.abs() == ground_size / 2.0 {
|
if p.x.abs() == ground_size / 2.0 || p.z.abs() == ground_size / 2.0 {
|
||||||
p.y = 10.0;
|
p.y = 10.0;
|
||||||
|
|||||||
@@ -105,7 +105,16 @@ impl WAABB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn dilate_by_factor(&mut self, factor: SimdFloat) {
|
pub fn dilate_by_factor(&mut self, factor: SimdFloat) {
|
||||||
let dilation = (self.maxs - self.mins) * factor;
|
// If some of the AABBs on this WAABB are invalid,
|
||||||
|
// don't, dilate them.
|
||||||
|
let is_valid = self.mins.x.simd_le(self.maxs.x);
|
||||||
|
let factor = factor.select(is_valid, SimdFloat::zero());
|
||||||
|
|
||||||
|
// NOTE: we multiply each by factor instead of doing
|
||||||
|
// (maxs - mins) * factor. That's to avoid overflows (and
|
||||||
|
// therefore NaNs if this WAABB contains some invalid
|
||||||
|
// AABBs initialised with f32::MAX
|
||||||
|
let dilation = self.maxs * factor - self.mins * factor;
|
||||||
self.mins -= dilation;
|
self.mins -= dilation;
|
||||||
self.maxs += dilation;
|
self.maxs += dilation;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user