Archive for March, 2006

PyODE physics in PyOgre example

Guess it shouldn’t have taken so long for me to get around to doing this, but at least it’s done now.

Attached to this post you’ll find a zip file, containing a small example application which allows you to spawn PyODE physics-enabled cubes with the middle mouse button into a PyOgre world. You can then bounce and roll the cubes around by holding the left or right mouse buttons.

The code is fairly straight-forward, and I’ve included quite a number of comments. Should be easy enough to follow what’s going on if you’ve been through the PyOgre tutorials.

A note of performance and stability - you can safely spawn loads of cubes as long as there are not too many collisions going on at once (after around 50 cubes, things start to get really sluggish if there are too many inter-cube collisions going on). In practice though, I doubt you’d need that many collisions happening at any one time. Also, If you make a large pile of cubes, lift them all up, and let them fall down together, it seems to bomb out as there are too many collisions happening when they all land on top of eachother at once. I haven’t debugged this very much, so I’m not sure yet if it’s a ODE limitation, or something bad I’m doing in the code. If anyone works it out, I’d be interested to know.

Please don’t ask for advice on stuff like per-polygon collisions, terrain collision and the like, I have not really messed with this beyond the state of this example. Once you get the basics going after checking out the example, I’m sure a few questions shot off at the PyOgre Forums would turn up more useful results than asking me :).

Have fun ;).

Technorati Tags: , , , , ,

Attached Files:

Heavy Delphi cracksmoking

As we all know, PNG images are so much cooler than BMP images. Especially with alpha channels.

A while ago, I found this rather spiffy PNG library for Delphi, which allows you to load PNG files into a TPicture or similar, complete with alpha channels. Generally, it works simplest with TImage, however being a TGraphic subclass, you can do all sorts of drawing and everything else on it.

ANYWAY, I wanted to be able to use these things on buttons (standard TSpeedButton and TBitBtn), however their Glyph property is a TBitmap, preventing us from doing a simple Button.Glyph.LoadFromfile and loaging a PNG file. The other option is to load up the PNG on it’s own with a TPNGObject, and assign it to the glyph property, however the alpha gets buggered.

So I came up with a crackful work-around (as I’m finding 90% of all Delphi coding is):

procedure pngGlyph(Btn: TControl; Img: String);
var
	PNG: TPNGObject;
	BMP: TBitmap;
begin
	PNG := TPNGObject.Create;
	BMP := TBitmap.Create;

	try
		PNG.LoadFromFile('path\to\glyphs\'+Img+'.PNG');   // Update the path to your .png files, or update this to get them somewhere else.

		BMP.Width := PNG.Width;
		BMP.Height := PNG.Height;
		BMP.Canvas.Brush.Style := bsSolid;
		BMP.Canvas.Brush.Color := clBtnFace;
		BMP.Canvas.FillRect(Rect(0, 0, PNG.Width, PNG.Height));
		BMP.Canvas.Draw(0, 0, PNG);
		BMP.Canvas.Pixels[0, BMP.Height-1] := clBtnFace;

		if (Btn is TSpeedButton) then
			(Btn as TSpeedButton).Glyph.Assign(BMP);
		if (Btn is TBitBtn) then
			(Btn as TBitBtn).Glyph.Assign(BMP);
	finally
		PNG.Free;
		BMP.Free;
	end;
end;

To use it, you call it like “pngGlyph(SpeedOrBitButton, ‘glyphname’);”, and the procedure will hack your button’s glyph into something that looks nice. You can use fully alpha-enabled PNG files, and they should look right.

Of corse it would be better to create a new button type with this procedure inside that, so you don’t have to call this for every button you want to add a PNG to, but I don’t really feel like re-adding a million buttons, it’s quicker for me to do a million procedure calls :).

RSS seems messy

Heh :D
So I’ve started work on my own small RSS aggregator for some or other web project I may or may not actually complete. And no, it’s nothing like Gregarius, it’s more of an ‘internal function’ of a larger project.

So anyway, after checking out the various RSS version specs and things, I hunted down as many feeds as I could to get an idea of the kinds of data I’m going to end up sifting through.

Wow. Despite the fact that there are standards out there doesn’t seem to mean much. Nearly every feed is a world apart from the next one, either throwing in millions of useless custom tags, renaming standard tags to some other random thing that made sense to the author and nobody else, leaving out loads of actual useful information, mixing and matching the specs as they feel the urge, and a million other randomnesses.

Anyway, on the way to making sense of it all, I fed some of them through MagpieRSS, which actually does a fairly reasonable job of making them a bit more sane. Still, I have to guess a lot of fields and things, and pretty much hope for the best.

At the moment, people’s RSS feeds generally seems more psychotic than some of their use of HTML.

Technorati Tags: , ,