ANIMATION: OPENING THE DOOR

Avalon has some resources for animation but we can use the "main loop" sometimes to do it.

We will use the timer to create an animation to open the door, replacing some code of the previous lesson.

We will create a method:

...
 public  void moving001(Double pX){
  Matrix3D open001 = new Matrix3D(0.1,0,0,0,0,0.1,0,0,0,0,0.1,0,pX,0,-5.5,1); 
  MatrixTransform3D mopen001= new MatrixTransform3D(open001);
  ModelVisual3D mv3D = VP.Children[0] as ModelVisual3D;
  Model3DGroup  m3Dg = mv3D.Content as  Model3DGroup;
  m3Dg.Children[7].Transform= mopen001  ;
    
 }
...

that will run when the user clicks the button and:

...
 if (modelHit  != null){
   GeometryModel3D gm3D = modelHit as GeometryModel3D; 
   if(gm3D.Geometry == TheCanvas.Resources["buttonG"]){
    if(op==0){
      
     op=1;
     start001=1;
    doorSound.Play();
    }
    else{
      
    op=0;
    start001=1;
    doorSound.Play();
   }
   return HitTestResultBehavior.Stop;//Exit
  }
...

At the "main loop" we have:

...
 void OnTimerEvent(object sender, System.EventArgs args){
    
   if(op==1 && start001==1){
    pXc = pXc - 0.125;
    moving001(pXc);
    if(pXc==-9){
     start001=0;
      
    }
   }
  if(op==0 && start001==1){
    pXc = pXc + 0.125;
    moving001(pXc);
    if(pXc==-5){
     start001=0;
      
    }
   } 
  }
...

For the demo, create a folder having the name of the .ZIP file and download it - right-clicking the link - and unzip inside the folder :

tu26v.zip

Liberate the firewall and play this web3d application:

We are doing our tests at a: Notebook DELL Latitude D600 - Intel Pentium M755 2.0 GHZ - Memory: 512 MB - VideoCard ATI Radeon 9000 32MB DDR 4xAGP - Resolution 1400x1050 - Communication: ADSL 256 kbps (Download: 45 kBps, Upload: 14 kBps)


PREVIOUS LESSON NEXT LESSON
T.CONTENTS HOMEPAGE