lilith3d

 

Engine

Documentation

Notes

Tutorial 2: Moving Around

  • World Definition
  • Loading terrains
  • Camera rotation and moving

Before looking at the code for the 2nd tutorial, open up the worlddefine.h file in the main lilith directory. Don't change it. Get through the tutorials first before playing with settings, but here is where you would change the engine. (But be careful - many of the settings are touchy). Here you can change the size of the world, the level of detail, distance to far plane...all kinds of stuff. The tutorial and demo is 256x256 map squares, which is 257x257 vertices at about 2 meters / map square. That's roughly 1/2km X 1/2km world. (And if you couldn't resist changing something and just wiped out the engine, get a fresh copy.)

Tutorial 2: Loading a terrain

First things first...the basic boring hills there just aren't going to cut it. Lilith can load in a grey scale texture and use it for a height map. The height map can be any size. The call:

lilith->GetTerrainMesh()->LoadHeightMap( "../graphics/heightMap.tga" );

makes this happen.

Tutorial 2: About the TimeClock

The TimeClock measures the relentless beat of game time. From it, you can query:

  • Current Frame & Frames per second
  • Velocity
  • Game time in hours, milliseconds, or calendar units
  • The current state of the sky and lighting

"velocity" deserves more comment. Anything that changes over time can and should use this method. Simple example: movement. If you have a ship that moves 10 units/second, and want to know how far it moved between the last frame and this frame, you would say:

delta = timeClock->CalcVelocity( 10.0 );

Tutorial 2: Adjust the camera

Moving the camera around the world! The controls are set up like a first person RPG. Holding down the right mouse button, and moving around, rotates your head. Holding down the left button while the right button is pressed moves forward.

Rotation occurs relative to "where you are looking". The code:

camera->MoveCameraRotation( Camera::YAW, -xVel );
camera->MoveCameraRotation( Camera::PITCH, yVel );

works no matter where the camera is facing. (YAW, PITCH are local, not global.)

There are 2 movement modes: "2D" is a walking mode and used to move the camera like a walker, or on a track. "3D" mode moves the camera the way the head is pointed, like a plane. You can use

MoveCameraAxial3D
MoveCameraAxial2D 

depending on which mode you want. The tutorial uses the 3D mode. The "creation" demo uses the 2D mode.

Tutorial 2: Incremental move

Since we want the camera to move while both buttons are down, the actual move occurs outside the event loop.

if (   SDL_GetMouseState(0, 0) == (SDL_BUTTON( SDL_BUTTON_LEFT ) 
     | SDL_BUTTON( SDL_BUTTON_RIGHT ) ) )
lilith->GetCamera()->MoveCameraAxial3D( 20.0f );

Conclusion

Now we're getting somewhere! Enjoy flying around the world.