/** * Multiple updates may happen per frame, they are batched and updated once in the view step to improve performance. * @override * @protected - CCKCLightBulbNode calls updateRender for its child socket node */ updateRender() { const startPosition = this.circuitElement.startPositionProperty.get(); const endPosition = this.circuitElement.endPositionProperty.get(); const angle = endPosition.minus( startPosition ).angle + Math.PI / 4; // Update the node transform in a single step, see #66 this.contentNode.setMatrix( SCRATCH_MATRIX.setToTranslationRotationPoint( startPosition, angle ) ); }
/** * Multiple updates may happen per frame, they are batched and updated once in the view step to improve performance. * @override * @protected - CCKCLightBulbNode calls updateRender for its child socket node */ updateRender() { const startPosition = this.circuitElement.startPositionProperty.get(); const endPosition = this.circuitElement.endPositionProperty.get(); const angle = Vector2.getAngleBetweenVectors( startPosition, endPosition ) + Math.PI / 4; // Update the node transform in a single step, see #66 SCRATCH_MATRIX.setToTranslationRotationPoint( startPosition, angle ); this.contentNode.setMatrix( SCRATCH_MATRIX ); this.rayNodeContainer.setMatrix( SCRATCH_MATRIX ); this.highlightNode && this.highlightNode.setMatrix( SCRATCH_MATRIX ); this.socketNode && this.socketNode.updateRender(); }
/** * Multiple updates may happen per frame, they are batched and updated once in the view step to improve performance. * @protected - CCKCLightBulbNode calls updateRender for its child socket node */ updateRender() { const startPosition = this.circuitElement.startPositionProperty.get(); const endPosition = this.circuitElement.endPositionProperty.get(); if ( startPosition.equals( endPosition ) ) { // We are (hopefully!) in the middle of updating both vertices and we (hopefully!) will receive another callback // shortly with the correct values for both startPosition and endPosition // See https://github.com/phetsims/circuit-construction-kit-common/issues/413 // assert && timer.setTimeout( function() { // assert && assert( !this.circuitElement.startPositionProperty.get().equals( this.circuitElement.endPositionProperty.get() ), 'vertices cannot be in the same spot' ); // }, 0 ); return; } const angle = Vector2.getAngleBetweenVectors( startPosition, endPosition ); const magnitude = Vector2.getDistanceBetweenVectors( startPosition, endPosition ); // Update the node transform in a single step, see #66 matrix.setToTranslationRotationPoint( startPosition, angle ); this.contentNode.setMatrix( matrix ); if ( this.highlightNode && this.circuitLayerNode.circuit.selectedCircuitElementProperty.get() === this.circuitElement ) { this.highlightNode.setMatrix( matrix ); } // Update the fire transform const flameExtent = 0.8; const scale = magnitude / fireImage.width * flameExtent; const flameMargin = ( 1 - flameExtent ) / 2; const flameX = magnitude * flameMargin / scale; const flameY = -fireImage.height; matrix.multiplyMatrix( rotationMatrix.setToScale( scale ) ) .multiplyMatrix( rotationMatrix.setToTranslation( flameX, flameY ) ); this.fireNode && this.fireNode.setMatrix( matrix ); }