spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / 3d / lesson31

Lesson 31 - VRML 97--Magical Mystery Tour - Part 3

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Here's the next step, and it's an exciting one.

Thus far we've had a world we can navigate using the browser controls, and added some limited "animation" of the Viewpoint by creating a list for selection in the VRML browser. What about really animating the Viewpoint, creating a simple tour of our world?

We can do this by creating a Viewpoint node that we place in a Transform node. Check out the code.

    #VRML V2.0 utf8 Viewpoint { position 0, 0, 30 } DEF World Transform {   translation 0 0 0   children  [     DEF Tour Transform {       children  [         DEF Viewer Viewpoint { position 0, 0, 0 }              ]     }# end of Tour transform      DEF Center Transform {       translation 0 0 0       children  [         Shape  {           geometry Sphere {}           appearance Appearance {             material Material { diffuseColor 1 1 1 }           }         }       ]     }# end of Center transform--white     DEF Right Transform {       translation 10 0 0       children  [         Shape  {           geometry Box {}           appearance Appearance {             material Material { diffuseColor 0 1 0 }           }         }       ]     }# end of Right transform--green     DEF Left Transform {       translation -10 0 0       children  [         Shape  {           geometry Box {}           appearance Appearance {             material Material { diffuseColor 1 0 0 }           }         }       ]     }# end of Left transform--red     DEF Front Transform {       translation 0 0 10       children  [         Shape  {           geometry Box {}           appearance Appearance {             material Material { diffuseColor 1 0 1 }           }         }         DEF StartTour TouchSensor {}       ]     }# end of Front transform--magenta     DEF Back Transform {       translation 0 0 -10       children  [         Shape  {           geometry Box {}           appearance Appearance {             material Material { diffuseColor 0 1 1 }           }         }       ]     }# end of Back transform--cyan     DEF Top Transform {       translation 0 10 0       children  [         Shape  {           geometry Box {}           appearance Appearance {             material Material { diffuseColor 1 1 0 }           }         }       ]     }# end of Top transform--yellow     DEF Bottom Transform {       translation 0 -10 0       children  [         Shape  {           geometry Box {}           appearance Appearance {             material Material { diffuseColor 0 0 1 }           }         }       ]     }# end of Bottom transform--blue   ] }# end of World Transform DEF Timer TimeSensor { cycleInterval 20 } DEF Translator PositionInterpolator {   key [0, .5, 1]   keyValue [0 0 30, -10 0 10, -10 0 10] }# end of Translator   DEF Rotator OrientationInterpolator {   key [0, .5, 1]   keyValue [0 1 0 0, 0 1 0 0, 0 1 0 -1] } ROUTE StartTour.touchTime TO Timer.startTime ROUTE Timer.isActive TO Viewer.set_bind ROUTE Timer.fraction_changed TO Translator.set_fraction ROUTE Timer.fraction_changed TO Rotator.set_fraction ROUTE Translator.value_changed TO Tour.set_translation ROUTE Rotator.value_changed TO Tour.set_rotation

Sure there's a lot here, but it's well worth our attention. An unnamed Viewpoint node, set to 0, 0, 30 starts the file. Thus the browser will first bind to this node, and the viewer will begin from the same front view we've already been using. But we can change this with a click of the mouse.

A second viewpoint named Viewer is set in a Transform named Tour. In effect, the Viewpoint has been turned into a camera that can be transformed in space just like any other object. Translating Tour moves the Viewpoint. Rotating Tour rotates the Viewpoint.

A TouchSensor named StartTour is included in the Transform that contains the magenta cube. Thus clicking on the magenta cube will trigger the sensor. Following the ROUTE statements at the bottom of the code, we find that clicking on that cube will bind the Viewer Viewpoint. This binding triggers the TimeSensor, which in turn starts the animation. The animation contains both a translation and a rotation. The first half of the animation moves the viewer to a position in front of the red cube, but does so without turning. Then the cube stops moving and starts turning toward the center of the space. This animation requires three keys for both the position and rotation interpolators.

Give it a try.

CLICK HERE to view this example if you have a VRML browser. If you don't yet have a VRML browser, hurry up and download the new Cosmo Player for free from Cosmo Software.

In this file, the tour begins when you click and can't be stopped until it's done, when the TimeSensor deactivates. The deactivation of Timer generates a FALSE isActive message that is sent to Viewer to unbind it. Another approach would replace the routing statements as follows:

    ROUTE StartTour.isActive TO Viewer.set_bind ROUTE Viewer.bindTime TO Timer.startTime ROUTE Timer.fraction_changed TO Translator.set_fraction ROUTE Timer.fraction_changed TO Rotator.set_fraction ROUTE Translator.value_changed TO Tour.set_translation ROUTE Rotator.value_changed TO Tour.set_rotation

In this case, the TouchSensor triggers the binding directly, and the binding triggers Timer. This is the opposite of the previous example. But the difference is interesting. A TouchSensor is activated when the user presses down on the mouse button, but is deactivated when the button is released. Thus letting up on the mouse button switches the user back to the original Viewport. This puts the tour under the user's control. If you want to stop, just let up on the button!

CLICK HERE to view this example if you have a VRML browser.

To Return to Parts 1 and 2, Use Arrow Buttons

Previous Lesson / Table of Contents / Next Lesson


internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Review: Lenovo ThinkPad SL300 · OCZ PC3-10666 Gold 2x1GB Review · Apple Recommends Antivirus for Macs

Created: January 5, 1998
Revised: January 5, 1998

URL: http://webreference.com/3d/lesson31/part3.html