Skip to content

Commit

Permalink
model position for sensor body, see #107
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Sep 5, 2019
1 parent 8b6c487 commit e5b3075
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
9 changes: 7 additions & 2 deletions js/energy-skate-park/measure/model/MeasureModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ define( function( require ) {
this.sampleSkaterProperty = new BooleanProperty( true, { tandem: tandem.createTandem( 'sampleSkaterProperty' ) } );

// @public - the position of the sensor, in model coordinates (meters)
this.sensorPositionProperty = new Vector2Property( new Vector2( -4, 5 ) );
this.sensorProbePositionProperty = new Vector2Property( new Vector2( -4, 1.5 ) );

// @public - the position of the sensor body in model coordinates, set later because it will be relative to other
// panels in the view, and this similarly should not be reset on reset(). This is meant to be the origin of the
// body (top left)
this.sensorBodyPositionProperty = new Vector2Property( new Vector2( 0, 0 ) );

// @public {ObservableArray.<SkaterSample>} - list of all samples of skater physical values at a particular time
this.skaterSamples = new ObservableArray();
Expand Down Expand Up @@ -89,7 +94,7 @@ define( function( require ) {

this.clearSavedSamples();

this.sensorPositionProperty.reset();
this.sensorProbePositionProperty.reset();
this.sampleSkaterProperty.reset();
},

Expand Down
7 changes: 3 additions & 4 deletions js/energy-skate-park/measure/view/MeasureScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ define( require => {
this.addChild( comboBoxParent );

// @private - for layout
this.pathSensor = new SkaterPathSensorNode( model.skaterSamples, model.sensorPositionProperty, this.modelViewTransform, this.controlPanel, {
this.pathSensor = new SkaterPathSensorNode( model.skaterSamples, model.sensorProbePositionProperty, model.sensorBodyPositionProperty, this.modelViewTransform, this.controlPanel, {
tandem: tandem.createTandem( 'pathSensor' )
} );
this.pathSensor.top = this.modelViewTransform.modelToViewDeltaY( -2 );

// insert the samples and measure into the layering so that the measurable path is above the track but below
// the skater, and the sensor is below the measuring tape to avoid occlusion
Expand Down Expand Up @@ -89,8 +88,8 @@ define( require => {
// in the measure screen the legend is in the top left of the screen
this.pieChartLegend.mutate( { top: this.controlPanel.top, left: this.fixedLeft } );

this.pathSensor.top = this.pieChartLegend.bottom + 10;
this.pathSensor.left = this.fixedLeft;
// position the body relative to the pie chart legend, this sets the origin of the body (top left)
this.model.sensorBodyPositionProperty.set( this.modelViewTransform.viewToModelXY( this.fixedLeft, this.pieChartLegend.bottom + 10 ) );

// control panel is taller for this screen so move the measuring tape to a different place
if ( this.showMeasuringTape ) {
Expand Down
42 changes: 24 additions & 18 deletions js/energy-skate-park/measure/view/SkaterPathSensorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ define( require => {

/**
* @param {ObservableArray.<SkaterSample>} samples
* @param {Vector2Property} sensorPositionProperty
* @param {ModelViewTransform} modelViewTransform
* @param {Vector2Property} sensorProbePositionProperty
* @param {Vector2Property} sensorBodyPositionProperty
* @param {ModelViewTransform} modelViewTransform
* @param {EnergySkateParkControlPanel} controlPanel - so the readout doesn't occlude control panel bounds
* @param {object} options
* @returns {ObservableArray.<SkaterSample>}
* @param {object} options
* @returns {ObservableArray.<SkaterSample>}
*/
constructor( samples, sensorPositionProperty, modelViewTransform, controlPanel, options ) {
constructor( samples, sensorProbePositionProperty, sensorBodyPositionProperty, modelViewTransform, controlPanel, options ) {
options = _.extend( {

// prevent block fitting so that things don't jiggle as the probe moves, see
// prevent block fitting so that things don't jiggle as the probe moves, see
preventFit: true
}, options );
super( options );
Expand Down Expand Up @@ -157,25 +158,35 @@ define( require => {
} );
body.addChild( content );

sensorBodyPositionProperty.link( ( bodyPosition ) => {
body.leftTop = modelViewTransform.modelToViewPosition( bodyPosition );
} );

// the probe
this.probeNode = new ProbeNode( {
scale: 0.40,
rotation: Math.PI / 2,
sensorTypeFunction: ProbeNode.crosshairs(),
center: modelViewTransform.modelToViewPosition( sensorPositionProperty.get() ),
center: modelViewTransform.modelToViewPosition( sensorProbePositionProperty.get() ),
cursor: 'pointer'
} );

sensorProbePositionProperty.link( ( position ) => {
this.probeNode.translation = modelViewTransform.modelToViewPosition( position );
} );

// points and control points for the wire
const p1Property = new Property( body.getCenterBottom().minusXY( 0, 5 ) );
const normal1Property = new DerivedProperty( [ sensorPositionProperty ], ( sensorPosition ) => {

const p1Property = new DerivedProperty( [ sensorBodyPositionProperty ], ( bodyPosition ) => {
return body.getCenterBottom().minusXY( 0, 5 );
} );
const normal1Property = new DerivedProperty( [ sensorProbePositionProperty, sensorBodyPositionProperty ], ( sensorPosition ) => {

// changes with the probe position so the wire looks like it has slack as it gets longer
const viewPosition = modelViewTransform.modelToViewPosition( sensorPosition );
const distanceToBody = viewPosition.minus( p1Property.get() );
return new Vector2( distanceToBody.x / 3, Math.max( distanceToBody.y, body.height * 2 ) );
} );
const p2Property = new DerivedProperty( [ sensorPositionProperty ], ( sensorPosition ) => {
const p2Property = new DerivedProperty( [ sensorProbePositionProperty ], ( sensorPosition ) => {

// calculate the left of the probe in view coordinates
const viewPosition = modelViewTransform.modelToViewPosition( sensorPosition );
Expand All @@ -200,7 +211,7 @@ define( require => {

// display the sample that is close to the sample of the probe - find the closest one in case multiple samples
// are near the probe center
sensorPositionProperty.link( ( modelPosition ) => {
sensorProbePositionProperty.link( ( modelPosition ) => {

// clear the previous sample
this.inspectedSample && this.clearDisplay( this.inspectedSample );
Expand All @@ -226,14 +237,9 @@ define( require => {
// add a drag listener to the probe body
this.probeNode.addInputListener( new DragListener( {
transform: modelViewTransform,
locationProperty: sensorPositionProperty,
locationProperty: sensorProbePositionProperty,
tandem: options.tandem.createTandem( 'dragListener' )
} ) );

// translate the probeNode with the positionProperty
sensorPositionProperty.link( ( position ) => {
this.probeNode.translation = modelViewTransform.modelToViewPosition( position );
} );
}

/**
Expand Down

0 comments on commit e5b3075

Please sign in to comment.