Gamasutra: The Art & Business of Making Gamesspacer
Toward Programmer Interactivity: Writing Games In Modern Programming Languages
View All     RSS
September 2, 2014
arrowPress Releases
September 2, 2014
PR Newswire
View All





If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 
Toward Programmer Interactivity: Writing Games In Modern Programming Languages

August 13, 1999 Article Start Page 1 of 4 Next
 

What's the most productive way to spend the next month? You could write three or four short stories for The New Yorker. You could pen maybe half the songs for your next album. You could devote three hours each morning to updating your popular game-related news site. Or you could continue debugging the unit AI for your up-and-coming real-time strategy game, which will put you close to a third of the way toward getting behavior that won't look blatantly stupid to the average Wal-Mart shopper.

Let's face it: game programming is hard. And it's easy to be jealous of those other guys.

That's not to say that writing songs or fiction is easy, but you're not going to see an author throw up his hands and say, "The technical problems involved in writing a story about a mermaid are going to take me six weeks to solve." Or "I've written this brilliant essay, but I'm having the hardest time keeping the characters from constantly walking into each other."

Writing and debugging code in Visual C++ doesn't have nearly the same easy flow as editing and revising paragraphs in Word. Quick: You have thirty seconds to compute the value of "sin(0.43) * 1.8" without using a calculator! (30 second pause.) Odds are that you're sitting in front of hugely powerful computer, and yet you didn't have an easy way to get at the answer. There's no sine key on the Windows calculator. And could you have created a Visual C++ project and written code to display the result in less than thirty seconds? Something isn't at all right with this picture.

Let's jump off into a caffeine-induced fantasy-land for a minute, and pretend we have a magical system that makes programming be fantastically straightfoward.

First, we dispense with our math problem by typing it in directly:

sin(0.43) * 1.8

and we get an answer back right away:

1.227597

Well, shoot, a Commodore 64 could have done that! Let's write some basic vector functions:

magnitude (x,y,z) = sqrt(x*x + y*y + z*z)

dot (x1,y1,y2) (x2,y2,z2) = x1*x2 + y1*y2 + z1*z2

normalize (x,y,z) = (x*m, y*m, z*m) where m = 1.0 / magnitude(x,y,z)

Now let's test these out (the first line of each pair is our query; the second is the result):

magnitude(10,20,30)
37.416574

normalize(10,20,30)
(0.2672612, 0.5345225, 0.8017637)

normalize(1,0,0)
(1,0,0)

(1,0,0) `dot` (0,1,0)
0

We're already getting interesting results. Obviously, a unit vector is, by definition, already normalized, but it's nice to be able to quickly verify that. It also looks like a unit vector dotted with an orthogonal unit vector gives a result of zero. We haven't proven it, but it's an interesting theory nonetheless. This is amazing! Three lines of "code" and we're learning properties of vector math.

Even more amazing is that we aren't in fantasy land at all. This is real code, written in a real programming language (not just a math package) with existing compilers that generate machine code. You can be doing the same thing on your Windows, Linux, or MacOS machine within a few minutes. For free.


Article Start Page 1 of 4 Next

Related Jobs

Shiver Entertainment
Shiver Entertainment — South Miami, Florida, United States
[09.02.14]

Senior Technical Director/Artist
Shiver Entertainment
Shiver Entertainment — Miami, Florida, United States
[09.02.14]

Gameplay Programmer/Engineer - All Levels
WB Games
WB Games — Kirkland, Washington, United States
[09.02.14]

Senior Software Engineer, Graphics
Wargaming.net
Wargaming.net — Chicago, Illinois, United States
[09.02.14]

QA Analyst - Web






Comments



none
 
Comment: