1     /**
2      * ...
3      * @author Matthew Casperson
4      */
5
6     package ;
7
8     import sandy.core.scenegraph.Shape3D;
9     import sandy.materials.attributes.LineAttributes;
10    import sandy.materials.attributes.MaterialAttributes;
11    import sandy.materials.WireFrameMaterial;
12    import sandy.materials.ColorMaterial;
13    import sandy.materials.Material;
14    import sandy.materials.Appearance;
15    import sandy.primitive.Box;
16    import feffects.Tween;
17    import feffects.easing.Linear;
18
19
20    class TweenedObject extends MeshObject
21    {
22       public var x:Float;
23       public var z:Float;
24       public var destination:MeshObject;
25
26       public function new(engineManager:EngineManager)
27       {
28          x = 0;
29          z = 0;
30          var mesh:Shape3D = new Box("", 10, 10, 10);
31          mesh.y = 60;
32          mesh.enableForcedDepth = true;
33          #if js
34             mesh.forcedDepth = 2;
35          #else
36             mesh.forcedDepth = 0;
37          #end
38
39          var materialAttr:MaterialAttributes = new MaterialAttributes([new LineAttributes( 1, 0, 1 )]);
40          var material:Material = new ColorMaterial( 0xFFCC33, 1, materialAttr );
41          var app:Appearance = new Appearance( material );
42          mesh.appearance = app;
43
44          var clonedMesh:Shape3D = mesh.clone();
45          clonedMesh.y = 60;
46          #if js
47             mesh.forcedDepth = 2;
48          #else
49             mesh.forcedDepth = 0;
50          #end
51          clonedMesh.enableForcedDepth = true;
52
53          var materialAttr2:MaterialAttributes = new MaterialAttributes([new LineAttributes( 1, 0, 1 )]);
54          var material2:Material = new ColorMaterial( 0xFF0000, 1, materialAttr2 );
55          var app2:Appearance = new Appearance( material2 );
56          clonedMesh.appearance = app2;
57
58          destination = new MeshObject(engineManager, clonedMesh);
59
60          super(engineManager, mesh);
61
62          setTween(0);
63       }
64
65       override public function enterFrame(dt:Float) : Void
66       {
67          this.model.x = this.x;
68          this.model.z = this.z;
69          engineManager.camera.lookAt(this.model.x, this.model.y, this.model.z);
70       }
71
72       private function setTween(value:Float):Void
73       {
74          var randXPos:Float = Math.random() * 200 - 100;
75          var randZPos:Float = Math.random() * 200 - 100;
76          var tween:Tween = new Tween( this.x, randXPos, 2000, this, "x");
77          var tween2:Tween = new Tween( this.z, randZPos, 2000, this, "z");
78          tween.setTweenHandlers(null, setTween);
79          tween.start();
80          tween2.start();
81          destination.model.x = randXPos;
82          destination.model.z = randZPos;
83
84       }
85
86
87    }

Top