Flash Away3D中的场景拖动

private function onEnterFrame(event:Event):void{
	if(this.canDrag&&this.isDrag){
		var pos3D:Vector3D=App.sceneCamera.lookAtPosition;
		var vec:Vector3D=App.view.unproject(App.stage2D.mouseX,App.stage2D.mouseY,1);
		var vec2:Vector3D=App.view.unproject(this.lastMouseX,this.lastMouseY,1);
		this.getCross(vec, App.camera.position, 200);
		this.getCross(vec2, App.camera.position, 200);
		var vec3:Vector3D=vec.subtract(vec2);
		pos3D.x = this._cameraPos3D.x-vec3.x;
		pos3D.z = this._cameraPos3D.z-vec3.z; 
		App.sceneCamera.lookAtPosition=pos3D; 
	}
}

public static function getCross(source:Vector3D, reference:Vector3D, y:Number=0):void{
	if (source.y==reference.y || source.y==y) { return; }
	source.x += (y-source.y)/(reference.y-source.y)*(reference.x-source.x); 
	source.z += (y-source.y)/(reference.y-source.y)*(reference.z-source.z);
}

你可能感兴趣的:(Flash)