4 Replies Latest reply on Mar 18, 2011 1:17 AM by Matt Paintin Branched to a new discussion.

    Inverse Position Expression...still need some help please!!

    Matt Paintin Level 1

      Following up a post from a few days ago....

       

      Im creating a hand made anamorphic lens flare and I want to control the position of the elements in it with a null

       

      Mylenium kindly pointed me to his site which has great projects to download but its beyond my math capabilities and I havent been able to get my head around it and apply it to my project.

       

      I have this expression which has got me started

       

      pRef=thisComp.layer("null 1").position;

      X=thisComp.width-pRef[0];
      Y=thisComp.height-pRef[1];

      [X,Y]

       

       

      But if I want to add additional lens flare elements that move at a different relative position, this expression wont do it. Its only good for one element.

      I only want a few elements in the flare

       

      Can anyone suggest a simple way to do this? Im only looking at having 2 or 3 flare elements in it...nothing heavy.

        • 1. Re: Inverse Position Expression...still need some help please!!
          Mylenium Most Valuable Participant

          Sorry for not checking back, but the current forum problems make it  difficult to post without being kicked out every 2 minutes.... What you  want is very much in the project I was pointing you to - you need a  relative offset along an imaginary view axis, so let's try this by  commenting some updated code for the position of a secondary element a  bit (parts you won't need not included):

           

          cSource3D=thisComp.layer("Light"); //reference a 3D light as source

          cSource2D=cSouce3D.toComp([0,0,0]); //convert to screen coordinates

           

          cMiddleX=thisComp.width*0.5; //midpoint X

          cMiddleY=this Comp.height*0.5; //midpoint Y

           

          cDiffX=cSource[0]-cMiddleX; //position difference X

          cDiffY=cSource[1]-cMiddleY; //position difference Y

           

          cAngle=Math.atan2(cDiffY,cDiffX); //find angle

           

          cOffset=200; //distance from middle

           

          X=cMiddleX+Math.sin(cAngle)*cOffset;

          Y=cMiddleY+Math.cos(cAngle)*cOffset;

           

          [X,Y]

           

          Mylenium

          • 2. Re: Inverse Position Expression...still need some help please!!
            Matt Paintin Level 1

            Thanks Mylenium

            I totally understand your problems replying....its not a problem....I know you are a busy guy! Im just grateful you have taken the time to help out!

             

            Forgive my ignorance with the math on this subject

             

            So if I am to understand it correctly to I just apply the complete revised expression to my secondary element?

            • 3. Re: Inverse Position Expression...still need some help please!!
              Mylenium Most Valuable Participant

              cSource3D=thisComp.layer("Light"); //reference a 3D light as source

              cSource2D=cSource3D.toComp([0,0,0]); //convert to screen coordinates

               

              cMiddleX=thisComp.width*0.5; //midpoint X

              cMiddleY=thisComp.height*0.5; //midpoint Y

               

              cDiffX=cSource2D[0]-cMiddleX; //position difference X

              cDiffY=cSource2D[1]-cMiddleY; //position difference Y

               

              cAngle=Math.atan2(cDiffY,cDiffX); //find angle

               

              cOffset=200; //distance from middle

               

              X=cMiddleX+Math.sin(cAngle)*cOffset;

              Y=cMiddleY+Math.cos(cAngle)*cOffset;

               

              [X,Y]

               

              Yes, simply copy&paste the above code ( I corrected the typos) to your secondary element and adjust the cOffset variable to suit (you could tie it to a slider, if needed; negative values move in opposite direction). Make sure to adjust the reference to the light in your comp (or your 3D Null). If you use an expression Point control or the Lensflare effect on a solid, you don't need the first line and the second line would then look something like that:

               

              cSource2D=thisComp.layer("Lensflare").effect("Lens Flare")("Flare Center")

               

              Mylenium

              • 4. Re: Inverse Position Expression...still need some help please!!
                Matt Paintin Level 1

                Thats great Mylenium

                 

                Again, thank you so much for taking the time to explain the details.