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
{type: :sensor_changed, sensor: :accelerometer, value: Vector3}.
Constant Summary collapse
- TYPES =
Recognised type symbols.
C::Window::SENSOR_TYPES
- TYPE_INDEX =
Type symbol → integer index Hash.
TYPES.each_with_index.to_h.freeze
Class Method Summary collapse
-
.available?(type) ⇒ Boolean
trueif available. -
.disable(type) ⇒ Object
Returns the disable.
-
.enable(type) ⇒ Object
Returns the enable.
-
.value(type) ⇒ Object
Returns the value.
Class Method Details
.available?(type) ⇒ Boolean
true if available.
28 29 30 |
# File 'lib/sfml/window/sensor.rb', line 28 def available?(type) C::Window.sfSensor_isAvailable(_index(type)) end |
.disable(type) ⇒ Object
Returns the disable.
38 39 40 |
# File 'lib/sfml/window/sensor.rb', line 38 def disable(type) C::Window.sfSensor_setEnabled(_index(type), false) end |