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/Samples/UI/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.You'll notice a few changes in the ViewEventListener
and ContextEventListener
classes.
ViewEventListener
now has methods for setting/unsetting focus (ViewEventListener::SetFocus
and ViewEventListener::KillFocus
) and doesn't set the focus when the view is created, because now we have more than one view and it wouldn't make sense to set the focus every time a view is created. Each view requests a new texture when created and uses can be queried for its ID so it can be drawn.
ContextEventListener
now exposes a method CreateView
, instead of creating one when the context is ready. This is more flexible, as the ContextEventListener
is a single instance and the ContextReady
event is fired only once. With this method exposed, we can create views dynamically.
By default, this sample creates 5 views, as defined in Application.h
In the Application::Initialize
method, we set up a listener and a game object texture for each view.
Since this time we do not create views in the ContextReady
handler, we'll have to do it elsewhere. In this sample we'll just try to create all the views every frame in the main loop, that is if the view context is ready and we have not created them yet.
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 UI integration:
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.