| 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/private/SkNoncopyable.h" |
| 16 | |
| 17 | // NOTE -- This entire header / impl is deprecated, and will be removed from Skia soon. |
| 18 | // |
| 19 | // Skia now has support for a 4x matrix (SkM44) in SkCanvas. |
| 20 | // |
| 21 | |
| 22 | class SkCanvas; |
| 23 | |
| 24 | // DEPRECATED |
| 25 | class SkPatch3D { |
| 26 | public: |
| 27 | SkPatch3D(); |
| 28 | |
| 29 | void reset(); |
| 30 | void transform(const SkM44&, SkPatch3D* dst = nullptr) const; |
| 31 | |
| 32 | // dot a unit vector with the patch's normal |
| 33 | SkScalar dotWith(SkScalar dx, SkScalar dy, SkScalar dz) const; |
| 34 | SkScalar dotWith(const SkV3& v) const { |
| 35 | return this->dotWith(v.x, v.y, v.z); |
| 36 | } |
| 37 | |
| 38 | // deprecated, but still here for animator (for now) |
| 39 | void rotate(SkScalar /*x*/, SkScalar /*y*/, SkScalar /*z*/) {} |
| 40 | void rotateDegrees(SkScalar /*x*/, SkScalar /*y*/, SkScalar /*z*/) {} |
| 41 | |
| 42 | private: |
| 43 | public: // make public for SkDraw3D for now |
| 44 | SkV3 fU, fV; |
| 45 | SkV3 fOrigin; |
| 46 | |
| 47 | friend class SkCamera3D; |
| 48 | }; |
| 49 | |
| 50 | // DEPRECATED |
| 51 | class SkCamera3D { |
| 52 | public: |
| 53 | SkCamera3D(); |
| 54 | |
| 55 | void reset(); |
| 56 | void update(); |
| 57 | void patchToMatrix(const SkPatch3D&, SkMatrix* matrix) const; |
| 58 | |
| 59 | SkV3 fLocation; // origin of the camera's space |
| 60 | SkV3 fAxis; // view direction |
| 61 | SkV3 fZenith; // up direction |
| 62 | SkV3 fObserver; // eye position (may not be the same as the origin) |
| 63 | |
| 64 | private: |
| 65 | mutable SkMatrix fOrientation; |
| 66 | mutable bool fNeedToUpdate; |
| 67 | |
| 68 | void doUpdate() const; |
| 69 | }; |
| 70 | |
| 71 | // DEPRECATED |
| 72 | class SK_API Sk3DView : SkNoncopyable { |
| 73 | public: |
| 74 | Sk3DView(); |
| 75 | ~Sk3DView(); |
| 76 | |
| 77 | void save(); |
| 78 | void restore(); |
| 79 | |
| 80 | void translate(SkScalar x, SkScalar y, SkScalar z); |
| 81 | void rotateX(SkScalar deg); |
| 82 | void rotateY(SkScalar deg); |
| 83 | void rotateZ(SkScalar deg); |
| 84 | |
| 85 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 86 | void setCameraLocation(SkScalar x, SkScalar y, SkScalar z); |
| 87 | SkScalar getCameraLocationX() const; |
| 88 | SkScalar getCameraLocationY() const; |
| 89 | SkScalar getCameraLocationZ() const; |
| 90 | #endif |
| 91 | |
| 92 | void getMatrix(SkMatrix*) const; |
| 93 | void applyToCanvas(SkCanvas*) const; |
| 94 | |
| 95 | SkScalar dotWithNormal(SkScalar dx, SkScalar dy, SkScalar dz) const; |
| 96 | |
| 97 | private: |
| 98 | struct Rec { |
| 99 | Rec* fNext; |
| 100 | SkM44 fMatrix; |
| 101 | }; |
| 102 | Rec* fRec; |
| 103 | Rec fInitialRec; |
| 104 | SkCamera3D fCamera; |
| 105 | }; |
| 106 | |
| 107 | #endif |
| 108 | |