-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New component: ScaleHeightSlider #107
Comments
A worry I have about this, upon first draft implementation, is that it seems the slider wont fit when the panels are set for dev bounds. Any ideas @DianaTavares ? (Again, this is a first draft, far from the final look of the feature) |
Above commit implements most of the feature, but there's some necessary work: For this to properly function, the scale has to have Pushing and leaving a TODO for us to work on this together. |
@AgustinVallejo took a look about how if canMove is false, the physics body is static (can't get pushed around), but if canMove is true, then we get input listeners. We should determine how best to handle this, but when canMove is true, we still get the scale "bouncing" as an object is put on it, so probably we want to investigate using isStatic:true in some form (maybe needing to toggle it to update the position??). |
@samreid and I basically got to a commit point on this today. It involved recognizing the scale as a "KINEMATIC" body type, which isn't supported by density/buoyancy, but is in P2. We just need to add support for this. @samreid saw this as a pretty standard third body type, so a general supporting feature to PhysicsEngine seems possible and nice. Subject: [PATCH] can't move ground scale, https://github.com/phetsims/buoyancy/issues/113
---
Index: js/buoyancy/model/BuoyancyLabModel.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/buoyancy/model/BuoyancyLabModel.ts b/js/buoyancy/model/BuoyancyLabModel.ts
--- a/js/buoyancy/model/BuoyancyLabModel.ts (revision fef8d2d2d41e83302a53f0e7e7aba6ed3b78c567)
+++ b/js/buoyancy/model/BuoyancyLabModel.ts (date 1712356266269)
@@ -28,6 +28,7 @@
public readonly densityExpandedProperty: Property<boolean>;
public readonly showFluidDisplacedProperty: Property<boolean>;
public readonly poolScaleHeightProperty: NumberProperty;
+ public readonly poolScale: Scale;
public constructor( options: BuoyancyLabModelOptions ) {
@@ -65,9 +66,9 @@
} );
// Pool scale
- const poolScaleDefaultPosition = new Vector2( 0.35, -Scale.SCALE_BASE_BOUNDS.minY + 0.5 * this.poolBounds.minY );
- const poolScale = new Scale( this.engine, this.gravityProperty, {
- matrix: Matrix3.translation( poolScaleDefaultPosition.x, poolScaleDefaultPosition.y ),
+ this.poolScale = new Scale( this.engine, this.gravityProperty, {
+ // TODO: DUplicateion with propert listener in screen view,https://github.com/phetsims/density-buoyancy-common/issues/107
+ matrix: Matrix3.translation( 0.35, this.poolBounds.minY + Scale.SCALE_HEIGHT / 2 ),
displayType: DisplayType.NEWTONS,
tandem: tandem.createTandem( 'poolScale' ),
canMove: false, //TODO This should be true, but first some work is needed https://github.com/phetsims/density-buoyancy-common/issues/107
@@ -76,17 +77,11 @@
}
} );
- poolScale.startDrag( poolScale.matrix.translation );
-
- this.poolScaleHeightProperty.lazyLink( height => {
- const modelHeight = -0.5 * ( 2 - height ) * this.poolBounds.height - 2 * Scale.SCALE_BASE_BOUNDS.minY;
- poolScale.updateDrag( poolScale.matrix.translation.setXY( poolScaleDefaultPosition.x, modelHeight ) );
- } );
-
- this.availableMasses.push( poolScale );
+ // Make sure to render it
+ this.availableMasses.push( this.poolScale );
// Adjust pool volume so that it's at the desired value WITH the pool scale inside.
- this.pool.liquidVolumeProperty.value -= poolScale.volumeProperty.value;
+ this.pool.liquidVolumeProperty.value -= this.poolScale.volumeProperty.value;
this.pool.liquidVolumeProperty.setInitialValue( this.pool.liquidVolumeProperty.value );
}
Index: js/common/model/P2Engine.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/model/P2Engine.ts b/js/common/model/P2Engine.ts
--- a/js/common/model/P2Engine.ts (revision fef8d2d2d41e83302a53f0e7e7aba6ed3b78c567)
+++ b/js/common/model/P2Engine.ts (date 1712352270856)
@@ -319,7 +319,7 @@
*/
public createBox( width: number, height: number, isStatic?: boolean ): PhysicsEngineBody {
const body = new p2.Body( {
- type: isStatic ? p2.Body.STATIC : p2.Body.DYNAMIC,
+ type: isStatic === 'KINEMATIC' ? p2.Body.KINEMATIC : isStatic ? p2.Body.STATIC : p2.Body.DYNAMIC,
fixedRotation: true
} );
Index: js/buoyancy/view/BuoyancyLabScreenView.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/buoyancy/view/BuoyancyLabScreenView.ts b/js/buoyancy/view/BuoyancyLabScreenView.ts
--- a/js/buoyancy/view/BuoyancyLabScreenView.ts (revision fef8d2d2d41e83302a53f0e7e7aba6ed3b78c567)
+++ b/js/buoyancy/view/BuoyancyLabScreenView.ts (date 1712356268749)
@@ -32,6 +32,8 @@
import ScaleView from '../../common/view/ScaleView.js';
import Bounds2 from '../../../../dot/js/Bounds2.js';
import ScaleHeightSlider from '../../common/view/ScaleHeightSlider.js';
+import Utils from '../../../../dot/js/Utils.js';
+import Scale from '../../common/model/Scale.js';
// constants
const MARGIN = DensityBuoyancyCommonConstants.MARGIN;
@@ -183,6 +185,25 @@
waterLevelSlider.bottom = bottomRightPoolPoint.y;
waterLevelSlider.left = bottomRightPoolPoint.x + 5;
};
+ const halfScaleHeight = Scale.SCALE_HEIGHT / 2;
+ const maxY = model.pool.liquidYInterpolatedProperty.value - halfScaleHeight;
+
+ model.poolScaleHeightProperty.link( height => {
+
+ const minY = model.poolBounds.minY + halfScaleHeight;
+
+ const currentHeight = Utils.linear( 0, 1, minY, maxY, height );
+
+ model.poolScale.matrix.set12( currentHeight );
+ model.poolScale.writeData();
+ model.poolScale.transformedEmitter.emit();
+
+ // const modelHeight = -0.5 * ( 2 - height ) * model.poolBounds.height - 2 * Scale.SCALE_BASE_BOUNDS.minY;
+ // const newPosition = poolScale.matrix.translation.setXY( poolScaleDefaultPosition.x, modelHeight );
+ // poolScale.body.position[ 1 ] = currentHeight;
+ } );
+
+
}
private static getFluidDisplacedPanelScaleIcon(): Node {
Index: js/common/model/Scale.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/model/Scale.ts b/js/common/model/Scale.ts
--- a/js/common/model/Scale.ts (revision fef8d2d2d41e83302a53f0e7e7aba6ed3b78c567)
+++ b/js/common/model/Scale.ts (date 1712352270860)
@@ -79,7 +79,7 @@
public constructor( engine: PhysicsEngine, gravityProperty: TProperty<Gravity>, providedOptions: ScaleOptions ) {
const config = optionize<ScaleOptions, SelfOptions, InstrumentedMassOptions>()( {
- body: engine.createBox( SCALE_WIDTH, SCALE_HEIGHT, providedOptions.canMove === false ),
+ body: engine.createBox( SCALE_WIDTH, SCALE_HEIGHT, 'KINEMATIC' ),
shape: Shape.rect( -SCALE_WIDTH / 2, -SCALE_HEIGHT / 2, SCALE_WIDTH, SCALE_HEIGHT ),
volume: SCALE_VOLUME,
massShape: MassShape.BLOCK, |
Signed-off-by: Michael Kauzmann <michael.kauzmann@colorado.edu>
Signed-off-by: Michael Kauzmann <michael.kauzmann@colorado.edu>
I got to a commit point. It turns out we didn't need KINEMATIC after all, you can move static objects around too. Still some TODOs and design questions. |
Next steps here:
|
Signed-off-by: Michael Kauzmann <michael.kauzmann@colorado.edu>
Signed-off-by: Michael Kauzmann <michael.kauzmann@colorado.edu>
Signed-off-by: Michael Kauzmann <michael.kauzmann@colorado.edu>
Signed-off-by: Michael Kauzmann <michael.kauzmann@colorado.edu>
@DianaTavares, please note that I believe it will be fastest and easiest to discuss this issue in person from here. All work for me is done.
This is because the p2 engine uses a stiffness that allows for some overlap. |
From design discussion: (1): scale taking up volume and block buoyant force
(2) slider movement vs scale movement
(3) slider thumb overlapping with panels
|
Achieved this, but I'm not confortable with the solution. Currently it's hard-coded so the slider's height is 125 (previously it was 150)... I would very much like this number to be obtained from the pool and scale's dimensions, but my first attempts failed. Left a TODO and will check later. |
@DianaTavares Please review and close if ready :) |
The slider is amazing!! Thanks!! |
I'm seeing that the slider doesn't quite align with the bottom of the scale. I believe this is because of the z dimention, and should be an easy offset, especially now that we have a THREE-supported MVT from #113. I'll take a look. |
Two thoughts here:
Subject: [PATCH] custom margins when space is tight, https://github.com/phetsims/buoyancy/issues/144
---
Index: js/buoyancy/view/BuoyancyLabScreenView.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/buoyancy/view/BuoyancyLabScreenView.ts b/js/buoyancy/view/BuoyancyLabScreenView.ts
--- a/js/buoyancy/view/BuoyancyLabScreenView.ts (revision 905b50bcb4a7becc66fe06087a93acb6324e9b2d)
+++ b/js/buoyancy/view/BuoyancyLabScreenView.ts (date 1713562889583)
@@ -213,7 +213,7 @@
const bottomRightPoolPoint = this.modelToViewPoint( new Vector3(
this.model.poolBounds.maxX,
this.model.poolBounds.minY,
- this.model.poolBounds.maxZ
+ this.model.poolScale.getBounds().maxZ
) );
scaleHeightSlider.bottom = bottomRightPoolPoint.y;
scaleHeightSlider.left = bottomRightPoolPoint.x + DensityBuoyancyCommonConstants.MARGIN / 2;
|
Signed-off-by: Michael Kauzmann <michael.kauzmann@colorado.edu>
Signed-off-by: Michael Kauzmann <michael.kauzmann@colorado.edu>
Alright. I think I have gotten this. @AgustinVallejo, can you give me a spot check? It is complex, but it was the best I could think of. Two things here:
|
Looks like we aren't handling the reset case. |
Signed-off-by: Michael Kauzmann <michael.kauzmann@colorado.edu>
Ok. We are now resetting the Property. @AgustinVallejo, ready for review now (I hope). |
Really happy with the final look of this component, thanks!! |
From phetsims/buoyancy#113, the scale in the water on the lab screen will be a bit different.
The slider should be "attached" to the scale, and the height adjusted accordingly.
The text was updated successfully, but these errors were encountered: