|
|
|||
File indexing completed on 2026-06-02 08:58:15
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_SENSOR_HPP 0026 #define SFML_SENSOR_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Window/Export.hpp> 0032 #include <SFML/System/Vector3.hpp> 0033 #include <SFML/System/Time.hpp> 0034 0035 0036 namespace sf 0037 { 0038 //////////////////////////////////////////////////////////// 0039 /// \brief Give access to the real-time state of the sensors 0040 /// 0041 //////////////////////////////////////////////////////////// 0042 class SFML_WINDOW_API Sensor 0043 { 0044 public: 0045 0046 //////////////////////////////////////////////////////////// 0047 /// \brief Sensor type 0048 /// 0049 //////////////////////////////////////////////////////////// 0050 enum Type 0051 { 0052 Accelerometer, //!< Measures the raw acceleration (m/s^2) 0053 Gyroscope, //!< Measures the raw rotation rates (degrees/s) 0054 Magnetometer, //!< Measures the ambient magnetic field (micro-teslas) 0055 Gravity, //!< Measures the direction and intensity of gravity, independent of device acceleration (m/s^2) 0056 UserAcceleration, //!< Measures the direction and intensity of device acceleration, independent of the gravity (m/s^2) 0057 Orientation, //!< Measures the absolute 3D orientation (degrees) 0058 0059 Count //!< Keep last -- the total number of sensor types 0060 }; 0061 0062 //////////////////////////////////////////////////////////// 0063 /// \brief Check if a sensor is available on the underlying platform 0064 /// 0065 /// \param sensor Sensor to check 0066 /// 0067 /// \return True if the sensor is available, false otherwise 0068 /// 0069 //////////////////////////////////////////////////////////// 0070 static bool isAvailable(Type sensor); 0071 0072 //////////////////////////////////////////////////////////// 0073 /// \brief Enable or disable a sensor 0074 /// 0075 /// All sensors are disabled by default, to avoid consuming too 0076 /// much battery power. Once a sensor is enabled, it starts 0077 /// sending events of the corresponding type. 0078 /// 0079 /// This function does nothing if the sensor is unavailable. 0080 /// 0081 /// \param sensor Sensor to enable 0082 /// \param enabled True to enable, false to disable 0083 /// 0084 //////////////////////////////////////////////////////////// 0085 static void setEnabled(Type sensor, bool enabled); 0086 0087 //////////////////////////////////////////////////////////// 0088 /// \brief Get the current sensor value 0089 /// 0090 /// \param sensor Sensor to read 0091 /// 0092 /// \return The current sensor value 0093 /// 0094 //////////////////////////////////////////////////////////// 0095 static Vector3f getValue(Type sensor); 0096 }; 0097 0098 } // namespace sf 0099 0100 0101 #endif // SFML_SENSOR_HPP 0102 0103 0104 //////////////////////////////////////////////////////////// 0105 /// \class sf::Sensor 0106 /// \ingroup window 0107 /// 0108 /// sf::Sensor provides an interface to the state of the 0109 /// various sensors that a device provides. It only contains static 0110 /// functions, so it's not meant to be instantiated. 0111 /// 0112 /// This class allows users to query the sensors values at any 0113 /// time and directly, without having to deal with a window and 0114 /// its events. Compared to the SensorChanged event, sf::Sensor 0115 /// can retrieve the state of a sensor at any time (you don't need to 0116 /// store and update its current value on your side). 0117 /// 0118 /// Depending on the OS and hardware of the device (phone, tablet, ...), 0119 /// some sensor types may not be available. You should always check 0120 /// the availability of a sensor before trying to read it, with the 0121 /// sf::Sensor::isAvailable function. 0122 /// 0123 /// You may wonder why some sensor types look so similar, for example 0124 /// Accelerometer and Gravity / UserAcceleration. The first one 0125 /// is the raw measurement of the acceleration, and takes into account 0126 /// both the earth gravity and the user movement. The others are 0127 /// more precise: they provide these components separately, which is 0128 /// usually more useful. In fact they are not direct sensors, they 0129 /// are computed internally based on the raw acceleration and other sensors. 0130 /// This is exactly the same for Gyroscope vs Orientation. 0131 /// 0132 /// Because sensors consume a non-negligible amount of current, they are 0133 /// all disabled by default. You must call sf::Sensor::setEnabled for each 0134 /// sensor in which you are interested. 0135 /// 0136 /// Usage example: 0137 /// \code 0138 /// if (sf::Sensor::isAvailable(sf::Sensor::Gravity)) 0139 /// { 0140 /// // gravity sensor is available 0141 /// } 0142 /// 0143 /// // enable the gravity sensor 0144 /// sf::Sensor::setEnabled(sf::Sensor::Gravity, true); 0145 /// 0146 /// // get the current value of gravity 0147 /// sf::Vector3f gravity = sf::Sensor::getValue(sf::Sensor::Gravity); 0148 /// \endcode 0149 /// 0150 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|