pub struct MouseButtonState { /* private fields */ }Expand description
Represents the different possible states of a mouse button
Implementations§
Source§impl MouseButtonState
impl MouseButtonState
Sourcepub fn was_triggered(&self) -> bool
pub fn was_triggered(&self) -> bool
is true when the button goes from an “unpressed” to a “pressed” state.
Examples found in repository?
examples/add_planar_reflection.rs (line 124)
5fn main() -> BulletResult<()> {
6 let mut client = PhysicsClient::connect(Mode::Gui)?;
7 client
8 .set_default_search_path()?
9 .set_physics_engine_parameter(&PhysicsEngineParametersUpdate {
10 num_solver_iterations: Some(10),
11 ..Default::default()
12 })?
13 .set_time_step(Duration::from_secs_f64(1. / 120.))?;
14
15 let log_id = client.start_state_logging(
16 LoggingType::ProfileTimings,
17 "visualShapeBench.json",
18 Default::default(),
19 )?;
20
21 let plane = client.load_urdf(
22 "plane_transparent.urdf",
23 Some(UrdfOptions {
24 use_maximal_coordinates: Some(true),
25 ..Default::default()
26 }),
27 )?;
28
29 client
30 .configure_debug_visualizer(&DebugVisualizerOptions::Flag(
31 DebugVisualizerFlag::CovEnableRendering,
32 false,
33 ))?
34 .configure_debug_visualizer(&DebugVisualizerOptions::Flag(
35 DebugVisualizerFlag::CovEnablePlanarReflection,
36 true,
37 ))?
38 .configure_debug_visualizer(&DebugVisualizerOptions::Flag(
39 DebugVisualizerFlag::CovEnableGui,
40 false,
41 ))?
42 .configure_debug_visualizer(&DebugVisualizerOptions::Flag(
43 DebugVisualizerFlag::CovEnableTinyRenderer,
44 false,
45 ))?;
46
47 let shift = [0., -0.02, 0.];
48 let mesh_scale = [0.1, 0.1, 0.1];
49
50 let visual_shape = client.create_visual_shape(
51 VisualGeometry::Mesh {
52 file: "duck.obj",
53 scale: mesh_scale,
54 },
55 VisualShapeOptions {
56 transform: shift.into(),
57 rgba: [1., 1., 1., 1.],
58 specular: [0.4, 0.4, 0.],
59 flags: None,
60 },
61 )?;
62 let collision_shape = client.create_collision_shape(
63 CollisionGeometry::Mesh {
64 file: "duck_vhacd.obj",
65 scale: mesh_scale,
66 },
67 CollisionShapeOptions {
68 transform: shift.into(),
69 flags: None,
70 },
71 )?;
72
73 let range_x = 3;
74 let range_y = 3;
75
76 for i in 0..range_x {
77 for j in 0..range_y {
78 client.create_multi_body(&MultiBodyCreateOptions {
79 base: MultiBodyBase {
80 mass: 1.,
81 collision_shape,
82 visual_shape,
83 pose: na::Isometry3::translation(
84 ((-range_x as f64 / 2.) + i as f64) * mesh_scale[0] * 2.,
85 ((-range_y as f64 / 2.) + j as f64) * mesh_scale[1] * 2.,
86 1.,
87 ),
88 inertial_pose: na::Isometry3::identity(),
89 },
90 use_maximal_coordinates: true,
91 ..Default::default()
92 })?;
93 }
94 }
95
96 client
97 .configure_debug_visualizer(&DebugVisualizerOptions::Flag(
98 DebugVisualizerFlag::CovEnableRendering,
99 true,
100 ))?
101 .stop_state_logging(log_id)?
102 .set_gravity([0., 0., -9.81])?
103 .set_real_time_simulation(true)?;
104
105 let colors = [
106 [1., 0., 0., 1.],
107 [0., 1., 0., 1.],
108 [0., 0., 1., 1.],
109 [1., 1., 1., 1.],
110 ];
111 let mut current_color = 0;
112
113 loop {
114 let mouse_events = client.get_mouse_events()?;
115 for event in mouse_events {
116 match event {
117 MouseEvent::Move { .. } => {}
118 MouseEvent::Button {
119 mouse_x,
120 mouse_y,
121 button_index,
122 button_state,
123 } => {
124 if button_state.was_triggered() && button_index == 0 {
125 eprintln!("Mouse click at ({}, {})", mouse_x, mouse_y);
126 let (ray_from, ray_to) = get_ray_from_to(
127 client.get_debug_visualizer_camera()?,
128 mouse_x,
129 mouse_y,
130 );
131 eprintln!("Ray from: {:?}, Ray to: {:?}", ray_from, ray_to);
132 let ray_info = client.ray_test(ray_from, ray_to, None, None)?;
133 eprintln!("{:?}", ray_info);
134 for ray in ray_info {
135 if ray.object_unique_id != plane {
136 client.change_visual_shape(
137 ray.object_unique_id,
138 ray.link_index,
139 -1,
140 &ChangeVisualShapeOptions {
141 rgba_color: Some(colors[current_color]),
142 ..Default::default()
143 },
144 )?;
145 current_color = (current_color + 1) % colors.len()
146 }
147 }
148 eprintln!("aaa")
149 }
150 }
151 }
152 }
153 if !client.is_connected() {
154 return Ok(());
155 }
156 }
157}Sourcepub fn is_pressed(&self) -> bool
pub fn is_pressed(&self) -> bool
is true when the button is in a “pressed” state.
Sourcepub fn is_released(&self) -> bool
pub fn is_released(&self) -> bool
is true when the button goes from a “pressed” to an “unpressed” state.
Trait Implementations§
Source§impl Clone for MouseButtonState
impl Clone for MouseButtonState
Source§fn clone(&self) -> MouseButtonState
fn clone(&self) -> MouseButtonState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MouseButtonState
impl Debug for MouseButtonState
impl Copy for MouseButtonState
Auto Trait Implementations§
impl Freeze for MouseButtonState
impl RefUnwindSafe for MouseButtonState
impl Send for MouseButtonState
impl Sync for MouseButtonState
impl Unpin for MouseButtonState
impl UnwindSafe for MouseButtonState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.