Re: HUD Text in Virtual Reality Toolbox viewer window



Hello,

A few people recently asked us how to display continuously changing text (ie: aircraft velocity, air density, altitude, etc.) in VR Viewer during Simulink simulation.

Virtual Reality Toolbox allows setting the Text node strings using the MATLAB interface. It is possible to write an s-function that uses MATLAB commands to convert numeric values to string and output it to a Text node in the VR scene. It is also possible to use the "Embedded MATLAB Function" block to achieve the same effect.

Below (------------) you find an example code from such Embedded function block. This code assumes that in the same model there is also the VR Sink block, associated with the respective virtual world, and that the virtual scene contains a text node with DEF name HUDText.

It is also possible to leave most of the value conversion functionality to the VRML part of the model. You can define a dummy object whose fields correspond to the types of the values you want to display (Single float, vector of 3 floats, etc.) The signal is then sent to virtual scene using the VR Sink block, in VRML file is routed to a script that does the conversion to the text and updates the value of the Text node string displayed in the scene. This approach can be seen from the example .WRL file below (=============).

The HUD behaviour - maintaining constant relative position between user and the Text can be achieved by using ProximitySensor and routing its output to a HUD Transform. Also shown in the VRML example file below.

Hope this helps,

All the best,

Jan

------------
function fcn(u)
% This block supports an embeddable subset of the MATLAB language.
% See the help menu for details.

% Get vrworld associated with the VR Sink found there
wh=vrworld(get_param('HUD_DirectEmbedded/VR Sink', 'WorldFileName'));
% Handle to the Text node we want to control
nh=vrnode(wh,'HUDText');
% Set the new value of the 'string' field of the Text node)
% the string can be a vector of strings
setfield(nh, 'string', strcat('Value:  ', num2str(u)) );
------------

=============
##VRML V2.0 utf8

WorldInfo {
title "HUD Text Example - Using Routing Through a Script"
info ["HUDText string field to display a value sent from Simulink to "
"a dummy field of a dummy object (object that doesn't have a visual effect),"
"then routed to a Script that converts it into a string and updates the HUDText."
"Dummy field has to have the type corresponding to the value which we want to display,"
"e.g. SFFloat - 'rotation' of a TextureTransform, SFVec3F - 'center' of a Transform."
]
}


DEF User ProximitySensor {size 10e6 10e6 10e6}

Background {
 groundAngle [ 0.1, 1.309, 1.571 ]
 groundColor [ 0 0 0, 0 0.1 0.3, 0 0.2 0.5, 0 0.3 0.8 ]
 skyAngle [ 0.1, 0.15, 1.309, 1.571 ]
 skyColor [ 0.4 0.4 0.1, 0.4 0.4 0.1, 0 0.1 0.3, 0 0.2 0.6, 0.8 0.8 0.8 ]
}

DEF Box Transform {
 center 0 0 0
 children [

  Viewpoint {
   orientation 0 1 0 -1.5707
   position 5 0 0
   description "Ride with the Box"
  }

  Shape {
   geometry Box {
   }
   appearance Appearance {
    material Material {
     diffuseColor 0 0.6 0.8
    }
   }
  }
 ]
}

DEF HUDPos Transform {
 translation 5 0 0
 children [
  # 1st HUD Position Offset
  Transform {
   translation  -0.3 -0.1 -1
   children [
    Shape {
     appearance Appearance {
      material Material {
       diffuseColor 0.178062 0.8 0.0662137
      }
     }

     geometry DEF HUDText1 Text {
      string [
       "InitStr"
      ]
      fontStyle FontStyle {
       family "SANS"
       size 0.04
      }
     }
    }
   ]
  }

  # 2nd HUD Position Offset
  Transform {
   translation  0.3 -0.1 -1
   children [
    Shape {
     appearance Appearance {
      material Material {
       diffuseColor 0.178062 0.8 0.0662137
      }
     }

     geometry DEF HUDText3 Text {
      string [
       "InitStr"
      ]
      fontStyle FontStyle {
       size 0.04
       family "SANS"
      }
     }
    }
   ]
  }


] }

# Dummy objects to pass on the values sent from Simulink to a conversion Script.
#
# SFFloat - use a textureTransform 'rotation' field
# SFVec2F - use a textureTransform 'center' field
# SFVec3F - use a Transform 'center' field
#
# The type of routed field must correspond to the type of the Script eventIn it is routed to.


Shape {
 appearance Appearance {
  textureTransform DEF Charon TextureTransform {
   rotation 0
   center 0 0
  }
 }
 geometry NULL
}

DEF Charon3Floats Transform {
 center 0 0 0
}

# Script that converts a numeric value (scalar or vector) to a string
# The type of eventIn updateHUD must correspond to the type of the routed value.


DEF HUDScript Script {
eventIn SFFloat updateHUD1
eventIn SFVec3f updateHUD3
field SFNode HUDTextNode1 USE HUDText1
field SFNode HUDTextNode3 USE HUDText3
url "vrmlscript:
function updateHUD1 (value, timestamp) {
HUDTextNode1.string = new MFString('Single Value, Rounded: ' + value.toFixed(2) );
}
function updateHUD3 (value, timestamp) {
HUDTextNode3.string = new MFString('SFVec3F Value:', String(value[0]), String(value[1]), String(value[2]));
}
"
}


# Routes responsible for the HUD behaviour
ROUTE User.position_changed TO HUDPos.set_translation
ROUTE User.orientation_changed TO HUDPos.set_rotation

# Routing of numeric values to a conversion srcipt
ROUTE Charon.rotation TO HUDScript.updateHUD1
ROUTE Charon3Floats.center TO HUDScript.updateHUD3

=============

--

--
-----------------------------------------------------------
Jan Danek
danek@xxxxxxxxxxxx             http://www.humusoft.com
--
HUMUSOFT s.r.o., Pobrezni 20, 186 00 Praha, Czech Republic
Tel: +420 2 84011730           Direct Tel: +420 2 84011746
Fax: +420 2 84011740
-----------------------------------------------------------
.



Relevant Pages

  • Re: A Simple BMP Converter
    ... "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal ... Private Sub cmdSysInfo_Click ... Open Registry Key ... > color bar in the color display. ...
    (comp.lang.basic.visual.misc)
  • Re: help collecting data.
    ... Dim GetC As String ... the code in the cell that I want the order numbers(info from column C ... "Otto Moehrbach" wrote: ... display them both, seperated by a comma ...
    (microsoft.public.excel.misc)
  • Need help with GridView and LDAP/GC
    ... I could do the search with GC, and then lookup more ... DirectoryEntry searchRoot = new ... // Add search string if specified. ... // Display Name ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Output data from multiple records in a table
    ... > Dim rsR As DAO.Recordset ... > Dim strSQL As String ... > such as display it in a textbox on your form. ...
    (microsoft.public.access.modulesdaovba)
  • Image Link Still Not Work
    ... Just choose any .jpg. ... or something similar and display that .jpg if the file ... >It appears to work fine inputing the string into a text ... Roger had mentioned storing the path and then ...
    (microsoft.public.access.modulesdaovba)