
您可以自行前往示範網頁觀看並下載原始碼,不過要先說一下,解析度適合 1024x768 按 F11 以全螢幕看,並且只適用 Firefox, 而且會要你裝 google earth plugin,若你肯乖乖裝的話就可以用地球。
有心要寫這樣的頁面的人,可以參考
http://code.google.com/apis/maps/
http://code.google.com/apis/ajax/
http://code.google.com/apis/ajaxfeeds/
等等
這是屬於菠蘿麵包的地方,發表一些與數位家庭產品、觸控螢幕等工作上相關技術的心得。議題包括 embedded linux, 數位家庭, User Interface, 多點觸控。我喜歡狂想、自由,因此有時天馬行空任我遨遊,也希望您能喜歡這裡,一起享受自由的精神,當一個快樂的精靈。歡迎訂閱 Wonderfully Abdominous Digital Entertainment - Fantasy Space
package{
import flash.display.Sprite;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
// import extra modules
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cone;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.objects.primitives.Cylinder;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.objects.primitives.Sphere;
// end of extra modules
public class Panorama extends Sprite{
private var viewport:Viewport3D;
private var scene:Scene3D;
private var camera:Camera3D;
private var renderer:BasicRenderEngine;
public function Panorama()
{
initPapervision3D();
}
private function initPapervision3D():void
{
viewport = new Viewport3D();
addChild(viewport);
scene = new Scene3D();
camera = new Camera3D();
renderer = new BasicRenderEngine();
/* body of the example code */
// Plane
var m:WireframeMaterial = new WireframeMaterial();
var plane:Plane = new Plane(m, 800, 800, 2, 2);
scene.addChild(plane);
// Cone
var m2:WireframeMaterial = new WireframeMaterial(0xFF5600);
var cone:Cone = new Cone(m2, 100, 100, 8, 6);
cone.rotationY = 40;
cone.rotationX = -30;
cone.moveRight(300);
scene.addChild(cone);
// Sphere
var sphere:Sphere = new Sphere();
scene.addChild(sphere);
// Cylinder
var cylinder:Cylinder = new Cylinder(m2, 100, 100, 8, 6, -1);
cylinder.moveUp(300);
scene.addChild(cylinder);
// Cube
var materialsList:MaterialsList = new MaterialsList();
var cube:Cube;
/*
var frontMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);
var backMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);
var leftMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);
var rightMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);
var topMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);
var bottomMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);
materialsList.addMaterial(frontMaterial, "front");
materialsList.addMaterial(backMaterial, "back");
materialsList.addMaterial(leftMaterial, "left");
materialsList.addMaterial(rightMaterial, "right");
materialsList.addMaterial(topMaterial, "top");
materialsList.addMaterial(bottomMaterial, "bottom");
cube = new Cube(materialsList,500,500,500,1,1,1,Cube.ALL);
*/
var allM:WireframeMaterial = new WireframeMaterial();
materialsList.addMaterial(allM, "all");
cube = new Cube(materialsList,500,500,500,1,1,1,Cube.ALL);
cube.moveLeft(400);
cube.moveForward(200);
scene.addChild(cube);
/* end of the body of the example code */
renderer.renderScene(scene, camera, viewport);
}
}
}
package
{
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.net.URLLoader;
import flash.net.URLRequest;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Plane;
[SWF(width="640", height="480", frameRate="60")]
public class Panorama extends Sprite
{
private var container :Viewport3D;
private var scene :Scene3D;
private var camera :Camera3D;
private var renderer :BasicRenderEngine;
private var assetArray :Array;
private var cC :Array;
private var count :Number;
private var flying :DisplayObject3D;
private var front:BitmapMaterial;
private var back:BitmapMaterial;
private var bottom:BitmapMaterial;
private var right:BitmapMaterial;
private var left:BitmapMaterial;
private var top:BitmapMaterial;
private var movementFactor:Number = 100;
// set the key actions
private var keyRight:Boolean = false;
private var keyLeft:Boolean = false;
private var keyForward:Boolean = false;
private var keyBackward:Boolean = false;
private var forwardFactor:Number = 0;
private var sideFactor:Number = 0;
private var inertia:Number = 5;
public function Panorama()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
init3D();
stage.quality = StageQuality.LOW;
}
private function init3D():void
{
container = new Viewport3D(640,480,false,true);
scene = new Scene3D();
camera = new Camera3D();
container.buttonMode = true;
addChild( container );
renderer = new BasicRenderEngine();
flying = new DisplayObject3D();
var myurl:URLLoader = new URLLoader(new URLRequest("galleries.xml"));
myurl.addEventListener(Event.COMPLETE, loadAssets);
}
private function loadAssets(event:Event):void
{
var loader:URLLoader = event.target as URLLoader;
var xml:XML = XML(loader.data);
count = 0;
assetArray = new Array();
for each (var pic:XML in xml..photo) {
assetArray.push(pic.source);
}
loadOne();
}
private function loadOne():void
{
var loaD:Loader = new Loader();
loaD.contentLoaderInfo.addEventListener(Event.COMPLETE, progfin);
var urlreq:URLRequest = new URLRequest(assetArray[count]);
loaD.load(urlreq);
}
private function progfin(e:Event):void
{
var bmm:BitmapData = e.target.content.bitmapData;
count++;
if(count < assetArray.length) {
var doublePlane:DisplayObject3D = new DisplayObject3D();
var frontPlane:Plane = new Plane(new BitmapMaterial(bmm));
var rearPlane:Plane = new Plane(new BitmapMaterial(bmm));
rearPlane.rotationY = 180;
doublePlane.addChild(frontPlane);
doublePlane.addChild(rearPlane);
doublePlane.rotationX = Math.random() * 360;
doublePlane.rotationY = Math.random() * 360;
doublePlane.moveForward(1000);
flying.addChild(doublePlane);
loadOne();
} else {
createSphere();
addEventListeners();
};
}
private function createSphere():void
{
flying.z = 1000;
scene.addChild( flying);
}
private function addEventListeners():void
{
addEventListener(Event.ENTER_FRAME, render);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
// if key is pressed do this event listerners pay attention to the key press
private function onKeyDown(e:KeyboardEvent):void
{
switch(e.keyCode) {
case "W" .charCodeAt():
case Keyboard.UP:
keyForward = true;
keyBackward = false;
break;
case "S" .charCodeAt():
case Keyboard.DOWN:
keyForward = false;
keyBackward = true;
break;
case "A" .charCodeAt():
case Keyboard.LEFT:
keyLeft = true;
keyRight = false;
break;
case "D" .charCodeAt():
case Keyboard.RIGHT:
keyLeft = false;
keyRight = true;
break;
}
}
// this second function determines the keyup false
private function onKeyUp(e:KeyboardEvent):void
{
switch(e.keyCode) {
case "W" .charCodeAt():
case Keyboard.UP:
keyForward = false;
break;
case "S" .charCodeAt():
case Keyboard.DOWN:
keyBackward = false;
break;
case "A" .charCodeAt():
case Keyboard.LEFT:
keyLeft = false;
break;
case "D" .charCodeAt():
case Keyboard.RIGHT:
keyRight = false;
break;
}
}
private function onEnterFrame(e:Event):void
{
if (keyForward) {
forwardFactor += 10;
}
if (keyBackward) {
forwardFactor += -10;
}
if (keyLeft) {
sideFactor += -10;
}
if (keyRight) {
sideFactor += 10;
}
forwardFactor += ( 0 - forwardFactor ) / inertia;
sideFactor += ( 0 - sideFactor ) / inertia;
if ( forwardFactor > 0) {
camera.moveForward(forwardFactor);
}else {
camera.moveBackward( - forwardFactor );
}
if (sideFactor > 0) {
camera.moveRight( sideFactor );
}else {
camera.moveLeft( -sideFactor );
}
}
private function render(e:Event):void {
renderer.renderScene(scene, camera, container);
flying.yaw(1);
}
}
}
/* galleries.xml
<galleries>
<photo>
<source>pic.jpg</source>
</photo>
<photo>
<source>text.jpg</source>
</photo>
</galleries>
*/