206. Castle 3D – Adding scenery and tidying up
This is where I’ve got to now.
Scenery
I spent a lot of time creating some background scenery. I’ve explained before how to add a “sky globe”, a sphere that surrounds the camera, with a texture drawn on it, so it looks convincing.
My problem here was to find a suitable image. The final size needs to be twice as wide as it is high, eg 2000 x 1000, in order to wrap neatly onto a sphere. However, I’m going to have a castle sitting in the middle, so nobody is ever going to see the bottom of the sphere. So I can create an image that is twice as wide as it is high, but the texture I put on it doesn’t need to go all the way to the bottom.
What is very important is that the image is seamless, ie the right hand side connects seamlessly with the left hand side so you don’t notice a join. Unfortunately, I couldn’t find a suitable image that was also seamless, so in the end, I found an image I liked, and edited it in Paint.net until the left and right sides joined up so you barely notice.
I then spent a lot of time in Codea, placing the sphere and trying out various settings to see the effect. The sphere needs to be centred on the middle of the castle, and it needs to be at least big enough to contain the whole castle, but after that, it doesn’t really matter how big you make it. I can move the sphere up and down, though, to change which parts of the image appear on the screen.
Anyway, the result of nearly a day’s work is above, and it will do for now. I may come back to it later.
Tidying up
I put the people pictures into their own separate image, storing them in a larger size so I can walk up close to them without pixellation, as discussed in a recent post.
However, I noticed a problem that is common with 2D images. They have a picture in the middle, and transparent pixels all around them to fill up the rectangular image. The problem is that when you draw one of these pictures, OpenGL treats the transparent pixels as solid, and then won’t draw anything behind them. This means you need to draw these images after everything else, and draw them for furthest to nearest. I covered that at the end of this post.
So I need to put any 2D images I am using, into a table, and sort them by distance from the camera, before drawing them, furthest to nearest.
I also fixed, and simplified, my lighting. I won’t cover that here, I’ll put it all in one post.
Anyway, I hope you can see that projects like this don’t just happen, they are iterative, and you are having to solve problems and adapt, all the way through. It helps that I have learned a lot of techniques in the two years I’ve been using Codea (although it feels like I’ve been stumbling round in the dark for a lot of that time!). The more you can learn and understand, the better.