RTS-like "Terrain Camera"

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
VeeZed
Posts: 14
Joined: Wed Oct 27, 2010 8:04 pm
Location: Novosibirsk, Russia

RTS-like "Terrain Camera"

Post by VeeZed »

Hello everyone!

I'm a newbie user of IrrLicht engine (although I have some experience in pure-OGL development in the past), so don't kick me with your boots if I'm doing something wrong :)

Some time ago I started to work on a small hobby project based on IrrLicht. Pretty fast I found that there is no out-of-box implementation of the camera for the "terrain-based" projects. I.e. camera that can glide over terrain node, adjust angle via mouse (but don't lock it) and so on...

Therefore, I had to spent a little time to implement my own CameraNode Animator, that will accomplish my needs. And when I was reviewing the first results, I had a thought that it might be interesting for someone, so I decided to publish it here.

You can take a look on the demo:
- http://dl.dropbox.com/u/9070955/IrrLich ... raDemo.zip
(IMPORTANT! Put it into the default "examples" folder of the irrlicht, since I put the camera into the Terrain example, and this zip doesn't contain any resources)

You can perform glide using arrow keys, rotate camera holding RMouseButton, and adjust the distance using wheel. I also put a small "nice effect" to the wheel, so that the zooming goes smooth (however, it broke the ability to setup the camera position well).

The code of the animator is here:
- http://dl.dropbox.com/u/9070955/IrrLich ... errain.zip

The code is pretty straight-forward, i.e. you should create standard camera (not FPS), create animator and attach them to each other. If you leave the "Terrain" property NULL, then the camera will be based on the (X,0,Z) plane. Both camera and target avoid the collision with the terrain (using getHeight()). Therefore, you don't need to calculate the heights yourself and perform any specific actions every frame.

If you find this piece of code interesting, I would be happy to find some time to polish it (remove nasty hardcoded #defines, fix wheel, etc). Actually, I can contribute it to the IrrLicht itself, if it's worth that.

PS: The code is heavily based on the FPS camera by Nikolaus Gebhardt. Thanks to him, I only had to switch a couple of gears in it.

Wish everyone a good coding,
VeeZed
Birdman
Posts: 25
Joined: Mon Jan 28, 2008 5:45 am
Location: Buenos Aires

Great

Post by Birdman »

Works like a charm!

I just saw the demo, i will check the code later with more time, thanks for the addition!
The sleeper must awaken!
Post Reply