A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Curved (Parabolic) Cursor Reflection

  1. #1
    Senior Member
    Join Date
    Jan 2003
    Posts
    103

    Curved (Parabolic) Cursor Reflection

    I have a bit of a weird problem. I ALMOST have it working how I want it, but my lack of math skills are making it quite difficult. Anyway, I have a glass surface with a curved perspective image. It's almost impossible to explain, so I made an example of what I want to have happen (attached in MX 2004 format). Here's what I have on the reflected cursor MC:
    Code:
    onClipEvent (mouseMove) {
    	updateAfterEvent();
    	xcoordinate = Math.abs((_root._xmouse/2)-250);
    	_x = _root._xmouse;
    	_y = (_root._ymouse*-1)+1050+(xcoordinate);
    }
    Right now, the reflection of the cursor is acting as if it is a triangular, cornered wall behind it rather than a curved one. Obviously this is because I'm taking the absolute value rather than squaring a value (simple algebra, right?) Referring to the attached example, how do I make the reflected cursor follow the red CIRCULAR (parabolic) path instead of the purple triangular path? I can't find the right equation for that parabola for the life of me... PLEASE help, I'd really appreciate it! Thank you!
    Attached Files Attached Files

  2. #2
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    Location
    Houston!
    Posts
    338
    I think I got something pretty close to right.
    code:
    onClipEvent (mouseMove) {
    updateAfterEvent();
    xcoordinate = Math.abs((_root._xmouse/2)-250);
    _x = _root._xmouse;
    yDivide = Math.pow(_root._xmouse-505,2)/2100+527;
    _y = yDivide-(_root._ymouse-yDivide);
    }


    The problem is that your curve is actually an arc, not a parabola so it can't match up perfectly.

    You can see that the yDivide equation would look like this algebraically:
    y = (x-505)^2/2100+527
    A good rule of thumb for all equations in y-intercept is that a number grouped with the x (-505) will move the parent function (y=x^2) that many units to the left, or negative units in this case. A number on the outside (527) will move the line up that many units (but computers use an inverted y axis so positive numbers actually go down). The division by 2100 just makes the parabola wider and I just guessed at it.

    Hope this helps
    Neal

  3. #3
    Senior Member
    Join Date
    Jan 2003
    Posts
    103
    Whoa, not only was that quick, but perfectly correct! Thank you SO much!! Turns out I was just going at it wrong.

  4. #4
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270
    Yanathin,

    Here's the parabolic function you need for that curve. It took me a while, but it should work quite well. Just put it in your "cursorref" instance.
    Code:
    onClipEvent (mouseMove) {
    	updateAfterEvent();
    	// VARS
    	var aNum = (122/250000);
    	var bNum = 0;
    	var cNum = 540;
    	var funcOfX = _root.cursorimage._x - 500;
    	
    	//	FORMULA	
    	var firstTerm = aNum * Math.pow(funcOfX, 2);
    	var secondTerm = bNum * funcOfX;
    	var thirdTerm = cNum;
    	var parabolicFormula = firstTerm + secondTerm + thirdTerm;
    	
    	_x = _root.cursorimage._x;
    	_y = parabolicFormula + (parabolicFormula - (_root.cursorimage._y + _root.cursorimage._height));
    }
    If you want to modify the curve, PM me about the specifics of the quadtratic formula. Otherwise I'll leave it at this for now.

    +Q__
    Qwai•zang \kwî-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

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