[SOLVED] VR moving Quad relative to headset movement

Hello,
I have a VR application I am trying to feed stereo video to the perspective eye;
Leye = new Material(getAssetManager(), “jmevr/shaders/Unshaded.j3md”);
Reye = new Material(getAssetManager(), “jmevr/shaders/Unshaded.j3md”);
viewLeft = VRApplication.getLeftViewPort();
viewRight = VRApplication.getRightViewPort();

    quad1 = new Quad(16, 9); // replace the definition of Vertex and Textures Coordinates plus indexes

    geo1 = new Geometry("leftQuad", quad1); // using Quad object        
    geo1.setMaterial(Leye);

    quad2 = new Quad(16, 9); // replace the definition of Vertex and Textures Coordinates plus indexes
    geo2 = new Geometry("rightQuad", quad2); // using Quad object        
    geo2.setMaterial(Reye);
    geo1.setCullHint(Spatial.CullHint.Dynamic); // make sure we see it 
    geo2.setCullHint(Spatial.CullHint.Dynamic); // make sure we see it

    viewLeft.getCamera().getLocation();
    viewLeft.getCamera().getDirection();
    viewLeft.getCamera().getFrustumFar();

    viewLeft.attachScene(geo1);
    viewRight.attachScene(geo2);

I see the video( frames actually opencv,grabs frames from video, AWTloads it to texture)
The Problem is the quads dont move with the head movement in the VR? I have attach them and they show, but dont move with the view in my head set. What do I need to do to make the quads stay in view and move with the view in the headset?

Something like this:

geo1.setLocalTranslation(vrAppState.getFinalObserverPosition());
geo1.move(vrAppState.getFinalObserverRotation().mult(SOME_DISTANCE_AWAY));
geo1.setLocalRotation(vrAppState.getFinalObserverRotation());
geo1.rotate(0, FastMath.PI, 0);
geo2.setLocalTransform(geo1);

Also updateGeometricState since they’re not attached to the rootNode.

1 Like

Thank you sir, I’m on track. The information was very helpful I am seeing what I think I should see.
now.
here is the code snip:

      Vector3f v = VRApplication.getFinalObserverPosition();
        Quaternion q = VRApplication.getFinalObserverRotation();
        vpL = VRApplication.getLeftViewPort();
        vpR = VRApplication.getRightViewPort();

        // viewLeft.attachScene(geo1);
        // viewRight.attachScene(geo2);
         vpR.clearScenes();
         vpL.clearScenes();
         vpL.detachScene(geo1);
         vpR.detachScene(geo2);
         vpL.attachScene(geo1);
         vpR.attachScene(geo2);
        
        geo1.setLocalTranslation(v);
        geo1.move(VRApplication.getFinalObserverRotation().mult(new Vector3f(8.0f, -5.5f, 15.0f)));
        geo1.setLocalRotation(q);
        geo1.rotate(0, FastMath.PI, 0);
        geo2.setLocalTranslation(v);
        geo2.move(VRApplication.getFinalObserverRotation().mult(new Vector3f(8.0f, -5.5f, 15.0f)));
        geo2.setLocalRotation(q);
        geo2.rotate(0, FastMath.PI, 0);
        geo1.updateGeometricState();
        geo2.updateGeometricState();
1 Like