当前位置: 代码迷 >> Web前端 >> 鼠标追随旋转
  详细解决方案

鼠标追随旋转

热度:194   发布时间:2012-10-30 16:13:36.0
鼠标跟随旋转
package
{
import flash.events.Event;
import flash.geom.Point;
import flash.html.script.Package;

import mx.core.UIComponent;

public class testV extends UIComponent
{
public var point1:Point=new Point(300,150);
public var point2:Point=new Point(500,50);
public var point3:Point=new Point(700,150);
public var point5:Point=new Point(300,250);
public var r:RotateToMouse;
public function testV()
{
super();
graphics.lineStyle(1);

/*for(var angle:Number=0;angle<Math.PI*2;angle+=0.1){
            graphics.lineTo(angle*100,Math.sin(-angle)*100);   //这里angle改成负的,因为是FLash坐标系的原因
trace(angle*100,Math.sin(angle)*100);
}*/
this.addEventListener(Event.ADDED_TO_STAGE,addStage);
//addEventListener(Event.ENTER_FRAME, draw);
//draw();
}
public function addStage(e:Event):void
{
trace("addStage");
var r:Circle=new Circle();
addChild(r);
/*r=new RotateToMouse();
addChild(r);*/
}
public function draw(e:Event):void
{
graphics.clear();
graphics.lineStyle(1);
graphics.moveTo(point1.x,point1.y);
graphics.lineTo(point2.x,point2.y);
graphics.lineTo(point3.x,point3.y);
graphics.lineTo(point1.x,point1.y);

//定义向量
var v1_2:Vector2=new Vector2(point2.x-point1.x,point2.y-point1.y);
var v1_3:Vector2=new Vector2(point3.x-point1.x,point3.y-point1.y);

var v12_:Vector2=v1_2.Project(v1_3);    ///这时只知道向量大小,不知道具体位置
//trace(v12_.x,v12_.y);                  //这里投影出来的向量v12_它的高是0,这是与x轴平行的线,所以高是0
var point4:Point=new Point(point1.x+v12_.x,point1.y+v12_.y);//这里不知道向量v12_的位置,但知道它的横竖长度,因为是
//画出高
var v2_4:Vector2=new Vector2(point2.x-point4.x,point2.y-point4.y);
graphics.moveTo(point4.x,point4.y);
graphics.lineTo(point2.x,point2.y);
Vector2.DrawArrow(graphics,point4.x,point4.y,point2.x,point2.y);
var a:Number=Vector2.GetAngleOfTwoVector(v12_,v2_4);
trace(30*Math.PI/180);
graphics.moveTo(point4.x,point4.y);
graphics.lineTo(point5.x,point5.y);
var v45:Vector2=new Vector2(point5.x-point4.x,point5.y-point4.y);
Vector2.DrawArrow(graphics,point4.x,point4.y,point5.x,point5.y);
point5.x=mouseX;
point5.y=mouseY;
var dx:Number = point5.x-point4.x;
var dy:Number = point5.y-point4.y;
var radians:Number = Math.atan2(dy, dx);
//var angle:Number=Vector2.GetAngleOfTwoVector(v12_,v45);

v45.Rotate(radians);

}
}
}
  相关解决方案