Temporary repository for tutorial code ported to Sandy 1.2 ( AS2 ) The tutorial pages could be extended to include these 1.2 code versions, while keeping the 1.1 versions. The changes are not very complicated and has to do only with the new camera definition and the projection screen. ( I have made some changes to the Stage size and the camera position, just to get closer to the Box ). Here are the codes.
import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.*; import sandy.core.transform.*; import sandy.events.*; function init( Void ):Void { // we create our camera var cam:Camera3D = new Camera3D( 200, 200 ); // we move the camera backward to be able to see the object placed at 0,0,0 cam.setPosition(0, 0, -200); // we add the camera to the world World3D.getInstance().setCamera( cam ); // we create the root node. var bg:Group = new Group(); // and set it as the root node of the world. World3D.getInstance().setRootGroup( bg ); // and we lauch the scene creation createScene( bg ); // and now that everything is created, we can launch the world rendering. World3D.getInstance().render(); } function createScene( bg:Group ):Void { ;// make you implementation here } // We lauch the animation creation. init();
import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.*; import sandy.core.transform.*; import sandy.events.*; function init( Void ):Void { // we create our camera var cam:Camera3D = new Camera3D( 200, 200 ); // we move the camera backward to be able to see the object placed at 0,0,0 cam.setPosition(0, 0, -200); // we add the camera to the world World3D.getInstance().setCamera( cam ); // we create the root node. var bg:Group = new Group(); // and set it as the root node of the world. World3D.getInstance().setRootGroup( bg ); // and we lauch the scene creation createScene( bg ); // and now that everything is created, we can launch the world rendering. World3D.getInstance().render(); } function createScene( bg:Group ):Void { // We create our object. It is a cube of 50 pixels var o:Object3D = new Box( 50, 50, 50 ); // Now we simply link the Object leaf to the root node, and finish the tree creation bg.addChild( o); } // We lauch the animation creation. init();
import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.*; import sandy.core.transform.*; import sandy.events.*; function init( Void ):Void { // we create our camera var cam:Camera3D = new Camera3D( 200, 200); // we move the camera backward to be able to see the object placed at 0,0,0 cam.setPosition(0, 0, -200); // we add the camera to the world World3D.getInstance().setCamera( cam ); // we create the root node. var bg:Group = new Group(); // and set it as the root node of the world. World3D.getInstance().setRootGroup( bg ); // and we lauch the scene creation createScene( bg ); // and now that everything is created, we can launch the world rendering. World3D.getInstance().render(); } function createScene( bg:Group ):Void { // We create our object. It is a cube of 50 pixels var o:Object3D = new Box( 50, 50, 50 ); // We create the skin to change the box's appearance. // Here we are using the SimpleColor skin, which requires a fill color, an alpha, and a thickness. // I choose to make it a little bit transparent and red var skin:Skin = new SimpleColorSkin (0xFF0000, 80, 2); // Now we just have to apply the skin to the object. // The skin will be applied to all faces of the object o.setSkin (skin); // Now we simply add the Object to the root node, to finish the tree creation bg.addChild( o); } // We lauch the animation creation. init();
import sandy.core.light.*; import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.*; import sandy.core.transform.*; import sandy.events.*; function init( Void ):Void { // we create our camera var cam:Camera3D = new Camera3D( 200, 200); // we move the camera backward to be able to see the object placed at 0,0,0 cam.setPosition(0, 0, -100); // we add the camera to the world World3D.getInstance().setCamera( cam ); //We create the Light coming from the left with a low intensity (20) var l:Light3D = new Light3D (new Vector (1, 0, 0), 20); // set the world light World3D.getInstance ().setLight (l); // we create the root node. var bg:Group = new Group(); // and set it as the root node of the world. World3D.getInstance().setRootGroup( bg ); // and we lauch the scene creation createScene( bg ); // and now that everything is created, we can launch the world rendering. World3D.getInstance().render(); } function createScene (bg:Group):Void { // We create our object. It is a cube of 50 pixels, and with the quad mode, so here four points per face. var o:Object3D = new Box (50, 50, 50, 'quad'); // we create a skin to "dress up " the object a bit, and make it visually better. // SimpleColor skin is used here, it needs the fill color, alpha, and thickness var skin:Skin = new MixedSkin (0x00FF00, 100, 0, 1); // We enable the light skin.setLightingEnable(true); // We apply the skin to the object o.setSkin (skin); // We create two TransformGroup instances. Each one corresponds to a node of the tree we are going to create. var tg1:TransformGroup = new TransformGroup (); var tg2:TransformGroup = new TransformGroup (); // We also create two instances of Translation objects. // Give them an appropriate name, this becomes important very rapidly. var translation:Transform3D = new Transform3D (); // We create an interpolator to make it rotate linearly for a while var ease:Ease = new Ease (); ease.linear (); var rotint:RotationInterpolator = new RotationInterpolator (ease.create (), 300); // we translate the object by 500 pixels on the Z axis. translation.translate (0, 0, 200); // We apply those transformations to the nodes. tg1.setTransform (translation); tg2.setTransform (rotint); // We add the rotation tansformation to the node which represents the rotation,by setting it as a child. // The rotation will be applied first, translation later (higher in the tree) tg2.addChild (o); // Now we link the two nodes // The order here is very important. tg1.addChild (tg2); // Now we simply link the translation node to the root node, thus completing the tree creation bg.addChild (tg1); } // We launch the animation creation. init ();
import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.*; import sandy.core.transform.*; import sandy.events.*; function init( Void ):Void { // we create our camera var cam:Camera3D = new Camera3D( 200, 200); // we move the camera backward to be able to see the object placed at 0,0,0 cam.setPosition(0, 0, -100); // we add the camera to the world World3D.getInstance().setCamera( cam ); // we create the root node. var bg:Group = new Group(); // and set it as the root node of the world. World3D.getInstance().setRootGroup( bg ); // and we lauch the scene creation createScene( bg ); // and now that everything is created, we can launch the world rendering. World3D.getInstance().render(); } function createScene( bg:Group ):Void { // We create our object. Therefore we use the primitive Box. // A cube is a box with a similair height, width and depth. // Generate a cube. The height, width and depth are all 50 pixels. var o:Object3D = new Box( 50, 50, 50 , 'quad'); // We create a skin to decorate the object a little better // Here the skin SimpleColor that uses a fill color, alpha value and line color var skin:Skin = new MixedSkin( 0x00FF00, 100, 0, 100 ); // We apply the skin to the object. o.setSkin( skin ); // We create two different transform Groups. Each transform group conforms to a node of the transformation branch that we create. var tg1:TransformGroup = new TransformGroup(); var tg2:TransformGroup = new TransformGroup(); // We create the same two instances of the class TransForm3D. // Besides, we begin to give our variables the right names. You see that will be very important soon. var translation:Transform3D = new Transform3D(); var rotation:Transform3D = new Transform3D(); // Translate 200 pixels along the Z axis. translation.translate( 0, 0, 200 ); // Rotation of 30 degrees around the axices recorded in the vector 1, 1, 1 // ( that's correspondend to an equivalent rotation in three dimensions ) rotation.rotAxis( new Vector(1,1,1), 30); // We apply these transformations to the transform Groups. tg1.setTransform( translation ); tg2.setTransform( rotation ); // We add our object to the rotation transform Group. So we apply rotation to it before we apply translation. tg2.addChild( o ); // Now we connect our two nodes and confirm the translation and get the rotation from its parent. // The position of those two addChild methods is very important for the result. tg1.addChild( tg2 ); // nous ajoutons le transformGroup comme filds du BranchGroup afin de créer l'arborescence // Now we simply link the Object leaf to the root node, and finish the tree creation bg.addChild( tg1 ); } // We launch the creation of the scene. init();