/
dzhanibekov3.rs
77 lines (69 loc) · 2.37 KB
/
dzhanibekov3.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
extern crate nalgebra as na;
use na::{Isometry3, Point3, RealField, Vector3};
use ncollide3d::shape::{Compound, Cuboid, ShapeHandle};
use nphysics3d::force_generator::DefaultForceGeneratorSet;
use nphysics3d::joint::DefaultJointConstraintSet;
use nphysics3d::math::Velocity;
use nphysics3d::object::{
BodyPartHandle, ColliderDesc, DefaultBodySet, DefaultColliderSet, RigidBodyDesc,
};
use nphysics3d::world::{DefaultGeometricalWorld, DefaultMechanicalWorld};
use nphysics_testbed3d::Testbed;
/*
* NOTE: The `r` macro is only here to convert from f64 to the `N` scalar type.
* This simplifies experimentation with various scalar types (f32, fixed-point numbers, etc.)
*/
pub fn init_world<N: RealField>(testbed: &mut Testbed<N>) {
/*
* World
*/
let mechanical_world = DefaultMechanicalWorld::new(Vector3::zeros());
let geometrical_world = DefaultGeometricalWorld::new();
let mut bodies = DefaultBodySet::new();
let mut colliders = DefaultColliderSet::new();
let joint_constraints = DefaultJointConstraintSet::new();
let force_generators = DefaultForceGeneratorSet::new();
/*
* Create boxes to compute the inertia.
*/
let mut shapes = Vec::new();
shapes.push((
Isometry3::identity(),
ShapeHandle::new(Cuboid::new(Vector3::new(r!(1.0), r!(0.1), r!(0.1)))),
));
shapes.push((
Isometry3::translation(r!(0.0), r!(0.4), r!(0.0)),
ShapeHandle::new(Cuboid::new(Vector3::new(r!(0.1), r!(0.2), r!(0.1)))),
));
/*
* Create the rigid body.
*/
let rb = RigidBodyDesc::new()
.velocity(Velocity::angular(r!(0.0), r!(10.0), r!(0.1)))
.build();
let rb_handle = bodies.insert(rb);
/*
* Create the collider from which the inertia will be automatically computed.
*/
let geom = ShapeHandle::new(Compound::new(shapes));
let co = ColliderDesc::new(geom)
.density(r!(1.0))
.build(BodyPartHandle(rb_handle, 0));
colliders.insert(co);
/*
* Set up the testbed.
*/
testbed.set_world(
mechanical_world,
geometrical_world,
bodies,
colliders,
joint_constraints,
force_generators,
);
testbed.look_at(Point3::new(0.0, 0.0, 5.0), Point3::new(0.0, 0.0, 0.0));
}
fn main() {
let testbed = Testbed::<f32>::from_builders(0, vec![("Dzhanibekov effect", init_world)]);
testbed.run()
}