• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 package com.example.android.rs.vr.engine;
17 
18 import java.text.*;
19 import java.util.Arrays;
20 
21 public class Cube extends TriData {
22 
23     private float[] mTrim = {0, 0, 0, 0, 0, 0 };
24 
Cube(Volume v, float delta)25     public Cube(Volume v, float delta) {
26         this(v, delta, new float[]{0, 0, 0, 0, 0, 0});
27     }
28 
Cube(Volume v, float delta, float[] trim)29     public Cube(Volume v, float delta, float[] trim) {
30         this();
31         this.mTrim = trim;
32         float minx = delta + trim[0] * (v.mDimx - delta);
33         float miny = delta + trim[1] * (v.mDimy - delta);
34         float minz = delta + trim[2] * (v.mDimz - delta);
35         float maxx = v.mDimx - delta - trim[3] * (v.mDimx - delta);
36         float maxy = v.mDimy - delta - trim[4] * (v.mDimy - delta);
37         float maxz = v.mDimz - delta - trim[5] * (v.mDimz - delta);
38         mVert = new float[]{
39                 minx, miny, minz,
40                 maxx, miny, minz,
41                 maxx, maxy, minz,
42                 minx, maxy, minz,
43                 minx, miny, maxz,
44                 maxx, miny, maxz,
45                 maxx, maxy, maxz,
46                 minx, maxy, maxz,
47         };
48     }
49 
clone(Cube src)50     public void clone(Cube src) {
51         System.arraycopy(src.mTrim, 0, mTrim, 0, mTrim.length);
52         mVert = Arrays.copyOf(src.mVert, src.mVert.length);
53         mIndex = Arrays.copyOf(src.mIndex, src.mIndex.length);
54     }
55 
getTrim()56     public float[] getTrim() {
57         return mTrim;
58     }
59 
60     @Override
toString()61     public String toString() {
62         return "CUBE[" + fs(mVert, 0, 3) + "][" + fs(mVert, 18, 3) + "]";
63     }
64 
fs(float[] f, int off, int n)65     private static String fs(float[] f, int off, int n) {
66         DecimalFormat df = new DecimalFormat("##0.000");
67         String ret = "";
68         for (int i = off; i < off + n; i++) {
69             String s = "       " + df.format(f[i]);
70 
71             if (i != off) {
72                 ret += ",";
73             }
74             ret += s.substring(s.length() - 8);
75 
76         }
77         return ret;
78     }
79 
Cube()80     public Cube() {
81         mVert = new float[]{
82                 -1.f, -1.f, -1.f,
83                 1.f, -1.f, -1.f,
84                 1.f, 1.f, -1.f,
85                 -1.f, 1.f, -1.f,
86                 -1.f, -1.f, 1.f,
87                 1.f, -1.f, 1.f,
88                 1.f, 1.f, 1.f,
89                 -1.f, 1.f, 1.f,
90         };
91 
92         mIndex = new int[]{
93                 2, 1, 0,
94                 0, 3, 2,
95                 7, 4, 5,
96                 5, 6, 7,
97                 1, 2, 6,
98                 6, 5, 1,
99                 4, 7, 3,
100                 3, 0, 4,
101                 2, 3, 7,
102                 7, 6, 2,
103                 0, 1, 5,
104                 5, 4, 0
105         };
106         for (int i = 0; i < mIndex.length; i++) {
107             mIndex[i] *= 3;
108         }
109     }
110 }
111