1 /* 2 * Copyright (C) 2006 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.graphics; 18 19 /** 20 * A camera instance can be used to compute 3D transformations and 21 * generate a matrix that can be applied, for instance, on a 22 * {@link Canvas}. 23 */ 24 @android.ravenwood.annotation.RavenwoodKeepWholeClass 25 public class Camera { 26 /** 27 * Creates a new camera, with empty transformations. 28 */ Camera()29 public Camera() { 30 nativeConstructor(); 31 } 32 33 /** 34 * Saves the camera state. Each save should be balanced 35 * with a call to {@link #restore()}. 36 * 37 * @see #save() 38 */ save()39 public native void save(); 40 41 /** 42 * Restores the saved state, if any. 43 * 44 * @see #restore() 45 */ restore()46 public native void restore(); 47 48 /** 49 * Applies a translation transform on all three axis. 50 * 51 * @param x The distance to translate by on the X axis 52 * @param y The distance to translate by on the Y axis 53 * @param z The distance to translate by on the Z axis 54 */ translate(float x, float y, float z)55 public native void translate(float x, float y, float z); 56 57 /** 58 * Applies a rotation transform around the X axis. 59 * 60 * @param deg The angle of rotation around the X axis, in degrees 61 * 62 * @see #rotateY(float) 63 * @see #rotateZ(float) 64 * @see #rotate(float, float, float) 65 */ rotateX(float deg)66 public native void rotateX(float deg); 67 68 /** 69 * Applies a rotation transform around the Y axis. 70 * 71 * @param deg The angle of rotation around the Y axis, in degrees 72 * 73 * @see #rotateX(float) 74 * @see #rotateZ(float) 75 * @see #rotate(float, float, float) 76 */ rotateY(float deg)77 public native void rotateY(float deg); 78 79 /** 80 * Applies a rotation transform around the Z axis. 81 * 82 * @param deg The angle of rotation around the Z axis, in degrees 83 * 84 * @see #rotateX(float) 85 * @see #rotateY(float) 86 * @see #rotate(float, float, float) 87 */ rotateZ(float deg)88 public native void rotateZ(float deg); 89 90 /** 91 * Applies a rotation transform around all three axis. 92 * 93 * @param x The angle of rotation around the X axis, in degrees 94 * @param y The angle of rotation around the Y axis, in degrees 95 * @param z The angle of rotation around the Z axis, in degrees 96 * 97 * @see #rotateX(float) 98 * @see #rotateY(float) 99 * @see #rotateZ(float) 100 */ rotate(float x, float y, float z)101 public native void rotate(float x, float y, float z); 102 103 /** 104 * Gets the x location of the camera. 105 * 106 * @see #setLocation(float, float, float) 107 */ getLocationX()108 public native float getLocationX(); 109 110 /** 111 * Gets the y location of the camera. 112 * 113 * @see #setLocation(float, float, float) 114 */ getLocationY()115 public native float getLocationY(); 116 117 /** 118 * Gets the z location of the camera. 119 * 120 * @see #setLocation(float, float, float) 121 */ getLocationZ()122 public native float getLocationZ(); 123 124 /** 125 * Sets the location of the camera. The default location is set at 126 * 0, 0, -8. 127 * 128 * @param x The x location of the camera 129 * @param y The y location of the camera 130 * @param z The z location of the camera 131 */ setLocation(float x, float y, float z)132 public native void setLocation(float x, float y, float z); 133 134 /** 135 * Computes the matrix corresponding to the current transformation 136 * and copies it to the supplied matrix object. 137 * 138 * @param matrix The matrix to copy the current transforms into 139 */ getMatrix(Matrix matrix)140 public void getMatrix(Matrix matrix) { 141 nativeGetMatrix(matrix.ni()); 142 } 143 144 /** 145 * Computes the matrix corresponding to the current transformation 146 * and applies it to the specified Canvas. 147 * 148 * @param canvas The Canvas to set the transform matrix onto 149 */ applyToCanvas(Canvas canvas)150 public void applyToCanvas(Canvas canvas) { 151 nativeApplyToCanvas(canvas.getNativeCanvasWrapper()); 152 } 153 dotWithNormal(float dx, float dy, float dz)154 public native float dotWithNormal(float dx, float dy, float dz); 155 finalize()156 protected void finalize() throws Throwable { 157 try { 158 nativeDestructor(); 159 native_instance = 0; 160 } finally { 161 super.finalize(); 162 } 163 } 164 nativeConstructor()165 private native void nativeConstructor(); nativeDestructor()166 private native void nativeDestructor(); nativeGetMatrix(long native_matrix)167 private native void nativeGetMatrix(long native_matrix); nativeApplyToCanvas(long native_canvas)168 private native void nativeApplyToCanvas(long native_canvas); 169 170 private long native_instance; 171 } 172