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