Mouse3D moving light

Wednesday, November 19th, 2008 | examples

Mouse3D is bound to the interactiveSceneManager of your viewport. So to get the 3d “renderHitData” of where your mouse is, you need to:

Mouse3D.enabled = true;
viewport.interactive = true;
mouse3D = viewport.interactiveSceneManager.mouse3D;

Then you can get 3d data from your mouse3D object like you would any other DisplayObject3D. Just remember the mouse will need to be over an object with a “material.interactive = true” to get any data back.


source

package {
	import flash.events.Event;
	import flash.ui.Mouse;
 
	import org.papervision3d.core.utils.Mouse3D;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.shadematerials.PhongMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.view.BasicView;
 
	[SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")]
	public class Mouse3DExample extends BasicView 
	{
		private var mouse3D:Mouse3D;
		private var pivotPoint:DisplayObject3D;
		private var light:PointLight3D;
 
		public function Mouse3DExample() 
		{
			var headerText:headerContainer = new headerContainer();
			headerText.header.text = "Mouse over the sphere to move the light";
			addChild(headerText);
 
			viewport.interactive = true;
			Mouse3D.enabled = true;
			mouse3D = viewport.interactiveSceneManager.mouse3D;
 
			light = new PointLight3D(true);
			pivotPoint = new DisplayObject3D();
 
			var material:PhongMaterial = new PhongMaterial(light, 0xcc0000, 0x000000, 10);
			material.interactive = true;
			var sphere:Sphere = new Sphere(material, 500, 30, 30);
			sphere.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, objectOverHandler);
			sphere.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, objectOutHandler);
 
			var smallSphere1:Sphere = new Sphere(new PhongMaterial(light, 0x00cc00, 0x000000, 10), 100, 10, 10);
			var smallSphere2:Sphere = new Sphere(new PhongMaterial(light, 0x0000cc, 0x000000, 10), 100, 10, 10);
			smallSphere1.x = -500;
			smallSphere1.y = 500;
			smallSphere2.x = 400;
			smallSphere2.y = -600;
 
 
			pivotPoint.addChild(smallSphere1);
			pivotPoint.addChild(smallSphere2);
 
			scene.addChild(sphere);
			scene.addChild(pivotPoint);
			scene.addChild(light);
 
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
 
		private function objectOverHandler(event:InteractiveScene3DEvent):void
		{
			Mouse.hide();			
		}
 
		private function objectOutHandler(event:InteractiveScene3DEvent):void
		{
			Mouse.show();
		}
 
		private function enterFrameHandler(event:Event):void
		{
			pivotPoint.yaw(1);
			pivotPoint.pitch(.5);
			light.copyTransform(mouse3D);
			light.moveBackward(100);
			singleRender();
		}
	}
}

Tags: , ,

  • Good port!

    Mouse3D.enabled = true;
    mouse3D = viewport.interactiveSceneManager.mouse3D;

    what does this mean?
  • John Lindquist
    yeah, maybe it's best if I remove that from the code view. But then people might ask how the text got there :)
  • JB
    ahh I see
    I just did a cut n paste of the code view.
  • John Lindquist
    The header.swc is included in the lib folder of the source download. Just import the .zip into flex and it will compile just fine.
  • JB
    Thanks John, finally got to work something out that never got answered on the mailing list.

    ps
    var headerText:headerContainer = new headerContainer();
    is going to throw errors

    cheers :)
blog comments powered by Disqus

Search

Recommended Books

Speaking at FITC Toronto

Recent Comments

 

November 2008
M T W T F S S
    Dec »
 12
3456789
10111213141516
17181920212223
24252627282930

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