Showing the changes to interface/src/scripting/HMDScriptingInterface.h (1 of 3 files). Show all
Unified · Split
| @@ -24,6 +24,36 @@ class QScriptEngine; · 23 unmodified lines | ||
| 24 | 24 | |
| 25 | 25 | #include <QReadWriteLock> |
| 26 | 26 | |
| 27 | +/**jsdoc | |
| 28 | + * The HMD API provides access to the HMD used in VR display mode. | |
| 29 | + * | |
| 30 | + * @namespace HMD | |
| 31 | + * @property {Vec3} position - The position of the HMD if currently in VR display mode, otherwise | |
| 32 | + * {@link Vec3(0)|Vec3.ZERO}. <em>Read-only.</em> | |
| 33 | + * @property {Quat} orientation - The orientation of the HMD if currently in VR display mode, otherwise | |
| 34 | + * {@link Quat(0)|Quat.IDENTITY}.<em>Read-only.</em> | |
| 35 | + * @property {boolean} active - <code>true</code> if the display mode is HMD, otherwise <code>false</code>. <em>Read-only.</em> | |
| 36 | + * @property {boolean} mounted - <code>true</code> if currently in VR display mode and the HMD is being worn, otherwise | |
| 37 | + * <code>false</code>. <em>Read-only.</em> | |
| 38 | + * | |
| 39 | + * @property {number} playerHeight - The real-world height of the user. <em>Read-only.</em> <em>Currently always returns a | |
| 40 | + * value of <code>1.755</code>.</em> | |
| 41 | + * @property {number} eyeHeight - The real-world height of the user's eyes. <em>Read-only.</em> <em>Currently always returns a | |
| 42 | + * value of <code>1.655</code>.</em> | |
| 43 | + * @property {number} ipd - The inter-pupillary distance (distance between eyes) of the user, used for rendering. Defaults to | |
| 44 | + * the human average of <code>0.064</code> unless set by the HMD. <em>Read-only.</em> | |
| 45 | + * @property {number} ipdScale=1.0 - A scale factor applied to the <code>ipd</code> property value. | |
| 46 | + * | |
| 47 | + * @property {boolean} showTablet - <code>true</code> if the tablet is being displayed, <code>false</code> otherwise. | |
| 48 | + * <em>Read-only.</em> | |
| 49 | + * @property {boolean} tabletContextualMode - <code>true</code> if the tablet has been opened in contextual mode, otherwise | |
| 50 | + * <code>false</code>. In contextual mode, the tablet has been opened at a specific world position and orientation rather | |
| 51 | + * than at a position and orientation relative to the user. <em>Read-only.</em> | |
| 52 | + * @property {Uuid} tabletID - The UUID of the tablet body model overlay. | |
| 53 | + * @property {Uuid} tabletScreenID - The UUID of the tablet's screen overlay. | |
| 54 | + * @property {Uuid} homeButtonID - The UUID of the tablet's "home" button overlay. | |
| 55 | + * @property {Uuid} homeButtonHighlightID - The UUID of the tablet's "home" button highlight overlay. | |
| 56 | + */ | |
| 27 | 57 | class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Dependency { |
| 28 | 58 | Q_OBJECT |
| 29 | 59 | Q_PROPERTY(glm::vec3 position READ getPosition) |
| @@ -37,26 +67,200 @@ class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Depen · 7 unmodified lines | ||
| 37 | 67 | Q_PROPERTY(QUuid tabletScreenID READ getCurrentTabletScreenID WRITE setCurrentTabletScreenID) |
| 38 | 68 | |
| 39 | 69 | public: |
| 70 | + | |
| 71 | + /**jsdoc | |
| 72 | + * Calculate the intersection of a ray with the HUD overlay. | |
| 73 | + * @function HMD.calculateRayUICollisionPoint | |
| 74 | + * @param {Vec3} position - The origin of the ray. | |
| 75 | + * @param {Vec3} direction - The direction of the ray. | |
| 76 | + * @returns {Vec3} The point of intersection with the HUD overlay if it intersects, otherwise {@link Vec3(0)|Vec3.ZERO}. | |
| 77 | + */ | |
| 40 | 78 | Q_INVOKABLE glm::vec3 calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction) const; |
| 79 | + | |
| 80 | + /**jsdoc | |
| 81 | + * Get the 2D HUD overlay coordinates of a 3D point on the HUD overlay. | |
| 82 | + * 2D HUD overlay coordinates are pixels with the origin at the top left of the overlay. | |
| 83 | + * @function HMD.overlayFromWorldPoint | |
| 84 | + * @param {Vec3} position - The point on the HUD overlay in world coordinates. | |
| 85 | + * @returns {Vec2} The point on the HUD overlay in HUD coordinates. | |
| 86 | + * @example <caption>Draw a square on the HUD overlay in the direction you're looking.</caption> | |
| 87 | + * var hudIntersection = HMD.calculateRayUICollisionPoint(MyAvatar.getHeadPosition(), | |
| 88 | + * Quat.getForward(MyAvatar.headOrientation)); | |
| 89 | + * var hudPoint = HMD.overlayFromWorldPoint(hudIntersection); | |
| 90 | + * | |
| 91 | + * var DIMENSIONS = { x: 50, y: 50 }; | |
| 92 | + * var square = Overlays.addOverlay("rectangle", { | |
| 93 | + * x: hudPoint.x - DIMENSIONS.x / 2, | |
| 94 | + * y: hudPoint.y - DIMENSIONS.y / 2, | |
| 95 | + * width: DIMENSIONS.x, | |
| 96 | + * height: DIMENSIONS.y, | |
| 97 | + * color: { red: 255, green: 0, blue: 0 } | |
| 98 | + * }); | |
| 99 | + * | |
| 100 | + * Script.scriptEnding.connect(function () { | |
| 101 | + * Overlays.deleteOverlay(square); | |
| 102 | + * }); | |
| 103 | + */ | |
| 41 | 104 | Q_INVOKABLE glm::vec2 overlayFromWorldPoint(const glm::vec3& position) const; |
| 105 | + | |
| 106 | + /**jsdoc | |
| 107 | + * Get the 3D world coordinates of a 2D point on the HUD overlay. | |
| 108 | + * 2D HUD overlay coordinates are pixels with the origin at the top left of the overlay. | |
| 109 | + * @function HMD.worldPointFromOverlay | |
| 110 | + * @param {Vec2} coordinates - The point on the HUD overlay in HUD coordinates. | |
| 111 | + * @returns {Vec3} The point on the HUD overlay in world coordinates. | |
| 112 | + */ | |
| 42 | 113 | Q_INVOKABLE glm::vec3 worldPointFromOverlay(const glm::vec2& overlay) const; |
| 114 | + | |
| 115 | + /**jsdoc | |
| 116 | + * Get the 2D point on the HUD overlay represented by given spherical coordinates. | |
| 117 | + * 2D HUD overlay coordinates are pixels with the origin at the top left of the overlay. | |
| 118 | + * Spherical coordinates are polar coordinates in radians with <code>{ x: 0, y: 0 }</code> being the center of the HUD | |
| 119 | + * overlay. | |
| 120 | + * @function HMD.sphericalToOverlay | |
| 121 | + * @param {Vec2} sphericalPos - The point on the HUD overlay in spherical coordinates. | |
| 122 | + * @returns {Vec2} The point on the HUD overlay in HUD coordinates. | |
| 123 | + */ | |
| 43 | 124 | Q_INVOKABLE glm::vec2 sphericalToOverlay(const glm::vec2 & sphericalPos) const; |
| 125 | + | |
| 126 | + /**jsdoc | |
| 127 | + * Get the spherical coordinates of a 2D point on the HUD overlay. | |
| 128 | + * 2D HUD overlay coordinates are pixels with the origin at the top left of the overlay. | |
| 129 | + * Spherical coordinates are polar coordinates in radians with <code>{ x: 0, y: 0 }</code> being the center of the HUD | |
| 130 | + * overlay. | |
| 131 | + * @function HMD.overlayToSpherical | |
| 132 | + * @param {Vec2} overlayPos - The point on the HUD overlay in HUD coordinates. | |
| 133 | + * @returns {Vec2} The point on the HUD overlay in spherical coordinates. | |
| 134 | + */ | |
| 44 | 135 | Q_INVOKABLE glm::vec2 overlayToSpherical(const glm::vec2 & overlayPos) const; |
| 136 | + | |
| 137 | + /**jsdoc | |
| 138 | + * Recenter the HMD HUD to the current HMD position and orientation. | |
| 139 | + * @function HMD.centerUI | |
| 140 | + */ | |
| 141 | + Q_INVOKABLE void centerUI(); | |
| 142 | + | |
| 143 | + | |
| 144 | + /**jsdoc | |
| 145 | + * Get the name of the HMD audio input device. | |
| 146 | + * @function HMD.preferredAudioInput | |
| 147 | + * @returns {string} The name of the HMD audio input device if in HMD mode, otherwise an empty string. | |
| 148 | + */ | |
| 45 | 149 | Q_INVOKABLE QString preferredAudioInput() const; |
| 150 | + | |
| 151 | + /**jsdoc | |
| 152 | + * Get the name of the HMD audio output device. | |
| 153 | + * @function HMD.preferredAudioOutput | |
| 154 | + * @returns {string} The name of the HMD audio output device if in HMD mode, otherwise an empty string. | |
| 155 | + */ | |
| 46 | 156 | Q_INVOKABLE QString preferredAudioOutput() const; |
| 47 | 157 | |
| 158 | + | |
| 159 | + /**jsdoc | |
| 160 | + * Check whether there is an HMD available. | |
| 161 | + * @function HMD.isHMDAvailable | |
| 162 | + * @param {string} [name=""] - The name of the HMD to check for, e.g., <code>"Oculus Rift"</code>. The name is the same as | |
| 163 | + * may be displayed in Interface's "Display" menu. If no name is specified then any HMD matches. | |
| 164 | + * @returns {boolean} <code>true</code> if an HMD of the specified <code>name</code> is available, otherwise | |
| 165 | + * <code>false</code>. | |
| 166 | + * @example <caption>Report on HMD availability.</caption> | |
| 167 | + * print("Is any HMD available: " + HMD.isHMDAvailable()); | |
| 168 | + * print("Is an Oculus Rift HMD available: " + HMD.isHMDAvailable("Oculus Rift")); | |
| 169 | + * print("Is a Vive HMD available: " + HMD.isHMDAvailable("OpenVR (Vive)")); | |
| 170 | + */ | |
| 48 | 171 | Q_INVOKABLE bool isHMDAvailable(const QString& name = ""); |
| 172 | + | |
| 173 | + /**jsdoc | |
| 174 | + * Check whether there is an HMD head controller available. | |
| 175 | + * @function HMD.isHeadControllerAvailable | |
| 176 | + * @param {string} [name=""] - The name of the HMD head controller to check for, e.g., <code>"Oculus"</code>. If no name is | |
| 177 | + * specified then any HMD head controller matches. | |
| 178 | + * @returns {boolean} <code>true</code> if an HMD head controller of the specified <code>name</code> is available, | |
| 179 | + * otherwise <code>false</code>. | |
| 180 | + * @example <caption>Report HMD head controller availability.</caption> | |
| 181 | + * print("Is any HMD head controller available: " + HMD.isHeadControllerAvailable()); | |
| 182 | + * print("Is an Oculus head controller available: " + HMD.isHeadControllerAvailable("Oculus")); | |
| 183 | + * print("Is a Vive head controller available: " + HMD.isHeadControllerAvailable("OpenVR")); | |
| 184 | + */ | |
| 49 | 185 | Q_INVOKABLE bool isHeadControllerAvailable(const QString& name = ""); |
| 186 | + | |
| 187 | + /**jsdoc | |
| 188 | + * Check whether there are HMD hand controllers available. | |
| 189 | + * @function HMD.isHandControllerAvailable | |
| 190 | + * @param {string} [name=""] - The name of the HMD hand controller to check for, e.g., <code>"Oculus"</code>. If no name is | |
| 191 | + * specified then any HMD hand controller matches. | |
| 192 | + * @returns {boolean} <code>true</code> if an HMD hand controller of the specified <code>name</code> is available, | |
| 193 | + * otherwise <code>false</code>. | |
| 194 | + * @example <caption>Report HMD hand controller availability.</caption> | |
| 195 | + * print("Are any HMD hand controllers available: " + HMD.isHandControllerAvailable()); | |
| 196 | + * print("Are Oculus hand controllers available: " + HMD.isHandControllerAvailable("Oculus")); | |
| 197 | + * print("Are Vive hand controllers available: " + HMD.isHandControllerAvailable("OpenVR")); | |
| 198 | + */ | |
| 50 | 199 | Q_INVOKABLE bool isHandControllerAvailable(const QString& name = ""); |
| 200 | + | |
| 201 | + /**jsdoc | |
| 202 | + * Check whether there are specific HMD controllers available. | |
| 203 | + * @function HMD.isSubdeviceContainingNameAvailable | |
| 204 | + * @param {string} - The name of the HMD controller to check for, e.g., <code>"OculusTouch"</code>. | |
| 205 | + * @returns {boolean} <code>true</code> if an HMD controller with a name containing the specified <code>name</code> is | |
| 206 | + * available, otherwise <code>false</code>. | |
| 207 | + * @example <caption>Report if particular Oculus controllers are available.</caption> | |
| 208 | + * print("Is an Oculus Touch controller available: " + HMD.isSubdeviceContainingNameAvailable("Touch")); | |
| 209 | + * print("Is an Oculus Remote controller available: " + HMD.isSubdeviceContainingNameAvailable("Remote")); | |
| 210 | + */ | |
| 51 | 211 | Q_INVOKABLE bool isSubdeviceContainingNameAvailable(const QString& name); |
| 52 | 212 | |
| 213 | + /**jsdoc | |
| 214 | + * Signal that models of the HMD hand controllers being used should be displayed. The models are displayed at their actual, | |
| 215 | + * real-world locations. | |
| 216 | + * @function HMD.requestShowHandControllers | |
| 217 | + * @example <caption>Show your hand controllers for 10 seconds.</caption> | |
| 218 | + * HMD.requestShowHandControllers(); | |
| 219 | + * Script.setTimeout(function () { | |
| 220 | + * HMD.requestHideHandControllers(); | |
| 221 | + * }, 10000); | |
| 222 | + */ | |
| 53 | 223 | Q_INVOKABLE void requestShowHandControllers(); |
| 224 | + | |
| 225 | + /**jsdoc | |
| 226 | + * Signal that it is no longer necessary to display models of the HMD hand controllers being used. If no other scripts | |
| 227 | + * want the models displayed then they are no longer displayed. | |
| 228 | + * @function HMD.requestHideHandControllers | |
| 229 | + */ | |
| 54 | 230 | Q_INVOKABLE void requestHideHandControllers(); |
| 231 | + | |
| 232 | + /**jsdoc | |
| 233 | + * Check whether any script wants models of the HMD hand controllers displayed. Requests are made and canceled using | |
| 234 | + * {@link HMD.requestShowHandControllers|requestShowHandControllers} and | |
| 235 | + * {@link HMD.requestHideHandControllers|requestHideHandControllers}. | |
| 236 | + * @function HMD.shouldShowHandControllers | |
| 237 | + * @returns {boolean} <code>true</code> if any script is requesting that HMD hand controller models be displayed. | |
| 238 | + */ | |
| 55 | 239 | Q_INVOKABLE bool shouldShowHandControllers() const; |
| 56 | 240 | |
| 241 | + | |
| 242 | + /**jsdoc | |
| 243 | + * Causes the borders and decorations in HUD windows to be enlarged when the laser intersects them in HMD mode. By default, | |
| 244 | + * borders and decorations are not enlarged. | |
| 245 | + * @function HMD.activateHMDHandMouse | |
| 246 | + */ | |
| 57 | 247 | Q_INVOKABLE void activateHMDHandMouse(); |
| 248 | + | |
| 249 | + /**jsdoc | |
| 250 | + * Causes the border and decorations in HUD windows to no longer be enlarged when the laser intersects them in HMD mode. By | |
| 251 | + * default, borders and decorations are not enlarged. | |
| 252 | + * @function HMD.deactivateHMDHandMouse | |
| 253 | + */ | |
| 58 | 254 | Q_INVOKABLE void deactivateHMDHandMouse(); |
| 59 | 255 | |
| 256 | + | |
| 257 | + /**jsdoc | |
| 258 | + * Suppress the activation of the HMD-provided keyboard, if any. Successful calls should be balanced with a call to | |
| 259 | + * {@link HMD.unspressKeyboard|unspressKeyboard} within a reasonable amount of time. | |
| 260 | + * @function HMD.suppressKeyboard | |
| 261 | + * @returns {boolean} <code>true</code> if the current HMD provides a keyboard and it was successfully suppressed (e.g., it | |
| 262 | + * isn't being displayed), otherwise <code>false</code>. | |
| 263 | + */ | |
| 60 | 264 | /// Suppress the activation of any on-screen keyboard so that a script operation will |
| 61 | 265 | /// not be interrupted by a keyboard popup |
| 62 | 266 | /// Returns false if there is already an active keyboard displayed. |
| @@ -65,21 +269,68 @@ public: · 2 unmodified lines | ||
| 65 | 269 | /// call to unsuppressKeyboard() within a reasonable amount of time |
| 66 | 270 | Q_INVOKABLE bool suppressKeyboard(); |
| 67 | 271 | |
| 272 | + /**jsdoc | |
| 273 | + * Unsuppress the activation of the HMD-provided keyboard, if any. | |
| 274 | + * @function HMD.unsuppressKeyboard | |
| 275 | + */ | |
| 68 | 276 | /// Enable the keyboard following a suppressKeyboard call |
| 69 | 277 | Q_INVOKABLE void unsuppressKeyboard(); |
| 70 | 278 | |
| 279 | + /**jsdoc | |
| 280 | + * Check whether the HMD-provided keyboard, if any, is visible. | |
| 281 | + * @function HMD.isKeyboardVisible | |
| 282 | + * @returns {boolean} <code>true</code> if the current HMD provides a keyboard and it is visible, otherwise | |
| 283 | + * <code>false</code>. | |
| 284 | + */ | |
| 71 | 285 | /// Query the display plugin to determine the current VR keyboard visibility |
| 72 | 286 | Q_INVOKABLE bool isKeyboardVisible(); |
| 73 | 287 | |
| 74 | − // rotate the overlay UI sphere so that it is centered about the the current HMD position and orientation | |
| 75 | − Q_INVOKABLE void centerUI(); | |
| 76 | − | |
| 288 | + /**jsdoc | |
| 289 | + * Closes the tablet if it is open. | |
| 290 | + * @function HMD.closeTablet | |
| 291 | + */ | |
| 77 | 292 | Q_INVOKABLE void closeTablet(); |
| 78 | 293 | |
| 294 | + /**jsdoc | |
| 295 | + * Opens the tablet if the tablet is used in the current display mode and it isn't already showing, and sets the tablet to | |
| 296 | + * contextual mode if requested. In contextual mode, the page displayed on the tablet is wholly controlled by script (i.e., | |
| 297 | + * the user cannot navigate to another). | |
| 298 | + * @function HMD.openTablet | |
| 299 | + * @param {boolean} [contextualMode=false] - If <code>true</code> then the tablet is opened at a specific position and | |
| 300 | + * orientation already set by the script, otherwise it opens at a position and orientation relative to the user. For | |
| 301 | + * contextual mode, set the world or local position and orientation of the <code>HMD.tabletID</code> overlay. | |
| 302 | + */ | |
| 79 | 303 | Q_INVOKABLE void openTablet(bool contextualMode = false); |
| 80 | 304 | |
| 81 | 305 | signals: |
| 306 | + /**jsdoc | |
| 307 | + * Triggered when a request to show or hide models of the HMD hand controllers is made using | |
| 308 | + * {@link HMD.requestShowHandControllers|requestShowHandControllers} or | |
| 309 | + * {@link HMD.requestHideHandControllers|requestHideHandControllers}. | |
| 310 | + * @function HMD.shouldShowHandControllersChanged | |
| 311 | + * @returns {Signal} | |
| 312 | + * @example <caption>Report when showing of hand controllers changes.</caption> | |
| 313 | + * function onShouldShowHandControllersChanged() { | |
| 314 | + * print("Should show hand controllers: " + HMD.shouldShowHandControllers()); | |
| 315 | + * } | |
| 316 | + * HMD.shouldShowHandControllersChanged.connect(onShouldShowHandControllersChanged); | |
| 317 | + * | |
| 318 | + * HMD.requestShowHandControllers(); | |
| 319 | + * Script.setTimeout(function () { | |
| 320 | + * HMD.requestHideHandControllers(); | |
| 321 | + * }, 10000); | |
| 322 | + */ | |
| 82 | 323 | bool shouldShowHandControllersChanged(); |
| 324 | + | |
| 325 | + /**jsdoc | |
| 326 | + * Triggered when the <code>HMD.mounted</code> property value changes. | |
| 327 | + * @function HMD.mountedChanged | |
| 328 | + * @returns {Signal} | |
| 329 | + * @example <caption>Report when there's a change in the HMD being worn.</caption> | |
| 330 | + * HMD.mountedChanged.connect(function () { | |
| 331 | + * print("Mounted changed. HMD is mounted: " + HMD.mounted); | |
| 332 | + * }); | |
| 333 | + */ | |
| 83 | 334 | void mountedChanged(); |
| 84 | 335 | |
| 85 | 336 | public: |