1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
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
16 #include "camera_test.h"
17
18 namespace OHOS {
19 namespace Rosen {
20 namespace Drawing {
21 static constexpr scalar POSITION_RIGHT = 500;
22 static constexpr scalar POSITION_BOTTOM = 500;
TestCamera(Canvas & canvas,uint32_t width,uint32_t height)23 void CameraTest::TestCamera(Canvas& canvas, uint32_t width, uint32_t height)
24 {
25 LOGI("+++++++ TestCamera");
26
27 Brush brush;
28 Matrix m0;
29 m0.Translate(width / 2.0, height / 2.0); // Set matrix m0 to translate by (width / 2.0, height / 2.0).
30 canvas.SetMatrix(m0);
31
32 Camera3D camera;
33 camera.RotateXDegrees(-25); // Set camera to rotate by degrees -25 at x-aixs.
34 camera.RotateYDegrees(45); // Set camera to rotate by degrees 45 at y-aixs.
35 camera.Translate(-50, 50, 50); // Set camera to translate by (-50, 50, 50).
36 Drawing::Rect r(0, 0, POSITION_RIGHT, POSITION_BOTTOM); // rect is set to (fLeft, fTop, fRight, fBottom)
37
38 canvas.Save();
39 camera.Save();
40 camera.RotateYDegrees(90); // Set camera to rotate by degrees 90 at y-aixs.
41 Matrix m1;
42 camera.ApplyToMatrix(m1);
43 camera.Restore();
44 canvas.ConcatMatrix(m1);
45 brush.SetColor(Drawing::Color::COLOR_LTGRAY);
46 canvas.AttachBrush(brush);
47 canvas.DrawRect(r);
48 canvas.Restore();
49 LOGI("------- TestCamera");
50 }
51
CameraTestCase()52 std::vector<CameraTest::TestFunc> CameraTest::CameraTestCase()
53 {
54 std::vector<TestFunc> testFuncVec;
55 testFuncVec.push_back(TestCamera);
56 return testFuncVec;
57 }
58 } // namespace Drawing
59 } // namespace Rosen
60 } // namespace OHOS