2 * Copyright 2006 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 // Inspired by Rob Johnson's most excellent QuickDraw GX sample code
10 #ifndef SkCamera_DEFINED
11 #define SkCamera_DEFINED
20 void set(SkScalar x, SkScalar y, SkScalar z) {
21 fX = x; fY = y; fZ = z;
23 static SkScalar Dot(const SkUnit3D&, const SkUnit3D&);
24 static void Cross(const SkUnit3D&, const SkUnit3D&, SkUnit3D* cross);
30 void set(SkScalar x, SkScalar y, SkScalar z) {
31 fX = x; fY = y; fZ = z;
33 SkScalar normalize(SkUnit3D*) const;
35 typedef SkPoint3D SkVector3D;
42 void setRow(int row, SkScalar a, SkScalar b, SkScalar c, SkScalar d = 0) {
43 SkASSERT((unsigned)row < 3);
50 void setRotateX(SkScalar deg);
51 void setRotateY(SkScalar deg);
52 void setRotateZ(SkScalar deg);
53 void setTranslate(SkScalar x, SkScalar y, SkScalar z);
55 void preRotateX(SkScalar deg);
56 void preRotateY(SkScalar deg);
57 void preRotateZ(SkScalar deg);
58 void preTranslate(SkScalar x, SkScalar y, SkScalar z);
60 void setConcat(const SkMatrix3D& a, const SkMatrix3D& b);
61 void mapPoint(const SkPoint3D& src, SkPoint3D* dst) const;
62 void mapVector(const SkVector3D& src, SkVector3D* dst) const;
64 void mapPoint(SkPoint3D* v) const {
65 this->mapPoint(*v, v);
68 void mapVector(SkVector3D* v) const {
69 this->mapVector(*v, v);
78 void transform(const SkMatrix3D&, SkPatch3D* dst = NULL) const;
80 // dot a unit vector with the patch's normal
81 SkScalar dotWith(SkScalar dx, SkScalar dy, SkScalar dz) const;
82 SkScalar dotWith(const SkVector3D& v) const {
83 return this->dotWith(v.fX, v.fY, v.fZ);
86 // deprecated, but still here for animator (for now)
87 void rotate(SkScalar x, SkScalar y, SkScalar z) {}
88 void rotateDegrees(SkScalar x, SkScalar y, SkScalar z) {}
91 public: // make public for SkDraw3D for now
95 friend class SkCamera3D;
104 void patchToMatrix(const SkPatch3D&, SkMatrix* matrix) const;
112 mutable SkMatrix fOrientation;
113 mutable bool fNeedToUpdate;
115 void doUpdate() const;
118 class Sk3DView : SkNoncopyable {
126 void translate(SkScalar x, SkScalar y, SkScalar z);
127 void rotateX(SkScalar deg);
128 void rotateY(SkScalar deg);
129 void rotateZ(SkScalar deg);
131 #ifdef SK_BUILD_FOR_ANDROID
132 void setCameraLocation(SkScalar x, SkScalar y, SkScalar z);
133 SkScalar getCameraLocationX();
134 SkScalar getCameraLocationY();
135 SkScalar getCameraLocationZ();
138 void getMatrix(SkMatrix*) const;
139 void applyToCanvas(SkCanvas*) const;
141 SkScalar dotWithNormal(SkScalar dx, SkScalar dy, SkScalar dz) const;