Check out the Latest Articles:
3D plane, 3D lighting meet sound spectrum

Last post I did, I got a nice 3D sphere rendered with some simple diffuse ( I think ) lighting. It looks pretty good.
Here is another example with 3D lighting, only this time, I’m using a simple plane, and also using, drum roll, the sound spectrum to set the y property of the vertices.
All it is in the long run, is just a 3D sound visualizer I guess. Cool thing is that it doesn’t look bad, if you pretend not to see the buggy triangles being drawn without culling or whatever, it does the trick. I’m just not good enough at math and programming and stuff to get proper culling coded :) .

Anyway!!!
check out the swf, or just grab the shit source code.

ps: you might need to close any other pages / tabs with flash content using sound or video.
I know… that blows!

Flash 10 drawTriangles() with 3D light source headache.

The AS3.0 drawing API was update with the release of Flash Player 10. That’s no news, everyone knows that.
Well I had not ever used any of the new stuff in the API, shame on me!

Anyway! There is a cool new function I wanted to try out: drawTriangles(). How cool is that ? Plot all your points out, make you commands and indices vectors and let Flash do the rest.
Ok so it gets even better to know that you can map a bitmap to the triangles by passing in a uvtData vector to the drawTriangles function. Sweet.

Obviously I was thinking: plot points, drawTriangles, make a sphere or 3d object and then add some lighting. Well no!! Because if you use the drawTriangles function you don’t have that much control over how each triangle will be rendered, and you can’t really change each triangle’s color depending on the light source. Or at least I don’t know how to do it.
So I basicaly had to end up coding my own version of the drawTriangles function so I could have control over the color of each triangle.

All of that brings us to computing the light source on each triangle and then rendering it.
I’m not going to get into the details of rendering lights, google will do a far better job than me. But the main concept is this:

  • Given a light source at x, y, z, get the vector going from the light source to the current triangle
  • Now get the normal vector to the triangle
  • Calculate the angle between those two vectors and get a scalar
  • Use that scalar to change the color values of the triangle
  • Draw the triangle

That’s all there is to it.
So, here it finaly is, a 3D sphere with some lighting, all that, no thanks to drawTriangles!
It’s rendering about 1000 triangles each frame.
You can get the source here. This is one of most unsexy code ever! You have been warned

Oh and don’t forget to double click the stage :)

So I’ve been porting some of my data structures from C over to AS3.0 and I decided to test the linked list out against the Array and Vector data types. It turns out that inserting or deleting items from a linked list is much faster than doing so in an Array or even a Vector. [...]

Dijkstra’s algorithm AS3

Say you live in weighted graph. And say you want to go from vertex A on that graph to vertex D, for instance, following the shortest path. Well it so happens that a smart man called Edsger Dijkstra already figured that one out. He came up with an algorithm to get the shortest path weight [...]

Soft body dynamics with Verlet integration

Just some fooling arround with Verlet integration to try and render soft bodies. They’re not perfect, but pretty fun to play arround with.
If you are interested in how this stuff works you should really read this article, it’s really “cool”.
Anyway, all this is, is a graph of vertices connected together with semi rigid constraints.
And now [...]

Fun with binary ( part one )

Everyone loves binary, playing around with zero’s and one’s is the shizzle… true dat!
On the other hand if you don’t know much about bits and bytes and so on, you should really read this article, it’s very good and does a better job than I ever could at explaining how binary and bitwise operators work.
Anyway… [...]