Sandy engine Study Notes: Camera

Source: Internet
Author: User

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.

 

 

  1. Package
  2. {
  3. Import flash. display. Sprite;
  4. Import flash. Events .*;
  5. Import Sandy. Core. scene3d;
  6. Import Sandy. Core. Data .*;
  7. Import Sandy. Core. scenegraph .*;
  8. Import Sandy. Materials .*;
  9. Import Sandy. Materials. Attributes .*;
  10. Import Sandy. Primitive .*;
  11. Import Sandy. parser .*;
  12. Import flash. UI. keyboard;
  13. Public class my3d extends Sprite
  14. {
  15. Private var scene: scene3d;
  16. Private var camera: camera3d;
  17. Private var pot: shape3d;
  18. Public Function my3d ()
  19. {
  20. VaR Parser: iparser = parser. Create ("asset/teieraase. ASE", parser. ase); // import the ASE format to rewrite the painting in flash.
  21. Parser. addeventlistener (parserevent. Fail, onerror); // listen on Model import failure
  22. Parser. addeventlistener (parserevent. init, createscene); // initialize the listener
  23. Stage. addeventlistener (keyboardevent. key_down, keypressed );
  24. Parser. parse (); // load the file
  25. }
  26. Private function onerror (pevt: parserevent): void
  27. {
  28. Trace ("file loading error ");
  29. }
  30. Private function createscene (p_eevent: parserevent): void
  31. {
  32. Camera = new camera3d (500,300); // create a camera
  33. Camera. Y = 30;
  34. Camera. z =-200;
  35. VaR G: Group = group (p_eevent.group );
  36. Pot = G. Children [0] As shape3d; // convert the model to the shape3d type
  37. Pot. x = 0;
  38. VaR materialattr: materialattributes = new materialattributes (New lightattributes (true, 0.2 ));
  39. VaR material: Material = new colormaterial (0xe0f87e, 0.9, materialattr); // Add color material and light
  40. Material. lightingenable = true; // enable light
  41. VaR app: appearance = new appearance (material); // create an object surface
  42. Pot. Appearance = app;
  43. Scene = new scene3d ("scene", this, camera, G );
  44. Addeventlistener (event. enter_frame, enterframehandler );
  45. }
  46. Private function enterframehandler (Event: Event): void
  47. {
  48. // Pot. Pan + = 3;
  49. Scene. Render ();
  50. }
  51. Private function keypressed (Event: keyboardevent): void
  52. {
  53. Switch (event. keycode)
  54. {
  55. Case keyboard. Up:
  56. Camera. Tilt + = 2; // move up
  57. Break;
  58. Case keyboard. down:
  59. Camera. Tilt-= 2; // move down
  60. Break;
  61. Case keyboard. Right:
  62. Camera. Pan-= 2; // move left
  63. Break;
  64. Case keyboard. left:
  65. Camera. Pan + = 2; // move right
  66. Break;
  67. Case keyboard. Control:
  68. Camera. Roll + = 2; // rotate
  69. Break;
  70. Case keyboard. page_down:
  71. Camera. Z-= 5; // move backward
  72. Break;
  73. Case keyboard. page_up: // move back
  74. Camera. Z + = 5;
  75. Break;
  76. }
  77. }
  78. }
  79. }

 

The keyboard control enables the camera to go up, down, and rotate forward and backward.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.