Jump to: navigation, search

Sound may be included in an H3D scene with the Sound node. In this example, the sound emits from the tip of the haptics tracker in the scene.

Image:Note-tip.pngThis tutorial refers to the source code. You can download it from SVN at H3D release branch, or find it at H3D/H3DAPI/examples/Sound.
<!!-- sound.x3d -->
  <IMPORT inlineDEF='H3D_EXPORTS' exportedDEF='HDEV' AS='HDEV' />
  <Viewpoint position="0 0 0.65" />
  <Sound maxFront="0.9" maxBack="0.9" minFront="0.0001" intensity="1" DEF="SOUND" >
    <AudioClip DEF="AUDIO" url="ding.wav" loop="TRUE"/>
  <ROUTE fromNode="HDEV" fromField="trackerPosition" toNode="SOUND" toField="location" />

The IMPORT statement imports the active haptics device, HDEV, from H3D_EXPORTS. Since we want to refer to the haptics device as HDEV in our scene, it is imported AS='HDEV'.

The position field of the Viewpoint node merely sets the position from which we view the scene.

We then include the Sound node, specifying the values of respective fields. maxFront, maxBack, minFront are distances that determine the volume of space the sound reaches, while intensity controls the loudness of the sound in decibels.

The Sound node has a sound source which is an X3DSoundSourceNode. In this example we use the AudioClip as the source. The url specifies the filepath to the clip. We set loop to true, which ensures that the clip repeats itself when the AudioClip is enabled. We do not need to enable AudioClip as it is enabled by default.

To model sound emitting from the tip of the haptic device, we route HDEV's trackerPosition to the location field of the Sound node. The trackerPosition is a Vec3f of the position of the device tracker in world coordinates. With ROUTE, the location is updated to the value of trackerPosition every time it changes.


Personal tools
go to