Archive for the ‘Programming’ Category

Amazing

Friday, September 9th, 2005

I was working on my game last night, trying to implement vehicle physics. I couldn’t used the basic capped cylinder geometry for the tires on my vehicle because tires aren’t shaped like that. I implemented some code to turn the list of faces on my model into an ODE geometry, but collision just didn’t work. I then went to google for help, and apparently Triangle Mesh collision detection is a mess in ODE. Frustrated, I went to google looking for a new physics engine to use for my game, and I found this.

I am just totally amazed. It’s got everything I need to make an awesome 3d game. It looks easy to use (I’ve already looked at some tutorials) and it combines all of the benefits of a C++ based engine with the ridiculously awesome programming capabilities of python. To anyone who has started to do work on my game, don’t worry – this doesn’t really mean anything to you other than that the probability of this game being finished has just shot up. Well, really, I should have defined a probability function that maps a given time to a probability of the project’s completion by that date, and the area under the above curve has increased significantly.

This is going to be great.

Assumptions Always Get Me

Thursday, September 8th, 2005

As it turns out, a for cylinder to be ‘capped’ doesn’t mean that it has a flat top, like every other cylinder I’ve ever used, but rather it means it has a rounded top. Like a sphere that’s taken in the middle and stretched out. If you wondered, capped cylinders make lousy tires.

pyODE

Tuesday, September 6th, 2005

Tonight I started work on integrating pyODE into my game. At first I thought it was going to be very difficult, but then I started working on it and it seemed like it was easier than I had expected. Then I tried more and found out that it was, indeed, rather difficult. I will prevail, though.

I do so enjoy programming

Sunday, September 4th, 2005

There’s something I enjoy about finding bugs in a program. The methodical search for the imperfect delights me, and whenever I find a bug my mind usually works on several possibilities at once. As a general rule of thumb, when I see my program behaving strangely, in two ways that seem totally unconnected, it’s a good posibility that they are linked directly. There’s something very intellectually pleasing about two unconnected phenomena that are actually directly related.

On that note, I beleive that computer science and programming are the purest of all sciences, and that programmers make the best scientists. The reason for this is simple; science is all about the scientific method. First, some sort of phenomenon is observed. In an attempt to explain the phenomenon, a model is constructed or an explanation given for the phenomenon. In order for the model to prove usefull at all, it has to be tested. If the model withstands testing and results are produced succesfully from that model, it’s accepted as ‘true’ or ‘valid’ or whatever you please. If it doesn’t produce usefull or valid results, it’s rejected and a new idea is sought out.

Finding bugs in a software program is science on a small scale. You observe a bug. You construct a mental model of your program in order to determine what caused it to err. Once you have constructed a model and explained why the software is doing what it’s doing, you test your hypothesis by looking for and fixing the fault. If you run the program and it works, good. If not, you revisit your mental model and attempt to correct it in order to have it predict the bug that you’re observing.

Another thing that I should think would make good programmers into good scientists is the nature of the debbugging proces – I’m not sure how others work, but for me the key to understanding why a bug is happening is to insert all kinds of output statements in my program, so it tells me exactly what it’s doing. This is akin to constructing an experiment and gathering all of the necessary data. With a computer the only data you can’t collect is that which you don’t understand.

On a final note, the biggest difference between computer science and the rest of scientific endeavors is how easy it is to ‘jump in and get going’. If someone tells you that an object is made of up atoms, you can’t bust it up and count the atoms. You can’t take it apart and put in different atoms to see how it works. You can’t even look real close and see the atoms – all you can do is take his word for it, and beleive him when he shows you pictures of some little bumps. With computer science, that isn’t the case at all. If someone tells you that this sorting algorithm runs in this time, you can easily implement the algorithm yourself and see how fast it runs. If someone tells you that acecss times for heaps are on the order of log(n), you can check it out for yourself. True, there are some things like parrellel computing and such that you can’t really do unless you have the equipment, but for the most part all you need to do computer science is a pencil and paper. Sure, a computer helps, but it’s not really even necessary. Most of the time you can even do it in your head.

I could go on, but I’m going to get back to programming.

Now With Muzzle Flashes!

Thursday, September 1st, 2005

Muzzle Flash!

OpenGL Is Kinda Wierd

Tuesday, August 30th, 2005

I guess I had been assuming that using an RGBA pixel format would enable alpha-testing, but apparently it didn’t. After looking up a bunch of examples which used a hack involving a blend-function to get around the lack of a pixel format with an alpha channel, I realized there was probably some test I needed to enable. I about smacked my forehead when I went to google and saw what the issue was, I just needed this bit of code:

glEnable(GL_ALPHA_TEST)

I wish I would have seen or thought of that earlier.

update: I need to go to bed for now, but after a bit of a struggle at first I implemented a lighting system, and if I do say so myself, the results are quite handsome. I also got some ‘under the hood’ work done, shuffling the game code so that the scene manager system is more prominent, allowing each scene to control the camera and other functions more easily. The other nice result is that the main loop of the game is simplified nicely. As for PyODE, which I thought I was going to put in tonight, I may wait on that. I’m not sure, yet.

rrrrowrr

I, for one, am Excited

Tuesday, August 30th, 2005

Tonight I’m going to use PyODE to add some decent physics to my game. I can’t wait.

Always Get the Basics

Monday, August 29th, 2005

I was working on some code for the Zombie game just now. At the risk of giving away spoilers, I was writing code to make sure the player stayed in the bed of a truck, which will be driving about and therefore oriented in any different number of angles.

My game was using a strange coordinate system because I hadn’t bothered to write clean code. Most sprite based entities whose angle was ‘zero’ would face upwards, while mesh-based entities whose angle was zero would face to the right. On top of that, the way angles worked may have been counter-clockwise for the sprites and clockwise for the meshes. I knew i was going to have to fix this code eventually, but tonight I tried to unsuccessfully to write code for the player in the truck of the bed. My plan was to translate the player’s position to the truck’s coordinate system and then slide him into a certain box representing the bed of the truck but i kept getting screwed up results. I finaly gave up and rewrote the crappy code, and as a result everything is much smother now.

Moral of the story: get the basics down good.

Update: YEEEEEHAWWWW

Yee-Haww!

Mind Blowingly Cool

Tuesday, August 23rd, 2005

The title applies if you’re interested in this sort of thing, only. If not then maybe you’d like this.

Consider several .mp3 music files stored in a .zip file. What’s going on there? What’d it take to get those files there? First, some source had to produce rapid fluctuations in local air pressure, with frequencies ranging from 50 to 20,000 times a second. These fluctuations in air pressure caused a distrubance in an electrical system, most likely moving some sort of magnet through a loop of coil, causing current to flow opposing the change in magnetic flux. This change in current passed through a single cable which was attached to a digital volmeter. At some frequency, most likely 44,100 times a second, the output value from this voltmeter was shunted along a data bus to a memory controller coupled with a simple counting circuit which increments is incremented at that same 44,100 frequency. Every time the voltmeter’s output is latched to the databus headed for a memory counter, the counting circuit is incremented and the current voltage on the input signal is stored in the memory in binary form. While this process is occuring, a microprocessor somehow connected to the aforementioned memory controller ocaisionally follows an instruction whereby the entire contents of that memory controller is latched to a databus, fed into a register somewhere near the procesor and then moved into a hard drive’s cache for permanent storage. This process was repeated several times, to create several raw audio data files, which are a record of measurements taken of those air-pressure variations. By creating air pressure variations of the same intensity recorded in those data files, the sound of that disturbance could be reproduced.

Once those audio data files were created, a new aglorithm is run upon them, sliding a short ‘time window’ along them and using a form of Fourier transformation called a ‘Modified Discrete Cosine Transformation’ in order to roughly approximate the signal in that short window with a series of sine and cosine waves of varying intensity and frequency. The result of the aglorithm is information describing a mathematical function which, although not identical, gives a good local approximation of the original signal made by that source above. This new information is then scanned by a tokenizer which makes frequency counts of tokens of varying lengths found within the data file storing information that describes the rough approximation of the original squence. The most frequently occuring tokens are stored in a list and instances of these tokens are replaced by an index into that list, resulting in an even smaller amount of data. This data, when certain token references are replaced by their values from a lookup table, can be used to construct a mathematical function that closely approximates the signal emitted by that distrubance mentioned so long ago.

Just think, then – every time you download one of his albums off of bittorrent, 50 Cent has to do all that work. And you wondered why piracy was wrong.

DRM from an Encryption Perspective

Tuesday, August 23rd, 2005

I had this idea a while ago and never really developed it, so I place it here for further consideration. I think a lot about DRM software – that is, software designed to prevent piracy of information. It appears to me that attempting to build an impenetrable DRM system is akin to a special problem in encryption. Because there is plenty of literature and knowledge about encryption, converting the DRM ‘problem’ into a special case of encryption would greatly contribute to any consideration of a DRM method.

For the uninitiated, the basic encryption problem is that Alice wants to send a message to Bob, without anyone else, like Eve, being able to tell what that message is. The ‘DRM’ case isn’t too far from it – suppose Alice is a musician and Bob is a music buyer. Alice wants to be able to create a message such that bob can read it, but nobody else can read it, no matter how much information bob gives them. That is the goal of DRM software – so that only someone who has purchased (and therefore has license to use) some peice of copyright material is able to use it.

The thing is, though, that problem is completely absurd and no rational person would attempt it. Whenever Bob has read the message, all he’s got to do is give that message to Eve and the system is broken. You can gussy it up all you like with fancy equipment but as long as Bob is capable of comprehending the message Alice sends to him, he can just transmit that same message to Eve. Viewed as an encryption problem, DRM becomes entirely a fool’s pursuit. Something tells me the situation has to be more complicated than that, but I don’t really think it is.