Original address http://bvu.javaeye.com/blog/393116
With this, you can browse 3D objects.
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 previusmousex: number;
19 Private VaR previusmousey: 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 Previusmousex = Event. stagex;
57 Previusmousey = 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 - Previusmousex;
68 VaR differencey: Number = Event. stagey - Previusmousey;
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 Previusmousex = Event. stagex;
82 Previusmousey = Event. stagey;
83
84 Camera. orbit (camerapitch, camerayaw, True , Cameratarget );
85 }
86 }
87 }
88 }