• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2011 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.scenegraph)
18 
19 //#define DEBUG_CAMERA
20 #include "scenegraph_objects.rsh"
21 
22 void root(const rs_allocation *v_in, rs_allocation *v_out, const float *usrData) {
23 
24     SgCamera *cam = (SgCamera *)rsGetElementAt(*v_in, 0);
25     float aspect = *usrData;
26     if (cam->aspect != aspect) {
27         cam->isDirty = 1;
28         cam->aspect = aspect;
29     }
30     if (cam->isDirty) {
31         rsMatrixLoadPerspective(&cam->proj, cam->horizontalFOV, cam->aspect, cam->near, cam->far);
32     }
33 
34     const SgTransform *camTransform = (const SgTransform *)rsGetElementAt(cam->transformMatrix, 0);
35     //rsDebug("Camera stamp", cam->transformTimestamp);
36     //rsDebug("Transform stamp", camTransform->timestamp);
37     if (camTransform->timestamp != cam->transformTimestamp || cam->isDirty) {
38         cam->isDirty = 1;
39         rs_matrix4x4 camPosMatrix;
40         rsMatrixLoad(&camPosMatrix, &camTransform->globalMat);
41         float4 zero = {0.0f, 0.0f, 0.0f, 1.0f};
42         cam->position = rsMatrixMultiply(&camPosMatrix, zero);
43 
44         rsMatrixInverse(&camPosMatrix);
45         rsMatrixLoad(&cam->view, &camPosMatrix);
46 
47         rsMatrixLoad(&cam->viewProj, &cam->proj);
48         rsMatrixMultiply(&cam->viewProj, &cam->view);
49 
50         rsExtractFrustumPlanes(&cam->viewProj,
51                                &cam->frustumPlanes[0], &cam->frustumPlanes[1],
52                                &cam->frustumPlanes[2], &cam->frustumPlanes[3],
53                                &cam->frustumPlanes[3], &cam->frustumPlanes[4]);
54     }
55 
56     if (cam->isDirty) {
57         cam->timestamp ++;
58     }
59 
60     cam->isDirty = 0;
61     cam->transformTimestamp = camTransform->timestamp;
62 
63 #ifdef DEBUG_CAMERA
64     printCameraInfo(cam);
65 #endif //DEBUG_CAMERA
66 }
67