Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
SkM44 Class Reference

#include <SkM44.h>

Public Types

enum  Uninitialized_Constructor { kUninitialized_Constructor }
 
enum  NaN_Constructor { kNaN_Constructor }
 

Public Member Functions

 SkM44 (const SkM44 &src)=default
 
SkM44operator= (const SkM44 &src)=default
 
constexpr SkM44 ()
 
 SkM44 (const SkM44 &a, const SkM44 &b)
 
 SkM44 (Uninitialized_Constructor)
 
constexpr SkM44 (NaN_Constructor)
 
constexpr SkM44 (SkScalar m0, SkScalar m4, SkScalar m8, SkScalar m12, SkScalar m1, SkScalar m5, SkScalar m9, SkScalar m13, SkScalar m2, SkScalar m6, SkScalar m10, SkScalar m14, SkScalar m3, SkScalar m7, SkScalar m11, SkScalar m15)
 
bool operator== (const SkM44 &other) const
 
bool operator!= (const SkM44 &other) const
 
void getColMajor (SkScalar v[]) const
 
void getRowMajor (SkScalar v[]) const
 
SkScalar rc (int r, int c) const
 
void setRC (int r, int c, SkScalar value)
 
SkV4 row (int i) const
 
SkV4 col (int i) const
 
void setRow (int i, const SkV4 &v)
 
void setCol (int i, const SkV4 &v)
 
SkM44setIdentity ()
 
SkM44setTranslate (SkScalar x, SkScalar y, SkScalar z=0)
 
SkM44setScale (SkScalar x, SkScalar y, SkScalar z=1)
 
SkM44setRotateUnitSinCos (SkV3 axis, SkScalar sinAngle, SkScalar cosAngle)
 
SkM44setRotateUnit (SkV3 axis, SkScalar radians)
 
SkM44setRotate (SkV3 axis, SkScalar radians)
 
SkM44setConcat (const SkM44 &a, const SkM44 &b)
 
SkM44preConcat (const SkM44 &m)
 
SkM44postConcat (const SkM44 &m)
 
void normalizePerspective ()
 
bool isFinite () const
 
bool invert (SkM44 *inverse) const
 
SkM44 transpose () const
 
void dump () const
 
SkV4 map (float x, float y, float z, float w) const
 
SkV4 operator* (const SkV4 &v) const
 
SkV3 operator* (SkV3 v) const
 
SkMatrix asM33 () const
 
 SkM44 (const SkMatrix &src)
 
SkM44preTranslate (SkScalar x, SkScalar y, SkScalar z=0)
 
SkM44postTranslate (SkScalar x, SkScalar y, SkScalar z=0)
 
SkM44preScale (SkScalar x, SkScalar y)
 
SkM44preScale (SkScalar x, SkScalar y, SkScalar z)
 
SkM44preConcat (const SkMatrix &)
 

Static Public Member Functions

static SkM44 Rows (const SkV4 &r0, const SkV4 &r1, const SkV4 &r2, const SkV4 &r3)
 
static SkM44 Cols (const SkV4 &c0, const SkV4 &c1, const SkV4 &c2, const SkV4 &c3)
 
static SkM44 RowMajor (const SkScalar r[16])
 
static SkM44 ColMajor (const SkScalar c[16])
 
static SkM44 Translate (SkScalar x, SkScalar y, SkScalar z=0)
 
static SkM44 Scale (SkScalar x, SkScalar y, SkScalar z=1)
 
static SkM44 Rotate (SkV3 axis, SkScalar radians)
 
static SkM44 RectToRect (const SkRect &src, const SkRect &dst)
 
static SkM44 LookAt (const SkV3 &eye, const SkV3 &center, const SkV3 &up)
 
static SkM44 Perspective (float near, float far, float angle)
 

Friends

class SkMatrixPriv
 
SkM44 operator* (const SkM44 &a, const SkM44 &b)
 

Detailed Description

4x4 matrix used by SkCanvas and other parts of Skia.

Skia assumes a right-handed coordinate system: +X goes to the right +Y goes down +Z goes into the screen (away from the viewer)

Definition at line 150 of file SkM44.h.

Member Enumeration Documentation

◆ NaN_Constructor

Enumerator
kNaN_Constructor 

Definition at line 171 of file SkM44.h.

171 {
173 };
@ kNaN_Constructor
Definition: SkM44.h:172

◆ Uninitialized_Constructor

Enumerator
kUninitialized_Constructor 

Definition at line 166 of file SkM44.h.

166 {
168 };
@ kUninitialized_Constructor
Definition: SkM44.h:167

Constructor & Destructor Documentation

◆ SkM44() [1/7]

SkM44::SkM44 ( const SkM44 src)
default

◆ SkM44() [2/7]

constexpr SkM44::SkM44 ( )
inlineconstexpr

Definition at line 155 of file SkM44.h.

156 : fMat{1, 0, 0, 0,
157 0, 1, 0, 0,
158 0, 0, 1, 0,
159 0, 0, 0, 1}
160 {}

◆ SkM44() [3/7]

SkM44::SkM44 ( const SkM44 a,
const SkM44 b 
)
inline

Definition at line 162 of file SkM44.h.

162 {
163 this->setConcat(a, b);
164 }
SkM44 & setConcat(const SkM44 &a, const SkM44 &b)
Definition: SkM44.cpp:48
static bool b

◆ SkM44() [4/7]

SkM44::SkM44 ( Uninitialized_Constructor  )
inline

Definition at line 169 of file SkM44.h.

169{}

◆ SkM44() [5/7]

constexpr SkM44::SkM44 ( NaN_Constructor  )
inlineconstexpr

◆ SkM44() [6/7]

constexpr SkM44::SkM44 ( SkScalar  m0,
SkScalar  m4,
SkScalar  m8,
SkScalar  m12,
SkScalar  m1,
SkScalar  m5,
SkScalar  m9,
SkScalar  m13,
SkScalar  m2,
SkScalar  m6,
SkScalar  m10,
SkScalar  m14,
SkScalar  m3,
SkScalar  m7,
SkScalar  m11,
SkScalar  m15 
)
inlineconstexpr

The constructor parameters are in row-major order.

Definition at line 184 of file SkM44.h.

189 : fMat{m0, m1, m2, m3,
190 m4, m5, m6, m7,
191 m8, m9, m10, m11,
192 m12, m13, m14, m15}
193 {}

◆ SkM44() [7/7]

SkM44::SkM44 ( const SkMatrix src)
inlineexplicit

Definition at line 415 of file SkM44.h.

418 0, 0, 1, 0,
420 {}
constexpr SkM44()
Definition: SkM44.h:155
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

Member Function Documentation

◆ asM33()

SkMatrix SkM44::asM33 ( ) const
inline

Definition at line 409 of file SkM44.h.

409 {
410 return SkMatrix::MakeAll(fMat[0], fMat[4], fMat[12],
411 fMat[1], fMat[5], fMat[13],
412 fMat[3], fMat[7], fMat[15]);
413 }
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
Definition: SkMatrix.h:179

◆ col()

SkV4 SkM44::col ( int  i) const
inline

Definition at line 276 of file SkM44.h.

276 {
277 SkASSERT(i >= 0 && i <= 3);
278 return {fMat[i*4 + 0], fMat[i*4 + 1], fMat[i*4 + 2], fMat[i*4 + 3]};
279 }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ ColMajor()

static SkM44 SkM44::ColMajor ( const SkScalar  c[16])
inlinestatic

Definition at line 218 of file SkM44.h.

218 {
219 return SkM44(c[0], c[4], c[ 8], c[12],
220 c[1], c[5], c[ 9], c[13],
221 c[2], c[6], c[10], c[14],
222 c[3], c[7], c[11], c[15]);
223 }

◆ Cols()

static SkM44 SkM44::Cols ( const SkV4 c0,
const SkV4 c1,
const SkV4 c2,
const SkV4 c3 
)
inlinestatic

Definition at line 203 of file SkM44.h.

203 {
205 m.setCol(0, c0);
206 m.setCol(1, c1);
207 m.setCol(2, c2);
208 m.setCol(3, c3);
209 return m;
210 }
Definition: SkM44.h:150

◆ dump()

void SkM44::dump ( ) const

Definition at line 291 of file SkM44.cpp.

291 {
292 SkDebugf("|%g %g %g %g|\n"
293 "|%g %g %g %g|\n"
294 "|%g %g %g %g|\n"
295 "|%g %g %g %g|\n",
296 fMat[0], fMat[4], fMat[8], fMat[12],
297 fMat[1], fMat[5], fMat[9], fMat[13],
298 fMat[2], fMat[6], fMat[10], fMat[14],
299 fMat[3], fMat[7], fMat[11], fMat[15]);
300}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1

◆ getColMajor()

void SkM44::getColMajor ( SkScalar  v[]) const
inline

Definition at line 256 of file SkM44.h.

256 {
257 memcpy(v, fMat, sizeof(fMat));
258 }

◆ getRowMajor()

void SkM44::getRowMajor ( SkScalar  v[]) const

Definition at line 44 of file SkM44.cpp.

44 {
45 transpose_arrays(v, fMat);
46}
static void transpose_arrays(SkScalar dst[], const SkScalar src[])
Definition: SkM44.cpp:37

◆ invert()

bool SkM44::invert ( SkM44 inverse) const

If this is invertible, return that in inverse and return true. If it is not invertible, return false and leave the inverse parameter unchanged.

We always perform the calculation in doubles, to avoid prematurely losing precision along the way. This relies on the compiler automatically promoting our SkScalar values to double (if needed).

Definition at line 247 of file SkM44.cpp.

247 {
248 SkScalar tmp[16];
249 if (SkInvert4x4Matrix(fMat, tmp) == 0.0f) {
250 return false;
251 }
252 memcpy(inverse->fMat, tmp, sizeof(tmp));
253 return true;
254}
SkScalar SkInvert4x4Matrix(const SkScalar inMatrix[16], SkScalar outMatrix[16])
float SkScalar
Definition: extension.cpp:12

◆ isFinite()

bool SkM44::isFinite ( ) const
inline

Returns true if all elements of the matrix are finite. Returns false if any element is infinity, or NaN.

Returns
true if matrix has only finite elements

Definition at line 378 of file SkM44.h.

378{ return SkIsFinite(fMat, 16); }
static bool SkIsFinite(T x, Pack... values)

◆ LookAt()

SkM44 SkM44::LookAt ( const SkV3 eye,
const SkV3 center,
const SkV3 up 
)
static

Definition at line 331 of file SkM44.cpp.

331 {
332 SkV3 f = normalize(center - eye);
333 SkV3 u = normalize(up);
334 SkV3 s = normalize(f.cross(u));
335
337 if (!SkM44::Cols(v4(s, 0), v4(s.cross(f), 0), v4(-f, 0), v4(eye, 1)).invert(&m)) {
338 m.setIdentity();
339 }
340 return m;
341}
static SkV3 normalize(SkV3 v)
Definition: SkM44.cpp:323
static SkV4 v4(SkV3 v, SkScalar w)
Definition: SkM44.cpp:329
static SkScalar center(float pos0, float pos1)
bool invert(SkM44 *inverse) const
Definition: SkM44.cpp:247
static SkM44 Cols(const SkV4 &c0, const SkV4 &c1, const SkV4 &c2, const SkV4 &c3)
Definition: SkM44.h:203
struct MyStruct s
Definition: SkM44.h:56

◆ map()

SkV4 SkM44::map ( float  x,
float  y,
float  z,
float  w 
) const

Definition at line 129 of file SkM44.cpp.

129 {
130 auto c0 = skvx::float4::Load(fMat + 0);
131 auto c1 = skvx::float4::Load(fMat + 4);
132 auto c2 = skvx::float4::Load(fMat + 8);
133 auto c3 = skvx::float4::Load(fMat + 12);
134
135 SkV4 v;
136 (c0*x + (c1*y + (c2*z + c3*w))).store(&v.x);
137 return v;
138}
SI void store(P *ptr, const T &val)
double y
double x
SkScalar w
Definition: SkM44.h:98
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition: SkVx.h:109

◆ normalizePerspective()

void SkM44::normalizePerspective ( )

A matrix is categorized as 'perspective' if the bottom row is not [0, 0, 0, 1]. For most uses, a bottom row of [0, 0, 0, X] behaves like a non-perspective matrix, though it will be categorized as perspective. Calling normalizePerspective() will change the matrix such that, if its bottom row was [0, 0, 0, X], it will be changed to [0, 0, 0, 1] by scaling the rest of the matrix by 1/X.

| A B C D | | A/X B/X C/X D/X | | E F G H | -> | E/X F/X G/X H/X | for X != 0 | I J K L | | I/X J/X K/X L/X | | 0 0 0 X | | 0 0 0 1 |

Definition at line 226 of file SkM44.cpp.

226 {
227 // If the bottom row of the matrix is [0, 0, 0, not_one], we will treat the matrix as if it
228 // is in perspective, even though it stills behaves like its affine. If we divide everything
229 // by the not_one value, then it will behave the same, but will be treated as affine,
230 // and therefore faster (e.g. clients can forward-difference calculations).
231 if (fMat[15] != 1 && fMat[15] != 0 && fMat[3] == 0 && fMat[7] == 0 && fMat[11] == 0) {
232 double inv = 1.0 / fMat[15];
233 (skvx::float4::Load(fMat + 0) * inv).store(fMat + 0);
234 (skvx::float4::Load(fMat + 4) * inv).store(fMat + 4);
235 (skvx::float4::Load(fMat + 8) * inv).store(fMat + 8);
236 (skvx::float4::Load(fMat + 12) * inv).store(fMat + 12);
237 fMat[15] = 1.0f;
238 }
239}
static SkM44 inv(const SkM44 &m)
Definition: 3d.cpp:26

◆ operator!=()

bool SkM44::operator!= ( const SkM44 other) const
inline

Definition at line 252 of file SkM44.h.

252 {
253 return !(other == *this);
254 }

◆ operator*() [1/2]

SkV4 SkM44::operator* ( const SkV4 v) const
inline

Definition at line 392 of file SkM44.h.

392 {
393 return this->map(v.x, v.y, v.z, v.w);
394 }
SkV4 map(float x, float y, float z, float w) const
Definition: SkM44.cpp:129
float w
Definition: SkM44.h:99
float y
Definition: SkM44.h:99
float x
Definition: SkM44.h:99
float z
Definition: SkM44.h:99

◆ operator*() [2/2]

SkV3 SkM44::operator* ( SkV3  v) const
inline

Definition at line 395 of file SkM44.h.

395 {
396 auto v4 = this->map(v.x, v.y, v.z, 0);
397 return {v4.x, v4.y, v4.z};
398 }
float y
Definition: SkM44.h:57
float z
Definition: SkM44.h:57
float x
Definition: SkM44.h:57

◆ operator=()

SkM44 & SkM44::operator= ( const SkM44 src)
default

◆ operator==()

bool SkM44::operator== ( const SkM44 other) const

Definition at line 18 of file SkM44.cpp.

18 {
19 if (this == &other) {
20 return true;
21 }
22
23 auto a0 = skvx::float4::Load(fMat + 0);
24 auto a1 = skvx::float4::Load(fMat + 4);
25 auto a2 = skvx::float4::Load(fMat + 8);
26 auto a3 = skvx::float4::Load(fMat + 12);
27
28 auto b0 = skvx::float4::Load(other.fMat + 0);
29 auto b1 = skvx::float4::Load(other.fMat + 4);
30 auto b2 = skvx::float4::Load(other.fMat + 8);
31 auto b3 = skvx::float4::Load(other.fMat + 12);
32
33 auto eq = (a0 == b0) & (a1 == b1) & (a2 == b2) & (a3 == b3);
34 return (eq[0] & eq[1] & eq[2] & eq[3]) == ~0;
35}
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
Definition: M44Test.cpp:18

◆ Perspective()

SkM44 SkM44::Perspective ( float  near,
float  far,
float  angle 
)
static

Definition at line 343 of file SkM44.cpp.

343 {
344 SkASSERT(far > near);
345
346 float denomInv = sk_ieee_float_divide(1, far - near);
347 float halfAngle = angle * 0.5f;
348 SkASSERT(halfAngle != 0);
349 float cot = sk_ieee_float_divide(1, std::tan(halfAngle));
350
351 SkM44 m;
352 m.setRC(0, 0, cot);
353 m.setRC(1, 1, cot);
354 m.setRC(2, 2, (far + near) * denomInv);
355 m.setRC(2, 3, 2 * far * near * denomInv);
356 m.setRC(3, 2, -1);
357 return m;
358}
static constexpr float sk_ieee_float_divide(float numer, float denom)

◆ postConcat()

SkM44 & SkM44::postConcat ( const SkM44 m)
inline

Definition at line 355 of file SkM44.h.

355 {
356 return this->setConcat(m, *this);
357 }

◆ postTranslate()

SkM44 & SkM44::postTranslate ( SkScalar  x,
SkScalar  y,
SkScalar  z = 0 
)

Definition at line 100 of file SkM44.cpp.

100 {
101 skvx::float4 t = { x, y, z, 0 };
102 (t * fMat[ 3] + skvx::float4::Load(fMat + 0)).store(fMat + 0);
103 (t * fMat[ 7] + skvx::float4::Load(fMat + 4)).store(fMat + 4);
104 (t * fMat[11] + skvx::float4::Load(fMat + 8)).store(fMat + 8);
105 (t * fMat[15] + skvx::float4::Load(fMat + 12)).store(fMat + 12);
106 return *this;
107}
Definition: SkVx.h:83

◆ preConcat() [1/2]

SkM44 & SkM44::preConcat ( const SkM44 m)
inline

Definition at line 351 of file SkM44.h.

351 {
352 return this->setConcat(*this, m);
353 }

◆ preConcat() [2/2]

SkM44 & SkM44::preConcat ( const SkMatrix b)

Definition at line 70 of file SkM44.cpp.

70 {
71 auto c0 = skvx::float4::Load(fMat + 0);
72 auto c1 = skvx::float4::Load(fMat + 4);
73 auto c3 = skvx::float4::Load(fMat + 12);
74
75 auto compute = [&](float r0, float r1, float r3) {
76 return (c0*r0 + (c1*r1 + c3*r3));
77 };
78
79 auto m0 = compute(b[0], b[3], b[6]);
80 auto m1 = compute(b[1], b[4], b[7]);
81 auto m3 = compute(b[2], b[5], b[8]);
82
83 m0.store(fMat + 0);
84 m1.store(fMat + 4);
85 m3.store(fMat + 12);
86 return *this;
87}

◆ preScale() [1/2]

SkM44 & SkM44::preScale ( SkScalar  x,
SkScalar  y 
)

Definition at line 109 of file SkM44.cpp.

109 {
110 auto c0 = skvx::float4::Load(fMat + 0);
111 auto c1 = skvx::float4::Load(fMat + 4);
112
113 (c0 * x).store(fMat + 0);
114 (c1 * y).store(fMat + 4);
115 return *this;
116}

◆ preScale() [2/2]

SkM44 & SkM44::preScale ( SkScalar  x,
SkScalar  y,
SkScalar  z 
)

Definition at line 118 of file SkM44.cpp.

118 {
119 auto c0 = skvx::float4::Load(fMat + 0);
120 auto c1 = skvx::float4::Load(fMat + 4);
121 auto c2 = skvx::float4::Load(fMat + 8);
122
123 (c0 * x).store(fMat + 0);
124 (c1 * y).store(fMat + 4);
125 (c2 * z).store(fMat + 8);
126 return *this;
127}

◆ preTranslate()

SkM44 & SkM44::preTranslate ( SkScalar  x,
SkScalar  y,
SkScalar  z = 0 
)

Definition at line 89 of file SkM44.cpp.

89 {
90 auto c0 = skvx::float4::Load(fMat + 0);
91 auto c1 = skvx::float4::Load(fMat + 4);
92 auto c2 = skvx::float4::Load(fMat + 8);
93 auto c3 = skvx::float4::Load(fMat + 12);
94
95 // only need to update the last column
96 (c0*x + (c1*y + (c2*z + c3))).store(fMat + 12);
97 return *this;
98}

◆ rc()

SkScalar SkM44::rc ( int  r,
int  c 
) const
inline

Definition at line 261 of file SkM44.h.

261 {
262 SkASSERT(r >= 0 && r <= 3);
263 SkASSERT(c >= 0 && c <= 3);
264 return fMat[c*4 + r];
265 }

◆ RectToRect()

SkM44 SkM44::RectToRect ( const SkRect src,
const SkRect dst 
)
static

Definition at line 304 of file SkM44.cpp.

304 {
305 if (src.isEmpty()) {
306 return SkM44();
307 } else if (dst.isEmpty()) {
308 return SkM44::Scale(0.f, 0.f, 0.f);
309 }
310
311 float sx = dst.width() / src.width();
312 float sy = dst.height() / src.height();
313
314 float tx = dst.fLeft - sx * src.fLeft;
315 float ty = dst.fTop - sy * src.fTop;
316
317 return SkM44{sx, 0.f, 0.f, tx,
318 0.f, sy, 0.f, ty,
319 0.f, 0.f, 1.f, 0.f,
320 0.f, 0.f, 0.f, 1.f};
321}
static SkM44 Scale(SkScalar x, SkScalar y, SkScalar z=1)
Definition: SkM44.h:232
dst
Definition: cp.py:12

◆ Rotate()

static SkM44 SkM44::Rotate ( SkV3  axis,
SkScalar  radians 
)
inlinestatic

Definition at line 239 of file SkM44.h.

239 {
241 m.setRotate(axis, radians);
242 return m;
243 }

◆ row()

SkV4 SkM44::row ( int  i) const
inline

Definition at line 272 of file SkM44.h.

272 {
273 SkASSERT(i >= 0 && i <= 3);
274 return {fMat[i + 0], fMat[i + 4], fMat[i + 8], fMat[i + 12]};
275 }

◆ RowMajor()

static SkM44 SkM44::RowMajor ( const SkScalar  r[16])
inlinestatic

Definition at line 212 of file SkM44.h.

212 {
213 return SkM44(r[ 0], r[ 1], r[ 2], r[ 3],
214 r[ 4], r[ 5], r[ 6], r[ 7],
215 r[ 8], r[ 9], r[10], r[11],
216 r[12], r[13], r[14], r[15]);
217 }

◆ Rows()

static SkM44 SkM44::Rows ( const SkV4 r0,
const SkV4 r1,
const SkV4 r2,
const SkV4 r3 
)
inlinestatic

Definition at line 195 of file SkM44.h.

195 {
197 m.setRow(0, r0);
198 m.setRow(1, r1);
199 m.setRow(2, r2);
200 m.setRow(3, r3);
201 return m;
202 }

◆ Scale()

static SkM44 SkM44::Scale ( SkScalar  x,
SkScalar  y,
SkScalar  z = 1 
)
inlinestatic

Definition at line 232 of file SkM44.h.

232 {
233 return SkM44(x, 0, 0, 0,
234 0, y, 0, 0,
235 0, 0, z, 0,
236 0, 0, 0, 1);
237 }

◆ setCol()

void SkM44::setCol ( int  i,
const SkV4 v 
)
inline

Definition at line 288 of file SkM44.h.

288 {
289 SkASSERT(i >= 0 && i <= 3);
290 memcpy(&fMat[i*4], v.ptr(), sizeof(v));
291 }
const float * ptr() const
Definition: SkM44.h:129

◆ setConcat()

SkM44 & SkM44::setConcat ( const SkM44 a,
const SkM44 b 
)

Definition at line 48 of file SkM44.cpp.

48 {
49 auto c0 = skvx::float4::Load(a.fMat + 0);
50 auto c1 = skvx::float4::Load(a.fMat + 4);
51 auto c2 = skvx::float4::Load(a.fMat + 8);
52 auto c3 = skvx::float4::Load(a.fMat + 12);
53
54 auto compute = [&](skvx::float4 r) {
55 return c0*r[0] + (c1*r[1] + (c2*r[2] + c3*r[3]));
56 };
57
58 auto m0 = compute(skvx::float4::Load(b.fMat + 0));
59 auto m1 = compute(skvx::float4::Load(b.fMat + 4));
60 auto m2 = compute(skvx::float4::Load(b.fMat + 8));
61 auto m3 = compute(skvx::float4::Load(b.fMat + 12));
62
63 m0.store(fMat + 0);
64 m1.store(fMat + 4);
65 m2.store(fMat + 8);
66 m3.store(fMat + 12);
67 return *this;
68}
struct MyStruct a[10]

◆ setIdentity()

SkM44 & SkM44::setIdentity ( )
inline

Definition at line 293 of file SkM44.h.

293 {
294 *this = { 1, 0, 0, 0,
295 0, 1, 0, 0,
296 0, 0, 1, 0,
297 0, 0, 0, 1 };
298 return *this;
299 }

◆ setRC()

void SkM44::setRC ( int  r,
int  c,
SkScalar  value 
)
inline

Definition at line 266 of file SkM44.h.

266 {
267 SkASSERT(r >= 0 && r <= 3);
268 SkASSERT(c >= 0 && c <= 3);
269 fMat[c*4 + r] = value;
270 }
uint8_t value

◆ setRotate()

SkM44 & SkM44::setRotate ( SkV3  axis,
SkScalar  radians 
)

Set this matrix to rotate about the specified axis vector, by an angle specified in radians.

Note: axis is not assumed to be unit-length, so it will be normalized internally. If axis is already unit-length, call setRotateAboutUnitRadians() instead.

Definition at line 279 of file SkM44.cpp.

279 {
280 SkScalar len = axis.length();
281 if (len > 0 && SkIsFinite(len)) {
282 this->setRotateUnit(axis * (SK_Scalar1 / len), radians);
283 } else {
284 this->setIdentity();
285 }
286 return *this;
287}
#define SK_Scalar1
Definition: SkScalar.h:18
SkM44 & setRotateUnit(SkV3 axis, SkScalar radians)
Definition: SkM44.h:332
SkM44 & setIdentity()
Definition: SkM44.h:293
SkScalar length() const
Definition: SkM44.h:88

◆ setRotateUnit()

SkM44 & SkM44::setRotateUnit ( SkV3  axis,
SkScalar  radians 
)
inline

Set this matrix to rotate about the specified unit-length axis vector, by an angle specified in radians.

This does not attempt to verify that axis.length() == 1.

Definition at line 332 of file SkM44.h.

332 {
333 return this->setRotateUnitSinCos(axis, SkScalarSin(radians), SkScalarCos(radians));
334 }
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarCos(radians)
Definition: SkScalar.h:46
SkM44 & setRotateUnitSinCos(SkV3 axis, SkScalar sinAngle, SkScalar cosAngle)
Definition: SkM44.cpp:262

◆ setRotateUnitSinCos()

SkM44 & SkM44::setRotateUnitSinCos ( SkV3  axis,
SkScalar  sinAngle,
SkScalar  cosAngle 
)

Set this matrix to rotate about the specified unit-length axis vector, by an angle specified by its sin() and cos().

This does not attempt to verify that axis.length() == 1 or that the sin,cos values are correct.

Definition at line 262 of file SkM44.cpp.

262 {
263 // Taken from "Essential Mathematics for Games and Interactive Applications"
264 // James M. Van Verth and Lars M. Bishop -- third edition
265 SkScalar x = axis.x;
266 SkScalar y = axis.y;
267 SkScalar z = axis.z;
268 SkScalar c = cosAngle;
269 SkScalar s = sinAngle;
270 SkScalar t = 1 - c;
271
272 *this = { t*x*x + c, t*x*y - s*z, t*x*z + s*y, 0,
273 t*x*y + s*z, t*y*y + c, t*y*z - s*x, 0,
274 t*x*z - s*y, t*y*z + s*x, t*z*z + c, 0,
275 0, 0, 0, 1 };
276 return *this;
277}

◆ setRow()

void SkM44::setRow ( int  i,
const SkV4 v 
)
inline

Definition at line 281 of file SkM44.h.

281 {
282 SkASSERT(i >= 0 && i <= 3);
283 fMat[i + 0] = v.x;
284 fMat[i + 4] = v.y;
285 fMat[i + 8] = v.z;
286 fMat[i + 12] = v.w;
287 }

◆ setScale()

SkM44 & SkM44::setScale ( SkScalar  x,
SkScalar  y,
SkScalar  z = 1 
)
inline

Definition at line 309 of file SkM44.h.

309 {
310 *this = { x, 0, 0, 0,
311 0, y, 0, 0,
312 0, 0, z, 0,
313 0, 0, 0, 1 };
314 return *this;
315 }

◆ setTranslate()

SkM44 & SkM44::setTranslate ( SkScalar  x,
SkScalar  y,
SkScalar  z = 0 
)
inline

Definition at line 301 of file SkM44.h.

301 {
302 *this = { 1, 0, 0, x,
303 0, 1, 0, y,
304 0, 0, 1, z,
305 0, 0, 0, 1 };
306 return *this;
307 }

◆ Translate()

static SkM44 SkM44::Translate ( SkScalar  x,
SkScalar  y,
SkScalar  z = 0 
)
inlinestatic

Definition at line 225 of file SkM44.h.

225 {
226 return SkM44(1, 0, 0, x,
227 0, 1, 0, y,
228 0, 0, 1, z,
229 0, 0, 0, 1);
230 }

◆ transpose()

SkM44 SkM44::transpose ( ) const

Definition at line 256 of file SkM44.cpp.

256 {
258 transpose_arrays(trans.fMat, fMat);
259 return trans;
260}

Friends And Related Function Documentation

◆ operator*

SkM44 operator* ( const SkM44 a,
const SkM44 b 
)
friend

Definition at line 347 of file SkM44.h.

347 {
348 return SkM44(a, b);
349 }

◆ SkMatrixPriv

friend class SkMatrixPriv
friend

Definition at line 439 of file SkM44.h.


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