2.9.16
Coherent GT
A modern user interface library for games
Sample - Multiple views

This tutorial demonstrates showing different views on different objects in the world.

You can move in the world using W/A/S/D, look around using the mouse and lock/unlock the mouse by pressing Alt. Input forwarding works only when the mouse is unlocked.

Note
Supplied code, unrelated to Coherent GT integration, is not representative for a well-designed, high-performance solution. It's written for simplicity and its purpose is to demonstrate integration in an existing game framework.

Building the Multiple View sample

The sample solution is already configured and you only have to compile and run it.

It uses a sample mini game framework that provides very basic functionality.

The output will be in the Coherent/bin directory.

Prerequisites

  1. This sample assumes you read Sample - Input in 3D.

Key points

Note
This section is provided for completeness and describes the changes in the supplied mini game framework from the previous samples. Feel free to skip it.
  1. The Renderer now exposes a method for creating textures with user provided IDs. It also has a map of IDs to their corresponding textures.
  2. The Z-Buffer is turned on, since we draw multiple objects.
  3. The Renderer::DrawScene method has its signature changed to easily draw multiple objects.
  4. The GameObject now stores a texture ID of the texture that's mapped onto it.

Sample walk-through

By default, this sample creates 3 views, as defined in Application.h

const int VIEWS_COUNT = 3;

We'll create the views in the Application::Initialize method via Application::CreateViews

void Application::CreateViews()
{
const char* sampleUrls[] =
{
"http://www.msn.com/",
"http://www.google.com/",
"http://www.yahoo.com/",
};
const size_t sampleUrlsCount = sizeof(sampleUrls) / sizeof(sampleUrls[0]);
viewInfo.Width = VIEW_WIDTH;
viewInfo.Height = VIEW_HEIGHT;
for (int i = 0; i < VIEWS_COUNT; ++i)
{
viewInfo.ResourceHandler = &m_FileHandler;
viewInfo.ViewListener = &m_ViewListeners[i];
AddView(viewInfo, sampleUrls[i % sampleUrlsCount]);
}
}

In the Application::OnIdle callback, we have 2 new methods - UpdateGameObjectsTransformations and UpdatePickedObject.

UpdateGameObjectsTransformations updates the rotation and scaling of each object, so that the objects are always facing the camera (using a billboarding technique) and the selected object is enlarged.

UpdatePickedObject intersects every object with the ray, computed from the mouse position, updates the index of the picked object and sets/unsets view focus when the selection changes. The following new member variables are used for game logic and are not related to Coherent GT integration:

float m_ScaleFactor[VIEWS_COUNT];
float m_ScaleStep[VIEWS_COUNT];
float m_TargetScale[VIEWS_COUNT];
int m_FocusedObjectIndex;
static const int NO_FOCUSED_OBJECT = -1;

After we've updated the transformations and picking information, we dim the views that are not selected with a color multiplier and draw all objects.