Utilisation d'un PROTO

L'utilisation d'un proto simplifie la création d'un programme en VRML

Dans notre exemple le proto " RotationUniforme" va gérer :

  • Le mouvement de rotation d'une pièce
  • Le début, la pause ou l'arrêt du mouvement

Il faut donc renseigner les paramètres suivants :

  • La durée du cycle (CycleInterval 3.529)
  • La direction de l'axe de rotation (AxeRotation 0 0 1)
  • La ou les pièces en rotation (nœud Enfant)

Il faut également router les "Animation_Click.touchTime" vers le proto :

 

#VRML V2.0 utf8

Déclaration du PROTO

EXTERNPROTO RotationUniforme[exposedField MFNode Enfant field SFTime CycleInterval field SFVec3f AxeRotation eventIn SFTime MarcheArret  ][ "ProtoRotationUniforme.wrl"]

 

Viewpoint { position 5 0 5 orientation 0 1 0 0.8 description "Perspective" }

Viewpoint { position 0 0 6 orientation -1 1 0 0 description "Face" }

< COLOR="#0000ff">Viewpoint { position 5 0 -5 orientation 0 1 0 2.4 description "Perspective arrière" }

NavigationInfo { type "EXAMINE" }

Les paramètres du mouvement de chaque objet en rotation sont définis à l'aide du proto:

Durée d"un tour

Axe de rotation

Transform { children [ Inline { url "couronne.wrl" } ]}

DEF PignonMoteur RotationUniforme { CycleInterval 3.529 AxeRotation 0 0 1 Enfant [

  Transform { rotation 0 0 1 0.785 children [ Inline { url "pignon moteur.wrl" } ] }

]}

DEF PorteSatellite RotationUniforme { CycleInterval 20 AxeRotation 0 0 1 Enfant [

  Transform { translation 0 0 -.7 children [  Inline { url "porte satellite.wrl" } ] }

  Transform { translation 0 -1.05 0 children [

     DEF Satellite RotationUniforme {   CycleInterval 7.5 AxeRotation 0 0 -1 Enfant [  

        Inline { url "satellite.wrl" }

     ]   }

  ] }

  Transform { translation 0 1.05 0 rotation 0 0 1 3.14 children [ USE Satellite ] }

  Transform { translation 1.05 0 0 rotation 0 0 1 1.57 children [ USE Satellite ] }

  Transform { translation -1.05 0 0 rotation 0 0 1 -1.57 children [ USE Satellite ]}

]}

 

DEF Animation_Click TouchSensor {}

 

ROUTE Animation_Click.touchTime TO PignonMoteur.MarcheArret

ROUTE Animation_Click.touchTime TO Satellite.MarcheArret

ROUTE Animation_Click.touchTime TO PorteSatellite.MarcheArret

Détail du proto rotation uniforme