Monday, April 21, 2008

Sacral knowledge of jMonkeyEngine

I've seen a few Open Source project with documentation worse, than jMonkey, but I was lucky - I actually knew something about those projects subject matter, so I could make sense out of them! With jMonkey even core developers seem to have a problem. One way or another, I was finally able to come up with a working tree. Well, working as in "it looks ok". It hasn't grown yet - that the next step. Apparently, the main problem was that a Spatial in jMe has internal coordinate axis, but they are not aligned with the Spatial (contrary to what wiki says). The axis are attached at the beginning of coordinate system to some well-defined (published in wiki) point, but the directions of the axis change with every setLocalRotation() call. In general, I don't see any (easy) way to figure an angle between the direction of cylinder and its Z-axis.
To find the direction there is a neat trick (and I don't know how it works, but it does):

Vector3f direction = trunk.getLocalRotation().getRotationColumn(2);
direction.normalize();

gives you true direction (vector3f) aligned with the cylinder's axis - coords (x,y,z) in local coordinate system of the end of a vector with length==1.
Conversely, if you multiply that by the length of the cylinder you'll get the coordinates of that point and localToWorld() would correctly convert that!
The full story here

Friday, April 18, 2008

My latest and greatest attempt to grow a jMonkeyTree


The idea was that all the cylinders are attached to the end of green cylinder. Why that doesn't happen?! jMonkey documentation doesn't help much.

Friday, April 11, 2008

Strange API of jMonkey

Thanks to our favorite search engine, I found some information on how to generate life-like plants using regular geometrical shapes. I grabbed jMonkey and attempted to implement the same logic there. Everything was just fine until I needed to attach branches to the trunk. It appears jMonkey has NO API that lets me get to the ends of cylinder. More to the point, there is no clean API to get ANYTHING, related to a cylinder location. One would expect something like getLocation call, but no! They have getLocalTranslation(). That seems to return the coordinates of the middle. It should be fairly trivial to get to the ends, knowing the middle and the length, but I don't see any API giving me the direction of cylinder axis. I put a question on jMonkey forum 2 days ago - so far no responses.
I just don't understand this! I can not believe getting the direction is impossible - the engine draws it somehow. But how people can come up with such unclear API and no documentation is beyond my understanding. Project Wonderland wants to switch to jMonkey in the next version - good luck to these folks, they will need it!

Tuesday, April 8, 2008

Models - dumb opaque boxes

The next step - after providing a terrain - is to put something on it. I was thinking about a few different plants and an animals or two, say elks and wolves. Obviously, I didn't want to draw (or create a models of) all the plants I need. Using just one model doesn't sound good either - who's ever seen a forest of identical trees?! The right approach would be to have a model of a tree with a trunk and a branch, as separate objects, and then randomly choose the height of a tree and number/position of the branches on the trunk, proportionally to the trunk's height.
Turns out, jME considers all models more or less opaque 3D-objects. From code point of view, they are just arrays of bytes (wrapped in Nodes) without any insight into their composition. That makes it impossible to generate a tree at runtime or have any real way of merging models.
Character modeling is in even sorrier state, because this way one needs to draw (make models of) all permutations of armor type-weapon-body type, and that's if I somehow can apply a pattern to a model!
There's got to be a better way of doing things. Let's see what available!

Monday, April 7, 2008

C# Game Development

C# Game Development - interesting (some postings) blog

Making money off highways as a main source of income

About a month ago I had a business trip to Austin, TX. While there, I decided to visit a neighboring city of College Station for personal reasons. Unfortunately, instead of listening to the locals I decided to follow the guidance of my trusty (if slightly dimwitted) GPS. Instead of taking highways 290-21, I took 79. Big mistake! The police was behind every bush (no pun intended) in every little town along the way, stopping people for 1 mile over the limit! They got me twice - one in the great city of Thorndale (for 64 in 45 miles zone at midnight). They even have a stationary radar there and the policeman gives you a nice price list, telling you how much you need to pay for what violation. Needless to say, that got me pissed so I decided to find a local lawyer and fight the ticket. According to the price list my violation is worth $190, so I decided I could afford another $100, but make things a bit easier for the next unfortunate soul driving though that speed trap and maybe give a hint to the town government that they should look for another source of income. I called several (3) local lawyers. 2 didn't get back to me, while the secretary of the last one nicely explained that they have more than enough work as it is and can not help me. Looks like just about everyone in that town shares of the profits somehow.
Well, having no options I decided to pay the fee. Obviously, they don't take checks, just money/postal orders. Sent them one over certified mail. I thought that to be the end of the story and the glorious city of Thorndale, TX and peculiar habits of its citizens started to fade from my memory. Apparently, that was too easy.
These guys now claim they haven't received the pledge and the postal order and threaten me with a warrant. What makes it strange is that USPS is sure they delivered the letter (one can track certified mail). Now I just need to see if somebody cashed the postal order. I wonder if this is how they double the loot - claim they haven't received it and make you send the money again?

First graphic output


I used jMonkey engine to produce my first output (see above). Turns out these guys have a handy class painting terrain out of height map. I also used their pattern to give the terrain some hint of color.
Learned a few interesting things and probably going to learn some more because the jME class for terrains insist on having the map in single-dimensional array of integers as opposite to 2-dimensional array of floats, while the latter seemed the obvious choice to me.
It also takes some time (1-2 seconds) for jMe to prepare and display 128x128 height map. While such map is rather large, I'll spend some time profiling the code.

Saturday, April 5, 2008

How this came to be

For a number of years now I wanted to write a computer game. I also wanted to do something with artificial intelligence (and I'm treating this term loosely). I don't know why. Perhaps because I've done a lot of other things in software development but somehow opportunities to do these two never crossed my path. Perhaps because I like to play computer games. Perhaps because I'm a very good at software development and architecture and I feel like I can do much better games that what's out there. Besides I have some pretty good ideas.
I believe I want to do a game because it seems to me that a good computer game is the very epitome of creativity and creativity is that attracted me to software development in the fist place.
At this point I know next to nothing about 3D and graphics used in game development, or anything else of game development, for that matter. I decided to have this blog as a way to describe my path - things I learned, discovered, frustrations and so on. If nothing else, it'd be fun to read in a year or so.
I started at the beginning - I decided to model the ground and then show it, using some graphics library. The ground is where everything starts and I'll probably get to learn all these fancy words:mesh, camera, scene graph. Gotta make reading books easier afterwards.
The beginning is really traditional - search on Google for "terrain modeling". Got a few articles, scientific and otherwise, one of which really attracted my attention: Realtime Procedural Terrain Generation
By now I read a few articles referenced from this one and wrote a diamond-square height map generation routine. To calculate the height I decided to use the method from
Alan Fournier, Don Fussell and Loren Carpenter:
Computer Rendering of Stochastic
Models. Communications of the ACM, Volume
25, Issue 6 (June 1982).

(That's reference 4 from the original article), so I modified the "square" part to take into account only 3 points, if the 4th hasn't been calculated by the time the algorithm needs it. That made recursive calculation much faster and isolated recursive branches, so if push comes to shove the calculation could be done by separate threads.
I chose Java as the programming language. Java neatly solves the distribution problem and I believe contemporary computers powerful enough to render stuff quickly even from the bytecode. I also would like to have access to the whole Open Source set of products. I want to be creative and re-inventing wheels I've invented several times already or know how to invent is not a part of my plans.