Looking around the inside of a Sphere

Monday, January 5th, 2009 | examples


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: ,

8 Comments to Looking around the inside of a Sphere

malte
January 13, 2009

how is it possible to rotate complete 360 degrees in the sphere? now i can only see the half…

John Lindquist
January 13, 2009

you can add another line like:

lookAtMe.z += (mouse3D.z - lookAtMe.z) * .03;

But you’ll have to manage/limit the movement yourself since the axis of the camera will get all screwy. For example, imagine you want to look at something behind you. And instead of turning around like a normal human would, you do a back-bend so you now see everything upside-down. Then something is in front of you, so you turn around normally, but everything is still upside-down. A whole bunch of those types of problems creep in when you just let the camera follow the mouse. So if you just use that line above, expect weird stuff to happen ;)

malte
January 13, 2009

thanks alot. it works(without upside down) but there is a flip when reaching some point then its normal again. not sure why…

John Lindquist
January 13, 2009

it’s the same as the problem I was explained. The axis gets screwy if you just look around everywhere.

malte
January 13, 2009

any idea how to avoid these effects? i really like the mouse3d approach you used in this example and it would be nice to look around the whole sphere.
thanks in advance.

sacen
January 15, 2009

planing to make a website out of this

Thanks
Sacen

sacen
January 15, 2009

Hi, Nice effect. Just wounding how you add images so it looks like the shark on http://osflash.org/papervision3d ? Planing to make a website out of this.Any advice will be great.

Many thanks
Sacen

vinnie vivace
March 16, 2009

Hi. Brand new to Papervision, and 3D in general, so please excuse ignorance. Im wanting to do something similar to this example, but rather, walk around the outside of a sphere, i.e. walk around the outside of a small planet. Is that acheivable?

Leave a comment