Skip to content

Commit 5f88496

Browse files
ap4123IgnisRBX
andauthored
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]>
1 parent 149bdb3 commit 5f88496

File tree

3 files changed

+87
-34
lines changed

3 files changed

+87
-34
lines changed
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

content/en-us/reference/engine/classes/Camera.yaml

Lines changed: 81 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ properties:
238238
viewport to its opposite corner) the camera can view. See
239239
`Class.Camera.FieldOfView|FieldOfView` for a more general explanation of
240240
field of view.
241+
242+
Note that `DiagonalFieldOfView` represents the field of view that is
243+
visible by the `Class.Camera` rendering into the fullscreen area which
244+
may be occluded by notches or screen cutouts on some devices. See `Class.
245+
Camera.ViewportSize|ViewportSize` for more information.
241246
code_samples:
242247
type: float
243248
tags:
@@ -271,6 +276,11 @@ properties:
271276
using binoculars.
272277
- Increasing FOV when the player is "sprinting" to give the impression of
273278
a lack of control.
279+
280+
Note that `FieldOfView` represents the field of view that is visible by
281+
the `Class.Camera` rendering into the fullscreen area which may be
282+
occluded by notches or screen cutouts on some devices. See `Class.Camera.
283+
ViewportSize|ViewportSize` for more information.
274284
code_samples:
275285
type: float
276286
tags: []
@@ -534,15 +544,36 @@ properties:
534544
writeCapabilities: []
535545
- name: Camera.ViewportSize
536546
summary: |
537-
Describes the dimensions, in pixels, of the client's viewport.
547+
The dimensions of the device safe area on a Roblox client.
538548
description: |
539-
**ViewportSize** describes the dimensions, in pixels, of the client's
540-
viewport.
541-
542-
This property ignores the GUI inset applied by the top bar, meaning the
543-
center of the screen can be found at precisely at 50% of the viewport in
544-
both directions. You can find the position of a `Datatype.Vector3` in the
545-
world on the viewport using `Class.Camera:WorldToViewportPoint()`.
549+
`Class.Camera.ViewportSize|ViewportSize` returns the dimensions of the
550+
device safe area on the current screen. This area is a rectangle which
551+
includes the Roblox top bar area but does not include any device notches
552+
or screen cutouts. The units of `Class.Camera.ViewportSize|ViewportSize` are Roblox
553+
UI offset units which may be different from native display pixels.
554+
555+
<img src="../../../assets/engine-api/classes/Camera/DeviceSafeAreaVsFullscreen.png" width="840" alt="Mobile device screen with cutout showing device safe area." />
556+
557+
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`.
546577
code_samples:
547578
type: Vector2
548579
tags:
@@ -1158,26 +1189,45 @@ methods:
11581189
summary: |
11591190
Creates a unit `Datatype.Ray` from a position on the viewport (in pixels),
11601191
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.
11621193
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
11731212
`Class.Camera:ScreenPointToRay()`.
11741213
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+
11751222
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
11771224
the screen, for example:
11781225
11791226
```lua
1180-
local camera = workspace.CurrentCamera
1227+
local Workspace = game:GetService("Workspace")
1228+
1229+
local camera = Workspace.CurrentCamera
1230+
11811231
local viewportPoint = camera.ViewportSize / 2
11821232
local unitRay = camera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y, 0)
11831233
```
@@ -1186,33 +1236,30 @@ methods:
11861236
create a longer ray, you can do the following:
11871237
11881238
```lua
1189-
local camera = workspace.CurrentCamera
1239+
local Workspace = game:GetService("Workspace")
1240+
1241+
local camera = Workspace.CurrentCamera
1242+
11901243
local length = 500
11911244
local unitRay = camera:ScreenPointToRay(100, 100)
11921245
local extendedRay = Ray.new(unitRay.Origin, unitRay.Direction * length)
11931246
```
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`.
12001247
code_samples:
12011248
parameters:
12021249
- name: x
12031250
type: float
12041251
default:
12051252
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.
12091256
- name: 'y'
12101257
type: float
12111258
default:
12121259
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
1262+
coordinates.
12161263
- name: depth
12171264
type: float
12181265
default: 0

0 commit comments

Comments
 (0)