Basic user interaction - Linderdaum Engine
Gallery
Community
SEARCH
TOOLBOX
LANGUAGES

Basic user interaction

From Linderdaum Engine

Jump to: navigation, search

Here we will learn how to enhance Engine initialization application with simple reactions to user input.

We would like to:

  • Rotate the cube using left mouse button
  • Move camera around using keyboard

Rotation with mouse

Let's start with mouse and add the following code to DrawOverlay() fucntion:

   bool MousePressedL = Env->GUI->IsKeyPressed( LK_LBUTTON );
 
   Env->Engine->GetViewport()->UpdateTrackball( &Trackball, 10.0f, MousePressedL );

Trackball and rotation matrices should be declared beforehand:

   clVirtualTrackball   Trackball;

and the use both rotation matrices to create new modelview matrix for our cube:

   Env->Context->BeginTransform( Trackball.GetRotationMatrix() * ModelView );

You can now rotate the cube with left mouse button.

Cube.jpg

Camera