• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.modelviewer;
18 
19 import java.io.Writer;
20 import java.util.Map;
21 import java.util.Vector;
22 
23 import android.content.res.Resources;
24 import android.renderscript.*;
25 import android.renderscript.Element.Builder;
26 import android.renderscript.ProgramStore.DepthFunc;
27 import android.util.Log;
28 
29 enum TransformType {
30 
31     NONE(0),
32     TRANSLATE(1),
33     ROTATE(2),
34     SCALE(3);
35 
36     int mID;
TransformType(int id)37     TransformType(int id) {
38         mID = id;
39     }
40 }
41 
42 public class SgTransform {
43 
44 
45     ScriptField_SgTransform mTransformField;
46     ScriptField_SgTransform mChildField;
47     public ScriptField_SgTransform.Item mTransformData;
48 
49     RenderScript mRS;
50 
51     Vector mChildren;
52     SgTransform mParent;
53     int mIndexInParentGroup;
54 
setParent(SgTransform parent, int parentIndex)55     public void setParent(SgTransform parent, int parentIndex) {
56         mParent = parent;
57         mIndexInParentGroup = parentIndex;
58     }
59 
addChild(SgTransform child)60     public void addChild(SgTransform child) {
61         mChildren.add(child);
62         child.setParent(this, mChildren.size() - 1);
63     }
64 
setTransform(int index, Float4 value, TransformType type)65     public void setTransform(int index, Float4 value, TransformType type) {
66         mTransformData.transforms[index] = value;
67         mTransformData.transformTypes[index] = type.mID;
68     }
69 
initData()70     void initData() {
71         int numElements = mTransformData.transforms.length;
72         mTransformData.transformTypes = new int[numElements];
73         for (int i = 0; i < numElements; i ++) {
74             mTransformData.transforms[i] = new Float4(0, 0, 0, 0);
75             mTransformData.transformTypes[i] = TransformType.NONE.mID;
76         }
77 
78         mTransformData.isDirty = 1;
79         mTransformData.children = null;
80     }
81 
SgTransform(RenderScript rs)82     public SgTransform(RenderScript rs) {
83         mRS = rs;
84         mTransformData = new ScriptField_SgTransform.Item();
85         mChildren = new Vector();
86         initData();
87     }
88 
getData()89     public ScriptField_SgTransform.Item getData() {
90         if (mChildren.size() != 0) {
91             mChildField = new ScriptField_SgTransform(mRS, mChildren.size());
92             mTransformData.children = mChildField.getAllocation();
93 
94             for (int i = 0; i < mChildren.size(); i ++) {
95                 SgTransform child = (SgTransform)mChildren.get(i);
96                 mChildField.set(child.getData(), i, false);
97             }
98             mChildField.copyAll();
99         }
100 
101         return mTransformData;
102     }
103 
getField()104     public ScriptField_SgTransform getField() {
105         mTransformField = new ScriptField_SgTransform(mRS, 1);
106         mTransformField.set(getData(), 0, true);
107         return mTransformField;
108     }
109 }
110 
111 
112 
113