blob: d7252fbb40ff035e8d88b4e1a180b8b0e8cb4d2f [file] [log] [blame]
Jason Sams2a1cc8f2009-06-15 19:04:56 -07001 /*
2 * Copyright (C) 2009 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
18package com.android.rollo;
19
20import java.io.Writer;
21import java.lang.Math;
22
23import android.renderscript.RenderScript;
24
25
26class RolloMesh {
Jason Sams56bc1af2009-06-16 17:49:58 -070027 static public final float mCardHeight = 1.2f;
28 static public final float mCardWidth = 1.8f;
29 static public final float mTabHeight = 0.2f;
30 static public final float mTabs = 3;
31 static public final float mTabGap = 0.1f;
Jason Sams2a1cc8f2009-06-15 19:04:56 -070032
33 static RenderScript.TriangleMesh createCard(RenderScript rs) {
34 RenderScript.Element vtx = rs.elementGetPredefined(
35 RenderScript.ElementPredefined.ST_XYZ_F32);
36 RenderScript.Element idx = rs.elementGetPredefined(
37 RenderScript.ElementPredefined.INDEX_16);
38
Jason Sams56bc1af2009-06-16 17:49:58 -070039 float w = mCardWidth / 2;
40 float h = mCardHeight;
41 float z = 0;
Jason Sams2a1cc8f2009-06-15 19:04:56 -070042
Jason Sams56bc1af2009-06-16 17:49:58 -070043 rs.triangleMeshBegin(vtx, idx);
44 rs.triangleMeshAddVertex_XYZ_ST(-w, 0, z, 0, 0);
45 rs.triangleMeshAddVertex_XYZ_ST(-w, h, z, 0, 1);
46 rs.triangleMeshAddVertex_XYZ_ST( w, h, z, 1, 1);
47 rs.triangleMeshAddVertex_XYZ_ST( w, 0, z, 1, 0);
Jason Sams2a1cc8f2009-06-15 19:04:56 -070048 rs.triangleMeshAddTriangle(0,1,2);
49 rs.triangleMeshAddTriangle(0,2,3);
50 return rs.triangleMeshCreate();
51 }
52
53 static RenderScript.TriangleMesh createTab(RenderScript rs) {
54 RenderScript.Element vtx = rs.elementGetPredefined(
55 RenderScript.ElementPredefined.ST_XYZ_F32);
56 RenderScript.Element idx = rs.elementGetPredefined(
57 RenderScript.ElementPredefined.INDEX_16);
58
Jason Sams56bc1af2009-06-16 17:49:58 -070059
60 float tabSlope = 0.1f;
61 float num = 0;
62
63 float w = (mCardWidth - ((mTabs - 1) * mTabGap)) / mTabs;
64 float w1 = -(mCardWidth / 2) + ((w + mTabGap) * num);
65 float w2 = w1 + (w * tabSlope);
66 float w3 = w1 + w - (w * tabSlope);
67 float w4 = w1 + w;
68 float h1 = mCardHeight;
69 float h2 = h1 + mTabHeight;
70 float z = 0;
71
72 float stScale = w / mTabHeight / 2;
73 float stScale2 = stScale * (tabSlope / w);
74
75
Jason Sams2a1cc8f2009-06-15 19:04:56 -070076 rs.triangleMeshBegin(vtx, idx);
Jason Sams56bc1af2009-06-16 17:49:58 -070077 rs.triangleMeshAddVertex_XYZ_ST(w1, h1, z, -stScale, 0);
78 rs.triangleMeshAddVertex_XYZ_ST(w2, h2, z, -stScale2, 1);
79 rs.triangleMeshAddVertex_XYZ_ST(w3, h2, z, stScale2, 1);
80 rs.triangleMeshAddVertex_XYZ_ST(w4, h1, z, stScale, 0);
Jason Sams2a1cc8f2009-06-15 19:04:56 -070081 rs.triangleMeshAddTriangle(0,1,2);
82 rs.triangleMeshAddTriangle(0,2,3);
83 return rs.triangleMeshCreate();
84 }
85
86
87
88}
89
90