Browse Source

Replaced all instances of onTouchMoved to onTouchDragged in the Sandbox modules.

This happened in AngleToy, MoveToToy, PickingToy, and RotateToToy. onTouchMoved does not get called on iOS or Android. It's purely a mouse function, despite the name. By switching to onTouchDragged, the toys should now work on mobile platforms. This does have a side effect on desktop platforms - users now need to mouse click down or click/drag in these toys instead of just moving the mouse.
Mike Lilligreen 11 years ago
parent
commit
8b22129d10

+ 46 - 1
modules/AngleToy/1/main.cs

@@ -212,7 +212,52 @@ function AngleToy::createMathematicalObjects( %this )
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
-function AngleToy::onTouchMoved(%this, %touchID, %worldPosition)
+function AngleToy::onTouchDown(%this, %touchID, %worldPosition)
+{
+    // Used to let the repointing target kno  
+    AngleToy.repointTarget = %worldPosition;
+
+    // Calculate the angle to the mouse.
+    %angle = mAtan( %worldPosition );
+    
+    // "Point" particles towards cursor
+    AngleToy.EmitterParameters.selectField( "EmissionAngle" );
+    AngleToy.EmitterParameters.addDataKey( 0, %angle );
+    AngleToy.EmitterParameters.deselectField();
+    
+    // Show Sin, Cos, Tan
+    %sin = mSin( %angle );
+    %cos = mCos( %angle );
+    %tan = mTan( %angle );
+
+    // Find the vector that's 20/21 units from the center in the direction of
+    // %worldPosition.  Here are a couple of ways to do that:
+    %worldPositionAtRadius20 = Vector2Direction( %angle, 20 );
+    %worldPositionAtRadius21 = Vector2Scale( Vector2Normalize( %worldPosition ), 21 );
+
+    // Draw the Sine    
+    %onYAxis = setWord( %worldPositionAtRadius20, 0, 0 ); // Set the X-component to 0
+    AngleToy.SinLineSegment.draw( %worldPositionAtRadius20, %onYAxis );
+    AngleToy.SinLabel.setPosition( Vector2Add( %onYAxis, "0 -1" ) );
+    AngleToy.SinLabel.setText( mFloatLength( %sin, 4 ) );
+    
+    // Draw the Cosine
+    %onXAxis = setWord( %worldPositionAtRadius20, 1, 0 ); // Set the Y-component to 0
+    AngleToy.CosLineSegment.draw( %worldPositionAtRadius20, %onXAxis );
+    AngleToy.CosLabel.setPosition( Vector2Add( %onXAxis, "-1 0" ) );
+    AngleToy.CosLabel.setAngle( 90 );
+    AngleToy.CosLabel.setText( mFloatLength( %cos, 4 ) );
+    
+    // Draw the Tangent
+    AngleToy.TanLineSegment.drawTangent( %worldPositionAtRadius20, %tan, %angle );
+    AngleToy.TanLabel.setPosition( %worldPositionAtRadius21 );
+    AngleToy.TanLabel.setAngle( %angle - 90 );
+    AngleToy.TanLabel.setText( mFloatLength( %tan, 4 ) );
+}
+
+//-----------------------------------------------------------------------------
+
+function AngleToy::onTouchDragged(%this, %touchID, %worldPosition)
 {
 {
     // Used to let the repointing target kno  
     // Used to let the repointing target kno  
     AngleToy.repointTarget = %worldPosition;
     AngleToy.repointTarget = %worldPosition;

+ 1 - 1
modules/MoveToToy/1/main.cs

@@ -170,7 +170,7 @@ function MoveToToy::onTouchDown(%this, %touchID, %worldPosition)
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
-function MoveToToy::onTouchMoved(%this, %touchID, %worldPosition)
+function MoveToToy::onTouchDragged(%this, %touchID, %worldPosition)
 {
 {
     // Finish if not tracking the mouse.
     // Finish if not tracking the mouse.
     if ( !MoveToToy.trackMouse )
     if ( !MoveToToy.trackMouse )

+ 53 - 1
modules/PickingToy/1/main.cs

@@ -156,7 +156,59 @@ function PickingToy::createRaycastOverlay( %this )
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
-function PickingToy::onTouchMoved(%this, %touchID, %worldPosition)
+function PickingToy::onTouchDown(%this, %touchID, %worldPosition)
+{
+    // Update cursor position.
+    PickingToy.CursorObject.Position = %worldPosition;
+    
+    // Are we in ray mode?
+    if ( PickingToy.PickType $= "ray" )
+    {
+        // Yes, so update the ray geometry.
+        PickingToy.RaycastOverlay.PolyList = PickingToy.RayStart SPC %worldPosition;
+    }    
+    
+    // Handle picking mode appropriately.
+    switch$( PickingToy.PickType )
+    {
+        case "point":
+            %picked = SandboxScene.pickPoint( %worldPosition, "", "", PickingToy.PickMode );
+        
+        case "area":
+            %halfSize = PickingToy.PickAreaSize * 0.5;
+            %lower = (%worldPosition._0 - %halfSize) SPC(%worldPosition._1 - %halfSize);    
+            %upper = (%worldPosition._0 + %halfSize) SPC(%worldPosition._1 + %halfSize);    
+            %picked = SandboxScene.pickArea( %lower, %upper, "", "", PickingToy.PickMode );
+            
+        case "ray":
+            %picked = SandboxScene.pickRay( PickingToy.RayStart, %worldPosition, "", "", PickingToy.PickMode );
+            
+        case "circle":
+            %halfSize = PickingToy.PickAreaSize * 0.5;
+            %picked = SandboxScene.pickCircle( %worldPosition, %halfSize, "", "", PickingToy.PickMode );
+    }
+        
+    // Fetch pick count.
+    %pickCount = %picked.Count;
+    
+    // See if the target object is amongst those picked.
+    for( %i = 0; %i < %pickCount; %i++ )
+    {
+        // If this is the target object then make it opaque.
+        if ( getWord( %picked, %i ) == PickingToy.TargetObject )
+        {
+            PickingToy.TargetObject.setBlendAlpha( 1.0 );
+            return;
+        }
+    }
+    
+    // Target not picked so make it transparent.
+    PickingToy.TargetObject.setBlendAlpha( 0.25 );
+}
+
+//-----------------------------------------------------------------------------
+
+function PickingToy::onTouchDragged(%this, %touchID, %worldPosition)
 {
 {
     // Update cursor position.
     // Update cursor position.
     PickingToy.CursorObject.Position = %worldPosition;
     PickingToy.CursorObject.Position = %worldPosition;

+ 1 - 1
modules/RotateToToy/1/main.cs

@@ -130,7 +130,7 @@ function RotateToToy::onTouchDown(%this, %touchID, %worldPosition)
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
-function RotateToToy::onTouchMoved(%this, %touchID, %worldPosition)
+function RotateToToy::onTouchDragged(%this, %touchID, %worldPosition)
 {
 {
     // Finish if not tracking the mouse.
     // Finish if not tracking the mouse.
     if ( !RotateToToy.trackMouse )
     if ( !RotateToToy.trackMouse )