stalgiag / p5.xr

a library that helps turn p5.js sketches into immersive experiences using WebXR
GNU Lesser General Public License v2.1
117 stars 25 forks source link

Am I using setViewerPosition correctly? #119

Closed msub2 closed 3 years ago

msub2 commented 3 years ago

For some background, the whole reason I started helping out on p5.xr is that I'm currently including it in https://github.com/msub2/webxr-showcase, and I'd like to see it become more fully featured so as to stand with the likes of A-Frame, babylon.js, etc. For the current example project I'm working on across engines/frameworks/libraries, I'm implementing smooth locomotion and tracked controllers. Tracked controllers are pretty much a solved problem now, but I'm having a bit of trouble figuring out how to accomplish movement. My initial thought was to try using setViewerPosition from p5xrViewer.js, but although I can see the value changing it doesn't seem to affect my view. Is this intended, or is something not working behind the scenes? Let me know if there's something I'm missing here.

For reference, here's the code I have right now:

let x = 0;

function preload() {
    createVRCanvas();
}

function setup() {
    setVRBackgroundColor(0, 0, 255);
    angleMode(DEGREES);
}

function draw() {
    const right = getXRInput(RIGHT);
    if (right != null) {
        push();
        fill(255, 255, 255);
        applyMatrix(...right.pose);
        box(0.15);
        pop();
    }

    rotateX(-90);
    fill(0, 255, 0);
    noStroke();
    plane(10, 10);

    setViewerPosition(x, 0, 0);
    x += 0.1;

    console.log(p5xr.instance.viewer.position);
}

I should see myself slowly sliding to the side, but it doesn't seem to move me at all.

msub2 commented 3 years ago

Never mind, I did the same thing I did with LOVR and forgot to put it before actually drawing everything in my scene 🤦‍♂️