aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/PhysicsSimulationWeight.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/PhysicsSimulationWeight.tsx')
-rw-r--r--src/client/views/nodes/PhysicsSimulationWeight.tsx95
1 files changed, 52 insertions, 43 deletions
diff --git a/src/client/views/nodes/PhysicsSimulationWeight.tsx b/src/client/views/nodes/PhysicsSimulationWeight.tsx
index e7bd86915..fc75fa5aa 100644
--- a/src/client/views/nodes/PhysicsSimulationWeight.tsx
+++ b/src/client/views/nodes/PhysicsSimulationWeight.tsx
@@ -8,20 +8,25 @@ export interface IForce {
directionInDegrees: number;
}
export interface IWeightProps {
- dataDoc: Doc;
+ adjustPendulumAngle: boolean;
color: string;
+ dataDoc: Doc;
mass: number;
- wedge: boolean;
radius: number;
+ simulationReset: boolean;
+ startPosX: number;
+ startPosY: number;
startVelX?: number;
startVelY?: number;
timestepSize: number;
+ updateDisplay: boolean,
walls: IWallProps[];
- wedgeWidth: number;
+ wedge: boolean;
wedgeHeight: number;
+ wedgeWidth: number;
xMax: number;
- yMax: number;
xMin: number;
+ yMax: number;
yMin: number;
}
@@ -37,6 +42,7 @@ interface IState {
yPosition: number,
xVelocity: number,
yVelocity: number,
+ update: boolean,
}
export default class Weight extends React.Component<IWeightProps, IState> {
@@ -133,8 +139,9 @@ export default class Weight extends React.Component<IWeightProps, IState> {
}
componentDidUpdate(prevProps: Readonly<IWeightProps>, prevState: Readonly<IState>, snapshot?: any): void {
+
// When display values updated by user, update real values
- if (this.props.dataDoc['updateDisplay'] != prevProps.dataDoc['updateDisplay']) {
+ if (this.props.updateDisplay != prevProps.updateDisplay) {
if (this.props.dataDoc['positionXDisplay'] != this.state.xPosition) {
let x = this.props.dataDoc['positionXDisplay'];
x = Math.max(0, x);
@@ -167,47 +174,29 @@ export default class Weight extends React.Component<IWeightProps, IState> {
}
}
// Update sim
- if (this.state.timer != prevState.timer) {
- if (!this.props.dataDoc['simulationPaused']) {
- console.log('update')
- let collisions = false;
- if (!this.props.dataDoc['pendulum']) {
- const collisionsWithGround = this.checkForCollisionsWithGround();
- const collisionsWithWalls = this.checkForCollisionsWithWall();
- collisions = collisionsWithGround || collisionsWithWalls;
- }
- if (!collisions) {
- this.update();
- }
- this.setDisplayValues();
+ if (!this.props.dataDoc['simulationPaused']) {
+ if (this.state.timer != prevState.timer) {
+ console.log('update sim')
+ console.log('update')
+ let collisions = false;
+ if (!this.props.dataDoc['pendulum']) {
+ const collisionsWithGround = this.checkForCollisionsWithGround();
+ const collisionsWithWalls = this.checkForCollisionsWithWall();
+ collisions = collisionsWithGround || collisionsWithWalls;
+ }
+ if (!collisions) {
+ this.update();
+ }
+ this.setDisplayValues();
}
}
- this.weightStyle = {
- backgroundColor: this.props.color,
- borderStyle: "solid",
- borderColor: this.state.dragging ? "lightblue" : "black",
- position: "absolute" as "absolute",
- left: this.state.xPosition + "px",
- top: this.state.yPosition + "px",
- width: 2 * this.props.radius + "px",
- height: 2 * this.props.radius + "px",
- borderRadius: 50 + "%",
- display: "flex",
- zIndex: 5,
- justifyContent: "center",
- alignItems: "center",
- touchAction: "none",
- };
- if (this.props.dataDoc['simulationReset'] != prevProps.dataDoc['simulationReset']) {
+ if (this.props.simulationReset != prevProps.simulationReset) {
+ console.log('reset sim')
this.resetEverything();
}
- if (this.props.dataDoc['startForces'] != prevProps.dataDoc['startForces']) {
- this.setState({xVelocity: this.props.startVelX ?? 0})
- this.setState({yVelocity: this.props.startVelY ?? 0})
- this.setDisplayValues();
- }
- if (this.props.dataDoc['adjustPendulumAngle'] != prevProps.dataDoc['adjustPendulumAngle']) {
+ if (this.props.adjustPendulumAngle != prevProps.adjustPendulumAngle) {
+ console.log('update angle')
// Change pendulum angle based on input field
let length = this.props.dataDoc['pendulumLength'] ?? 0;
const x =
@@ -222,18 +211,21 @@ export default class Weight extends React.Component<IWeightProps, IState> {
this.setState({updatedStartPosY: yPos})
}
// Update x start position
- if (this.props.dataDoc['startPosX'] != prevProps.dataDoc['startPosX']) {
+ if (this.props.startPosX != prevProps.startPosX) {
+ console.log('update start x pos')
this.setState({updatedStartPosX: this.props.dataDoc['startPosX']})
this.setState({xPosition: this.props.dataDoc['startPosX']})
this.setXPosDisplay(this.props.dataDoc['startPosX']);
}
// Update y start position
- if (this.props.dataDoc['startPosY'] != prevProps.dataDoc['startPosY']) {
+ if (this.props.startPosY != prevProps.startPosY) {
+ console.log('update start y pos')
this.setState({updatedStartPosY: this.props.dataDoc['startPosY']})
this.setState({yPosition: this.props.dataDoc['startPosY']})
this.setYPosDisplay(this.props.dataDoc['startPosY']);
}
if (this.state.xVelocity != prevState.xVelocity) {
+ console.log('check for kinetic friction')
if (this.props.dataDoc['wedge'] && this.state.xVelocity != 0 && !this.state.kineticFriction) {
this.setState({kineticFriction: true});
//switch from static to kinetic friction
@@ -276,6 +268,23 @@ export default class Weight extends React.Component<IWeightProps, IState> {
}
}
}
+
+ this.weightStyle = {
+ backgroundColor: this.props.color,
+ borderStyle: "solid",
+ borderColor: this.state.dragging ? "lightblue" : "black",
+ position: "absolute" as "absolute",
+ left: this.state.xPosition + "px",
+ top: this.state.yPosition + "px",
+ width: 2 * this.props.radius + "px",
+ height: 2 * this.props.radius + "px",
+ borderRadius: 50 + "%",
+ display: "flex",
+ zIndex: 5,
+ justifyContent: "center",
+ alignItems: "center",
+ touchAction: "none",
+ };
}
resetEverything = () => {