AR Session screen rotation adaptation
This article introduces how to configure AR Session when running WeChat Mini Programs in landscape mode.
Before you begin
- Understand what the rotation angle of the camera image relative to the screen orientation is through AR-driven 3D rendering.
- Learn about the concepts and workflow of AR Session.
Screen orientation enumeration in the Mega Mini Program plugin
Note
Refer to the official definitions of iOS, Android, and other systems for the definition of mobile screen orientation.
Screen orientation enumeration in the Mega Mini Program plugin DeviceOrientation:
| Constant | Value | Description |
|---|---|---|
Portrait |
0 | Portrait |
LandscapeLeft |
90 | LandscapeLeft |
PortraitUpsideDown |
180 | PortraitUpsideDown |
LandscapeRight |
270 | LandscapeRight |
Modify screen orientation in the WeChat Mini Program global configuration
Add the window configuration in app.json. For specific definitions, see Responding to display area changes.
"window": {
"pageOrientation": "landscape"
}
Fill in "portrait" (portrait mode) or "landscape" (landscape mode) based on actual requirements.
Caution
Never use "auto" in AR Mini Program applications, as it may cause severe AR display anomalies in certain cases.
Set screen orientation
Call setDeviceOrientation(deviceOrientation) and pass the screen rotation direction. It can be called at any time and takes effect immediately.
For example, to use in landscape mode with the screen rotated 90 degrees counterclockwise relative to the natural vertical position:
let deviceOrientation = mega.DeviceOrientation.LandscapeLeft;
session.setDeviceOrientation(deviceOrientation);
The screen orientation setting provided by the Mega plugin is to compensate for the lack of screen orientation monitoring in WeChat Mini Programs. WeChat only offers two options, portrait and landscape, in the pageOrientation setting, which are insufficient for AR applications. For example, a landscape mode rotated 90 degrees counterclockwise from the natural orientation is entirely different from one rotated 270 degrees counterclockwise.
Therefore, when pageOrientation in app.json is set to portrait, you may omit calling setDeviceOrientation(deviceOrientation), as the natural vertical orientation of most phones is the default orientation for the session.
When pageOrientation in app.json is set to landscape, you must call setDeviceOrientation(deviceOrientation) to fix the screen orientation to LandscapeLeft or LandscapeRight.