Level: Beginner Version : 1.0 author : Thomas PFEIFFER aka Kiroukou date : May 25th 2006 Reference : understand Sandy
In this tutorial I'll show you how to create your first box – more precisely your first cube – with Sandy.
In 50 lines of code, you will get familiar with the Sandy API, initialization of your application and scene creation, and you will have a first visual result (yes the result is very basic, but the next tutorials are here to make it better
)
We are going to set up a screen to draw the scene (the drawn objects), a camera to visualize the 3D world, and project it on a 2D space (the screen), the groups which are the most important part, and finally the Box primitive which helps you to create very easily a 3D object.
So here is your first Sandy code. In order to display the object, we are going to move the camera back to have enough distance to see the object which is at the coordinates 0,0,0 (as was the camera initially). To move the camera backward, we just have to make the Z value, the third coordinate, negative.
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 { // screen creation, the object where objects will be displayed. var screen:ClipScreen = new ClipScreen( this.createEmptyMovieClip('screen', 1), 600, 600 ); // we create our camera var cam:Camera3D = new Camera3D( 700, screen); // we move the camera backward to be able to see the object placed at 0,0,0 cam.setPosition(0, 0, -500); // we add the camera to the world World3D.getInstance().addCamera( 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();
Source :
.fla source file
Demo :