blob: 36790686fecac156e19227f248b37474eecfc277 [file] [log] [blame]
Alex Sakhartchouk094a0682010-08-13 10:44:14 -07001// 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
Alex Sakhartchouk27f50522010-08-18 15:46:43 -070017#pragma rs java_package_name(com.android.modelviewer)
Alex Sakhartchouk094a0682010-08-13 10:44:14 -070018
19#include "rs_graphics.rsh"
20#include "transform_def.rsh"
21
22rs_program_vertex gPVBackground;
23rs_program_fragment gPFBackground;
24
25rs_allocation gTGrid;
26rs_mesh gTestMesh;
27
28rs_program_store gPFSBackground;
29
30float gRotate;
31
32rs_font gItalic;
33rs_allocation gTextAlloc;
34
35rs_script gTransformRS;
36
37SgTransform *gGroup;
38SgTransform *gRobot1;
39int gRobot1Index;
40SgTransform *gRobot2;
41int gRobot2Index;
42
43SgTransform *gRootNode;
44
Alex Sakhartchouk094a0682010-08-13 10:44:14 -070045void init() {
46 gRotate = 0.0f;
47}
48
49int root(int launchID) {
50
Alex Sakhartchouk9e401bc2010-10-13 14:22:02 -070051 gGroup->transforms[1].w += 0.5f;
Alex Sakhartchouk094a0682010-08-13 10:44:14 -070052 gGroup->isDirty = 1;
53
54 SgTransform *robot1Ptr = gRobot1 + gRobot1Index;
55
Alex Sakhartchouk9e401bc2010-10-13 14:22:02 -070056 robot1Ptr->transforms[1].w -= 1.5f;
Alex Sakhartchouk094a0682010-08-13 10:44:14 -070057 robot1Ptr->isDirty = 1;
58
59 SgTransform *robot2Ptr = gRobot2 + gRobot2Index;
Alex Sakhartchouk9e401bc2010-10-13 14:22:02 -070060 robot2Ptr->transforms[1].w += 2.5f;
Alex Sakhartchouk094a0682010-08-13 10:44:14 -070061 robot2Ptr->isDirty = 1;
62
63 rsForEach(gTransformRS, gRootNode->children, gRootNode->children, 0);
64
65 rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
66 rsgClearDepth(1.0f);
67
68 rsgBindProgramVertex(gPVBackground);
Alex Sakhartchoukdb6f11b2010-09-07 12:10:18 -070069 rs_matrix4x4 proj;
70 float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
71 rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f);
72 rsgProgramVertexLoadProjectionMatrix(&proj);
Alex Sakhartchouk094a0682010-08-13 10:44:14 -070073
74 rsgBindProgramFragment(gPFBackground);
75 rsgBindProgramStore(gPFSBackground);
76 rsgBindTexture(gPFBackground, 0, gTGrid);
77
Jason Sams1d45c472010-08-25 14:31:48 -070078 rsgProgramVertexLoadModelMatrix(&robot1Ptr->globalMat);
Alex Sakhartchouk094a0682010-08-13 10:44:14 -070079 rsgDrawMesh(gTestMesh);
80
Jason Sams1d45c472010-08-25 14:31:48 -070081 rsgProgramVertexLoadModelMatrix(&robot2Ptr->globalMat);
Alex Sakhartchouk094a0682010-08-13 10:44:14 -070082 rsgDrawMesh(gTestMesh);
83
Jason Sams62f258f2011-01-28 15:49:07 -080084 //color(0.3f, 0.3f, 0.3f, 1.0f);
Alex Sakhartchouk094a0682010-08-13 10:44:14 -070085 rsgDrawText("Renderscript transform test", 30, 695);
86
87 rsgBindFont(gItalic);
88 rsgDrawText(gTextAlloc, 30, 730);
89
90 return 10;
91}