dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Trigonometry

  1. #1
    Senior Member Bernz's Avatar
    Join Date
    Jun 2005
    Location
    Mid-Eastern U.S.
    Posts
    161

    Trigonometry

    I am making my own scripted camera.

    The idea behind a scripted camera is that you just move it anywhere you want on the screen, and, once the movie is compiled, a script in it makes that part of the movie visible. The idea comes from this web page.

    I've already gotten it to be able to go left, right, up, down, and resize. However, I also want it to be able to rotate, which is something that even the guy who invented it can't figure out. Unfortunately, that requires trigonometry, and I can't get it to work in Flash.

    Once horizontal and vertical movements, and resizing, have been taken care of, I think all the math that's left is this:

    If I've got it right (I might not), and that's how to solve it, I myself could do it with a pencil and paper, but I can't seem to get Flash to do the trig correctly, at least not with all four quadrants with the same code.

    The FLA file with my code in it is HERE.

    I feel like I'm so close to figuring it out. I know ActionScript, and I know Trig, just... not both at the same time.

  2. #2
    VIP Member
    Join Date
    Nov 2000
    Location
    United Kingdom
    Posts
    254
    I often attept things I cant do. lol. What exactly are you trying to figure out. I normally just write down tre maths. and then translate it into stes in flash.

  3. #3
    Senior Member Bernz's Avatar
    Join Date
    Jun 2005
    Location
    Mid-Eastern U.S.
    Posts
    161
    Well, if you go to the link I provided, it'll explain the basic idea behind a scripted camera. (Mine is a little different, in that the (0,0) point is in the upper left, and that it doesn't turn invisible because it has the controlls for the movie in it.)

    Basically, having the initial x and y cordinates, the _x and _y, I figure out what the coordinates should be after the rotation, the _x and _y, by using the angle of rotation, _rotation, and the distance from the (0,0) point of the camera to the (0,0) point of the _root.

    Either my math is wrong, or my scripting is wrong, but I can't get it to work correctly.

  4. #4
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    Basically that approach should be correct.
    I just fix some positve/negative things.
    Attached Files Attached Files

  5. #5
    Senior Member Bernz's Avatar
    Join Date
    Jun 2005
    Location
    Mid-Eastern U.S.
    Posts
    161
    Thank you so much!!!


    I had messed around with the +/- signs, but I was never able to get it to work in all four quadrants. I guess it's because of your changing my Math.asin(_parent._y/r) into Math.atan2(y, x). I would never have though of that.


    Side note:
    Hmm, calculating trigonometry seems to take a chunk out of my CPU I'd rather save for other calcutations. I think I'll make the symbol into a component, and make it able to be used either with or without the trig.

  6. #6
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    If you dont insist on Math, and _parent is the _root, then use localToGlobal make the script very simple.
    code:
    this.onEnterFrame = function() {
    _parent._yscale = 10000/(this._yscale);
    _parent._xscale = 10000/(this._xscale);
    _parent._rotation = -this._rotation;
    var point = {x:0, y:0};
    this.localToGlobal(point);
    _parent._x-=point.x;
    _parent._y-=point.y;
    };


  7. #7
    Senior Member Bernz's Avatar
    Join Date
    Jun 2005
    Location
    Mid-Eastern U.S.
    Posts
    161
    HEY, WOW!!!

    I didn't know about that function! Thanks!


    So, that's, how may hours of my life I've wasted trying to get that trig to work, when all I had to do was use localToGlobal()?

    Oh, and, by the way, I've discovered that the code should be
    Code:
    function camControl():Void {
    	_parent._yscale = 10000/(this._yscale);
    	_parent._xscale = 10000/(this._xscale);
    	_parent._rotation = -this._rotation;
    	var point = {x:0, y:0};
    	this.localToGlobal(point);
    	_parent._x-=point.x;
    	_parent._y-=point.y;
    }
    camControl();
    this.onEnterFrame=camControl;
    to get it to work on most keyframes.
    Last edited by Bernz; 06-05-2005 at 09:45 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center