Saturday, October 3, 2009

Heightmaps!

Okay, so last night before I went to bed I built from scratch a new heightmap system utilizing SFML and OpenGL this time. I am happy to wave goodbye to SDL! I implemented OpenGL's Select mode Picking system and had to debug it for a while for a stupid perspective FOV mismatch. Soon after I confirmed that it would not suit my purposes and then came across that it's going to be phased out in OGL 3.0 anyway as its not actually 3d graphics related. So I ripped out all the select mode picking code and put in a transposition system.

In essence, you are reversing the normal matrix transformations (from space->model->world->clip->screen to screen->clip->world->model->space (that's simplified, there's a few more steps inbetween). For those of you who don't understand any of that, it basically turns a 3 dimensional coordinate (x, y, z) into a 2 dimensional screen coordinate or vice versa. In reality they are 3 dimensional screen coordinates with the z being the top of the depth buffer or 0..1 for near and far planes respectively. Now I can tell exactly where in the world the user is clicking, and it even has a cute side effect where when I create a box where you are clicking in the world, if one holds the mouse button down, then you are now clicking on the edge of the newly created box, so it moves to there, but now you are clicking on the edge of where it just moved, so it moves closer, and closer, and closer, and smacks the screen in the face. It's kind of funny, albeit unexpected at first. I am thinking if I disable writing to the depth buffer when I draw it that should fix that issue as my select code is using the depth buffer to determine where in the near/far clip planes the user is clicking (it thus picks the closest).

Anyway, now I have a terrain mesh that has a cursor and allows raising and lowering. I have some issue somewhere in the renderer though that is causing strange (albeit cool looking) circular artifacts when you edit the mesh. When you raise a lump, it actually raises a LOT of lumps. I was too sleepy to correct this so I decided it would be best to take a break.

I then started reading over the docs for Bullet physics again. Pondering on how I want to implement things, and even where I want to take this. So I decided to sleep on it.

Actually I lied, I played Aion for a few hours and THEN went to sleep. Anyway, I ended up dreaming about programming! Woke up pondering a few things. Now I am just stopping reading back over Ogre3d. Exciting news there!! The next version will use the MIT license, which will loosen licensing requirements with Ogre even further! The Google Summer of Code 2009 also evidently resulted in someone totally revamping the samples. I am not sure if these new and improved samples are in the Ogre distribution yet, but they are accessible (at least the one I've been looking over) in the Ogre Wiki. It's about time too, some of those samples were ....

So in all of this, I found on the Ogre forums someone has written a terrain manager. I haven't looked at its code yet but have been perusing the monolithic thread that it started from. It now has its own forum section, but if that link works correctly you should see where the author is pondering changes for his next version and he mentions some shortcomings with the current design.

Anyway, so now I'm at the point where I'm trying to determine if I should stay the path or just return home to Ogre. If I stay where I am at, I can continue doing interesting things, but it will be all on my own with straight OpenGL. I can also learn from the other managers, etc... This will allow me to really support anything, my next steps anyway were to add in some basic LOD and eventually paging once I got textures working nicely. While the custom Ogre terrain manager cannot support paging or LOD in its current state (although the Ogre scene manager might/should(?) handle the LOD business anyway. There is also a 3rd iteration of the slowly developing paging system for it too. It already can splat textures and do some other nifty things though.

So I'm just not sure. It's one of those could go either way things, the pros and cons are fairly convoluted in this one. I suppose I could even take the Ogre heightmap code and just take a stake to it and turn it into some hybrid mixture. I suppose I should eat, about four hours overdue from lunch and had no breakfast and ate shitty junk food last night. Afterwards I have actual internship and school work beckoning, as well as a required legion event on Aion. But in reality, I will probably just keep perusing the forums and reading up on everything. Knowledge is power.

No comments:

Post a Comment