A starry sky dome
What if the Universe was just a giant ball and we're inside it? That's what we're going to imagine to implement a starry sky spherical background.
In computer graphics, you can create backgrounds to make the scene look bigger than it really is. You can use a spherical texture, or skydome, as we will use here. (A common alternative in many game engines is a cuboid skybox, constructed from six internal faces of a cube.)
Among the set of textures that we provided with this book is milky_way_tex.png
. Drag a copy of this file into your res/drawable/
directory, if it's not there already.
Now, we can add the starry sky dome to our scene. Add the following code to MainActivity.setup()
:
//Stars in the sky Transform stars = new Transform() .setParent(RenderBox.mainCamera.transform, false) .setLocalScale(Camera.Z_FAR * 0.99f, Camera.Z_FAR * 0.99f, Camera.Z_FAR * 0.99f) .addComponent(new Sphere(R.drawable.milky_way_tex, false...