Tutorial Home / Complex Interactions / Introduction to Scripting

return to Complex Interations


Overview

Scripts are necessary whenever some intelligence is required for an interaction. They are the logic or brain of your Synthetic Environment. Examples of common situations where a script is required include:

We will be working with my pre-written javascripts as programming is beyond the scope of this course, however, feel free to look at the scripts if you want to gain a better understanding of what's going on "behind the scenes". Most of the actual logic is pretty basic ie. there is no heavy maths or complex functions. The biggest hurdle for newbies, or even those familiar with javascript, is understanding how VRML interfaces with javascript.

Don't expect miracles in a day - it's best to get familiar with VRML before you tackle any scripting. If you're keen to learn more about javascript programming for VRML I suggest you take a look at Bob Crispen's Taming VRML Scripts tutorial at VRML Works.

back to top | return to Complex Interations


Required Files

Download and unzip the following file (using WinZip) into the relevant folder of your working directory.

camera_switched.zip (51.3Kb)

This file contains:

scripts.zip (1.2Kb)

This file contains:

back to top | return to Complex Interations


Tutorial

Launch Cosmo Worlds and Open the file camera_switched.wrl
Note: as there are now many objects in the scene it may be hard to find what you're looking for in the Outline Editor. The best approach is to either select the object in the viewport and it will be highlighted in the Outline Editor or search By Name... or object type using the drop-down list.

Import the file rollover_script.wrl.

 

This will add rolloverScript and a TouchSensor to the bottom of the scene graph.

Select the script in the Outline Editor and the Property Inspector will change to display the script properties.

If you want to take a look at the script, click on the Edit Script button but don't make any changes.

Drag both the TouchSensor and rolloverScript up the scene graph and drop them under the lensRotationGroup.

This attaches the TouchSensor to the object.

Expand the rolloverScript and click on the color_changed output arrow to start the route.

Scroll and drill-down in the scene graph and complete the route by clicking on the input arrow of emissiveColor on the mainLensBody.

Preview your work. The lens should now highlight yellow when the mouse rolls over it.

Try it yourself. Repeat the above steps to add highlights to the other interactive components as per the Finished Project.

Note: you will need to go through the above process before you can continue on the the control script below.

 

Import the file cameraControl_script.wrl.

Expand the cameraControlScript and take a look at the inputs and outputs that we need to wire up.

Don't be daunted by all the text. The names a quite long in the hope of making them easier to understand.

We'll start with the inputs.

Find the powerButtonGroup in the Outline Editor and the TouchSensor you attached to it in the previous section.

Click on the touchTime output to start the route.

Scroll back down to the script and click on set_power input to finish the route.

Repeat the above steps to connect the following routes:

  • modeDial to set_mode
  • powerButton to set_power
  • flashButton to set_flash
  • shutterReleaseButton to set_shutterRelease

Now the outputs. Select modeRotation_changed and route it to the rotation of modeDial.

Repeat to finish the routes:

  • powerLEDcolor_changed to emissiveColor of powerLED
  • flashLEDcolor_changed to emissiveColor of flashLED
  • shutterReleaseLEDcolor_changed to emissiveColor of shutterReleaseLED
  • flashChoice_changed to whichChoice of flash
  • screenChoice_changed to whichChoice of screenSwitch
  • shutterReleaseStartTime_changed to startTime of shutterReleaseSound
  • flashBulbOn_changed to on property of flashBulb (point light)

This completes all the interactions on the camera itself.

It's a lot to take in in one session but it's just a matter of being careful and methodical. The repetitive nature of creating the above routes will reinforce the process for you.

That's my story and I'm sticking to it ;-)

 
Save your work.  
Preview in Cosmo Player.  

back to top | return to Complex Interations