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

  • You really have a unique way to pen down your thoughts.
  • I was taken with the level of understanding so clearly demonstrated in this post.  I hope the rest of this site contains content as entertaining and informative as this!
  • Great Thank you for posting the great content…Nice i liked more
  • good to sharing,i will follow this site
  • Thanks, for very interesting post. I have a high regard for the valuable information
  • Above the code is very helpful to me.Most of the people looking for this kind of information.
  • Thanks for the informative post. I will surely look forward to these. The techniques given here very impressive.
  • This is great achievement and great creativeness...

    With best regards
  • Above the code is very helpful to improve my script knowledge.All the points are explained very clearly.
  • Really very nice  I like it very much Thanks
  • Great code
  • Great code about this matter
  • Yes, i totally believe in what you said here. This is an indeed post post i must say and great read for me. Hope to see more article. Thanks.
  • For a long time, I am searching for this installation. Now only I have got it. Really great work. I have got your site through Google. Thanks for sharing. Surely I will try it...
  • Thanks for this usefull information, i really need it.
  • This is exactly the code I have been looking for.

  • It is very Useful post to me and i am also web developer and domain registrar in Chennai. Domain Registration | Web Hosting Chennai Cheap Domain Registration
  • This is really an excellent. Thanks for providing code here. Hope you frequently update the posts with good blogs. Thanks!
  • Nice information on  this blog,I got lots of ideas , thanks for the update
  • Yes, good information you guys have here. I always prefer to read good
    quality contents and I think I have found it on your post here.
    Thanks!
  • I feeling so glad to visit on this site again and it's really great for me to read this article. This post is completely informative and interesting.
  • I am glad to visit your blog.. I found this post is really useful one. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. register website name
  • I really enjoyed this article. It is always nice when you read some
    thing that is not only informative but entertaining. Excellent! that
    is not only informative but entertaining. Excellent!
  • Tony
    Flex Example:
  • AT
    Hi, Im really appreciate that you made this website. It's really useful for me.

    I have a question here, i have no problem to follow your example here and make a sphere that will allow me looked inside it; but when i tried to add an image inside of it then i got a problem.

    the only thing i'm able to see in the sphere is only a red square of thing. i assumed that's the indicator for the mouse, though it wouldn't move around in this test like the example i've tried earlier.

    when i tried to zoom out a bit, then i'm able to see the image i've pasted. its outside that sphere, but i still wouldn't be able to move rotated the sphere what soever.

    here is what i have wrote..

    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.special.CompositeMaterial;
    import org.papervision3d.materials.BitmapFileMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    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;

    public class space extends BasicView
    {
    private var lookAtMe;DisplayObject3D;
    private var sphere:Sphere;
    private var mouse3D:Mouse3D;
    private var plane:Plane;

    public function space ()
    {
    viewport.interactive = true;
    mouse3D = viewport.interactiveSceneManager.mouse3D;
    Mouse3D.enabled = true;

    lookAtMe = new DisplayObject3D();

    var bitmapFileMaterial:CompositeMaterial = new CompositeMaterial();
    bitmapFileMaterial.interactive = true;
    bitmapFileMaterial.doubleSided = true;

    sphere = new Sphere(new BitmapFileMaterial('sky2.jpg'), 400, 12, 12);

    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) * .009;
    lookAtMe.y += (mouse3D.y - lookAtMe.y) * .009;

    plane.copyTransform(mouse3D);

    super.onRenderTick(event);
    }
    }
    }

    please let me know i have done wrong.
  • hi there,
    I have been trying to use this example in Flex but still didn't really figure out how.

    Do you have some examples for flex?
  • 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?
  • sacen
    Hi, Nice effect. Just wounding how you add images so it looks like the shark on http://osflash.org/papervision... ? Planing to make a website out of this.Any advice will be great.

    Many thanks
    Sacen
  • sacen
    planing to make a website out of this

    Thanks
    Sacen
  • malte
    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.
  • John Lindquist
    it's the same as the problem I was explained. The axis gets screwy if you just look around everywhere.
  • malte
    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
    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
    how is it possible to rotate complete 360 degrees in the sphere? now i can only see the half...
blog comments powered by Disqus

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 ...