papervision3d相機旋轉(papervision3d camera orbit)

來源:互聯網
上載者:User

原文地址 http://bvu.javaeye.com/blog/393116

有了這個,就可以做三維物體的瀏覽了。

 

 1 package
2 {
3 import flash.events.MouseEvent;
4
5 import org.papervision3d.lights.PointLight3D;
6 import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
7 import org.papervision3d.objects.DisplayObject3D;
8 import org.papervision3d.objects.primitives.Sphere;
9 import org.papervision3d.view.BasicView;
10
11 [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")]
12 public class OrbitingCameraExample extends BasicView
13 {
14 private var isOribiting:Boolean;
15 private var cameraPitch:Number = 90;
16 private var cameraYaw:Number = 270;
17 private var cameraTarget:DisplayObject3D = DisplayObject3D.ZERO;
18 private var previousMouseX:Number;
19 private var previousMouseY:Number;
20
21 private var light:PointLight3D;
22
23 public function OrbitingCameraExample()
24 {
25 light = new PointLight3D();
26 var material:FlatShadeMaterial = new FlatShadeMaterial(light, 0xcc0000);
27
28 var sphere1:Sphere = new Sphere(material, 300, 10, 10);
29 var sphere2:Sphere = new Sphere(material, 100, 10, 10);
30 sphere2.x = 300;
31 sphere2.y = 300;
32 sphere2.z = 700
33 var sphere3:Sphere = new Sphere(material, 100, 10, 10);
34 sphere3.x = 600;
35 sphere3.y = -400;
36 sphere3.z = -200;
37 var sphere4:Sphere = new Sphere(material, 100, 10, 10);
38 sphere4.x = -700;
39 sphere3.z = -100;
40
41 scene.addChild(sphere1);
42 scene.addChild(sphere2);
43 scene.addChild(sphere3);
44 scene.addChild(sphere4);
45
46 stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
47 stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
48 stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
49
50 startRendering();
51 }
52
53 private function onMouseDown(event:MouseEvent):void
54 {
55 isOribiting = true;
56 previousMouseX = event.stageX;
57 previousMouseY = event.stageY;
58 }
59
60 private function onMouseUp(event:MouseEvent):void
61 {
62 isOribiting = false;
63 }
64
65 private function onMouseMove(event:MouseEvent):void
66 {
67 var differenceX:Number = event.stageX - previousMouseX;
68 var differenceY:Number = event.stageY - previousMouseY;
69
70 if(isOribiting)
71 {
72 cameraPitch += differenceY;
73 cameraYaw += differenceX;
74
75 cameraPitch %= 360;
76 cameraYaw %= 360;
77
78 cameraPitch = cameraPitch > 0 ? cameraPitch : 0.0001;
79 cameraPitch = cameraPitch < 90 ? cameraPitch : 89.9999;
80
81 previousMouseX = event.stageX;
82 previousMouseY = event.stageY;
83
84 camera.orbit(cameraPitch, cameraYaw, true, cameraTarget);
85 }
86 }
87 }
88 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.