Thursday, April 22, 2010

3D rotation based on Mouse Position

var defRot:Number = 35;

stage.addEventListener(MouseEvent.MOUSE_MOVE, updateRot);

function updateRot(myEvent:MouseEvent):void {
if(mouseX > 300){
if(imageGallery_mc.rotationY >= defRot){
imageGallery_mc.rotationY = defRot;
}else{
imageGallery_mc.rotationY+= .5;
}
}
if(mouseX < 300){
if(imageGallery_mc.rotationY <= -defRot){
imageGallery_mc.rotationY = -defRot;
}else{
imageGallery_mc.rotationY-= .5;
}
}
if(mouseY > 240){
if(imageGallery_mc.rotationX >= defRot){
imageGallery_mc.rotationX = defRot;
}else{
imageGallery_mc.rotationX+= .5;
}
}
if(mouseY < 240){
if(imageGallery_mc.rotationX <= -defRot){
imageGallery_mc.rotationX = -defRot;
}else{
imageGallery_mc.rotationX-= .5;
}
}
}

No comments:

Post a Comment