Skip to content

Commit

Permalink
hoist projector constant to GeometricOptics (see #129)
Browse files Browse the repository at this point in the history
veillette committed Jul 29, 2021

Verified

This commit was signed with the committer’s verified signature.
mpoke Marius Poke
1 parent a7d913b commit 6ad09cc
Showing 3 changed files with 20 additions and 15 deletions.
10 changes: 6 additions & 4 deletions js/common/GeometricOpticsConstants.js
Original file line number Diff line number Diff line change
@@ -99,12 +99,14 @@ const GeometricOpticsConstants = {
// PROJECTION SCREEN

MASK_CORNERS: {
LEFT_TOP: new Vector2( -25, 33 ), // centimeters
LEFT_BOTTOM: new Vector2( -25, -56 ),
RIGHT_BOTTOM: new Vector2( 25, -88 ),
RIGHT_TOP: new Vector2( 25, 67 )
LEFT_TOP: new Vector2( -28, 39 ), // centimeters
LEFT_BOTTOM: new Vector2( -28, -51 ),
RIGHT_BOTTOM: new Vector2( 25, -83 ),
RIGHT_TOP: new Vector2( 25, 72 )
},

PROJECTOR_INITIAL_POSITION: new Vector2( 200, 0 ),
PROJECTOR_SCALE: 0.5, // scaling factor applied to the projector screen image
FULL_BRIGHT_SPOT_HEIGHT: 7, // centimeters

//----------------------------------------------------------------------------------------
4 changes: 2 additions & 2 deletions js/lens/model/ProjectorScreen.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
*/

import Matrix3 from '../../../../dot/js/Matrix3.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import Vector2Property from '../../../../dot/js/Vector2Property.js';
import Line from '../../../../kite/js/segments/Line.js';
import Shape from '../../../../kite/js/Shape.js';
@@ -17,6 +16,7 @@ import geometricOptics from '../../geometricOptics.js';
import Spotlight from './Spotlight.js';

const MASK_CORNERS = GeometricOpticsConstants.MASK_CORNERS;
const INITIAL_POSITION = GeometricOpticsConstants.PROJECTOR_INITIAL_POSITION;

class ProjectorScreen {

@@ -37,7 +37,7 @@ class ProjectorScreen {
assert && assert( tandem instanceof Tandem, 'invalid tandem' );

// @public {Property.<Vector2>} position of the center of the screen
this.positionProperty = new Vector2Property( new Vector2( 200, 0 ) );
this.positionProperty = new Vector2Property( INITIAL_POSITION );

// @public (read-only) {Property.<Vector2>} position of the optic
this.opticPositionProperty = optic.positionProperty;
21 changes: 12 additions & 9 deletions js/lens/view/ProjectorScreenNode.js
Original file line number Diff line number Diff line change
@@ -18,9 +18,11 @@ import Path from '../../../../scenery/js/nodes/Path.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import projectorScreen3dImage from '../../../images/projector-screen-3d_png.js';
import GeometricOpticsColors from '../../common/GeometricOpticsColors.js';
import GeometricOpticsConstants from '../../common/GeometricOpticsConstants.js';
import geometricOptics from '../../geometricOptics.js';

const SPOTLIGHT_FILL = GeometricOpticsColors.projectorScreenSpotlightFillProperty;
const PROJECTOR_SCALE = GeometricOpticsConstants.PROJECTOR_SCALE;

class ProjectorScreenNode extends Node {

@@ -49,24 +51,25 @@ class ProjectorScreenNode extends Node {
super( options );

// create projectorScreen target
const projectorScreenImage = new Image( projectorScreen3dImage, { scale: 0.5 } );
const projectorScreenImage = new Image( projectorScreen3dImage, { scale: PROJECTOR_SCALE } );

// add projectorScreen image to scene graph
this.addChild( projectorScreenImage );

// difference between the left top position of the image and the "center" of the blackboard
const offset = new Vector2( -30, 75 );
// TODO: the model should give its size to the view rather than the other way around (see #153)
// determine the size of the projector in model coordinates
const modelChildHeight = Math.abs( modelViewTransform.viewToModelDeltaY( projectorScreenImage.height ) );
const modelChildWidth = modelViewTransform.viewToModelDeltaX( projectorScreenImage.width );

// difference between the left top position of the image and the "center" of the blackboard in model coordinates
const offset = new Vector2( -modelChildWidth, modelChildHeight ).divideScalar( 2 );

// @private {Property.<Vector2} create a property for the left top position of the projectorScreen target
this.imagePositionProperty = new Vector2Property( projectorScreen.positionProperty.value.plus( offset ) );

// TODO: the model should give its size to the view rather than the other way around (see #153)
// determine the size of the projector in model coordinates
const modelChildHeight = Math.abs( modelViewTransform.viewToModelDeltaY( this.height ) );
const modelChildWidth = modelViewTransform.viewToModelDeltaX( this.width );

// keep at least half of the projector screen within visible bounds and right of the optic
const projectorScreenDragBoundsProperty = new DerivedProperty( [ visibleModelBoundsProperty, projectorScreen.opticPositionProperty ],
const projectorScreenDragBoundsProperty = new DerivedProperty(
[ visibleModelBoundsProperty, projectorScreen.opticPositionProperty ],
( visibleBounds, opticPosition ) => {
return new Bounds2( opticPosition.x,
visibleBounds.minY + modelChildHeight / 2,

0 comments on commit 6ad09cc

Please sign in to comment.