Skip to content

Commit

Permalink
Apply scaling and mipmapping to FieldNode's sprite, see phetsims/fara…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Mar 26, 2024
1 parent 414bdc1 commit 5e3408d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions js/Matrix3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,48 @@ export default class Matrix3 implements TPoolable {
return this.setToTranslationRotation( translation.x, translation.y, angle );
}

/**
* Sets this matrix to the combined scale+translation+rotation.
*
* The order of operations is scale, then rotate, then translate.
*
* @param x
* @param y
* @param angle - in radians
*/
public setToScaleTranslationRotation( scale: number, x: number, y: number, angle: number ): this {
let c = Math.cos( angle );
let s = Math.sin( angle );

// Handle cases close to 0, since we want Math.PI/2 rotations (and the like) to be exact
if ( Math.abs( c ) < 1e-15 ) {
c = 0;
}
if ( Math.abs( s ) < 1e-15 ) {
s = 0;
}

c *= scale;
s *= scale;

return this.rowMajor(
c, -s, x,
s, c, y,
0, 0, 1,
Matrix3Type.AFFINE );
}

/**
* Sets this matrix to the combined translation+rotation (where the rotation logically would happen first, THEN it
* would be translated).
*
* @param translation
* @param angle - in radians
*/
public setToScaleTranslationRotationPoint( scale: number, translation: Vector2, angle: number ): this {
return this.setToScaleTranslationRotation( scale, translation.x, translation.y, angle );
}

/**
* Sets this matrix to the values contained in an SVGMatrix.
*/
Expand Down

0 comments on commit 5e3408d

Please sign in to comment.