Mouse Aware 3D

Sunday, 9 November 2008 23:44 by shawny

While setting up my recent project for use with 3D, I wanted to have a way to have the 3D scene mouse aware.  This can be accomplished quite easily by adding the following lines of code to your onEnterFrame event listener.

private function onEnterFrame(e:event):void

{

    // In my case, I would use a pivot as 'yourObject' since I'm adding a multitude of objects to a single display 3D object

    yourObject.rotationX += ((this.width/2)-mouseX);
    yourPbject.rotationY += ((this.height/2)-mouseY);

Then all you have to do is render the scene.  Couple of handy lines of code.  I have seen examples on the web where the calculation is divided by some number to slow down the speed of rotation.  One example that I like a lot is located at http://www.sebleedelisle.com?p=157 .

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading