Book Image

DirectX 11.1 Game Programming

By : Pooya Eimandar
Book Image

DirectX 11.1 Game Programming

By: Pooya Eimandar

Overview of this book

<p>DirectX is designed to create eye-popping 3-D visuals and immersive sound effects found in many of today's PC games. DirectX 11.1 includes numerous improvements from its previous version. It's designed to be more efficient, leverage the power of today's multi-core processors, and provide support for sophisticated shading and texturing techniques such as tessellation.</p> <p>DirectX 11.1 Game Programming brings unprecedented power and flexibility to programmers who want to excel in graphical programs. DirectX 11.1 Game Programming is an introduction to creating interactive computer graphics and games, using Direct3D 11.1. You would be guided through the new features of Direct3D along with XAML to build an extensible multithreaded framework for creating 3D applications and games on the Windows 8 metro style platform.</p> <p>DirectX 11.1 Game Programming explores the techniques to set up a 3D multithreaded framework for metro style graphics programs. You would be guided through the process of extending your framework to utilize the advantages of Direct3D 11.1.</p> <p>We would then explore Visual Studio Model editor for loading and editing your assets and learn how to render them with the Direct3D pipeline. We will also explore the supporting inputs such as keyboards, pointers, Xbox controllers, and how to render the complete 3D scene using camera, sound, billboard, tessellation, post processors, and parallel libraries, along with supporting XAML. <br />You would also learn the different techniques of debugging the program and would be well equipped with everything you need to start programming 3D applications and games with DirectX 11.1 on Windows 8 platforms.</p>
Table of Contents (12 chapters)

The input devices we'll need


In this section, we are going to learn how to handle input devices such as a keyboard, mouse or touch, and Xbox controllers. Let's start the integration of our framework with the keyboard, the old friend of gamers.

Keyboard

Open the Inputs project from the source code and then open the KeyboardState.cpp class from the FrameWork/Input folder. The KeyboardState.cpp class has the following code:

bool KeyboardState::IsKeyDown(VirtualKey key)
{
  return keys[key] == true;
}
bool KeyboardState::IsKeyUp(VirtualKey key)
{
  return keys[key] == false;
}
void KeyboardState::SaveKeyState(VirtualKey key, bool IsPressed)
{
  keys[key] = IsPressed;
}
void KeyboardState::ClearBuffer()
{
  for (auto k : this->keys) { k.second = false; }
}
void KeyboardState::Unload()
{
  keys.clear();
}

The preceding methods simply store the states of the keys. When the keys are pressed or released, the SaveKeyState method stores the keys' states as Boolean values. The IsKeyDown and IsKeyUp...