Debian Codegraph @

core/java/android/app/wallpapereffectsgeneration/CameraAttributes.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package android.app.wallpapereffectsgeneration;
18
19 import android.annotation.FloatRange;
20 import android.annotation.NonNull;
21 import android.annotation.Size;
22 import android.annotation.SystemApi;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25
26 /**
27 * Representing the position and other parameters of camera of a single frame.
28 *
29 * @hide
30 */
31 @SystemApi
32 public final class CameraAttributes implements Parcelable {
33 /**
34 * The location of the anchor within the 3D scene.
35 * Expecting 3 floats representing the x, y, z coordinates
36 * of the anchor point.
37 */
38 @NonNull
39 private float[] mAnchorPointInWorldSpace;
40 /**
41 * Where the anchor point should project to in the output image.
42 * Expecting 2 floats representing the u,v coordinates of the
43 * anchor point.
44 */
45 @NonNull
46 private float[] mAnchorPointInOutputUvSpace;
47 /**
48 * Specifies the amount of yaw orbit rotation the camera should perform
49 * around the anchor point in world space.
50 */
51 private float mCameraOrbitYawDegrees;
52 /**
53 * Specifies the amount of pitch orbit rotation the camera should perform
54 * around the anchor point in world space.
55 */
56 private float mCameraOrbitPitchDegrees;
57 /**
58 * Specifies by how much the camera should be placed towards the anchor
59 * point in world space, which is also called dolly distance.
60 */
61 private float mDollyDistanceInWorldSpace;
62 /**
63 * Specifies the vertical fov degrees of the virtual image.
64 */
65 private float mVerticalFovDegrees;
66 /**
67 * The frustum of near plane.
68 */
69 private float mFrustumNearInWorldSpace;
70 /**
71 * The frustum of far plane.
72 */
73 private float mFrustumFarInWorldSpace;
74
75 private CameraAttributes(Parcel in) {
76 this.mCameraOrbitYawDegrees = in.readFloat();
77 this.mCameraOrbitPitchDegrees = in.readFloat();
78 this.mDollyDistanceInWorldSpace = in.readFloat();
79 this.mVerticalFovDegrees = in.readFloat();
80 this.mFrustumNearInWorldSpace = in.readFloat();
81 this.mFrustumFarInWorldSpace = in.readFloat();
82 this.mAnchorPointInWorldSpace = in.createFloatArray();
83 this.mAnchorPointInOutputUvSpace = in.createFloatArray();
84 }
85
86 private CameraAttributes(float[] anchorPointInWorldSpace, float[] anchorPointInOutputUvSpace,
87 float cameraOrbitYawDegrees, float cameraOrbitPitchDegrees,
88 float dollyDistanceInWorldSpace,
89 float verticalFovDegrees, float frustumNearInWorldSpace, float frustumFarInWorldSpace) {
90 mAnchorPointInWorldSpace = anchorPointInWorldSpace;
91 mAnchorPointInOutputUvSpace = anchorPointInOutputUvSpace;
92 mCameraOrbitYawDegrees = cameraOrbitYawDegrees;
93 mCameraOrbitPitchDegrees = cameraOrbitPitchDegrees;
94 mDollyDistanceInWorldSpace = dollyDistanceInWorldSpace;
95 mVerticalFovDegrees = verticalFovDegrees;
96 mFrustumNearInWorldSpace = frustumNearInWorldSpace;
97 mFrustumFarInWorldSpace = frustumFarInWorldSpace;
98 }
99
100 /**
101 * Get the location of the anchor within the 3D scene. The response float array contains
102 * 3 floats representing the x, y, z coordinates
103 */
104 @NonNull
105 public float[] getAnchorPointInWorldSpace() {
106 return mAnchorPointInWorldSpace;
107 }
108
109 /**
110 * Get where the anchor point should project to in the output image. The response float
111 * array contains 2 floats representing the u,v coordinates of the anchor point.
112 */
113 @NonNull
114 public float[] getAnchorPointInOutputUvSpace() {
115 return mAnchorPointInOutputUvSpace;
116 }
117
118 /**
119 * Get the camera yaw orbit rotation.
120 */
121 @FloatRange(from = -180.0f, to = 180.0f)
122 public float getCameraOrbitYawDegrees() {
123 return mCameraOrbitYawDegrees;
124 }
125
126 /**
127 * Get the camera pitch orbit rotation.
128 */
129 @FloatRange(from = -90.0f, to = 90.0f)
130 public float getCameraOrbitPitchDegrees() {
131 return mCameraOrbitPitchDegrees;
132 }
133
134 /**
135 * Get how many units the camera should be placed towards the anchor point in world space.
136 */
137 public float getDollyDistanceInWorldSpace() {
138 return mDollyDistanceInWorldSpace;
139 }
140
141 /**
142 * Get the camera vertical fov degrees.
143 */
144 @FloatRange(from = 0.0f, to = 180.0f, fromInclusive = false)
145 public float getVerticalFovDegrees() {
146 return mVerticalFovDegrees;
147 }
148
149 /**
150 * Get the frustum in near plane.
151 */
152 @FloatRange(from = 0.0f)
153 public float getFrustumNearInWorldSpace() {
154 return mFrustumNearInWorldSpace;
155 }
156
157 /**
158 * Get the frustum in far plane.
159 */
160 @FloatRange(from = 0.0f)
161 public float getFrustumFarInWorldSpace() {
162 return mFrustumFarInWorldSpace;
163 }
164
165 @NonNull
166 public static final Creator<CameraAttributes> CREATOR = new Creator<CameraAttributes>() {
167 @Override
168 public CameraAttributes createFromParcel(Parcel in) {
169 return new CameraAttributes(in);
170 }
171
172 @Override
173 public CameraAttributes[] newArray(int size) {
174 return new CameraAttributes[size];
175 }
176 };
177
178 @Override
179 public void writeToParcel(@NonNull Parcel out, int flags) {
180 out.writeFloat(mCameraOrbitYawDegrees);
181 out.writeFloat(mCameraOrbitPitchDegrees);
182 out.writeFloat(mDollyDistanceInWorldSpace);
183 out.writeFloat(mVerticalFovDegrees);
184 out.writeFloat(mFrustumNearInWorldSpace);
185 out.writeFloat(mFrustumFarInWorldSpace);
186 out.writeFloatArray(mAnchorPointInWorldSpace);
187 out.writeFloatArray(mAnchorPointInOutputUvSpace);
188 }
189
190 @Override
191 public int describeContents() {
192 return 0;
193 }
194
195 /**
196 * Builder for {@link CameraAttributes}.
197 *
198 * @hide
199 */
200 @SystemApi
201 public static final class Builder {
202 @NonNull
203 private float[] mAnchorPointInWorldSpace;
204 @NonNull
205 private float[] mAnchorPointInOutputUvSpace;
206 private float mCameraOrbitYawDegrees;
207 private float mCameraOrbitPitchDegrees;
208 private float mDollyDistanceInWorldSpace;
209 private float mVerticalFovDegrees;
210 private float mFrustumNearInWorldSpace;
211 private float mFrustumFarInWorldSpace;
212
213 /**
214 * Constructor with anchor point in world space and anchor point in output image
215 * space.
216 *
217 * @param anchorPointInWorldSpace the location of the anchor within the 3D scene. The
218 * float array contains 3 floats representing the x, y, z coordinates.
219 * @param anchorPointInOutputUvSpace where the anchor point should project to in the
220 * output image. The float array contains 2 floats representing the u,v coordinates
221 * of the anchor point.
222 *
223 * @hide
224 */
225 @SystemApi
226 public Builder(@NonNull @Size(3) float[] anchorPointInWorldSpace,
227 @NonNull @Size(2) float[] anchorPointInOutputUvSpace) {
228 mAnchorPointInWorldSpace = anchorPointInWorldSpace;
229 mAnchorPointInOutputUvSpace = anchorPointInOutputUvSpace;
230 }
231
232 /**
233 * Sets the camera orbit yaw rotation.
234 */
235 @NonNull
236 public Builder setCameraOrbitYawDegrees(
237 @FloatRange(from = -180.0f, to = 180.0f) float cameraOrbitYawDegrees) {
238 mCameraOrbitYawDegrees = cameraOrbitYawDegrees;
239 return this;
240 }
241
242 /**
243 * Sets the camera orbit pitch rotation.
244 */
245 @NonNull
246 public Builder setCameraOrbitPitchDegrees(
247 @FloatRange(from = -90.0f, to = 90.0f) float cameraOrbitPitchDegrees) {
248 mCameraOrbitPitchDegrees = cameraOrbitPitchDegrees;
249 return this;
250 }
251
252 /**
253 * Sets the camera dolly distance.
254 */
255 @NonNull
256 public Builder setDollyDistanceInWorldSpace(float dollyDistanceInWorldSpace) {
257 mDollyDistanceInWorldSpace = dollyDistanceInWorldSpace;
258 return this;
259 }
260
261 /**
262 * Sets the camera vertical fov degree.
263 */
264 @NonNull
265 public Builder setVerticalFovDegrees(
266 @FloatRange(from = 0.0f, to = 180.0f, fromInclusive = false)
267 float verticalFovDegrees) {
268 mVerticalFovDegrees = verticalFovDegrees;
269 return this;
270 }
271
272 /**
273 * Sets the frustum in near plane.
274 */
275 @NonNull
276 public Builder setFrustumNearInWorldSpace(
277 @FloatRange(from = 0.0f) float frustumNearInWorldSpace) {
278 mFrustumNearInWorldSpace = frustumNearInWorldSpace;
279 return this;
280 }
281
282 /**
283 * Sets the frustum in far plane.
284 */
285 @NonNull
286 public Builder setFrustumFarInWorldSpace(
287 @FloatRange(from = 0.0f) float frustumFarInWorldSpace) {
288 mFrustumFarInWorldSpace = frustumFarInWorldSpace;
289 return this;
290 }
291
292 /**
293 * Builds a new {@link CameraAttributes} instance.
294 */
295 @NonNull
296 public CameraAttributes build() {
297 return new CameraAttributes(mAnchorPointInWorldSpace,
298 mAnchorPointInOutputUvSpace,
299 mCameraOrbitYawDegrees,
300 mCameraOrbitPitchDegrees,
301 mDollyDistanceInWorldSpace,
302 mVerticalFovDegrees,
303 mFrustumNearInWorldSpace,
304 mFrustumFarInWorldSpace);
305 }
306 }
307 }