• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 //  Inspired by Rob Johnson's most excellent QuickDraw GX sample code
9 
10 #ifndef SkCamera_DEFINED
11 #define SkCamera_DEFINED
12 
13 #include "include/core/SkM44.h"
14 #include "include/core/SkMatrix.h"
15 #include "include/core/SkScalar.h"
16 #include "include/core/SkTypes.h"
17 #include "include/private/base/SkNoncopyable.h"
18 
19 // NOTE -- This entire header / impl is deprecated, and will be removed from Skia soon.
20 //
21 // Skia now has support for a 4x matrix (SkM44) in SkCanvas.
22 //
23 
24 class SkCanvas;
25 
26 // DEPRECATED
27 class SkPatch3D {
28 public:
29     SkPatch3D();
30 
31     void    reset();
32     void    transform(const SkM44&, SkPatch3D* dst = nullptr) const;
33 
34     // dot a unit vector with the patch's normal
35     SkScalar dotWith(SkScalar dx, SkScalar dy, SkScalar dz) const;
dotWith(const SkV3 & v)36     SkScalar dotWith(const SkV3& v) const {
37         return this->dotWith(v.x, v.y, v.z);
38     }
39 
40     // deprecated, but still here for animator (for now)
rotate(SkScalar,SkScalar,SkScalar)41     void rotate(SkScalar /*x*/, SkScalar /*y*/, SkScalar /*z*/) {}
rotateDegrees(SkScalar,SkScalar,SkScalar)42     void rotateDegrees(SkScalar /*x*/, SkScalar /*y*/, SkScalar /*z*/) {}
43 
44 private:
45 public: // make public for SkDraw3D for now
46     SkV3  fU, fV;
47     SkV3  fOrigin;
48 
49     friend class SkCamera3D;
50 };
51 
52 // DEPRECATED
53 class SkCamera3D {
54 public:
55     SkCamera3D();
56 
57     void reset();
58     void update();
59     void patchToMatrix(const SkPatch3D&, SkMatrix* matrix) const;
60 
61     SkV3   fLocation;   // origin of the camera's space
62     SkV3   fAxis;       // view direction
63     SkV3   fZenith;     // up direction
64     SkV3   fObserver;   // eye position (may not be the same as the origin)
65 
66 private:
67     mutable SkMatrix    fOrientation;
68     mutable bool        fNeedToUpdate;
69 
70     void doUpdate() const;
71 };
72 
73 // DEPRECATED
74 class SK_API Sk3DView : SkNoncopyable {
75 public:
76     Sk3DView();
77     ~Sk3DView();
78 
79     void save();
80     void restore();
81 
82     void translate(SkScalar x, SkScalar y, SkScalar z);
83     void rotateX(SkScalar deg);
84     void rotateY(SkScalar deg);
85     void rotateZ(SkScalar deg);
86 
87 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
88     void setCameraLocation(SkScalar x, SkScalar y, SkScalar z);
89     SkScalar getCameraLocationX() const;
90     SkScalar getCameraLocationY() const;
91     SkScalar getCameraLocationZ() const;
92 #endif
93 
94     void getMatrix(SkMatrix*) const;
95     void applyToCanvas(SkCanvas*) const;
96 
97     SkScalar dotWithNormal(SkScalar dx, SkScalar dy, SkScalar dz) const;
98 
99 private:
100     struct Rec {
101         Rec*    fNext;
102         SkM44   fMatrix;
103     };
104     Rec*        fRec;
105     Rec         fInitialRec;
106     SkCamera3D  fCamera;
107 };
108 
109 #endif
110