You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update Camera.ViewportSize with behavior for notched devices (#898)
## Changes
Currently Camera.ViewportSize, FieldOfView, and DiagonalFieldOfView do
not mention changes that were made to support notched devices. I updated
these properties to describe the new behaviors.
## Checks
By submitting your pull request for review, you agree to the following:
- [x] This contribution was created in whole or in part by me, and I
have the right to submit it under the terms of this repository's open
source licenses.
- [x] I understand and agree that this contribution and a record of it
are public, maintained indefinitely, and may be redistributed under the
terms of this repository's open source licenses.
- [x] To the best of my knowledge, all proposed changes are accurate.
---------
Co-authored-by: IgnisRBX <[email protected]>
As noted above, `Class.Camera.ViewportSize|ViewportSize` is not equal to the fullscreen
558
+
area size on displays with cutouts or
559
+
notches. To obtain the fullscreen area size on all displays, you can query the
560
+
`Class.ScreenGui.AbsoluteSize|AbsoluteSize` property of a `Class.ScreenGui` with
561
+
`Class.ScreenGui.ScreenInsets|ScreenInsets` set to `Enum.ScreenInsets.None|None`. See
562
+
`Enum.ScreenInsets` for a more information about how screen areas are defined.
563
+
564
+
Finally, note that `Class.Camera.ViewportSize|ViewportSize` is not the actual viewport size
565
+
the camera uses for rendering (the camera renders in the fullscreen area). Also, the
566
+
`Class.Camera.FieldOfView` and `Class.Camera.DiagonalFieldOfView` properties are
567
+
based on the fullscreen area, not `Class.Camera.ViewportSize|ViewportSize`.
568
+
569
+
##### Camera Updates
570
+
571
+
Only the `Class.Camera` currently referred to by `Class.Workspace.
572
+
CurrentCamera` has its `Class.Camera.ViewportSize|ViewportSize` updated each
573
+
frame during the `Class.RunService.PreRender|PreRender` step. The
574
+
`Class.Camera.ViewportSize|ViewportSize` of all other cameras in your
575
+
experience won't be updated, including those used for
576
+
`Class.ViewportFrame|ViewportFrames`.
546
577
code_samples:
547
578
type: Vector2
548
579
tags:
@@ -1158,26 +1189,45 @@ methods:
1158
1189
summary: |
1159
1190
Creates a unit `Datatype.Ray` from a position on the viewport (in pixels),
1160
1191
at a given depth from the `Class.Camera`, orientated in the camera's
1161
-
direction. Does not account for the GUI inset.
1192
+
direction. Does not account for the `Enum.ScreenInsets|CoreUISafeInsets` inset.
1162
1193
description: |
1163
-
This function creates a unit `Datatype.Ray` from a 2D position on the
1164
-
viewport (defined in pixels). This position does **not** account for the
1165
-
GUI inset. The `Datatype.Ray` originates from the `Datatype.Vector3`
1166
-
equivalent of the 2D position in the world at the given depth (in studs)
1167
-
away from the `Class.Camera`.
1168
-
1169
-
As this function does not acknowledge the GUI inset, the viewport position
1170
-
given is not equivalent to the screen position used by GUI elements. If
1171
-
you are not using `Class.ScreenGui.IgnoreGuiInset` and need an otherwise
1172
-
identical function that accounts for the GUI offset, use
1194
+
This function creates a unit `Datatype.Ray` from a 2D position in device
1195
+
safe viewport coordinates, defined in pixels. The ray originates from the
1196
+
`Datatype.Vector3` equivalent of the 2D position in the world at the
1197
+
given depth (in studs) away from the `Class.Camera`.
1198
+
1199
+
As illustrated below, `(0, 0)` corresponds to the top‑left point of the Roblox
1200
+
top bar. This means that the input 2D position does **not** account for the
1201
+
`Enum.ScreenInsets|CoreUISafeInsets` inset, but it does account for any
1202
+
`Enum.ScreenInsets|DeviceSafeInsets`.
1203
+
1204
+
<img src="../../../assets/engine-api/classes/Camera/ViewportPointToRayOrigin.png" width="840" alt="Diagram showing the origin of the device safe area viewport coordinate system." />
1205
+
1206
+
Note that UI instances use a different coordinate system
1207
+
(`Class.GuiObject.AbsolutePosition` uses the
1208
+
`Enum.ScreenInsets|CoreUISafeInsets` viewport coordinate system
1209
+
while this function uses the `Enum.ScreenInsets|DeviceSafeInsets`
1210
+
viewport coordinate system). If you
1211
+
would like to specify position in core UI coordinates, please use
1173
1212
`Class.Camera:ScreenPointToRay()`.
1174
1213
1214
+
Also note that this function only works for the `Class.Workspace.
1215
+
CurrentCamera` camera.
1216
+
Other cameras, such as those you create for a `Class.ViewportFrame`, have
1217
+
an initial viewport size of `(1, 1)` and are only updated after you set
1218
+
them to `Class.Workspace.CurrentCamera|CurrentCamera`. The mismatch in
1219
+
viewport size causes the camera to return a ray with an incorrect
1220
+
`Datatype.Ray.Direction`.
1221
+
1175
1222
This function can be used in conjunction with the
1176
-
`Class.Camera.ViewportSize` property to create a ray from the centre of
1223
+
`Class.Camera.ViewportSize|ViewportSize` property to create a ray from the centre of
1177
1224
the screen, for example:
1178
1225
1179
1226
```lua
1180
-
local camera = workspace.CurrentCamera
1227
+
local Workspace = game:GetService("Workspace")
1228
+
1229
+
local camera = Workspace.CurrentCamera
1230
+
1181
1231
local viewportPoint = camera.ViewportSize / 2
1182
1232
local unitRay = camera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y, 0)
1183
1233
```
@@ -1186,33 +1236,30 @@ methods:
1186
1236
create a longer ray, you can do the following:
1187
1237
1188
1238
```lua
1189
-
local camera = workspace.CurrentCamera
1239
+
local Workspace = game:GetService("Workspace")
1240
+
1241
+
local camera = Workspace.CurrentCamera
1242
+
1190
1243
local length = 500
1191
1244
local unitRay = camera:ScreenPointToRay(100, 100)
1192
1245
local extendedRay = Ray.new(unitRay.Origin, unitRay.Direction * length)
1193
1246
```
1194
-
1195
-
This function only works for the current Workspace camera. Other cameras,
1196
-
such as those you create for a `Class.ViewportFrame`, have an initial
1197
-
viewport size of `(1, 1)` and are only updated after you set them to
1198
-
`Class.Workspace.CurrentCamera`. The mismatch in viewport size causes the
1199
-
camera to return a ray with an incorrect `Datatype.Ray.Direction`.
1200
1247
code_samples:
1201
1248
parameters:
1202
1249
- name: x
1203
1250
type: float
1204
1251
default:
1205
1252
summary: |
1206
-
The position on the X axis, in pixels, of the viewport point at which
1207
-
to originate the `Datatype.Ray`. This position does not account for
1208
-
the GUI inset.
1253
+
The position on the **X** axis, in pixels, of the viewport point at
1254
+
which to originate the `Datatype.Ray`, in device safe area
1255
+
coordinates.
1209
1256
- name: 'y'
1210
1257
type: float
1211
1258
default:
1212
1259
summary: |
1213
-
The position on the Y axis, in pixels, of the viewport point at which
1214
-
to originate the `Datatype.Ray`. This position does not account for
1215
-
the GUI inset.
1260
+
The position on the **Y** axis, in pixels, of the viewport point at
1261
+
which to originate the `Datatype.Ray`, in device safe area
0 commit comments