Class VRView

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class VRView extends Container

Component that renders an application scene in virtual reality: stereo side-by-side per-eye views with sensor-fusion head tracking, built entirely on the portable com.codename1.gpu pipeline so it works on every platform where Display#isGpuSupported() is true - including the simulator.

Supply a VRRenderer that draws the scene; the view clears the frame, splits the viewport per eye, positions a VRCameraRig from the HeadTracker orientation and invokes the renderer once per eye.

IMPORTANT: VRRenderer callbacks run on the platform render thread, never on the EDT. Do not touch Codename One UI components from them.

VRView vr = new VRView(new VRRenderer() {
    Mesh cube;
    Material material;
    public void onInit(GraphicsDevice device) {
        cube = Primitives.cube(device, 0.5f);
        material = new Material(Material.Type.PHONG).setColor(0xff3366ff);
    }
    public void onEyeFrame(GraphicsDevice device, VREye eye, Camera camera) {
        device.draw(cube, material, Matrix4.translation(0, 0, -2));
    }
    public void onDispose(GraphicsDevice device) { }
});
vr.setContinuous(true);
form.add(BorderLayout.CENTER, vr);
  • Constructor Details

    • VRView

      public VRView(VRRenderer renderer)

      Creates a VR view with default settings.

      Parameters
      • renderer: draws the scene, once per eye per frame
    • VRView

      public VRView(VRRenderer renderer, VRSettings settings)

      Creates a VR view.

      Parameters
      • renderer: draws the scene, once per eye per frame

      • settings: eye separation and lens parameters; null uses defaults

  • Method Details

    • isSupported

      public boolean isSupported()
      True when the current platform provides a 3D backend. Equivalent to Display#isGpuSupported().
    • getSettings

      public VRSettings getSettings()
      The settings this view was created with.
    • getHeadTracker

      public HeadTracker getHeadTracker()
      The head tracker driving this view. Exposed to tune the fusion filter or observe the raw orientation.
    • setHeadTrackingEnabled

      public void setHeadTrackingEnabled(boolean enabled)
      Enables or disables head tracking. When disabled the last orientation freezes; combine with VRCameraRig manually for custom control.
    • isHeadTrackingEnabled

      public boolean isHeadTrackingEnabled()
      True when head tracking drives the view orientation.
    • recenter

      public void recenter()
      Rotates the view so the current direction becomes "straight ahead".
    • setStereo

      public void setStereo(boolean stereo)
      Switches between side-by-side stereo and a single centered viewpoint.
    • isStereo

      public boolean isStereo()
      True when rendering side-by-side stereo.
    • setPosition

      public void setPosition(float x, float y, float z)
      Sets the head center position in world space, for example to move the viewer through the scene.
    • setClearColor

      public void setClearColor(int argb)
      The background clear color as 0xAARRGGBB. Default opaque black.
    • setContinuous

      public VRView setContinuous(boolean continuous)
      Controls whether the view renders continuously or only when #requestRender() is called. Head tracked scenes normally want continuous rendering.
    • requestRender

      public void requestRender()
      Requests that a single frame be rendered.
    • getRenderView

      public RenderView getRenderView()
      The underlying render view, exposed for advanced integration.
    • initComponent

      protected void initComponent()
      Description copied from class: Component
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component
    • deinitialize

      protected void deinitialize()
      Description copied from class: Component
      Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.
      Overrides:
      deinitialize in class Component