1 // Copyright (C) 2009 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma version(1) 16 17 #pragma rs java_package_name(com.android.modelviewer) 18 19 #include "rs_graphics.rsh" 20 #include "transform_def.rsh" 21 22 rs_program_vertex gPVBackground; 23 rs_program_fragment gPFBackground; 24 25 rs_allocation gTGrid; 26 rs_mesh gTestMesh; 27 28 rs_program_store gPFSBackground; 29 30 float gRotate; 31 32 rs_font gItalic; 33 rs_allocation gTextAlloc; 34 35 rs_script gTransformRS; 36 37 SgTransform *gGroup; 38 SgTransform *gRobot1; 39 int gRobot1Index; 40 SgTransform *gRobot2; 41 int gRobot2Index; 42 43 SgTransform *gRootNode; 44 45 void init() { 46 gRotate = 0.0f; 47 } 48 49 int root(void) { 50 51 gGroup->transforms[1].w += 0.5f; 52 gGroup->isDirty = 1; 53 54 SgTransform *robot1Ptr = gRobot1 + gRobot1Index; 55 56 robot1Ptr->transforms[1].w -= 1.5f; 57 robot1Ptr->isDirty = 1; 58 59 SgTransform *robot2Ptr = gRobot2 + gRobot2Index; 60 robot2Ptr->transforms[1].w += 2.5f; 61 robot2Ptr->isDirty = 1; 62 63 rsForEach(gTransformRS, gRootNode->children, gRootNode->children); 64 65 rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f); 66 rsgClearDepth(1.0f); 67 68 rsgBindProgramVertex(gPVBackground); 69 rs_matrix4x4 proj; 70 float aspect = (float)rsgGetWidth() / (float)rsgGetHeight(); 71 rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f); 72 rsgProgramVertexLoadProjectionMatrix(&proj); 73 74 rsgBindProgramFragment(gPFBackground); 75 rsgBindProgramStore(gPFSBackground); 76 rsgBindTexture(gPFBackground, 0, gTGrid); 77 78 rsgProgramVertexLoadModelMatrix(&robot1Ptr->globalMat); 79 rsgDrawMesh(gTestMesh); 80 81 rsgProgramVertexLoadModelMatrix(&robot2Ptr->globalMat); 82 rsgDrawMesh(gTestMesh); 83 84 //color(0.3f, 0.3f, 0.3f, 1.0f); 85 rsgDrawText("Renderscript transform test", 30, 695); 86 87 rsgBindFont(gItalic); 88 rsgDrawText(gTextAlloc, 30, 730); 89 90 return 10; 91 } 92