2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
21 #include "dali-scene-loader/public-api/view-projection.h"
22 #include <dali-test-suite-utils.h>
25 using namespace Dali::SceneLoader;
29 void SetPerspectiveProjection(Matrix& m)
31 auto data = m.AsFloat();
38 data[0] = 2.f * near / (right - left);
39 data[5] = 2.f * near / (top - bottom);
40 data[8] = (right + left) / (right - left);
41 data[9] = (top + bottom) / (top - bottom);
42 data[10] = (far + near) / (far - near);
44 data[14] = 2 * far * near / (far - near);
49 int UtcDaliViewProjection(void)
53 viewMatrix.SetTransformComponents( Vector3::ONE,
54 Quaternion(Radian(Degree(90.f)), Vector3::YAXIS),
55 Vector3::XAXIS * 200.f);
56 vp.GetView() = viewMatrix;
58 Matrix projectionMatrix;
59 SetPerspectiveProjection(projectionMatrix);
60 vp.GetProjection() = projectionMatrix;
64 [&](const ViewProjection& vp) {
65 DALI_TEST_EQUAL(vp.GetView(), viewMatrix);
66 DALI_TEST_EQUAL(vp.GetProjection(), projectionMatrix);
69 Matrix expectedViewProjection{ false };
70 Matrix::Multiply(expectedViewProjection, viewMatrix, projectionMatrix);
71 auto viewProjectionResult = vp.GetViewProjection();
72 DALI_TEST_EQUAL(viewProjectionResult, expectedViewProjection);
74 Matrix expectedInverseProjection{ projectionMatrix };
75 expectedInverseProjection.Invert();
76 auto inverseProjectionResult = vp.GetInverseProjection();
77 DALI_TEST_EQUAL(inverseProjectionResult, expectedInverseProjection);
82 int UtcDaliViewProjectionUpdateFail(void)
85 DALI_TEST_ASSERTION(vp.Update(), "Failed to find inverse");