PV3d Plane Face Mouse Example
@author jessefreeman
/**
* Copyright FlashBum ( http://wonderfl.net/user/FlashBum )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/k0hG
*/
package
{
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.view.BasicView;
import flash.events.Event;
/**
* @author jessefreeman
*/
public class FlashTest extends BasicView
{
private var plane : Plane;
public function FlashTest()
{
super( );
create3dObject( );
startRendering( );
}
private function create3dObject() : void
{
var mat : ColorMaterial = new ColorMaterial( 0xff0000, 1, true );
plane = new Plane( mat );
scene.addChild( plane );
}
/**
* This rotates the plane to "face" the mouse.
*/
protected function updateMouseRotation() : void {
var tmpWidth : Number = 400;
var tempHeight : Number = 400;
var rotY : Number = (mouseX - (stage.stageWidth * .5)) / (tmpWidth * .5) * (-20);
var rotX : Number = (mouseY - (stage.stageHeight * .5)) / (tempHeight * .5) * (-20);
plane.rotationX = plane.rotationX + (rotX - plane.rotationX) * .5;
plane.rotationY = plane.rotationY + (rotY - plane.rotationY) * .5;
}
override protected function onRenderTick(event:Event = null):void
{
updateMouseRotation();
super.onRenderTick(event);
}
}
}