3
$\begingroup$

I would like to get the tossing feature in the IOS app to work in the Mathematica pc version. See the video below at the 8:50 mark to see the tossing feature in IOS. Is this possible on a pc? Is it possible with touchscreen pc? How would I go about enabling this feature programmatically in Mathematica 11?

Please see the video below at the 8:50 mark.

Wolfram Player for IOS

$\endgroup$
2
$\begingroup$

I'm pretty sure it's not built-in in desktop.

If you want to roll this yourself you can (but it gets a bit gross).

Here's the prototype code I've been working with, based on, in a sense, computing an angular momentum for the ViewMatrix.

Clear[tossableGraphic];
Options[tossableGraphic] =
  Join[
   Options[Graphics3D],
   Options[DynamicWrapper]
   ];
tossableGraphic[g_, showView : True | False : False, 
  ops : OptionsPattern[]] :=
 DynamicModule[
  {
   viewPoint = OptionValue[ViewPoint],
   viewAngle = OptionValue[ViewAngle],
   viewVertical = OptionValue[ViewVertical],
   viewCenter = OptionValue[ViewCenter],
   viewMatOld,
   timeStart = None,
   timeEnd = None,
   momTime,
   momTimeNew,
   viewMom,
   calcMom,
   setViewMat,
   resetMom,
   movedFlag
   },
  If[showView,
    Column[{
       #,
       ViewPoint -> Dynamic[viewPoint],
       ViewAngle -> Dynamic[viewAngle],
       ViewVertical -> Dynamic[viewVertical],
       ViewCenter -> Dynamic[viewCenter]
       }] &,
    Identity
    ]@
   DynamicWrapper[
    EventHandler[
     Graphics3D[
      g,
      FilterRules[
       {
        ViewPoint -> Dynamic[viewPoint],
        ViewAngle -> Dynamic[viewAngle],
        ViewVertical -> Dynamic[viewVertical],
        ViewCenter -> Dynamic[viewCenter],
        ops
        },
       Options[Graphics3D]
       ]
      ],
     {
      "MouseDown" :>
       (
        timeStart = Now;
        resetMom[];
        setViewMat[]
        ),
      "MouseDragged" :>
       (
        resetMom[];
        If[! ListQ@viewMatOld[[1]],
         viewMatOld[[1]] =
          Replace[viewPoint, Except[_List] -> {0, 0, 0}]
         ];
        If[! ListQ@viewMatOld[[3]],
         viewMatOld[[3]] =
          Replace[viewVertical, Except[_List] -> {0, 0, 0}]
         ];
        movedFlag = True
        ),
      "MouseUp" :>
       (
        timeEnd = Now;
        calcMom[]
        ),
      PassEventsDown -> True
      }
     ],
    If[! DateObjectQ@momTime, momTime = Now];
    momTimeNew = Now;
    With[{
      tDiff =
       QuantityMagnitude[
        UnitConvert[momTimeNew - momTime, "Seconds"]
        ]
      },
     If[viewPoint =!= Automatic,
      Replace[viewMom[[1]],
       {ts_, vecs_} :>

        With[{r = RotationMatrix[ts*tDiff, vecs]},
         If[MatchQ[r, {__List}],
          viewPoint = r.viewPoint
          ]
         ]
       ]
      ];
     If[viewVertical =!= Automatic,
      Replace[viewMom[[3]],
       {ts_, vecs_} :>

        With[{r = RotationMatrix[ts*tDiff, vecs]},
         If[MatchQ[r, {__List}],
          viewVertical = r.viewVertical
          ]
         ]
       ]
      ]
     ];
    momTime = Now,
    Evaluate@FilterRules[
      {
       TrackedSymbols :> {viewMom},
       ops,
       UpdateInterval -> .1
       },
      Options[DynamicWrapper]
      ]
    ],
  Initialization :>
   {
    resetMom[] :=

     viewMom = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
    resetMom[],
    setViewMat[] :=
     viewMatOld =
      {
       viewPoint,
       viewAngle,
       viewVertical,
       viewCenter
       },
    setViewMat[],
    calcMom[] :=
     (
      If[movedFlag &&

        AllTrue[{timeStart, timeEnd}, DateObjectQ],
       viewMom =
        Replace[viewMom, Automatic -> {0, 0, 0}, 1];
       With[{ts = 
          QuantityMagnitude@
           UnitConvert[timeEnd - timeStart, "Seconds"]},
        viewMom[[1]] =
         {
          1/ts,
          {
           Replace[viewMatOld[[1]], Automatic -> {0, 0, 0}],
           viewPoint
           }
          };
        viewMom[[3]] =
         {
          1/ts,
          {
           Replace[viewMatOld[[3]], Automatic -> {0, 0, 0}],
           viewVertical
           }
          }
        ];
       Replace[viewMom, Automatic -> {0, 0, 0}, 1]
       ];
      movedFlag = False;
      timeStart = None;
      timeEnd = None
      )
    }
  ]

It works if you swipe directly up:

tossableGraphic[{Sphere[], Sphere[{1, 0, 0}]}]

asd

But any other direction leads to funkiness:

badbadbad

To get this to work properly would require a complete understanding of the the different components of the ViewMatrix combine to give the view we see.

With that in hand, it would be possible to implement this, and would even be possible to introduce a damping like they show in that video.

Unfortunately I don't really want to get into the details of parsing the ViewMatrix bits right now, so consider this a template for an answer, not an answer itself.

| improve this answer | |
$\endgroup$
  • $\begingroup$ @MichaelMcCain you should put in a suggestion or post the same question on Wolfram Community (WRI is generally more responsive there). $\endgroup$ – b3m2a1 Dec 19 '17 at 23:33
  • $\begingroup$ I will do that. $\endgroup$ – Michael McCain Dec 20 '17 at 1:01
  • $\begingroup$ You should also like (on both) that this a cross-posting so that people know to look one place or the other. See some of Kuba's posts to get a sense for what I mean. $\endgroup$ – b3m2a1 Dec 20 '17 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.