From 6ad09cc83f9db273cc91ff5277eb310f0671bf4a Mon Sep 17 00:00:00 2001 From: Martin Veillette Date: Thu, 29 Jul 2021 16:38:33 -0400 Subject: [PATCH] hoist projector constant to GeometricOptics (see #129) --- js/common/GeometricOpticsConstants.js | 10 ++++++---- js/lens/model/ProjectorScreen.js | 4 ++-- js/lens/view/ProjectorScreenNode.js | 21 ++++++++++++--------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/js/common/GeometricOpticsConstants.js b/js/common/GeometricOpticsConstants.js index 2e742736..55531cbc 100644 --- a/js/common/GeometricOpticsConstants.js +++ b/js/common/GeometricOpticsConstants.js @@ -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 //---------------------------------------------------------------------------------------- diff --git a/js/lens/model/ProjectorScreen.js b/js/lens/model/ProjectorScreen.js index efbaab27..5cd897c5 100644 --- a/js/lens/model/ProjectorScreen.js +++ b/js/lens/model/ProjectorScreen.js @@ -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.} 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.} position of the optic this.opticPositionProperty = optic.positionProperty; diff --git a/js/lens/view/ProjectorScreenNode.js b/js/lens/view/ProjectorScreenNode.js index 6de440ae..dacd6fc3 100644 --- a/js/lens/view/ProjectorScreenNode.js +++ b/js/lens/view/ProjectorScreenNode.js @@ -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. { return new Bounds2( opticPosition.x, visibleBounds.minY + modelChildHeight / 2,