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.
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.
Renderer
now exposes a method for creating textures with user provided IDs. It also has a map of IDs to their corresponding textures.Renderer::DrawScene
method has its signature changed to easily draw multiple objects.GameObject
now stores a texture ID of the texture that's mapped onto it.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]);Coherent::UIGT::ViewInfo viewInfo;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.