base.camLens.setFov(<field of view in degrees>) base.camLens.setNear(<distance of near clipping plane - anything closer than this will disappear>) base.camLens.setFar(<distance to far clipping plane - anything further than this will disappear>)
from direct.gui.OnscreenText import OnscreenText textobject = OnscreenText(pos = (0, -0.9), fg = (1,1,1,1), bg = (0.3, 0.3, 0.3, 0.5), align = TextNode.ACenter, scale = 0.07, mayChange = True)
You can look up the various creation parameters for OnscreenText. And then any time you want to display some text, just set the
text property for this object. The following code sets the text to the current camera location values using a python formatted string
textobject.setText("Your location is (%2.2f,%2.2f,%2.2f)" % (base.camera.getX(), base.camera.getY(), base.camera.getZ()))
Make your label show an updated camera position as you move around.
# HINT - Creating a 3D audio manager # Note that 'reference_point' could be the nodepath of a listener's location audio3d = Audio3DManager.Audio3DManager(base.sfxManagerList, <reference point>) audio3d.setDropOffFactor(<drop off factor>) # HINT - Loading a 3D sound and attaching it to an object sound = audio3d.loadSfx(<filename>) sound.setVolume(<volume between 0 and 1>) audio3d.attachSoundToObject(sound, <object> ) audio3d.setSoundMinDistance(sound, <distance>) sound.play()
create_terrainmethod to your
Worldclass. Inside it, do the following:
#HINT - Creating a Hightfield Tesselator and a Terrain Node tess = HeightfieldTesselator(<some name you choose>) tess.setHeightfield(Filename(<filename of hightmap>)) tess.setVerticalScale(<vertical scale>) tess.setHorizontalScale(<horizontal scale>) terrain = tess.generate() terrain.reparentTo(render)
tess.setFocalPoint(<heightmap x coord>,<heightmap y coord>)
Note that the coordinates are in heightmap pixels (so 256,256 would place you in the center of a 512×512 map).
<nodepath>.setTexGen(TextureStage.getDefault(),TexGenAttrib.MWorldPosition). You will also have to scale the texture and center it by using the
<nodepath>.setTexScale(<texture stage>, <u scale>, <v scale>)and
<nodepath>.setTexOffset(<texture stage>, <u offset>, <v offset>)methods. Good uniform scale would be 1/128 (this value is 1/(<horizontal scale of terrain>*<terrain size>), i.e. 1/(0.25*512)), and centering just involves an offset of -0.5 for both
create_skyboxmethod in your
Worldclass. Use it to load the skybox model as the member variable self.skybox in your World class, attach it to render and scale it up 200 times. A skybox represents a horizon that the user should never be able to reach and pass through, and therefore it needs to move with the user, always keeping the user at its center. This is easy to do since World already has a move method that updates the camera position. Once the camera position has been updated in that method, give self.skybox the same position as the camera. Try moving outside of the room and notice how the clouds seems to stay put.
Models/skybox.eggsimply by opening the file in a text editor and changing the texture filenames to your files.
# HINT - Adding fog to a sub-tree starting at '<nodepath>' fog = Fog("Fog") fog.setColor(0.6,0.6,0.8) fog.setExpDensity(0.008) <nodepath>.setFog(fog)