• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

# Fast way to smooth a 2D polygon

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

21 replies to this topic

### #21samoth  Crossbones+   -  Reputation: 2843

Like
0Likes
Like

Posted 17 July 2012 - 08:40 AM

samoth, could you please explain your approach visually? I don't understand what kind of vector you mean.

I am talking about the vector that you refer to as "normal" in your 5:05 post. Which I guess is somewhat kind of the correct term too, although this "normal" is not necessarily "normal length" in the soft body calculation. I called it "pressure" vector for that reason. Maybe "perpendicular" is a better term... but let's not dispute what we call it, if everyone knows what vector we talk about.

Either way, it's that vector one would be interested in, as it is already available for free and it points into the correct direction. If you imagine a straight line between two control points, then the smoothed point in the middle would be "pulled" outside in the direction of the normal (by a small amount, say, 1/3 of the normal's length, one would need to experiment what looks best).

Note that coincidentially, drawing the outline and smoothing is almost the same. Except for the outline, you will need to normalize the "non-normal normal".

As for "fast inverse square root in Java", this is probably a bit of a non-optimization. Executing half a dozen lines of Java code including two rounding operations is almost guaranteed to be much slower than to just tell the Java compiler to divide by a square root.

Edited by samoth, 17 July 2012 - 08:41 AM.

### #22pekhe  Members   -  Reputation: 136

Like
0Likes
Like

Posted 17 July 2012 - 09:07 AM

Yeah, I created a little timer app that measures how many milliseconds are spent when calculating 1 000 000 times the square root. The "inverse square root" algorithm didn't do any better than the default "Math.sqrt".

Okay... I'll go with the Math.sqrt.
Later when I optimize the code, I want to learn how to implement OpenCL with LWJGL and Slick2D so i can calculate all this smoothing and outlines on GPU.

Edited by pekhe, 17 July 2012 - 09:29 AM.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS