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/camera-parameters.h"
22 #include <dali-test-suite-utils.h>
23 #include <string_view>
26 using namespace Dali::SceneLoader;
28 int UtcDaliCameraParameters(void)
30 Quaternion qView = Quaternion(Radian(Degree(180.f)), Vector3::YAXIS);
31 CameraParameters camParams;
32 camParams.matrix.SetTransformComponents(Vector3::ONE * 2.f,
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;
41 Quaternion orientation;
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);
49 CameraActor camera = CameraActor::New();
50 for (auto i : { false, true })
52 camParams.isPerspective = i;
54 auto viewProjection = camParams.GetViewProjection();
56 Matrix::Multiply(view, Matrix(qView), camParams.matrix);
58 DALI_TEST_EQUAL(viewProjection.GetView(), view);
60 camParams.ConfigureCamera(camera);
61 DALI_TEST_EQUAL(camParams.zNear, camera.GetNearClippingPlane());
62 DALI_TEST_EQUAL(camParams.zFar, camera.GetFarClippingPlane());
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);