Archive for January 5th, 2009

Looking around the inside of a Sphere

Monday, January 5th, 2009 | examples | Comments


source

package
{
	import flash.events.Event;
	import flash.ui.Mouse;
 
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.core.utils.Mouse3D;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.materials.special.CompositeMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.view.layer.ViewportLayer;
	import org.papervision3d.view.layer.util.ViewportLayerSortMode;
 
	[SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")]
	public class LookingAroundTheInsideOfASphere extends BasicView
	{
		private var lookAtMe:DisplayObject3D;
		private var sphere:Sphere;
		private var mouse3D:Mouse3D;
		private var plane:Plane;
 
		public function LookingAroundTheInsideOfASphere()
		{
			viewport.interactive = true;
			mouse3D = viewport.interactiveSceneManager.mouse3D;
			Mouse3D.enabled = true;
 
			lookAtMe = new DisplayObject3D();
 
			var wireframeMaterial:WireframeMaterial = new WireframeMaterial(0x444444);
			var colorMaterial:ColorMaterial = new ColorMaterial(0xdddddd);
			var sphereMaterial:CompositeMaterial = new CompositeMaterial();
			sphereMaterial.addMaterial(wireframeMaterial);
			sphereMaterial.addMaterial(colorMaterial);
			sphereMaterial.interactive = true;
			sphereMaterial.doubleSided = true;
 
			sphere = new Sphere(sphereMaterial, 500, 24, 18);
 
			var planeMaterial:MaterialObject3D = new ColorMaterial(0xcc0000);
			planeMaterial.doubleSided = true;
			plane = new Plane(planeMaterial, 50, 50);
 
			var viewportLayer:ViewportLayer = new ViewportLayer(viewport, plane);
			viewportLayer.layerIndex = 1;
 
			viewport.containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT;
			viewport.containerSprite.addLayer(viewportLayer);
 
			scene.addChild(plane);
 
			camera.z = -300;
			camera.target = lookAtMe;
 
			scene.addChild(sphere);
 
			startRendering();	
 
			Mouse.hide();
		}
 
		override protected function onRenderTick(event:Event=null):void
		{
			lookAtMe.x += (mouse3D.x - lookAtMe.x) * .03;
			lookAtMe.y += (mouse3D.y - lookAtMe.y) * .03;
 
			plane.copyTransform(mouse3D);
 
			super.onRenderTick(event);
		}
	}
}

Tags: ,

Search

Recommended Books

Speaking at FITC Toronto

 

January 2009
M T W T F S S
« Dec   Feb »
 1234
567891011
12131415161718
19202122232425
262728293031  

Preferred Video Tutorial Resolution

  • 1024x768 (53%, 85 Votes)
  • 1280x1024 (15%, 24 Votes)
  • 1920x1080 (15%, 24 Votes)
  • 800x600 (13%, 20 Votes)
  • 480x320 (4%, 6 Votes)
  • 640x480 (0%, 2 Votes)

Total Voters: 160

Loading ... Loading ...