Course 3: how to use a camera? By moving the camera to make changes to the photography object, the animation becomes easier. Because you don't need to change the properties of the object to be observed, just change the camera's changes.
- Package
- {
- Import flash. display. Sprite;
- Import flash. Events .*;
- Import Sandy. Core. scene3d;
- Import Sandy. Core. Data .*;
- Import Sandy. Core. scenegraph .*;
- Import Sandy. Materials .*;
- Import Sandy. Materials. Attributes .*;
- Import Sandy. Primitive .*;
- Import Sandy. parser .*;
- Import flash. UI. keyboard;
- Public class my3d extends Sprite
- {
- Private var scene: scene3d;
- Private var camera: camera3d;
- Private var pot: shape3d;
- Public Function my3d ()
- {
- VaR Parser: iparser = parser. Create ("asset/teieraase. ASE", parser. ase); // import the ASE format to rewrite the painting in flash.
- Parser. addeventlistener (parserevent. Fail, onerror); // listen on Model import failure
- Parser. addeventlistener (parserevent. init, createscene); // initialize the listener
- Stage. addeventlistener (keyboardevent. key_down, keypressed );
- Parser. parse (); // load the file
- }
- Private function onerror (pevt: parserevent): void
- {
- Trace ("file loading error ");
- }
- Private function createscene (p_eevent: parserevent): void
- {
- Camera = new camera3d (500,300); // create a camera
- Camera. Y = 30;
- Camera. z =-200;
- VaR G: Group = group (p_eevent.group );
- Pot = G. Children [0] As shape3d; // convert the model to the shape3d type
- Pot. x = 0;
- VaR materialattr: materialattributes = new materialattributes (New lightattributes (true, 0.2 ));
- VaR material: Material = new colormaterial (0xe0f87e, 0.9, materialattr); // Add color material and light
- Material. lightingenable = true; // enable light
- VaR app: appearance = new appearance (material); // create an object surface
- Pot. Appearance = app;
- Scene = new scene3d ("scene", this, camera, G );
- Addeventlistener (event. enter_frame, enterframehandler );
- }
- Private function enterframehandler (Event: Event): void
- {
- // Pot. Pan + = 3;
- Scene. Render ();
- }
- Private function keypressed (Event: keyboardevent): void
- {
- Switch (event. keycode)
- {
- Case keyboard. Up:
- Camera. Tilt + = 2; // move up
- Break;
- Case keyboard. down:
- Camera. Tilt-= 2; // move down
- Break;
- Case keyboard. Right:
- Camera. Pan-= 2; // move left
- Break;
- Case keyboard. left:
- Camera. Pan + = 2; // move right
- Break;
- Case keyboard. Control:
- Camera. Roll + = 2; // rotate
- Break;
- Case keyboard. page_down:
- Camera. Z-= 5; // move backward
- Break;
- Case keyboard. page_up: // move back
- Camera. Z + = 5;
- Break;
- }
- }
- }
- }
The keyboard control enables the camera to go up, down, and rotate forward and backward.