hlxldb

LED光立方制作全过程(四十三)

0
阅读(2180)

Step 67PC Software: Effect 2, sidewaves

 

 

This is basically the exact same function as the ripple function.

The only difference is the coordinates of the point used to calculate the distance to each x/y coordinate. We call this point the origin, since the wave emanates from this point.

The origin coordinate is calculated like this:

x = sin(iteration counter) y = cos(iteration counter)

The result is that these x and y coordinates moves around in a circle, resulting in a sin wave that comes in from the side.

We just wanted to show you how easy it is to completely alter an effect by tweaking some variables when working with math based effects!

 

Step 68PC Software: Effect 3, fireworks

PC Software: Effect 3, fireworks

PC Software: Effect 3, fireworks

 

This effect was quite fun to make.

To make this effect, we really had to sit down and think about how fireworks work, and which forces influence the firework particles.

We came up with a theoretical model of how fireworks work:

1) A rocket is shot up to a random position, origin_x, origin_y, origin_z.

2) The rocket explodes and throws burning particles out in random directions at random velocities.

3) The particles are slowed down by air resistance and pulled towards the ground by gravity.


With this model in mind we created a fireworks effect with a pretty convincing result. Here is how it works:

1) A random origin position is chosen. (within certain limits, x and y between 2 and 5 to keep the fireworks more or less in the center of the cube. z between 5 and 6. Fireworks exploding near the ground can be dangerous! :p)

2) The rocket, in this case a single voxel is moved up the Z axis at the x and y coordinates until it reaches origin_z.

3) An array of n particles is created. Each particle has an x, y and z coordinate as well as a velocity for each axis, dx, dy and dz.

4) We for() loop through 25 particle animation steps:

5) A slowrate is calculated, this is the air resistance. The slowrate is calculated using tan() which will return an exponentially increasing number, slowing the particles faster and faster.

6) A gravity variable is calculated. Also using tan(). The effect of gravity is also exponential. This probably isn't the mathematically correct way of calculating gravity's effect on an object, but it looks good.

7) For each particle, the x y and z coordinates are incremented by their dx, dy and dz velocities divided by the slowrate. This will make the particles move slower and slower.

8) The z coordinate is decreased by the gravity variable.

9) The particle is drawn on the cube.

10) Delay for a while, then do the next iteration of the explosion animation.


We are quite pleased with the result.