1 /* 2 * Copyright (C) 2011 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 com.android.scenegraph; 18 19 import java.lang.Math; 20 import java.util.ArrayList; 21 22 import com.android.scenegraph.SceneManager; 23 24 import android.renderscript.*; 25 import android.renderscript.Matrix4f; 26 import android.renderscript.RenderScriptGL; 27 import android.util.Log; 28 29 /** 30 * @hide 31 */ 32 public class Camera extends SceneGraphBase { 33 34 Transform mTransform; 35 36 ScriptField_Camera_s.Item mData; 37 ScriptField_Camera_s mField; 38 Camera()39 public Camera() { 40 mData = new ScriptField_Camera_s.Item(); 41 mData.near = 0.1f; 42 mData.far = 1000.0f; 43 mData.horizontalFOV = 60.0f; 44 mData.aspect = 0; 45 } 46 setTransform(Transform t)47 public void setTransform(Transform t) { 48 mTransform = t; 49 if (mField != null) { 50 mField.set_transformMatrix(0, mTransform.getRSData().getAllocation(), true); 51 mField.set_isDirty(0, 1, true); 52 } 53 } setFOV(float fov)54 public void setFOV(float fov) { 55 mData.horizontalFOV = fov; 56 if (mField != null) { 57 mField.set_horizontalFOV(0, fov, true); 58 mField.set_isDirty(0, 1, true); 59 } 60 } 61 setNear(float n)62 public void setNear(float n) { 63 mData.near = n; 64 if (mField != null) { 65 mField.set_near(0, n, true); 66 mField.set_isDirty(0, 1, true); 67 } 68 } 69 setFar(float f)70 public void setFar(float f) { 71 mData.far = f; 72 if (mField != null) { 73 mField.set_far(0, f, true); 74 mField.set_isDirty(0, 1, true); 75 } 76 } 77 setName(String n)78 public void setName(String n) { 79 super.setName(n); 80 if (mField != null) { 81 RenderScriptGL rs = SceneManager.getRS(); 82 mData.name = getNameAlloc(rs); 83 mField.set_name(0, mData.name, true); 84 mField.set_isDirty(0, 1, true); 85 } 86 } 87 getRSData()88 ScriptField_Camera_s getRSData() { 89 if (mField != null) { 90 return mField; 91 } 92 93 RenderScriptGL rs = SceneManager.getRS(); 94 if (rs == null) { 95 return null; 96 } 97 98 if (mTransform == null) { 99 throw new RuntimeException("Cameras without transforms are invalid"); 100 } 101 102 mField = new ScriptField_Camera_s(rs, 1); 103 104 mData.transformMatrix = mTransform.getRSData().getAllocation(); 105 mData.transformTimestamp = 1; 106 mData.timestamp = 1; 107 mData.isDirty = 1; 108 mData.name = getNameAlloc(rs); 109 mField.set(mData, 0, true); 110 111 return mField; 112 } 113 } 114 115 116 117 118 119