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; dotWith(const SkV3 & v)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) rotate(SkScalar,SkScalar,SkScalar)39 void rotate(SkScalar /*x*/, SkScalar /*y*/, SkScalar /*z*/) {} rotateDegrees(SkScalar,SkScalar,SkScalar)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 void setCameraLocation(SkScalar x, SkScalar y, SkScalar z); 86 SkScalar getCameraLocationX() const; 87 SkScalar getCameraLocationY() const; 88 SkScalar getCameraLocationZ() const; 89 90 void getMatrix(SkMatrix*) const; 91 void applyToCanvas(SkCanvas*) const; 92 93 SkScalar dotWithNormal(SkScalar dx, SkScalar dy, SkScalar dz) const; 94 95 private: 96 struct Rec { 97 Rec* fNext; 98 SkM44 fMatrix; 99 }; 100 Rec* fRec; 101 Rec fInitialRec; 102 SkCamera3D fCamera; 103 }; 104 105 #endif 106