Added libdli to dali-toolkit as dali-scene-loader.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene-loader / utc-Dali-CameraParameters.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
18 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
20
21 #include "dali-scene-loader/public-api/camera-parameters.h"
22 #include <dali-test-suite-utils.h>
23 #include <string_view>
24
25 using namespace Dali;
26 using namespace Dali::SceneLoader;
27
28 int UtcDaliCameraParameters(void)
29 {
30   Quaternion qView = Quaternion(Radian(Degree(180.f)), Vector3::YAXIS);
31   CameraParameters camParams;
32   camParams.matrix.SetTransformComponents(Vector3::ONE * 2.f,
33     qView,
34     Vector3::ZAXIS * -100.f);
35   camParams.orthographicSize = Vector4{ -1.f, 1.f, -1.f, 1.f };
36   camParams.yFov = Radian(M_PI * .5).radian;
37   camParams.zNear = 1.f;
38   camParams.zFar = 1000.f;
39
40   Vector3 scale;
41   Quaternion orientation;
42   Vector3 position;
43   camParams.CalculateTransformComponents(position, orientation, scale);
44   DALI_TEST_EQUAL(scale, Vector3::ONE * 2.f);
45   DALI_TEST_EQUAL(orientation, Quaternion::IDENTITY); // 2 180 degrees rotations along y
46   DALI_TEST_EQUAL(position, Vector3::ZAXIS * -100.f);
47
48   TestApplication app;
49   CameraActor camera = CameraActor::New();
50   for (auto i : { false, true })
51   {
52     camParams.isPerspective = i;
53
54     auto viewProjection = camParams.GetViewProjection();
55     Matrix view{ false };
56     Matrix::Multiply(view, Matrix(qView), camParams.matrix);
57     view.Invert();
58     DALI_TEST_EQUAL(viewProjection.GetView(), view);
59
60     camParams.ConfigureCamera(camera);
61     DALI_TEST_EQUAL(camParams.zNear, camera.GetNearClippingPlane());
62     DALI_TEST_EQUAL(camParams.zFar, camera.GetFarClippingPlane());
63
64     DALI_TEST_EQUAL(camera.GetInvertYAxis(), true);
65     DALI_TEST_EQUAL(camera.GetProperty(Actor::Property::POSITION).Get<Vector3>(), position);
66     DALI_TEST_EQUAL(camera.GetProperty(Actor::Property::ORIENTATION).Get<Quaternion>(), orientation);
67     DALI_TEST_EQUAL(camera.GetProperty(Actor::Property::SCALE).Get<Vector3>(), scale);
68   }
69
70   END_TEST;
71 }