Manipulator with MATLAB® GUI in Active Stereoscopic Vision Mode

The vrmanipul_stereo3d example shows a manipulator in active stereoscopic vision mode. It illustrates the effect of stereo rendering properties and the way how to work with the stereoscopic vision VRFIGURE properties.

The manipulator will be displayed in active stereoscopic vision mode only if quad-buffered OpenGL rendering is supported by your graphics card and is enabled by the graphics card driver. Please note that stereoscopic vision effect will be visible only if you use a 3D capable monitor (or a 3D TV set) with active shutter glasses, autostereoscopic 3D monitor or similar active stereoscopic vision technology.

After starting the example, you will see a control panel with three sliders. Use first two sliders for setting stereoscopic vision VRFIGURE properties, namely for setting Stereo3DCameraOffset and Stereo3DHIT (HIT stands for Horizontal Image Translation). Use the third slider for zooming the camera.

Each virtual scene we create has a maximum amount of usable depth within which it is possible to create effective 3D effects. By tuning the 2 properties below we can adjust the best 3D perception for given scene, with given camera zoom (viewpoint field of view) setting.

The Stereo3DCameraOffset property defines the half of the interaxial distance between the left and right cameras (viewpoints). By adjusting the distance between cameras, we are able to dynamically increase or decrease the depth of a scene.

The Stereo3DHIT property defines the horizontal shifting of the left and right eye images to change the value of the parallax of corresponding points. By changing its value you can alter the on screen depth position of your scene.

For more information on stereoscopic vision VRFIGURE properties please refer to the product documentation.

Create a World Object

We begin by creating an object of class VRWORLD that represents the virtual world.

wh = vrworld('vrmanipul.wrl');

Open the Virtual World

The world must be opened before it can be used. This is accomplished with the OPEN command.


Accessing VRML Nodes

To access a VRML node, an appropriate VRNODE object must be created. The node is identified by its name and the world it belongs to.

H.View1 = vrnode(wh, 'View1');
H.View2 = vrnode(wh, 'View2');

Create Dialog

The dialog is used to interactively change field values of the VRML node referred to by the VRNODE object just created.

figh = dialog('Position',[360 350 530 185], 'Name', 'Simulink 3D Animation Example', ...
              'WindowStyle', 'normal', ...
              'CloseRequestFcn', ...
              'w = vrworld(''vrmanipul.wrl''); close(w); try; delete(w); end; closereq');

Create Stereoscopic Vision Properties Panel

stereopanel = uipanel(figh, ...
                      'Title', 'Stereoscopic Vision Properties', ...
                      'Units', 'pixels', ...
                      'Position', [0 72 530 103]);

% Create Stereoscopic Vision Camera Offset Control
H.cameraoffset = uicontrol('Parent',stereopanel, 'Style','slider', ...
                   'Position',[164 62 352 20], 'Value', 0, ...
                   'Min', 0, 'Max', 100, ...
                   'Callback', 'set(H.vrfig, ''Stereo3DCameraOffset'', get(H.cameraoffset,''Value'')/10);');

uicontrol('Parent',stereopanel, 'Position',[0 65 154 14], 'String','Camera Offset', ...
          'Style','text', 'HorizontalAlignment','right');

% Create Stereoscopic Vision Horizontal Image Translation Control
H.hit = uicontrol('Parent',stereopanel, 'Style','slider', ...
                   'Position',[164 21 352 20], 'Value', 0, ...
                   'Min', 0, 'Max', 0.35, ...
                   'Callback', 'set(H.vrfig, ''Stereo3DHIT'', get(H.hit,''Value''));');

uicontrol('Parent',stereopanel, 'Position',[0 24, 154 14], 'String','Horizontal Image Translation', ...
          'Style','text', 'HorizontalAlignment','right');

Create Navigation Properties Panel

navigationpanel = uipanel(figh, ...
                      'Title', 'Navigation', ...
                      'Units', 'pixels', ...
                      'Position', [0 0 530 62]);

% Create Camera Field of View Control
H.zoom = uicontrol('Parent',navigationpanel, 'Style','slider', ...
                  'Position',[164 21 352 20], 'Value', 1, ...
                  'Callback', ['viewpointdesc = get(H.vrfig, ''Viewpoint'');', ...
                               'H.(viewpointdesc).fieldOfView = 0.4 + 0.4 * (1-get(H.zoom,''Value''));']);

uicontrol('Parent',navigationpanel, 'Position',[0 24 154 14], 'String','Camera Zoom', ...
          'Style','text', 'HorizontalAlignment','right');

Attempt to Create Virtual Figure in Active Stereoscopic Vision Mode

If virtual figure is created in active stereoscopic vision mode it should be possible to modify stereoscopic vision properties and to see the stereoscopic vision 3D effect via shutter glasses.

% Suppress possible warning about active stereoscopic vision mode failure and create vrfigure
[lwm, lwi] = lastwarn;
ws = warning('off', 'sl3d:interface:enginewarn');
H.vrfig = vrfigure(wh, 'Stereo3D', 'active');

% Set the handles
setappdata(figh, 'Handles', H);

% Set defaults
defco = 22; defhit = 0.014;
set(H.vrfig, 'Stereo3DCameraOffset', defco/10, 'Stereo3DHIT', defhit);
set(H.cameraoffset, 'Value', defco);
set(H.hit, 'Value', defhit);
H.View1.fieldOfView = 0.4;

% Draw the vrfigure

% Re-enable possible warning about active stereoscopic vision mode failure
lastwarn(lwm, lwi);

Check Whether Virtual Figure Is in Active Stereoscopic Vision Mode

If the virtual figure could not be created in the active stereoscopic vision mode, display a message and gray-out the stereoscopic vision property controls.

if strcmp(get(H.vrfig, 'Stereo3D'), 'off')
  set(stereopanel, 'Title', [get(stereopanel, 'Title') ' (not available for current display)']);
  set(get(stereopanel, 'Children'), 'Enable', 'off');

The example is finished by closing the control panel.

Was this topic helpful?