**
Distorting 3d objects
**

*
Black/Twilight/Spinning Kids
*

This is just theory and partially untested.

Do you want to have spikes on your ball? Ok, then this article is just for you. When I was making a 64k intro I needed to generate a lot of objects, and animating a few of them would also be desired, so I tried a few aspects of distorting the objects... and so I came up with this thingie.

The atan2 function in math.h returns the tangens of an angle you give it with two variables. So if you pass x and y (-100..100 let's say) you would get back an angle that goes from 0 to 2*pi. Then think, we want soft spikes and for generating them we would need a periodical function, and bingo, we already have two that are of use here. Sin and cos. We will be using cosinus for simplification of the distortion algorithm because of its start at +1.

But what do we pass to the cos? Well as I said, atan2 returns an angle which ranges from [0..2pi] and like magic 2pi is also the base period of cos and sin functions. We will be using cos because we do less adds this way.

As I said before we get an angle with atan2 but passing the x and y of a vertex to the atan2 function only returns the angle for the z axis, what about x and y axis? Well, you just do the same thing... for y pass x and z and for x pass y and z.

distortvaluemul = ((1-cos(atan2(x,y)*NR_Z_SPIKES))+ (1-cos(atan2(x,z)*NR_Y_SPIKES))+ (1-cos(atan2(y,z)*NR_X_SPIKES)));

With this you get the length of the distortion, and just multiply the
vertex with distortvaluemul which is *positive* and ranges from 0..6.

To optimize this algorithm, you can make a look up table from the cos and atan2 functions, of course fixpointed, and for better appearance and animation just include a frame counter variable (or in demos a timer) and use it in the cos() so you make the spikes travel around the object... That's about all. Simple. Short.

**
Black/Twilight/Spinning Kids
**