Selaa lähdekoodia

Properly defining flicker delta and depths

rickfromwork 4 vuotta sitten
vanhempi
commit
ead1135f13
1 muutettua tiedostoa jossa 8 lisäystä ja 6 poistoa
  1. 8 6
      gui/src/3D/controls/touchButton3D.ts

+ 8 - 6
gui/src/3D/controls/touchButton3D.ts

@@ -49,17 +49,19 @@ export class TouchButton3D extends Button3D {
                 const distance = _this._collisionMesh.getAbsolutePosition().subtract(indexMesh.getAbsolutePosition()).length();
                 const distance = _this._collisionMesh.getAbsolutePosition().subtract(indexMesh.getAbsolutePosition()).length();
                 console.log(distance);
                 console.log(distance);
 
 
-                // for some reason the absolute positions don't line up? I'll have to ask about that.
-
                 const dummyPosition = Vector3.Zero();
                 const dummyPosition = Vector3.Zero();
                 const dummyPointerId = 0;
                 const dummyPointerId = 0;
                 const dummyButtonIndex = 0;// left click;
                 const dummyButtonIndex = 0;// left click;
 
 
+                const touchDepth = 0.5;
+                const hoverDepth = 0.8;
+                const flickerDelta = 0.05; // A delta to avoid state flickering when on the threshold
+
                 // Update button state and fire events
                 // Update button state and fire events
                 switch(_this._buttonState)
                 switch(_this._buttonState)
                 {
                 {
                     case ButtonState.None:
                     case ButtonState.None:
-                        if (distance < 1)
+                        if (distance < hoverDepth - flickerDelta)
                         {
                         {
                             console.log("Now hovering");
                             console.log("Now hovering");
                             _this._buttonState = ButtonState.Hover;
                             _this._buttonState = ButtonState.Hover;
@@ -68,13 +70,13 @@ export class TouchButton3D extends Button3D {
 
 
                         break;
                         break;
                     case ButtonState.Hover:
                     case ButtonState.Hover:
-                        if (distance > 1.1)
+                        if (distance > hoverDepth + flickerDelta)
                         {
                         {
                             console.log("Out of range");
                             console.log("Out of range");
                             _this._buttonState = ButtonState.None;
                             _this._buttonState = ButtonState.None;
                             _this._onPointerOut(_this);
                             _this._onPointerOut(_this);
                         }
                         }
-                        else if (distance < 0.4)
+                        else if (distance < touchDepth - flickerDelta)
                         {
                         {
                             console.log("now pressing");
                             console.log("now pressing");
                             _this._buttonState = ButtonState.Press;
                             _this._buttonState = ButtonState.Press;
@@ -87,7 +89,7 @@ export class TouchButton3D extends Button3D {
 
 
                         break;
                         break;
                     case ButtonState.Press:
                     case ButtonState.Press:
-                        if (distance > 0.5)
+                        if (distance > touchDepth + flickerDelta)
                         {
                         {
                             console.log("no longer pressing");
                             console.log("no longer pressing");
                             _this._buttonState = ButtonState.Hover;                            _this._onPointerUp(_this, dummyPosition, dummyPointerId, dummyButtonIndex, false /*notifyClick*/);
                             _this._buttonState = ButtonState.Hover;                            _this._onPointerUp(_this, dummyPosition, dummyPointerId, dummyButtonIndex, false /*notifyClick*/);