-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mechamarkers input to bar screen,
- Loading branch information
Showing
4 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2020, University of Colorado Boulder | ||
|
||
/** | ||
* This file is to prototype mechamarkers as an input controller to proportion | ||
* @author Michael Kauzmann (PhET Interactive Simulations) | ||
*/ | ||
|
||
import Utils from '../../../../dot/js/Utils.js'; | ||
import proportion from '../../proportion.js'; | ||
import MarkerInput from '../../../../tangible/js/MarkerInput.js'; | ||
|
||
// constants | ||
const BASE_MARKER = 1; | ||
const RATIO_MARKER_A = 2; | ||
const RATIO_MARKER_B = 3; | ||
|
||
// tweak this as needed depending on the input camera | ||
const HEIGHT_OF_ONE = 600; | ||
|
||
class ProportionMarkerInput extends MarkerInput { | ||
|
||
/** | ||
* @param {ProportionModel} model | ||
*/ | ||
static init( model ) { | ||
|
||
// initialize Mechamarkers with GFL specific update function. | ||
super.init( Mechamarkers => { | ||
|
||
// must have the base marker | ||
if ( Mechamarkers.getMarker( BASE_MARKER ).present ) { | ||
|
||
// handle first ratio marker | ||
if ( Mechamarkers.getMarker( RATIO_MARKER_A ).present ) { | ||
const heightOfA = Mechamarkers.getMarker( BASE_MARKER ).center.y - Mechamarkers.getMarker( RATIO_MARKER_A ).center.y; | ||
|
||
// TODO: why clamp at 0/1? | ||
model.leftValueProperty.value = Utils.clamp( heightOfA / HEIGHT_OF_ONE, 0, 1 ); | ||
} | ||
|
||
// handle second ratio marker | ||
if ( Mechamarkers.getMarker( RATIO_MARKER_B ).present ) { | ||
const heightOfB = Mechamarkers.getMarker( BASE_MARKER ).center.y - Mechamarkers.getMarker( RATIO_MARKER_B ).center.y; | ||
model.rightValueProperty.value = Utils.clamp( heightOfB / HEIGHT_OF_ONE, 0, 1 ); | ||
} | ||
} | ||
} ); | ||
} | ||
} | ||
|
||
proportion.register( 'ProportionMarkerInput', ProportionMarkerInput ); | ||
export default ProportionMarkerInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters