Jump to content

HELP! Polar To Rect Conversion (In Codelab)


Recommended Posts

I'm Trying To Make This Work.

int Amount1=0;	//[0,100]Slider 1 Description
int Amount2=0;	//[0,100]Slider 2 Description
int Amount3=0;	//[0,100]Slider 3 Description

void Render(Surface dst, Surface src, Rectangle rect)
{
   PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
   Surface dst = dstArgs.Surface;
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

   long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);
   long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);

   for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
       	double r = System.Math.Sqrt(x * x + y * y);
	dst[x,y] = src[r, CenterY];
       }
   }
}

Basically It Move Pixels To The Center And Then Moving Them Right Based On The Radius Value, If I Knew How To Move The Pixels Then I Could Easily Finish It (And Make The Pixels On The Left Go To The Left As Well) So Yeah. Any Help Would Be Appreciated.

Link to comment
Share on other sites

Okay, I got it. You weren't thinking in the right direction :D

int Amount1=0;   //[0,100]Slider 1 Description
int Amount2=0;   //[0,100]Slider 2 Description
int Amount3=0;   //[0,100]Slider 3 Description

void Render(Surface dst, Surface src, Rectangle rect)
{
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
   float width = dst.Bounds.Right - dst.Bounds.Left;
   long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);
   long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);
   float r, theta, offx, offy, setx, sety;
   for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           r = y/2;
           theta = (float)((System.Math.PI*2)*(x/width));
           offx = (float)(r*System.Math.Cos(theta));
           offy = (float)(r*System.Math.Sin(theta));
           setx = (float)(CenterX+offx);
           sety = (float)(CenterY-offy);
           dst[x,y] = src.GetBilinearSample(setx, sety);
       }
   }
}

It's actually rather simple.

~~

Link to comment
Share on other sites

I Don't Expect You To Get It Perfect BTW, But Much Thanks For It.

Steps For Unpefrectness:

1. New 400x400 Image

2. Make New Layer

3. Horizontal Line With Width Of 20 in middle

4. run rect to polar

5. run codelab script

It's Still Pretty **** Good In My Opinion.

EDITED: This is a family friendly site. Please reserve the cussing for your mother. :P ~BoltBait

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...