The forum on this site is closed for new comments and posts. Continue the conversation in our Snap AR Discord server.

Smoothing out Noisey Input Data

  • Hi Sava,

    For rotations, it's usually better to work in quaternions than euler angles. You can do something like this to get the Y and Z angle deltas:

    //@input SceneObject obj1
    //@input SceneObject obj2

    // Returns the delta quaternion
    function getDiff(q1, q2){
    return q2.multiply(q1.invert());
    }

    // Returns Y rotation of a quaternion
    function getYRot(q){
    return Math.atan(q.y, q.w);
    }

    // Returns Z rotation of a quaternion
    function getZRot(q){
    return Math.atan(q.z, q.w);
    }

    var t1 = script.obj1.getTransform();
    var t2 = script.obj2.getTransform();

    var diff = getDiff(
    t1.getWorldRotation(),
    t2.getWorldRotation()
    );

    print("y: " + getYRot(diff));
    print("z: " + getZRot(diff));

    Hope this helps! Looks like a really cool lens!

    Comment actions Permalink
  • Hey! That works! Never thought I'd learn a useful math lesson on how Euler coordinates aren't reliable for rotation lol. My one concern is this method seems fairly resource intensive. Are there any computationaly cheap ways to approximate the Y/Z components without using arctan?

     

    Edit: I want to use the following formula:

     

    I'm just a little uncertain what the function does with q.z, comma q.w. is it simply arcatan(q.z/q.w)?

    Math.atan(q.z, q.w)
    Comment actions Permalink
  • Hi Sava! 

    Glad you're thinking about performance! Did you see some performance slow down when you used it? 

    The Math.atan function is actually the built in javascript function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2. 

    The first argument is the Y coordinate, and the second is the X coordinate of a point, where the arctan is the (counter clockwise) angle to the (positive) x axis (between -PI, PI). 

    Can't wait to see the result! Looks awesome!

    Jon

    Comment actions Permalink
  • When I initially tried it the frame rate seems low, but after I restarted the app, it was running smooth. I guess I'll keep Math.atan for now, and figure out a cheap approximation later, if the need arises.

    Thanks for all the help guys,

     

    Sava

    Comment actions Permalink

We're here to help! We just need a little bit of information...

What system are you using?

Have you downloaded the latest version of Lens Studio?

Please download the latest version of Lens Studio. If you still run into this issue, please come back and report it!

Is this issue causing Lens Studio to crash?

What system do you run Lens Studio on?

Version

Graphics

Follow the next steps to help us solve your issue:

  • Copy and paste this text into your TerminalCommand Window
    open ~/Library/Preferences/Snap/Lens\ Studio/ %LOCALAPPDATA%\Snap\Lens Studio Copy Text
  • Press ReturnEnter to run the command. The Lens Studio folder will automatically open
  • Prepare to upload your files: zip the "Log" Folder by right-clicking and choosing "compress."
    Locate the Log.txt file right above it.

    Attach a screenshot of the issue:

Name:

Email:

What is this most relevant to?

Please enter a brief description of your issue:

Thanks for submitting this issue.

Unfortunately, it's likely due to the operating system or hardware you're using – since they don't meet the system requirements for Lens Studio.

Still, we hear you loud and clear, and are logging the issue in case there's ever a workaround we can provide!

Minimum Requirements

Operating System: Windows 10 (64 bit); MacOS 10.11+

Hardware: Minimum of Intel Core i3 2.5Ghz or AMD Phenom II 2.6Ghz with 4 GB RAM; Intel HD Graphics 4000 / Nvidia GeForce 710 / AMD Radeon HD 6450 or better; screen resolution of 1280x768 or higher

We'll try to resolve this issue as soon as possible. Thanks for letting us know about it!

Keep an eye out for a followup email from us. We may have a couple more questions for you, or we might already have a solution to offer.

Happy creating!