Jason Sams | 2a1cc8f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | package com.android.rollo; |
| 19 | |
| 20 | import java.io.Writer; |
| 21 | import java.lang.Math; |
| 22 | |
| 23 | import android.renderscript.RenderScript; |
| 24 | |
| 25 | |
| 26 | class RolloMesh { |
Jason Sams | 56bc1af | 2009-06-16 17:49:58 -0700 | [diff] [blame^] | 27 | 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 Sams | 2a1cc8f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 32 | |
| 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 Sams | 56bc1af | 2009-06-16 17:49:58 -0700 | [diff] [blame^] | 39 | float w = mCardWidth / 2; |
| 40 | float h = mCardHeight; |
| 41 | float z = 0; |
Jason Sams | 2a1cc8f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 42 | |
Jason Sams | 56bc1af | 2009-06-16 17:49:58 -0700 | [diff] [blame^] | 43 | 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 Sams | 2a1cc8f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 48 | 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 Sams | 56bc1af | 2009-06-16 17:49:58 -0700 | [diff] [blame^] | 59 | |
| 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 Sams | 2a1cc8f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 76 | rs.triangleMeshBegin(vtx, idx); |
Jason Sams | 56bc1af | 2009-06-16 17:49:58 -0700 | [diff] [blame^] | 77 | 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 Sams | 2a1cc8f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 81 | rs.triangleMeshAddTriangle(0,1,2); |
| 82 | rs.triangleMeshAddTriangle(0,2,3); |
| 83 | return rs.triangleMeshCreate(); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | |
| 88 | } |
| 89 | |
| 90 | |