Archive for September, 2008

Never sort, always compare

Friday, September 26th, 2008

I had an instance today where I needed to find the boundaries of a collection of points. All of the points were in an array, so I thought, “OK, I’ll do a sortOn for x and then get the top and bottom values and then do the same for y. This worked, but was really slow. After doing a few tests, I realised the quicker way was to loop through the array and compare to an initial value. An added bonus is that I only need to loop through the array once for any number of values. Here’s the code:


var xLo:Number =
var xHi:Number = points[0].x;
var yLo:Number =
var yHi:Number = points[0].y;

var len:int = points.length;
for (var i:int = 0; i < len; i++)
{
var pt:Point = points[i] as Point;
if (pt.x < xLo) xLo = pt.x;
if (pt.x > xHi) xHi = pt.x;
if (pt.y < yLo) yLo = pt.y;
if (pt.y > yHi) yHi = pt.y;
}

Back To The Trees! Source

Wednesday, September 24th, 2008

Here’s the source from my last tree experiment. Please note that it’s the source folder from Flex project, but of course you can just use the classes…

If you do use it in a Flex Project, you’ll need to import the playerglobal.swc from Flash for it to work (it uses BezierSegment from the fl.motion package)

get the source code

I should add that this code is far from optimised. The bezier curve class I’m using wasn’t really designed for this, so it is very slow when smoothing as it iterates over all of the points. I’m going to be optimising this soon so keep an eye out!

Back to the trees!

Wednesday, September 24th, 2008

I’ve been having a play with generative trees again. I’ve been meaning for a while to integrate Bezier curves into my trees for some time, but haven’t had the time to update my BezierChain class to make it accept any number of points. Well, in my paid work, I had to do exactly that, so I thought it was time to put them in. Click the link to see the results!

Random trees with Bezier Curves

I’ll post up the source code if anyone is interested…

Racing Game: Moving into the 3rd Dimension

Friday, September 19th, 2008

So far, I’ve been working with Box2D’s debug mode, which provides a really quick way to test out your physics model to make sure it works, but doesn’t exactly look pretty. The next step was to make it look a bit better.
(more…)

Real Car Physics

Thursday, September 18th, 2008

This website here has a link to a document that shows how to do realistic car physics (thanks to John from Unwrong for pointing me in the right direction). Scroll down to the bottom to find the link. It’s really in depth!

LINK

Flash assets in Flex? With Code? Strongly typed? Use a SWC!

Thursday, September 18th, 2008

Flash -> File -> Publish settings -> Flash -> Export SWC.
Flex -> Project -> Properties -> Actionscript Build Path -> Library Path -> Add SWC

Done! Strongly typed, auto completing, code intact Flash library assets in Flex!

No messing.