Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | List of all members
SkCamera3D Class Reference

#include <SkCamera.h>

Public Member Functions

 SkCamera3D ()
 
void reset ()
 
void update ()
 
void patchToMatrix (const SkPatch3D &, SkMatrix *matrix) const
 

Public Attributes

SkV3 fLocation
 
SkV3 fAxis
 
SkV3 fZenith
 
SkV3 fObserver
 

Detailed Description

Definition at line 53 of file SkCamera.h.

Constructor & Destructor Documentation

◆ SkCamera3D()

SkCamera3D::SkCamera3D ( )

Definition at line 54 of file SkCamera.cpp.

54 {
55 this->reset();
56}
void reset()
Definition: SkCamera.cpp:58

Member Function Documentation

◆ patchToMatrix()

void SkCamera3D::patchToMatrix ( const SkPatch3D quilt,
SkMatrix matrix 
) const

Definition at line 113 of file SkCamera.cpp.

113 {
114 if (fNeedToUpdate) {
115 this->doUpdate();
116 fNeedToUpdate = false;
117 }
118
119 const SkScalar* mapPtr = (const SkScalar*)(const void*)&fOrientation;
120 const SkScalar* patchPtr;
121
122 SkV3 diff = quilt.fOrigin - fLocation;
123 SkScalar dot = diff.dot({mapPtr[6], mapPtr[7], mapPtr[8]});
124
125 // This multiplies fOrientation by the matrix [quilt.fU quilt.fV diff] -- U, V, and diff are
126 // column vectors in the matrix -- then divides by the length of the projection of diff onto
127 // the view axis (which is 'dot'). This transforms the patch (which transforms from local path
128 // space to world space) into view space (since fOrientation transforms from world space to
129 // view space).
130 //
131 // The divide by 'dot' isn't strictly necessary as the homogeneous divide would do much the
132 // same thing (it's just scaling the entire matrix by 1/dot). It looks like it's normalizing
133 // the matrix into some canonical space.
134 patchPtr = (const SkScalar*)&quilt;
135 matrix->set(SkMatrix::kMScaleX, SkScalarDotDiv(3, patchPtr, 1, mapPtr, 1, dot));
136 matrix->set(SkMatrix::kMSkewY, SkScalarDotDiv(3, patchPtr, 1, mapPtr+3, 1, dot));
137 matrix->set(SkMatrix::kMPersp0, SkScalarDotDiv(3, patchPtr, 1, mapPtr+6, 1, dot));
138
139 patchPtr += 3;
140 matrix->set(SkMatrix::kMSkewX, SkScalarDotDiv(3, patchPtr, 1, mapPtr, 1, dot));
141 matrix->set(SkMatrix::kMScaleY, SkScalarDotDiv(3, patchPtr, 1, mapPtr+3, 1, dot));
142 matrix->set(SkMatrix::kMPersp1, SkScalarDotDiv(3, patchPtr, 1, mapPtr+6, 1, dot));
143
144 patchPtr = (const SkScalar*)(const void*)&diff;
145 matrix->set(SkMatrix::kMTransX, SkScalarDotDiv(3, patchPtr, 1, mapPtr, 1, dot));
146 matrix->set(SkMatrix::kMTransY, SkScalarDotDiv(3, patchPtr, 1, mapPtr+3, 1, dot));
148}
static SkScalar SkScalarDotDiv(int count, const SkScalar a[], int step_a, const SkScalar b[], int step_b, SkScalar denom)
Definition: SkCamera.cpp:10
#define SK_Scalar1
Definition: SkScalar.h:18
SkV3 fLocation
Definition: SkCamera.h:61
static constexpr int kMScaleX
horizontal scale factor
Definition: SkMatrix.h:353
static constexpr int kMTransY
vertical translation
Definition: SkMatrix.h:358
static constexpr int kMPersp1
input y perspective factor
Definition: SkMatrix.h:360
static constexpr int kMPersp0
input x perspective factor
Definition: SkMatrix.h:359
static constexpr int kMPersp2
perspective bias
Definition: SkMatrix.h:361
static constexpr int kMTransX
horizontal translation
Definition: SkMatrix.h:355
static constexpr int kMSkewY
vertical skew factor
Definition: SkMatrix.h:356
static constexpr int kMScaleY
vertical scale factor
Definition: SkMatrix.h:357
static constexpr int kMSkewX
horizontal skew factor
Definition: SkMatrix.h:354
SkV3 fOrigin
Definition: SkCamera.h:47
float SkScalar
Definition: extension.cpp:12
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
SINT T dot(const Vec< N, T > &a, const Vec< N, T > &b)
Definition: SkVx.h:964
Definition: SkM44.h:56
SkScalar dot(const SkV3 &v) const
Definition: SkM44.h:90

◆ reset()

void SkCamera3D::reset ( )

Definition at line 58 of file SkCamera.cpp.

58 {
59 fLocation = {0, 0, -SkIntToScalar(576)}; // 8 inches backward
60 fAxis = {0, 0, SK_Scalar1}; // forward
61 fZenith = {0, -SK_Scalar1, 0}; // up
62
63 fObserver = {0, 0, fLocation.z};
64
65 fNeedToUpdate = true;
66}
#define SkIntToScalar(x)
Definition: SkScalar.h:57
SkV3 fZenith
Definition: SkCamera.h:63
SkV3 fObserver
Definition: SkCamera.h:64
SkV3 fAxis
Definition: SkCamera.h:62
float z
Definition: SkM44.h:57

◆ update()

void SkCamera3D::update ( )

Definition at line 68 of file SkCamera.cpp.

68 {
69 fNeedToUpdate = true;
70}

Member Data Documentation

◆ fAxis

SkV3 SkCamera3D::fAxis

Definition at line 62 of file SkCamera.h.

◆ fLocation

SkV3 SkCamera3D::fLocation

Definition at line 61 of file SkCamera.h.

◆ fObserver

SkV3 SkCamera3D::fObserver

Definition at line 64 of file SkCamera.h.

◆ fZenith

SkV3 SkCamera3D::fZenith

Definition at line 63 of file SkCamera.h.


The documentation for this class was generated from the following files: