|
@@ -179,14 +179,52 @@ module BABYLON.GUI {
|
|
|
protected _computeAlignment(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
|
|
|
this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
|
|
|
this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Move one end of the line given 3D cartesian coordinates.
|
|
|
+ * @param position Targeted world position
|
|
|
+ * @param scene Scene
|
|
|
+ * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
|
|
|
+ */
|
|
|
+ public moveToVector3(position: Vector3, scene: Scene, end: boolean = false): void {
|
|
|
+ if (!this._host || this._root !== this._host._rootContainer) {
|
|
|
+ Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var globalViewport = this._host._getGlobalViewport(scene);
|
|
|
+ var projectedPosition = Vector3.Project(position, Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
|
|
|
|
|
|
- public _moveToProjectedPosition(projectedPosition: Vector3): void {
|
|
|
- this.x1 = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
|
|
|
- this.y1 = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
|
|
|
+ this._moveToProjectedPosition(projectedPosition, end)
|
|
|
|
|
|
- this._x1.ignoreAdaptiveScaling = true;
|
|
|
- this._y1.ignoreAdaptiveScaling = true;
|
|
|
+ if (projectedPosition.z < 0 || projectedPosition.z > 1) {
|
|
|
+ this.notRenderable = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.notRenderable = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Move one end of the line to a position in screen absolute space.
|
|
|
+ * @param projectedPosition Position in screen absolute space (X, Y)
|
|
|
+ * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
|
|
|
+ */
|
|
|
+ public _moveToProjectedPosition(projectedPosition: Vector3, end: boolean = false): void {
|
|
|
+ let x: string = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
|
|
|
+ let y: string = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
|
|
|
+
|
|
|
+ if (end) {
|
|
|
+ this.x2 = x;
|
|
|
+ this.y2 = y;
|
|
|
+ this._x2.ignoreAdaptiveScaling = true;
|
|
|
+ this._y2.ignoreAdaptiveScaling = true;
|
|
|
+ } else {
|
|
|
+ this.x1 = x;
|
|
|
+ this.y1 = y;
|
|
|
+ this._x1.ignoreAdaptiveScaling = true;
|
|
|
+ this._y1.ignoreAdaptiveScaling = true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|