Module: SFML::Sensor
- Defined in:
- lib/sfml/window/sensor.rb
Overview
Mobile-platform inertial / environment sensors. SFML treats every device the same way: identify the sensor by symbol, ask if it’s available, enable it before reading, then poll a Vector3 value whose components depend on the sensor type (e.g. acceleration in m/s² for ‘:accelerometer`, angular velocity in deg/s for `:gyroscope`, magnetic field in µT for `:magnetometer`).
if SFML::Sensor.available?(:accelerometer)
SFML::Sensor.enable(:accelerometer)
gravity = SFML::Sensor.value(:accelerometer)
end
On desktop platforms without sensor hardware, ‘available?` returns `false` and `value` returns the zero vector — calls don’t raise.
Sensor data also surfaces through the event loop as ‘:sensor_changed, sensor: :accelerometer, value: Vector3`.
Constant Summary collapse
- TYPES =
C::Window::SENSOR_TYPES
- TYPE_INDEX =
TYPES.each_with_index.to_h.freeze
Class Method Summary collapse
Class Method Details
.available?(type) ⇒ Boolean
25 26 27 |
# File 'lib/sfml/window/sensor.rb', line 25 def available?(type) C::Window.sfSensor_isAvailable(_index(type)) end |
.disable(type) ⇒ Object
33 34 35 |
# File 'lib/sfml/window/sensor.rb', line 33 def disable(type) C::Window.sfSensor_setEnabled(_index(type), false) end |