Home | History | Annotate | Download | only in fountain
      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.fountain_v11;
     18 
     19 import android.content.res.Resources;
     20 import android.renderscript.*;
     21 import android.util.Log;
     22 
     23 
     24 public class FountainRS {
     25     public static final int PART_COUNT = 50000;
     26 
     27     public FountainRS() {
     28     }
     29 
     30     private Resources mRes;
     31     private RenderScriptGL mRS;
     32     private ScriptC_fountain mScript;
     33     public void init(RenderScriptGL rs, Resources res, int width, int height) {
     34         mRS = rs;
     35         mRes = res;
     36 
     37         ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder(rs);
     38         pfb.setVaryingColor(true);
     39         rs.bindProgramFragment(pfb.create());
     40 
     41         ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT);//
     42  //                                                        Allocation.USAGE_GRAPHICS_VERTEX);
     43 
     44         Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS);
     45         smb.addVertexAllocation(points.getAllocation());
     46         smb.addIndexSetType(Mesh.Primitive.POINT);
     47         Mesh sm = smb.create();
     48 
     49         mScript = new ScriptC_fountain(mRS, mRes, R.raw.fountain);
     50         mScript.set_partMesh(sm);
     51         mScript.bind_point(points);
     52         mRS.bindRootScript(mScript);
     53     }
     54 
     55     boolean holdingColor[] = new boolean[10];
     56     public void newTouchPosition(float x, float y, float pressure, int id) {
     57         if (id >= holdingColor.length) {
     58             return;
     59         }
     60         int rate = (int)(pressure * pressure * 500.f);
     61         if (rate > 500) {
     62             rate = 500;
     63         }
     64         if (rate > 0) {
     65             mScript.invoke_addParticles(rate, x, y, id, !holdingColor[id]);
     66             holdingColor[id] = true;
     67         } else {
     68             holdingColor[id] = false;
     69         }
     70 
     71     }
     72 }
     73