Converting Nose's 3D Position values to 2D values?

659 Views Asked by At

Just wondering if this has been attempted before.

I'm making a game where by 2D objects fall from the top and I use my nose to 'catch' those objects.

Currently I have it set up in such a way that if the X and Y values for the nose and 2D object are the same, it increases the counter.

However I've noticed that the position for 3D and 2D objects both reflect very different values.

I've tried using null objects to contain the 2D canvas, but it didn't work either.

Messing around with tolerance values didn't achieve the desired effect.

Equals Patch

First number is taken from the null object, second number is taken from the nose's position.

From nullobject: -0.09079 From nose: 0.00108

Is this something to do with limitations or am I doing something wrongly here? Thanks for taking your time to read this :(

1

There are 1 best solutions below

0
On

Here is a project that translates 3D nose position to 2D screen space. I made a video on how to do it: video and here is a link to free download.

It requires a few lines of script and the Scene Module to project the 3D position to 2D screen space.

const Scene = require('Scene');
const Patches = require('Patches');

Promise.all([

    // The 3D Object or 3D Point we want to track
    Scene.root.findFirst('Nose3D'),

]).then(function (results) {

    // Define variable names for items we found
    const nose3D = results[0];

    // This transforms the world coordinate of the 3D Object to a screen coordinate.
    var nose2D = Scene.projectToScreen(nose3D.worldTransform.position)

    // Get the Nose3D Position, then set the projectToScreen point Nose2D
    Patches.outputs.getPoint("Nose3D").then(pointSignal => {

        Patches.inputs.setPoint2D('Nose2D', nose2D);

    });
});