sandy学习笔记:Mode7演示

      树人的叶子 2009-3-29 16:44

 压缩包下载

package
{
 import flash.display.Bitmap;
 import flash.display.Sprite;
 import flash.events.*;
 import flash.net.*;
 import flash.text.*;
 import flash.ui.Keyboard;
 
 import mx.events.*;
 import mx.resources.*;
 
 import sandy.core.Scene3D;
 import sandy.core.data.*;
 import sandy.core.scenegraph.*;
 import sandy.core.scenegraph.mode7.*;
 import sandy.materials.*;
 import sandy.materials.attributes.*;
 import sandy.primitive.*;
 
 [SWF(width='700',height='500',backgroundColor='0xCCBBBB',frameRate='30')]
 public class Example4 extends Sprite
 {
  private var scenne:Scene3D;
  private var camera:Camera3D;
  private var ranY:Number=0.5;
  private var box:Box;
  private var box2:Box;
  private var box3:Box;
  private var plane:Plane3D;

        [Embed(source="map.jpg")]
   public var pic:Class;
        private var bitmap:Bitmap;
        private var _upPush:int;
  private var _downPush:int;
  private var _leftPush:int;
  private var _rightPush:int;
        private var _mode7:Mode7;
  public function Example4()
  {
   bitmap=new pic() as Bitmap;
   
   camera=new CameraMode7(700,500);
   camera.x = 0;
   camera.y = 100;
   camera.z = 0;
   camera.tilt =20;

   var root:Group=createScene();
   scenne=new Scene3D("scene1",this,camera,root); 
   addEventListener(Event.ENTER_FRAME,Run);
   stage.addEventListener (KeyboardEvent.KEY_DOWN, onKey);
   stage.addEventListener (KeyboardEvent.KEY_UP, onKey);
   
   
  }
  
  private function onKey (kEvt:KeyboardEvent):void
  {
   if (kEvt.type==KeyboardEvent.KEY_DOWN)
   {
    if (kEvt.keyCode==Keyboard.UP)
    {
     _upPush=1;
    }
    else if (kEvt.keyCode == Keyboard.DOWN)
    {
     _downPush=1;
    }
    else if (kEvt.keyCode == Keyboard.LEFT)
    {
     _leftPush=1;
     trace("left");
    }
    else if (kEvt.keyCode == Keyboard.RIGHT)
    {
     _rightPush=1;
    }
   }
   else if (kEvt.type == KeyboardEvent.KEY_UP)
   {
    if (kEvt.keyCode==Keyboard.UP)
    {
     _upPush=0;
    }
    else if (kEvt.keyCode == Keyboard.DOWN)
    {
     _downPush=0;
    }
    else if (kEvt.keyCode == Keyboard.LEFT)
    {
     _leftPush=0;
    }
    else if (kEvt.keyCode == Keyboard.RIGHT)
    {
     _rightPush=0;
    }
   }
  }
  
  
  
  private function createScene():Group
  {
   var g:Group=new Group();
   box=new Box("box",50,50,50);
   box.x=-20;
   box.y=0;
   box.z=-100;
   box.rotateX=50;
   
   
      box2=new Box("box2",50,50,50);
   box2.x=50;
   box2.y=0;
   box2.z=-100;
   box2.rotateX=50;
  
   
   box3=new Box("box3",50,50,50);
   box3.x=120;
   box3.y=0;
   box3.z=-100;
   box3.rotateX=50;

             _mode7 = new Mode7();   
   _mode7.setBitmap ( bitmap.bitmapData );
   _mode7.setHorizon (true, 0x000000, 1);
   _mode7.setNearFar (true); 
       
        g.addChild( _mode7);
     g.addChild(box);
  g.addChild(box2);
     g.addChild(box3);
     _mode7.repeatMap = false;
   var materialAttr:MaterialAttributes = new MaterialAttributes(
                        new LineAttributes( 0.5, 0x2111BB, 0 ),
                        new LightAttributes( true, 0.1)
                     );

   var material:Material = new ColorMaterial( 0x0000FF, 1, materialAttr );
   var material2:Material = new ColorMaterial( 0x00FF00, 1, materialAttr );
   var material3:Material = new ColorMaterial( 0xFF0000, 1, materialAttr );
 
   material.lightingEnable = true;
   material2.lightingEnable = true;
   material3.lightingEnable = true;
  
   
   var app:Appearance = new Appearance( material );
   var app2:Appearance = new Appearance( material2 );
   var app3:Appearance = new Appearance( material3 );
 
   box.appearance = app;
   box2.appearance = app2;
   box3.appearance = app3;
 
   box.container.buttonMode = true;
   box2.container.buttonMode = true;
   box3.container.buttonMode = true;
   box.container.addEventListener(MouseEvent.CLICK, clickHandler);
      box2.container.addEventListener(MouseEvent.CLICK, clickHandler2);
      box3.container.addEventListener(MouseEvent.CLICK, clickHandler3);
   return g;

  }
  private function Run(event:Event):void
  {
   scenne.render();
   box.rotateY+=1;
   box2.rotateY+=1;
   box3.rotateY+=1;
 
      camera.rotateY += (_leftPush - _rightPush) * 2;
      var rotationRadian:Number=Math.PI*camera.rotateY/180;
   camera.x += Math.sin(- rotationRadian) * (_upPush - _downPush) * 8;
   camera.z += Math.cos(- rotationRadian) * (_upPush - _downPush) * 8;    
  }
  private function clickHandler(event:MouseEvent):void
  {

   trace("第一个你点了");
   navigateToURL(new URLRequest("http://www.baidu.com"),"_blank");
  }
  private function clickHandler2(event:MouseEvent):void
  {

   trace("第二个你点了我 ");
    navigateToURL(new URLRequest("http://www.google.cn"),"_blank");
  }
  private function clickHandler3(event:MouseEvent):void
  {

   trace("第三个你点了我 ");
    navigateToURL(new URLRequest("http://www.hao123.com"),"_blank");
  }
 }
}

标签集:TAGS:sandy
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}