From 6c4907ed1dfc5d25d446ec3b77437ac7d29d02f3 Mon Sep 17 00:00:00 2001 From: Vladimir Kononovich Date: Sat, 19 Dec 2020 23:33:11 +0300 Subject: [PATCH] Reformat Windows (Resharper) --- Windows/DirectInputManager.cpp | 264 +- Windows/DirectXTK/Audio.h | 1052 ++--- Windows/DirectXTK/CommonStates.h | 72 +- Windows/DirectXTK/DDSTextureLoader.h | 218 +- Windows/DirectXTK/DirectXHelpers.h | 148 +- Windows/DirectXTK/Effects.h | 1094 +++--- Windows/DirectXTK/GeometricPrimitive.h | 143 +- Windows/DirectXTK/Model.h | 199 +- Windows/DirectXTK/PrimitiveBatch.h | 177 +- Windows/DirectXTK/ScreenGrab.h | 21 +- Windows/DirectXTK/SimpleMath.h | 2068 +++++----- Windows/DirectXTK/SimpleMath.inl | 4537 +++++++++++----------- Windows/DirectXTK/SpriteBatch.h | 136 +- Windows/DirectXTK/SpriteFont.h | 97 +- Windows/DirectXTK/VertexTypes.h | 481 +-- Windows/DirectXTK/WICTextureLoader.h | 186 +- Windows/DirectXTK/XboxDDSTextureLoader.h | 52 +- Windows/Renderer.cpp | 257 +- Windows/Renderer.h | 50 +- Windows/SoundManager.cpp | 117 +- Windows/SoundManager.h | 6 +- Windows/WindowsKeyManager.cpp | 487 ++- Windows/WindowsKeyManager.h | 61 +- Windows/XInputManager.cpp | 63 +- Windows/XInputManager.h | 20 +- Windows/stdafx.h | 2 +- 26 files changed, 6430 insertions(+), 5578 deletions(-) diff --git a/Windows/DirectInputManager.cpp b/Windows/DirectInputManager.cpp index 3793ce2..aedb873 100644 --- a/Windows/DirectInputManager.cpp +++ b/Windows/DirectInputManager.cpp @@ -26,18 +26,23 @@ void DirectInputManager::Initialize() // Register with the DirectInput subsystem and get a pointer to a IDirectInput interface we can use. // Create a DInput object - if(FAILED(hr = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&_directInput, nullptr))) { + if (FAILED( + hr = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&_directInput, + nullptr))) + { MessageManager::Log("[DInput] DirectInput8Create failed: " + std::to_string(hr)); return; } IDirectInputJoyConfig8* pJoyConfig = nullptr; - if(FAILED(hr = _directInput->QueryInterface(IID_IDirectInputJoyConfig8, (void**)&pJoyConfig))) { + if (FAILED(hr = _directInput->QueryInterface(IID_IDirectInputJoyConfig8, (void**)&pJoyConfig))) + { MessageManager::Log("[DInput] QueryInterface failed: " + std::to_string(hr)); return; } - if(pJoyConfig) { + if (pJoyConfig) + { pJoyConfig->Release(); } @@ -48,19 +53,25 @@ bool DirectInputManager::ProcessDevice(const DIDEVICEINSTANCE* pdidInstance) { const GUID* deviceGuid = &pdidInstance->guidInstance; - auto comp = [=](GUID guid) { + auto comp = [=](GUID guid) + { return guid.Data1 == deviceGuid->Data1 && guid.Data2 == deviceGuid->Data2 && guid.Data3 == deviceGuid->Data3 && memcmp(guid.Data4, deviceGuid->Data4, sizeof(guid.Data4)) == 0; }; - bool wasProcessedBefore = std::find_if(_processedGuids.begin(), _processedGuids.end(), comp) != _processedGuids.end(); - if(wasProcessedBefore) { + bool wasProcessedBefore = std::find_if(_processedGuids.begin(), _processedGuids.end(), comp) != _processedGuids. + end(); + if (wasProcessedBefore) + { return false; - } else { + } + else + { bool isXInput = IsXInputDevice(&pdidInstance->guidProduct); - if(isXInput) { + if (isXInput) + { _xinputDeviceGuids.push_back(*deviceGuid); _processedGuids.push_back(*deviceGuid); } @@ -75,76 +86,89 @@ bool DirectInputManager::ProcessDevice(const DIDEVICEINSTANCE* pdidInstance) //----------------------------------------------------------------------------- bool DirectInputManager::IsXInputDevice(const GUID* pGuidProductFromDirectInput) { - IWbemLocator* pIWbemLocator = NULL; - IEnumWbemClassObject* pEnumDevices = NULL; - IWbemClassObject* pDevices[20] = { 0 }; - IWbemServices* pIWbemServices = NULL; - BSTR bstrNamespace = NULL; - BSTR bstrDeviceID = NULL; - BSTR bstrClassName = NULL; - DWORD uReturned = 0; - bool bIsXinputDevice = false; - UINT iDevice = 0; - VARIANT var; - HRESULT hr; + IWbemLocator* pIWbemLocator = NULL; + IEnumWbemClassObject* pEnumDevices = NULL; + IWbemClassObject* pDevices[20] = {0}; + IWbemServices* pIWbemServices = NULL; + BSTR bstrNamespace = NULL; + BSTR bstrDeviceID = NULL; + BSTR bstrClassName = NULL; + DWORD uReturned = 0; + bool bIsXinputDevice = false; + UINT iDevice = 0; + VARIANT var; + HRESULT hr; // CoInit if needed hr = CoInitialize(NULL); bool bCleanupCOM = SUCCEEDED(hr); // Create WMI - hr = CoCreateInstance(__uuidof(WbemLocator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IWbemLocator), (LPVOID*)&pIWbemLocator); - if(FAILED(hr) || pIWbemLocator == NULL) { + hr = CoCreateInstance(__uuidof(WbemLocator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IWbemLocator), + (LPVOID*)&pIWbemLocator); + if (FAILED(hr) || pIWbemLocator == NULL) + { goto LCleanup; } - bstrNamespace = SysAllocString(L"\\\\.\\root\\cimv2"); + bstrNamespace = SysAllocString(L"\\\\.\\root\\cimv2"); bstrClassName = SysAllocString(L"Win32_PNPEntity"); bstrDeviceID = SysAllocString(L"DeviceID"); // Connect to WMI hr = pIWbemLocator->ConnectServer(bstrNamespace, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices); - if(FAILED(hr) || pIWbemServices == NULL) { + if (FAILED(hr) || pIWbemServices == NULL) + { goto LCleanup; } // Switch security level to IMPERSONATE. - CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE); + CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, + RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE); hr = pIWbemServices->CreateInstanceEnum(bstrClassName, 0, NULL, &pEnumDevices); - if(FAILED(hr) || pEnumDevices == NULL) { + if (FAILED(hr) || pEnumDevices == NULL) + { goto LCleanup; } // Loop over all devices - for(;; ) { + for (;;) + { // Get 20 at a time hr = pEnumDevices->Next(10000, 20, pDevices, &uReturned); - if(FAILED(hr) || uReturned == 0 || bIsXinputDevice) { + if (FAILED(hr) || uReturned == 0 || bIsXinputDevice) + { break; } - for(iDevice = 0; iDevice < uReturned; iDevice++) { + for (iDevice = 0; iDevice < uReturned; iDevice++) + { // For each device, get its device ID hr = pDevices[iDevice]->Get(bstrDeviceID, 0L, &var, NULL, NULL); - if(SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL) { + if (SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL) + { // Check if the device ID contains "IG_". If it does, then it's an XInput device // This information can not be found from DirectInput - if(wcsstr(var.bstrVal, L"IG_")) { + if (wcsstr(var.bstrVal, L"IG_")) + { // If it does, then get the VID/PID from var.bstrVal DWORD dwPid = 0, dwVid = 0; WCHAR* strVid = wcsstr(var.bstrVal, L"VID_"); - if(strVid && swscanf_s(strVid, L"VID_%4X", &dwVid) != 1) { + if (strVid && swscanf_s(strVid, L"VID_%4X", &dwVid) != 1) + { dwVid = 0; } WCHAR* strPid = wcsstr(var.bstrVal, L"PID_"); - if(strPid && swscanf_s(strPid, L"PID_%4X", &dwPid) != 1) { + if (strPid && swscanf_s(strPid, L"PID_%4X", &dwPid) != 1) + { dwPid = 0; } // Compare the VID/PID to the DInput device DWORD dwVidPid = MAKELONG(dwVid, dwPid); - if(dwVidPid == pGuidProductFromDirectInput->Data1) { + if (dwVidPid == pGuidProductFromDirectInput->Data1) + { bIsXinputDevice = true; pDevices[iDevice]->Release(); pDevices[iDevice] = nullptr; @@ -159,31 +183,40 @@ bool DirectInputManager::IsXInputDevice(const GUID* pGuidProductFromDirectInput) } LCleanup: - if(bstrNamespace) { + if (bstrNamespace) + { SysFreeString(bstrNamespace); } - if(bstrDeviceID) { + if (bstrDeviceID) + { SysFreeString(bstrDeviceID); } - if(bstrClassName) { + if (bstrClassName) + { SysFreeString(bstrClassName); } - for(iDevice = 0; iDevice < 20; iDevice++) { - if(pDevices[iDevice]) { + for (iDevice = 0; iDevice < 20; iDevice++) + { + if (pDevices[iDevice]) + { pDevices[iDevice]->Release(); } } - if(pEnumDevices) { + if (pEnumDevices) + { pEnumDevices->Release(); } - if(pIWbemLocator) { + if (pIWbemLocator) + { pIWbemLocator->Release(); } - if(pIWbemServices) { + if (pIWbemServices) + { pIWbemServices->Release(); } - if(bCleanupCOM) { + if (bCleanupCOM) + { CoUninitialize(); } @@ -192,7 +225,8 @@ LCleanup: void DirectInputManager::UpdateDeviceList() { - if(_needToUpdate) { + if (_needToUpdate) + { //An update is already pending, skip return; } @@ -200,15 +234,20 @@ void DirectInputManager::UpdateDeviceList() HRESULT hr; // Enumerate devices - if(SUCCEEDED(hr = _directInput->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, nullptr, DIEDFL_ALLDEVICES))) { - if(!_joysticksToAdd.empty()) { + if (SUCCEEDED( + hr = _directInput->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, nullptr, DIEDFL_ALLDEVICES))) + { + if (!_joysticksToAdd.empty()) + { //Sleeping apparently lets us read accurate "default" values, otherwise a PS4 controller returns all 0s, despite not doing so normally - for(DirectInputData &joystick : _joysticksToAdd) { + for (DirectInputData& joystick : _joysticksToAdd) + { UpdateInputState(joystick); } std::this_thread::sleep_for(std::chrono::duration(100)); - for(DirectInputData &joystick : _joysticksToAdd) { + for (DirectInputData& joystick : _joysticksToAdd) + { UpdateInputState(joystick); joystick.defaultState = joystick.state; } @@ -216,7 +255,8 @@ void DirectInputManager::UpdateDeviceList() } } - if(_requestUpdate) { + if (_requestUpdate) + { _requestUpdate = false; _needToUpdate = true; } @@ -231,38 +271,51 @@ int DirectInputManager::EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstan { HRESULT hr; - if(ProcessDevice(pdidInstance)) { + if (ProcessDevice(pdidInstance)) + { _processedGuids.push_back(pdidInstance->guidInstance); // Obtain an interface to the enumerated joystick. LPDIRECTINPUTDEVICE8 pJoystick = nullptr; hr = _directInput->CreateDevice(pdidInstance->guidInstance, &pJoystick, nullptr); - if(SUCCEEDED(hr)) { + if (SUCCEEDED(hr)) + { DIJOYSTATE2 state; memset(&state, 0, sizeof(state)); - DirectInputData data{ pJoystick, state, state, false }; + DirectInputData data{pJoystick, state, state, false}; memcpy(&data.instanceInfo, pdidInstance, sizeof(DIDEVICEINSTANCE)); // Set the data format to "simple joystick" - a predefined data format // A data format specifies which controls on a device we are interested in, and how they should be reported. // This tells DInput that we will be passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState(). - if(SUCCEEDED(hr = data.joystick->SetDataFormat(&c_dfDIJoystick2))) { + if (SUCCEEDED(hr = data.joystick->SetDataFormat(&c_dfDIJoystick2))) + { // Set the cooperative level to let DInput know how this device should interact with the system and with other DInput applications. - if(SUCCEEDED(hr = data.joystick->SetCooperativeLevel(_hWnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))) { + if (SUCCEEDED(hr = data.joystick->SetCooperativeLevel(_hWnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))) + { // Enumerate the joystick objects. The callback function enabled user interface elements for objects that are found, and sets the min/max values property for discovered axes. - if(SUCCEEDED(hr = data.joystick->EnumObjects(EnumObjectsCallback, data.joystick, DIDFT_ALL))) { + if (SUCCEEDED(hr = data.joystick->EnumObjects(EnumObjectsCallback, data.joystick, DIDFT_ALL))) + { _joysticksToAdd.push_back(data); - } else { + } + else + { MessageManager::Log("[DInput] Failed to enumerate objects: " + std::to_string(hr)); } - } else { + } + else + { MessageManager::Log("[DInput] Failed to set cooperative level: " + std::to_string(hr)); } - } else { + } + else + { MessageManager::Log("[DInput] Failed to set data format: " + std::to_string(hr)); } - } else { + } + else + { MessageManager::Log("[DInput] Failed to create directinput device" + std::to_string(hr)); } } @@ -280,7 +333,8 @@ int DirectInputManager::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi LPDIRECTINPUTDEVICE8 joystick = (LPDIRECTINPUTDEVICE8)pContext; // For axes that are returned, set the DIPROP_RANGE property for the enumerated axis in order to scale min/max values. - if(pdidoi->dwType & DIDFT_AXIS) { + if (pdidoi->dwType & DIDFT_AXIS) + { DIPROPRANGE diprg; diprg.diph.dwSize = sizeof(DIPROPRANGE); diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER); @@ -290,7 +344,8 @@ int DirectInputManager::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi diprg.lMax = +1000; // Set the range for the axis - if(FAILED(joystick->SetProperty(DIPROP_RANGE, &diprg.diph))) { + if (FAILED(joystick->SetProperty(DIPROP_RANGE, &diprg.diph))) + { return DIENUM_STOP; } } @@ -301,25 +356,32 @@ int DirectInputManager::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi void DirectInputManager::RefreshState() { - if(_needToUpdate) { + if (_needToUpdate) + { vector joysticks; //Keep exisiting joysticks, if they still work, otherwise remove them from the list - for(DirectInputData &joystick : _joysticks) { - if(joystick.stateValid) { + for (DirectInputData& joystick : _joysticks) + { + if (joystick.stateValid) + { joysticks.push_back(joystick); - } else { + } + else + { MessageManager::Log("[DInput] Device lost, trying to reacquire..."); - + //Release the joystick, we'll try to initialize it again if it still exists const GUID* deviceGuid = &joystick.instanceInfo.guidInstance; - auto comp = [=](GUID guid) { + auto comp = [=](GUID guid) + { return guid.Data1 == deviceGuid->Data1 && guid.Data2 == deviceGuid->Data2 && guid.Data3 == deviceGuid->Data3 && memcmp(guid.Data4, deviceGuid->Data4, sizeof(guid.Data4)) == 0; }; - _processedGuids.erase(std::remove_if(_processedGuids.begin(), _processedGuids.end(), comp), _processedGuids.end()); + _processedGuids.erase(std::remove_if(_processedGuids.begin(), _processedGuids.end(), comp), + _processedGuids.end()); joystick.joystick->Unacquire(); joystick.joystick->Release(); @@ -327,7 +389,8 @@ void DirectInputManager::RefreshState() } //Add the newly-found joysticks - for(DirectInputData &joystick : _joysticksToAdd) { + for (DirectInputData& joystick : _joysticksToAdd) + { joysticks.push_back(joystick); } @@ -336,7 +399,8 @@ void DirectInputManager::RefreshState() _needToUpdate = false; } - for(DirectInputData &joystick : _joysticks) { + for (DirectInputData& joystick : _joysticks) + { UpdateInputState(joystick); } } @@ -348,7 +412,8 @@ int DirectInputManager::GetJoystickCount() bool DirectInputManager::IsPressed(int port, int button) { - if(port >= (int)_joysticks.size() || !_joysticks[port].stateValid) { + if (port >= (int)_joysticks.size() || !_joysticks[port].stateValid) + { return false; } @@ -359,47 +424,51 @@ bool DirectInputManager::IsPressed(int port, int button) int povDirection = state.rgdwPOV[0] / 4500; bool povCentered = (LOWORD(state.rgdwPOV[0]) == 0xFFFF) || povDirection >= 8; - switch(button) { - case 0x00: return state.lY - defaultState.lY < -deadRange; - case 0x01: return state.lY - defaultState.lY > deadRange; - case 0x02: return state.lX - defaultState.lX < -deadRange; - case 0x03: return state.lX - defaultState.lX > deadRange; - case 0x04: return state.lRy - defaultState.lRy < -deadRange; - case 0x05: return state.lRy - defaultState.lRy > deadRange; - case 0x06: return state.lRx - defaultState.lRx < -deadRange; - case 0x07: return state.lRx - defaultState.lRx > deadRange; - case 0x08: return state.lZ - defaultState.lZ < -deadRange; - case 0x09: return state.lZ - defaultState.lZ > deadRange; - case 0x0A: return state.lRz - defaultState.lRz < -deadRange; - case 0x0B: return state.lRz - defaultState.lRz > deadRange; - case 0x0C: return !povCentered && (povDirection == 7 || povDirection == 0 || povDirection == 1); - case 0x0D: return !povCentered && (povDirection >= 3 && povDirection <= 5); - case 0x0E: return !povCentered && (povDirection >= 1 && povDirection <= 3); - case 0x0F: return !povCentered && (povDirection >= 5 && povDirection <= 7); - default: return state.rgbButtons[button - 0x10] != 0; + switch (button) + { + case 0x00: return state.lY - defaultState.lY < -deadRange; + case 0x01: return state.lY - defaultState.lY > deadRange; + case 0x02: return state.lX - defaultState.lX < -deadRange; + case 0x03: return state.lX - defaultState.lX > deadRange; + case 0x04: return state.lRy - defaultState.lRy < -deadRange; + case 0x05: return state.lRy - defaultState.lRy > deadRange; + case 0x06: return state.lRx - defaultState.lRx < -deadRange; + case 0x07: return state.lRx - defaultState.lRx > deadRange; + case 0x08: return state.lZ - defaultState.lZ < -deadRange; + case 0x09: return state.lZ - defaultState.lZ > deadRange; + case 0x0A: return state.lRz - defaultState.lRz < -deadRange; + case 0x0B: return state.lRz - defaultState.lRz > deadRange; + case 0x0C: return !povCentered && (povDirection == 7 || povDirection == 0 || povDirection == 1); + case 0x0D: return !povCentered && (povDirection >= 3 && povDirection <= 5); + case 0x0E: return !povCentered && (povDirection >= 1 && povDirection <= 3); + case 0x0F: return !povCentered && (povDirection >= 5 && povDirection <= 7); + default: return state.rgbButtons[button - 0x10] != 0; } return false; } -void DirectInputManager::UpdateInputState(DirectInputData &data) +void DirectInputManager::UpdateInputState(DirectInputData& data) { DIJOYSTATE2 newState; HRESULT hr; // Poll the device to read the current state hr = data.joystick->Poll(); - if(FAILED(hr)) { + if (FAILED(hr)) + { // DInput is telling us that the input stream has been interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. We just re-acquire and try again. hr = data.joystick->Acquire(); - while(hr == DIERR_INPUTLOST) { + while (hr == DIERR_INPUTLOST) + { hr = data.joystick->Acquire(); } // hr may be DIERR_OTHERAPPHASPRIO or other errors. This may occur when the app is minimized or in the process of // switching, so just try again later - if(FAILED(hr)) { + if (FAILED(hr)) + { data.stateValid = false; _requestUpdate = true; return; @@ -407,7 +476,8 @@ void DirectInputManager::UpdateInputState(DirectInputData &data) } // Get the input's device state - if(FAILED(hr = data.joystick->GetDeviceState(sizeof(DIJOYSTATE2), &newState))) { + if (FAILED(hr = data.joystick->GetDeviceState(sizeof(DIJOYSTATE2), &newState))) + { MessageManager::Log("[DInput] Failed to get device state: " + std::to_string(hr)); data.stateValid = false; _requestUpdate = true; @@ -428,7 +498,8 @@ DirectInputManager::DirectInputManager(shared_ptr console, HWND hWnd) DirectInputManager::~DirectInputManager() { - for(DirectInputData &data: _joysticks) { + for (DirectInputData& data : _joysticks) + { data.joystick->Unacquire(); data.joystick->Release(); } @@ -439,7 +510,8 @@ DirectInputManager::~DirectInputManager() _processedGuids.clear(); _xinputDeviceGuids.clear(); - if(_directInput) { + if (_directInput) + { _directInput->Release(); _directInput = nullptr; } diff --git a/Windows/DirectXTK/Audio.h b/Windows/DirectXTK/Audio.h index a05bdd7..a6fd63c 100644 --- a/Windows/DirectXTK/Audio.h +++ b/Windows/DirectXTK/Audio.h @@ -93,626 +93,656 @@ namespace DirectX { - #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) +#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) #define XM_CALLCONV __fastcall typedef const XMVECTOR& HXMVECTOR; typedef const XMMATRIX& FXMMATRIX; - #endif +#endif - class SoundEffectInstance; + class SoundEffectInstance; - //---------------------------------------------------------------------------------- - struct AudioStatistics - { - size_t playingOneShots; // Number of one-shot sounds currently playing - size_t playingInstances; // Number of sound effect instances currently playing - size_t allocatedInstances; // Number of SoundEffectInstance allocated - size_t allocatedVoices; // Number of XAudio2 voices allocated (standard, 3D, one-shots, and idle one-shots) - size_t allocatedVoices3d; // Number of XAudio2 voices allocated for 3D - size_t allocatedVoicesOneShot; // Number of XAudio2 voices allocated for one-shot sounds - size_t allocatedVoicesIdle; // Number of XAudio2 voices allocated for one-shot sounds but not currently in use - size_t audioBytes; // Total wave data (in bytes) in SoundEffects and in-memory WaveBanks + //---------------------------------------------------------------------------------- + struct AudioStatistics + { + size_t playingOneShots; // Number of one-shot sounds currently playing + size_t playingInstances; // Number of sound effect instances currently playing + size_t allocatedInstances; // Number of SoundEffectInstance allocated + size_t allocatedVoices; // Number of XAudio2 voices allocated (standard, 3D, one-shots, and idle one-shots) + size_t allocatedVoices3d; // Number of XAudio2 voices allocated for 3D + size_t allocatedVoicesOneShot; // Number of XAudio2 voices allocated for one-shot sounds + size_t allocatedVoicesIdle; // Number of XAudio2 voices allocated for one-shot sounds but not currently in use + size_t audioBytes; // Total wave data (in bytes) in SoundEffects and in-memory WaveBanks #if defined(_XBOX_ONE) && defined(_TITLE) size_t xmaAudioBytes; // Total wave data (in bytes) in SoundEffects and in-memory WaveBanks allocated with ApuAlloc #endif - }; + }; - //---------------------------------------------------------------------------------- - class IVoiceNotify - { - public: - virtual void __cdecl OnBufferEnd() = 0; - // Notfication that a voice buffer has finished - // Note this is called from XAudio2's worker thread, so it should perform very minimal and thread-safe operations + //---------------------------------------------------------------------------------- + class IVoiceNotify + { + public: + virtual void __cdecl OnBufferEnd() = 0; + // Notfication that a voice buffer has finished + // Note this is called from XAudio2's worker thread, so it should perform very minimal and thread-safe operations - virtual void __cdecl OnCriticalError() = 0; - // Notification that the audio engine encountered a critical error + virtual void __cdecl OnCriticalError() = 0; + // Notification that the audio engine encountered a critical error - virtual void __cdecl OnReset() = 0; - // Notification of an audio engine reset + virtual void __cdecl OnReset() = 0; + // Notification of an audio engine reset - virtual void __cdecl OnUpdate() = 0; - // Notification of an audio engine per-frame update (opt-in) + virtual void __cdecl OnUpdate() = 0; + // Notification of an audio engine per-frame update (opt-in) - virtual void __cdecl OnDestroyEngine() = 0; - // Notification that the audio engine is being destroyed + virtual void __cdecl OnDestroyEngine() = 0; + // Notification that the audio engine is being destroyed - virtual void __cdecl OnTrim() = 0; - // Notification of a request to trim the voice pool + virtual void __cdecl OnTrim() = 0; + // Notification of a request to trim the voice pool - virtual void __cdecl GatherStatistics( AudioStatistics& stats ) const = 0; - // Contribute to statistics request - }; + virtual void __cdecl GatherStatistics(AudioStatistics& stats) const = 0; + // Contribute to statistics request + }; - //---------------------------------------------------------------------------------- - enum AUDIO_ENGINE_FLAGS - { - AudioEngine_Default = 0x0, + //---------------------------------------------------------------------------------- + enum AUDIO_ENGINE_FLAGS + { + AudioEngine_Default = 0x0, - AudioEngine_EnvironmentalReverb = 0x1, - AudioEngine_ReverbUseFilters = 0x2, - AudioEngine_UseMasteringLimiter = 0x4, + AudioEngine_EnvironmentalReverb = 0x1, + AudioEngine_ReverbUseFilters = 0x2, + AudioEngine_UseMasteringLimiter = 0x4, - AudioEngine_Debug = 0x10000, - AudioEngine_ThrowOnNoAudioHW = 0x20000, - AudioEngine_DisableVoiceReuse = 0x40000, - }; + AudioEngine_Debug = 0x10000, + AudioEngine_ThrowOnNoAudioHW = 0x20000, + AudioEngine_DisableVoiceReuse = 0x40000, + }; - inline AUDIO_ENGINE_FLAGS operator|(AUDIO_ENGINE_FLAGS a, AUDIO_ENGINE_FLAGS b) { return static_cast( static_cast(a) | static_cast(b) ); } + inline AUDIO_ENGINE_FLAGS operator|(AUDIO_ENGINE_FLAGS a, AUDIO_ENGINE_FLAGS b) + { + return static_cast(static_cast(a) | static_cast(b)); + } - enum SOUND_EFFECT_INSTANCE_FLAGS - { - SoundEffectInstance_Default = 0x0, + enum SOUND_EFFECT_INSTANCE_FLAGS + { + SoundEffectInstance_Default = 0x0, - SoundEffectInstance_Use3D = 0x1, - SoundEffectInstance_ReverbUseFilters = 0x2, - SoundEffectInstance_NoSetPitch = 0x4, + SoundEffectInstance_Use3D = 0x1, + SoundEffectInstance_ReverbUseFilters = 0x2, + SoundEffectInstance_NoSetPitch = 0x4, - SoundEffectInstance_UseRedirectLFE = 0x10000, - }; + SoundEffectInstance_UseRedirectLFE = 0x10000, + }; - inline SOUND_EFFECT_INSTANCE_FLAGS operator|(SOUND_EFFECT_INSTANCE_FLAGS a, SOUND_EFFECT_INSTANCE_FLAGS b) { return static_cast( static_cast(a) | static_cast(b) ); } + inline SOUND_EFFECT_INSTANCE_FLAGS operator|(SOUND_EFFECT_INSTANCE_FLAGS a, SOUND_EFFECT_INSTANCE_FLAGS b) + { + return static_cast(static_cast(a) | static_cast(b)); + } - enum AUDIO_ENGINE_REVERB - { - Reverb_Off, - Reverb_Default, - Reverb_Generic, - Reverb_Forest, - Reverb_PaddedCell, - Reverb_Room, - Reverb_Bathroom, - Reverb_LivingRoom, - Reverb_StoneRoom, - Reverb_Auditorium, - Reverb_ConcertHall, - Reverb_Cave, - Reverb_Arena, - Reverb_Hangar, - Reverb_CarpetedHallway, - Reverb_Hallway, - Reverb_StoneCorridor, - Reverb_Alley, - Reverb_City, - Reverb_Mountains, - Reverb_Quarry, - Reverb_Plain, - Reverb_ParkingLot, - Reverb_SewerPipe, - Reverb_Underwater, - Reverb_SmallRoom, - Reverb_MediumRoom, - Reverb_LargeRoom, - Reverb_MediumHall, - Reverb_LargeHall, - Reverb_Plate, - Reverb_MAX - }; + enum AUDIO_ENGINE_REVERB + { + Reverb_Off, + Reverb_Default, + Reverb_Generic, + Reverb_Forest, + Reverb_PaddedCell, + Reverb_Room, + Reverb_Bathroom, + Reverb_LivingRoom, + Reverb_StoneRoom, + Reverb_Auditorium, + Reverb_ConcertHall, + Reverb_Cave, + Reverb_Arena, + Reverb_Hangar, + Reverb_CarpetedHallway, + Reverb_Hallway, + Reverb_StoneCorridor, + Reverb_Alley, + Reverb_City, + Reverb_Mountains, + Reverb_Quarry, + Reverb_Plain, + Reverb_ParkingLot, + Reverb_SewerPipe, + Reverb_Underwater, + Reverb_SmallRoom, + Reverb_MediumRoom, + Reverb_LargeRoom, + Reverb_MediumHall, + Reverb_LargeHall, + Reverb_Plate, + Reverb_MAX + }; - enum SoundState - { - STOPPED = 0, - PLAYING, - PAUSED - }; + enum SoundState + { + STOPPED = 0, + PLAYING, + PAUSED + }; - //---------------------------------------------------------------------------------- - class AudioEngine - { - public: - explicit AudioEngine( AUDIO_ENGINE_FLAGS flags = AudioEngine_Default, _In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr, - AUDIO_STREAM_CATEGORY category = AudioCategory_GameEffects ); + //---------------------------------------------------------------------------------- + class AudioEngine + { + public: + explicit AudioEngine(AUDIO_ENGINE_FLAGS flags = AudioEngine_Default, _In_opt_ const WAVEFORMATEX* wfx = nullptr, + _In_opt_z_ const wchar_t* deviceId = nullptr, + AUDIO_STREAM_CATEGORY category = AudioCategory_GameEffects); - AudioEngine(AudioEngine&& moveFrom); - AudioEngine& operator= (AudioEngine&& moveFrom); - virtual ~AudioEngine(); + AudioEngine(AudioEngine&& moveFrom); + AudioEngine& operator=(AudioEngine&& moveFrom); + virtual ~AudioEngine(); - bool __cdecl Update(); - // Performs per-frame processing for the audio engine, returns false if in 'silent mode' + bool __cdecl Update(); + // Performs per-frame processing for the audio engine, returns false if in 'silent mode' - bool __cdecl Reset( _In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr ); - // Reset audio engine from critical error/silent mode using a new device; can also 'migrate' the graph - // Returns true if succesfully reset, false if in 'silent mode' due to no default device - // Note: One shots are lost, all SoundEffectInstances are in the STOPPED state after successful reset + bool __cdecl Reset(_In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr); + // Reset audio engine from critical error/silent mode using a new device; can also 'migrate' the graph + // Returns true if succesfully reset, false if in 'silent mode' due to no default device + // Note: One shots are lost, all SoundEffectInstances are in the STOPPED state after successful reset - void __cdecl Suspend(); - void __cdecl Resume(); - // Suspend/resumes audio processing (i.e. global pause/resume) + void __cdecl Suspend(); + void __cdecl Resume(); + // Suspend/resumes audio processing (i.e. global pause/resume) - float __cdecl GetMasterVolume() const; - void __cdecl SetMasterVolume( float volume ); - // Master volume property for all sounds + float __cdecl GetMasterVolume() const; + void __cdecl SetMasterVolume(float volume); + // Master volume property for all sounds - void __cdecl SetReverb( AUDIO_ENGINE_REVERB reverb ); - void __cdecl SetReverb( _In_opt_ const XAUDIO2FX_REVERB_PARAMETERS* native ); - // Sets environmental reverb for 3D positional audio (if active) + void __cdecl SetReverb(AUDIO_ENGINE_REVERB reverb); + void __cdecl SetReverb(_In_opt_ const XAUDIO2FX_REVERB_PARAMETERS* native); + // Sets environmental reverb for 3D positional audio (if active) - void __cdecl SetMasteringLimit( int release, int loudness ); - // Sets the mastering volume limiter properties (if active) + void __cdecl SetMasteringLimit(int release, int loudness); + // Sets the mastering volume limiter properties (if active) - AudioStatistics __cdecl GetStatistics() const; - // Gathers audio engine statistics + AudioStatistics __cdecl GetStatistics() const; + // Gathers audio engine statistics - WAVEFORMATEXTENSIBLE __cdecl GetOutputFormat() const; - // Returns the format consumed by the mastering voice (which is the same as the device output if defaults are used) + WAVEFORMATEXTENSIBLE __cdecl GetOutputFormat() const; + // Returns the format consumed by the mastering voice (which is the same as the device output if defaults are used) - uint32_t __cdecl GetChannelMask() const; - // Returns the output channel mask + uint32_t __cdecl GetChannelMask() const; + // Returns the output channel mask - int __cdecl GetOutputChannels() const; - // Returns the number of output channels + int __cdecl GetOutputChannels() const; + // Returns the number of output channels - bool __cdecl IsAudioDevicePresent() const; - // Returns true if the audio graph is operating normally, false if in 'silent mode' + bool __cdecl IsAudioDevicePresent() const; + // Returns true if the audio graph is operating normally, false if in 'silent mode' - bool __cdecl IsCriticalError() const; - // Returns true if the audio graph is halted due to a critical error (which also places the engine into 'silent mode') + bool __cdecl IsCriticalError() const; + // Returns true if the audio graph is halted due to a critical error (which also places the engine into 'silent mode') - // Voice pool management. - void __cdecl SetDefaultSampleRate( int sampleRate ); - // Sample rate for voices in the reuse pool (defaults to 44100) + // Voice pool management. + void __cdecl SetDefaultSampleRate(int sampleRate); + // Sample rate for voices in the reuse pool (defaults to 44100) - void __cdecl SetMaxVoicePool( size_t maxOneShots, size_t maxInstances ); - // Maximum number of voices to allocate for one-shots and instances - // Note: one-shots over this limit are ignored; too many instance voices throws an exception + void __cdecl SetMaxVoicePool(size_t maxOneShots, size_t maxInstances); + // Maximum number of voices to allocate for one-shots and instances + // Note: one-shots over this limit are ignored; too many instance voices throws an exception - void __cdecl TrimVoicePool(); - // Releases any currently unused voices + void __cdecl TrimVoicePool(); + // Releases any currently unused voices - // Internal-use functions - void __cdecl AllocateVoice( _In_ const WAVEFORMATEX* wfx, SOUND_EFFECT_INSTANCE_FLAGS flags, bool oneshot, _Outptr_result_maybenull_ IXAudio2SourceVoice** voice ); + // Internal-use functions + void __cdecl AllocateVoice(_In_ const WAVEFORMATEX* wfx, SOUND_EFFECT_INSTANCE_FLAGS flags, bool oneshot, + _Outptr_result_maybenull_ IXAudio2SourceVoice** voice); - void __cdecl DestroyVoice( _In_ IXAudio2SourceVoice* voice ); - // Should only be called for instance voices, not one-shots + void __cdecl DestroyVoice(_In_ IXAudio2SourceVoice* voice); + // Should only be called for instance voices, not one-shots - void __cdecl RegisterNotify( _In_ IVoiceNotify* notify, bool usesUpdate ); - void __cdecl UnregisterNotify( _In_ IVoiceNotify* notify, bool usesOneShots, bool usesUpdate ); + void __cdecl RegisterNotify(_In_ IVoiceNotify* notify, bool usesUpdate); + void __cdecl UnregisterNotify(_In_ IVoiceNotify* notify, bool usesOneShots, bool usesUpdate); - // XAudio2 interface access - IXAudio2* __cdecl GetInterface() const; - IXAudio2MasteringVoice* __cdecl GetMasterVoice() const; - IXAudio2SubmixVoice* __cdecl GetReverbVoice() const; - X3DAUDIO_HANDLE& __cdecl Get3DHandle() const; + // XAudio2 interface access + IXAudio2* __cdecl GetInterface() const; + IXAudio2MasteringVoice* __cdecl GetMasterVoice() const; + IXAudio2SubmixVoice* __cdecl GetReverbVoice() const; + X3DAUDIO_HANDLE& __cdecl Get3DHandle() const; - // Static functions - struct RendererDetail - { - std::wstring deviceId; - std::wstring description; - }; + // Static functions + struct RendererDetail + { + std::wstring deviceId; + std::wstring description; + }; - static std::vector __cdecl GetRendererDetails(); - // Returns a list of valid audio endpoint devices + static std::vector __cdecl GetRendererDetails(); + // Returns a list of valid audio endpoint devices - private: - // Private implementation. - class Impl; - std::unique_ptr pImpl; + private: + // Private implementation. + class Impl; + std::unique_ptr pImpl; - // Prevent copying. - AudioEngine(AudioEngine const&) DIRECTX_CTOR_DELETE - AudioEngine& operator= (AudioEngine const&) DIRECTX_CTOR_DELETE - }; + // Prevent copying. + AudioEngine(AudioEngine const&) DIRECTX_CTOR_DELETE + AudioEngine& operator=(AudioEngine const&) DIRECTX_CTOR_DELETE + }; - //---------------------------------------------------------------------------------- - class WaveBank - { - public: - WaveBank( _In_ AudioEngine* engine, _In_z_ const wchar_t* wbFileName ); + //---------------------------------------------------------------------------------- + class WaveBank + { + public: + WaveBank(_In_ AudioEngine* engine, _In_z_ const wchar_t* wbFileName); - WaveBank(WaveBank&& moveFrom); - WaveBank& operator= (WaveBank&& moveFrom); - virtual ~WaveBank(); + WaveBank(WaveBank&& moveFrom); + WaveBank& operator=(WaveBank&& moveFrom); + virtual ~WaveBank(); - void __cdecl Play( int index ); - void __cdecl Play( int index, float volume, float pitch, float pan ); + void __cdecl Play(int index); + void __cdecl Play(int index, float volume, float pitch, float pan); - void __cdecl Play( _In_z_ const char* name ); - void __cdecl Play( _In_z_ const char* name, float volume, float pitch, float pan ); + void __cdecl Play(_In_z_ const char* name); + void __cdecl Play(_In_z_ const char* name, float volume, float pitch, float pan); - std::unique_ptr __cdecl CreateInstance( int index, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default ); - std::unique_ptr __cdecl CreateInstance( _In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default ); + std::unique_ptr __cdecl CreateInstance( + int index, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default); + std::unique_ptr __cdecl CreateInstance( + _In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default); - bool __cdecl IsPrepared() const; - bool __cdecl IsInUse() const; - bool __cdecl IsStreamingBank() const; + bool __cdecl IsPrepared() const; + bool __cdecl IsInUse() const; + bool __cdecl IsStreamingBank() const; - size_t __cdecl GetSampleSizeInBytes( int index ) const; - // Returns size of wave audio data + size_t __cdecl GetSampleSizeInBytes(int index) const; + // Returns size of wave audio data - size_t __cdecl GetSampleDuration( int index ) const; - // Returns the duration in samples + size_t __cdecl GetSampleDuration(int index) const; + // Returns the duration in samples - size_t __cdecl GetSampleDurationMS( int index ) const; - // Returns the duration in milliseconds + size_t __cdecl GetSampleDurationMS(int index) const; + // Returns the duration in milliseconds - const WAVEFORMATEX* __cdecl GetFormat( int index, _Out_writes_bytes_(maxsize) WAVEFORMATEX* wfx, size_t maxsize ) const; + const WAVEFORMATEX* __cdecl GetFormat(int index, _Out_writes_bytes_(maxsize) WAVEFORMATEX* wfx, + size_t maxsize) const; - int __cdecl Find( _In_z_ const char* name ) const; + int __cdecl Find(_In_z_ const char* name) const; #if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ ) - bool __cdecl FillSubmitBuffer( int index, _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer ) const; + bool __cdecl FillSubmitBuffer(int index, _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer) const; #else void __cdecl FillSubmitBuffer( int index, _Out_ XAUDIO2_BUFFER& buffer ) const; #endif - private: - // Private implementation. - class Impl; + private: + // Private implementation. + class Impl; - std::unique_ptr pImpl; + std::unique_ptr pImpl; - // Prevent copying. - WaveBank(WaveBank const&) DIRECTX_CTOR_DELETE - WaveBank& operator= (WaveBank const&) DIRECTX_CTOR_DELETE + // Prevent copying. + WaveBank(WaveBank const&) DIRECTX_CTOR_DELETE + WaveBank& operator=(WaveBank const&) DIRECTX_CTOR_DELETE - // Private interface - void __cdecl UnregisterInstance( _In_ SoundEffectInstance* instance ); + // Private interface + void __cdecl UnregisterInstance(_In_ SoundEffectInstance* instance); - friend class SoundEffectInstance; - }; + friend class SoundEffectInstance; + }; - //---------------------------------------------------------------------------------- - class SoundEffect - { - public: - SoundEffect( _In_ AudioEngine* engine, _In_z_ const wchar_t* waveFileName ); + //---------------------------------------------------------------------------------- + class SoundEffect + { + public: + SoundEffect(_In_ AudioEngine* engine, _In_z_ const wchar_t* waveFileName); - SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData, - _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes ); + SoundEffect(_In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData, + _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, + size_t audioBytes); - SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData, - _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes, - uint32_t loopStart, uint32_t loopLength ); + SoundEffect(_In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData, + _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, + size_t audioBytes, + uint32_t loopStart, uint32_t loopLength); #if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/) - SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData, - _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes, - _In_reads_(seekCount) const uint32_t* seekTable, size_t seekCount ); + SoundEffect(_In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData, + _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, + size_t audioBytes, + _In_reads_(seekCount) const uint32_t* seekTable, size_t seekCount); #endif - SoundEffect(SoundEffect&& moveFrom); - SoundEffect& operator= (SoundEffect&& moveFrom); - virtual ~SoundEffect(); + SoundEffect(SoundEffect&& moveFrom); + SoundEffect& operator=(SoundEffect&& moveFrom); + virtual ~SoundEffect(); - void __cdecl Play(); - void __cdecl Play(float volume, float pitch, float pan); + void __cdecl Play(); + void __cdecl Play(float volume, float pitch, float pan); - std::unique_ptr __cdecl CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default ); + std::unique_ptr __cdecl CreateInstance( + SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default); - bool __cdecl IsInUse() const; + bool __cdecl IsInUse() const; - size_t __cdecl GetSampleSizeInBytes() const; - // Returns size of wave audio data + size_t __cdecl GetSampleSizeInBytes() const; + // Returns size of wave audio data - size_t __cdecl GetSampleDuration() const; - // Returns the duration in samples + size_t __cdecl GetSampleDuration() const; + // Returns the duration in samples - size_t __cdecl GetSampleDurationMS() const; - // Returns the duration in milliseconds + size_t __cdecl GetSampleDurationMS() const; + // Returns the duration in milliseconds - const WAVEFORMATEX* __cdecl GetFormat() const; + const WAVEFORMATEX* __cdecl GetFormat() const; #if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/) - bool __cdecl FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer ) const; + bool __cdecl FillSubmitBuffer(_Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer) const; #else void __cdecl FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer ) const; #endif - private: - // Private implementation. - class Impl; - - std::unique_ptr pImpl; - - // Prevent copying. - SoundEffect(SoundEffect const&) DIRECTX_CTOR_DELETE - SoundEffect& operator= (SoundEffect const&) DIRECTX_CTOR_DELETE - - // Private interface - void __cdecl UnregisterInstance( _In_ SoundEffectInstance* instance ); - - friend class SoundEffectInstance; - }; - - - //---------------------------------------------------------------------------------- - struct AudioListener : public X3DAUDIO_LISTENER - { - AudioListener() - { - memset( this, 0, sizeof(X3DAUDIO_LISTENER) ); - - OrientFront.z = -1.f; - - OrientTop.y = 1.f; - } - - void XM_CALLCONV SetPosition( FXMVECTOR v ) - { - XMStoreFloat3( reinterpret_cast( &Position ), v ); - } - void __cdecl SetPosition( const XMFLOAT3& pos ) - { - Position.x = pos.x; - Position.y = pos.y; - Position.z = pos.z; - } - - void XM_CALLCONV SetVelocity( FXMVECTOR v ) - { - XMStoreFloat3( reinterpret_cast( &Velocity ), v ); - } - void __cdecl SetVelocity( const XMFLOAT3& vel ) - { - Velocity.x = vel.x; - Velocity.y = vel.y; - Velocity.z = vel.z; - } - - void XM_CALLCONV SetOrientation( FXMVECTOR forward, FXMVECTOR up ) - { - XMStoreFloat3( reinterpret_cast( &OrientFront ), forward ); - XMStoreFloat3( reinterpret_cast( &OrientTop ), up ); - } - void __cdecl SetOrientation( const XMFLOAT3& forward, const XMFLOAT3& up ) - { - OrientFront.x = forward.x; OrientTop.x = up.x; - OrientFront.y = forward.y; OrientTop.y = up.y; - OrientFront.z = forward.z; OrientTop.z = up.z; - } - - void XM_CALLCONV SetOrientationFromQuaternion( FXMVECTOR quat ) - { - XMVECTOR forward = XMVector3Rotate( g_XMIdentityR2, quat ); - XMStoreFloat3( reinterpret_cast( &OrientFront ), forward ); - - XMVECTOR up = XMVector3Rotate( g_XMIdentityR1, quat ); - XMStoreFloat3( reinterpret_cast( &OrientTop ), up ); - } - - void XM_CALLCONV Update( FXMVECTOR newPos, XMVECTOR upDir, float dt ) - // Updates velocity and orientation by tracking changes in position over time... - { - if ( dt > 0.f ) - { - XMVECTOR lastPos = XMLoadFloat3( reinterpret_cast( &Position ) ); - - XMVECTOR vDelta = ( newPos - lastPos ); - XMVECTOR v = vDelta / dt; - XMStoreFloat3( reinterpret_cast( &Velocity ), v ); - - vDelta = XMVector3Normalize( vDelta ); - XMStoreFloat3( reinterpret_cast( &OrientFront ), vDelta ); - - v = XMVector3Cross( upDir, vDelta ); - v = XMVector3Normalize( v ); - - v = XMVector3Cross( vDelta, v ); - v = XMVector3Normalize( v ); - XMStoreFloat3( reinterpret_cast( &OrientTop ), v ); - - XMStoreFloat3( reinterpret_cast( &Position ), newPos ); - } - } - }; - - - //---------------------------------------------------------------------------------- - struct AudioEmitter : public X3DAUDIO_EMITTER - { - float EmitterAzimuths[XAUDIO2_MAX_AUDIO_CHANNELS]; - - AudioEmitter() - { - memset( this, 0, sizeof(X3DAUDIO_EMITTER) ); - memset( EmitterAzimuths, 0, sizeof(EmitterAzimuths) ); - - OrientFront.z = -1.f; - - OrientTop.y = - ChannelRadius = - CurveDistanceScaler = - DopplerScaler = 1.f; - - ChannelCount = 1; - pChannelAzimuths = EmitterAzimuths; - - InnerRadiusAngle = X3DAUDIO_PI / 4.0f; - } - - void XM_CALLCONV SetPosition( FXMVECTOR v ) - { - XMStoreFloat3( reinterpret_cast( &Position ), v ); - } - void __cdecl SetPosition( const XMFLOAT3& pos ) - { - Position.x = pos.x; - Position.y = pos.y; - Position.z = pos.z; - } - - void XM_CALLCONV SetVelocity( FXMVECTOR v ) - { - XMStoreFloat3( reinterpret_cast( &Velocity ), v ); - } - void __cdecl SetVelocity( const XMFLOAT3& vel ) - { - Velocity.x = vel.x; - Velocity.y = vel.y; - Velocity.z = vel.z; - } - - void XM_CALLCONV SetOrientation( FXMVECTOR forward, FXMVECTOR up ) - { - XMStoreFloat3( reinterpret_cast( &OrientFront ), forward ); - XMStoreFloat3( reinterpret_cast( &OrientTop ), up ); - } - void __cdecl SetOrientation( const XMFLOAT3& forward, const XMFLOAT3& up ) - { - OrientFront.x = forward.x; OrientTop.x = up.x; - OrientFront.y = forward.y; OrientTop.y = up.y; - OrientFront.z = forward.z; OrientTop.z = up.z; - } - - void XM_CALLCONV SetOrientationFromQuaternion( FXMVECTOR quat ) - { - XMVECTOR forward = XMVector3Rotate( g_XMIdentityR2, quat ); - XMStoreFloat3( reinterpret_cast( &OrientFront ), forward ); - - XMVECTOR up = XMVector3Rotate( g_XMIdentityR1, quat ); - XMStoreFloat3( reinterpret_cast( &OrientTop ), up ); - } - - void XM_CALLCONV Update( FXMVECTOR newPos, XMVECTOR upDir, float dt ) - // Updates velocity and orientation by tracking changes in position over time... - { - if ( dt > 0.f ) - { - XMVECTOR lastPos = XMLoadFloat3( reinterpret_cast( &Position ) ); - - XMVECTOR vDelta = ( newPos - lastPos ); - XMVECTOR v = vDelta / dt; - XMStoreFloat3( reinterpret_cast( &Velocity ), v ); - - vDelta = XMVector3Normalize( vDelta ); - XMStoreFloat3( reinterpret_cast( &OrientFront ), vDelta ); - - v = XMVector3Cross( upDir, vDelta ); - v = XMVector3Normalize( v ); - - v = XMVector3Cross( vDelta, v ); - v = XMVector3Normalize( v ); - XMStoreFloat3( reinterpret_cast( &OrientTop ), v ); - - XMStoreFloat3( reinterpret_cast( &Position ), newPos ); - } - } - }; - - - //---------------------------------------------------------------------------------- - class SoundEffectInstance - { - public: - SoundEffectInstance(SoundEffectInstance&& moveFrom); - SoundEffectInstance& operator= (SoundEffectInstance&& moveFrom); - virtual ~SoundEffectInstance(); - - void __cdecl Play( bool loop = false ); - void __cdecl Stop( bool immediate = true ); - void __cdecl Pause(); - void __cdecl Resume(); - - void __cdecl SetVolume( float volume ); - void __cdecl SetPitch( float pitch ); - void __cdecl SetPan( float pan ); - - void __cdecl Apply3D( const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords = true ); - - bool __cdecl IsLooped() const; - - SoundState __cdecl GetState(); - - // Notifications. - void __cdecl OnDestroyParent(); - - private: - // Private implementation. - class Impl; - - std::unique_ptr pImpl; - - // Private constructors - SoundEffectInstance( _In_ AudioEngine* engine, _In_ SoundEffect* effect, SOUND_EFFECT_INSTANCE_FLAGS flags ); - SoundEffectInstance( _In_ AudioEngine* engine, _In_ WaveBank* effect, int index, SOUND_EFFECT_INSTANCE_FLAGS flags ); - - friend std::unique_ptr __cdecl SoundEffect::CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS ); - friend std::unique_ptr __cdecl WaveBank::CreateInstance( int, SOUND_EFFECT_INSTANCE_FLAGS ); - - // Prevent copying. - SoundEffectInstance(SoundEffectInstance const&) DIRECTX_CTOR_DELETE - SoundEffectInstance& operator= (SoundEffectInstance const&) DIRECTX_CTOR_DELETE - }; - - - //---------------------------------------------------------------------------------- - class DynamicSoundEffectInstance - { - public: - DynamicSoundEffectInstance( _In_ AudioEngine* engine, - _In_opt_ std::function bufferNeeded, - int sampleRate, int channels, int sampleBits = 16, - SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default ); - DynamicSoundEffectInstance(DynamicSoundEffectInstance&& moveFrom); - DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance&& moveFrom); - virtual ~DynamicSoundEffectInstance(); + private: + // Private implementation. + class Impl; + + std::unique_ptr pImpl; + + // Prevent copying. + SoundEffect(SoundEffect const&) DIRECTX_CTOR_DELETE + SoundEffect& operator=(SoundEffect const&) DIRECTX_CTOR_DELETE + + // Private interface + void __cdecl UnregisterInstance(_In_ SoundEffectInstance* instance); + + friend class SoundEffectInstance; + }; + + + //---------------------------------------------------------------------------------- + struct AudioListener : public X3DAUDIO_LISTENER + { + AudioListener() + { + memset(this, 0, sizeof(X3DAUDIO_LISTENER)); + + OrientFront.z = -1.f; + + OrientTop.y = 1.f; + } + + void XM_CALLCONV SetPosition(FXMVECTOR v) + { + XMStoreFloat3(reinterpret_cast(&Position), v); + } + + void __cdecl SetPosition(const XMFLOAT3& pos) + { + Position.x = pos.x; + Position.y = pos.y; + Position.z = pos.z; + } + + void XM_CALLCONV SetVelocity(FXMVECTOR v) + { + XMStoreFloat3(reinterpret_cast(&Velocity), v); + } + + void __cdecl SetVelocity(const XMFLOAT3& vel) + { + Velocity.x = vel.x; + Velocity.y = vel.y; + Velocity.z = vel.z; + } + + void XM_CALLCONV SetOrientation(FXMVECTOR forward, FXMVECTOR up) + { + XMStoreFloat3(reinterpret_cast(&OrientFront), forward); + XMStoreFloat3(reinterpret_cast(&OrientTop), up); + } + + void __cdecl SetOrientation(const XMFLOAT3& forward, const XMFLOAT3& up) + { + OrientFront.x = forward.x; + OrientTop.x = up.x; + OrientFront.y = forward.y; + OrientTop.y = up.y; + OrientFront.z = forward.z; + OrientTop.z = up.z; + } + + void XM_CALLCONV SetOrientationFromQuaternion(FXMVECTOR quat) + { + XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat); + XMStoreFloat3(reinterpret_cast(&OrientFront), forward); + + XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat); + XMStoreFloat3(reinterpret_cast(&OrientTop), up); + } + + void XM_CALLCONV Update(FXMVECTOR newPos, XMVECTOR upDir, float dt) + // Updates velocity and orientation by tracking changes in position over time... + { + if (dt > 0.f) + { + XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast(&Position)); + + XMVECTOR vDelta = (newPos - lastPos); + XMVECTOR v = vDelta / dt; + XMStoreFloat3(reinterpret_cast(&Velocity), v); + + vDelta = XMVector3Normalize(vDelta); + XMStoreFloat3(reinterpret_cast(&OrientFront), vDelta); + + v = XMVector3Cross(upDir, vDelta); + v = XMVector3Normalize(v); + + v = XMVector3Cross(vDelta, v); + v = XMVector3Normalize(v); + XMStoreFloat3(reinterpret_cast(&OrientTop), v); + + XMStoreFloat3(reinterpret_cast(&Position), newPos); + } + } + }; + + + //---------------------------------------------------------------------------------- + struct AudioEmitter : public X3DAUDIO_EMITTER + { + float EmitterAzimuths[XAUDIO2_MAX_AUDIO_CHANNELS]; + + AudioEmitter() + { + memset(this, 0, sizeof(X3DAUDIO_EMITTER)); + memset(EmitterAzimuths, 0, sizeof(EmitterAzimuths)); + + OrientFront.z = -1.f; + + OrientTop.y = + ChannelRadius = + CurveDistanceScaler = + DopplerScaler = 1.f; + + ChannelCount = 1; + pChannelAzimuths = EmitterAzimuths; + + InnerRadiusAngle = X3DAUDIO_PI / 4.0f; + } + + void XM_CALLCONV SetPosition(FXMVECTOR v) + { + XMStoreFloat3(reinterpret_cast(&Position), v); + } + + void __cdecl SetPosition(const XMFLOAT3& pos) + { + Position.x = pos.x; + Position.y = pos.y; + Position.z = pos.z; + } + + void XM_CALLCONV SetVelocity(FXMVECTOR v) + { + XMStoreFloat3(reinterpret_cast(&Velocity), v); + } + + void __cdecl SetVelocity(const XMFLOAT3& vel) + { + Velocity.x = vel.x; + Velocity.y = vel.y; + Velocity.z = vel.z; + } + + void XM_CALLCONV SetOrientation(FXMVECTOR forward, FXMVECTOR up) + { + XMStoreFloat3(reinterpret_cast(&OrientFront), forward); + XMStoreFloat3(reinterpret_cast(&OrientTop), up); + } + + void __cdecl SetOrientation(const XMFLOAT3& forward, const XMFLOAT3& up) + { + OrientFront.x = forward.x; + OrientTop.x = up.x; + OrientFront.y = forward.y; + OrientTop.y = up.y; + OrientFront.z = forward.z; + OrientTop.z = up.z; + } + + void XM_CALLCONV SetOrientationFromQuaternion(FXMVECTOR quat) + { + XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat); + XMStoreFloat3(reinterpret_cast(&OrientFront), forward); + + XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat); + XMStoreFloat3(reinterpret_cast(&OrientTop), up); + } + + void XM_CALLCONV Update(FXMVECTOR newPos, XMVECTOR upDir, float dt) + // Updates velocity and orientation by tracking changes in position over time... + { + if (dt > 0.f) + { + XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast(&Position)); + + XMVECTOR vDelta = (newPos - lastPos); + XMVECTOR v = vDelta / dt; + XMStoreFloat3(reinterpret_cast(&Velocity), v); + + vDelta = XMVector3Normalize(vDelta); + XMStoreFloat3(reinterpret_cast(&OrientFront), vDelta); + + v = XMVector3Cross(upDir, vDelta); + v = XMVector3Normalize(v); + + v = XMVector3Cross(vDelta, v); + v = XMVector3Normalize(v); + XMStoreFloat3(reinterpret_cast(&OrientTop), v); + + XMStoreFloat3(reinterpret_cast(&Position), newPos); + } + } + }; + + + //---------------------------------------------------------------------------------- + class SoundEffectInstance + { + public: + SoundEffectInstance(SoundEffectInstance&& moveFrom); + SoundEffectInstance& operator=(SoundEffectInstance&& moveFrom); + virtual ~SoundEffectInstance(); + + void __cdecl Play(bool loop = false); + void __cdecl Stop(bool immediate = true); + void __cdecl Pause(); + void __cdecl Resume(); + + void __cdecl SetVolume(float volume); + void __cdecl SetPitch(float pitch); + void __cdecl SetPan(float pan); + + void __cdecl Apply3D(const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords = true); + + bool __cdecl IsLooped() const; + + SoundState __cdecl GetState(); + + // Notifications. + void __cdecl OnDestroyParent(); + + private: + // Private implementation. + class Impl; + + std::unique_ptr pImpl; + + // Private constructors + SoundEffectInstance(_In_ AudioEngine* engine, _In_ SoundEffect* effect, SOUND_EFFECT_INSTANCE_FLAGS flags); + SoundEffectInstance(_In_ AudioEngine* engine, _In_ WaveBank* effect, int index, + SOUND_EFFECT_INSTANCE_FLAGS flags); + + friend std::unique_ptr __cdecl SoundEffect::CreateInstance(SOUND_EFFECT_INSTANCE_FLAGS); + friend std::unique_ptr __cdecl WaveBank::CreateInstance(int, SOUND_EFFECT_INSTANCE_FLAGS); + + // Prevent copying. + SoundEffectInstance(SoundEffectInstance const&) DIRECTX_CTOR_DELETE + SoundEffectInstance& operator=(SoundEffectInstance const&) DIRECTX_CTOR_DELETE + }; - void __cdecl Play(); - void __cdecl Stop( bool immediate = true ); - void __cdecl Pause(); - void __cdecl Resume(); - void __cdecl SetVolume( float volume ); - void __cdecl SetPitch( float pitch ); - void __cdecl SetPan( float pan ); + //---------------------------------------------------------------------------------- + class DynamicSoundEffectInstance + { + public: + DynamicSoundEffectInstance(_In_ AudioEngine* engine, + _In_opt_ std::function + bufferNeeded, + int sampleRate, int channels, int sampleBits = 16, + SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default); + DynamicSoundEffectInstance(DynamicSoundEffectInstance&& moveFrom); + DynamicSoundEffectInstance& operator=(DynamicSoundEffectInstance&& moveFrom); + virtual ~DynamicSoundEffectInstance(); - void __cdecl Apply3D( const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords = true ); + void __cdecl Play(); + void __cdecl Stop(bool immediate = true); + void __cdecl Pause(); + void __cdecl Resume(); - void __cdecl SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, size_t audioBytes ); - void __cdecl SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, uint32_t offset, size_t audioBytes ); + void __cdecl SetVolume(float volume); + void __cdecl SetPitch(float pitch); + void __cdecl SetPan(float pan); - SoundState __cdecl GetState(); + void __cdecl Apply3D(const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords = true); - size_t __cdecl GetSampleDuration( size_t bytes ) const; - // Returns duration in samples of a buffer of a given size + void __cdecl SubmitBuffer(_In_reads_bytes_(audioBytes) const uint8_t* pAudioData, size_t audioBytes); + void __cdecl SubmitBuffer(_In_reads_bytes_(audioBytes) const uint8_t* pAudioData, uint32_t offset, + size_t audioBytes); - size_t __cdecl GetSampleDurationMS( size_t bytes ) const; - // Returns duration in milliseconds of a buffer of a given size + SoundState __cdecl GetState(); - size_t __cdecl GetSampleSizeInBytes( uint64_t duration ) const; - // Returns size of a buffer for a duration given in milliseconds + size_t __cdecl GetSampleDuration(size_t bytes) const; + // Returns duration in samples of a buffer of a given size - int __cdecl GetPendingBufferCount() const; + size_t __cdecl GetSampleDurationMS(size_t bytes) const; + // Returns duration in milliseconds of a buffer of a given size - const WAVEFORMATEX* __cdecl GetFormat() const; + size_t __cdecl GetSampleSizeInBytes(uint64_t duration) const; + // Returns size of a buffer for a duration given in milliseconds - private: - // Private implementation. - class Impl; + int __cdecl GetPendingBufferCount() const; - std::unique_ptr pImpl; + const WAVEFORMATEX* __cdecl GetFormat() const; - // Prevent copying. - DynamicSoundEffectInstance(DynamicSoundEffectInstance const&) DIRECTX_CTOR_DELETE - DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance const&) DIRECTX_CTOR_DELETE - }; + private: + // Private implementation. + class Impl; + + std::unique_ptr pImpl; + + // Prevent copying. + DynamicSoundEffectInstance(DynamicSoundEffectInstance const&) DIRECTX_CTOR_DELETE + DynamicSoundEffectInstance& operator=(DynamicSoundEffectInstance const&) DIRECTX_CTOR_DELETE + }; } -#pragma warning(pop) \ No newline at end of file +#pragma warning(pop) diff --git a/Windows/DirectXTK/CommonStates.h b/Windows/DirectXTK/CommonStates.h index cfeb436..77c85b9 100644 --- a/Windows/DirectXTK/CommonStates.h +++ b/Windows/DirectXTK/CommonStates.h @@ -35,47 +35,47 @@ namespace DirectX { - class CommonStates - { - public: - explicit CommonStates(_In_ ID3D11Device* device); - CommonStates(CommonStates&& moveFrom); - CommonStates& operator= (CommonStates&& moveFrom); - virtual ~CommonStates(); + class CommonStates + { + public: + explicit CommonStates(_In_ ID3D11Device* device); + CommonStates(CommonStates&& moveFrom); + CommonStates& operator=(CommonStates&& moveFrom); + virtual ~CommonStates(); - // Blend states. - ID3D11BlendState* __cdecl Opaque() const; - ID3D11BlendState* __cdecl AlphaBlend() const; - ID3D11BlendState* __cdecl Additive() const; - ID3D11BlendState* __cdecl NonPremultiplied() const; + // Blend states. + ID3D11BlendState* __cdecl Opaque() const; + ID3D11BlendState* __cdecl AlphaBlend() const; + ID3D11BlendState* __cdecl Additive() const; + ID3D11BlendState* __cdecl NonPremultiplied() const; - // Depth stencil states. - ID3D11DepthStencilState* __cdecl DepthNone() const; - ID3D11DepthStencilState* __cdecl DepthDefault() const; - ID3D11DepthStencilState* __cdecl DepthRead() const; + // Depth stencil states. + ID3D11DepthStencilState* __cdecl DepthNone() const; + ID3D11DepthStencilState* __cdecl DepthDefault() const; + ID3D11DepthStencilState* __cdecl DepthRead() const; - // Rasterizer states. - ID3D11RasterizerState* __cdecl CullNone() const; - ID3D11RasterizerState* __cdecl CullClockwise() const; - ID3D11RasterizerState* __cdecl CullCounterClockwise() const; - ID3D11RasterizerState* __cdecl Wireframe() const; + // Rasterizer states. + ID3D11RasterizerState* __cdecl CullNone() const; + ID3D11RasterizerState* __cdecl CullClockwise() const; + ID3D11RasterizerState* __cdecl CullCounterClockwise() const; + ID3D11RasterizerState* __cdecl Wireframe() const; - // Sampler states. - ID3D11SamplerState* __cdecl PointWrap() const; - ID3D11SamplerState* __cdecl PointClamp() const; - ID3D11SamplerState* __cdecl LinearWrap() const; - ID3D11SamplerState* __cdecl LinearClamp() const; - ID3D11SamplerState* __cdecl AnisotropicWrap() const; - ID3D11SamplerState* __cdecl AnisotropicClamp() const; + // Sampler states. + ID3D11SamplerState* __cdecl PointWrap() const; + ID3D11SamplerState* __cdecl PointClamp() const; + ID3D11SamplerState* __cdecl LinearWrap() const; + ID3D11SamplerState* __cdecl LinearClamp() const; + ID3D11SamplerState* __cdecl AnisotropicWrap() const; + ID3D11SamplerState* __cdecl AnisotropicClamp() const; - private: - // Private implementation. - class Impl; + private: + // Private implementation. + class Impl; - std::shared_ptr pImpl; + std::shared_ptr pImpl; - // Prevent copying. - CommonStates(CommonStates const&) DIRECTX_CTOR_DELETE - CommonStates& operator= (CommonStates const&) DIRECTX_CTOR_DELETE - }; + // Prevent copying. + CommonStates(CommonStates const&) DIRECTX_CTOR_DELETE + CommonStates& operator=(CommonStates const&) DIRECTX_CTOR_DELETE + }; } diff --git a/Windows/DirectXTK/DDSTextureLoader.h b/Windows/DirectXTK/DDSTextureLoader.h index e2a40d2..7ed9f3a 100644 --- a/Windows/DirectXTK/DDSTextureLoader.h +++ b/Windows/DirectXTK/DDSTextureLoader.h @@ -33,128 +33,128 @@ namespace DirectX { - enum DDS_ALPHA_MODE - { - DDS_ALPHA_MODE_UNKNOWN = 0, - DDS_ALPHA_MODE_STRAIGHT = 1, - DDS_ALPHA_MODE_PREMULTIPLIED = 2, - DDS_ALPHA_MODE_OPAQUE = 3, - DDS_ALPHA_MODE_CUSTOM = 4, - }; + enum DDS_ALPHA_MODE + { + DDS_ALPHA_MODE_UNKNOWN = 0, + DDS_ALPHA_MODE_STRAIGHT = 1, + DDS_ALPHA_MODE_PREMULTIPLIED = 2, + DDS_ALPHA_MODE_OPAQUE = 3, + DDS_ALPHA_MODE_CUSTOM = 4, + }; - // Standard version - HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice, - _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, - _In_ size_t ddsDataSize, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _In_ size_t maxsize = 0, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr - ); + // Standard version + HRESULT __cdecl CreateDDSTextureFromMemory(_In_ ID3D11Device* d3dDevice, + _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, + _In_ size_t ddsDataSize, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _In_ size_t maxsize = 0, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr + ); - HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice, - _In_z_ const wchar_t* szFileName, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _In_ size_t maxsize = 0, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr - ); + HRESULT __cdecl CreateDDSTextureFromFile(_In_ ID3D11Device* d3dDevice, + _In_z_ const wchar_t* szFileName, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _In_ size_t maxsize = 0, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr + ); - // Standard version with optional auto-gen mipmap support - #if defined(_XBOX_ONE) && defined(_TITLE) + // Standard version with optional auto-gen mipmap support +#if defined(_XBOX_ONE) && defined(_TITLE) HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11DeviceX* d3dDevice, _In_opt_ ID3D11DeviceContextX* d3dContext, - #else - HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice, - _In_opt_ ID3D11DeviceContext* d3dContext, - #endif - _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, - _In_ size_t ddsDataSize, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _In_ size_t maxsize = 0, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr - ); +#else + HRESULT __cdecl CreateDDSTextureFromMemory(_In_ ID3D11Device* d3dDevice, + _In_opt_ ID3D11DeviceContext* d3dContext, +#endif + _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, + _In_ size_t ddsDataSize, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _In_ size_t maxsize = 0, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr + ); - #if defined(_XBOX_ONE) && defined(_TITLE) +#if defined(_XBOX_ONE) && defined(_TITLE) HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11DeviceX* d3dDevice, _In_opt_ ID3D11DeviceContextX* d3dContext, - #else - HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice, - _In_opt_ ID3D11DeviceContext* d3dContext, - #endif - _In_z_ const wchar_t* szFileName, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _In_ size_t maxsize = 0, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr - ); +#else + HRESULT __cdecl CreateDDSTextureFromFile(_In_ ID3D11Device* d3dDevice, + _In_opt_ ID3D11DeviceContext* d3dContext, +#endif + _In_z_ const wchar_t* szFileName, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _In_ size_t maxsize = 0, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr + ); - // Extended version - HRESULT __cdecl CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice, - _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, - _In_ size_t ddsDataSize, - _In_ size_t maxsize, - _In_ D3D11_USAGE usage, - _In_ unsigned int bindFlags, - _In_ unsigned int cpuAccessFlags, - _In_ unsigned int miscFlags, - _In_ bool forceSRGB, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr - ); + // Extended version + HRESULT __cdecl CreateDDSTextureFromMemoryEx(_In_ ID3D11Device* d3dDevice, + _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, + _In_ size_t ddsDataSize, + _In_ size_t maxsize, + _In_ D3D11_USAGE usage, + _In_ unsigned int bindFlags, + _In_ unsigned int cpuAccessFlags, + _In_ unsigned int miscFlags, + _In_ bool forceSRGB, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr + ); - HRESULT __cdecl CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice, - _In_z_ const wchar_t* szFileName, - _In_ size_t maxsize, - _In_ D3D11_USAGE usage, - _In_ unsigned int bindFlags, - _In_ unsigned int cpuAccessFlags, - _In_ unsigned int miscFlags, - _In_ bool forceSRGB, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr - ); + HRESULT __cdecl CreateDDSTextureFromFileEx(_In_ ID3D11Device* d3dDevice, + _In_z_ const wchar_t* szFileName, + _In_ size_t maxsize, + _In_ D3D11_USAGE usage, + _In_ unsigned int bindFlags, + _In_ unsigned int cpuAccessFlags, + _In_ unsigned int miscFlags, + _In_ bool forceSRGB, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr + ); - // Extended version with optional auto-gen mipmap support - #if defined(_XBOX_ONE) && defined(_TITLE) + // Extended version with optional auto-gen mipmap support +#if defined(_XBOX_ONE) && defined(_TITLE) HRESULT __cdecl CreateDDSTextureFromMemoryEx( _In_ ID3D11DeviceX* d3dDevice, _In_opt_ ID3D11DeviceContextX* d3dContext, - #else - HRESULT __cdecl CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice, - _In_opt_ ID3D11DeviceContext* d3dContext, - #endif - _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, - _In_ size_t ddsDataSize, - _In_ size_t maxsize, - _In_ D3D11_USAGE usage, - _In_ unsigned int bindFlags, - _In_ unsigned int cpuAccessFlags, - _In_ unsigned int miscFlags, - _In_ bool forceSRGB, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr - ); +#else + HRESULT __cdecl CreateDDSTextureFromMemoryEx(_In_ ID3D11Device* d3dDevice, + _In_opt_ ID3D11DeviceContext* d3dContext, +#endif + _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, + _In_ size_t ddsDataSize, + _In_ size_t maxsize, + _In_ D3D11_USAGE usage, + _In_ unsigned int bindFlags, + _In_ unsigned int cpuAccessFlags, + _In_ unsigned int miscFlags, + _In_ bool forceSRGB, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr + ); - #if defined(_XBOX_ONE) && defined(_TITLE) +#if defined(_XBOX_ONE) && defined(_TITLE) HRESULT __cdecl CreateDDSTextureFromFileEx( _In_ ID3D11DeviceX* d3dDevice, _In_opt_ ID3D11DeviceContextX* d3dContext, - #else - HRESULT __cdecl CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice, - _In_opt_ ID3D11DeviceContext* d3dContext, - #endif - _In_z_ const wchar_t* szFileName, - _In_ size_t maxsize, - _In_ D3D11_USAGE usage, - _In_ unsigned int bindFlags, - _In_ unsigned int cpuAccessFlags, - _In_ unsigned int miscFlags, - _In_ bool forceSRGB, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr - ); -} \ No newline at end of file +#else + HRESULT __cdecl CreateDDSTextureFromFileEx(_In_ ID3D11Device* d3dDevice, + _In_opt_ ID3D11DeviceContext* d3dContext, +#endif + _In_z_ const wchar_t* szFileName, + _In_ size_t maxsize, + _In_ D3D11_USAGE usage, + _In_ unsigned int bindFlags, + _In_ unsigned int cpuAccessFlags, + _In_ unsigned int miscFlags, + _In_ bool forceSRGB, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr + ); +} diff --git a/Windows/DirectXTK/DirectXHelpers.h b/Windows/DirectXTK/DirectXHelpers.h index 40ce645..e0e481a 100644 --- a/Windows/DirectXTK/DirectXHelpers.h +++ b/Windows/DirectXTK/DirectXHelpers.h @@ -56,95 +56,97 @@ namespace DirectX { - // simliar to std::lock_guard for exception-safe Direct3D 11 resource locking - class MapGuard : public D3D11_MAPPED_SUBRESOURCE - { - public: - MapGuard( _In_ ID3D11DeviceContext* context, - _In_ ID3D11Resource *resource, - _In_ UINT subresource, - _In_ D3D11_MAP mapType, - _In_ UINT mapFlags ) - : mContext(context), mResource(resource), mSubresource(subresource) - { - HRESULT hr = mContext->Map( resource, subresource, mapType, mapFlags, this ); - if (FAILED(hr)) - { - throw std::exception(); - } - } + // simliar to std::lock_guard for exception-safe Direct3D 11 resource locking + class MapGuard : public D3D11_MAPPED_SUBRESOURCE + { + public: + MapGuard(_In_ ID3D11DeviceContext* context, + _In_ ID3D11Resource* resource, + _In_ UINT subresource, + _In_ D3D11_MAP mapType, + _In_ UINT mapFlags) + : mContext(context), mResource(resource), mSubresource(subresource) + { + HRESULT hr = mContext->Map(resource, subresource, mapType, mapFlags, this); + if (FAILED(hr)) + { + throw std::exception(); + } + } - ~MapGuard() - { - mContext->Unmap( mResource, mSubresource ); - } + ~MapGuard() + { + mContext->Unmap(mResource, mSubresource); + } - uint8_t* get() const - { - return reinterpret_cast( pData ); - } - uint8_t* get(size_t slice) const - { - return reinterpret_cast( pData ) + ( slice * DepthPitch ); - } + uint8_t* get() const + { + return reinterpret_cast(pData); + } - uint8_t* scanline(size_t row) const - { - return reinterpret_cast( pData ) + ( row * RowPitch ); - } - uint8_t* scanline(size_t slice, size_t row) const - { - return reinterpret_cast( pData ) + ( slice * DepthPitch ) + ( row * RowPitch ); - } + uint8_t* get(size_t slice) const + { + return reinterpret_cast(pData) + (slice * DepthPitch); + } - private: - ID3D11DeviceContext* mContext; - ID3D11Resource* mResource; - UINT mSubresource; + uint8_t* scanline(size_t row) const + { + return reinterpret_cast(pData) + (row * RowPitch); + } - MapGuard(MapGuard const&); - MapGuard& operator= (MapGuard const&); - }; + uint8_t* scanline(size_t slice, size_t row) const + { + return reinterpret_cast(pData) + (slice * DepthPitch) + (row * RowPitch); + } + + private: + ID3D11DeviceContext* mContext; + ID3D11Resource* mResource; + UINT mSubresource; + + MapGuard(MapGuard const&); + MapGuard& operator=(MapGuard const&); + }; - // Helper sets a D3D resource name string (used by PIX and debug layer leak reporting). - template - inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char (&name)[TNameLength]) - { - #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) - #if defined(_XBOX_ONE) && defined(_TITLE) + // Helper sets a D3D resource name string (used by PIX and debug layer leak reporting). + template + inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char (&name)[TNameLength]) + { +#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) +#if defined(_XBOX_ONE) && defined(_TITLE) WCHAR wname[MAX_PATH]; int result = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, name, TNameLength, wname, MAX_PATH ); if ( result > 0 ) { resource->SetName( wname ); } - #else - resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name); - #endif - #else +#else + resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name); +#endif +#else UNREFERENCED_PARAMETER(resource); UNREFERENCED_PARAMETER(name); - #endif - } +#endif + } - template - inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const wchar_t (&name)[TNameLength]) - { - #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) - #if defined(_XBOX_ONE) && defined(_TITLE) + template + inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const wchar_t (&name)[TNameLength]) + { +#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) +#if defined(_XBOX_ONE) && defined(_TITLE) resource->SetName( name ); - #else - char aname[MAX_PATH]; - int result = WideCharToMultiByte( CP_ACP, 0, name, TNameLength, aname, MAX_PATH, nullptr, nullptr ); - if ( result > 0 ) - { - resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, aname); - } - #endif - #else +#else + char aname[MAX_PATH]; + int result = WideCharToMultiByte(CP_ACP, 0, name, TNameLength, aname, MAX_PATH, nullptr, nullptr); + if (result > 0) + { + resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, aname); + } +#endif +#else UNREFERENCED_PARAMETER(resource); UNREFERENCED_PARAMETER(name); - #endif - } -} \ No newline at end of file +#endif + } +} diff --git a/Windows/DirectXTK/Effects.h b/Windows/DirectXTK/Effects.h index 5c594f2..92d785b 100644 --- a/Windows/DirectXTK/Effects.h +++ b/Windows/DirectXTK/Effects.h @@ -39,574 +39,588 @@ namespace DirectX { - #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) +#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) #define XM_CALLCONV __fastcall typedef const XMVECTOR& HXMVECTOR; typedef const XMMATRIX& FXMMATRIX; - #endif - - //---------------------------------------------------------------------------------- - // Abstract interface representing any effect which can be applied onto a D3D device context. - class IEffect - { - public: - virtual ~IEffect() { } - - virtual void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) = 0; - - virtual void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) = 0; - }; +#endif + + //---------------------------------------------------------------------------------- + // Abstract interface representing any effect which can be applied onto a D3D device context. + class IEffect + { + public: + virtual ~IEffect() + { + } + + virtual void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) = 0; + + virtual void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) = + 0; + }; + + + // Abstract interface for effects with world, view, and projection matrices. + class IEffectMatrices + { + public: + virtual ~IEffectMatrices() + { + } + + virtual void XM_CALLCONV SetWorld(FXMMATRIX value) = 0; + virtual void XM_CALLCONV SetView(FXMMATRIX value) = 0; + virtual void XM_CALLCONV SetProjection(FXMMATRIX value) = 0; + }; + + + // Abstract interface for effects which support directional lighting. + class IEffectLights + { + public: + virtual ~IEffectLights() + { + } + + virtual void __cdecl SetLightingEnabled(bool value) = 0; + virtual void __cdecl SetPerPixelLighting(bool value) = 0; + virtual void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) = 0; + + virtual void __cdecl SetLightEnabled(int whichLight, bool value) = 0; + virtual void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) = 0; + virtual void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) = 0; + virtual void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) = 0; + + virtual void __cdecl EnableDefaultLighting() = 0; + + static const int MaxDirectionalLights = 3; + }; + + + // Abstract interface for effects which support fog. + class IEffectFog + { + public: + virtual ~IEffectFog() + { + } + + virtual void __cdecl SetFogEnabled(bool value) = 0; + virtual void __cdecl SetFogStart(float value) = 0; + virtual void __cdecl SetFogEnd(float value) = 0; + virtual void XM_CALLCONV SetFogColor(FXMVECTOR value) = 0; + }; + + + // Abstract interface for effects which support skinning + class IEffectSkinning + { + public: + virtual ~IEffectSkinning() + { + } + + virtual void __cdecl SetWeightsPerVertex(int value) = 0; + virtual void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) = 0; + virtual void __cdecl ResetBoneTransforms() = 0; + + static const int MaxBones = 72; + }; + + + //---------------------------------------------------------------------------------- + // Built-in shader supports optional texture mapping, vertex coloring, directional lighting, and fog. + class BasicEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog + { + public: + explicit BasicEffect(_In_ ID3D11Device* device); + BasicEffect(BasicEffect&& moveFrom); + BasicEffect& operator=(BasicEffect&& moveFrom); + virtual ~BasicEffect(); + + // IEffect methods. + void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; + + void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; + + // Camera settings. + void XM_CALLCONV SetWorld(FXMMATRIX value) override; + void XM_CALLCONV SetView(FXMMATRIX value) override; + void XM_CALLCONV SetProjection(FXMMATRIX value) override; + + // Material settings. + void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); + void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); + void XM_CALLCONV SetSpecularColor(FXMVECTOR value); + void __cdecl SetSpecularPower(float value); + void __cdecl DisableSpecular(); + void __cdecl SetAlpha(float value); + + // Light settings. + void __cdecl SetLightingEnabled(bool value) override; + void __cdecl SetPerPixelLighting(bool value) override; + void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; + + void __cdecl SetLightEnabled(int whichLight, bool value) override; + void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; + void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; + void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; + + void __cdecl EnableDefaultLighting() override; + + // Fog settings. + void __cdecl SetFogEnabled(bool value) override; + void __cdecl SetFogStart(float value) override; + void __cdecl SetFogEnd(float value) override; + void XM_CALLCONV SetFogColor(FXMVECTOR value) override; + + // Vertex color setting. + void __cdecl SetVertexColorEnabled(bool value); + + // Texture setting. + void __cdecl SetTextureEnabled(bool value); + void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); + + private: + // Private implementation. + class Impl; + + std::unique_ptr pImpl; + + // Prevent copying. + BasicEffect(BasicEffect const&) DIRECTX_CTOR_DELETE + BasicEffect& operator=(BasicEffect const&) DIRECTX_CTOR_DELETE + }; - // Abstract interface for effects with world, view, and projection matrices. - class IEffectMatrices - { - public: - virtual ~IEffectMatrices() { } - - virtual void XM_CALLCONV SetWorld(FXMMATRIX value) = 0; - virtual void XM_CALLCONV SetView(FXMMATRIX value) = 0; - virtual void XM_CALLCONV SetProjection(FXMMATRIX value) = 0; - }; - - - // Abstract interface for effects which support directional lighting. - class IEffectLights - { - public: - virtual ~IEffectLights() { } - - virtual void __cdecl SetLightingEnabled(bool value) = 0; - virtual void __cdecl SetPerPixelLighting(bool value) = 0; - virtual void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) = 0; - - virtual void __cdecl SetLightEnabled(int whichLight, bool value) = 0; - virtual void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) = 0; - virtual void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) = 0; - virtual void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) = 0; + // Built-in shader supports per-pixel alpha testing. + class AlphaTestEffect : public IEffect, public IEffectMatrices, public IEffectFog + { + public: + explicit AlphaTestEffect(_In_ ID3D11Device* device); + AlphaTestEffect(AlphaTestEffect&& moveFrom); + AlphaTestEffect& operator=(AlphaTestEffect&& moveFrom); + virtual ~AlphaTestEffect(); + + // IEffect methods. + void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; + + void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; + + // Camera settings. + void XM_CALLCONV SetWorld(FXMMATRIX value) override; + void XM_CALLCONV SetView(FXMMATRIX value) override; + void XM_CALLCONV SetProjection(FXMMATRIX value) override; + + // Material settings. + void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); + void __cdecl SetAlpha(float value); + + // Fog settings. + void __cdecl SetFogEnabled(bool value) override; + void __cdecl SetFogStart(float value) override; + void __cdecl SetFogEnd(float value) override; + void XM_CALLCONV SetFogColor(FXMVECTOR value) override; + + // Vertex color setting. + void __cdecl SetVertexColorEnabled(bool value); - virtual void __cdecl EnableDefaultLighting() = 0; - - static const int MaxDirectionalLights = 3; - }; - - - // Abstract interface for effects which support fog. - class IEffectFog - { - public: - virtual ~IEffectFog() { } - - virtual void __cdecl SetFogEnabled(bool value) = 0; - virtual void __cdecl SetFogStart(float value) = 0; - virtual void __cdecl SetFogEnd(float value) = 0; - virtual void XM_CALLCONV SetFogColor(FXMVECTOR value) = 0; - }; - - - // Abstract interface for effects which support skinning - class IEffectSkinning - { - public: - virtual ~IEffectSkinning() { } - - virtual void __cdecl SetWeightsPerVertex(int value) = 0; - virtual void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) = 0; - virtual void __cdecl ResetBoneTransforms() = 0; - - static const int MaxBones = 72; - }; - - - //---------------------------------------------------------------------------------- - // Built-in shader supports optional texture mapping, vertex coloring, directional lighting, and fog. - class BasicEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog - { - public: - explicit BasicEffect(_In_ ID3D11Device* device); - BasicEffect(BasicEffect&& moveFrom); - BasicEffect& operator= (BasicEffect&& moveFrom); - virtual ~BasicEffect(); - - // IEffect methods. - void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; - - void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; - - // Camera settings. - void XM_CALLCONV SetWorld(FXMMATRIX value) override; - void XM_CALLCONV SetView(FXMMATRIX value) override; - void XM_CALLCONV SetProjection(FXMMATRIX value) override; - - // Material settings. - void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); - void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); - void XM_CALLCONV SetSpecularColor(FXMVECTOR value); - void __cdecl SetSpecularPower(float value); - void __cdecl DisableSpecular(); - void __cdecl SetAlpha(float value); - - // Light settings. - void __cdecl SetLightingEnabled(bool value) override; - void __cdecl SetPerPixelLighting(bool value) override; - void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; - - void __cdecl SetLightEnabled(int whichLight, bool value) override; - void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; - void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; - void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; - - void __cdecl EnableDefaultLighting() override; - - // Fog settings. - void __cdecl SetFogEnabled(bool value) override; - void __cdecl SetFogStart(float value) override; - void __cdecl SetFogEnd(float value) override; - void XM_CALLCONV SetFogColor(FXMVECTOR value) override; - - // Vertex color setting. - void __cdecl SetVertexColorEnabled(bool value); - - // Texture setting. - void __cdecl SetTextureEnabled(bool value); - void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); - - private: - // Private implementation. - class Impl; - - std::unique_ptr pImpl; - - // Prevent copying. - BasicEffect(BasicEffect const&) DIRECTX_CTOR_DELETE - BasicEffect& operator= (BasicEffect const&) DIRECTX_CTOR_DELETE - }; - - - - // Built-in shader supports per-pixel alpha testing. - class AlphaTestEffect : public IEffect, public IEffectMatrices, public IEffectFog - { - public: - explicit AlphaTestEffect(_In_ ID3D11Device* device); - AlphaTestEffect(AlphaTestEffect&& moveFrom); - AlphaTestEffect& operator= (AlphaTestEffect&& moveFrom); - virtual ~AlphaTestEffect(); - - // IEffect methods. - void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; - - void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; - - // Camera settings. - void XM_CALLCONV SetWorld(FXMMATRIX value) override; - void XM_CALLCONV SetView(FXMMATRIX value) override; - void XM_CALLCONV SetProjection(FXMMATRIX value) override; - - // Material settings. - void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); - void __cdecl SetAlpha(float value); - - // Fog settings. - void __cdecl SetFogEnabled(bool value) override; - void __cdecl SetFogStart(float value) override; - void __cdecl SetFogEnd(float value) override; - void XM_CALLCONV SetFogColor(FXMVECTOR value) override; - - // Vertex color setting. - void __cdecl SetVertexColorEnabled(bool value); - - // Texture setting. - void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); - - // Alpha test settings. - void __cdecl SetAlphaFunction(D3D11_COMPARISON_FUNC value); - void __cdecl SetReferenceAlpha(int value); - - private: - // Private implementation. - class Impl; - - std::unique_ptr pImpl; - - // Prevent copying. - AlphaTestEffect(AlphaTestEffect const&) DIRECTX_CTOR_DELETE - AlphaTestEffect& operator= (AlphaTestEffect const&) DIRECTX_CTOR_DELETE - }; - - - - // Built-in shader supports two layer multitexturing (eg. for lightmaps or detail textures). - class DualTextureEffect : public IEffect, public IEffectMatrices, public IEffectFog - { - public: - explicit DualTextureEffect(_In_ ID3D11Device* device); - DualTextureEffect(DualTextureEffect&& moveFrom); - DualTextureEffect& operator= (DualTextureEffect&& moveFrom); - ~DualTextureEffect(); - - // IEffect methods. - void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; - - void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; - - // Camera settings. - void XM_CALLCONV SetWorld(FXMMATRIX value) override; - void XM_CALLCONV SetView(FXMMATRIX value) override; - void XM_CALLCONV SetProjection(FXMMATRIX value) override; - - // Material settings. - void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); - void __cdecl SetAlpha(float value); - - // Fog settings. - void __cdecl SetFogEnabled(bool value) override; - void __cdecl SetFogStart(float value) override; - void __cdecl SetFogEnd(float value) override; - void XM_CALLCONV SetFogColor(FXMVECTOR value) override; - - // Vertex color setting. - void __cdecl SetVertexColorEnabled(bool value); - - // Texture settings. - void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); - void __cdecl SetTexture2(_In_opt_ ID3D11ShaderResourceView* value); - - private: - // Private implementation. - class Impl; - - std::unique_ptr pImpl; - - // Prevent copying. - DualTextureEffect(DualTextureEffect const&) DIRECTX_CTOR_DELETE - DualTextureEffect& operator= (DualTextureEffect const&) DIRECTX_CTOR_DELETE - }; - - - - // Built-in shader supports cubic environment mapping. - class EnvironmentMapEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog - { - public: - explicit EnvironmentMapEffect(_In_ ID3D11Device* device); - EnvironmentMapEffect(EnvironmentMapEffect&& moveFrom); - EnvironmentMapEffect& operator= (EnvironmentMapEffect&& moveFrom); - virtual ~EnvironmentMapEffect(); - - // IEffect methods. - void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; - - void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; - - // Camera settings. - void XM_CALLCONV SetWorld(FXMMATRIX value) override; - void XM_CALLCONV SetView(FXMMATRIX value) override; - void XM_CALLCONV SetProjection(FXMMATRIX value) override; - - // Material settings. - void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); - void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); - void __cdecl SetAlpha(float value); - - // Light settings. - void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; - - void __cdecl SetLightEnabled(int whichLight, bool value) override; - void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; - void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; - - void __cdecl EnableDefaultLighting() override; - - // Fog settings. - void __cdecl SetFogEnabled(bool value) override; - void __cdecl SetFogStart(float value) override; - void __cdecl SetFogEnd(float value) override; - void XM_CALLCONV SetFogColor(FXMVECTOR value) override; - - // Texture setting. - void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); - - // Environment map settings. - void __cdecl SetEnvironmentMap(_In_opt_ ID3D11ShaderResourceView* value); - void __cdecl SetEnvironmentMapAmount(float value); - void XM_CALLCONV SetEnvironmentMapSpecular(FXMVECTOR value); - void __cdecl SetFresnelFactor(float value); - - private: - // Private implementation. - class Impl; - - std::unique_ptr pImpl; - - // Unsupported interface methods. - void __cdecl SetLightingEnabled(bool value) override; - void __cdecl SetPerPixelLighting(bool value) override; - void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; - - // Prevent copying. - EnvironmentMapEffect(EnvironmentMapEffect const&) DIRECTX_CTOR_DELETE - EnvironmentMapEffect& operator= (EnvironmentMapEffect const&) DIRECTX_CTOR_DELETE - }; - - - - // Built-in shader supports skinned animation. - class SkinnedEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog, public IEffectSkinning - { - public: - explicit SkinnedEffect(_In_ ID3D11Device* device); - SkinnedEffect(SkinnedEffect&& moveFrom); - SkinnedEffect& operator= (SkinnedEffect&& moveFrom); - virtual ~SkinnedEffect(); - - // IEffect methods. - void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; - - void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; - - // Camera settings. - void XM_CALLCONV SetWorld(FXMMATRIX value) override; - void XM_CALLCONV SetView(FXMMATRIX value) override; - void XM_CALLCONV SetProjection(FXMMATRIX value) override; - - // Material settings. - void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); - void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); - void XM_CALLCONV SetSpecularColor(FXMVECTOR value); - void __cdecl SetSpecularPower(float value); - void __cdecl DisableSpecular(); - void __cdecl SetAlpha(float value); - - // Light settings. - void __cdecl SetPerPixelLighting(bool value) override; - void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; - - void __cdecl SetLightEnabled(int whichLight, bool value) override; - void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; - void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; - void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; - - void __cdecl EnableDefaultLighting() override; - - // Fog settings. - void __cdecl SetFogEnabled(bool value) override; - void __cdecl SetFogStart(float value) override; - void __cdecl SetFogEnd(float value) override; - void XM_CALLCONV SetFogColor(FXMVECTOR value) override; - - // Texture setting. - void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); - - // Animation settings. - void __cdecl SetWeightsPerVertex(int value) override; - void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override; - void __cdecl ResetBoneTransforms() override; - - private: - // Private implementation. - class Impl; - - std::unique_ptr pImpl; - - // Unsupported interface method. - void __cdecl SetLightingEnabled(bool value) override; - - // Prevent copying. - SkinnedEffect(SkinnedEffect const&) DIRECTX_CTOR_DELETE - SkinnedEffect& operator= (SkinnedEffect const&) DIRECTX_CTOR_DELETE - }; - - - - //---------------------------------------------------------------------------------- - // Built-in effect for Visual Studio Shader Designer (DGSL) shaders - class DGSLEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectSkinning - { - public: - explicit DGSLEffect( _In_ ID3D11Device* device, _In_opt_ ID3D11PixelShader* pixelShader = nullptr, - _In_ bool enableSkinning = false ); - DGSLEffect(DGSLEffect&& moveFrom); - DGSLEffect& operator= (DGSLEffect&& moveFrom); - virtual ~DGSLEffect(); - - // IEffect methods. - void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; - - void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; - - // Camera settings. - void XM_CALLCONV SetWorld(FXMMATRIX value) override; - void XM_CALLCONV SetView(FXMMATRIX value) override; - void XM_CALLCONV SetProjection(FXMMATRIX value) override; - - // Material settings. - void XM_CALLCONV SetAmbientColor(FXMVECTOR value); - void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); - void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); - void XM_CALLCONV SetSpecularColor(FXMVECTOR value); - void __cdecl SetSpecularPower(float value); - void __cdecl DisableSpecular(); - void __cdecl SetAlpha(float value); - - // Additional settings. - void XM_CALLCONV SetUVTransform(FXMMATRIX value); - void __cdecl SetViewport( float width, float height ); - void __cdecl SetTime( float time ); - void __cdecl SetAlphaDiscardEnable(bool value); - - // Light settings. - void __cdecl SetLightingEnabled(bool value) override; - void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; - - void __cdecl SetLightEnabled(int whichLight, bool value) override; - void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; - void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; - void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; - - void __cdecl EnableDefaultLighting() override; - - static const int MaxDirectionalLights = 4; - - // Vertex color setting. - void __cdecl SetVertexColorEnabled(bool value); - - // Texture settings. - void __cdecl SetTextureEnabled(bool value); - void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); - void __cdecl SetTexture2(_In_opt_ ID3D11ShaderResourceView* value); - void __cdecl SetTexture(int whichTexture, _In_opt_ ID3D11ShaderResourceView* value); - - static const int MaxTextures = 8; - - // Animation setting. - void __cdecl SetWeightsPerVertex(int value) override; - void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override; - void __cdecl ResetBoneTransforms() override; - - private: - // Private implementation. - class Impl; - - std::unique_ptr pImpl; - - // Unsupported interface methods. - void __cdecl SetPerPixelLighting(bool value) override; - - // Prevent copying. - DGSLEffect(DGSLEffect const&) DIRECTX_CTOR_DELETE - DGSLEffect& operator= (DGSLEffect const&) DIRECTX_CTOR_DELETE - }; + // Texture setting. + void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); + + // Alpha test settings. + void __cdecl SetAlphaFunction(D3D11_COMPARISON_FUNC value); + void __cdecl SetReferenceAlpha(int value); + + private: + // Private implementation. + class Impl; + std::unique_ptr pImpl; + // Prevent copying. + AlphaTestEffect(AlphaTestEffect const&) DIRECTX_CTOR_DELETE + AlphaTestEffect& operator=(AlphaTestEffect const&) DIRECTX_CTOR_DELETE + }; + + + // Built-in shader supports two layer multitexturing (eg. for lightmaps or detail textures). + class DualTextureEffect : public IEffect, public IEffectMatrices, public IEffectFog + { + public: + explicit DualTextureEffect(_In_ ID3D11Device* device); + DualTextureEffect(DualTextureEffect&& moveFrom); + DualTextureEffect& operator=(DualTextureEffect&& moveFrom); + ~DualTextureEffect(); - //---------------------------------------------------------------------------------- - // Abstract interface to factory for sharing effects and texture resources - class IEffectFactory - { - public: - virtual ~IEffectFactory() {} + // IEffect methods. + void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; - struct EffectInfo - { - const WCHAR* name; - bool perVertexColor; - bool enableSkinning; - bool enableDualTexture; - float specularPower; - float alpha; - DirectX::XMFLOAT3 ambientColor; - DirectX::XMFLOAT3 diffuseColor; - DirectX::XMFLOAT3 specularColor; - DirectX::XMFLOAT3 emissiveColor; - const WCHAR* texture; - const WCHAR* texture2; + void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; - EffectInfo() { memset( this, 0, sizeof(EffectInfo) ); }; - }; + // Camera settings. + void XM_CALLCONV SetWorld(FXMMATRIX value) override; + void XM_CALLCONV SetView(FXMMATRIX value) override; + void XM_CALLCONV SetProjection(FXMMATRIX value) override; - virtual std::shared_ptr __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) = 0; + // Material settings. + void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); + void __cdecl SetAlpha(float value); - virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) = 0; - }; + // Fog settings. + void __cdecl SetFogEnabled(bool value) override; + void __cdecl SetFogStart(float value) override; + void __cdecl SetFogEnd(float value) override; + void XM_CALLCONV SetFogColor(FXMVECTOR value) override; + // Vertex color setting. + void __cdecl SetVertexColorEnabled(bool value); - // Factory for sharing effects and texture resources - class EffectFactory : public IEffectFactory - { - public: - explicit EffectFactory(_In_ ID3D11Device* device); - EffectFactory(EffectFactory&& moveFrom); - EffectFactory& operator= (EffectFactory&& moveFrom); - virtual ~EffectFactory(); + // Texture settings. + void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); + void __cdecl SetTexture2(_In_opt_ ID3D11ShaderResourceView* value); - // IEffectFactory methods. - virtual std::shared_ptr __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override; - virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override; + private: + // Private implementation. + class Impl; + + std::unique_ptr pImpl; + + // Prevent copying. + DualTextureEffect(DualTextureEffect const&) DIRECTX_CTOR_DELETE + DualTextureEffect& operator=(DualTextureEffect const&) DIRECTX_CTOR_DELETE + }; + + + // Built-in shader supports cubic environment mapping. + class EnvironmentMapEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog + { + public: + explicit EnvironmentMapEffect(_In_ ID3D11Device* device); + EnvironmentMapEffect(EnvironmentMapEffect&& moveFrom); + EnvironmentMapEffect& operator=(EnvironmentMapEffect&& moveFrom); + virtual ~EnvironmentMapEffect(); + + // IEffect methods. + void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; + + void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; + + // Camera settings. + void XM_CALLCONV SetWorld(FXMMATRIX value) override; + void XM_CALLCONV SetView(FXMMATRIX value) override; + void XM_CALLCONV SetProjection(FXMMATRIX value) override; + + // Material settings. + void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); + void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); + void __cdecl SetAlpha(float value); - // Settings. - void __cdecl ReleaseCache(); + // Light settings. + void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; - void __cdecl SetSharing( bool enabled ); + void __cdecl SetLightEnabled(int whichLight, bool value) override; + void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; + void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; + + void __cdecl EnableDefaultLighting() override; - void __cdecl SetDirectory( _In_opt_z_ const WCHAR* path ); + // Fog settings. + void __cdecl SetFogEnabled(bool value) override; + void __cdecl SetFogStart(float value) override; + void __cdecl SetFogEnd(float value) override; + void XM_CALLCONV SetFogColor(FXMVECTOR value) override; + + // Texture setting. + void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); + + // Environment map settings. + void __cdecl SetEnvironmentMap(_In_opt_ ID3D11ShaderResourceView* value); + void __cdecl SetEnvironmentMapAmount(float value); + void XM_CALLCONV SetEnvironmentMapSpecular(FXMVECTOR value); + void __cdecl SetFresnelFactor(float value); + + private: + // Private implementation. + class Impl; + + std::unique_ptr pImpl; + + // Unsupported interface methods. + void __cdecl SetLightingEnabled(bool value) override; + void __cdecl SetPerPixelLighting(bool value) override; + void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; + + // Prevent copying. + EnvironmentMapEffect(EnvironmentMapEffect const&) DIRECTX_CTOR_DELETE + EnvironmentMapEffect& operator=(EnvironmentMapEffect const&) DIRECTX_CTOR_DELETE + }; + + + // Built-in shader supports skinned animation. + class SkinnedEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog, + public IEffectSkinning + { + public: + explicit SkinnedEffect(_In_ ID3D11Device* device); + SkinnedEffect(SkinnedEffect&& moveFrom); + SkinnedEffect& operator=(SkinnedEffect&& moveFrom); + virtual ~SkinnedEffect(); + + // IEffect methods. + void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; + + void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; + + // Camera settings. + void XM_CALLCONV SetWorld(FXMMATRIX value) override; + void XM_CALLCONV SetView(FXMMATRIX value) override; + void XM_CALLCONV SetProjection(FXMMATRIX value) override; + + // Material settings. + void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); + void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); + void XM_CALLCONV SetSpecularColor(FXMVECTOR value); + void __cdecl SetSpecularPower(float value); + void __cdecl DisableSpecular(); + void __cdecl SetAlpha(float value); + + // Light settings. + void __cdecl SetPerPixelLighting(bool value) override; + void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; + + void __cdecl SetLightEnabled(int whichLight, bool value) override; + void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; + void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; + void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; + + void __cdecl EnableDefaultLighting() override; + + // Fog settings. + void __cdecl SetFogEnabled(bool value) override; + void __cdecl SetFogStart(float value) override; + void __cdecl SetFogEnd(float value) override; + void XM_CALLCONV SetFogColor(FXMVECTOR value) override; + + // Texture setting. + void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); + + // Animation settings. + void __cdecl SetWeightsPerVertex(int value) override; + void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override; + void __cdecl ResetBoneTransforms() override; + + private: + // Private implementation. + class Impl; + + std::unique_ptr pImpl; + + // Unsupported interface method. + void __cdecl SetLightingEnabled(bool value) override; + + // Prevent copying. + SkinnedEffect(SkinnedEffect const&) DIRECTX_CTOR_DELETE + SkinnedEffect& operator=(SkinnedEffect const&) DIRECTX_CTOR_DELETE + }; + + + //---------------------------------------------------------------------------------- + // Built-in effect for Visual Studio Shader Designer (DGSL) shaders + class DGSLEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectSkinning + { + public: + explicit DGSLEffect(_In_ ID3D11Device* device, _In_opt_ ID3D11PixelShader* pixelShader = nullptr, + _In_ bool enableSkinning = false); + DGSLEffect(DGSLEffect&& moveFrom); + DGSLEffect& operator=(DGSLEffect&& moveFrom); + virtual ~DGSLEffect(); + + // IEffect methods. + void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; + + void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; + + // Camera settings. + void XM_CALLCONV SetWorld(FXMMATRIX value) override; + void XM_CALLCONV SetView(FXMMATRIX value) override; + void XM_CALLCONV SetProjection(FXMMATRIX value) override; + + // Material settings. + void XM_CALLCONV SetAmbientColor(FXMVECTOR value); + void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); + void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); + void XM_CALLCONV SetSpecularColor(FXMVECTOR value); + void __cdecl SetSpecularPower(float value); + void __cdecl DisableSpecular(); + void __cdecl SetAlpha(float value); + + // Additional settings. + void XM_CALLCONV SetUVTransform(FXMMATRIX value); + void __cdecl SetViewport(float width, float height); + void __cdecl SetTime(float time); + void __cdecl SetAlphaDiscardEnable(bool value); + + // Light settings. + void __cdecl SetLightingEnabled(bool value) override; + void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; + + void __cdecl SetLightEnabled(int whichLight, bool value) override; + void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; + void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; + void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; + + void __cdecl EnableDefaultLighting() override; + + static const int MaxDirectionalLights = 4; + + // Vertex color setting. + void __cdecl SetVertexColorEnabled(bool value); + + // Texture settings. + void __cdecl SetTextureEnabled(bool value); + void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); + void __cdecl SetTexture2(_In_opt_ ID3D11ShaderResourceView* value); + void __cdecl SetTexture(int whichTexture, _In_opt_ ID3D11ShaderResourceView* value); + + static const int MaxTextures = 8; + + // Animation setting. + void __cdecl SetWeightsPerVertex(int value) override; + void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override; + void __cdecl ResetBoneTransforms() override; + + private: + // Private implementation. + class Impl; + + std::unique_ptr pImpl; + + // Unsupported interface methods. + void __cdecl SetPerPixelLighting(bool value) override; + + // Prevent copying. + DGSLEffect(DGSLEffect const&) DIRECTX_CTOR_DELETE + DGSLEffect& operator=(DGSLEffect const&) DIRECTX_CTOR_DELETE + }; + + + //---------------------------------------------------------------------------------- + // Abstract interface to factory for sharing effects and texture resources + class IEffectFactory + { + public: + virtual ~IEffectFactory() + { + } + + struct EffectInfo + { + const WCHAR* name; + bool perVertexColor; + bool enableSkinning; + bool enableDualTexture; + float specularPower; + float alpha; + DirectX::XMFLOAT3 ambientColor; + DirectX::XMFLOAT3 diffuseColor; + DirectX::XMFLOAT3 specularColor; + DirectX::XMFLOAT3 emissiveColor; + const WCHAR* texture; + const WCHAR* texture2; + + EffectInfo() { memset(this, 0, sizeof(EffectInfo)); }; + }; + + virtual std::shared_ptr __cdecl CreateEffect(_In_ const EffectInfo& info, + _In_opt_ ID3D11DeviceContext* deviceContext) = 0; + + virtual void __cdecl CreateTexture(_In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, + _Outptr_ ID3D11ShaderResourceView** textureView) = 0; + }; + + + // Factory for sharing effects and texture resources + class EffectFactory : public IEffectFactory + { + public: + explicit EffectFactory(_In_ ID3D11Device* device); + EffectFactory(EffectFactory&& moveFrom); + EffectFactory& operator=(EffectFactory&& moveFrom); + virtual ~EffectFactory(); + + // IEffectFactory methods. + virtual std::shared_ptr __cdecl CreateEffect(_In_ const EffectInfo& info, + _In_opt_ ID3D11DeviceContext* deviceContext) override; + virtual void __cdecl CreateTexture(_In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, + _Outptr_ ID3D11ShaderResourceView** textureView) override; - private: - // Private implementation. - class Impl; + // Settings. + void __cdecl ReleaseCache(); - std::shared_ptr pImpl; + void __cdecl SetSharing(bool enabled); - // Prevent copying. - EffectFactory(EffectFactory const&) DIRECTX_CTOR_DELETE - EffectFactory& operator= (EffectFactory const&) DIRECTX_CTOR_DELETE - }; + void __cdecl SetDirectory(_In_opt_z_ const WCHAR* path); + private: + // Private implementation. + class Impl; - // Factory for sharing Visual Studio Shader Designer (DGSL) shaders and texture resources - class DGSLEffectFactory : public IEffectFactory - { - public: - explicit DGSLEffectFactory(_In_ ID3D11Device* device); - DGSLEffectFactory(DGSLEffectFactory&& moveFrom); - DGSLEffectFactory& operator= (DGSLEffectFactory&& moveFrom); - virtual ~DGSLEffectFactory(); + std::shared_ptr pImpl; + + // Prevent copying. + EffectFactory(EffectFactory const&) DIRECTX_CTOR_DELETE + EffectFactory& operator=(EffectFactory const&) DIRECTX_CTOR_DELETE + }; - // IEffectFactory methods. - virtual std::shared_ptr __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override; - virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override; - // DGSL methods. - struct DGSLEffectInfo : public EffectInfo - { - const WCHAR* textures[6]; - const WCHAR* pixelShader; + // Factory for sharing Visual Studio Shader Designer (DGSL) shaders and texture resources + class DGSLEffectFactory : public IEffectFactory + { + public: + explicit DGSLEffectFactory(_In_ ID3D11Device* device); + DGSLEffectFactory(DGSLEffectFactory&& moveFrom); + DGSLEffectFactory& operator=(DGSLEffectFactory&& moveFrom); + virtual ~DGSLEffectFactory(); - DGSLEffectInfo() { memset( this, 0, sizeof(DGSLEffectInfo) ); }; - }; - - virtual std::shared_ptr __cdecl CreateDGSLEffect( _In_ const DGSLEffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ); - - virtual void __cdecl CreatePixelShader( _In_z_ const WCHAR* shader, _Outptr_ ID3D11PixelShader** pixelShader ); - - // Settings. - void __cdecl ReleaseCache(); - - void __cdecl SetSharing( bool enabled ); - - void __cdecl SetDirectory( _In_opt_z_ const WCHAR* path ); - - private: - // Private implementation. - class Impl; - - std::shared_ptr pImpl; - - // Prevent copying. - DGSLEffectFactory(DGSLEffectFactory const&) DIRECTX_CTOR_DELETE - DGSLEffectFactory& operator= (DGSLEffectFactory const&) DIRECTX_CTOR_DELETE - }; + // IEffectFactory methods. + virtual std::shared_ptr __cdecl CreateEffect(_In_ const EffectInfo& info, + _In_opt_ ID3D11DeviceContext* deviceContext) override; + virtual void __cdecl CreateTexture(_In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, + _Outptr_ ID3D11ShaderResourceView** textureView) override; + + // DGSL methods. + struct DGSLEffectInfo : public EffectInfo + { + const WCHAR* textures[6]; + const WCHAR* pixelShader; + + DGSLEffectInfo() { memset(this, 0, sizeof(DGSLEffectInfo)); }; + }; + + virtual std::shared_ptr __cdecl CreateDGSLEffect(_In_ const DGSLEffectInfo& info, + _In_opt_ ID3D11DeviceContext* deviceContext); + + virtual void __cdecl CreatePixelShader(_In_z_ const WCHAR* shader, _Outptr_ ID3D11PixelShader** pixelShader); + + // Settings. + void __cdecl ReleaseCache(); + + void __cdecl SetSharing(bool enabled); + + void __cdecl SetDirectory(_In_opt_z_ const WCHAR* path); + + private: + // Private implementation. + class Impl; + std::shared_ptr pImpl; + + // Prevent copying. + DGSLEffectFactory(DGSLEffectFactory const&) DIRECTX_CTOR_DELETE + DGSLEffectFactory& operator=(DGSLEffectFactory const&) DIRECTX_CTOR_DELETE + }; } #pragma warning(pop) diff --git a/Windows/DirectXTK/GeometricPrimitive.h b/Windows/DirectXTK/GeometricPrimitive.h index 6e0584e..0637a50 100644 --- a/Windows/DirectXTK/GeometricPrimitive.h +++ b/Windows/DirectXTK/GeometricPrimitive.h @@ -43,68 +43,107 @@ namespace DirectX { - #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) +#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) #define XM_CALLCONV __fastcall typedef const XMVECTOR& HXMVECTOR; typedef const XMMATRIX& FXMMATRIX; - #endif +#endif - class IEffect; + class IEffect; - class GeometricPrimitive - { - public: - virtual ~GeometricPrimitive(); - - // Factory methods. - static std::unique_ptr __cdecl CreateCube (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); - static std::unique_ptr __cdecl CreateBox (_In_ ID3D11DeviceContext* deviceContext, const XMFLOAT3& size, bool rhcoords = true, bool invertn = false); - static std::unique_ptr __cdecl CreateSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, bool invertn = false); - static std::unique_ptr __cdecl CreateGeoSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 3, bool rhcoords = true); - static std::unique_ptr __cdecl CreateCylinder (_In_ ID3D11DeviceContext* deviceContext, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true); - static std::unique_ptr __cdecl CreateCone (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true); - static std::unique_ptr __cdecl CreateTorus (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true); - static std::unique_ptr __cdecl CreateTetrahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); - static std::unique_ptr __cdecl CreateOctahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); - static std::unique_ptr __cdecl CreateDodecahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); - static std::unique_ptr __cdecl CreateIcosahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); - static std::unique_ptr __cdecl CreateTeapot (_In_ ID3D11DeviceContext* deviceContext, float size = 1, size_t tessellation = 8, bool rhcoords = true); - static std::unique_ptr __cdecl CreateCustom (_In_ ID3D11DeviceContext* deviceContext, const std::vector& vertices, const std::vector& indices); + class GeometricPrimitive + { + public: + virtual ~GeometricPrimitive(); - static void __cdecl CreateCube (std::vector& vertices, std::vector& indices, float size = 1, bool rhcoords = true); - static void __cdecl CreateBox (std::vector& vertices, std::vector& indices, const XMFLOAT3& size, bool rhcoords = true, bool invertn = false); - static void __cdecl CreateSphere (std::vector& vertices, std::vector& indices, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, bool invertn = false); - static void __cdecl CreateGeoSphere (std::vector& vertices, std::vector& indices, float diameter = 1, size_t tessellation = 3, bool rhcoords = true); - static void __cdecl CreateCylinder (std::vector& vertices, std::vector& indices, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true); - static void __cdecl CreateCone (std::vector& vertices, std::vector& indices, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true); - static void __cdecl CreateTorus (std::vector& vertices, std::vector& indices, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true); - static void __cdecl CreateTetrahedron (std::vector& vertices, std::vector& indices, float size = 1, bool rhcoords = true); - static void __cdecl CreateOctahedron (std::vector& vertices, std::vector& indices, float size = 1, bool rhcoords = true); - static void __cdecl CreateDodecahedron (std::vector& vertices, std::vector& indices, float size = 1, bool rhcoords = true); - static void __cdecl CreateIcosahedron (std::vector& vertices, std::vector& indices, float size = 1, bool rhcoords = true); - static void __cdecl CreateTeapot (std::vector& vertices, std::vector& indices, float size = 1, size_t tessellation = 8, bool rhcoords = true); + // Factory methods. + static std::unique_ptr __cdecl CreateCube( + _In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); + static std::unique_ptr __cdecl CreateBox(_In_ ID3D11DeviceContext* deviceContext, + const XMFLOAT3& size, bool rhcoords = true, + bool invertn = false); + static std::unique_ptr __cdecl CreateSphere( + _In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, + bool invertn = false); + static std::unique_ptr __cdecl CreateGeoSphere( + _In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 3, bool rhcoords = true); + static std::unique_ptr __cdecl CreateCylinder( + _In_ ID3D11DeviceContext* deviceContext, float height = 1, float diameter = 1, size_t tessellation = 32, + bool rhcoords = true); + static std::unique_ptr __cdecl CreateCone( + _In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float height = 1, size_t tessellation = 32, + bool rhcoords = true); + static std::unique_ptr __cdecl CreateTorus( + _In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float thickness = 0.333f, + size_t tessellation = 32, bool rhcoords = true); + static std::unique_ptr __cdecl CreateTetrahedron( + _In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); + static std::unique_ptr __cdecl CreateOctahedron( + _In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); + static std::unique_ptr __cdecl CreateDodecahedron( + _In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); + static std::unique_ptr __cdecl CreateIcosahedron( + _In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); + static std::unique_ptr __cdecl CreateTeapot( + _In_ ID3D11DeviceContext* deviceContext, float size = 1, size_t tessellation = 8, bool rhcoords = true); + static std::unique_ptr __cdecl CreateCustom( + _In_ ID3D11DeviceContext* deviceContext, const std::vector& vertices, + const std::vector& indices); - // Draw the primitive. - void XM_CALLCONV Draw(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, FXMVECTOR color = Colors::White, _In_opt_ ID3D11ShaderResourceView* texture = nullptr, bool wireframe = false, - _In_opt_ std::function setCustomState = nullptr ); + static void __cdecl CreateCube(std::vector& vertices, std::vector& indices, + float size = 1, bool rhcoords = true); + static void __cdecl CreateBox(std::vector& vertices, std::vector& indices, + const XMFLOAT3& size, bool rhcoords = true, bool invertn = false); + static void __cdecl CreateSphere(std::vector& vertices, + std::vector& indices, float diameter = 1, size_t tessellation = 16, + bool rhcoords = true, bool invertn = false); + static void __cdecl CreateGeoSphere(std::vector& vertices, + std::vector& indices, float diameter = 1, size_t tessellation = 3, + bool rhcoords = true); + static void __cdecl CreateCylinder(std::vector& vertices, + std::vector& indices, float height = 1, float diameter = 1, + size_t tessellation = 32, bool rhcoords = true); + static void __cdecl CreateCone(std::vector& vertices, std::vector& indices, + float diameter = 1, float height = 1, size_t tessellation = 32, + bool rhcoords = true); + static void __cdecl CreateTorus(std::vector& vertices, + std::vector& indices, float diameter = 1, float thickness = 0.333f, + size_t tessellation = 32, bool rhcoords = true); + static void __cdecl CreateTetrahedron(std::vector& vertices, + std::vector& indices, float size = 1, bool rhcoords = true); + static void __cdecl CreateOctahedron(std::vector& vertices, + std::vector& indices, float size = 1, bool rhcoords = true); + static void __cdecl CreateDodecahedron(std::vector& vertices, + std::vector& indices, float size = 1, bool rhcoords = true); + static void __cdecl CreateIcosahedron(std::vector& vertices, + std::vector& indices, float size = 1, bool rhcoords = true); + static void __cdecl CreateTeapot(std::vector& vertices, + std::vector& indices, float size = 1, size_t tessellation = 8, + bool rhcoords = true); - // Draw the primitive using a custom effect. - void __cdecl Draw( _In_ IEffect* effect, _In_ ID3D11InputLayout* inputLayout, bool alpha = false, bool wireframe = false, - _In_opt_ std::function setCustomState = nullptr ); + // Draw the primitive. + void XM_CALLCONV Draw(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, FXMVECTOR color = Colors::White, + _In_opt_ ID3D11ShaderResourceView* texture = nullptr, bool wireframe = false, + _In_opt_ std::function setCustomState = nullptr); - // Create input layout for drawing with a custom effect. - void __cdecl CreateInputLayout( _In_ IEffect* effect, _Outptr_ ID3D11InputLayout** inputLayout ); - - private: - GeometricPrimitive(); + // Draw the primitive using a custom effect. + void __cdecl Draw(_In_ IEffect* effect, _In_ ID3D11InputLayout* inputLayout, bool alpha = false, + bool wireframe = false, + _In_opt_ std::function setCustomState = nullptr); - // Private implementation. - class Impl; + // Create input layout for drawing with a custom effect. + void __cdecl CreateInputLayout(_In_ IEffect* effect, _Outptr_ ID3D11InputLayout** inputLayout); - std::unique_ptr pImpl; + private: + GeometricPrimitive(); - // Prevent copying. - GeometricPrimitive(GeometricPrimitive const&) DIRECTX_CTOR_DELETE - GeometricPrimitive& operator= (GeometricPrimitive const&) DIRECTX_CTOR_DELETE - }; + // Private implementation. + class Impl; + + std::unique_ptr pImpl; + + // Prevent copying. + GeometricPrimitive(GeometricPrimitive const&) DIRECTX_CTOR_DELETE + GeometricPrimitive& operator=(GeometricPrimitive const&) DIRECTX_CTOR_DELETE + }; } diff --git a/Windows/DirectXTK/Model.h b/Windows/DirectXTK/Model.h index 75fd90f..153cbcd 100644 --- a/Windows/DirectXTK/Model.h +++ b/Windows/DirectXTK/Model.h @@ -47,117 +47,140 @@ namespace DirectX { - #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) +#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) #define XM_CALLCONV __fastcall typedef const XMVECTOR& HXMVECTOR; typedef const XMMATRIX& FXMMATRIX; - #endif +#endif - class IEffect; - class IEffectFactory; - class CommonStates; - class ModelMesh; + class IEffect; + class IEffectFactory; + class CommonStates; + class ModelMesh; - //---------------------------------------------------------------------------------- - // Each mesh part is a submesh with a single effect - class ModelMeshPart - { - public: - ModelMeshPart(); - virtual ~ModelMeshPart(); + //---------------------------------------------------------------------------------- + // Each mesh part is a submesh with a single effect + class ModelMeshPart + { + public: + ModelMeshPart(); + virtual ~ModelMeshPart(); - uint32_t indexCount; - uint32_t startIndex; - uint32_t vertexOffset; - uint32_t vertexStride; - D3D_PRIMITIVE_TOPOLOGY primitiveType; - DXGI_FORMAT indexFormat; - Microsoft::WRL::ComPtr inputLayout; - Microsoft::WRL::ComPtr indexBuffer; - Microsoft::WRL::ComPtr vertexBuffer; - std::shared_ptr effect; - std::shared_ptr> vbDecl; - bool isAlpha; + uint32_t indexCount; + uint32_t startIndex; + uint32_t vertexOffset; + uint32_t vertexStride; + D3D_PRIMITIVE_TOPOLOGY primitiveType; + DXGI_FORMAT indexFormat; + Microsoft::WRL::ComPtr inputLayout; + Microsoft::WRL::ComPtr indexBuffer; + Microsoft::WRL::ComPtr vertexBuffer; + std::shared_ptr effect; + std::shared_ptr> vbDecl; + bool isAlpha; - typedef std::vector> Collection; + typedef std::vector> Collection; - // Draw mesh part with custom effect - void __cdecl Draw( _In_ ID3D11DeviceContext* deviceContext, _In_ IEffect* ieffect, _In_ ID3D11InputLayout* iinputLayout, - _In_opt_ std::function setCustomState = nullptr ) const; + // Draw mesh part with custom effect + void __cdecl Draw(_In_ ID3D11DeviceContext* deviceContext, _In_ IEffect* ieffect, + _In_ ID3D11InputLayout* iinputLayout, + _In_opt_ std::function setCustomState = nullptr) const; - // Create input layout for drawing with a custom effect. - void __cdecl CreateInputLayout( _In_ ID3D11Device* d3dDevice, _In_ IEffect* ieffect, _Outptr_ ID3D11InputLayout** iinputLayout ); + // Create input layout for drawing with a custom effect. + void __cdecl CreateInputLayout(_In_ ID3D11Device* d3dDevice, _In_ IEffect* ieffect, + _Outptr_ ID3D11InputLayout** iinputLayout); - // Change effect used by part and regenerate input layout (be sure to call Model::Modified as well) - void __cdecl ModifyEffect( _In_ ID3D11Device* d3dDevice, _In_ std::shared_ptr& ieffect, bool isalpha = false ); - }; + // Change effect used by part and regenerate input layout (be sure to call Model::Modified as well) + void __cdecl ModifyEffect(_In_ ID3D11Device* d3dDevice, _In_ std::shared_ptr& ieffect, + bool isalpha = false); + }; - //---------------------------------------------------------------------------------- - // A mesh consists of one or more model mesh parts - class ModelMesh - { - public: - ModelMesh(); - virtual ~ModelMesh(); + //---------------------------------------------------------------------------------- + // A mesh consists of one or more model mesh parts + class ModelMesh + { + public: + ModelMesh(); + virtual ~ModelMesh(); - BoundingSphere boundingSphere; - BoundingBox boundingBox; - ModelMeshPart::Collection meshParts; - std::wstring name; - bool ccw; - bool pmalpha; + BoundingSphere boundingSphere; + BoundingBox boundingBox; + ModelMeshPart::Collection meshParts; + std::wstring name; + bool ccw; + bool pmalpha; - typedef std::vector> Collection; + typedef std::vector> Collection; - // Setup states for drawing mesh - void __cdecl PrepareForRendering( _In_ ID3D11DeviceContext* deviceContext, CommonStates& states, bool alpha = false, bool wireframe = false ) const; + // Setup states for drawing mesh + void __cdecl PrepareForRendering(_In_ ID3D11DeviceContext* deviceContext, CommonStates& states, + bool alpha = false, bool wireframe = false) const; - // Draw the mesh - void XM_CALLCONV Draw( _In_ ID3D11DeviceContext* deviceContext, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, - bool alpha = false, _In_opt_ std::function setCustomState = nullptr ) const; - }; + // Draw the mesh + void XM_CALLCONV Draw(_In_ ID3D11DeviceContext* deviceContext, FXMMATRIX world, CXMMATRIX view, + CXMMATRIX projection, + bool alpha = false, + _In_opt_ std::function setCustomState = nullptr) const; + }; - //---------------------------------------------------------------------------------- - // A model consists of one or more meshes - class Model - { - public: - virtual ~Model(); + //---------------------------------------------------------------------------------- + // A model consists of one or more meshes + class Model + { + public: + virtual ~Model(); - ModelMesh::Collection meshes; - std::wstring name; + ModelMesh::Collection meshes; + std::wstring name; - // Draw all the meshes in the model - void XM_CALLCONV Draw( _In_ ID3D11DeviceContext* deviceContext, CommonStates& states, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, - bool wireframe = false, _In_opt_ std::function setCustomState = nullptr ) const; + // Draw all the meshes in the model + void XM_CALLCONV Draw(_In_ ID3D11DeviceContext* deviceContext, CommonStates& states, FXMMATRIX world, + CXMMATRIX view, CXMMATRIX projection, + bool wireframe = false, + _In_opt_ std::function setCustomState = nullptr) const; - // Notify model that effects, parts list, or mesh list has changed - void __cdecl Modified() { mEffectCache.clear(); } + // Notify model that effects, parts list, or mesh list has changed + void __cdecl Modified() { mEffectCache.clear(); } - // Update all effects used by the model - void __cdecl UpdateEffects( _In_ std::function setEffect ); + // Update all effects used by the model + void __cdecl UpdateEffects(_In_ std::function setEffect); - // Loads a model from a Visual Studio Starter Kit .CMO file - static std::unique_ptr __cdecl CreateFromCMO( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, size_t dataSize, - _In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false ); - static std::unique_ptr __cdecl CreateFromCMO( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName, - _In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false ); + // Loads a model from a Visual Studio Starter Kit .CMO file + static std::unique_ptr __cdecl CreateFromCMO(_In_ ID3D11Device* d3dDevice, + _In_reads_bytes_(dataSize) const uint8_t* meshData, + size_t dataSize, + _In_ IEffectFactory& fxFactory, bool ccw = true, + bool pmalpha = false); + static std::unique_ptr __cdecl CreateFromCMO(_In_ ID3D11Device* d3dDevice, + _In_z_ const wchar_t* szFileName, + _In_ IEffectFactory& fxFactory, bool ccw = true, + bool pmalpha = false); - // Loads a model from a DirectX SDK .SDKMESH file - static std::unique_ptr __cdecl CreateFromSDKMESH( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize, - _In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false ); - static std::unique_ptr __cdecl CreateFromSDKMESH( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName, - _In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false ); + // Loads a model from a DirectX SDK .SDKMESH file + static std::unique_ptr __cdecl CreateFromSDKMESH(_In_ ID3D11Device* d3dDevice, + _In_reads_bytes_(dataSize) const uint8_t* meshData, + _In_ size_t dataSize, + _In_ IEffectFactory& fxFactory, bool ccw = false, + bool pmalpha = false); + static std::unique_ptr __cdecl CreateFromSDKMESH(_In_ ID3D11Device* d3dDevice, + _In_z_ const wchar_t* szFileName, + _In_ IEffectFactory& fxFactory, bool ccw = false, + bool pmalpha = false); - // Loads a model from a .VBO file - static std::unique_ptr __cdecl CreateFromVBO( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize, - _In_opt_ std::shared_ptr ieffect = nullptr, bool ccw = false, bool pmalpha = false ); - static std::unique_ptr __cdecl CreateFromVBO( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName, - _In_opt_ std::shared_ptr ieffect = nullptr, bool ccw = false, bool pmalpha = false ); + // Loads a model from a .VBO file + static std::unique_ptr __cdecl CreateFromVBO(_In_ ID3D11Device* d3dDevice, + _In_reads_bytes_(dataSize) const uint8_t* meshData, + _In_ size_t dataSize, + _In_opt_ std::shared_ptr ieffect = nullptr, + bool ccw = false, bool pmalpha = false); + static std::unique_ptr __cdecl CreateFromVBO(_In_ ID3D11Device* d3dDevice, + _In_z_ const wchar_t* szFileName, + _In_opt_ std::shared_ptr ieffect = nullptr, + bool ccw = false, bool pmalpha = false); - private: - std::set mEffectCache; - }; - } \ No newline at end of file + private: + std::set mEffectCache; + }; +} diff --git a/Windows/DirectXTK/PrimitiveBatch.h b/Windows/DirectXTK/PrimitiveBatch.h index c2e7965..b870c05 100644 --- a/Windows/DirectXTK/PrimitiveBatch.h +++ b/Windows/DirectXTK/PrimitiveBatch.h @@ -41,118 +41,129 @@ namespace DirectX { - namespace Internal - { - // Base class, not to be used directly: clients should access this via the derived PrimitiveBatch. - class PrimitiveBatchBase - { - protected: - PrimitiveBatchBase(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices, size_t vertexSize); - PrimitiveBatchBase(PrimitiveBatchBase&& moveFrom); - PrimitiveBatchBase& operator= (PrimitiveBatchBase&& moveFrom); - virtual ~PrimitiveBatchBase(); + namespace Internal + { + // Base class, not to be used directly: clients should access this via the derived PrimitiveBatch. + class PrimitiveBatchBase + { + protected: + PrimitiveBatchBase(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices, + size_t vertexSize); + PrimitiveBatchBase(PrimitiveBatchBase&& moveFrom); + PrimitiveBatchBase& operator=(PrimitiveBatchBase&& moveFrom); + virtual ~PrimitiveBatchBase(); - public: - // Begin/End a batch of primitive drawing operations. - void __cdecl Begin(); - void __cdecl End(); + public: + // Begin/End a batch of primitive drawing operations. + void __cdecl Begin(); + void __cdecl End(); - protected: - // Internal, untyped drawing method. - void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIndexed, _In_opt_count_(indexCount) uint16_t const* indices, size_t indexCount, size_t vertexCount, _Out_ void** pMappedVertices); + protected: + // Internal, untyped drawing method. + void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIndexed, + _In_opt_count_(indexCount) uint16_t const* indices, size_t indexCount, size_t vertexCount, + _Out_ void** pMappedVertices); - private: - // Private implementation. - class Impl; + private: + // Private implementation. + class Impl; - std::unique_ptr pImpl; + std::unique_ptr pImpl; - // Prevent copying. - PrimitiveBatchBase(PrimitiveBatchBase const&) DIRECTX_CTOR_DELETE - PrimitiveBatchBase& operator= (PrimitiveBatchBase const&) DIRECTX_CTOR_DELETE - }; - } + // Prevent copying. + PrimitiveBatchBase(PrimitiveBatchBase const&) DIRECTX_CTOR_DELETE + PrimitiveBatchBase& operator=(PrimitiveBatchBase const&) DIRECTX_CTOR_DELETE + }; + } - // Template makes the API typesafe, eg. PrimitiveBatch. - template - class PrimitiveBatch : public Internal::PrimitiveBatchBase - { - static const size_t DefaultBatchSize = 2048; + // Template makes the API typesafe, eg. PrimitiveBatch. + template + class PrimitiveBatch : public Internal::PrimitiveBatchBase + { + static const size_t DefaultBatchSize = 2048; - public: - PrimitiveBatch(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices = DefaultBatchSize * 3, size_t maxVertices = DefaultBatchSize) - : PrimitiveBatchBase(deviceContext, maxIndices, maxVertices, sizeof(TVertex)) - { } + public: + PrimitiveBatch(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices = DefaultBatchSize * 3, + size_t maxVertices = DefaultBatchSize) + : PrimitiveBatchBase(deviceContext, maxIndices, maxVertices, sizeof(TVertex)) + { + } - PrimitiveBatch(PrimitiveBatch&& moveFrom) - : PrimitiveBatchBase(std::move(moveFrom)) - { } + PrimitiveBatch(PrimitiveBatch&& moveFrom) + : PrimitiveBatchBase(std::move(moveFrom)) + { + } - PrimitiveBatch& __cdecl operator= (PrimitiveBatch&& moveFrom) - { - PrimitiveBatchBase::operator=(std::move(moveFrom)); - return *this; - } + PrimitiveBatch& __cdecl operator=(PrimitiveBatch&& moveFrom) + { + PrimitiveBatchBase::operator=(std::move(moveFrom)); + return *this; + } - // Similar to the D3D9 API DrawPrimitiveUP. - void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount) - { - void* mappedVertices; + // Similar to the D3D9 API DrawPrimitiveUP. + void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(vertexCount) TVertex const* vertices, + size_t vertexCount) + { + void* mappedVertices; - PrimitiveBatchBase::Draw(topology, false, nullptr, 0, vertexCount, &mappedVertices); + PrimitiveBatchBase::Draw(topology, false, nullptr, 0, vertexCount, &mappedVertices); - memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex)); - } + memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex)); + } - // Similar to the D3D9 API DrawIndexedPrimitiveUP. - void __cdecl DrawIndexed(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(indexCount) uint16_t const* indices, size_t indexCount, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount) - { - void* mappedVertices; + // Similar to the D3D9 API DrawIndexedPrimitiveUP. + void __cdecl DrawIndexed(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(indexCount) uint16_t const* indices, + size_t indexCount, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount) + { + void* mappedVertices; - PrimitiveBatchBase::Draw(topology, true, indices, indexCount, vertexCount, &mappedVertices); + PrimitiveBatchBase::Draw(topology, true, indices, indexCount, vertexCount, &mappedVertices); - memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex)); - } + memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex)); + } - void __cdecl DrawLine(TVertex const& v1, TVertex const& v2) - { - TVertex* mappedVertices; + void __cdecl DrawLine(TVertex const& v1, TVertex const& v2) + { + TVertex* mappedVertices; - PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_LINELIST, false, nullptr, 0, 2, reinterpret_cast(&mappedVertices)); + PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_LINELIST, false, nullptr, 0, 2, + reinterpret_cast(&mappedVertices)); - mappedVertices[0] = v1; - mappedVertices[1] = v2; - } + mappedVertices[0] = v1; + mappedVertices[1] = v2; + } - void __cdecl DrawTriangle(TVertex const& v1, TVertex const& v2, TVertex const& v3) - { - TVertex* mappedVertices; + void __cdecl DrawTriangle(TVertex const& v1, TVertex const& v2, TVertex const& v3) + { + TVertex* mappedVertices; - PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, false, nullptr, 0, 3, reinterpret_cast(&mappedVertices)); + PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, false, nullptr, 0, 3, + reinterpret_cast(&mappedVertices)); - mappedVertices[0] = v1; - mappedVertices[1] = v2; - mappedVertices[2] = v3; - } + mappedVertices[0] = v1; + mappedVertices[1] = v2; + mappedVertices[2] = v3; + } - void __cdecl DrawQuad(TVertex const& v1, TVertex const& v2, TVertex const& v3, TVertex const& v4) - { - static const uint16_t quadIndices[] = { 0, 1, 2, 0, 2, 3 }; + void __cdecl DrawQuad(TVertex const& v1, TVertex const& v2, TVertex const& v3, TVertex const& v4) + { + static const uint16_t quadIndices[] = {0, 1, 2, 0, 2, 3}; - TVertex* mappedVertices; + TVertex* mappedVertices; - PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, true, quadIndices, 6, 4, reinterpret_cast(&mappedVertices)); + PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, true, quadIndices, 6, 4, + reinterpret_cast(&mappedVertices)); - mappedVertices[0] = v1; - mappedVertices[1] = v2; - mappedVertices[2] = v3; - mappedVertices[3] = v4; - } - }; + mappedVertices[0] = v1; + mappedVertices[1] = v2; + mappedVertices[2] = v3; + mappedVertices[3] = v4; + } + }; } diff --git a/Windows/DirectXTK/ScreenGrab.h b/Windows/DirectXTK/ScreenGrab.h index 2a1b661..62e2e6b 100644 --- a/Windows/DirectXTK/ScreenGrab.h +++ b/Windows/DirectXTK/ScreenGrab.h @@ -47,18 +47,19 @@ namespace DirectX { - HRESULT __cdecl SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext, - _In_ ID3D11Resource* pSource, - _In_z_ LPCWSTR fileName ); + HRESULT __cdecl SaveDDSTextureToFile(_In_ ID3D11DeviceContext* pContext, + _In_ ID3D11Resource* pSource, + _In_z_ LPCWSTR fileName); #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (_WIN32_WINNT > _WIN32_WINNT_WIN8) - HRESULT __cdecl SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, - _In_ ID3D11Resource* pSource, - _In_ REFGUID guidContainerFormat, - _In_z_ LPCWSTR fileName, - _In_opt_ const GUID* targetFormat = nullptr, - _In_opt_ std::function setCustomProps = nullptr ); + HRESULT __cdecl SaveWICTextureToFile(_In_ ID3D11DeviceContext* pContext, + _In_ ID3D11Resource* pSource, + _In_ REFGUID guidContainerFormat, + _In_z_ LPCWSTR fileName, + _In_opt_ const GUID* targetFormat = nullptr, + _In_opt_ std::function setCustomProps + = nullptr); #endif -} \ No newline at end of file +} diff --git a/Windows/DirectXTK/SimpleMath.h b/Windows/DirectXTK/SimpleMath.h index c0cf1c8..dbab2dd 100644 --- a/Windows/DirectXTK/SimpleMath.h +++ b/Windows/DirectXTK/SimpleMath.h @@ -28,900 +28,1230 @@ namespace DirectX { + namespace SimpleMath + { + struct Vector4; + struct Matrix; + struct Quaternion; + struct Plane; + + //------------------------------------------------------------------------------ + // 2D vector + struct Vector2 : public XMFLOAT2 + { + Vector2() : XMFLOAT2(0.f, 0.f) + { + } + + explicit Vector2(float x) : XMFLOAT2(x, x) + { + } -namespace SimpleMath -{ - -struct Vector4; -struct Matrix; -struct Quaternion; -struct Plane; - -//------------------------------------------------------------------------------ -// 2D vector -struct Vector2 : public XMFLOAT2 -{ - Vector2() : XMFLOAT2(0.f, 0.f) {} - explicit Vector2(float x) : XMFLOAT2( x, x ) {} - Vector2(float _x, float _y) : XMFLOAT2(_x, _y) {} - explicit Vector2(_In_reads_(2) const float *pArray) : XMFLOAT2(pArray) {} - Vector2(FXMVECTOR V) { XMStoreFloat2( this, V ); } - Vector2(const XMFLOAT2& V) { this->x = V.x; this->y = V.y; } - - operator XMVECTOR() const { return XMLoadFloat2( this ); } - - // Comparison operators - bool operator == ( const Vector2& V ) const; - bool operator != ( const Vector2& V ) const; - - // Assignment operators - Vector2& operator= (const Vector2& V) { x = V.x; y = V.y; return *this; } - Vector2& operator= (const XMFLOAT2& V) { x = V.x; y = V.y; return *this; } - Vector2& operator+= (const Vector2& V); - Vector2& operator-= (const Vector2& V); - Vector2& operator*= (const Vector2& V); - Vector2& operator*= (float S); - Vector2& operator/= (float S); - - // Unary operators - Vector2 operator+ () const { return *this; } - Vector2 operator- () const { return Vector2(-x, -y); } - - // Vector operations - bool InBounds( const Vector2& Bounds ) const; - - float Length() const; - float LengthSquared() const; - - float Dot( const Vector2& V ) const; - void Cross( const Vector2& V, Vector2& result ) const; - Vector2 Cross( const Vector2& V ) const; - - void Normalize(); - void Normalize( Vector2& result ) const; - - void Clamp( const Vector2& vmin, const Vector2& vmax ); - void Clamp( const Vector2& vmin, const Vector2& vmax, Vector2& result ) const; - - // Static functions - static float Distance( const Vector2& v1, const Vector2& v2 ); - static float DistanceSquared( const Vector2& v1, const Vector2& v2 ); - - static void Min( const Vector2& v1, const Vector2& v2, Vector2& result ); - static Vector2 Min( const Vector2& v1, const Vector2& v2 ); - - static void Max( const Vector2& v1, const Vector2& v2, Vector2& result ); - static Vector2 Max( const Vector2& v1, const Vector2& v2 ); - - static void Lerp( const Vector2& v1, const Vector2& v2, float t, Vector2& result ); - static Vector2 Lerp( const Vector2& v1, const Vector2& v2, float t ); - - static void SmoothStep( const Vector2& v1, const Vector2& v2, float t, Vector2& result ); - static Vector2 SmoothStep( const Vector2& v1, const Vector2& v2, float t ); - - static void Barycentric( const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, Vector2& result ); - static Vector2 Barycentric( const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g ); - - static void CatmullRom( const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, Vector2& result ); - static Vector2 CatmullRom( const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t ); - - static void Hermite( const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, Vector2& result ); - static Vector2 Hermite( const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t ); - - static void Reflect( const Vector2& ivec, const Vector2& nvec, Vector2& result ); - static Vector2 Reflect( const Vector2& ivec, const Vector2& nvec ); - - static void Refract( const Vector2& ivec, const Vector2& nvec, float refractionIndex, Vector2& result ); - static Vector2 Refract( const Vector2& ivec, const Vector2& nvec, float refractionIndex ); - - static void Transform( const Vector2& v, const Quaternion& quat, Vector2& result ); - static Vector2 Transform( const Vector2& v, const Quaternion& quat ); - - static void Transform( const Vector2& v, const Matrix& m, Vector2& result ); - static Vector2 Transform( const Vector2& v, const Matrix& m ); - static void Transform( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector2* resultArray ); - - static void Transform( const Vector2& v, const Matrix& m, Vector4& result ); - static void Transform( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray ); - - static void TransformNormal( const Vector2& v, const Matrix& m, Vector2& result ); - static Vector2 TransformNormal( const Vector2& v, const Matrix& m ); - static void TransformNormal( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector2* resultArray ); - - // Constants - static const Vector2 Zero; - static const Vector2 One; - static const Vector2 UnitX; - static const Vector2 UnitY; -}; + Vector2(float _x, float _y) : XMFLOAT2(_x, _y) + { + } + + explicit Vector2(_In_reads_(2) const float* pArray) : XMFLOAT2(pArray) + { + } + + Vector2(FXMVECTOR V) { XMStoreFloat2(this, V); } + + Vector2(const XMFLOAT2& V) + { + this->x = V.x; + this->y = V.y; + } + + operator XMVECTOR() const { return XMLoadFloat2(this); } + + // Comparison operators + bool operator ==(const Vector2& V) const; + bool operator !=(const Vector2& V) const; + + // Assignment operators + Vector2& operator=(const Vector2& V) + { + x = V.x; + y = V.y; + return *this; + } + + Vector2& operator=(const XMFLOAT2& V) + { + x = V.x; + y = V.y; + return *this; + } + + Vector2& operator+=(const Vector2& V); + Vector2& operator-=(const Vector2& V); + Vector2& operator*=(const Vector2& V); + Vector2& operator*=(float S); + Vector2& operator/=(float S); + + // Unary operators + Vector2 operator+() const { return *this; } + Vector2 operator-() const { return Vector2(-x, -y); } + + // Vector operations + bool InBounds(const Vector2& Bounds) const; + + float Length() const; + float LengthSquared() const; + + float Dot(const Vector2& V) const; + void Cross(const Vector2& V, Vector2& result) const; + Vector2 Cross(const Vector2& V) const; + + void Normalize(); + void Normalize(Vector2& result) const; + + void Clamp(const Vector2& vmin, const Vector2& vmax); + void Clamp(const Vector2& vmin, const Vector2& vmax, Vector2& result) const; + + // Static functions + static float Distance(const Vector2& v1, const Vector2& v2); + static float DistanceSquared(const Vector2& v1, const Vector2& v2); + + static void Min(const Vector2& v1, const Vector2& v2, Vector2& result); + static Vector2 Min(const Vector2& v1, const Vector2& v2); + + static void Max(const Vector2& v1, const Vector2& v2, Vector2& result); + static Vector2 Max(const Vector2& v1, const Vector2& v2); + + static void Lerp(const Vector2& v1, const Vector2& v2, float t, Vector2& result); + static Vector2 Lerp(const Vector2& v1, const Vector2& v2, float t); + + static void SmoothStep(const Vector2& v1, const Vector2& v2, float t, Vector2& result); + static Vector2 SmoothStep(const Vector2& v1, const Vector2& v2, float t); + + static void Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, + Vector2& result); + static Vector2 Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g); + + static void CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, + Vector2& result); + static Vector2 CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t); + + static void Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, + Vector2& result); + static Vector2 Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t); + + static void Reflect(const Vector2& ivec, const Vector2& nvec, Vector2& result); + static Vector2 Reflect(const Vector2& ivec, const Vector2& nvec); + + static void Refract(const Vector2& ivec, const Vector2& nvec, float refractionIndex, Vector2& result); + static Vector2 Refract(const Vector2& ivec, const Vector2& nvec, float refractionIndex); + + static void Transform(const Vector2& v, const Quaternion& quat, Vector2& result); + static Vector2 Transform(const Vector2& v, const Quaternion& quat); + + static void Transform(const Vector2& v, const Matrix& m, Vector2& result); + static Vector2 Transform(const Vector2& v, const Matrix& m); + static void Transform(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, + _Out_writes_(count) Vector2* resultArray); + + static void Transform(const Vector2& v, const Matrix& m, Vector4& result); + static void Transform(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, + _Out_writes_(count) Vector4* resultArray); + + static void TransformNormal(const Vector2& v, const Matrix& m, Vector2& result); + static Vector2 TransformNormal(const Vector2& v, const Matrix& m); + static void TransformNormal(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, + _Out_writes_(count) Vector2* resultArray); + + // Constants + static const Vector2 Zero; + static const Vector2 One; + static const Vector2 UnitX; + static const Vector2 UnitY; + }; + + // Binary operators + Vector2 operator+(const Vector2& V1, const Vector2& V2); + Vector2 operator-(const Vector2& V1, const Vector2& V2); + Vector2 operator*(const Vector2& V1, const Vector2& V2); + Vector2 operator*(const Vector2& V, float S); + Vector2 operator/(const Vector2& V1, const Vector2& V2); + Vector2 operator*(float S, const Vector2& V); + + //------------------------------------------------------------------------------ + // 3D vector + struct Vector3 : public XMFLOAT3 + { + Vector3() : XMFLOAT3(0.f, 0.f, 0.f) + { + } + + explicit Vector3(float x) : XMFLOAT3(x, x, x) + { + } -// Binary operators -Vector2 operator+ (const Vector2& V1, const Vector2& V2); -Vector2 operator- (const Vector2& V1, const Vector2& V2); -Vector2 operator* (const Vector2& V1, const Vector2& V2); -Vector2 operator* (const Vector2& V, float S); -Vector2 operator/ (const Vector2& V1, const Vector2& V2); -Vector2 operator* (float S, const Vector2& V); - -//------------------------------------------------------------------------------ -// 3D vector -struct Vector3 : public XMFLOAT3 -{ - Vector3() : XMFLOAT3(0.f, 0.f, 0.f) {} - explicit Vector3(float x) : XMFLOAT3( x, x, x ) {} - Vector3(float _x, float _y, float _z) : XMFLOAT3(_x, _y, _z) {} - explicit Vector3(_In_reads_(3) const float *pArray) : XMFLOAT3(pArray) {} - Vector3(FXMVECTOR V) { XMStoreFloat3( this, V ); } - Vector3(const XMFLOAT3& V) { this->x = V.x; this->y = V.y; this->z = V.z; } - - operator XMVECTOR() const { return XMLoadFloat3( this ); } - - // Comparison operators - bool operator == ( const Vector3& V ) const; - bool operator != ( const Vector3& V ) const; - - // Assignment operators - Vector3& operator= (const Vector3& V) { x = V.x; y = V.y; z = V.z; return *this; } - Vector3& operator= (const XMFLOAT3& V) { x = V.x; y = V.y; z = V.z; return *this; } - Vector3& operator+= (const Vector3& V); - Vector3& operator-= (const Vector3& V); - Vector3& operator*= (const Vector3& V); - Vector3& operator*= (float S); - Vector3& operator/= (float S); - - // Unary operators - Vector3 operator+ () const { return *this; } - Vector3 operator- () const; - - // Vector operations - bool InBounds( const Vector3& Bounds ) const; - - float Length() const; - float LengthSquared() const; - - float Dot( const Vector3& V ) const; - void Cross( const Vector3& V, Vector3& result ) const; - Vector3 Cross( const Vector3& V ) const; - - void Normalize(); - void Normalize( Vector3& result ) const; - - void Clamp( const Vector3& vmin, const Vector3& vmax ); - void Clamp( const Vector3& vmin, const Vector3& vmax, Vector3& result ) const; - - // Static functions - static float Distance( const Vector3& v1, const Vector3& v2 ); - static float DistanceSquared( const Vector3& v1, const Vector3& v2 ); - - static void Min( const Vector3& v1, const Vector3& v2, Vector3& result ); - static Vector3 Min( const Vector3& v1, const Vector3& v2 ); - - static void Max( const Vector3& v1, const Vector3& v2, Vector3& result ); - static Vector3 Max( const Vector3& v1, const Vector3& v2 ); - - static void Lerp( const Vector3& v1, const Vector3& v2, float t, Vector3& result ); - static Vector3 Lerp( const Vector3& v1, const Vector3& v2, float t ); - - static void SmoothStep( const Vector3& v1, const Vector3& v2, float t, Vector3& result ); - static Vector3 SmoothStep( const Vector3& v1, const Vector3& v2, float t ); - - static void Barycentric( const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, Vector3& result ); - static Vector3 Barycentric( const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g ); - - static void CatmullRom( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, Vector3& result ); - static Vector3 CatmullRom( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t ); - - static void Hermite( const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, Vector3& result ); - static Vector3 Hermite( const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t ); - - static void Reflect( const Vector3& ivec, const Vector3& nvec, Vector3& result ); - static Vector3 Reflect( const Vector3& ivec, const Vector3& nvec ); - - static void Refract( const Vector3& ivec, const Vector3& nvec, float refractionIndex, Vector3& result ); - static Vector3 Refract( const Vector3& ivec, const Vector3& nvec, float refractionIndex ); - - static void Transform( const Vector3& v, const Quaternion& quat, Vector3& result ); - static Vector3 Transform( const Vector3& v, const Quaternion& quat ); - - static void Transform( const Vector3& v, const Matrix& m, Vector3& result ); - static Vector3 Transform( const Vector3& v, const Matrix& m ); - static void Transform( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector3* resultArray ); - - static void Transform( const Vector3& v, const Matrix& m, Vector4& result ); - static void Transform( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray ); - - static void TransformNormal( const Vector3& v, const Matrix& m, Vector3& result ); - static Vector3 TransformNormal( const Vector3& v, const Matrix& m ); - static void TransformNormal( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector3* resultArray ); - - // Constants - static const Vector3 Zero; - static const Vector3 One; - static const Vector3 UnitX; - static const Vector3 UnitY; - static const Vector3 UnitZ; - static const Vector3 Up; - static const Vector3 Down; - static const Vector3 Right; - static const Vector3 Left; - static const Vector3 Forward; - static const Vector3 Backward; -}; + Vector3(float _x, float _y, float _z) : XMFLOAT3(_x, _y, _z) + { + } -// Binary operators -Vector3 operator+ (const Vector3& V1, const Vector3& V2); -Vector3 operator- (const Vector3& V1, const Vector3& V2); -Vector3 operator* (const Vector3& V1, const Vector3& V2); -Vector3 operator* (const Vector3& V, float S); -Vector3 operator/ (const Vector3& V1, const Vector3& V2); -Vector3 operator* (float S, const Vector3& V); + explicit Vector3(_In_reads_(3) const float* pArray) : XMFLOAT3(pArray) + { + } -//------------------------------------------------------------------------------ -// 4D vector -struct Vector4 : public XMFLOAT4 -{ - Vector4() : XMFLOAT4(0.f, 0.f, 0.f, 0.f) {} - explicit Vector4(float x) : XMFLOAT4( x, x, x, x ) {} - Vector4(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w) {} - explicit Vector4(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {} - Vector4(FXMVECTOR V) { XMStoreFloat4( this, V ); } - Vector4(const XMFLOAT4& V) { this->x = V.x; this->y = V.y; this->z = V.z; this->w = V.w; } - - operator XMVECTOR() const { return XMLoadFloat4( this ); } - - // Comparison operators - bool operator == ( const Vector4& V ) const; - bool operator != ( const Vector4& V ) const; - - // Assignment operators - Vector4& operator= (const Vector4& V) { x = V.x; y = V.y; z = V.z; w = V.w; return *this; } - Vector4& operator= (const XMFLOAT4& V) { x = V.x; y = V.y; z = V.z; w = V.w; return *this; } - Vector4& operator+= (const Vector4& V); - Vector4& operator-= (const Vector4& V); - Vector4& operator*= (const Vector4& V); - Vector4& operator*= (float S); - Vector4& operator/= (float S); - - // Unary operators - Vector4 operator+ () const { return *this; } - Vector4 operator- () const; - - // Vector operations - bool InBounds( const Vector4& Bounds ) const; - - float Length() const; - float LengthSquared() const; - - float Dot( const Vector4& V ) const; - void Cross( const Vector4& v1, const Vector4& v2, Vector4& result ) const; - Vector4 Cross( const Vector4& v1, const Vector4& v2 ) const; - - void Normalize(); - void Normalize( Vector4& result ) const; - - void Clamp( const Vector4& vmin, const Vector4& vmax ); - void Clamp( const Vector4& vmin, const Vector4& vmax, Vector4& result ) const; - - // Static functions - static float Distance( const Vector4& v1, const Vector4& v2 ); - static float DistanceSquared( const Vector4& v1, const Vector4& v2 ); - - static void Min( const Vector4& v1, const Vector4& v2, Vector4& result ); - static Vector4 Min( const Vector4& v1, const Vector4& v2 ); - - static void Max( const Vector4& v1, const Vector4& v2, Vector4& result ); - static Vector4 Max( const Vector4& v1, const Vector4& v2 ); - - static void Lerp( const Vector4& v1, const Vector4& v2, float t, Vector4& result ); - static Vector4 Lerp( const Vector4& v1, const Vector4& v2, float t ); - - static void SmoothStep( const Vector4& v1, const Vector4& v2, float t, Vector4& result ); - static Vector4 SmoothStep( const Vector4& v1, const Vector4& v2, float t ); - - static void Barycentric( const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, Vector4& result ); - static Vector4 Barycentric( const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g ); - - static void CatmullRom( const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, Vector4& result ); - static Vector4 CatmullRom( const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t ); - - static void Hermite( const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, Vector4& result ); - static Vector4 Hermite( const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t ); - - static void Reflect( const Vector4& ivec, const Vector4& nvec, Vector4& result ); - static Vector4 Reflect( const Vector4& ivec, const Vector4& nvec ); - - static void Refract( const Vector4& ivec, const Vector4& nvec, float refractionIndex, Vector4& result ); - static Vector4 Refract( const Vector4& ivec, const Vector4& nvec, float refractionIndex ); - - static void Transform( const Vector2& v, const Quaternion& quat, Vector4& result ); - static Vector4 Transform( const Vector2& v, const Quaternion& quat ); - - static void Transform( const Vector3& v, const Quaternion& quat, Vector4& result ); - static Vector4 Transform( const Vector3& v, const Quaternion& quat ); - - static void Transform( const Vector4& v, const Quaternion& quat, Vector4& result ); - static Vector4 Transform( const Vector4& v, const Quaternion& quat ); - - static void Transform( const Vector4& v, const Matrix& m, Vector4& result ); - static Vector4 Transform( const Vector4& v, const Matrix& m ); - static void Transform( _In_reads_(count) const Vector4* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray ); - - // Constants - static const Vector4 Zero; - static const Vector4 One; - static const Vector4 UnitX; - static const Vector4 UnitY; - static const Vector4 UnitZ; - static const Vector4 UnitW; -}; - -// Binary operators -Vector4 operator+ (const Vector4& V1, const Vector4& V2); -Vector4 operator- (const Vector4& V1, const Vector4& V2); -Vector4 operator* (const Vector4& V1, const Vector4& V2); -Vector4 operator* (const Vector4& V, float S); -Vector4 operator/ (const Vector4& V1, const Vector4& V2); -Vector4 operator* (float S, const Vector4& V); - -//------------------------------------------------------------------------------ -// 4x4 Matrix (assumes right-handed cooordinates) -struct Matrix : public XMFLOAT4X4 -{ - Matrix() : XMFLOAT4X4( 1.f, 0, 0, 0, - 0, 1.f, 0, 0, - 0, 0, 1.f, 0, - 0, 0, 0, 1.f ) {} - Matrix(float m00, float m01, float m02, float m03, - float m10, float m11, float m12, float m13, - float m20, float m21, float m22, float m23, - float m30, float m31, float m32, float m33) : XMFLOAT4X4(m00, m01, m02, m03, - m10, m11, m12, m13, - m20, m21, m22, m23, - m30, m31, m32, m33) {} - explicit Matrix( const Vector3& r0, const Vector3& r1, const Vector3& r2 ) : XMFLOAT4X4( r0.x, r0.y, r0.z, 0, - r1.x, r1.y, r1.z, 0, - r2.x, r2.y, r2.z, 0, - 0, 0, 0, 1.f ) {} - explicit Matrix( const Vector4& r0, const Vector4& r1, const Vector4& r2, const Vector4& r3 ) : XMFLOAT4X4( r0.x, r0.y, r0.z, r0.w, - r1.x, r1.y, r1.z, r1.w, - r2.x, r2.y, r2.z, r2.w, - r3.x, r3.y, r3.z, r3.w ) {} - Matrix(const XMFLOAT4X4& M) { memcpy_s(this, sizeof(float)*16, &M, sizeof(XMFLOAT4X4)); } - Matrix(const XMFLOAT3X3& M); - Matrix(const XMFLOAT4X3& M); + Vector3(FXMVECTOR V) { XMStoreFloat3(this, V); } + + Vector3(const XMFLOAT3& V) + { + this->x = V.x; + this->y = V.y; + this->z = V.z; + } + + operator XMVECTOR() const { return XMLoadFloat3(this); } + + // Comparison operators + bool operator ==(const Vector3& V) const; + bool operator !=(const Vector3& V) const; + + // Assignment operators + Vector3& operator=(const Vector3& V) + { + x = V.x; + y = V.y; + z = V.z; + return *this; + } + + Vector3& operator=(const XMFLOAT3& V) + { + x = V.x; + y = V.y; + z = V.z; + return *this; + } + + Vector3& operator+=(const Vector3& V); + Vector3& operator-=(const Vector3& V); + Vector3& operator*=(const Vector3& V); + Vector3& operator*=(float S); + Vector3& operator/=(float S); + + // Unary operators + Vector3 operator+() const { return *this; } + Vector3 operator-() const; + + // Vector operations + bool InBounds(const Vector3& Bounds) const; + + float Length() const; + float LengthSquared() const; + + float Dot(const Vector3& V) const; + void Cross(const Vector3& V, Vector3& result) const; + Vector3 Cross(const Vector3& V) const; + + void Normalize(); + void Normalize(Vector3& result) const; + + void Clamp(const Vector3& vmin, const Vector3& vmax); + void Clamp(const Vector3& vmin, const Vector3& vmax, Vector3& result) const; + + // Static functions + static float Distance(const Vector3& v1, const Vector3& v2); + static float DistanceSquared(const Vector3& v1, const Vector3& v2); + + static void Min(const Vector3& v1, const Vector3& v2, Vector3& result); + static Vector3 Min(const Vector3& v1, const Vector3& v2); + + static void Max(const Vector3& v1, const Vector3& v2, Vector3& result); + static Vector3 Max(const Vector3& v1, const Vector3& v2); + + static void Lerp(const Vector3& v1, const Vector3& v2, float t, Vector3& result); + static Vector3 Lerp(const Vector3& v1, const Vector3& v2, float t); + + static void SmoothStep(const Vector3& v1, const Vector3& v2, float t, Vector3& result); + static Vector3 SmoothStep(const Vector3& v1, const Vector3& v2, float t); + + static void Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, + Vector3& result); + static Vector3 Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g); + + static void CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, + Vector3& result); + static Vector3 CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t); + + static void Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, + Vector3& result); + static Vector3 Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t); + + static void Reflect(const Vector3& ivec, const Vector3& nvec, Vector3& result); + static Vector3 Reflect(const Vector3& ivec, const Vector3& nvec); + + static void Refract(const Vector3& ivec, const Vector3& nvec, float refractionIndex, Vector3& result); + static Vector3 Refract(const Vector3& ivec, const Vector3& nvec, float refractionIndex); + + static void Transform(const Vector3& v, const Quaternion& quat, Vector3& result); + static Vector3 Transform(const Vector3& v, const Quaternion& quat); + + static void Transform(const Vector3& v, const Matrix& m, Vector3& result); + static Vector3 Transform(const Vector3& v, const Matrix& m); + static void Transform(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, + _Out_writes_(count) Vector3* resultArray); + + static void Transform(const Vector3& v, const Matrix& m, Vector4& result); + static void Transform(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, + _Out_writes_(count) Vector4* resultArray); + + static void TransformNormal(const Vector3& v, const Matrix& m, Vector3& result); + static Vector3 TransformNormal(const Vector3& v, const Matrix& m); + static void TransformNormal(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, + _Out_writes_(count) Vector3* resultArray); + + // Constants + static const Vector3 Zero; + static const Vector3 One; + static const Vector3 UnitX; + static const Vector3 UnitY; + static const Vector3 UnitZ; + static const Vector3 Up; + static const Vector3 Down; + static const Vector3 Right; + static const Vector3 Left; + static const Vector3 Forward; + static const Vector3 Backward; + }; + + // Binary operators + Vector3 operator+(const Vector3& V1, const Vector3& V2); + Vector3 operator-(const Vector3& V1, const Vector3& V2); + Vector3 operator*(const Vector3& V1, const Vector3& V2); + Vector3 operator*(const Vector3& V, float S); + Vector3 operator/(const Vector3& V1, const Vector3& V2); + Vector3 operator*(float S, const Vector3& V); + + //------------------------------------------------------------------------------ + // 4D vector + struct Vector4 : public XMFLOAT4 + { + Vector4() : XMFLOAT4(0.f, 0.f, 0.f, 0.f) + { + } + + explicit Vector4(float x) : XMFLOAT4(x, x, x, x) + { + } + + Vector4(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w) + { + } + + explicit Vector4(_In_reads_(4) const float* pArray) : XMFLOAT4(pArray) + { + } + + Vector4(FXMVECTOR V) { XMStoreFloat4(this, V); } + + Vector4(const XMFLOAT4& V) + { + this->x = V.x; + this->y = V.y; + this->z = V.z; + this->w = V.w; + } + + operator XMVECTOR() const { return XMLoadFloat4(this); } + + // Comparison operators + bool operator ==(const Vector4& V) const; + bool operator !=(const Vector4& V) const; + + // Assignment operators + Vector4& operator=(const Vector4& V) + { + x = V.x; + y = V.y; + z = V.z; + w = V.w; + return *this; + } + + Vector4& operator=(const XMFLOAT4& V) + { + x = V.x; + y = V.y; + z = V.z; + w = V.w; + return *this; + } + + Vector4& operator+=(const Vector4& V); + Vector4& operator-=(const Vector4& V); + Vector4& operator*=(const Vector4& V); + Vector4& operator*=(float S); + Vector4& operator/=(float S); + + // Unary operators + Vector4 operator+() const { return *this; } + Vector4 operator-() const; + + // Vector operations + bool InBounds(const Vector4& Bounds) const; + + float Length() const; + float LengthSquared() const; + + float Dot(const Vector4& V) const; + void Cross(const Vector4& v1, const Vector4& v2, Vector4& result) const; + Vector4 Cross(const Vector4& v1, const Vector4& v2) const; + + void Normalize(); + void Normalize(Vector4& result) const; + + void Clamp(const Vector4& vmin, const Vector4& vmax); + void Clamp(const Vector4& vmin, const Vector4& vmax, Vector4& result) const; + + // Static functions + static float Distance(const Vector4& v1, const Vector4& v2); + static float DistanceSquared(const Vector4& v1, const Vector4& v2); + + static void Min(const Vector4& v1, const Vector4& v2, Vector4& result); + static Vector4 Min(const Vector4& v1, const Vector4& v2); + + static void Max(const Vector4& v1, const Vector4& v2, Vector4& result); + static Vector4 Max(const Vector4& v1, const Vector4& v2); + + static void Lerp(const Vector4& v1, const Vector4& v2, float t, Vector4& result); + static Vector4 Lerp(const Vector4& v1, const Vector4& v2, float t); + + static void SmoothStep(const Vector4& v1, const Vector4& v2, float t, Vector4& result); + static Vector4 SmoothStep(const Vector4& v1, const Vector4& v2, float t); + + static void Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, + Vector4& result); + static Vector4 Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g); + + static void CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, + Vector4& result); + static Vector4 CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t); + + static void Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, + Vector4& result); + static Vector4 Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t); + + static void Reflect(const Vector4& ivec, const Vector4& nvec, Vector4& result); + static Vector4 Reflect(const Vector4& ivec, const Vector4& nvec); + + static void Refract(const Vector4& ivec, const Vector4& nvec, float refractionIndex, Vector4& result); + static Vector4 Refract(const Vector4& ivec, const Vector4& nvec, float refractionIndex); + + static void Transform(const Vector2& v, const Quaternion& quat, Vector4& result); + static Vector4 Transform(const Vector2& v, const Quaternion& quat); + + static void Transform(const Vector3& v, const Quaternion& quat, Vector4& result); + static Vector4 Transform(const Vector3& v, const Quaternion& quat); + + static void Transform(const Vector4& v, const Quaternion& quat, Vector4& result); + static Vector4 Transform(const Vector4& v, const Quaternion& quat); + + static void Transform(const Vector4& v, const Matrix& m, Vector4& result); + static Vector4 Transform(const Vector4& v, const Matrix& m); + static void Transform(_In_reads_(count) const Vector4* varray, size_t count, const Matrix& m, + _Out_writes_(count) Vector4* resultArray); + + // Constants + static const Vector4 Zero; + static const Vector4 One; + static const Vector4 UnitX; + static const Vector4 UnitY; + static const Vector4 UnitZ; + static const Vector4 UnitW; + }; + + // Binary operators + Vector4 operator+(const Vector4& V1, const Vector4& V2); + Vector4 operator-(const Vector4& V1, const Vector4& V2); + Vector4 operator*(const Vector4& V1, const Vector4& V2); + Vector4 operator*(const Vector4& V, float S); + Vector4 operator/(const Vector4& V1, const Vector4& V2); + Vector4 operator*(float S, const Vector4& V); + + //------------------------------------------------------------------------------ + // 4x4 Matrix (assumes right-handed cooordinates) + struct Matrix : public XMFLOAT4X4 + { + Matrix() : XMFLOAT4X4(1.f, 0, 0, 0, + 0, 1.f, 0, 0, + 0, 0, 1.f, 0, + 0, 0, 0, 1.f) + { + } + + Matrix(float m00, float m01, float m02, float m03, + float m10, float m11, float m12, float m13, + float m20, float m21, float m22, float m23, + float m30, float m31, float m32, float m33) : XMFLOAT4X4(m00, m01, m02, m03, + m10, m11, m12, m13, + m20, m21, m22, m23, + m30, m31, m32, m33) + { + } + + explicit Matrix(const Vector3& r0, const Vector3& r1, const Vector3& r2) : XMFLOAT4X4(r0.x, r0.y, r0.z, 0, + r1.x, r1.y, r1.z, 0, + r2.x, r2.y, r2.z, 0, + 0, 0, 0, 1.f) + { + } + + explicit Matrix(const Vector4& r0, const Vector4& r1, const Vector4& r2, const Vector4& r3) : XMFLOAT4X4( + r0.x, r0.y, r0.z, r0.w, + r1.x, r1.y, r1.z, r1.w, + r2.x, r2.y, r2.z, r2.w, + r3.x, r3.y, r3.z, r3.w) + { + } + + Matrix(const XMFLOAT4X4& M) { memcpy_s(this, sizeof(float) * 16, &M, sizeof(XMFLOAT4X4)); } + Matrix(const XMFLOAT3X3& M); + Matrix(const XMFLOAT4X3& M); + + explicit Matrix(_In_reads_(16) const float* pArray) : XMFLOAT4X4(pArray) + { + } + + Matrix(CXMMATRIX M) { XMStoreFloat4x4(this, M); } + + operator XMMATRIX() const { return XMLoadFloat4x4(this); } + + // Comparison operators + bool operator ==(const Matrix& M) const; + bool operator !=(const Matrix& M) const; + + // Assignment operators + Matrix& operator=(const Matrix& M) + { + memcpy_s(this, sizeof(float) * 16, &M, sizeof(float) * 16); + return *this; + } + + Matrix& operator=(const XMFLOAT4X4& M) + { + memcpy_s(this, sizeof(float) * 16, &M, sizeof(XMFLOAT4X4)); + return *this; + } + + Matrix& operator=(const XMFLOAT3X3& M); + Matrix& operator=(const XMFLOAT4X3& M); + Matrix& operator+=(const Matrix& M); + Matrix& operator-=(const Matrix& M); + Matrix& operator*=(const Matrix& M); + Matrix& operator*=(float S); + Matrix& operator/=(float S); + + Matrix& operator/=(const Matrix& M); + // Element-wise divide + + // Unary operators + Matrix operator+() const { return *this; } + Matrix operator-() const; + + // Properties + Vector3 Up() const { return Vector3(_21, _22, _23); } + + void Up(const Vector3& v) + { + _21 = v.x; + _22 = v.y; + _23 = v.z; + } + + Vector3 Down() const { return Vector3(-_21, -_22, -_23); } + + void Down(const Vector3& v) + { + _21 = -v.x; + _22 = -v.y; + _23 = -v.z; + } + + Vector3 Right() const { return Vector3(_11, _12, _13); } + + void Right(const Vector3& v) + { + _11 = v.x; + _12 = v.y; + _13 = v.z; + } + + Vector3 Left() const { return Vector3(-_11, -_12, -_13); } + + void Left(const Vector3& v) + { + _11 = -v.x; + _12 = -v.y; + _13 = -v.z; + } + + Vector3 Forward() const { return Vector3(-_31, -_32, -_33); } + + void Forward(const Vector3& v) + { + _31 = -v.x; + _32 = -v.y; + _33 = -v.z; + } + + Vector3 Backward() const { return Vector3(_31, _32, _33); } + + void Backward(const Vector3& v) + { + _31 = v.x; + _32 = v.y; + _33 = v.z; + } + + Vector3 Translation() const { return Vector3(_41, _42, _43); } + + void Translation(const Vector3& v) + { + _41 = v.x; + _42 = v.y; + _43 = v.z; + } - explicit Matrix(_In_reads_(16) const float *pArray) : XMFLOAT4X4(pArray) {} - Matrix( CXMMATRIX M ) { XMStoreFloat4x4( this, M ); } - - operator XMMATRIX() const { return XMLoadFloat4x4( this ); } - - // Comparison operators - bool operator == ( const Matrix& M ) const; - bool operator != ( const Matrix& M ) const; - - // Assignment operators - Matrix& operator= (const Matrix& M) { memcpy_s( this, sizeof(float)*16, &M, sizeof(float)*16 ); return *this; } - Matrix& operator= (const XMFLOAT4X4& M) { memcpy_s( this, sizeof(float)*16, &M, sizeof(XMFLOAT4X4) ); return *this; } - Matrix& operator= (const XMFLOAT3X3& M); - Matrix& operator= (const XMFLOAT4X3& M); - Matrix& operator+= (const Matrix& M); - Matrix& operator-= (const Matrix& M); - Matrix& operator*= (const Matrix& M); - Matrix& operator*= (float S); - Matrix& operator/= (float S); - - Matrix& operator/= (const Matrix& M); - // Element-wise divide - - // Unary operators - Matrix operator+ () const { return *this; } - Matrix operator- () const; - - // Properties - Vector3 Up() const { return Vector3( _21, _22, _23); } - void Up( const Vector3& v ) { _21 = v.x; _22 = v.y; _23 = v.z; } - - Vector3 Down() const { return Vector3( -_21, -_22, -_23); } - void Down( const Vector3& v ) { _21 = -v.x; _22 = -v.y; _23 = -v.z; } - - Vector3 Right() const { return Vector3( _11, _12, _13 ); } - void Right( const Vector3& v ) { _11 = v.x; _12 = v.y; _13 = v.z; } - - Vector3 Left() const { return Vector3( -_11, -_12, -_13 ); } - void Left( const Vector3& v ) { _11 = -v.x; _12 = -v.y; _13 = -v.z; } - - Vector3 Forward() const { return Vector3( -_31, -_32, -_33 ); } - void Forward( const Vector3& v ) { _31 = -v.x; _32 = -v.y; _33 = -v.z; } - - Vector3 Backward() const { return Vector3( _31, _32, _33 ); } - void Backward( const Vector3& v ) { _31 = v.x; _32 = v.y; _33 = v.z; } - - Vector3 Translation() const { return Vector3( _41, _42, _43 ); } - void Translation( const Vector3& v ) { _41 = v.x; _42 = v.y; _43 = v.z; } - - // Matrix operations - bool Decompose( Vector3& scale, Quaternion& rotation, Vector3& translation ); - - Matrix Transpose() const; - void Transpose( Matrix& result ) const; - - Matrix Invert() const; - void Invert( Matrix& result ) const; - - float Determinant() const; - - // Static functions - static Matrix CreateBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp, _In_opt_ const Vector3* cameraForward = nullptr ); - - static Matrix CreateConstrainedBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& rotateAxis, - _In_opt_ const Vector3* cameraForward = nullptr, _In_opt_ const Vector3* objectForward = nullptr); - - static Matrix CreateTranslation( const Vector3& position ); - static Matrix CreateTranslation( float x, float y, float z ); - - static Matrix CreateScale( const Vector3& scales ); - static Matrix CreateScale( float xs, float ys, float zs ); - static Matrix CreateScale( float scale ); - - static Matrix CreateRotationX( float radians ); - static Matrix CreateRotationY( float radians ); - static Matrix CreateRotationZ( float radians ); - - static Matrix CreateFromAxisAngle( const Vector3& axis, float angle ); - - static Matrix CreatePerspectiveFieldOfView( float fov, float aspectRatio, float nearPlane, float farPlane ); - static Matrix CreatePerspective( float width, float height, float nearPlane, float farPlane ); - static Matrix CreatePerspectiveOffCenter( float left, float right, float bottom, float top, float nearPlane, float farPlane ); - static Matrix CreateOrthographic( float width, float height, float zNearPlane, float zFarPlane ); - static Matrix CreateOrthographicOffCenter( float left, float right, float bottom, float top, float zNearPlane, float zFarPlane ); - - static Matrix CreateLookAt( const Vector3& position, const Vector3& target, const Vector3& up ); - static Matrix CreateWorld( const Vector3& position, const Vector3& forward, const Vector3& up ); - - static Matrix CreateFromQuaternion( const Quaternion& quat ); - - static Matrix CreateFromYawPitchRoll( float yaw, float pitch, float roll ); - - static Matrix CreateShadow( const Vector3& lightDir, const Plane& plane ); - - static Matrix CreateReflection( const Plane& plane ); - - static void Lerp( const Matrix& M1, const Matrix& M2, float t, Matrix& result ); - static Matrix Lerp( const Matrix& M1, const Matrix& M2, float t ); - - static void Transform( const Matrix& M, const Quaternion& rotation, Matrix& result ); - static Matrix Transform( const Matrix& M, const Quaternion& rotation ); - - // Constants - static const Matrix Identity; -}; - -// Binary operators -Matrix operator+ (const Matrix& M1, const Matrix& M2); -Matrix operator- (const Matrix& M1, const Matrix& M2); -Matrix operator* (const Matrix& M1, const Matrix& M2); -Matrix operator* (const Matrix& M, float S); -Matrix operator/ (const Matrix& M, float S); -Matrix operator/ (const Matrix& M1, const Matrix& M2); - // Element-wise divide -Matrix operator* (float S, const Matrix& M); - - -//----------------------------------------------------------------------------- -// Plane -struct Plane : public XMFLOAT4 -{ - Plane() : XMFLOAT4(0.f, 1.f, 0.f, 0.f) {} - Plane(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w) {} - Plane(const Vector3& normal, float d) : XMFLOAT4(normal.x, normal.y, normal.z, d) {} - Plane(const Vector3& point1, const Vector3& point2, const Vector3& point3 ); - Plane(const Vector3& point, const Vector3& normal); - explicit Plane(const Vector4& v) : XMFLOAT4(v.x, v.y, v.z, v.w) {} - explicit Plane(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {} - Plane(FXMVECTOR V) { XMStoreFloat4( this, V ); } - Plane(const XMFLOAT4& p) { this->x = p.x; this->y = p.y; this->z = p.z; this->w = p.w; } - - operator XMVECTOR() const { return XMLoadFloat4( this ); } - - // Comparison operators - bool operator == ( const Plane& p ) const; - bool operator != ( const Plane& p ) const; - - // Assignment operators - Plane& operator= (const Plane& p) { x = p.x; y = p.y; z = p.z; w = p.w; return *this; } - Plane& operator= (const XMFLOAT4& p) { x = p.x; y = p.y; z = p.z; w = p.w; return *this; } - - // Properties - Vector3 Normal() const { return Vector3( x, y, z ); } - void Normal( const Vector3& normal ) { x = normal.x; y = normal.y; z = normal.z; } - - float D() const { return w; } - void D(float d) { w = d; } - - // Plane operations - void Normalize(); - void Normalize( Plane& result ) const; - - float Dot( const Vector4& v ) const; - float DotCoordinate( const Vector3& position ) const; - float DotNormal( const Vector3& normal ) const; - - // Static functions - static void Transform( const Plane& plane, const Matrix& M, Plane& result ); - static Plane Transform( const Plane& plane, const Matrix& M ); - - static void Transform( const Plane& plane, const Quaternion& rotation, Plane& result ); - static Plane Transform( const Plane& plane, const Quaternion& rotation ); - // Input quaternion must be the inverse transpose of the transformation -}; - -//------------------------------------------------------------------------------ -// Quaternion -struct Quaternion : public XMFLOAT4 -{ - Quaternion() : XMFLOAT4(0, 0, 0, 1.f) {} - Quaternion( float _x, float _y, float _z, float _w ) : XMFLOAT4(_x, _y, _z, _w) {} - Quaternion( const Vector3& v, float scalar ) : XMFLOAT4( v.x, v.y, v.z, scalar ) {} - explicit Quaternion( const Vector4& v ) : XMFLOAT4( v.x, v.y, v.z, v.w ) {} - explicit Quaternion(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {} - Quaternion(FXMVECTOR V) { XMStoreFloat4( this, V ); } - Quaternion(const XMFLOAT4& q) { this->x = q.x; this->y = q.y; this->z = q.z; this->w = q.w; } - - operator XMVECTOR() const { return XMLoadFloat4( this ); } - - // Comparison operators - bool operator == ( const Quaternion& q ) const; - bool operator != ( const Quaternion& q ) const; - - // Assignment operators - Quaternion& operator= (const Quaternion& q) { x = q.x; y = q.y; z = q.z; w = q.w; return *this; } - Quaternion& operator= (const XMFLOAT4& q) { x = q.x; y = q.y; z = q.z; w = q.w; return *this; } - Quaternion& operator+= (const Quaternion& q); - Quaternion& operator-= (const Quaternion& q); - Quaternion& operator*= (const Quaternion& q); - Quaternion& operator*= (float S); - Quaternion& operator/= (const Quaternion& q); - - // Unary operators - Quaternion operator+ () const { return *this; } - Quaternion operator- () const; - - // Quaternion operations - float Length() const; - float LengthSquared() const; - - void Normalize(); - void Normalize( Quaternion& result ) const; - - void Conjugate(); - void Conjugate( Quaternion& result ) const; - - void Inverse( Quaternion& result ) const; - - float Dot( const Quaternion& Q ) const; - - // Static functions - static Quaternion CreateFromAxisAngle( const Vector3& axis, float angle ); - static Quaternion CreateFromYawPitchRoll( float yaw, float pitch, float roll ); - static Quaternion CreateFromRotationMatrix( const Matrix& M ); - - static void Lerp( const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result ); - static Quaternion Lerp( const Quaternion& q1, const Quaternion& q2, float t ); - - static void Slerp( const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result ); - static Quaternion Slerp( const Quaternion& q1, const Quaternion& q2, float t ); - - static void Concatenate( const Quaternion& q1, const Quaternion& q2, Quaternion& result ); - static Quaternion Concatenate( const Quaternion& q1, const Quaternion& q2 ); - - // Constants - static const Quaternion Identity; -}; - -// Binary operators -Quaternion operator+ (const Quaternion& Q1, const Quaternion& Q2); -Quaternion operator- (const Quaternion& Q1, const Quaternion& Q2); -Quaternion operator* (const Quaternion& Q1, const Quaternion& Q2); -Quaternion operator* (const Quaternion& Q, float S); -Quaternion operator/ (const Quaternion& Q1, const Quaternion& Q2); -Quaternion operator* (float S, const Quaternion& Q); - -//------------------------------------------------------------------------------ -// Color -struct Color : public XMFLOAT4 -{ - Color() : XMFLOAT4(0, 0, 0, 1.f) {} - Color( float _r, float _g, float _b ) : XMFLOAT4(_r, _g, _b, 1.f) {} - Color( float _r, float _g, float _b, float _a ) : XMFLOAT4(_r, _g, _b, _a) {} - explicit Color( const Vector3& clr ) : XMFLOAT4( clr.x, clr.y, clr.z, 1.f ) {} - explicit Color( const Vector4& clr ) : XMFLOAT4( clr.x, clr.y, clr.z, clr.w ) {} - explicit Color(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {} - Color(FXMVECTOR V) { XMStoreFloat4( this, V ); } - Color(const XMFLOAT4& c) { this->x = c.x; this->y = c.y; this->z = c.z; this->w = c.w; } - - explicit Color( const DirectX::PackedVector::XMCOLOR& Packed ); - // BGRA Direct3D 9 D3DCOLOR packed color - - explicit Color( const DirectX::PackedVector::XMUBYTEN4& Packed ); - // RGBA XNA Game Studio packed color - - operator XMVECTOR() const { return XMLoadFloat4( this ); } - operator const float*() const { return reinterpret_cast(this); } - - // Comparison operators - bool operator == ( const Color& c ) const; - bool operator != ( const Color& c ) const; - - // Assignment operators - Color& operator= (const Color& c) { x = c.x; y = c.y; z = c.z; w = c.w; return *this; } - Color& operator= (const XMFLOAT4& c) { x = c.x; y = c.y; z = c.z; w = c.w; return *this; } - Color& operator= (const DirectX::PackedVector::XMCOLOR& Packed); - Color& operator= (const DirectX::PackedVector::XMUBYTEN4& Packed); - Color& operator+= (const Color& c); - Color& operator-= (const Color& c); - Color& operator*= (const Color& c); - Color& operator*= (float S); - Color& operator/= (const Color& c); - - // Unary operators - Color operator+ () const { return *this; } - Color operator- () const; - - // Properties - float R() const { return x; } - void R(float r) { x = r; } - - float G() const { return y; } - void G(float g) { y = g; } - - float B() const { return z; } - void B(float b) { z = b; } - - float A() const { return w; } - void A(float a) { w = a; } - - // Color operations - DirectX::PackedVector::XMCOLOR BGRA() const; - DirectX::PackedVector::XMUBYTEN4 RGBA() const; - - Vector3 ToVector3() const; - Vector4 ToVector4() const; - - void Negate(); - void Negate( Color& result ) const; - - void Saturate(); - void Saturate( Color& result ) const; - - void Premultiply(); - void Premultiply( Color& result ) const; - - void AdjustSaturation( float sat ); - void AdjustSaturation( float sat, Color& result ) const; - - void AdjustContrast( float contrast ); - void AdjustContrast( float contrast, Color& result ) const; - - // Static functions - static void Modulate( const Color& c1, const Color& c2, Color& result ); - static Color Modulate( const Color& c1, const Color& c2 ); - - static void Lerp( const Color& c1, const Color& c2, float t, Color& result ); - static Color Lerp( const Color& c1, const Color& c2, float t ); -}; - -// Binary operators -Color operator+ (const Color& C1, const Color& C2); -Color operator- (const Color& C1, const Color& C2); -Color operator* (const Color& C1, const Color& C2); -Color operator* (const Color& C, float S); -Color operator/ (const Color& C1, const Color& C2); -Color operator* (float S, const Color& C); - -//------------------------------------------------------------------------------ -// Ray -class Ray -{ -public: - Vector3 position; - Vector3 direction; - - Ray() : position(0,0,0), direction(0,0,1) {} - Ray( const Vector3& pos, const Vector3& dir ) : position(pos), direction(dir) {} - - // Comparison operators - bool operator == ( const Ray& r ) const; - bool operator != ( const Ray& r ) const; - - // Ray operations - bool Intersects( const BoundingSphere& sphere, _Out_ float& Dist ) const; - bool Intersects( const BoundingBox& box, _Out_ float& Dist ) const; - bool Intersects( const Vector3& tri0, const Vector3& tri1, const Vector3& tri2, _Out_ float& Dist ) const; - bool Intersects( const Plane& plane, _Out_ float& Dist ) const; -}; - -//------------------------------------------------------------------------------ -// Viewport -class Viewport -{ -public: - float x; - float y; - float width; - float height; - float minDepth; - float maxDepth; - - Viewport() : - x(0.f), y(0.f), width(0.f), height(0.f), minDepth(0.f), maxDepth(1.f) {} - Viewport( float ix, float iy, float iw, float ih, float iminz = 0.f, float imaxz = 1.f ) : - x(ix), y(iy), width(iw), height(ih), minDepth(iminz), maxDepth(imaxz) {} - explicit Viewport(const RECT& rct) : - x(float(rct.left)), y(float(rct.top)), - width(float(rct.right - rct.left)), - height(float(rct.bottom - rct.top)), - minDepth(0.f), maxDepth(1.f) {} - explicit Viewport(const D3D11_VIEWPORT& vp) : - x(vp.TopLeftX), y(vp.TopLeftY), - width(vp.Width), height(vp.Height), - minDepth(vp.MinDepth), maxDepth(vp.MaxDepth) {} - - // Direct3D 11 interop - operator D3D11_VIEWPORT() { return *reinterpret_cast(this); } - const D3D11_VIEWPORT* Get11() const { return reinterpret_cast(this); } - - // Comparison operators - bool operator == ( const Viewport& vp ) const; - bool operator != ( const Viewport& vp ) const; - - // Assignment operators - Viewport& operator= (const Viewport& vp); - Viewport& operator= (const RECT& rct); - Viewport& operator= (const D3D11_VIEWPORT& vp); - - // Viewport operations - float AspectRatio() const; - - Vector3 Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world ) const; - void Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result ) const; - - Vector3 Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world ) const; - void Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result ) const; - - // Static methods - static RECT __cdecl ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UINT backBufferHeight, int outputWidth, int outputHeight); - static RECT __cdecl ComputeTitleSafeArea(UINT backBufferWidth, UINT backBufferHeight); -}; + // Matrix operations + bool Decompose(Vector3& scale, Quaternion& rotation, Vector3& translation); + + Matrix Transpose() const; + void Transpose(Matrix& result) const; + + Matrix Invert() const; + void Invert(Matrix& result) const; + + float Determinant() const; + + // Static functions + static Matrix CreateBillboard(const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp, + _In_opt_ const Vector3* cameraForward = nullptr); + + static Matrix CreateConstrainedBillboard(const Vector3& object, const Vector3& cameraPosition, + const Vector3& rotateAxis, + _In_opt_ const Vector3* cameraForward = nullptr, + _In_opt_ const Vector3* objectForward = nullptr); + + static Matrix CreateTranslation(const Vector3& position); + static Matrix CreateTranslation(float x, float y, float z); + + static Matrix CreateScale(const Vector3& scales); + static Matrix CreateScale(float xs, float ys, float zs); + static Matrix CreateScale(float scale); + + static Matrix CreateRotationX(float radians); + static Matrix CreateRotationY(float radians); + static Matrix CreateRotationZ(float radians); + + static Matrix CreateFromAxisAngle(const Vector3& axis, float angle); + + static Matrix CreatePerspectiveFieldOfView(float fov, float aspectRatio, float nearPlane, float farPlane); + static Matrix CreatePerspective(float width, float height, float nearPlane, float farPlane); + static Matrix CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlane, + float farPlane); + static Matrix CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane); + static Matrix CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, + float zFarPlane); + + static Matrix CreateLookAt(const Vector3& position, const Vector3& target, const Vector3& up); + static Matrix CreateWorld(const Vector3& position, const Vector3& forward, const Vector3& up); + + static Matrix CreateFromQuaternion(const Quaternion& quat); + + static Matrix CreateFromYawPitchRoll(float yaw, float pitch, float roll); + + static Matrix CreateShadow(const Vector3& lightDir, const Plane& plane); + + static Matrix CreateReflection(const Plane& plane); + + static void Lerp(const Matrix& M1, const Matrix& M2, float t, Matrix& result); + static Matrix Lerp(const Matrix& M1, const Matrix& M2, float t); + + static void Transform(const Matrix& M, const Quaternion& rotation, Matrix& result); + static Matrix Transform(const Matrix& M, const Quaternion& rotation); + + // Constants + static const Matrix Identity; + }; + + // Binary operators + Matrix operator+(const Matrix& M1, const Matrix& M2); + Matrix operator-(const Matrix& M1, const Matrix& M2); + Matrix operator*(const Matrix& M1, const Matrix& M2); + Matrix operator*(const Matrix& M, float S); + Matrix operator/(const Matrix& M, float S); + Matrix operator/(const Matrix& M1, const Matrix& M2); + // Element-wise divide + Matrix operator*(float S, const Matrix& M); + + + //----------------------------------------------------------------------------- + // Plane + struct Plane : public XMFLOAT4 + { + Plane() : XMFLOAT4(0.f, 1.f, 0.f, 0.f) + { + } + + Plane(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w) + { + } + + Plane(const Vector3& normal, float d) : XMFLOAT4(normal.x, normal.y, normal.z, d) + { + } + + Plane(const Vector3& point1, const Vector3& point2, const Vector3& point3); + Plane(const Vector3& point, const Vector3& normal); + + explicit Plane(const Vector4& v) : XMFLOAT4(v.x, v.y, v.z, v.w) + { + } + + explicit Plane(_In_reads_(4) const float* pArray) : XMFLOAT4(pArray) + { + } + + Plane(FXMVECTOR V) { XMStoreFloat4(this, V); } + + Plane(const XMFLOAT4& p) + { + this->x = p.x; + this->y = p.y; + this->z = p.z; + this->w = p.w; + } + + operator XMVECTOR() const { return XMLoadFloat4(this); } + + // Comparison operators + bool operator ==(const Plane& p) const; + bool operator !=(const Plane& p) const; + + // Assignment operators + Plane& operator=(const Plane& p) + { + x = p.x; + y = p.y; + z = p.z; + w = p.w; + return *this; + } + + Plane& operator=(const XMFLOAT4& p) + { + x = p.x; + y = p.y; + z = p.z; + w = p.w; + return *this; + } + + // Properties + Vector3 Normal() const { return Vector3(x, y, z); } + + void Normal(const Vector3& normal) + { + x = normal.x; + y = normal.y; + z = normal.z; + } + + float D() const { return w; } + void D(float d) { w = d; } + + // Plane operations + void Normalize(); + void Normalize(Plane& result) const; + + float Dot(const Vector4& v) const; + float DotCoordinate(const Vector3& position) const; + float DotNormal(const Vector3& normal) const; + + // Static functions + static void Transform(const Plane& plane, const Matrix& M, Plane& result); + static Plane Transform(const Plane& plane, const Matrix& M); + + static void Transform(const Plane& plane, const Quaternion& rotation, Plane& result); + static Plane Transform(const Plane& plane, const Quaternion& rotation); + // Input quaternion must be the inverse transpose of the transformation + }; + + //------------------------------------------------------------------------------ + // Quaternion + struct Quaternion : public XMFLOAT4 + { + Quaternion() : XMFLOAT4(0, 0, 0, 1.f) + { + } + + Quaternion(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w) + { + } + + Quaternion(const Vector3& v, float scalar) : XMFLOAT4(v.x, v.y, v.z, scalar) + { + } + + explicit Quaternion(const Vector4& v) : XMFLOAT4(v.x, v.y, v.z, v.w) + { + } + + explicit Quaternion(_In_reads_(4) const float* pArray) : XMFLOAT4(pArray) + { + } + + Quaternion(FXMVECTOR V) { XMStoreFloat4(this, V); } + + Quaternion(const XMFLOAT4& q) + { + this->x = q.x; + this->y = q.y; + this->z = q.z; + this->w = q.w; + } + + operator XMVECTOR() const { return XMLoadFloat4(this); } + + // Comparison operators + bool operator ==(const Quaternion& q) const; + bool operator !=(const Quaternion& q) const; + + // Assignment operators + Quaternion& operator=(const Quaternion& q) + { + x = q.x; + y = q.y; + z = q.z; + w = q.w; + return *this; + } + + Quaternion& operator=(const XMFLOAT4& q) + { + x = q.x; + y = q.y; + z = q.z; + w = q.w; + return *this; + } + + Quaternion& operator+=(const Quaternion& q); + Quaternion& operator-=(const Quaternion& q); + Quaternion& operator*=(const Quaternion& q); + Quaternion& operator*=(float S); + Quaternion& operator/=(const Quaternion& q); + + // Unary operators + Quaternion operator+() const { return *this; } + Quaternion operator-() const; + + // Quaternion operations + float Length() const; + float LengthSquared() const; + + void Normalize(); + void Normalize(Quaternion& result) const; + + void Conjugate(); + void Conjugate(Quaternion& result) const; + + void Inverse(Quaternion& result) const; + + float Dot(const Quaternion& Q) const; + + // Static functions + static Quaternion CreateFromAxisAngle(const Vector3& axis, float angle); + static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll); + static Quaternion CreateFromRotationMatrix(const Matrix& M); + + static void Lerp(const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result); + static Quaternion Lerp(const Quaternion& q1, const Quaternion& q2, float t); + + static void Slerp(const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result); + static Quaternion Slerp(const Quaternion& q1, const Quaternion& q2, float t); + + static void Concatenate(const Quaternion& q1, const Quaternion& q2, Quaternion& result); + static Quaternion Concatenate(const Quaternion& q1, const Quaternion& q2); + + // Constants + static const Quaternion Identity; + }; + + // Binary operators + Quaternion operator+(const Quaternion& Q1, const Quaternion& Q2); + Quaternion operator-(const Quaternion& Q1, const Quaternion& Q2); + Quaternion operator*(const Quaternion& Q1, const Quaternion& Q2); + Quaternion operator*(const Quaternion& Q, float S); + Quaternion operator/(const Quaternion& Q1, const Quaternion& Q2); + Quaternion operator*(float S, const Quaternion& Q); + + //------------------------------------------------------------------------------ + // Color + struct Color : public XMFLOAT4 + { + Color() : XMFLOAT4(0, 0, 0, 1.f) + { + } + + Color(float _r, float _g, float _b) : XMFLOAT4(_r, _g, _b, 1.f) + { + } + + Color(float _r, float _g, float _b, float _a) : XMFLOAT4(_r, _g, _b, _a) + { + } + + explicit Color(const Vector3& clr) : XMFLOAT4(clr.x, clr.y, clr.z, 1.f) + { + } + + explicit Color(const Vector4& clr) : XMFLOAT4(clr.x, clr.y, clr.z, clr.w) + { + } + + explicit Color(_In_reads_(4) const float* pArray) : XMFLOAT4(pArray) + { + } + + Color(FXMVECTOR V) { XMStoreFloat4(this, V); } + + Color(const XMFLOAT4& c) + { + this->x = c.x; + this->y = c.y; + this->z = c.z; + this->w = c.w; + } + + explicit Color(const DirectX::PackedVector::XMCOLOR& Packed); + // BGRA Direct3D 9 D3DCOLOR packed color + + explicit Color(const DirectX::PackedVector::XMUBYTEN4& Packed); + // RGBA XNA Game Studio packed color + + operator XMVECTOR() const { return XMLoadFloat4(this); } + operator const float*() const { return reinterpret_cast(this); } + + // Comparison operators + bool operator ==(const Color& c) const; + bool operator !=(const Color& c) const; + + // Assignment operators + Color& operator=(const Color& c) + { + x = c.x; + y = c.y; + z = c.z; + w = c.w; + return *this; + } + + Color& operator=(const XMFLOAT4& c) + { + x = c.x; + y = c.y; + z = c.z; + w = c.w; + return *this; + } + + Color& operator=(const DirectX::PackedVector::XMCOLOR& Packed); + Color& operator=(const DirectX::PackedVector::XMUBYTEN4& Packed); + Color& operator+=(const Color& c); + Color& operator-=(const Color& c); + Color& operator*=(const Color& c); + Color& operator*=(float S); + Color& operator/=(const Color& c); + + // Unary operators + Color operator+() const { return *this; } + Color operator-() const; + + // Properties + float R() const { return x; } + void R(float r) { x = r; } + + float G() const { return y; } + void G(float g) { y = g; } + + float B() const { return z; } + void B(float b) { z = b; } + + float A() const { return w; } + void A(float a) { w = a; } + + // Color operations + DirectX::PackedVector::XMCOLOR BGRA() const; + DirectX::PackedVector::XMUBYTEN4 RGBA() const; + + Vector3 ToVector3() const; + Vector4 ToVector4() const; + + void Negate(); + void Negate(Color& result) const; + + void Saturate(); + void Saturate(Color& result) const; + + void Premultiply(); + void Premultiply(Color& result) const; + + void AdjustSaturation(float sat); + void AdjustSaturation(float sat, Color& result) const; + + void AdjustContrast(float contrast); + void AdjustContrast(float contrast, Color& result) const; + + // Static functions + static void Modulate(const Color& c1, const Color& c2, Color& result); + static Color Modulate(const Color& c1, const Color& c2); + + static void Lerp(const Color& c1, const Color& c2, float t, Color& result); + static Color Lerp(const Color& c1, const Color& c2, float t); + }; + + // Binary operators + Color operator+(const Color& C1, const Color& C2); + Color operator-(const Color& C1, const Color& C2); + Color operator*(const Color& C1, const Color& C2); + Color operator*(const Color& C, float S); + Color operator/(const Color& C1, const Color& C2); + Color operator*(float S, const Color& C); + + //------------------------------------------------------------------------------ + // Ray + class Ray + { + public: + Vector3 position; + Vector3 direction; + + Ray() : position(0, 0, 0), direction(0, 0, 1) + { + } + + Ray(const Vector3& pos, const Vector3& dir) : position(pos), direction(dir) + { + } + + // Comparison operators + bool operator ==(const Ray& r) const; + bool operator !=(const Ray& r) const; + + // Ray operations + bool Intersects(const BoundingSphere& sphere, _Out_ float& Dist) const; + bool Intersects(const BoundingBox& box, _Out_ float& Dist) const; + bool Intersects(const Vector3& tri0, const Vector3& tri1, const Vector3& tri2, _Out_ float& Dist) const; + bool Intersects(const Plane& plane, _Out_ float& Dist) const; + }; + + //------------------------------------------------------------------------------ + // Viewport + class Viewport + { + public: + float x; + float y; + float width; + float height; + float minDepth; + float maxDepth; + + Viewport() : + x(0.f), y(0.f), width(0.f), height(0.f), minDepth(0.f), maxDepth(1.f) + { + } + + Viewport(float ix, float iy, float iw, float ih, float iminz = 0.f, float imaxz = 1.f) : + x(ix), y(iy), width(iw), height(ih), minDepth(iminz), maxDepth(imaxz) + { + } + + explicit Viewport(const RECT& rct) : + x(float(rct.left)), y(float(rct.top)), + width(float(rct.right - rct.left)), + height(float(rct.bottom - rct.top)), + minDepth(0.f), maxDepth(1.f) + { + } + + explicit Viewport(const D3D11_VIEWPORT& vp) : + x(vp.TopLeftX), y(vp.TopLeftY), + width(vp.Width), height(vp.Height), + minDepth(vp.MinDepth), maxDepth(vp.MaxDepth) + { + } + + // Direct3D 11 interop + operator D3D11_VIEWPORT() { return *reinterpret_cast(this); } + const D3D11_VIEWPORT* Get11() const { return reinterpret_cast(this); } + + // Comparison operators + bool operator ==(const Viewport& vp) const; + bool operator !=(const Viewport& vp) const; + + // Assignment operators + Viewport& operator=(const Viewport& vp); + Viewport& operator=(const RECT& rct); + Viewport& operator=(const D3D11_VIEWPORT& vp); + + // Viewport operations + float AspectRatio() const; + + Vector3 Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world) const; + void Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, + Vector3& result) const; + + Vector3 Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world) const; + void Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, + Vector3& result) const; + + // Static methods + static RECT __cdecl ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UINT backBufferHeight, + int outputWidth, int outputHeight); + static RECT __cdecl ComputeTitleSafeArea(UINT backBufferWidth, UINT backBufferHeight); + }; #include "SimpleMath.inl" - -}; // namespace SimpleMath - + }; // namespace SimpleMath }; // namespace DirectX //------------------------------------------------------------------------------ // Support for SimpleMath and Standard C++ Library containers namespace std { + template <> + struct less + { + bool operator()(const DirectX::SimpleMath::Vector2& V1, const DirectX::SimpleMath::Vector2& V2) const + { + return ((V1.x < V2.x) || ((V1.x == V2.x) && (V1.y < V2.y))); + } + }; - template<> struct less - { - bool operator()(const DirectX::SimpleMath::Vector2& V1, const DirectX::SimpleMath::Vector2& V2) const - { - return ( (V1.x < V2.x) || ((V1.x == V2.x) && (V1.y < V2.y)) ); - } - }; + template <> + struct less + { + bool operator()(const DirectX::SimpleMath::Vector3& V1, const DirectX::SimpleMath::Vector3& V2) const + { + return ((V1.x < V2.x) + || ((V1.x == V2.x) && (V1.y < V2.y)) + || ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z))); + } + }; - template<> struct less - { - bool operator()(const DirectX::SimpleMath::Vector3& V1, const DirectX::SimpleMath::Vector3& V2) const - { - return ( (V1.x < V2.x) - || ((V1.x == V2.x) && (V1.y < V2.y)) - || ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z)) ); - } - }; + template <> + struct less + { + bool operator()(const DirectX::SimpleMath::Vector4& V1, const DirectX::SimpleMath::Vector4& V2) const + { + return ((V1.x < V2.x) + || ((V1.x == V2.x) && (V1.y < V2.y)) + || ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z)) + || ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z) && (V1.w < V2.w))); + } + }; - template<> struct less - { - bool operator()(const DirectX::SimpleMath::Vector4& V1, const DirectX::SimpleMath::Vector4& V2) const - { - return ( (V1.x < V2.x) - || ((V1.x == V2.x) && (V1.y < V2.y)) - || ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z)) - || ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z) && (V1.w < V2.w)) ); - } - }; + template <> + struct less + { + bool operator()(const DirectX::SimpleMath::Matrix& M1, const DirectX::SimpleMath::Matrix& M2) const + { + if (M1._11 != M2._11) return M1._11 < M2._11; + if (M1._12 != M2._12) return M1._12 < M2._12; + if (M1._13 != M2._13) return M1._13 < M2._13; + if (M1._14 != M2._14) return M1._14 < M2._14; + if (M1._21 != M2._21) return M1._21 < M2._21; + if (M1._22 != M2._22) return M1._22 < M2._22; + if (M1._23 != M2._23) return M1._23 < M2._23; + if (M1._24 != M2._24) return M1._24 < M2._24; + if (M1._31 != M2._31) return M1._31 < M2._31; + if (M1._32 != M2._32) return M1._32 < M2._32; + if (M1._33 != M2._33) return M1._33 < M2._33; + if (M1._34 != M2._34) return M1._34 < M2._34; + if (M1._41 != M2._41) return M1._41 < M2._41; + if (M1._42 != M2._42) return M1._42 < M2._42; + if (M1._43 != M2._43) return M1._43 < M2._43; + if (M1._44 != M2._44) return M1._44 < M2._44; - template<> struct less - { - bool operator()(const DirectX::SimpleMath::Matrix& M1, const DirectX::SimpleMath::Matrix& M2) const - { - if (M1._11 != M2._11) return M1._11 < M2._11; - if (M1._12 != M2._12) return M1._12 < M2._12; - if (M1._13 != M2._13) return M1._13 < M2._13; - if (M1._14 != M2._14) return M1._14 < M2._14; - if (M1._21 != M2._21) return M1._21 < M2._21; - if (M1._22 != M2._22) return M1._22 < M2._22; - if (M1._23 != M2._23) return M1._23 < M2._23; - if (M1._24 != M2._24) return M1._24 < M2._24; - if (M1._31 != M2._31) return M1._31 < M2._31; - if (M1._32 != M2._32) return M1._32 < M2._32; - if (M1._33 != M2._33) return M1._33 < M2._33; - if (M1._34 != M2._34) return M1._34 < M2._34; - if (M1._41 != M2._41) return M1._41 < M2._41; - if (M1._42 != M2._42) return M1._42 < M2._42; - if (M1._43 != M2._43) return M1._43 < M2._43; - if (M1._44 != M2._44) return M1._44 < M2._44; + return false; + } + }; - return false; - } - }; + template <> + struct less + { + bool operator()(const DirectX::SimpleMath::Plane& P1, const DirectX::SimpleMath::Plane& P2) const + { + return ((P1.x < P2.x) + || ((P1.x == P2.x) && (P1.y < P2.y)) + || ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z < P2.z)) + || ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z == P2.z) && (P1.w < P2.w))); + } + }; - template<> struct less - { - bool operator()(const DirectX::SimpleMath::Plane& P1, const DirectX::SimpleMath::Plane& P2) const - { - return ( (P1.x < P2.x) - || ((P1.x == P2.x) && (P1.y < P2.y)) - || ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z < P2.z)) - || ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z == P2.z) && (P1.w < P2.w)) ); - } - }; + template <> + struct less + { + bool operator()(const DirectX::SimpleMath::Quaternion& Q1, const DirectX::SimpleMath::Quaternion& Q2) const + { + return ((Q1.x < Q2.x) + || ((Q1.x == Q2.x) && (Q1.y < Q2.y)) + || ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z < Q2.z)) + || ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z == Q2.z) && (Q1.w < Q2.w))); + } + }; - template<> struct less - { - bool operator()(const DirectX::SimpleMath::Quaternion& Q1, const DirectX::SimpleMath::Quaternion& Q2) const - { - return ( (Q1.x < Q2.x) - || ((Q1.x == Q2.x) && (Q1.y < Q2.y)) - || ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z < Q2.z)) - || ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z == Q2.z) && (Q1.w < Q2.w)) ); - } - }; + template <> + struct less + { + bool operator()(const DirectX::SimpleMath::Color& C1, const DirectX::SimpleMath::Color& C2) const + { + return ((C1.x < C2.x) + || ((C1.x == C2.x) && (C1.y < C2.y)) + || ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z < C2.z)) + || ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z == C2.z) && (C1.w < C2.w))); + } + }; - template<> struct less - { - bool operator()(const DirectX::SimpleMath::Color& C1, const DirectX::SimpleMath::Color& C2) const - { - return ( (C1.x < C2.x) - || ((C1.x == C2.x) && (C1.y < C2.y)) - || ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z < C2.z)) - || ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z == C2.z) && (C1.w < C2.w)) ); - } - }; + template <> + struct less + { + bool operator()(const DirectX::SimpleMath::Ray& R1, const DirectX::SimpleMath::Ray& R2) const + { + if (R1.position.x != R2.position.x) return R1.position.x < R2.position.x; + if (R1.position.y != R2.position.y) return R1.position.y < R2.position.y; + if (R1.position.z != R2.position.z) return R1.position.z < R2.position.z; - template<> struct less - { - bool operator()(const DirectX::SimpleMath::Ray& R1, const DirectX::SimpleMath::Ray& R2) const - { - if (R1.position.x != R2.position.x) return R1.position.x < R2.position.x; - if (R1.position.y != R2.position.y) return R1.position.y < R2.position.y; - if (R1.position.z != R2.position.z) return R1.position.z < R2.position.z; + if (R1.direction.x != R2.direction.x) return R1.direction.x < R2.direction.x; + if (R1.direction.y != R2.direction.y) return R1.direction.y < R2.direction.y; + if (R1.direction.z != R2.direction.z) return R1.direction.z < R2.direction.z; - if (R1.direction.x != R2.direction.x) return R1.direction.x < R2.direction.x; - if (R1.direction.y != R2.direction.y) return R1.direction.y < R2.direction.y; - if (R1.direction.z != R2.direction.z) return R1.direction.z < R2.direction.z; + return false; + } + }; - return false; - } - }; + template <> + struct less + { + bool operator()(const DirectX::SimpleMath::Viewport& vp1, const DirectX::SimpleMath::Viewport& vp2) const + { + if (vp1.x != vp2.x) return (vp1.x < vp2.x); + if (vp1.y != vp2.y) return (vp1.y < vp2.y); - template<> struct less - { - bool operator()(const DirectX::SimpleMath::Viewport& vp1, const DirectX::SimpleMath::Viewport& vp2) const - { - if (vp1.x != vp2.x) return (vp1.x < vp2.x); - if (vp1.y != vp2.y) return (vp1.y < vp2.y); + if (vp1.width != vp2.width) return (vp1.width < vp2.width); + if (vp1.height != vp2.height) return (vp1.height < vp2.height); - if (vp1.width != vp2.width) return (vp1.width < vp2.width); - if (vp1.height != vp2.height) return (vp1.height < vp2.height); - - if (vp1.minDepth != vp2.minDepth) return (vp1.minDepth < vp2.minDepth); - if (vp1.maxDepth != vp2.maxDepth) return (vp1.maxDepth < vp2.maxDepth); - - return false; - } - }; + if (vp1.minDepth != vp2.minDepth) return (vp1.minDepth < vp2.minDepth); + if (vp1.maxDepth != vp2.maxDepth) return (vp1.maxDepth < vp2.maxDepth); + return false; + } + }; } // namespace std diff --git a/Windows/DirectXTK/SimpleMath.inl b/Windows/DirectXTK/SimpleMath.inl index 0d719ec..9c4e48c 100644 --- a/Windows/DirectXTK/SimpleMath.inl +++ b/Windows/DirectXTK/SimpleMath.inl @@ -23,558 +23,564 @@ // Comparision operators //------------------------------------------------------------------------------ -inline bool Vector2::operator == ( const Vector2& V ) const +inline bool Vector2::operator ==(const Vector2& V) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR v2 = XMLoadFloat2( &V ); - return XMVector2Equal( v1, v2 ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR v2 = XMLoadFloat2(&V); + return XMVector2Equal(v1, v2); } -inline bool Vector2::operator != ( const Vector2& V ) const +inline bool Vector2::operator !=(const Vector2& V) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR v2 = XMLoadFloat2( &V ); - return XMVector2NotEqual( v1, v2 ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR v2 = XMLoadFloat2(&V); + return XMVector2NotEqual(v1, v2); } //------------------------------------------------------------------------------ // Assignment operators //------------------------------------------------------------------------------ -inline Vector2& Vector2::operator+= (const Vector2& V) +inline Vector2& Vector2::operator+=(const Vector2& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR v2 = XMLoadFloat2( &V ); - XMVECTOR X = XMVectorAdd(v1,v2); - XMStoreFloat2( this, X ); - return *this; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR v2 = XMLoadFloat2(&V); + XMVECTOR X = XMVectorAdd(v1, v2); + XMStoreFloat2(this, X); + return *this; } -inline Vector2& Vector2::operator-= (const Vector2& V) +inline Vector2& Vector2::operator-=(const Vector2& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR v2 = XMLoadFloat2( &V ); - XMVECTOR X = XMVectorSubtract(v1,v2); - XMStoreFloat2( this, X ); - return *this; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR v2 = XMLoadFloat2(&V); + XMVECTOR X = XMVectorSubtract(v1, v2); + XMStoreFloat2(this, X); + return *this; } -inline Vector2& Vector2::operator*= (const Vector2& V) +inline Vector2& Vector2::operator*=(const Vector2& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR v2 = XMLoadFloat2( &V ); - XMVECTOR X = XMVectorMultiply(v1,v2); - XMStoreFloat2( this, X ); - return *this; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR v2 = XMLoadFloat2(&V); + XMVECTOR X = XMVectorMultiply(v1, v2); + XMStoreFloat2(this, X); + return *this; } -inline Vector2& Vector2::operator*= (float S) +inline Vector2& Vector2::operator*=(float S) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR X = XMVectorScale(v1,S); - XMStoreFloat2( this, X ); - return *this; -} + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR X = XMVectorScale(v1, S); + XMStoreFloat2(this, X); + return *this; +} -inline Vector2& Vector2::operator/= (float S) +inline Vector2& Vector2::operator/=(float S) { - using namespace DirectX; - assert( S != 0.0f ); - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR X = XMVectorScale(v1, 1.f/S); - XMStoreFloat2( this, X ); - return *this; -} + using namespace DirectX; + assert(S != 0.0f); + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR X = XMVectorScale(v1, 1.f / S); + XMStoreFloat2(this, X); + return *this; +} //------------------------------------------------------------------------------ // Binary operators //------------------------------------------------------------------------------ -inline Vector2 operator+ (const Vector2& V1, const Vector2& V2) +inline Vector2 operator+(const Vector2& V1, const Vector2& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &V1 ); - XMVECTOR v2 = XMLoadFloat2( &V2 ); - XMVECTOR X = XMVectorAdd(v1,v2); - Vector2 R; - XMStoreFloat2( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&V1); + XMVECTOR v2 = XMLoadFloat2(&V2); + XMVECTOR X = XMVectorAdd(v1, v2); + Vector2 R; + XMStoreFloat2(&R, X); + return R; } -inline Vector2 operator- (const Vector2& V1, const Vector2& V2) +inline Vector2 operator-(const Vector2& V1, const Vector2& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &V1 ); - XMVECTOR v2 = XMLoadFloat2( &V2 ); - XMVECTOR X = XMVectorSubtract(v1,v2); - Vector2 R; - XMStoreFloat2( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&V1); + XMVECTOR v2 = XMLoadFloat2(&V2); + XMVECTOR X = XMVectorSubtract(v1, v2); + Vector2 R; + XMStoreFloat2(&R, X); + return R; } -inline Vector2 operator* (const Vector2& V1, const Vector2& V2) +inline Vector2 operator*(const Vector2& V1, const Vector2& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &V1 ); - XMVECTOR v2 = XMLoadFloat2( &V2 ); - XMVECTOR X = XMVectorMultiply(v1,v2); - Vector2 R; - XMStoreFloat2( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&V1); + XMVECTOR v2 = XMLoadFloat2(&V2); + XMVECTOR X = XMVectorMultiply(v1, v2); + Vector2 R; + XMStoreFloat2(&R, X); + return R; } -inline Vector2 operator* (const Vector2& V, float S) +inline Vector2 operator*(const Vector2& V, float S) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &V ); - XMVECTOR X = XMVectorScale(v1,S); - Vector2 R; - XMStoreFloat2( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&V); + XMVECTOR X = XMVectorScale(v1, S); + Vector2 R; + XMStoreFloat2(&R, X); + return R; } -inline Vector2 operator/ (const Vector2& V1, const Vector2& V2) +inline Vector2 operator/(const Vector2& V1, const Vector2& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &V1 ); - XMVECTOR v2 = XMLoadFloat2( &V2 ); - XMVECTOR X = XMVectorDivide(v1,v2); - Vector2 R; - XMStoreFloat2( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&V1); + XMVECTOR v2 = XMLoadFloat2(&V2); + XMVECTOR X = XMVectorDivide(v1, v2); + Vector2 R; + XMStoreFloat2(&R, X); + return R; } -inline Vector2 operator* (float S, const Vector2& V) +inline Vector2 operator*(float S, const Vector2& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &V ); - XMVECTOR X = XMVectorScale(v1,S); - Vector2 R; - XMStoreFloat2( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&V); + XMVECTOR X = XMVectorScale(v1, S); + Vector2 R; + XMStoreFloat2(&R, X); + return R; } //------------------------------------------------------------------------------ // Vector operations //------------------------------------------------------------------------------ -inline bool Vector2::InBounds( const Vector2& Bounds ) const +inline bool Vector2::InBounds(const Vector2& Bounds) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR v2 = XMLoadFloat2( &Bounds ); - return XMVector2InBounds( v1, v2 ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR v2 = XMLoadFloat2(&Bounds); + return XMVector2InBounds(v1, v2); } inline float Vector2::Length() const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR X = XMVector2Length( v1 ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR X = XMVector2Length(v1); + return XMVectorGetX(X); } inline float Vector2::LengthSquared() const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR X = XMVector2LengthSq( v1 ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR X = XMVector2LengthSq(v1); + return XMVectorGetX(X); } -inline float Vector2::Dot( const Vector2& V ) const +inline float Vector2::Dot(const Vector2& V) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR v2 = XMLoadFloat2( &V ); - XMVECTOR X = XMVector2Dot( v1, v2 ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR v2 = XMLoadFloat2(&V); + XMVECTOR X = XMVector2Dot(v1, v2); + return XMVectorGetX(X); } -inline void Vector2::Cross( const Vector2& V, Vector2& result ) const +inline void Vector2::Cross(const Vector2& V, Vector2& result) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR v2 = XMLoadFloat2( &V ); - XMVECTOR R = XMVector2Cross( v1, v2 ); - XMStoreFloat2( &result, R ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR v2 = XMLoadFloat2(&V); + XMVECTOR R = XMVector2Cross(v1, v2); + XMStoreFloat2(&result, R); } -inline Vector2 Vector2::Cross( const Vector2& V ) const +inline Vector2 Vector2::Cross(const Vector2& V) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR v2 = XMLoadFloat2( &V ); - XMVECTOR R = XMVector2Cross( v1, v2 ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR v2 = XMLoadFloat2(&V); + XMVECTOR R = XMVector2Cross(v1, v2); - Vector2 result; - XMStoreFloat2( &result, R ); - return result; + Vector2 result; + XMStoreFloat2(&result, R); + return result; } inline void Vector2::Normalize() { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR X = XMVector2Normalize( v1 ); - XMStoreFloat2( this, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR X = XMVector2Normalize(v1); + XMStoreFloat2(this, X); } -inline void Vector2::Normalize( Vector2& result ) const +inline void Vector2::Normalize(Vector2& result) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR X = XMVector2Normalize( v1 ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR X = XMVector2Normalize(v1); + XMStoreFloat2(&result, X); } -inline void Vector2::Clamp( const Vector2& vmin, const Vector2& vmax ) +inline void Vector2::Clamp(const Vector2& vmin, const Vector2& vmax) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR v2 = XMLoadFloat2( &vmin ); - XMVECTOR v3 = XMLoadFloat2( &vmax ); - XMVECTOR X = XMVectorClamp( v1, v2, v3 ); - XMStoreFloat2( this, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR v2 = XMLoadFloat2(&vmin); + XMVECTOR v3 = XMLoadFloat2(&vmax); + XMVECTOR X = XMVectorClamp(v1, v2, v3); + XMStoreFloat2(this, X); } -inline void Vector2::Clamp( const Vector2& vmin, const Vector2& vmax, Vector2& result ) const +inline void Vector2::Clamp(const Vector2& vmin, const Vector2& vmax, Vector2& result) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( this ); - XMVECTOR v2 = XMLoadFloat2( &vmin ); - XMVECTOR v3 = XMLoadFloat2( &vmax ); - XMVECTOR X = XMVectorClamp( v1, v2, v3 ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(this); + XMVECTOR v2 = XMLoadFloat2(&vmin); + XMVECTOR v3 = XMLoadFloat2(&vmax); + XMVECTOR X = XMVectorClamp(v1, v2, v3); + XMStoreFloat2(&result, X); } //------------------------------------------------------------------------------ // Static functions //------------------------------------------------------------------------------ -inline float Vector2::Distance( const Vector2& v1, const Vector2& v2 ) +inline float Vector2::Distance(const Vector2& v1, const Vector2& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR V = XMVectorSubtract( x2, x1 ); - XMVECTOR X = XMVector2Length( V ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR V = XMVectorSubtract(x2, x1); + XMVECTOR X = XMVector2Length(V); + return XMVectorGetX(X); } -inline float Vector2::DistanceSquared( const Vector2& v1, const Vector2& v2 ) +inline float Vector2::DistanceSquared(const Vector2& v1, const Vector2& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR V = XMVectorSubtract( x2, x1 ); - XMVECTOR X = XMVector2LengthSq( V ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR V = XMVectorSubtract(x2, x1); + XMVECTOR X = XMVector2LengthSq(V); + return XMVectorGetX(X); } -inline void Vector2::Min( const Vector2& v1, const Vector2& v2, Vector2& result ) +inline void Vector2::Min(const Vector2& v1, const Vector2& v2, Vector2& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR X = XMVectorMin( x1, x2 ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR X = XMVectorMin(x1, x2); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::Min( const Vector2& v1, const Vector2& v2 ) +inline Vector2 Vector2::Min(const Vector2& v1, const Vector2& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR X = XMVectorMin( x1, x2 ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR X = XMVectorMin(x1, x2); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } -inline void Vector2::Max( const Vector2& v1, const Vector2& v2, Vector2& result ) +inline void Vector2::Max(const Vector2& v1, const Vector2& v2, Vector2& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR X = XMVectorMax( x1, x2 ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR X = XMVectorMax(x1, x2); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::Max( const Vector2& v1, const Vector2& v2 ) +inline Vector2 Vector2::Max(const Vector2& v1, const Vector2& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR X = XMVectorMax( x1, x2 ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR X = XMVectorMax(x1, x2); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } -inline void Vector2::Lerp( const Vector2& v1, const Vector2& v2, float t, Vector2& result ) +inline void Vector2::Lerp(const Vector2& v1, const Vector2& v2, float t, Vector2& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::Lerp( const Vector2& v1, const Vector2& v2, float t ) +inline Vector2 Vector2::Lerp(const Vector2& v1, const Vector2& v2, float t) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } -inline void Vector2::SmoothStep( const Vector2& v1, const Vector2& v2, float t, Vector2& result ) +inline void Vector2::SmoothStep(const Vector2& v1, const Vector2& v2, float t, Vector2& result) { - using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t*t*(3.f - 2.f*t); - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t * (3.f - 2.f * t); + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::SmoothStep( const Vector2& v1, const Vector2& v2, float t ) +inline Vector2 Vector2::SmoothStep(const Vector2& v1, const Vector2& v2, float t) { - using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t*t*(3.f - 2.f*t); - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); + using namespace DirectX; + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t * (3.f - 2.f * t); + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } -inline void Vector2::Barycentric( const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, Vector2& result ) +inline void Vector2::Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, + Vector2& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR x3 = XMLoadFloat2( &v3 ); - XMVECTOR X = XMVectorBaryCentric( x1, x2, x3, f, g ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR x3 = XMLoadFloat2(&v3); + XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::Barycentric( const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g ) +inline Vector2 Vector2::Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR x3 = XMLoadFloat2( &v3 ); - XMVECTOR X = XMVectorBaryCentric( x1, x2, x3, f, g ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR x3 = XMLoadFloat2(&v3); + XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } -inline void Vector2::CatmullRom( const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, Vector2& result ) +inline void Vector2::CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, + Vector2& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR x3 = XMLoadFloat2( &v3 ); - XMVECTOR x4 = XMLoadFloat2( &v4 ); - XMVECTOR X = XMVectorCatmullRom( x1, x2, x3, x4, t ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR x3 = XMLoadFloat2(&v3); + XMVECTOR x4 = XMLoadFloat2(&v4); + XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::CatmullRom( const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t ) +inline Vector2 Vector2::CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &v2 ); - XMVECTOR x3 = XMLoadFloat2( &v3 ); - XMVECTOR x4 = XMLoadFloat2( &v4 ); - XMVECTOR X = XMVectorCatmullRom( x1, x2, x3, x4, t ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&v2); + XMVECTOR x3 = XMLoadFloat2(&v3); + XMVECTOR x4 = XMLoadFloat2(&v4); + XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } -inline void Vector2::Hermite( const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, Vector2& result ) +inline void Vector2::Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, + Vector2& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &t1 ); - XMVECTOR x3 = XMLoadFloat2( &v2 ); - XMVECTOR x4 = XMLoadFloat2( &t2 ); - XMVECTOR X = XMVectorHermite( x1, x2, x3, x4, t ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&t1); + XMVECTOR x3 = XMLoadFloat2(&v2); + XMVECTOR x4 = XMLoadFloat2(&t2); + XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::Hermite( const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t ) +inline Vector2 Vector2::Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat2( &v1 ); - XMVECTOR x2 = XMLoadFloat2( &t1 ); - XMVECTOR x3 = XMLoadFloat2( &v2 ); - XMVECTOR x4 = XMLoadFloat2( &t2 ); - XMVECTOR X = XMVectorHermite( x1, x2, x3, x4, t ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat2(&v1); + XMVECTOR x2 = XMLoadFloat2(&t1); + XMVECTOR x3 = XMLoadFloat2(&v2); + XMVECTOR x4 = XMLoadFloat2(&t2); + XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } -inline void Vector2::Reflect( const Vector2& ivec, const Vector2& nvec, Vector2& result ) +inline void Vector2::Reflect(const Vector2& ivec, const Vector2& nvec, Vector2& result) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat2( &ivec ); - XMVECTOR n = XMLoadFloat2( &nvec ); - XMVECTOR X = XMVector2Reflect( i, n ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat2(&ivec); + XMVECTOR n = XMLoadFloat2(&nvec); + XMVECTOR X = XMVector2Reflect(i, n); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::Reflect( const Vector2& ivec, const Vector2& nvec ) +inline Vector2 Vector2::Reflect(const Vector2& ivec, const Vector2& nvec) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat2( &ivec ); - XMVECTOR n = XMLoadFloat2( &nvec ); - XMVECTOR X = XMVector2Reflect( i, n ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat2(&ivec); + XMVECTOR n = XMLoadFloat2(&nvec); + XMVECTOR X = XMVector2Reflect(i, n); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } -inline void Vector2::Refract( const Vector2& ivec, const Vector2& nvec, float refractionIndex, Vector2& result ) +inline void Vector2::Refract(const Vector2& ivec, const Vector2& nvec, float refractionIndex, Vector2& result) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat2( &ivec ); - XMVECTOR n = XMLoadFloat2( &nvec ); - XMVECTOR X = XMVector2Refract( i, n, refractionIndex ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat2(&ivec); + XMVECTOR n = XMLoadFloat2(&nvec); + XMVECTOR X = XMVector2Refract(i, n, refractionIndex); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::Refract( const Vector2& ivec, const Vector2& nvec, float refractionIndex ) +inline Vector2 Vector2::Refract(const Vector2& ivec, const Vector2& nvec, float refractionIndex) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat2( &ivec ); - XMVECTOR n = XMLoadFloat2( &nvec ); - XMVECTOR X = XMVector2Refract( i, n, refractionIndex ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat2(&ivec); + XMVECTOR n = XMLoadFloat2(&nvec); + XMVECTOR X = XMVector2Refract(i, n, refractionIndex); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } -inline void Vector2::Transform( const Vector2& v, const Quaternion& quat, Vector2& result ) +inline void Vector2::Transform(const Vector2& v, const Quaternion& quat, Vector2& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &v ); - XMVECTOR q = XMLoadFloat4( &quat ); - XMVECTOR X = XMVector3Rotate( v1, q ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&v); + XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::Transform( const Vector2& v, const Quaternion& quat ) +inline Vector2 Vector2::Transform(const Vector2& v, const Quaternion& quat) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &v ); - XMVECTOR q = XMLoadFloat4( &quat ); - XMVECTOR X = XMVector3Rotate( v1, q ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&v); + XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } -inline void Vector2::Transform( const Vector2& v, const Matrix& m, Vector2& result ) +inline void Vector2::Transform(const Vector2& v, const Matrix& m, Vector2& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector2TransformCoord( v1, M ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector2TransformCoord(v1, M); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::Transform( const Vector2& v, const Matrix& m ) +inline Vector2 Vector2::Transform(const Vector2& v, const Matrix& m) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector2TransformCoord( v1, M ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector2TransformCoord(v1, M); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } _Use_decl_annotations_ -inline void Vector2::Transform( const Vector2* varray, size_t count, const Matrix& m, Vector2* resultArray ) + +inline void Vector2::Transform(const Vector2* varray, size_t count, const Matrix& m, Vector2* resultArray) { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVector2TransformCoordStream( resultArray, sizeof(XMFLOAT2), varray, sizeof(XMFLOAT2), count, M ); + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(&m); + XMVector2TransformCoordStream(resultArray, sizeof(XMFLOAT2), varray, sizeof(XMFLOAT2), count, M); } -inline void Vector2::Transform( const Vector2& v, const Matrix& m, Vector4& result ) +inline void Vector2::Transform(const Vector2& v, const Matrix& m, Vector4& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector2Transform( v1, M ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector2Transform(v1, M); + XMStoreFloat4(&result, X); } _Use_decl_annotations_ -inline void Vector2::Transform( const Vector2* varray, size_t count, const Matrix& m, Vector4* resultArray ) + +inline void Vector2::Transform(const Vector2* varray, size_t count, const Matrix& m, Vector4* resultArray) { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVector2TransformStream( resultArray, sizeof(XMFLOAT4), varray, sizeof(XMFLOAT2), count, M ); + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(&m); + XMVector2TransformStream(resultArray, sizeof(XMFLOAT4), varray, sizeof(XMFLOAT2), count, M); } -inline void Vector2::TransformNormal( const Vector2& v, const Matrix& m, Vector2& result ) +inline void Vector2::TransformNormal(const Vector2& v, const Matrix& m, Vector2& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector2TransformNormal( v1, M ); - XMStoreFloat2( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector2TransformNormal(v1, M); + XMStoreFloat2(&result, X); } -inline Vector2 Vector2::TransformNormal( const Vector2& v, const Matrix& m ) +inline Vector2 Vector2::TransformNormal(const Vector2& v, const Matrix& m) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector2TransformNormal( v1, M ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector2TransformNormal(v1, M); - Vector2 result; - XMStoreFloat2( &result, X ); - return result; + Vector2 result; + XMStoreFloat2(&result, X); + return result; } _Use_decl_annotations_ -inline void Vector2::TransformNormal( const Vector2* varray, size_t count, const Matrix& m, Vector2* resultArray ) + +inline void Vector2::TransformNormal(const Vector2* varray, size_t count, const Matrix& m, Vector2* resultArray) { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVector2TransformNormalStream( resultArray, sizeof(XMFLOAT2), varray, sizeof(XMFLOAT2), count, M ); + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(&m); + XMVector2TransformNormalStream(resultArray, sizeof(XMFLOAT2), varray, sizeof(XMFLOAT2), count, M); } @@ -588,572 +594,578 @@ inline void Vector2::TransformNormal( const Vector2* varray, size_t count, const // Comparision operators //------------------------------------------------------------------------------ -inline bool Vector3::operator == ( const Vector3& V ) const +inline bool Vector3::operator ==(const Vector3& V) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR v2 = XMLoadFloat3( &V ); - return XMVector3Equal( v1, v2 ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR v2 = XMLoadFloat3(&V); + return XMVector3Equal(v1, v2); } -inline bool Vector3::operator != ( const Vector3& V ) const +inline bool Vector3::operator !=(const Vector3& V) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR v2 = XMLoadFloat3( &V ); - return XMVector3NotEqual( v1, v2 ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR v2 = XMLoadFloat3(&V); + return XMVector3NotEqual(v1, v2); } //------------------------------------------------------------------------------ // Assignment operators //------------------------------------------------------------------------------ -inline Vector3& Vector3::operator+= (const Vector3& V) +inline Vector3& Vector3::operator+=(const Vector3& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR v2 = XMLoadFloat3( &V ); - XMVECTOR X = XMVectorAdd(v1,v2); - XMStoreFloat3( this, X ); - return *this; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR v2 = XMLoadFloat3(&V); + XMVECTOR X = XMVectorAdd(v1, v2); + XMStoreFloat3(this, X); + return *this; } -inline Vector3& Vector3::operator-= (const Vector3& V) +inline Vector3& Vector3::operator-=(const Vector3& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR v2 = XMLoadFloat3( &V ); - XMVECTOR X = XMVectorSubtract(v1,v2); - XMStoreFloat3( this, X ); - return *this; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR v2 = XMLoadFloat3(&V); + XMVECTOR X = XMVectorSubtract(v1, v2); + XMStoreFloat3(this, X); + return *this; } -inline Vector3& Vector3::operator*= (const Vector3& V) +inline Vector3& Vector3::operator*=(const Vector3& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR v2 = XMLoadFloat3( &V ); - XMVECTOR X = XMVectorMultiply(v1,v2); - XMStoreFloat3( this, X ); - return *this; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR v2 = XMLoadFloat3(&V); + XMVECTOR X = XMVectorMultiply(v1, v2); + XMStoreFloat3(this, X); + return *this; } -inline Vector3& Vector3::operator*= (float S) +inline Vector3& Vector3::operator*=(float S) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR X = XMVectorScale(v1,S); - XMStoreFloat3( this, X ); - return *this; -} + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR X = XMVectorScale(v1, S); + XMStoreFloat3(this, X); + return *this; +} -inline Vector3& Vector3::operator/= (float S) +inline Vector3& Vector3::operator/=(float S) { - using namespace DirectX; - assert( S != 0.0f ); - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR X = XMVectorScale(v1, 1.f/S); - XMStoreFloat3( this, X ); - return *this; -} + using namespace DirectX; + assert(S != 0.0f); + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR X = XMVectorScale(v1, 1.f / S); + XMStoreFloat3(this, X); + return *this; +} //------------------------------------------------------------------------------ // Urnary operators //------------------------------------------------------------------------------ -inline Vector3 Vector3::operator- () const +inline Vector3 Vector3::operator-() const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR X = XMVectorNegate( v1 ); - Vector3 R; - XMStoreFloat3( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR X = XMVectorNegate(v1); + Vector3 R; + XMStoreFloat3(&R, X); + return R; } //------------------------------------------------------------------------------ // Binary operators //------------------------------------------------------------------------------ -inline Vector3 operator+ (const Vector3& V1, const Vector3& V2) +inline Vector3 operator+(const Vector3& V1, const Vector3& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &V1 ); - XMVECTOR v2 = XMLoadFloat3( &V2 ); - XMVECTOR X = XMVectorAdd(v1,v2); - Vector3 R; - XMStoreFloat3( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&V1); + XMVECTOR v2 = XMLoadFloat3(&V2); + XMVECTOR X = XMVectorAdd(v1, v2); + Vector3 R; + XMStoreFloat3(&R, X); + return R; } -inline Vector3 operator- (const Vector3& V1, const Vector3& V2) +inline Vector3 operator-(const Vector3& V1, const Vector3& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &V1 ); - XMVECTOR v2 = XMLoadFloat3( &V2 ); - XMVECTOR X = XMVectorSubtract(v1,v2); - Vector3 R; - XMStoreFloat3( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&V1); + XMVECTOR v2 = XMLoadFloat3(&V2); + XMVECTOR X = XMVectorSubtract(v1, v2); + Vector3 R; + XMStoreFloat3(&R, X); + return R; } -inline Vector3 operator* (const Vector3& V1, const Vector3& V2) +inline Vector3 operator*(const Vector3& V1, const Vector3& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &V1 ); - XMVECTOR v2 = XMLoadFloat3( &V2 ); - XMVECTOR X = XMVectorMultiply(v1,v2); - Vector3 R; - XMStoreFloat3( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&V1); + XMVECTOR v2 = XMLoadFloat3(&V2); + XMVECTOR X = XMVectorMultiply(v1, v2); + Vector3 R; + XMStoreFloat3(&R, X); + return R; } -inline Vector3 operator* (const Vector3& V, float S) +inline Vector3 operator*(const Vector3& V, float S) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &V ); - XMVECTOR X = XMVectorScale(v1,S); - Vector3 R; - XMStoreFloat3( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&V); + XMVECTOR X = XMVectorScale(v1, S); + Vector3 R; + XMStoreFloat3(&R, X); + return R; } -inline Vector3 operator/ (const Vector3& V1, const Vector3& V2) +inline Vector3 operator/(const Vector3& V1, const Vector3& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &V1 ); - XMVECTOR v2 = XMLoadFloat3( &V2 ); - XMVECTOR X = XMVectorDivide(v1,v2); - Vector3 R; - XMStoreFloat3( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&V1); + XMVECTOR v2 = XMLoadFloat3(&V2); + XMVECTOR X = XMVectorDivide(v1, v2); + Vector3 R; + XMStoreFloat3(&R, X); + return R; } -inline Vector3 operator* (float S, const Vector3& V) +inline Vector3 operator*(float S, const Vector3& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &V ); - XMVECTOR X = XMVectorScale(v1,S); - Vector3 R; - XMStoreFloat3( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&V); + XMVECTOR X = XMVectorScale(v1, S); + Vector3 R; + XMStoreFloat3(&R, X); + return R; } //------------------------------------------------------------------------------ // Vector operations //------------------------------------------------------------------------------ -inline bool Vector3::InBounds( const Vector3& Bounds ) const +inline bool Vector3::InBounds(const Vector3& Bounds) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR v2 = XMLoadFloat3( &Bounds ); - return XMVector3InBounds( v1, v2 ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR v2 = XMLoadFloat3(&Bounds); + return XMVector3InBounds(v1, v2); } inline float Vector3::Length() const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR X = XMVector3Length( v1 ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR X = XMVector3Length(v1); + return XMVectorGetX(X); } inline float Vector3::LengthSquared() const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR X = XMVector3LengthSq( v1 ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR X = XMVector3LengthSq(v1); + return XMVectorGetX(X); } -inline float Vector3::Dot( const Vector3& V ) const +inline float Vector3::Dot(const Vector3& V) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR v2 = XMLoadFloat3( &V ); - XMVECTOR X = XMVector3Dot( v1, v2 ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR v2 = XMLoadFloat3(&V); + XMVECTOR X = XMVector3Dot(v1, v2); + return XMVectorGetX(X); } -inline void Vector3::Cross( const Vector3& V, Vector3& result ) const +inline void Vector3::Cross(const Vector3& V, Vector3& result) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR v2 = XMLoadFloat3( &V ); - XMVECTOR R = XMVector3Cross( v1, v2 ); - XMStoreFloat3( &result, R ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR v2 = XMLoadFloat3(&V); + XMVECTOR R = XMVector3Cross(v1, v2); + XMStoreFloat3(&result, R); } -inline Vector3 Vector3::Cross( const Vector3& V ) const +inline Vector3 Vector3::Cross(const Vector3& V) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR v2 = XMLoadFloat3( &V ); - XMVECTOR R = XMVector3Cross( v1, v2 ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR v2 = XMLoadFloat3(&V); + XMVECTOR R = XMVector3Cross(v1, v2); - Vector3 result; - XMStoreFloat3( &result, R ); - return result; + Vector3 result; + XMStoreFloat3(&result, R); + return result; } inline void Vector3::Normalize() { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR X = XMVector3Normalize( v1 ); - XMStoreFloat3( this, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR X = XMVector3Normalize(v1); + XMStoreFloat3(this, X); } -inline void Vector3::Normalize( Vector3& result ) const +inline void Vector3::Normalize(Vector3& result) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR X = XMVector3Normalize( v1 ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR X = XMVector3Normalize(v1); + XMStoreFloat3(&result, X); } -inline void Vector3::Clamp( const Vector3& vmin, const Vector3& vmax ) +inline void Vector3::Clamp(const Vector3& vmin, const Vector3& vmax) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR v2 = XMLoadFloat3( &vmin ); - XMVECTOR v3 = XMLoadFloat3( &vmax ); - XMVECTOR X = XMVectorClamp( v1, v2, v3 ); - XMStoreFloat3( this, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR v2 = XMLoadFloat3(&vmin); + XMVECTOR v3 = XMLoadFloat3(&vmax); + XMVECTOR X = XMVectorClamp(v1, v2, v3); + XMStoreFloat3(this, X); } -inline void Vector3::Clamp( const Vector3& vmin, const Vector3& vmax, Vector3& result ) const +inline void Vector3::Clamp(const Vector3& vmin, const Vector3& vmax, Vector3& result) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( this ); - XMVECTOR v2 = XMLoadFloat3( &vmin ); - XMVECTOR v3 = XMLoadFloat3( &vmax ); - XMVECTOR X = XMVectorClamp( v1, v2, v3 ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(this); + XMVECTOR v2 = XMLoadFloat3(&vmin); + XMVECTOR v3 = XMLoadFloat3(&vmax); + XMVECTOR X = XMVectorClamp(v1, v2, v3); + XMStoreFloat3(&result, X); } //------------------------------------------------------------------------------ // Static functions //------------------------------------------------------------------------------ -inline float Vector3::Distance( const Vector3& v1, const Vector3& v2 ) +inline float Vector3::Distance(const Vector3& v1, const Vector3& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR V = XMVectorSubtract( x2, x1 ); - XMVECTOR X = XMVector3Length( V ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR V = XMVectorSubtract(x2, x1); + XMVECTOR X = XMVector3Length(V); + return XMVectorGetX(X); } -inline float Vector3::DistanceSquared( const Vector3& v1, const Vector3& v2 ) +inline float Vector3::DistanceSquared(const Vector3& v1, const Vector3& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR V = XMVectorSubtract( x2, x1 ); - XMVECTOR X = XMVector3LengthSq( V ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR V = XMVectorSubtract(x2, x1); + XMVECTOR X = XMVector3LengthSq(V); + return XMVectorGetX(X); } -inline void Vector3::Min( const Vector3& v1, const Vector3& v2, Vector3& result ) +inline void Vector3::Min(const Vector3& v1, const Vector3& v2, Vector3& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR X = XMVectorMin( x1, x2 ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR X = XMVectorMin(x1, x2); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::Min( const Vector3& v1, const Vector3& v2 ) +inline Vector3 Vector3::Min(const Vector3& v1, const Vector3& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR X = XMVectorMin( x1, x2 ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR X = XMVectorMin(x1, x2); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } -inline void Vector3::Max( const Vector3& v1, const Vector3& v2, Vector3& result ) +inline void Vector3::Max(const Vector3& v1, const Vector3& v2, Vector3& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR X = XMVectorMax( x1, x2 ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR X = XMVectorMax(x1, x2); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::Max( const Vector3& v1, const Vector3& v2 ) +inline Vector3 Vector3::Max(const Vector3& v1, const Vector3& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR X = XMVectorMax( x1, x2 ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR X = XMVectorMax(x1, x2); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } -inline void Vector3::Lerp( const Vector3& v1, const Vector3& v2, float t, Vector3& result ) +inline void Vector3::Lerp(const Vector3& v1, const Vector3& v2, float t, Vector3& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::Lerp( const Vector3& v1, const Vector3& v2, float t ) +inline Vector3 Vector3::Lerp(const Vector3& v1, const Vector3& v2, float t) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } -inline void Vector3::SmoothStep( const Vector3& v1, const Vector3& v2, float t, Vector3& result ) +inline void Vector3::SmoothStep(const Vector3& v1, const Vector3& v2, float t, Vector3& result) { - using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t*t*(3.f - 2.f*t); - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t * (3.f - 2.f * t); + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::SmoothStep( const Vector3& v1, const Vector3& v2, float t ) +inline Vector3 Vector3::SmoothStep(const Vector3& v1, const Vector3& v2, float t) { - using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t*t*(3.f - 2.f*t); - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); + using namespace DirectX; + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t * (3.f - 2.f * t); + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } -inline void Vector3::Barycentric( const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, Vector3& result ) +inline void Vector3::Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, + Vector3& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR x3 = XMLoadFloat3( &v3 ); - XMVECTOR X = XMVectorBaryCentric( x1, x2, x3, f, g ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR x3 = XMLoadFloat3(&v3); + XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::Barycentric( const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g ) +inline Vector3 Vector3::Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR x3 = XMLoadFloat3( &v3 ); - XMVECTOR X = XMVectorBaryCentric( x1, x2, x3, f, g ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR x3 = XMLoadFloat3(&v3); + XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } -inline void Vector3::CatmullRom( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, Vector3& result ) +inline void Vector3::CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, + Vector3& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR x3 = XMLoadFloat3( &v3 ); - XMVECTOR x4 = XMLoadFloat3( &v4 ); - XMVECTOR X = XMVectorCatmullRom( x1, x2, x3, x4, t ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR x3 = XMLoadFloat3(&v3); + XMVECTOR x4 = XMLoadFloat3(&v4); + XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::CatmullRom( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t ) +inline Vector3 Vector3::CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &v2 ); - XMVECTOR x3 = XMLoadFloat3( &v3 ); - XMVECTOR x4 = XMLoadFloat3( &v4 ); - XMVECTOR X = XMVectorCatmullRom( x1, x2, x3, x4, t ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&v2); + XMVECTOR x3 = XMLoadFloat3(&v3); + XMVECTOR x4 = XMLoadFloat3(&v4); + XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } -inline void Vector3::Hermite( const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, Vector3& result ) +inline void Vector3::Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, + Vector3& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &t1 ); - XMVECTOR x3 = XMLoadFloat3( &v2 ); - XMVECTOR x4 = XMLoadFloat3( &t2 ); - XMVECTOR X = XMVectorHermite( x1, x2, x3, x4, t ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&t1); + XMVECTOR x3 = XMLoadFloat3(&v2); + XMVECTOR x4 = XMLoadFloat3(&t2); + XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::Hermite( const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t ) +inline Vector3 Vector3::Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat3( &v1 ); - XMVECTOR x2 = XMLoadFloat3( &t1 ); - XMVECTOR x3 = XMLoadFloat3( &v2 ); - XMVECTOR x4 = XMLoadFloat3( &t2 ); - XMVECTOR X = XMVectorHermite( x1, x2, x3, x4, t ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat3(&v1); + XMVECTOR x2 = XMLoadFloat3(&t1); + XMVECTOR x3 = XMLoadFloat3(&v2); + XMVECTOR x4 = XMLoadFloat3(&t2); + XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } -inline void Vector3::Reflect( const Vector3& ivec, const Vector3& nvec, Vector3& result ) +inline void Vector3::Reflect(const Vector3& ivec, const Vector3& nvec, Vector3& result) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat3( &ivec ); - XMVECTOR n = XMLoadFloat3( &nvec ); - XMVECTOR X = XMVector3Reflect( i, n ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat3(&ivec); + XMVECTOR n = XMLoadFloat3(&nvec); + XMVECTOR X = XMVector3Reflect(i, n); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::Reflect( const Vector3& ivec, const Vector3& nvec ) +inline Vector3 Vector3::Reflect(const Vector3& ivec, const Vector3& nvec) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat3( &ivec ); - XMVECTOR n = XMLoadFloat3( &nvec ); - XMVECTOR X = XMVector3Reflect( i, n ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat3(&ivec); + XMVECTOR n = XMLoadFloat3(&nvec); + XMVECTOR X = XMVector3Reflect(i, n); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } -inline void Vector3::Refract( const Vector3& ivec, const Vector3& nvec, float refractionIndex, Vector3& result ) +inline void Vector3::Refract(const Vector3& ivec, const Vector3& nvec, float refractionIndex, Vector3& result) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat3( &ivec ); - XMVECTOR n = XMLoadFloat3( &nvec ); - XMVECTOR X = XMVector3Refract( i, n, refractionIndex ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat3(&ivec); + XMVECTOR n = XMLoadFloat3(&nvec); + XMVECTOR X = XMVector3Refract(i, n, refractionIndex); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::Refract( const Vector3& ivec, const Vector3& nvec, float refractionIndex ) +inline Vector3 Vector3::Refract(const Vector3& ivec, const Vector3& nvec, float refractionIndex) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat3( &ivec ); - XMVECTOR n = XMLoadFloat3( &nvec ); - XMVECTOR X = XMVector3Refract( i, n, refractionIndex ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat3(&ivec); + XMVECTOR n = XMLoadFloat3(&nvec); + XMVECTOR X = XMVector3Refract(i, n, refractionIndex); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } -inline void Vector3::Transform( const Vector3& v, const Quaternion& quat, Vector3& result ) +inline void Vector3::Transform(const Vector3& v, const Quaternion& quat, Vector3& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &v ); - XMVECTOR q = XMLoadFloat4( &quat ); - XMVECTOR X = XMVector3Rotate( v1, q ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&v); + XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::Transform( const Vector3& v, const Quaternion& quat ) +inline Vector3 Vector3::Transform(const Vector3& v, const Quaternion& quat) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &v ); - XMVECTOR q = XMLoadFloat4( &quat ); - XMVECTOR X = XMVector3Rotate( v1, q ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&v); + XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } -inline void Vector3::Transform( const Vector3& v, const Matrix& m, Vector3& result ) +inline void Vector3::Transform(const Vector3& v, const Matrix& m, Vector3& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector3TransformCoord( v1, M ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector3TransformCoord(v1, M); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::Transform( const Vector3& v, const Matrix& m ) +inline Vector3 Vector3::Transform(const Vector3& v, const Matrix& m) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector3TransformCoord( v1, M ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector3TransformCoord(v1, M); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } _Use_decl_annotations_ -inline void Vector3::Transform( const Vector3* varray, size_t count, const Matrix& m, Vector3* resultArray ) + +inline void Vector3::Transform(const Vector3* varray, size_t count, const Matrix& m, Vector3* resultArray) { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVector3TransformCoordStream( resultArray, sizeof(XMFLOAT3), varray, sizeof(XMFLOAT3), count, M ); + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(&m); + XMVector3TransformCoordStream(resultArray, sizeof(XMFLOAT3), varray, sizeof(XMFLOAT3), count, M); } -inline void Vector3::Transform( const Vector3& v, const Matrix& m, Vector4& result ) +inline void Vector3::Transform(const Vector3& v, const Matrix& m, Vector4& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector3Transform( v1, M ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector3Transform(v1, M); + XMStoreFloat4(&result, X); } _Use_decl_annotations_ -inline void Vector3::Transform( const Vector3* varray, size_t count, const Matrix& m, Vector4* resultArray ) + +inline void Vector3::Transform(const Vector3* varray, size_t count, const Matrix& m, Vector4* resultArray) { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVector3TransformStream( resultArray, sizeof(XMFLOAT4), varray, sizeof(XMFLOAT3), count, M ); + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(&m); + XMVector3TransformStream(resultArray, sizeof(XMFLOAT4), varray, sizeof(XMFLOAT3), count, M); } -inline void Vector3::TransformNormal( const Vector3& v, const Matrix& m, Vector3& result ) +inline void Vector3::TransformNormal(const Vector3& v, const Matrix& m, Vector3& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector3TransformNormal( v1, M ); - XMStoreFloat3( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector3TransformNormal(v1, M); + XMStoreFloat3(&result, X); } -inline Vector3 Vector3::TransformNormal( const Vector3& v, const Matrix& m ) +inline Vector3 Vector3::TransformNormal(const Vector3& v, const Matrix& m) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector3TransformNormal( v1, M ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector3TransformNormal(v1, M); - Vector3 result; - XMStoreFloat3( &result, X ); - return result; + Vector3 result; + XMStoreFloat3(&result, X); + return result; } _Use_decl_annotations_ -inline void Vector3::TransformNormal( const Vector3* varray, size_t count, const Matrix& m, Vector3* resultArray ) + +inline void Vector3::TransformNormal(const Vector3* varray, size_t count, const Matrix& m, Vector3* resultArray) { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVector3TransformNormalStream( resultArray, sizeof(XMFLOAT3), varray, sizeof(XMFLOAT3), count, M ); + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(&m); + XMVector3TransformNormalStream(resultArray, sizeof(XMFLOAT3), varray, sizeof(XMFLOAT3), count, M); } @@ -1167,576 +1179,580 @@ inline void Vector3::TransformNormal( const Vector3* varray, size_t count, const // Comparision operators //------------------------------------------------------------------------------ -inline bool Vector4::operator == ( const Vector4& V ) const +inline bool Vector4::operator ==(const Vector4& V) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR v2 = XMLoadFloat4( &V ); - return XMVector4Equal( v1, v2 ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR v2 = XMLoadFloat4(&V); + return XMVector4Equal(v1, v2); } -inline bool Vector4::operator != ( const Vector4& V ) const +inline bool Vector4::operator !=(const Vector4& V) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR v2 = XMLoadFloat4( &V ); - return XMVector4NotEqual( v1, v2 ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR v2 = XMLoadFloat4(&V); + return XMVector4NotEqual(v1, v2); } //------------------------------------------------------------------------------ // Assignment operators //------------------------------------------------------------------------------ -inline Vector4& Vector4::operator+= (const Vector4& V) +inline Vector4& Vector4::operator+=(const Vector4& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR v2 = XMLoadFloat4( &V ); - XMVECTOR X = XMVectorAdd(v1,v2); - XMStoreFloat4( this, X ); - return *this; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR v2 = XMLoadFloat4(&V); + XMVECTOR X = XMVectorAdd(v1, v2); + XMStoreFloat4(this, X); + return *this; } -inline Vector4& Vector4::operator-= (const Vector4& V) +inline Vector4& Vector4::operator-=(const Vector4& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR v2 = XMLoadFloat4( &V ); - XMVECTOR X = XMVectorSubtract(v1,v2); - XMStoreFloat4( this, X ); - return *this; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR v2 = XMLoadFloat4(&V); + XMVECTOR X = XMVectorSubtract(v1, v2); + XMStoreFloat4(this, X); + return *this; } -inline Vector4& Vector4::operator*= (const Vector4& V) +inline Vector4& Vector4::operator*=(const Vector4& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR v2 = XMLoadFloat4( &V ); - XMVECTOR X = XMVectorMultiply(v1,v2); - XMStoreFloat4( this, X ); - return *this; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR v2 = XMLoadFloat4(&V); + XMVECTOR X = XMVectorMultiply(v1, v2); + XMStoreFloat4(this, X); + return *this; } -inline Vector4& Vector4::operator*= (float S) +inline Vector4& Vector4::operator*=(float S) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR X = XMVectorScale(v1,S); - XMStoreFloat4( this, X ); - return *this; -} + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR X = XMVectorScale(v1, S); + XMStoreFloat4(this, X); + return *this; +} -inline Vector4& Vector4::operator/= (float S) +inline Vector4& Vector4::operator/=(float S) { - using namespace DirectX; - assert( S != 0.0f ); - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR X = XMVectorScale(v1, 1.f/S); - XMStoreFloat4( this, X ); - return *this; -} + using namespace DirectX; + assert(S != 0.0f); + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR X = XMVectorScale(v1, 1.f / S); + XMStoreFloat4(this, X); + return *this; +} //------------------------------------------------------------------------------ // Urnary operators //------------------------------------------------------------------------------ -inline Vector4 Vector4::operator- () const +inline Vector4 Vector4::operator-() const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR X = XMVectorNegate( v1 ); - Vector4 R; - XMStoreFloat4( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR X = XMVectorNegate(v1); + Vector4 R; + XMStoreFloat4(&R, X); + return R; } //------------------------------------------------------------------------------ // Binary operators //------------------------------------------------------------------------------ -inline Vector4 operator+ (const Vector4& V1, const Vector4& V2) +inline Vector4 operator+(const Vector4& V1, const Vector4& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( &V1 ); - XMVECTOR v2 = XMLoadFloat4( &V2 ); - XMVECTOR X = XMVectorAdd(v1,v2); - Vector4 R; - XMStoreFloat4( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(&V1); + XMVECTOR v2 = XMLoadFloat4(&V2); + XMVECTOR X = XMVectorAdd(v1, v2); + Vector4 R; + XMStoreFloat4(&R, X); + return R; } -inline Vector4 operator- (const Vector4& V1, const Vector4& V2) +inline Vector4 operator-(const Vector4& V1, const Vector4& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( &V1 ); - XMVECTOR v2 = XMLoadFloat4( &V2 ); - XMVECTOR X = XMVectorSubtract(v1,v2); - Vector4 R; - XMStoreFloat4( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(&V1); + XMVECTOR v2 = XMLoadFloat4(&V2); + XMVECTOR X = XMVectorSubtract(v1, v2); + Vector4 R; + XMStoreFloat4(&R, X); + return R; } -inline Vector4 operator* (const Vector4& V1, const Vector4& V2) +inline Vector4 operator*(const Vector4& V1, const Vector4& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( &V1 ); - XMVECTOR v2 = XMLoadFloat4( &V2 ); - XMVECTOR X = XMVectorMultiply(v1,v2); - Vector4 R; - XMStoreFloat4( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(&V1); + XMVECTOR v2 = XMLoadFloat4(&V2); + XMVECTOR X = XMVectorMultiply(v1, v2); + Vector4 R; + XMStoreFloat4(&R, X); + return R; } -inline Vector4 operator* (const Vector4& V, float S) +inline Vector4 operator*(const Vector4& V, float S) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( &V ); - XMVECTOR X = XMVectorScale(v1,S); - Vector4 R; - XMStoreFloat4( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(&V); + XMVECTOR X = XMVectorScale(v1, S); + Vector4 R; + XMStoreFloat4(&R, X); + return R; } -inline Vector4 operator/ (const Vector4& V1, const Vector4& V2) +inline Vector4 operator/(const Vector4& V1, const Vector4& V2) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( &V1 ); - XMVECTOR v2 = XMLoadFloat4( &V2 ); - XMVECTOR X = XMVectorDivide(v1,v2); - Vector4 R; - XMStoreFloat4( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(&V1); + XMVECTOR v2 = XMLoadFloat4(&V2); + XMVECTOR X = XMVectorDivide(v1, v2); + Vector4 R; + XMStoreFloat4(&R, X); + return R; } -inline Vector4 operator* (float S, const Vector4& V) +inline Vector4 operator*(float S, const Vector4& V) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( &V ); - XMVECTOR X = XMVectorScale(v1,S); - Vector4 R; - XMStoreFloat4( &R, X ); - return R; + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(&V); + XMVECTOR X = XMVectorScale(v1, S); + Vector4 R; + XMStoreFloat4(&R, X); + return R; } //------------------------------------------------------------------------------ // Vector operations //------------------------------------------------------------------------------ -inline bool Vector4::InBounds( const Vector4& Bounds ) const +inline bool Vector4::InBounds(const Vector4& Bounds) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR v2 = XMLoadFloat4( &Bounds ); - return XMVector4InBounds( v1, v2 ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR v2 = XMLoadFloat4(&Bounds); + return XMVector4InBounds(v1, v2); } inline float Vector4::Length() const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR X = XMVector4Length( v1 ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR X = XMVector4Length(v1); + return XMVectorGetX(X); } inline float Vector4::LengthSquared() const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR X = XMVector4LengthSq( v1 ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR X = XMVector4LengthSq(v1); + return XMVectorGetX(X); } -inline float Vector4::Dot( const Vector4& V ) const +inline float Vector4::Dot(const Vector4& V) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR v2 = XMLoadFloat4( &V ); - XMVECTOR X = XMVector4Dot( v1, v2 ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR v2 = XMLoadFloat4(&V); + XMVECTOR X = XMVector4Dot(v1, v2); + return XMVectorGetX(X); } -inline void Vector4::Cross( const Vector4& v1, const Vector4& v2, Vector4& result ) const +inline void Vector4::Cross(const Vector4& v1, const Vector4& v2, Vector4& result) const { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( this ); - XMVECTOR x2 = XMLoadFloat4( &v1 ); - XMVECTOR x3 = XMLoadFloat4( &v2 ); - XMVECTOR R = XMVector4Cross( x1, x2, x3 ); - XMStoreFloat4( &result, R ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(this); + XMVECTOR x2 = XMLoadFloat4(&v1); + XMVECTOR x3 = XMLoadFloat4(&v2); + XMVECTOR R = XMVector4Cross(x1, x2, x3); + XMStoreFloat4(&result, R); } -inline Vector4 Vector4::Cross( const Vector4& v1, const Vector4& v2 ) const +inline Vector4 Vector4::Cross(const Vector4& v1, const Vector4& v2) const { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( this ); - XMVECTOR x2 = XMLoadFloat4( &v1 ); - XMVECTOR x3 = XMLoadFloat4( &v2 ); - XMVECTOR R = XMVector4Cross( x1, x2, x3 ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(this); + XMVECTOR x2 = XMLoadFloat4(&v1); + XMVECTOR x3 = XMLoadFloat4(&v2); + XMVECTOR R = XMVector4Cross(x1, x2, x3); - Vector4 result; - XMStoreFloat4( &result, R ); - return result; + Vector4 result; + XMStoreFloat4(&result, R); + return result; } inline void Vector4::Normalize() { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR X = XMVector4Normalize( v1 ); - XMStoreFloat4( this, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR X = XMVector4Normalize(v1); + XMStoreFloat4(this, X); } -inline void Vector4::Normalize( Vector4& result ) const +inline void Vector4::Normalize(Vector4& result) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR X = XMVector4Normalize( v1 ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR X = XMVector4Normalize(v1); + XMStoreFloat4(&result, X); } -inline void Vector4::Clamp( const Vector4& vmin, const Vector4& vmax ) +inline void Vector4::Clamp(const Vector4& vmin, const Vector4& vmax) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR v2 = XMLoadFloat4( &vmin ); - XMVECTOR v3 = XMLoadFloat4( &vmax ); - XMVECTOR X = XMVectorClamp( v1, v2, v3 ); - XMStoreFloat4( this, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR v2 = XMLoadFloat4(&vmin); + XMVECTOR v3 = XMLoadFloat4(&vmax); + XMVECTOR X = XMVectorClamp(v1, v2, v3); + XMStoreFloat4(this, X); } -inline void Vector4::Clamp( const Vector4& vmin, const Vector4& vmax, Vector4& result ) const +inline void Vector4::Clamp(const Vector4& vmin, const Vector4& vmax, Vector4& result) const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( this ); - XMVECTOR v2 = XMLoadFloat4( &vmin ); - XMVECTOR v3 = XMLoadFloat4( &vmax ); - XMVECTOR X = XMVectorClamp( v1, v2, v3 ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(this); + XMVECTOR v2 = XMLoadFloat4(&vmin); + XMVECTOR v3 = XMLoadFloat4(&vmax); + XMVECTOR X = XMVectorClamp(v1, v2, v3); + XMStoreFloat4(&result, X); } //------------------------------------------------------------------------------ // Static functions //------------------------------------------------------------------------------ -inline float Vector4::Distance( const Vector4& v1, const Vector4& v2 ) +inline float Vector4::Distance(const Vector4& v1, const Vector4& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR V = XMVectorSubtract( x2, x1 ); - XMVECTOR X = XMVector4Length( V ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR V = XMVectorSubtract(x2, x1); + XMVECTOR X = XMVector4Length(V); + return XMVectorGetX(X); } -inline float Vector4::DistanceSquared( const Vector4& v1, const Vector4& v2 ) +inline float Vector4::DistanceSquared(const Vector4& v1, const Vector4& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR V = XMVectorSubtract( x2, x1 ); - XMVECTOR X = XMVector4LengthSq( V ); - return XMVectorGetX( X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR V = XMVectorSubtract(x2, x1); + XMVECTOR X = XMVector4LengthSq(V); + return XMVectorGetX(X); } -inline void Vector4::Min( const Vector4& v1, const Vector4& v2, Vector4& result ) +inline void Vector4::Min(const Vector4& v1, const Vector4& v2, Vector4& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR X = XMVectorMin( x1, x2 ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR X = XMVectorMin(x1, x2); + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Min( const Vector4& v1, const Vector4& v2 ) +inline Vector4 Vector4::Min(const Vector4& v1, const Vector4& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR X = XMVectorMin( x1, x2 ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR X = XMVectorMin(x1, x2); - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::Max( const Vector4& v1, const Vector4& v2, Vector4& result ) +inline void Vector4::Max(const Vector4& v1, const Vector4& v2, Vector4& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR X = XMVectorMax( x1, x2 ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR X = XMVectorMax(x1, x2); + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Max( const Vector4& v1, const Vector4& v2 ) +inline Vector4 Vector4::Max(const Vector4& v1, const Vector4& v2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR X = XMVectorMax( x1, x2 ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR X = XMVectorMax(x1, x2); - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::Lerp( const Vector4& v1, const Vector4& v2, float t, Vector4& result ) +inline void Vector4::Lerp(const Vector4& v1, const Vector4& v2, float t, Vector4& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Lerp( const Vector4& v1, const Vector4& v2, float t ) +inline Vector4 Vector4::Lerp(const Vector4& v1, const Vector4& v2, float t) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::SmoothStep( const Vector4& v1, const Vector4& v2, float t, Vector4& result ) +inline void Vector4::SmoothStep(const Vector4& v1, const Vector4& v2, float t, Vector4& result) { - using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t*t*(3.f - 2.f*t); - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t * (3.f - 2.f * t); + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::SmoothStep( const Vector4& v1, const Vector4& v2, float t ) +inline Vector4 Vector4::SmoothStep(const Vector4& v1, const Vector4& v2, float t) { - using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t*t*(3.f - 2.f*t); - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR X = XMVectorLerp( x1, x2, t ); + using namespace DirectX; + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t * (3.f - 2.f * t); + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR X = XMVectorLerp(x1, x2, t); - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::Barycentric( const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, Vector4& result ) +inline void Vector4::Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, + Vector4& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR x3 = XMLoadFloat4( &v3 ); - XMVECTOR X = XMVectorBaryCentric( x1, x2, x3, f, g ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR x3 = XMLoadFloat4(&v3); + XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Barycentric( const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g ) +inline Vector4 Vector4::Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR x3 = XMLoadFloat4( &v3 ); - XMVECTOR X = XMVectorBaryCentric( x1, x2, x3, f, g ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR x3 = XMLoadFloat4(&v3); + XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::CatmullRom( const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, Vector4& result ) +inline void Vector4::CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, + Vector4& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR x3 = XMLoadFloat4( &v3 ); - XMVECTOR x4 = XMLoadFloat4( &v4 ); - XMVECTOR X = XMVectorCatmullRom( x1, x2, x3, x4, t ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR x3 = XMLoadFloat4(&v3); + XMVECTOR x4 = XMLoadFloat4(&v4); + XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::CatmullRom( const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t ) +inline Vector4 Vector4::CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &v2 ); - XMVECTOR x3 = XMLoadFloat4( &v3 ); - XMVECTOR x4 = XMLoadFloat4( &v4 ); - XMVECTOR X = XMVectorCatmullRom( x1, x2, x3, x4, t ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&v2); + XMVECTOR x3 = XMLoadFloat4(&v3); + XMVECTOR x4 = XMLoadFloat4(&v4); + XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::Hermite( const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, Vector4& result ) +inline void Vector4::Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, + Vector4& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &t1 ); - XMVECTOR x3 = XMLoadFloat4( &v2 ); - XMVECTOR x4 = XMLoadFloat4( &t2 ); - XMVECTOR X = XMVectorHermite( x1, x2, x3, x4, t ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&t1); + XMVECTOR x3 = XMLoadFloat4(&v2); + XMVECTOR x4 = XMLoadFloat4(&t2); + XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Hermite( const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t ) +inline Vector4 Vector4::Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( &v1 ); - XMVECTOR x2 = XMLoadFloat4( &t1 ); - XMVECTOR x3 = XMLoadFloat4( &v2 ); - XMVECTOR x4 = XMLoadFloat4( &t2 ); - XMVECTOR X = XMVectorHermite( x1, x2, x3, x4, t ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(&v1); + XMVECTOR x2 = XMLoadFloat4(&t1); + XMVECTOR x3 = XMLoadFloat4(&v2); + XMVECTOR x4 = XMLoadFloat4(&t2); + XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::Reflect( const Vector4& ivec, const Vector4& nvec, Vector4& result ) +inline void Vector4::Reflect(const Vector4& ivec, const Vector4& nvec, Vector4& result) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat4( &ivec ); - XMVECTOR n = XMLoadFloat4( &nvec ); - XMVECTOR X = XMVector4Reflect( i, n ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat4(&ivec); + XMVECTOR n = XMLoadFloat4(&nvec); + XMVECTOR X = XMVector4Reflect(i, n); + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Reflect( const Vector4& ivec, const Vector4& nvec ) +inline Vector4 Vector4::Reflect(const Vector4& ivec, const Vector4& nvec) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat4( &ivec ); - XMVECTOR n = XMLoadFloat4( &nvec ); - XMVECTOR X = XMVector4Reflect( i, n ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat4(&ivec); + XMVECTOR n = XMLoadFloat4(&nvec); + XMVECTOR X = XMVector4Reflect(i, n); - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::Refract( const Vector4& ivec, const Vector4& nvec, float refractionIndex, Vector4& result ) +inline void Vector4::Refract(const Vector4& ivec, const Vector4& nvec, float refractionIndex, Vector4& result) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat4( &ivec ); - XMVECTOR n = XMLoadFloat4( &nvec ); - XMVECTOR X = XMVector4Refract( i, n, refractionIndex ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat4(&ivec); + XMVECTOR n = XMLoadFloat4(&nvec); + XMVECTOR X = XMVector4Refract(i, n, refractionIndex); + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Refract( const Vector4& ivec, const Vector4& nvec, float refractionIndex ) +inline Vector4 Vector4::Refract(const Vector4& ivec, const Vector4& nvec, float refractionIndex) { - using namespace DirectX; - XMVECTOR i = XMLoadFloat4( &ivec ); - XMVECTOR n = XMLoadFloat4( &nvec ); - XMVECTOR X = XMVector4Refract( i, n, refractionIndex ); + using namespace DirectX; + XMVECTOR i = XMLoadFloat4(&ivec); + XMVECTOR n = XMLoadFloat4(&nvec); + XMVECTOR X = XMVector4Refract(i, n, refractionIndex); - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::Transform( const Vector2& v, const Quaternion& quat, Vector4& result ) +inline void Vector4::Transform(const Vector2& v, const Quaternion& quat, Vector4& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &v ); - XMVECTOR q = XMLoadFloat4( &quat ); - XMVECTOR X = XMVector3Rotate( v1, q ); - X = XMVectorSelect( g_XMIdentityR3, X, g_XMSelect1110 ); // result.w = 1.f - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&v); + XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Transform( const Vector2& v, const Quaternion& quat ) +inline Vector4 Vector4::Transform(const Vector2& v, const Quaternion& quat) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat2( &v ); - XMVECTOR q = XMLoadFloat4( &quat ); - XMVECTOR X = XMVector3Rotate( v1, q ); - X = XMVectorSelect( g_XMIdentityR3, X, g_XMSelect1110 ); // result.w = 1.f + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat2(&v); + XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::Transform( const Vector3& v, const Quaternion& quat, Vector4& result ) +inline void Vector4::Transform(const Vector3& v, const Quaternion& quat, Vector4& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &v ); - XMVECTOR q = XMLoadFloat4( &quat ); - XMVECTOR X = XMVector3Rotate( v1, q ); - X = XMVectorSelect( g_XMIdentityR3, X, g_XMSelect1110 ); // result.w = 1.f - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&v); + XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Transform( const Vector3& v, const Quaternion& quat ) +inline Vector4 Vector4::Transform(const Vector3& v, const Quaternion& quat) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat3( &v ); - XMVECTOR q = XMLoadFloat4( &quat ); - XMVECTOR X = XMVector3Rotate( v1, q ); - X = XMVectorSelect( g_XMIdentityR3, X, g_XMSelect1110 ); // result.w = 1.f + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat3(&v); + XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::Transform( const Vector4& v, const Quaternion& quat, Vector4& result ) +inline void Vector4::Transform(const Vector4& v, const Quaternion& quat, Vector4& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( &v ); - XMVECTOR q = XMLoadFloat4( &quat ); - XMVECTOR X = XMVector3Rotate( v1, q ); - X = XMVectorSelect( v1, X, g_XMSelect1110 ); // result.w = v.w - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(&v); + XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(v1, X, g_XMSelect1110); // result.w = v.w + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Transform( const Vector4& v, const Quaternion& quat ) +inline Vector4 Vector4::Transform(const Vector4& v, const Quaternion& quat) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( &v ); - XMVECTOR q = XMLoadFloat4( &quat ); - XMVECTOR X = XMVector3Rotate( v1, q ); - X = XMVectorSelect( v1, X, g_XMSelect1110 ); // result.w = v.w + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(&v); + XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(v1, X, g_XMSelect1110); // result.w = v.w - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } -inline void Vector4::Transform( const Vector4& v, const Matrix& m, Vector4& result ) +inline void Vector4::Transform(const Vector4& v, const Matrix& m, Vector4& result) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector4Transform( v1, M ); - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector4Transform(v1, M); + XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Transform( const Vector4& v, const Matrix& m ) +inline Vector4 Vector4::Transform(const Vector4& v, const Matrix& m) { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( &v ); - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVECTOR X = XMVector4Transform( v1, M ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(&v); + XMMATRIX M = XMLoadFloat4x4(&m); + XMVECTOR X = XMVector4Transform(v1, M); - Vector4 result; - XMStoreFloat4( &result, X ); - return result; + Vector4 result; + XMStoreFloat4(&result, X); + return result; } _Use_decl_annotations_ -inline void Vector4::Transform( const Vector4* varray, size_t count, const Matrix& m, Vector4* resultArray ) + +inline void Vector4::Transform(const Vector4* varray, size_t count, const Matrix& m, Vector4* resultArray) { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( &m ); - XMVector4TransformStream( resultArray, sizeof(XMFLOAT4), varray, sizeof(XMFLOAT4), count, M ); + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(&m); + XMVector4TransformStream(resultArray, sizeof(XMFLOAT4), varray, sizeof(XMFLOAT4), count, M); } @@ -1750,42 +1766,42 @@ inline void Vector4::Transform( const Vector4* varray, size_t count, const Matri // Comparision operators //------------------------------------------------------------------------------ -inline bool Matrix::operator == ( const Matrix& M ) const +inline bool Matrix::operator ==(const Matrix& M) const { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&_11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&_21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&_31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&_41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&_21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&_31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&_41)); - XMVECTOR y1 = XMLoadFloat4( reinterpret_cast(&M._11) ); - XMVECTOR y2 = XMLoadFloat4( reinterpret_cast(&M._21) ); - XMVECTOR y3 = XMLoadFloat4( reinterpret_cast(&M._31) ); - XMVECTOR y4 = XMLoadFloat4( reinterpret_cast(&M._41) ); + XMVECTOR y1 = XMLoadFloat4(reinterpret_cast(&M._11)); + XMVECTOR y2 = XMLoadFloat4(reinterpret_cast(&M._21)); + XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M._31)); + XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M._41)); - return ( XMVector4Equal( x1, y1 ) - && XMVector4Equal( x2, y2 ) - && XMVector4Equal( x3, y3 ) - && XMVector4Equal( x4, y4 ) ) != 0; + return (XMVector4Equal(x1, y1) + && XMVector4Equal(x2, y2) + && XMVector4Equal(x3, y3) + && XMVector4Equal(x4, y4)) != 0; } -inline bool Matrix::operator != ( const Matrix& M ) const +inline bool Matrix::operator !=(const Matrix& M) const { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&_11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&_21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&_31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&_41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&_21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&_31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&_41)); - XMVECTOR y1 = XMLoadFloat4( reinterpret_cast(&M._11) ); - XMVECTOR y2 = XMLoadFloat4( reinterpret_cast(&M._21) ); - XMVECTOR y3 = XMLoadFloat4( reinterpret_cast(&M._31) ); - XMVECTOR y4 = XMLoadFloat4( reinterpret_cast(&M._41) ); + XMVECTOR y1 = XMLoadFloat4(reinterpret_cast(&M._11)); + XMVECTOR y2 = XMLoadFloat4(reinterpret_cast(&M._21)); + XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M._31)); + XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M._41)); - return ( XMVector4NotEqual( x1, y1 ) - || XMVector4NotEqual( x2, y2 ) - || XMVector4NotEqual( x3, y3 ) - || XMVector4NotEqual( x4, y4 ) ) != 0; + return (XMVector4NotEqual(x1, y1) + || XMVector4NotEqual(x2, y2) + || XMVector4NotEqual(x3, y3) + || XMVector4NotEqual(x4, y4)) != 0; } //------------------------------------------------------------------------------ @@ -1794,412 +1810,460 @@ inline bool Matrix::operator != ( const Matrix& M ) const inline Matrix::Matrix(const XMFLOAT3X3& M) { - _11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f; - _21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f; - _31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f; - _41 = 0.f; _42 = 0.f; _43 = 0.f; _44 = 1.f; + _11 = M._11; + _12 = M._12; + _13 = M._13; + _14 = 0.f; + _21 = M._21; + _22 = M._22; + _23 = M._23; + _24 = 0.f; + _31 = M._31; + _32 = M._32; + _33 = M._33; + _34 = 0.f; + _41 = 0.f; + _42 = 0.f; + _43 = 0.f; + _44 = 1.f; } inline Matrix::Matrix(const XMFLOAT4X3& M) { - _11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f; - _21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f; - _31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f; - _41 = M._41; _42 = M._42; _43 = M._43; _44 = 1.f; + _11 = M._11; + _12 = M._12; + _13 = M._13; + _14 = 0.f; + _21 = M._21; + _22 = M._22; + _23 = M._23; + _24 = 0.f; + _31 = M._31; + _32 = M._32; + _33 = M._33; + _34 = 0.f; + _41 = M._41; + _42 = M._42; + _43 = M._43; + _44 = 1.f; } -inline Matrix& Matrix::operator= (const XMFLOAT3X3& M) +inline Matrix& Matrix::operator=(const XMFLOAT3X3& M) { - _11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f; - _21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f; - _31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f; - _41 = 0.f; _42 = 0.f; _43 = 0.f; _44 = 1.f; - return *this; + _11 = M._11; + _12 = M._12; + _13 = M._13; + _14 = 0.f; + _21 = M._21; + _22 = M._22; + _23 = M._23; + _24 = 0.f; + _31 = M._31; + _32 = M._32; + _33 = M._33; + _34 = 0.f; + _41 = 0.f; + _42 = 0.f; + _43 = 0.f; + _44 = 1.f; + return *this; } -inline Matrix& Matrix::operator= (const XMFLOAT4X3& M) +inline Matrix& Matrix::operator=(const XMFLOAT4X3& M) { - _11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f; - _21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f; - _31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f; - _41 = M._41; _42 = M._42; _43 = M._43; _44 = 1.f; - return *this; + _11 = M._11; + _12 = M._12; + _13 = M._13; + _14 = 0.f; + _21 = M._21; + _22 = M._22; + _23 = M._23; + _24 = 0.f; + _31 = M._31; + _32 = M._32; + _33 = M._33; + _34 = 0.f; + _41 = M._41; + _42 = M._42; + _43 = M._43; + _44 = 1.f; + return *this; } -inline Matrix& Matrix::operator+= (const Matrix& M) +inline Matrix& Matrix::operator+=(const Matrix& M) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&_11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&_21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&_31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&_41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&_21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&_31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&_41)); - XMVECTOR y1 = XMLoadFloat4( reinterpret_cast(&M._11) ); - XMVECTOR y2 = XMLoadFloat4( reinterpret_cast(&M._21) ); - XMVECTOR y3 = XMLoadFloat4( reinterpret_cast(&M._31) ); - XMVECTOR y4 = XMLoadFloat4( reinterpret_cast(&M._41) ); + XMVECTOR y1 = XMLoadFloat4(reinterpret_cast(&M._11)); + XMVECTOR y2 = XMLoadFloat4(reinterpret_cast(&M._21)); + XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M._31)); + XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M._41)); - x1 = XMVectorAdd( x1, y1 ); - x2 = XMVectorAdd( x2, y2 ); - x3 = XMVectorAdd( x3, y3 ); - x4 = XMVectorAdd( x4, y4 ); + x1 = XMVectorAdd(x1, y1); + x2 = XMVectorAdd(x2, y2); + x3 = XMVectorAdd(x3, y3); + x4 = XMVectorAdd(x4, y4); - XMStoreFloat4( reinterpret_cast(&_11), x1 ); - XMStoreFloat4( reinterpret_cast(&_21), x2 ); - XMStoreFloat4( reinterpret_cast(&_31), x3 ); - XMStoreFloat4( reinterpret_cast(&_41), x4 ); - return *this; + XMStoreFloat4(reinterpret_cast(&_11), x1); + XMStoreFloat4(reinterpret_cast(&_21), x2); + XMStoreFloat4(reinterpret_cast(&_31), x3); + XMStoreFloat4(reinterpret_cast(&_41), x4); + return *this; } -inline Matrix& Matrix::operator-= (const Matrix& M) +inline Matrix& Matrix::operator-=(const Matrix& M) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&_11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&_21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&_31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&_41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&_21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&_31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&_41)); - XMVECTOR y1 = XMLoadFloat4( reinterpret_cast(&M._11) ); - XMVECTOR y2 = XMLoadFloat4( reinterpret_cast(&M._21) ); - XMVECTOR y3 = XMLoadFloat4( reinterpret_cast(&M._31) ); - XMVECTOR y4 = XMLoadFloat4( reinterpret_cast(&M._41) ); + XMVECTOR y1 = XMLoadFloat4(reinterpret_cast(&M._11)); + XMVECTOR y2 = XMLoadFloat4(reinterpret_cast(&M._21)); + XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M._31)); + XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M._41)); - x1 = XMVectorSubtract( x1, y1 ); - x2 = XMVectorSubtract( x2, y2 ); - x3 = XMVectorSubtract( x3, y3 ); - x4 = XMVectorSubtract( x4, y4 ); + x1 = XMVectorSubtract(x1, y1); + x2 = XMVectorSubtract(x2, y2); + x3 = XMVectorSubtract(x3, y3); + x4 = XMVectorSubtract(x4, y4); - XMStoreFloat4( reinterpret_cast(&_11), x1 ); - XMStoreFloat4( reinterpret_cast(&_21), x2 ); - XMStoreFloat4( reinterpret_cast(&_31), x3 ); - XMStoreFloat4( reinterpret_cast(&_41), x4 ); - return *this; + XMStoreFloat4(reinterpret_cast(&_11), x1); + XMStoreFloat4(reinterpret_cast(&_21), x2); + XMStoreFloat4(reinterpret_cast(&_31), x3); + XMStoreFloat4(reinterpret_cast(&_41), x4); + return *this; } -inline Matrix& Matrix::operator*= (const Matrix& M) +inline Matrix& Matrix::operator*=(const Matrix& M) { - using namespace DirectX; - XMMATRIX M1 = XMLoadFloat4x4( this ); - XMMATRIX M2 = XMLoadFloat4x4( &M ); - XMMATRIX X = XMMatrixMultiply( M1, M2 ); - XMStoreFloat4x4( this, X ); - return *this; + using namespace DirectX; + XMMATRIX M1 = XMLoadFloat4x4(this); + XMMATRIX M2 = XMLoadFloat4x4(&M); + XMMATRIX X = XMMatrixMultiply(M1, M2); + XMStoreFloat4x4(this, X); + return *this; } -inline Matrix& Matrix::operator*= (float S) +inline Matrix& Matrix::operator*=(float S) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&_11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&_21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&_31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&_41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&_21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&_31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&_41)); - x1 = XMVectorScale( x1, S ); - x2 = XMVectorScale( x2, S ); - x3 = XMVectorScale( x3, S ); - x4 = XMVectorScale( x4, S ); + x1 = XMVectorScale(x1, S); + x2 = XMVectorScale(x2, S); + x3 = XMVectorScale(x3, S); + x4 = XMVectorScale(x4, S); - XMStoreFloat4( reinterpret_cast(&_11), x1 ); - XMStoreFloat4( reinterpret_cast(&_21), x2 ); - XMStoreFloat4( reinterpret_cast(&_31), x3 ); - XMStoreFloat4( reinterpret_cast(&_41), x4 ); - return *this; + XMStoreFloat4(reinterpret_cast(&_11), x1); + XMStoreFloat4(reinterpret_cast(&_21), x2); + XMStoreFloat4(reinterpret_cast(&_31), x3); + XMStoreFloat4(reinterpret_cast(&_41), x4); + return *this; } -inline Matrix& Matrix::operator/= (float S) +inline Matrix& Matrix::operator/=(float S) { - using namespace DirectX; - assert( S != 0.f ); - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&_11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&_21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&_31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&_41) ); + using namespace DirectX; + assert(S != 0.f); + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&_21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&_31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&_41)); - float rs = 1.f / S; + float rs = 1.f / S; - x1 = XMVectorScale( x1, rs ); - x2 = XMVectorScale( x2, rs ); - x3 = XMVectorScale( x3, rs ); - x4 = XMVectorScale( x4, rs ); + x1 = XMVectorScale(x1, rs); + x2 = XMVectorScale(x2, rs); + x3 = XMVectorScale(x3, rs); + x4 = XMVectorScale(x4, rs); - XMStoreFloat4( reinterpret_cast(&_11), x1 ); - XMStoreFloat4( reinterpret_cast(&_21), x2 ); - XMStoreFloat4( reinterpret_cast(&_31), x3 ); - XMStoreFloat4( reinterpret_cast(&_41), x4 ); - return *this; + XMStoreFloat4(reinterpret_cast(&_11), x1); + XMStoreFloat4(reinterpret_cast(&_21), x2); + XMStoreFloat4(reinterpret_cast(&_31), x3); + XMStoreFloat4(reinterpret_cast(&_41), x4); + return *this; } -inline Matrix& Matrix::operator/= (const Matrix& M) +inline Matrix& Matrix::operator/=(const Matrix& M) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&_11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&_21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&_31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&_41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&_21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&_31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&_41)); - XMVECTOR y1 = XMLoadFloat4( reinterpret_cast(&M._11) ); - XMVECTOR y2 = XMLoadFloat4( reinterpret_cast(&M._21) ); - XMVECTOR y3 = XMLoadFloat4( reinterpret_cast(&M._31) ); - XMVECTOR y4 = XMLoadFloat4( reinterpret_cast(&M._41) ); + XMVECTOR y1 = XMLoadFloat4(reinterpret_cast(&M._11)); + XMVECTOR y2 = XMLoadFloat4(reinterpret_cast(&M._21)); + XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M._31)); + XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M._41)); - x1 = XMVectorDivide( x1, y1 ); - x2 = XMVectorDivide( x2, y2 ); - x3 = XMVectorDivide( x3, y3 ); - x4 = XMVectorDivide( x4, y4 ); + x1 = XMVectorDivide(x1, y1); + x2 = XMVectorDivide(x2, y2); + x3 = XMVectorDivide(x3, y3); + x4 = XMVectorDivide(x4, y4); - XMStoreFloat4( reinterpret_cast(&_11), x1 ); - XMStoreFloat4( reinterpret_cast(&_21), x2 ); - XMStoreFloat4( reinterpret_cast(&_31), x3 ); - XMStoreFloat4( reinterpret_cast(&_41), x4 ); - return *this; + XMStoreFloat4(reinterpret_cast(&_11), x1); + XMStoreFloat4(reinterpret_cast(&_21), x2); + XMStoreFloat4(reinterpret_cast(&_31), x3); + XMStoreFloat4(reinterpret_cast(&_41), x4); + return *this; } //------------------------------------------------------------------------------ // Urnary operators //------------------------------------------------------------------------------ -inline Matrix Matrix::operator- () const +inline Matrix Matrix::operator-() const { - using namespace DirectX; - XMVECTOR v1 = XMLoadFloat4( reinterpret_cast(&_11) ); - XMVECTOR v2 = XMLoadFloat4( reinterpret_cast(&_21) ); - XMVECTOR v3 = XMLoadFloat4( reinterpret_cast(&_31) ); - XMVECTOR v4 = XMLoadFloat4( reinterpret_cast(&_41) ); + using namespace DirectX; + XMVECTOR v1 = XMLoadFloat4(reinterpret_cast(&_11)); + XMVECTOR v2 = XMLoadFloat4(reinterpret_cast(&_21)); + XMVECTOR v3 = XMLoadFloat4(reinterpret_cast(&_31)); + XMVECTOR v4 = XMLoadFloat4(reinterpret_cast(&_41)); - v1 = XMVectorNegate( v1 ); - v2 = XMVectorNegate( v2 ); - v3 = XMVectorNegate( v3 ); - v4 = XMVectorNegate( v4 ); + v1 = XMVectorNegate(v1); + v2 = XMVectorNegate(v2); + v3 = XMVectorNegate(v3); + v4 = XMVectorNegate(v4); - Matrix R; - XMStoreFloat4( reinterpret_cast(&R._11), v1 ); - XMStoreFloat4( reinterpret_cast(&R._21), v2 ); - XMStoreFloat4( reinterpret_cast(&R._31), v3 ); - XMStoreFloat4( reinterpret_cast(&R._41), v4 ); - return R; + Matrix R; + XMStoreFloat4(reinterpret_cast(&R._11), v1); + XMStoreFloat4(reinterpret_cast(&R._21), v2); + XMStoreFloat4(reinterpret_cast(&R._31), v3); + XMStoreFloat4(reinterpret_cast(&R._41), v4); + return R; } //------------------------------------------------------------------------------ // Binary operators //------------------------------------------------------------------------------ -inline Matrix operator+ (const Matrix& M1, const Matrix& M2) +inline Matrix operator+(const Matrix& M1, const Matrix& M2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&M1._11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&M1._21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&M1._31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&M1._41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M1._11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&M1._21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&M1._31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&M1._41)); - XMVECTOR y1 = XMLoadFloat4( reinterpret_cast(&M2._11) ); - XMVECTOR y2 = XMLoadFloat4( reinterpret_cast(&M2._21) ); - XMVECTOR y3 = XMLoadFloat4( reinterpret_cast(&M2._31) ); - XMVECTOR y4 = XMLoadFloat4( reinterpret_cast(&M2._41) ); + XMVECTOR y1 = XMLoadFloat4(reinterpret_cast(&M2._11)); + XMVECTOR y2 = XMLoadFloat4(reinterpret_cast(&M2._21)); + XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M2._31)); + XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M2._41)); - x1 = XMVectorAdd( x1, y1 ); - x2 = XMVectorAdd( x2, y2 ); - x3 = XMVectorAdd( x3, y3 ); - x4 = XMVectorAdd( x4, y4 ); + x1 = XMVectorAdd(x1, y1); + x2 = XMVectorAdd(x2, y2); + x3 = XMVectorAdd(x3, y3); + x4 = XMVectorAdd(x4, y4); - Matrix R; - XMStoreFloat4( reinterpret_cast(&R._11), x1 ); - XMStoreFloat4( reinterpret_cast(&R._21), x2 ); - XMStoreFloat4( reinterpret_cast(&R._31), x3 ); - XMStoreFloat4( reinterpret_cast(&R._41), x4 ); - return R; + Matrix R; + XMStoreFloat4(reinterpret_cast(&R._11), x1); + XMStoreFloat4(reinterpret_cast(&R._21), x2); + XMStoreFloat4(reinterpret_cast(&R._31), x3); + XMStoreFloat4(reinterpret_cast(&R._41), x4); + return R; } -inline Matrix operator- (const Matrix& M1, const Matrix& M2) +inline Matrix operator-(const Matrix& M1, const Matrix& M2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&M1._11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&M1._21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&M1._31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&M1._41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M1._11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&M1._21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&M1._31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&M1._41)); - XMVECTOR y1 = XMLoadFloat4( reinterpret_cast(&M2._11) ); - XMVECTOR y2 = XMLoadFloat4( reinterpret_cast(&M2._21) ); - XMVECTOR y3 = XMLoadFloat4( reinterpret_cast(&M2._31) ); - XMVECTOR y4 = XMLoadFloat4( reinterpret_cast(&M2._41) ); + XMVECTOR y1 = XMLoadFloat4(reinterpret_cast(&M2._11)); + XMVECTOR y2 = XMLoadFloat4(reinterpret_cast(&M2._21)); + XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M2._31)); + XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M2._41)); - x1 = XMVectorSubtract( x1, y1 ); - x2 = XMVectorSubtract( x2, y2 ); - x3 = XMVectorSubtract( x3, y3 ); - x4 = XMVectorSubtract( x4, y4 ); + x1 = XMVectorSubtract(x1, y1); + x2 = XMVectorSubtract(x2, y2); + x3 = XMVectorSubtract(x3, y3); + x4 = XMVectorSubtract(x4, y4); - Matrix R; - XMStoreFloat4( reinterpret_cast(&R._11), x1 ); - XMStoreFloat4( reinterpret_cast(&R._21), x2 ); - XMStoreFloat4( reinterpret_cast(&R._31), x3 ); - XMStoreFloat4( reinterpret_cast(&R._41), x4 ); - return R; + Matrix R; + XMStoreFloat4(reinterpret_cast(&R._11), x1); + XMStoreFloat4(reinterpret_cast(&R._21), x2); + XMStoreFloat4(reinterpret_cast(&R._31), x3); + XMStoreFloat4(reinterpret_cast(&R._41), x4); + return R; } -inline Matrix operator* (const Matrix& M1, const Matrix& M2) +inline Matrix operator*(const Matrix& M1, const Matrix& M2) { - using namespace DirectX; - XMMATRIX m1 = XMLoadFloat4x4( &M1 ); - XMMATRIX m2 = XMLoadFloat4x4( &M2 ); - XMMATRIX X = XMMatrixMultiply( m1, m2 ); + using namespace DirectX; + XMMATRIX m1 = XMLoadFloat4x4(&M1); + XMMATRIX m2 = XMLoadFloat4x4(&M2); + XMMATRIX X = XMMatrixMultiply(m1, m2); - Matrix R; - XMStoreFloat4x4( &R, X ); - return R; + Matrix R; + XMStoreFloat4x4(&R, X); + return R; } -inline Matrix operator* (const Matrix& M, float S) +inline Matrix operator*(const Matrix& M, float S) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&M._11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&M._21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&M._31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&M._41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M._11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&M._21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&M._31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&M._41)); - x1 = XMVectorScale( x1, S ); - x2 = XMVectorScale( x2, S ); - x3 = XMVectorScale( x3, S ); - x4 = XMVectorScale( x4, S ); + x1 = XMVectorScale(x1, S); + x2 = XMVectorScale(x2, S); + x3 = XMVectorScale(x3, S); + x4 = XMVectorScale(x4, S); - Matrix R; - XMStoreFloat4( reinterpret_cast(&R._11), x1 ); - XMStoreFloat4( reinterpret_cast(&R._21), x2 ); - XMStoreFloat4( reinterpret_cast(&R._31), x3 ); - XMStoreFloat4( reinterpret_cast(&R._41), x4 ); - return R; + Matrix R; + XMStoreFloat4(reinterpret_cast(&R._11), x1); + XMStoreFloat4(reinterpret_cast(&R._21), x2); + XMStoreFloat4(reinterpret_cast(&R._31), x3); + XMStoreFloat4(reinterpret_cast(&R._41), x4); + return R; } -inline Matrix operator/ (const Matrix& M, float S) +inline Matrix operator/(const Matrix& M, float S) { - using namespace DirectX; - assert( S != 0.f ); + using namespace DirectX; + assert(S != 0.f); - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&M._11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&M._21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&M._31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&M._41) ); + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M._11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&M._21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&M._31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&M._41)); - float rs = 1.f / S; + float rs = 1.f / S; - x1 = XMVectorScale( x1, rs ); - x2 = XMVectorScale( x2, rs ); - x3 = XMVectorScale( x3, rs ); - x4 = XMVectorScale( x4, rs ); + x1 = XMVectorScale(x1, rs); + x2 = XMVectorScale(x2, rs); + x3 = XMVectorScale(x3, rs); + x4 = XMVectorScale(x4, rs); - Matrix R; - XMStoreFloat4( reinterpret_cast(&R._11), x1 ); - XMStoreFloat4( reinterpret_cast(&R._21), x2 ); - XMStoreFloat4( reinterpret_cast(&R._31), x3 ); - XMStoreFloat4( reinterpret_cast(&R._41), x4 ); - return R; + Matrix R; + XMStoreFloat4(reinterpret_cast(&R._11), x1); + XMStoreFloat4(reinterpret_cast(&R._21), x2); + XMStoreFloat4(reinterpret_cast(&R._31), x3); + XMStoreFloat4(reinterpret_cast(&R._41), x4); + return R; } -inline Matrix operator/ (const Matrix& M1, const Matrix& M2) +inline Matrix operator/(const Matrix& M1, const Matrix& M2) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&M1._11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&M1._21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&M1._31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&M1._41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M1._11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&M1._21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&M1._31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&M1._41)); - XMVECTOR y1 = XMLoadFloat4( reinterpret_cast(&M2._11) ); - XMVECTOR y2 = XMLoadFloat4( reinterpret_cast(&M2._21) ); - XMVECTOR y3 = XMLoadFloat4( reinterpret_cast(&M2._31) ); - XMVECTOR y4 = XMLoadFloat4( reinterpret_cast(&M2._41) ); + XMVECTOR y1 = XMLoadFloat4(reinterpret_cast(&M2._11)); + XMVECTOR y2 = XMLoadFloat4(reinterpret_cast(&M2._21)); + XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M2._31)); + XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M2._41)); - x1 = XMVectorDivide( x1, y1 ); - x2 = XMVectorDivide( x2, y2 ); - x3 = XMVectorDivide( x3, y3 ); - x4 = XMVectorDivide( x4, y4 ); + x1 = XMVectorDivide(x1, y1); + x2 = XMVectorDivide(x2, y2); + x3 = XMVectorDivide(x3, y3); + x4 = XMVectorDivide(x4, y4); - Matrix R; - XMStoreFloat4( reinterpret_cast(&R._11), x1 ); - XMStoreFloat4( reinterpret_cast(&R._21), x2 ); - XMStoreFloat4( reinterpret_cast(&R._31), x3 ); - XMStoreFloat4( reinterpret_cast(&R._41), x4 ); - return R; + Matrix R; + XMStoreFloat4(reinterpret_cast(&R._11), x1); + XMStoreFloat4(reinterpret_cast(&R._21), x2); + XMStoreFloat4(reinterpret_cast(&R._31), x3); + XMStoreFloat4(reinterpret_cast(&R._41), x4); + return R; } -inline Matrix operator* (float S, const Matrix& M) +inline Matrix operator*(float S, const Matrix& M) { - using namespace DirectX; + using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&M._11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&M._21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&M._31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&M._41) ); + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M._11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&M._21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&M._31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&M._41)); - x1 = XMVectorScale( x1, S ); - x2 = XMVectorScale( x2, S ); - x3 = XMVectorScale( x3, S ); - x4 = XMVectorScale( x4, S ); + x1 = XMVectorScale(x1, S); + x2 = XMVectorScale(x2, S); + x3 = XMVectorScale(x3, S); + x4 = XMVectorScale(x4, S); - Matrix R; - XMStoreFloat4( reinterpret_cast(&R._11), x1 ); - XMStoreFloat4( reinterpret_cast(&R._21), x2 ); - XMStoreFloat4( reinterpret_cast(&R._31), x3 ); - XMStoreFloat4( reinterpret_cast(&R._41), x4 ); - return R; + Matrix R; + XMStoreFloat4(reinterpret_cast(&R._11), x1); + XMStoreFloat4(reinterpret_cast(&R._21), x2); + XMStoreFloat4(reinterpret_cast(&R._31), x3); + XMStoreFloat4(reinterpret_cast(&R._41), x4); + return R; } //------------------------------------------------------------------------------ // Matrix operations //------------------------------------------------------------------------------ -inline bool Matrix::Decompose( Vector3& scale, Quaternion& rotation, Vector3& translation ) +inline bool Matrix::Decompose(Vector3& scale, Quaternion& rotation, Vector3& translation) { - using namespace DirectX; + using namespace DirectX; - XMVECTOR s, r, t; + XMVECTOR s, r, t; - if ( !XMMatrixDecompose( &s, &r, &t, *this ) ) - return false; + if (!XMMatrixDecompose(&s, &r, &t, *this)) + return false; - XMStoreFloat3( &scale, s ); - XMStoreFloat4( &rotation, r ); - XMStoreFloat3( &translation, t ); + XMStoreFloat3(&scale, s); + XMStoreFloat4(&rotation, r); + XMStoreFloat3(&translation, t); - return true; + return true; } inline Matrix Matrix::Transpose() const { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( this ); - Matrix R; - XMStoreFloat4x4( &R, XMMatrixTranspose( M ) ); - return R; + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(this); + Matrix R; + XMStoreFloat4x4(&R, XMMatrixTranspose(M)); + return R; } -inline void Matrix::Transpose( Matrix& result ) const +inline void Matrix::Transpose(Matrix& result) const { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( this ); - XMStoreFloat4x4( &result, XMMatrixTranspose( M ) ); + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(this); + XMStoreFloat4x4(&result, XMMatrixTranspose(M)); } inline Matrix Matrix::Invert() const { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( this ); - Matrix R; - XMVECTOR det; - XMStoreFloat4x4( &R, XMMatrixInverse( &det, M ) ); - return R; + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(this); + Matrix R; + XMVECTOR det; + XMStoreFloat4x4(&R, XMMatrixInverse(&det, M)); + return R; } -inline void Matrix::Invert( Matrix& result ) const +inline void Matrix::Invert(Matrix& result) const { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( this ); - XMVECTOR det; - XMStoreFloat4x4( &result, XMMatrixInverse( &det, M ) ); + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(this); + XMVECTOR det; + XMStoreFloat4x4(&result, XMMatrixInverse(&det, M)); } inline float Matrix::Determinant() const { - using namespace DirectX; - XMMATRIX M = XMLoadFloat4x4( this ); - return XMVectorGetX( XMMatrixDeterminant( M ) ); + using namespace DirectX; + XMMATRIX M = XMLoadFloat4x4(this); + return XMVectorGetX(XMMatrixDeterminant(M)); } //------------------------------------------------------------------------------ @@ -2207,372 +2271,381 @@ inline float Matrix::Determinant() const //------------------------------------------------------------------------------ _Use_decl_annotations_ -inline Matrix Matrix::CreateBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp, const Vector3* cameraForward ) + +inline Matrix Matrix::CreateBillboard(const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp, + const Vector3* cameraForward) { - using namespace DirectX; - XMVECTOR O = XMLoadFloat3( &object ); - XMVECTOR C = XMLoadFloat3( &cameraPosition ); - XMVECTOR Z = XMVectorSubtract( O, C ); + using namespace DirectX; + XMVECTOR O = XMLoadFloat3(&object); + XMVECTOR C = XMLoadFloat3(&cameraPosition); + XMVECTOR Z = XMVectorSubtract(O, C); - XMVECTOR N = XMVector3LengthSq( Z ); - if ( XMVector3Less( N, g_XMEpsilon ) ) - { - if ( cameraForward ) - { - XMVECTOR F = XMLoadFloat3( cameraForward ); - Z = XMVectorNegate( F ); - } - else - Z = g_XMNegIdentityR2; - } - else - { - Z = XMVector3Normalize( Z ); - } + XMVECTOR N = XMVector3LengthSq(Z); + if (XMVector3Less(N, g_XMEpsilon)) + { + if (cameraForward) + { + XMVECTOR F = XMLoadFloat3(cameraForward); + Z = XMVectorNegate(F); + } + else + Z = g_XMNegIdentityR2; + } + else + { + Z = XMVector3Normalize(Z); + } - XMVECTOR up = XMLoadFloat3( &cameraUp ); - XMVECTOR X = XMVector3Cross( up, Z ); - X = XMVector3Normalize( X ); + XMVECTOR up = XMLoadFloat3(&cameraUp); + XMVECTOR X = XMVector3Cross(up, Z); + X = XMVector3Normalize(X); - XMVECTOR Y = XMVector3Cross( Z, X ); + XMVECTOR Y = XMVector3Cross(Z, X); - XMMATRIX M; - M.r[0] = X; - M.r[1] = Y; - M.r[2] = Z; - M.r[3] = XMVectorSetW( O, 1.f ); + XMMATRIX M; + M.r[0] = X; + M.r[1] = Y; + M.r[2] = Z; + M.r[3] = XMVectorSetW(O, 1.f); - Matrix R; - XMStoreFloat4x4( &R, M ); - return R; + Matrix R; + XMStoreFloat4x4(&R, M); + return R; } _Use_decl_annotations_ -inline Matrix Matrix::CreateConstrainedBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& rotateAxis, - const Vector3* cameraForward, const Vector3* objectForward ) + +inline Matrix Matrix::CreateConstrainedBillboard(const Vector3& object, const Vector3& cameraPosition, + const Vector3& rotateAxis, + const Vector3* cameraForward, const Vector3* objectForward) { - using namespace DirectX; + using namespace DirectX; - static const XMVECTORF32 s_minAngle = { 0.99825467075f, 0.99825467075f, 0.99825467075f, 0.99825467075f }; // 1.0 - XMConvertToRadians( 0.1f ); + static const XMVECTORF32 s_minAngle = {0.99825467075f, 0.99825467075f, 0.99825467075f, 0.99825467075f}; + // 1.0 - XMConvertToRadians( 0.1f ); - XMVECTOR O = XMLoadFloat3( &object ); - XMVECTOR C = XMLoadFloat3( &cameraPosition ); - XMVECTOR faceDir = XMVectorSubtract( O, C ); + XMVECTOR O = XMLoadFloat3(&object); + XMVECTOR C = XMLoadFloat3(&cameraPosition); + XMVECTOR faceDir = XMVectorSubtract(O, C); - XMVECTOR N = XMVector3LengthSq( faceDir ); - if (XMVector3Less(N, g_XMEpsilon)) - { - if (cameraForward) - { - XMVECTOR F = XMLoadFloat3( cameraForward ); - faceDir = XMVectorNegate( F ); - } - else - faceDir = g_XMNegIdentityR2; - } - else - { - faceDir = XMVector3Normalize( faceDir ); - } + XMVECTOR N = XMVector3LengthSq(faceDir); + if (XMVector3Less(N, g_XMEpsilon)) + { + if (cameraForward) + { + XMVECTOR F = XMLoadFloat3(cameraForward); + faceDir = XMVectorNegate(F); + } + else + faceDir = g_XMNegIdentityR2; + } + else + { + faceDir = XMVector3Normalize(faceDir); + } - XMVECTOR Y = XMLoadFloat3( &rotateAxis ); - XMVECTOR X, Z; + XMVECTOR Y = XMLoadFloat3(&rotateAxis); + XMVECTOR X, Z; - XMVECTOR dot = XMVectorAbs( XMVector3Dot( Y, faceDir ) ); - if ( XMVector3Greater( dot, s_minAngle ) ) - { - if ( objectForward ) - { - Z = XMLoadFloat3( objectForward ); - dot = XMVectorAbs( XMVector3Dot( Y, Z ) ); - if ( XMVector3Greater( dot, s_minAngle ) ) - { - dot = XMVectorAbs( XMVector3Dot( Y, g_XMNegIdentityR2 ) ); - Z = ( XMVector3Greater( dot, s_minAngle ) ) ? g_XMIdentityR0 : g_XMNegIdentityR2; - } - } - else - { - dot = XMVectorAbs( XMVector3Dot( Y, g_XMNegIdentityR2 ) ); - Z = ( XMVector3Greater( dot, s_minAngle ) ) ? g_XMIdentityR0 : g_XMNegIdentityR2; - } + XMVECTOR dot = XMVectorAbs(XMVector3Dot(Y, faceDir)); + if (XMVector3Greater(dot, s_minAngle)) + { + if (objectForward) + { + Z = XMLoadFloat3(objectForward); + dot = XMVectorAbs(XMVector3Dot(Y, Z)); + if (XMVector3Greater(dot, s_minAngle)) + { + dot = XMVectorAbs(XMVector3Dot(Y, g_XMNegIdentityR2)); + Z = (XMVector3Greater(dot, s_minAngle)) ? g_XMIdentityR0 : g_XMNegIdentityR2; + } + } + else + { + dot = XMVectorAbs(XMVector3Dot(Y, g_XMNegIdentityR2)); + Z = (XMVector3Greater(dot, s_minAngle)) ? g_XMIdentityR0 : g_XMNegIdentityR2; + } - X = XMVector3Cross( Y, Z ); - X = XMVector3Normalize( X ); + X = XMVector3Cross(Y, Z); + X = XMVector3Normalize(X); - Z = XMVector3Cross( X, Y ); - Z = XMVector3Normalize( Z ); - } - else - { - X = XMVector3Cross( Y, faceDir ); - X = XMVector3Normalize( X ); + Z = XMVector3Cross(X, Y); + Z = XMVector3Normalize(Z); + } + else + { + X = XMVector3Cross(Y, faceDir); + X = XMVector3Normalize(X); - Z = XMVector3Cross( X, Y ); - Z = XMVector3Normalize( Z ); - } + Z = XMVector3Cross(X, Y); + Z = XMVector3Normalize(Z); + } - XMMATRIX M; - M.r[0] = X; - M.r[1] = Y; - M.r[2] = Z; - M.r[3] = XMVectorSetW( O, 1.f ); + XMMATRIX M; + M.r[0] = X; + M.r[1] = Y; + M.r[2] = Z; + M.r[3] = XMVectorSetW(O, 1.f); - Matrix R; - XMStoreFloat4x4( &R, M ); - return R; + Matrix R; + XMStoreFloat4x4(&R, M); + return R; } -inline Matrix Matrix::CreateTranslation( const Vector3& position ) +inline Matrix Matrix::CreateTranslation(const Vector3& position) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixTranslation( position.x, position.y, position.z ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixTranslation(position.x, position.y, position.z)); + return R; } -inline Matrix Matrix::CreateTranslation( float x, float y, float z ) +inline Matrix Matrix::CreateTranslation(float x, float y, float z) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixTranslation( x, y, z ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixTranslation(x, y, z)); + return R; } -inline Matrix Matrix::CreateScale( const Vector3& scales ) +inline Matrix Matrix::CreateScale(const Vector3& scales) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixScaling( scales.x, scales.y, scales.z ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixScaling(scales.x, scales.y, scales.z)); + return R; } -inline Matrix Matrix::CreateScale( float xs, float ys, float zs ) +inline Matrix Matrix::CreateScale(float xs, float ys, float zs) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixScaling( xs, ys, zs ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixScaling(xs, ys, zs)); + return R; } -inline Matrix Matrix::CreateScale( float scale ) +inline Matrix Matrix::CreateScale(float scale) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixScaling( scale, scale, scale ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixScaling(scale, scale, scale)); + return R; } -inline Matrix Matrix::CreateRotationX( float radians ) +inline Matrix Matrix::CreateRotationX(float radians) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixRotationX( radians ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixRotationX(radians)); + return R; } -inline Matrix Matrix::CreateRotationY( float radians ) +inline Matrix Matrix::CreateRotationY(float radians) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixRotationY( radians ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixRotationY(radians)); + return R; } -inline Matrix Matrix::CreateRotationZ( float radians ) +inline Matrix Matrix::CreateRotationZ(float radians) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixRotationZ( radians ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixRotationZ(radians)); + return R; } -inline Matrix Matrix::CreateFromAxisAngle( const Vector3& axis, float angle ) +inline Matrix Matrix::CreateFromAxisAngle(const Vector3& axis, float angle) { - using namespace DirectX; - Matrix R; - XMVECTOR a = XMLoadFloat3( &axis ); - XMStoreFloat4x4( &R, XMMatrixRotationAxis( a, angle ) ); - return R; + using namespace DirectX; + Matrix R; + XMVECTOR a = XMLoadFloat3(&axis); + XMStoreFloat4x4(&R, XMMatrixRotationAxis(a, angle)); + return R; } -inline Matrix Matrix::CreatePerspectiveFieldOfView( float fov, float aspectRatio, float nearPlane, float farPlane ) +inline Matrix Matrix::CreatePerspectiveFieldOfView(float fov, float aspectRatio, float nearPlane, float farPlane) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixPerspectiveFovRH( fov, aspectRatio, nearPlane, farPlane ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixPerspectiveFovRH(fov, aspectRatio, nearPlane, farPlane)); + return R; } -inline Matrix Matrix::CreatePerspective( float width, float height, float nearPlane, float farPlane ) +inline Matrix Matrix::CreatePerspective(float width, float height, float nearPlane, float farPlane) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixPerspectiveRH( width, height, nearPlane, farPlane ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixPerspectiveRH(width, height, nearPlane, farPlane)); + return R; } -inline Matrix Matrix::CreatePerspectiveOffCenter( float left, float right, float bottom, float top, float nearPlane, float farPlane ) +inline Matrix Matrix::CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlane, + float farPlane) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixPerspectiveOffCenterRH( left, right, bottom, top, nearPlane, farPlane ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixPerspectiveOffCenterRH(left, right, bottom, top, nearPlane, farPlane)); + return R; } -inline Matrix Matrix::CreateOrthographic( float width, float height, float zNearPlane, float zFarPlane ) +inline Matrix Matrix::CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixOrthographicRH( width, height, zNearPlane, zFarPlane ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixOrthographicRH(width, height, zNearPlane, zFarPlane)); + return R; } -inline Matrix Matrix::CreateOrthographicOffCenter( float left, float right, float bottom, float top, float zNearPlane, float zFarPlane ) +inline Matrix Matrix::CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, + float zFarPlane) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixOrthographicOffCenterRH( left, right, bottom, top, zNearPlane, zFarPlane ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixOrthographicOffCenterRH(left, right, bottom, top, zNearPlane, zFarPlane)); + return R; } -inline Matrix Matrix::CreateLookAt( const Vector3& eye, const Vector3& target, const Vector3& up ) +inline Matrix Matrix::CreateLookAt(const Vector3& eye, const Vector3& target, const Vector3& up) { - using namespace DirectX; - Matrix R; - XMVECTOR eyev = XMLoadFloat3( &eye ); - XMVECTOR targetv = XMLoadFloat3( &target ); - XMVECTOR upv = XMLoadFloat3( &up ); - XMStoreFloat4x4( &R, XMMatrixLookAtRH( eyev, targetv, upv ) ); - return R; + using namespace DirectX; + Matrix R; + XMVECTOR eyev = XMLoadFloat3(&eye); + XMVECTOR targetv = XMLoadFloat3(&target); + XMVECTOR upv = XMLoadFloat3(&up); + XMStoreFloat4x4(&R, XMMatrixLookAtRH(eyev, targetv, upv)); + return R; } -inline Matrix Matrix::CreateWorld( const Vector3& position, const Vector3& forward, const Vector3& up ) +inline Matrix Matrix::CreateWorld(const Vector3& position, const Vector3& forward, const Vector3& up) { - using namespace DirectX; - XMVECTOR zaxis = XMVector3Normalize( XMVectorNegate( XMLoadFloat3( &forward ) ) ); - XMVECTOR yaxis = XMLoadFloat3( &up ); - XMVECTOR xaxis = XMVector3Normalize( XMVector3Cross( yaxis, zaxis ) ); - yaxis = XMVector3Cross( zaxis, xaxis ); - - Matrix R; - XMStoreFloat3( reinterpret_cast( &R._11 ), xaxis ); - XMStoreFloat3( reinterpret_cast( &R._21 ), yaxis ); - XMStoreFloat3( reinterpret_cast( &R._31 ), zaxis ); - R._14 = R._24 = R._34 = 0.f; - R._41 = position.x; R._42 = position.y; R._43 = position.z; - R._44 = 1.f; - return R; + using namespace DirectX; + XMVECTOR zaxis = XMVector3Normalize(XMVectorNegate(XMLoadFloat3(&forward))); + XMVECTOR yaxis = XMLoadFloat3(&up); + XMVECTOR xaxis = XMVector3Normalize(XMVector3Cross(yaxis, zaxis)); + yaxis = XMVector3Cross(zaxis, xaxis); + + Matrix R; + XMStoreFloat3(reinterpret_cast(&R._11), xaxis); + XMStoreFloat3(reinterpret_cast(&R._21), yaxis); + XMStoreFloat3(reinterpret_cast(&R._31), zaxis); + R._14 = R._24 = R._34 = 0.f; + R._41 = position.x; + R._42 = position.y; + R._43 = position.z; + R._44 = 1.f; + return R; } -inline Matrix Matrix::CreateFromQuaternion( const Quaternion& rotation ) +inline Matrix Matrix::CreateFromQuaternion(const Quaternion& rotation) { - using namespace DirectX; - Matrix R; - XMVECTOR quatv = XMLoadFloat4( &rotation ); - XMStoreFloat4x4( &R, XMMatrixRotationQuaternion( quatv ) ); - return R; + using namespace DirectX; + Matrix R; + XMVECTOR quatv = XMLoadFloat4(&rotation); + XMStoreFloat4x4(&R, XMMatrixRotationQuaternion(quatv)); + return R; } -inline Matrix Matrix::CreateFromYawPitchRoll( float yaw, float pitch, float roll ) +inline Matrix Matrix::CreateFromYawPitchRoll(float yaw, float pitch, float roll) { - using namespace DirectX; - Matrix R; - XMStoreFloat4x4( &R, XMMatrixRotationRollPitchYaw( pitch, yaw, roll ) ); - return R; + using namespace DirectX; + Matrix R; + XMStoreFloat4x4(&R, XMMatrixRotationRollPitchYaw(pitch, yaw, roll)); + return R; } -inline Matrix Matrix::CreateShadow( const Vector3& lightDir, const Plane& plane ) +inline Matrix Matrix::CreateShadow(const Vector3& lightDir, const Plane& plane) { - using namespace DirectX; - Matrix R; - XMVECTOR light = XMLoadFloat3( &lightDir ); - XMVECTOR planev = XMLoadFloat4( &plane ); - XMStoreFloat4x4( &R, XMMatrixShadow( planev, light ) ); - return R; + using namespace DirectX; + Matrix R; + XMVECTOR light = XMLoadFloat3(&lightDir); + XMVECTOR planev = XMLoadFloat4(&plane); + XMStoreFloat4x4(&R, XMMatrixShadow(planev, light)); + return R; } -inline Matrix Matrix::CreateReflection( const Plane& plane ) +inline Matrix Matrix::CreateReflection(const Plane& plane) { - using namespace DirectX; - Matrix R; - XMVECTOR planev = XMLoadFloat4( &plane ); - XMStoreFloat4x4( &R, XMMatrixReflect( planev ) ); - return R; + using namespace DirectX; + Matrix R; + XMVECTOR planev = XMLoadFloat4(&plane); + XMStoreFloat4x4(&R, XMMatrixReflect(planev)); + return R; } -inline void Matrix::Lerp( const Matrix& M1, const Matrix& M2, float t, Matrix& result ) +inline void Matrix::Lerp(const Matrix& M1, const Matrix& M2, float t, Matrix& result) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&M1._11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&M1._21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&M1._31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&M1._41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M1._11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&M1._21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&M1._31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&M1._41)); - XMVECTOR y1 = XMLoadFloat4( reinterpret_cast(&M2._11) ); - XMVECTOR y2 = XMLoadFloat4( reinterpret_cast(&M2._21) ); - XMVECTOR y3 = XMLoadFloat4( reinterpret_cast(&M2._31) ); - XMVECTOR y4 = XMLoadFloat4( reinterpret_cast(&M2._41) ); + XMVECTOR y1 = XMLoadFloat4(reinterpret_cast(&M2._11)); + XMVECTOR y2 = XMLoadFloat4(reinterpret_cast(&M2._21)); + XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M2._31)); + XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M2._41)); - x1 = XMVectorLerp( x1, y1, t ); - x2 = XMVectorLerp( x2, y2, t ); - x3 = XMVectorLerp( x3, y3, t ); - x4 = XMVectorLerp( x4, y4, t ); + x1 = XMVectorLerp(x1, y1, t); + x2 = XMVectorLerp(x2, y2, t); + x3 = XMVectorLerp(x3, y3, t); + x4 = XMVectorLerp(x4, y4, t); - XMStoreFloat4( reinterpret_cast(&result._11), x1 ); - XMStoreFloat4( reinterpret_cast(&result._21), x2 ); - XMStoreFloat4( reinterpret_cast(&result._31), x3 ); - XMStoreFloat4( reinterpret_cast(&result._41), x4 ); + XMStoreFloat4(reinterpret_cast(&result._11), x1); + XMStoreFloat4(reinterpret_cast(&result._21), x2); + XMStoreFloat4(reinterpret_cast(&result._31), x3); + XMStoreFloat4(reinterpret_cast(&result._41), x4); } -inline Matrix Matrix::Lerp( const Matrix& M1, const Matrix& M2, float t ) +inline Matrix Matrix::Lerp(const Matrix& M1, const Matrix& M2, float t) { - using namespace DirectX; - XMVECTOR x1 = XMLoadFloat4( reinterpret_cast(&M1._11) ); - XMVECTOR x2 = XMLoadFloat4( reinterpret_cast(&M1._21) ); - XMVECTOR x3 = XMLoadFloat4( reinterpret_cast(&M1._31) ); - XMVECTOR x4 = XMLoadFloat4( reinterpret_cast(&M1._41) ); + using namespace DirectX; + XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M1._11)); + XMVECTOR x2 = XMLoadFloat4(reinterpret_cast(&M1._21)); + XMVECTOR x3 = XMLoadFloat4(reinterpret_cast(&M1._31)); + XMVECTOR x4 = XMLoadFloat4(reinterpret_cast(&M1._41)); - XMVECTOR y1 = XMLoadFloat4( reinterpret_cast(&M2._11) ); - XMVECTOR y2 = XMLoadFloat4( reinterpret_cast(&M2._21) ); - XMVECTOR y3 = XMLoadFloat4( reinterpret_cast(&M2._31) ); - XMVECTOR y4 = XMLoadFloat4( reinterpret_cast(&M2._41) ); + XMVECTOR y1 = XMLoadFloat4(reinterpret_cast(&M2._11)); + XMVECTOR y2 = XMLoadFloat4(reinterpret_cast(&M2._21)); + XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M2._31)); + XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M2._41)); - x1 = XMVectorLerp( x1, y1, t ); - x2 = XMVectorLerp( x2, y2, t ); - x3 = XMVectorLerp( x3, y3, t ); - x4 = XMVectorLerp( x4, y4, t ); + x1 = XMVectorLerp(x1, y1, t); + x2 = XMVectorLerp(x2, y2, t); + x3 = XMVectorLerp(x3, y3, t); + x4 = XMVectorLerp(x4, y4, t); - Matrix result; - XMStoreFloat4( reinterpret_cast(&result._11), x1 ); - XMStoreFloat4( reinterpret_cast(&result._21), x2 ); - XMStoreFloat4( reinterpret_cast(&result._31), x3 ); - XMStoreFloat4( reinterpret_cast(&result._41), x4 ); - return result; + Matrix result; + XMStoreFloat4(reinterpret_cast(&result._11), x1); + XMStoreFloat4(reinterpret_cast(&result._21), x2); + XMStoreFloat4(reinterpret_cast(&result._31), x3); + XMStoreFloat4(reinterpret_cast(&result._41), x4); + return result; } -inline void Matrix::Transform( const Matrix& M, const Quaternion& rotation, Matrix& result ) +inline void Matrix::Transform(const Matrix& M, const Quaternion& rotation, Matrix& result) { - using namespace DirectX; - XMVECTOR quatv = XMLoadFloat4( &rotation ); + using namespace DirectX; + XMVECTOR quatv = XMLoadFloat4(&rotation); - XMMATRIX M0 = XMLoadFloat4x4( &M ); - XMMATRIX M1 = XMMatrixRotationQuaternion( quatv ); + XMMATRIX M0 = XMLoadFloat4x4(&M); + XMMATRIX M1 = XMMatrixRotationQuaternion(quatv); - XMStoreFloat4x4( &result, XMMatrixMultiply( M0, M1 ) ); + XMStoreFloat4x4(&result, XMMatrixMultiply(M0, M1)); } -inline Matrix Matrix::Transform( const Matrix& M, const Quaternion& rotation ) +inline Matrix Matrix::Transform(const Matrix& M, const Quaternion& rotation) { - using namespace DirectX; - XMVECTOR quatv = XMLoadFloat4( &rotation ); + using namespace DirectX; + XMVECTOR quatv = XMLoadFloat4(&rotation); - XMMATRIX M0 = XMLoadFloat4x4( &M ); - XMMATRIX M1 = XMMatrixRotationQuaternion( quatv ); + XMMATRIX M0 = XMLoadFloat4x4(&M); + XMMATRIX M1 = XMMatrixRotationQuaternion(quatv); - Matrix result; - XMStoreFloat4x4( &result, XMMatrixMultiply( M0, M1 ) ); - return result; + Matrix result; + XMStoreFloat4x4(&result, XMMatrixMultiply(M0, M1)); + return result; } @@ -2582,41 +2655,41 @@ inline Matrix Matrix::Transform( const Matrix& M, const Quaternion& rotation ) * ****************************************************************************/ -inline Plane::Plane(const Vector3& point1, const Vector3& point2, const Vector3& point3 ) +inline Plane::Plane(const Vector3& point1, const Vector3& point2, const Vector3& point3) { - using namespace DirectX; - XMVECTOR P0 = XMLoadFloat3( &point1 ); - XMVECTOR P1 = XMLoadFloat3( &point2 ); - XMVECTOR P2 = XMLoadFloat3( &point3 ); - XMStoreFloat4( this, XMPlaneFromPoints( P0, P1, P2 ) ); + using namespace DirectX; + XMVECTOR P0 = XMLoadFloat3(&point1); + XMVECTOR P1 = XMLoadFloat3(&point2); + XMVECTOR P2 = XMLoadFloat3(&point3); + XMStoreFloat4(this, XMPlaneFromPoints(P0, P1, P2)); } inline Plane::Plane(const Vector3& point, const Vector3& normal) { - using namespace DirectX; - XMVECTOR P = XMLoadFloat3( &point ); - XMVECTOR N = XMLoadFloat3( &normal ); - XMStoreFloat4( this, XMPlaneFromPointNormal( P, N ) ); + using namespace DirectX; + XMVECTOR P = XMLoadFloat3(&point); + XMVECTOR N = XMLoadFloat3(&normal); + XMStoreFloat4(this, XMPlaneFromPointNormal(P, N)); } //------------------------------------------------------------------------------ // Comparision operators //------------------------------------------------------------------------------ -inline bool Plane::operator == ( const Plane& p ) const +inline bool Plane::operator ==(const Plane& p) const { - using namespace DirectX; - XMVECTOR p1 = XMLoadFloat4( this ); - XMVECTOR p2 = XMLoadFloat4( &p ); - return XMPlaneEqual( p1, p2 ); + using namespace DirectX; + XMVECTOR p1 = XMLoadFloat4(this); + XMVECTOR p2 = XMLoadFloat4(&p); + return XMPlaneEqual(p1, p2); } -inline bool Plane::operator != ( const Plane& p ) const +inline bool Plane::operator !=(const Plane& p) const { - using namespace DirectX; - XMVECTOR p1 = XMLoadFloat4( this ); - XMVECTOR p2 = XMLoadFloat4( &p ); - return XMPlaneNotEqual( p1, p2 ); + using namespace DirectX; + XMVECTOR p1 = XMLoadFloat4(this); + XMVECTOR p2 = XMLoadFloat4(&p); + return XMPlaneNotEqual(p1, p2); } //------------------------------------------------------------------------------ @@ -2625,86 +2698,86 @@ inline bool Plane::operator != ( const Plane& p ) const inline void Plane::Normalize() { - using namespace DirectX; - XMVECTOR p = XMLoadFloat4( this ); - XMStoreFloat4( this, XMPlaneNormalize( p ) ); + using namespace DirectX; + XMVECTOR p = XMLoadFloat4(this); + XMStoreFloat4(this, XMPlaneNormalize(p)); } -inline void Plane::Normalize( Plane& result ) const +inline void Plane::Normalize(Plane& result) const { - using namespace DirectX; - XMVECTOR p = XMLoadFloat4( this ); - XMStoreFloat4( &result, XMPlaneNormalize( p ) ); + using namespace DirectX; + XMVECTOR p = XMLoadFloat4(this); + XMStoreFloat4(&result, XMPlaneNormalize(p)); } -inline float Plane::Dot( const Vector4& v ) const +inline float Plane::Dot(const Vector4& v) const { - using namespace DirectX; - XMVECTOR p = XMLoadFloat4( this ); - XMVECTOR v0 = XMLoadFloat4( &v ); - return XMVectorGetX( XMPlaneDot( p, v0 ) ); + using namespace DirectX; + XMVECTOR p = XMLoadFloat4(this); + XMVECTOR v0 = XMLoadFloat4(&v); + return XMVectorGetX(XMPlaneDot(p, v0)); } -inline float Plane::DotCoordinate( const Vector3& position ) const +inline float Plane::DotCoordinate(const Vector3& position) const { - using namespace DirectX; - XMVECTOR p = XMLoadFloat4( this ); - XMVECTOR v0 = XMLoadFloat3( &position ); - return XMVectorGetX( XMPlaneDotCoord( p, v0 ) ); + using namespace DirectX; + XMVECTOR p = XMLoadFloat4(this); + XMVECTOR v0 = XMLoadFloat3(&position); + return XMVectorGetX(XMPlaneDotCoord(p, v0)); } -inline float Plane::DotNormal( const Vector3& normal ) const +inline float Plane::DotNormal(const Vector3& normal) const { - using namespace DirectX; - XMVECTOR p = XMLoadFloat4( this ); - XMVECTOR n0 = XMLoadFloat3( &normal ); - return XMVectorGetX( XMPlaneDotNormal( p, n0 ) ); + using namespace DirectX; + XMVECTOR p = XMLoadFloat4(this); + XMVECTOR n0 = XMLoadFloat3(&normal); + return XMVectorGetX(XMPlaneDotNormal(p, n0)); } //------------------------------------------------------------------------------ // Static functions //------------------------------------------------------------------------------ -inline void Plane::Transform( const Plane& plane, const Matrix& M, Plane& result ) +inline void Plane::Transform(const Plane& plane, const Matrix& M, Plane& result) { - using namespace DirectX; - XMVECTOR p = XMLoadFloat4( &plane ); - XMMATRIX m0 = XMLoadFloat4x4( &M ); - XMStoreFloat4( &result, XMPlaneTransform( p, m0 ) ); + using namespace DirectX; + XMVECTOR p = XMLoadFloat4(&plane); + XMMATRIX m0 = XMLoadFloat4x4(&M); + XMStoreFloat4(&result, XMPlaneTransform(p, m0)); } -inline Plane Plane::Transform( const Plane& plane, const Matrix& M ) +inline Plane Plane::Transform(const Plane& plane, const Matrix& M) { - using namespace DirectX; - XMVECTOR p = XMLoadFloat4( &plane ); - XMMATRIX m0 = XMLoadFloat4x4( &M ); + using namespace DirectX; + XMVECTOR p = XMLoadFloat4(&plane); + XMMATRIX m0 = XMLoadFloat4x4(&M); - Plane result; - XMStoreFloat4( &result, XMPlaneTransform( p, m0 ) ); - return result; + Plane result; + XMStoreFloat4(&result, XMPlaneTransform(p, m0)); + return result; } -inline void Plane::Transform( const Plane& plane, const Quaternion& rotation, Plane& result ) +inline void Plane::Transform(const Plane& plane, const Quaternion& rotation, Plane& result) { - using namespace DirectX; - XMVECTOR p = XMLoadFloat4( &plane ); - XMVECTOR q = XMLoadFloat4( &rotation ); - XMVECTOR X = XMVector3Rotate( p, q ); - X = XMVectorSelect( p, X, g_XMSelect1110 ); // result.d = plane.d - XMStoreFloat4( &result, X ); + using namespace DirectX; + XMVECTOR p = XMLoadFloat4(&plane); + XMVECTOR q = XMLoadFloat4(&rotation); + XMVECTOR X = XMVector3Rotate(p, q); + X = XMVectorSelect(p, X, g_XMSelect1110); // result.d = plane.d + XMStoreFloat4(&result, X); } -inline Plane Plane::Transform( const Plane& plane, const Quaternion& rotation ) +inline Plane Plane::Transform(const Plane& plane, const Quaternion& rotation) { - using namespace DirectX; - XMVECTOR p = XMLoadFloat4( &plane ); - XMVECTOR q = XMLoadFloat4( &rotation ); - XMVECTOR X = XMVector3Rotate( p, q ); - X = XMVectorSelect( p, X, g_XMSelect1110 ); // result.d = plane.d + using namespace DirectX; + XMVECTOR p = XMLoadFloat4(&plane); + XMVECTOR q = XMLoadFloat4(&rotation); + XMVECTOR X = XMVector3Rotate(p, q); + X = XMVectorSelect(p, X, g_XMSelect1110); // result.d = plane.d - Plane result; - XMStoreFloat4( &result, X ); - return result; + Plane result; + XMStoreFloat4(&result, X); + return result; } @@ -2718,152 +2791,152 @@ inline Plane Plane::Transform( const Plane& plane, const Quaternion& rotation ) // Comparision operators //------------------------------------------------------------------------------ -inline bool Quaternion::operator == ( const Quaternion& q ) const +inline bool Quaternion::operator ==(const Quaternion& q) const { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( this ); - XMVECTOR q2 = XMLoadFloat4( &q ); - return XMQuaternionEqual( q1, q2 ); + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(this); + XMVECTOR q2 = XMLoadFloat4(&q); + return XMQuaternionEqual(q1, q2); } -inline bool Quaternion::operator != ( const Quaternion& q ) const +inline bool Quaternion::operator !=(const Quaternion& q) const { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( this ); - XMVECTOR q2 = XMLoadFloat4( &q ); - return XMQuaternionNotEqual( q1, q2 ); + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(this); + XMVECTOR q2 = XMLoadFloat4(&q); + return XMQuaternionNotEqual(q1, q2); } //------------------------------------------------------------------------------ // Assignment operators //------------------------------------------------------------------------------ -inline Quaternion& Quaternion::operator+= (const Quaternion& q) +inline Quaternion& Quaternion::operator+=(const Quaternion& q) { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( this ); - XMVECTOR q2 = XMLoadFloat4( &q ); - XMStoreFloat4( this, XMVectorAdd( q1, q2 ) ); - return *this; + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(this); + XMVECTOR q2 = XMLoadFloat4(&q); + XMStoreFloat4(this, XMVectorAdd(q1, q2)); + return *this; } -inline Quaternion& Quaternion::operator-= (const Quaternion& q) +inline Quaternion& Quaternion::operator-=(const Quaternion& q) { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( this ); - XMVECTOR q2 = XMLoadFloat4( &q ); - XMStoreFloat4( this, XMVectorSubtract( q1, q2 ) ); - return *this; + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(this); + XMVECTOR q2 = XMLoadFloat4(&q); + XMStoreFloat4(this, XMVectorSubtract(q1, q2)); + return *this; } -inline Quaternion& Quaternion::operator*= (const Quaternion& q) +inline Quaternion& Quaternion::operator*=(const Quaternion& q) { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( this ); - XMVECTOR q2 = XMLoadFloat4( &q ); - XMStoreFloat4( this, XMQuaternionMultiply( q1, q2 ) ); - return *this; + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(this); + XMVECTOR q2 = XMLoadFloat4(&q); + XMStoreFloat4(this, XMQuaternionMultiply(q1, q2)); + return *this; } -inline Quaternion& Quaternion::operator*= (float S) +inline Quaternion& Quaternion::operator*=(float S) { - using namespace DirectX; - XMVECTOR q = XMLoadFloat4( this ); - XMStoreFloat4( this, XMVectorScale( q, S ) ); - return *this; + using namespace DirectX; + XMVECTOR q = XMLoadFloat4(this); + XMStoreFloat4(this, XMVectorScale(q, S)); + return *this; } -inline Quaternion& Quaternion::operator/= (const Quaternion& q) +inline Quaternion& Quaternion::operator/=(const Quaternion& q) { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( this ); - XMVECTOR q2 = XMLoadFloat4( &q ); - q2 = XMQuaternionInverse( q2 ); - XMStoreFloat4( this, XMQuaternionMultiply( q1, q2 ) ); - return *this; + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(this); + XMVECTOR q2 = XMLoadFloat4(&q); + q2 = XMQuaternionInverse(q2); + XMStoreFloat4(this, XMQuaternionMultiply(q1, q2)); + return *this; } //------------------------------------------------------------------------------ // Urnary operators //------------------------------------------------------------------------------ -inline Quaternion Quaternion::operator- () const +inline Quaternion Quaternion::operator-() const { - using namespace DirectX; - XMVECTOR q = XMLoadFloat4( this ); + using namespace DirectX; + XMVECTOR q = XMLoadFloat4(this); - Quaternion R; - XMStoreFloat4( &R, XMVectorNegate( q ) ); - return R; + Quaternion R; + XMStoreFloat4(&R, XMVectorNegate(q)); + return R; } //------------------------------------------------------------------------------ // Binary operators //------------------------------------------------------------------------------ -inline Quaternion operator+ (const Quaternion& Q1, const Quaternion& Q2) +inline Quaternion operator+(const Quaternion& Q1, const Quaternion& Q2) { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( &Q1 ); - XMVECTOR q2 = XMLoadFloat4( &Q2 ); + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(&Q1); + XMVECTOR q2 = XMLoadFloat4(&Q2); - Quaternion R; - XMStoreFloat4( &R, XMVectorAdd( q1, q2 ) ); - return R; + Quaternion R; + XMStoreFloat4(&R, XMVectorAdd(q1, q2)); + return R; } -inline Quaternion operator- (const Quaternion& Q1, const Quaternion& Q2) +inline Quaternion operator-(const Quaternion& Q1, const Quaternion& Q2) { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( &Q1 ); - XMVECTOR q2 = XMLoadFloat4( &Q2 ); + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(&Q1); + XMVECTOR q2 = XMLoadFloat4(&Q2); - Quaternion R; - XMStoreFloat4( &R, XMVectorSubtract( q1, q2 ) ); - return R; + Quaternion R; + XMStoreFloat4(&R, XMVectorSubtract(q1, q2)); + return R; } -inline Quaternion operator* (const Quaternion& Q1, const Quaternion& Q2) +inline Quaternion operator*(const Quaternion& Q1, const Quaternion& Q2) { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( &Q1 ); - XMVECTOR q2 = XMLoadFloat4( &Q2 ); + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(&Q1); + XMVECTOR q2 = XMLoadFloat4(&Q2); - Quaternion R; - XMStoreFloat4( &R, XMQuaternionMultiply( q1, q2 ) ); - return R; + Quaternion R; + XMStoreFloat4(&R, XMQuaternionMultiply(q1, q2)); + return R; } -inline Quaternion operator* (const Quaternion& Q, float S) +inline Quaternion operator*(const Quaternion& Q, float S) { - using namespace DirectX; - XMVECTOR q = XMLoadFloat4( &Q ); + using namespace DirectX; + XMVECTOR q = XMLoadFloat4(&Q); - Quaternion R; - XMStoreFloat4( &R, XMVectorScale( q, S ) ); - return R; + Quaternion R; + XMStoreFloat4(&R, XMVectorScale(q, S)); + return R; } -inline Quaternion operator/ (const Quaternion& Q1, const Quaternion& Q2) +inline Quaternion operator/(const Quaternion& Q1, const Quaternion& Q2) { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( &Q1 ); - XMVECTOR q2 = XMLoadFloat4( &Q2 ); - q2 = XMQuaternionInverse( q2 ); + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(&Q1); + XMVECTOR q2 = XMLoadFloat4(&Q2); + q2 = XMQuaternionInverse(q2); - Quaternion R; - XMStoreFloat4( &R, XMQuaternionMultiply( q1, q2 ) ); - return R; + Quaternion R; + XMStoreFloat4(&R, XMQuaternionMultiply(q1, q2)); + return R; } -inline Quaternion operator* (float S, const Quaternion& Q) +inline Quaternion operator*(float S, const Quaternion& Q) { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( &Q ); + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(&Q); - Quaternion R; - XMStoreFloat4( &R, XMVectorScale( q1, S ) ); - return R; + Quaternion R; + XMStoreFloat4(&R, XMVectorScale(q1, S)); + return R; } //------------------------------------------------------------------------------ @@ -2872,181 +2945,181 @@ inline Quaternion operator* (float S, const Quaternion& Q) inline float Quaternion::Length() const { - using namespace DirectX; - XMVECTOR q = XMLoadFloat4( this ); - return XMVectorGetX( XMQuaternionLength( q ) ); + using namespace DirectX; + XMVECTOR q = XMLoadFloat4(this); + return XMVectorGetX(XMQuaternionLength(q)); } inline float Quaternion::LengthSquared() const { - using namespace DirectX; - XMVECTOR q = XMLoadFloat4( this ); - return XMVectorGetX( XMQuaternionLengthSq( q ) ); + using namespace DirectX; + XMVECTOR q = XMLoadFloat4(this); + return XMVectorGetX(XMQuaternionLengthSq(q)); } inline void Quaternion::Normalize() { - using namespace DirectX; - XMVECTOR q = XMLoadFloat4( this ); - XMStoreFloat4( this, XMQuaternionNormalize( q ) ); + using namespace DirectX; + XMVECTOR q = XMLoadFloat4(this); + XMStoreFloat4(this, XMQuaternionNormalize(q)); } -inline void Quaternion::Normalize( Quaternion& result ) const +inline void Quaternion::Normalize(Quaternion& result) const { - using namespace DirectX; - XMVECTOR q = XMLoadFloat4( this ); - XMStoreFloat4( &result, XMQuaternionNormalize( q ) ); + using namespace DirectX; + XMVECTOR q = XMLoadFloat4(this); + XMStoreFloat4(&result, XMQuaternionNormalize(q)); } inline void Quaternion::Conjugate() { - using namespace DirectX; - XMVECTOR q = XMLoadFloat4( this ); - XMStoreFloat4( this, XMQuaternionConjugate( q ) ); + using namespace DirectX; + XMVECTOR q = XMLoadFloat4(this); + XMStoreFloat4(this, XMQuaternionConjugate(q)); } -inline void Quaternion::Conjugate( Quaternion& result ) const +inline void Quaternion::Conjugate(Quaternion& result) const { - using namespace DirectX; - XMVECTOR q = XMLoadFloat4( this ); - XMStoreFloat4( &result, XMQuaternionConjugate( q ) ); + using namespace DirectX; + XMVECTOR q = XMLoadFloat4(this); + XMStoreFloat4(&result, XMQuaternionConjugate(q)); } -inline void Quaternion::Inverse( Quaternion& result ) const +inline void Quaternion::Inverse(Quaternion& result) const { - using namespace DirectX; - XMVECTOR q = XMLoadFloat4( this ); - XMStoreFloat4( &result, XMQuaternionInverse( q ) ); + using namespace DirectX; + XMVECTOR q = XMLoadFloat4(this); + XMStoreFloat4(&result, XMQuaternionInverse(q)); } -inline float Quaternion::Dot( const Quaternion& q ) const +inline float Quaternion::Dot(const Quaternion& q) const { - using namespace DirectX; - XMVECTOR q1 = XMLoadFloat4( this ); - XMVECTOR q2 = XMLoadFloat4( &q ); - return XMVectorGetX( XMQuaternionDot( q1, q2 ) ); + using namespace DirectX; + XMVECTOR q1 = XMLoadFloat4(this); + XMVECTOR q2 = XMLoadFloat4(&q); + return XMVectorGetX(XMQuaternionDot(q1, q2)); } //------------------------------------------------------------------------------ // Static functions //------------------------------------------------------------------------------ -inline Quaternion Quaternion::CreateFromAxisAngle( const Vector3& axis, float angle ) +inline Quaternion Quaternion::CreateFromAxisAngle(const Vector3& axis, float angle) { - using namespace DirectX; - XMVECTOR a = XMLoadFloat3( &axis ); + using namespace DirectX; + XMVECTOR a = XMLoadFloat3(&axis); - Quaternion R; - XMStoreFloat4( &R, XMQuaternionRotationAxis( a, angle ) ); - return R; + Quaternion R; + XMStoreFloat4(&R, XMQuaternionRotationAxis(a, angle)); + return R; } -inline Quaternion Quaternion::CreateFromYawPitchRoll( float yaw, float pitch, float roll ) +inline Quaternion Quaternion::CreateFromYawPitchRoll(float yaw, float pitch, float roll) { - using namespace DirectX; - Quaternion R; - XMStoreFloat4( &R, XMQuaternionRotationRollPitchYaw( pitch, yaw, roll ) ); - return R; + using namespace DirectX; + Quaternion R; + XMStoreFloat4(&R, XMQuaternionRotationRollPitchYaw(pitch, yaw, roll)); + return R; } -inline Quaternion Quaternion::CreateFromRotationMatrix( const Matrix& M ) +inline Quaternion Quaternion::CreateFromRotationMatrix(const Matrix& M) { - using namespace DirectX; - XMMATRIX M0 = XMLoadFloat4x4( &M ); + using namespace DirectX; + XMMATRIX M0 = XMLoadFloat4x4(&M); - Quaternion R; - XMStoreFloat4( &R, XMQuaternionRotationMatrix( M0 ) ); - return R; + Quaternion R; + XMStoreFloat4(&R, XMQuaternionRotationMatrix(M0)); + return R; } -inline void Quaternion::Lerp( const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result ) +inline void Quaternion::Lerp(const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result) { - using namespace DirectX; - XMVECTOR Q0 = XMLoadFloat4( &q1 ); - XMVECTOR Q1 = XMLoadFloat4( &q2 ); + using namespace DirectX; + XMVECTOR Q0 = XMLoadFloat4(&q1); + XMVECTOR Q1 = XMLoadFloat4(&q2); - XMVECTOR dot = XMVector4Dot( Q0, Q1 ); + XMVECTOR dot = XMVector4Dot(Q0, Q1); - XMVECTOR R; - if ( XMVector4GreaterOrEqual( dot, XMVectorZero() ) ) - { - R = XMVectorLerp( Q0, Q1, t ); - } - else - { - XMVECTOR tv = XMVectorReplicate( t ); - XMVECTOR t1v = XMVectorReplicate( 1.f - t ); - XMVECTOR X0 = XMVectorMultiply( Q0, t1v ); - XMVECTOR X1 = XMVectorMultiply( Q1, tv ); - R = XMVectorSubtract( X0, X1 ); - } + XMVECTOR R; + if (XMVector4GreaterOrEqual(dot, XMVectorZero())) + { + R = XMVectorLerp(Q0, Q1, t); + } + else + { + XMVECTOR tv = XMVectorReplicate(t); + XMVECTOR t1v = XMVectorReplicate(1.f - t); + XMVECTOR X0 = XMVectorMultiply(Q0, t1v); + XMVECTOR X1 = XMVectorMultiply(Q1, tv); + R = XMVectorSubtract(X0, X1); + } - XMStoreFloat4( &result, XMQuaternionNormalize( R ) ); + XMStoreFloat4(&result, XMQuaternionNormalize(R)); } -inline Quaternion Quaternion::Lerp( const Quaternion& q1, const Quaternion& q2, float t ) +inline Quaternion Quaternion::Lerp(const Quaternion& q1, const Quaternion& q2, float t) { - using namespace DirectX; - XMVECTOR Q0 = XMLoadFloat4( &q1 ); - XMVECTOR Q1 = XMLoadFloat4( &q2 ); + using namespace DirectX; + XMVECTOR Q0 = XMLoadFloat4(&q1); + XMVECTOR Q1 = XMLoadFloat4(&q2); - XMVECTOR dot = XMVector4Dot( Q0, Q1 ); + XMVECTOR dot = XMVector4Dot(Q0, Q1); - XMVECTOR R; - if ( XMVector4GreaterOrEqual( dot, XMVectorZero() ) ) - { - R = XMVectorLerp( Q0, Q1, t ); - } - else - { - XMVECTOR tv = XMVectorReplicate( t ); - XMVECTOR t1v = XMVectorReplicate( 1.f - t ); - XMVECTOR X0 = XMVectorMultiply( Q0, t1v ); - XMVECTOR X1 = XMVectorMultiply( Q1, tv ); - R = XMVectorSubtract( X0, X1 ); - } + XMVECTOR R; + if (XMVector4GreaterOrEqual(dot, XMVectorZero())) + { + R = XMVectorLerp(Q0, Q1, t); + } + else + { + XMVECTOR tv = XMVectorReplicate(t); + XMVECTOR t1v = XMVectorReplicate(1.f - t); + XMVECTOR X0 = XMVectorMultiply(Q0, t1v); + XMVECTOR X1 = XMVectorMultiply(Q1, tv); + R = XMVectorSubtract(X0, X1); + } - Quaternion result; - XMStoreFloat4( &result, XMQuaternionNormalize( R ) ); - return result; + Quaternion result; + XMStoreFloat4(&result, XMQuaternionNormalize(R)); + return result; } -inline void Quaternion::Slerp( const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result ) +inline void Quaternion::Slerp(const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result) { - using namespace DirectX; - XMVECTOR Q0 = XMLoadFloat4( &q1 ); - XMVECTOR Q1 = XMLoadFloat4( &q2 ); - XMStoreFloat4( &result, XMQuaternionSlerp( Q0, Q1, t ) ); + using namespace DirectX; + XMVECTOR Q0 = XMLoadFloat4(&q1); + XMVECTOR Q1 = XMLoadFloat4(&q2); + XMStoreFloat4(&result, XMQuaternionSlerp(Q0, Q1, t)); } -inline Quaternion Quaternion::Slerp( const Quaternion& q1, const Quaternion& q2, float t ) +inline Quaternion Quaternion::Slerp(const Quaternion& q1, const Quaternion& q2, float t) { - using namespace DirectX; - XMVECTOR Q0 = XMLoadFloat4( &q1 ); - XMVECTOR Q1 = XMLoadFloat4( &q2 ); + using namespace DirectX; + XMVECTOR Q0 = XMLoadFloat4(&q1); + XMVECTOR Q1 = XMLoadFloat4(&q2); - Quaternion result; - XMStoreFloat4( &result, XMQuaternionSlerp( Q0, Q1, t ) ); - return result; + Quaternion result; + XMStoreFloat4(&result, XMQuaternionSlerp(Q0, Q1, t)); + return result; } -inline void Quaternion::Concatenate( const Quaternion& q1, const Quaternion& q2, Quaternion& result ) +inline void Quaternion::Concatenate(const Quaternion& q1, const Quaternion& q2, Quaternion& result) { - using namespace DirectX; - XMVECTOR Q0 = XMLoadFloat4( &q1 ); - XMVECTOR Q1 = XMLoadFloat4( &q2 ); - XMStoreFloat4( &result, XMQuaternionMultiply( Q1, Q0 ) ); + using namespace DirectX; + XMVECTOR Q0 = XMLoadFloat4(&q1); + XMVECTOR Q1 = XMLoadFloat4(&q2); + XMStoreFloat4(&result, XMQuaternionMultiply(Q1, Q0)); } -inline Quaternion Quaternion::Concatenate( const Quaternion& q1, const Quaternion& q2 ) +inline Quaternion Quaternion::Concatenate(const Quaternion& q1, const Quaternion& q2) { - using namespace DirectX; - XMVECTOR Q0 = XMLoadFloat4( &q1 ); - XMVECTOR Q1 = XMLoadFloat4( &q2 ); + using namespace DirectX; + XMVECTOR Q0 = XMLoadFloat4(&q1); + XMVECTOR Q1 = XMLoadFloat4(&q2); - Quaternion result; - XMStoreFloat4( &result, XMQuaternionMultiply( Q1, Q0 ) ); - return result; + Quaternion result; + XMStoreFloat4(&result, XMQuaternionMultiply(Q1, Q0)); + return result; } @@ -3056,172 +3129,172 @@ inline Quaternion Quaternion::Concatenate( const Quaternion& q1, const Quaternio * ****************************************************************************/ -inline Color::Color( const DirectX::PackedVector::XMCOLOR& Packed ) +inline Color::Color(const DirectX::PackedVector::XMCOLOR& Packed) { - using namespace DirectX; - XMStoreFloat4( this, PackedVector::XMLoadColor( &Packed ) ); + using namespace DirectX; + XMStoreFloat4(this, PackedVector::XMLoadColor(&Packed)); } -inline Color::Color( const DirectX::PackedVector::XMUBYTEN4& Packed ) +inline Color::Color(const DirectX::PackedVector::XMUBYTEN4& Packed) { - using namespace DirectX; - XMStoreFloat4( this, PackedVector::XMLoadUByteN4( &Packed ) ); + using namespace DirectX; + XMStoreFloat4(this, PackedVector::XMLoadUByteN4(&Packed)); } //------------------------------------------------------------------------------ // Comparision operators //------------------------------------------------------------------------------ -inline bool Color::operator == ( const Color& c ) const +inline bool Color::operator ==(const Color& c) const { - using namespace DirectX; - XMVECTOR c1 = XMLoadFloat4( this ); - XMVECTOR c2 = XMLoadFloat4( &c ); - return XMColorEqual( c1, c2 ); + using namespace DirectX; + XMVECTOR c1 = XMLoadFloat4(this); + XMVECTOR c2 = XMLoadFloat4(&c); + return XMColorEqual(c1, c2); } -inline bool Color::operator != ( const Color& c ) const +inline bool Color::operator !=(const Color& c) const { - using namespace DirectX; - XMVECTOR c1 = XMLoadFloat4( this ); - XMVECTOR c2 = XMLoadFloat4( &c ); - return XMColorNotEqual( c1, c2 ); + using namespace DirectX; + XMVECTOR c1 = XMLoadFloat4(this); + XMVECTOR c2 = XMLoadFloat4(&c); + return XMColorNotEqual(c1, c2); } //------------------------------------------------------------------------------ // Assignment operators //------------------------------------------------------------------------------ -inline Color& Color::operator= (const DirectX::PackedVector::XMCOLOR& Packed) +inline Color& Color::operator=(const DirectX::PackedVector::XMCOLOR& Packed) { - using namespace DirectX; - XMStoreFloat4( this, PackedVector::XMLoadColor( &Packed ) ); - return *this; + using namespace DirectX; + XMStoreFloat4(this, PackedVector::XMLoadColor(&Packed)); + return *this; } -inline Color& Color::operator= (const DirectX::PackedVector::XMUBYTEN4& Packed) +inline Color& Color::operator=(const DirectX::PackedVector::XMUBYTEN4& Packed) { - using namespace DirectX; - XMStoreFloat4( this, PackedVector::XMLoadUByteN4( &Packed ) ); - return *this; + using namespace DirectX; + XMStoreFloat4(this, PackedVector::XMLoadUByteN4(&Packed)); + return *this; } -inline Color& Color::operator+= (const Color& c) +inline Color& Color::operator+=(const Color& c) { - using namespace DirectX; - XMVECTOR c1 = XMLoadFloat4( this ); - XMVECTOR c2 = XMLoadFloat4( &c ); - XMStoreFloat4( this, XMVectorAdd( c1, c2 ) ); - return *this; + using namespace DirectX; + XMVECTOR c1 = XMLoadFloat4(this); + XMVECTOR c2 = XMLoadFloat4(&c); + XMStoreFloat4(this, XMVectorAdd(c1, c2)); + return *this; } -inline Color& Color::operator-= (const Color& c) +inline Color& Color::operator-=(const Color& c) { - using namespace DirectX; - XMVECTOR c1 = XMLoadFloat4( this ); - XMVECTOR c2 = XMLoadFloat4( &c ); - XMStoreFloat4( this, XMVectorSubtract( c1, c2 ) ); - return *this; + using namespace DirectX; + XMVECTOR c1 = XMLoadFloat4(this); + XMVECTOR c2 = XMLoadFloat4(&c); + XMStoreFloat4(this, XMVectorSubtract(c1, c2)); + return *this; } -inline Color& Color::operator*= (const Color& c) +inline Color& Color::operator*=(const Color& c) { - using namespace DirectX; - XMVECTOR c1 = XMLoadFloat4( this ); - XMVECTOR c2 = XMLoadFloat4( &c ); - XMStoreFloat4( this, XMVectorMultiply( c1, c2 ) ); - return *this; + using namespace DirectX; + XMVECTOR c1 = XMLoadFloat4(this); + XMVECTOR c2 = XMLoadFloat4(&c); + XMStoreFloat4(this, XMVectorMultiply(c1, c2)); + return *this; } -inline Color& Color::operator*= (float S) +inline Color& Color::operator*=(float S) { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - XMStoreFloat4( this, XMVectorScale( c, S ) ); - return *this; + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + XMStoreFloat4(this, XMVectorScale(c, S)); + return *this; } -inline Color& Color::operator/= (const Color& c) +inline Color& Color::operator/=(const Color& c) { - using namespace DirectX; - XMVECTOR c1 = XMLoadFloat4( this ); - XMVECTOR c2 = XMLoadFloat4( &c ); - XMStoreFloat4( this, XMVectorDivide( c1, c2 ) ); - return *this; + using namespace DirectX; + XMVECTOR c1 = XMLoadFloat4(this); + XMVECTOR c2 = XMLoadFloat4(&c); + XMStoreFloat4(this, XMVectorDivide(c1, c2)); + return *this; } //------------------------------------------------------------------------------ // Urnary operators //------------------------------------------------------------------------------ -inline Color Color::operator- () const +inline Color Color::operator-() const { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - Color R; - XMStoreFloat4( &R, XMVectorNegate( c ) ); - return R; + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + Color R; + XMStoreFloat4(&R, XMVectorNegate(c)); + return R; } //------------------------------------------------------------------------------ // Binary operators //------------------------------------------------------------------------------ -inline Color operator+ (const Color& C1, const Color& C2) +inline Color operator+(const Color& C1, const Color& C2) { - using namespace DirectX; - XMVECTOR c1 = XMLoadFloat4( &C1 ); - XMVECTOR c2 = XMLoadFloat4( &C2 ); - Color R; - XMStoreFloat4( &R, XMVectorAdd( c1, c2 ) ); - return R; + using namespace DirectX; + XMVECTOR c1 = XMLoadFloat4(&C1); + XMVECTOR c2 = XMLoadFloat4(&C2); + Color R; + XMStoreFloat4(&R, XMVectorAdd(c1, c2)); + return R; } -inline Color operator- (const Color& C1, const Color& C2) +inline Color operator-(const Color& C1, const Color& C2) { - using namespace DirectX; - XMVECTOR c1 = XMLoadFloat4( &C1 ); - XMVECTOR c2 = XMLoadFloat4( &C2 ); - Color R; - XMStoreFloat4( &R, XMVectorSubtract( c1, c2 ) ); - return R; + using namespace DirectX; + XMVECTOR c1 = XMLoadFloat4(&C1); + XMVECTOR c2 = XMLoadFloat4(&C2); + Color R; + XMStoreFloat4(&R, XMVectorSubtract(c1, c2)); + return R; } -inline Color operator* (const Color& C1, const Color& C2) +inline Color operator*(const Color& C1, const Color& C2) { - using namespace DirectX; - XMVECTOR c1 = XMLoadFloat4( &C1 ); - XMVECTOR c2 = XMLoadFloat4( &C2 ); - Color R; - XMStoreFloat4( &R, XMVectorMultiply( c1, c2 ) ); - return R; + using namespace DirectX; + XMVECTOR c1 = XMLoadFloat4(&C1); + XMVECTOR c2 = XMLoadFloat4(&C2); + Color R; + XMStoreFloat4(&R, XMVectorMultiply(c1, c2)); + return R; } -inline Color operator* (const Color& C, float S) +inline Color operator*(const Color& C, float S) { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( &C ); - Color R; - XMStoreFloat4( &R, XMVectorScale( c, S ) ); - return R; + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(&C); + Color R; + XMStoreFloat4(&R, XMVectorScale(c, S)); + return R; } -inline Color operator/ (const Color& C1, const Color& C2) +inline Color operator/(const Color& C1, const Color& C2) { - using namespace DirectX; - XMVECTOR c1 = XMLoadFloat4( &C1 ); - XMVECTOR c2 = XMLoadFloat4( &C2 ); - Color R; - XMStoreFloat4( &R, XMVectorDivide( c1, c2 ) ); - return R; + using namespace DirectX; + XMVECTOR c1 = XMLoadFloat4(&C1); + XMVECTOR c2 = XMLoadFloat4(&C2); + Color R; + XMStoreFloat4(&R, XMVectorDivide(c1, c2)); + return R; } -inline Color operator* (float S, const Color& C) +inline Color operator*(float S, const Color& C) { - using namespace DirectX; - XMVECTOR c1 = XMLoadFloat4( &C ); - Color R; - XMStoreFloat4( &R, XMVectorScale( c1, S ) ); - return R; + using namespace DirectX; + XMVECTOR c1 = XMLoadFloat4(&C); + Color R; + XMStoreFloat4(&R, XMVectorScale(c1, S)); + return R; } //------------------------------------------------------------------------------ @@ -3230,146 +3303,146 @@ inline Color operator* (float S, const Color& C) inline DirectX::PackedVector::XMCOLOR Color::BGRA() const { - using namespace DirectX; - XMVECTOR clr = XMLoadFloat4( this ); - PackedVector::XMCOLOR Packed; - PackedVector::XMStoreColor( &Packed, clr ); - return Packed; + using namespace DirectX; + XMVECTOR clr = XMLoadFloat4(this); + PackedVector::XMCOLOR Packed; + PackedVector::XMStoreColor(&Packed, clr); + return Packed; } inline DirectX::PackedVector::XMUBYTEN4 Color::RGBA() const { - using namespace DirectX; - XMVECTOR clr = XMLoadFloat4( this ); - PackedVector::XMUBYTEN4 Packed; - PackedVector::XMStoreUByteN4( &Packed, clr ); - return Packed; + using namespace DirectX; + XMVECTOR clr = XMLoadFloat4(this); + PackedVector::XMUBYTEN4 Packed; + PackedVector::XMStoreUByteN4(&Packed, clr); + return Packed; } inline Vector3 Color::ToVector3() const { - return Vector3( x, y, z ); + return Vector3(x, y, z); } inline Vector4 Color::ToVector4() const { - return Vector4( x, y, z, w ); + return Vector4(x, y, z, w); } inline void Color::Negate() { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - XMStoreFloat4( this, XMColorNegative( c) ); + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + XMStoreFloat4(this, XMColorNegative(c)); } -inline void Color::Negate( Color& result ) const +inline void Color::Negate(Color& result) const { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - XMStoreFloat4( &result, XMColorNegative( c ) ); + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + XMStoreFloat4(&result, XMColorNegative(c)); } inline void Color::Saturate() { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - XMStoreFloat4( this, XMVectorSaturate( c ) ); + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + XMStoreFloat4(this, XMVectorSaturate(c)); } -inline void Color::Saturate( Color& result ) const +inline void Color::Saturate(Color& result) const { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - XMStoreFloat4( &result, XMVectorSaturate( c ) ); + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + XMStoreFloat4(&result, XMVectorSaturate(c)); } inline void Color::Premultiply() { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - XMVECTOR a = XMVectorSplatW( c ); - a = XMVectorSelect( g_XMIdentityR3, a, g_XMSelect1110 ); - XMStoreFloat4( this, XMVectorMultiply( c, a ) ); + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + XMVECTOR a = XMVectorSplatW(c); + a = XMVectorSelect(g_XMIdentityR3, a, g_XMSelect1110); + XMStoreFloat4(this, XMVectorMultiply(c, a)); } -inline void Color::Premultiply( Color& result ) const +inline void Color::Premultiply(Color& result) const { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - XMVECTOR a = XMVectorSplatW( c ); - a = XMVectorSelect( g_XMIdentityR3, a, g_XMSelect1110 ); - XMStoreFloat4( &result, XMVectorMultiply( c, a ) ); + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + XMVECTOR a = XMVectorSplatW(c); + a = XMVectorSelect(g_XMIdentityR3, a, g_XMSelect1110); + XMStoreFloat4(&result, XMVectorMultiply(c, a)); } -inline void Color::AdjustSaturation( float sat ) +inline void Color::AdjustSaturation(float sat) { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - XMStoreFloat4( this, XMColorAdjustSaturation( c, sat ) ); + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + XMStoreFloat4(this, XMColorAdjustSaturation(c, sat)); } -inline void Color::AdjustSaturation( float sat, Color& result ) const +inline void Color::AdjustSaturation(float sat, Color& result) const { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - XMStoreFloat4( &result, XMColorAdjustSaturation( c, sat ) ); + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + XMStoreFloat4(&result, XMColorAdjustSaturation(c, sat)); } -inline void Color::AdjustContrast( float contrast ) +inline void Color::AdjustContrast(float contrast) { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - XMStoreFloat4( this, XMColorAdjustContrast( c, contrast ) ); + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + XMStoreFloat4(this, XMColorAdjustContrast(c, contrast)); } -inline void Color::AdjustContrast( float contrast, Color& result ) const +inline void Color::AdjustContrast(float contrast, Color& result) const { - using namespace DirectX; - XMVECTOR c = XMLoadFloat4( this ); - XMStoreFloat4( &result, XMColorAdjustContrast( c, contrast ) ); + using namespace DirectX; + XMVECTOR c = XMLoadFloat4(this); + XMStoreFloat4(&result, XMColorAdjustContrast(c, contrast)); } //------------------------------------------------------------------------------ // Static functions //------------------------------------------------------------------------------ -inline void Color::Modulate( const Color& c1, const Color& c2, Color& result ) +inline void Color::Modulate(const Color& c1, const Color& c2, Color& result) { - using namespace DirectX; - XMVECTOR C0 = XMLoadFloat4( &c1 ); - XMVECTOR C1 = XMLoadFloat4( &c2 ); - XMStoreFloat4( &result, XMColorModulate( C0, C1 ) ); + using namespace DirectX; + XMVECTOR C0 = XMLoadFloat4(&c1); + XMVECTOR C1 = XMLoadFloat4(&c2); + XMStoreFloat4(&result, XMColorModulate(C0, C1)); } -inline Color Color::Modulate( const Color& c1, const Color& c2 ) +inline Color Color::Modulate(const Color& c1, const Color& c2) { - using namespace DirectX; - XMVECTOR C0 = XMLoadFloat4( &c1 ); - XMVECTOR C1 = XMLoadFloat4( &c2 ); + using namespace DirectX; + XMVECTOR C0 = XMLoadFloat4(&c1); + XMVECTOR C1 = XMLoadFloat4(&c2); - Color result; - XMStoreFloat4( &result, XMColorModulate( C0, C1 ) ); - return result; + Color result; + XMStoreFloat4(&result, XMColorModulate(C0, C1)); + return result; } -inline void Color::Lerp( const Color& c1, const Color& c2, float t, Color& result ) +inline void Color::Lerp(const Color& c1, const Color& c2, float t, Color& result) { - using namespace DirectX; - XMVECTOR C0 = XMLoadFloat4( &c1 ); - XMVECTOR C1 = XMLoadFloat4( &c2 ); - XMStoreFloat4( &result, XMVectorLerp( C0, C1, t ) ); + using namespace DirectX; + XMVECTOR C0 = XMLoadFloat4(&c1); + XMVECTOR C1 = XMLoadFloat4(&c2); + XMStoreFloat4(&result, XMVectorLerp(C0, C1, t)); } -inline Color Color::Lerp( const Color& c1, const Color& c2, float t ) +inline Color Color::Lerp(const Color& c1, const Color& c2, float t) { - using namespace DirectX; - XMVECTOR C0 = XMLoadFloat4( &c1 ); - XMVECTOR C1 = XMLoadFloat4( &c2 ); + using namespace DirectX; + XMVECTOR C0 = XMLoadFloat4(&c1); + XMVECTOR C1 = XMLoadFloat4(&c2); - Color result; - XMStoreFloat4( &result, XMVectorLerp( C0, C1, t ) ); - return result; + Color result; + XMStoreFloat4(&result, XMVectorLerp(C0, C1, t)); + return result; } @@ -3382,78 +3455,78 @@ inline Color Color::Lerp( const Color& c1, const Color& c2, float t ) //----------------------------------------------------------------------------- // Comparision operators //------------------------------------------------------------------------------ -inline bool Ray::operator == ( const Ray& r ) const +inline bool Ray::operator ==(const Ray& r) const { - using namespace DirectX; - XMVECTOR r1p = XMLoadFloat3( &position ); - XMVECTOR r2p = XMLoadFloat3( &r.position ); - XMVECTOR r1d = XMLoadFloat3( &direction ); - XMVECTOR r2d = XMLoadFloat3( &r.direction ); - return XMVector3Equal( r1p, r2p ) && XMVector3Equal( r1d, r2d ); + using namespace DirectX; + XMVECTOR r1p = XMLoadFloat3(&position); + XMVECTOR r2p = XMLoadFloat3(&r.position); + XMVECTOR r1d = XMLoadFloat3(&direction); + XMVECTOR r2d = XMLoadFloat3(&r.direction); + return XMVector3Equal(r1p, r2p) && XMVector3Equal(r1d, r2d); } -inline bool Ray::operator != ( const Ray& r ) const +inline bool Ray::operator !=(const Ray& r) const { - using namespace DirectX; - XMVECTOR r1p = XMLoadFloat3( &position ); - XMVECTOR r2p = XMLoadFloat3( &r.position ); - XMVECTOR r1d = XMLoadFloat3( &direction ); - XMVECTOR r2d = XMLoadFloat3( &r.direction ); - return XMVector3NotEqual( r1p, r2p ) && XMVector3NotEqual( r1d, r2d ); + using namespace DirectX; + XMVECTOR r1p = XMLoadFloat3(&position); + XMVECTOR r2p = XMLoadFloat3(&r.position); + XMVECTOR r1d = XMLoadFloat3(&direction); + XMVECTOR r2d = XMLoadFloat3(&r.direction); + return XMVector3NotEqual(r1p, r2p) && XMVector3NotEqual(r1d, r2d); } //----------------------------------------------------------------------------- // Ray operators //------------------------------------------------------------------------------ -inline bool Ray::Intersects( const BoundingSphere& sphere, _Out_ float& Dist ) const +inline bool Ray::Intersects(const BoundingSphere& sphere, _Out_ float& Dist) const { - return sphere.Intersects( position, direction, Dist ); + return sphere.Intersects(position, direction, Dist); } -inline bool Ray::Intersects( const BoundingBox& box, _Out_ float& Dist ) const +inline bool Ray::Intersects(const BoundingBox& box, _Out_ float& Dist) const { - return box.Intersects( position, direction, Dist ); + return box.Intersects(position, direction, Dist); } -inline bool Ray::Intersects( const Vector3& tri0, const Vector3& tri1, const Vector3& tri2, _Out_ float& Dist ) const +inline bool Ray::Intersects(const Vector3& tri0, const Vector3& tri1, const Vector3& tri2, _Out_ float& Dist) const { - return DirectX::TriangleTests::Intersects( position, direction, tri0, tri1, tri2, Dist ); + return DirectX::TriangleTests::Intersects(position, direction, tri0, tri1, tri2, Dist); } -inline bool Ray::Intersects( const Plane& plane, _Out_ float& Dist ) const +inline bool Ray::Intersects(const Plane& plane, _Out_ float& Dist) const { - using namespace DirectX; + using namespace DirectX; - XMVECTOR p = XMLoadFloat4( &plane ); - XMVECTOR dir = XMLoadFloat3( &direction ); + XMVECTOR p = XMLoadFloat4(&plane); + XMVECTOR dir = XMLoadFloat3(&direction); - XMVECTOR nd = XMPlaneDotNormal( p, dir ); + XMVECTOR nd = XMPlaneDotNormal(p, dir); - if ( XMVector3LessOrEqual( XMVectorAbs( nd ), g_RayEpsilon ) ) - { - Dist = 0.f; - return false; - } - else - { - // t = -(dot(n,origin) + D) / dot(n,dir) - XMVECTOR pos = XMLoadFloat3( &position ); - XMVECTOR v = XMPlaneDotNormal( p, pos ); - v = XMVectorAdd( v, XMVectorSplatW(p) ); - v = XMVectorDivide( v, nd ); - float dist = - XMVectorGetX( v ); - if (dist < 0) - { - Dist = 0.f; - return false; - } - else - { - Dist = dist; - return true; - } - } + if (XMVector3LessOrEqual(XMVectorAbs(nd), g_RayEpsilon)) + { + Dist = 0.f; + return false; + } + else + { + // t = -(dot(n,origin) + D) / dot(n,dir) + XMVECTOR pos = XMLoadFloat3(&position); + XMVECTOR v = XMPlaneDotNormal(p, pos); + v = XMVectorAdd(v, XMVectorSplatW(p)); + v = XMVectorDivide(v, nd); + float dist = - XMVectorGetX(v); + if (dist < 0) + { + Dist = 0.f; + return false; + } + else + { + Dist = dist; + return true; + } + } } @@ -3467,47 +3540,55 @@ inline bool Ray::Intersects( const Plane& plane, _Out_ float& Dist ) const // Comparision operators //------------------------------------------------------------------------------ -inline bool Viewport::operator == ( const Viewport& vp ) const +inline bool Viewport::operator ==(const Viewport& vp) const { - return (x == vp.x && y == vp.y - && width == vp.width && height == vp.height - && minDepth == vp.minDepth && maxDepth == vp.maxDepth); + return (x == vp.x && y == vp.y + && width == vp.width && height == vp.height + && minDepth == vp.minDepth && maxDepth == vp.maxDepth); } -inline bool Viewport::operator != ( const Viewport& vp ) const +inline bool Viewport::operator !=(const Viewport& vp) const { - return (x != vp.x || y != vp.y - || width != vp.width || height != vp.height - || minDepth != vp.minDepth || maxDepth != vp.maxDepth); + return (x != vp.x || y != vp.y + || width != vp.width || height != vp.height + || minDepth != vp.minDepth || maxDepth != vp.maxDepth); } //------------------------------------------------------------------------------ // Assignment operators //------------------------------------------------------------------------------ -inline Viewport& Viewport::operator= (const Viewport& vp) +inline Viewport& Viewport::operator=(const Viewport& vp) { - x = vp.x; y = vp.y; - width = vp.width; height = vp.height; - minDepth = vp.minDepth; maxDepth = vp.maxDepth; - return *this; + x = vp.x; + y = vp.y; + width = vp.width; + height = vp.height; + minDepth = vp.minDepth; + maxDepth = vp.maxDepth; + return *this; } -inline Viewport& Viewport::operator= (const RECT& rct) +inline Viewport& Viewport::operator=(const RECT& rct) { - x = float(rct.left); y = float(rct.top); - width = float(rct.right - rct.left); - height = float(rct.bottom - rct.top); - minDepth = 0.f; maxDepth = 1.f; - return *this; + x = float(rct.left); + y = float(rct.top); + width = float(rct.right - rct.left); + height = float(rct.bottom - rct.top); + minDepth = 0.f; + maxDepth = 1.f; + return *this; } -inline Viewport& Viewport::operator= (const D3D11_VIEWPORT& vp) +inline Viewport& Viewport::operator=(const D3D11_VIEWPORT& vp) { - x = vp.TopLeftX; y = vp.TopLeftY; - width = vp.Width; height = vp.Height; - minDepth = vp.MinDepth; maxDepth = vp.MaxDepth; - return *this; + x = vp.TopLeftX; + y = vp.TopLeftY; + width = vp.Width; + height = vp.Height; + minDepth = vp.MinDepth; + maxDepth = vp.MaxDepth; + return *this; } //------------------------------------------------------------------------------ @@ -3516,48 +3597,50 @@ inline Viewport& Viewport::operator= (const D3D11_VIEWPORT& vp) inline float Viewport::AspectRatio() const { - if (width == 0.f || height == 0.f) - return 0.f; + if (width == 0.f || height == 0.f) + return 0.f; - return (width / height); + return (width / height); } inline Vector3 Viewport::Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world) const { - using namespace DirectX; - XMVECTOR v = XMLoadFloat3(&p); - XMMATRIX projection = XMLoadFloat4x4(&proj); - v = XMVector3Project(v, x, y, width, height, minDepth, maxDepth, projection, view, world); - Vector3 result; - XMStoreFloat3(&result, v); - return result; + using namespace DirectX; + XMVECTOR v = XMLoadFloat3(&p); + XMMATRIX projection = XMLoadFloat4x4(&proj); + v = XMVector3Project(v, x, y, width, height, minDepth, maxDepth, projection, view, world); + Vector3 result; + XMStoreFloat3(&result, v); + return result; } -inline void Viewport::Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result) const +inline void Viewport::Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, + Vector3& result) const { - using namespace DirectX; - XMVECTOR v = XMLoadFloat3(&p); - XMMATRIX projection = XMLoadFloat4x4(&proj); - v = XMVector3Project(v, x, y, width, height, minDepth, maxDepth, projection, view, world); - XMStoreFloat3(&result, v); + using namespace DirectX; + XMVECTOR v = XMLoadFloat3(&p); + XMMATRIX projection = XMLoadFloat4x4(&proj); + v = XMVector3Project(v, x, y, width, height, minDepth, maxDepth, projection, view, world); + XMStoreFloat3(&result, v); } inline Vector3 Viewport::Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world) const { - using namespace DirectX; - XMVECTOR v = XMLoadFloat3(&p); - XMMATRIX projection = XMLoadFloat4x4(&proj); - v = XMVector3Unproject(v, x, y, width, height, minDepth, maxDepth, projection, view, world); - Vector3 result; - XMStoreFloat3(&result, v); - return result; + using namespace DirectX; + XMVECTOR v = XMLoadFloat3(&p); + XMMATRIX projection = XMLoadFloat4x4(&proj); + v = XMVector3Unproject(v, x, y, width, height, minDepth, maxDepth, projection, view, world); + Vector3 result; + XMStoreFloat3(&result, v); + return result; } -inline void Viewport::Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result) const +inline void Viewport::Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, + Vector3& result) const { - using namespace DirectX; - XMVECTOR v = XMLoadFloat3(&p); - XMMATRIX projection = XMLoadFloat4x4(&proj); - v = XMVector3Unproject(v, x, y, width, height, minDepth, maxDepth, projection, view, world); - XMStoreFloat3(&result, v); + using namespace DirectX; + XMVECTOR v = XMLoadFloat3(&p); + XMMATRIX projection = XMLoadFloat4x4(&proj); + v = XMVector3Unproject(v, x, y, width, height, minDepth, maxDepth, projection, view, world); + XMStoreFloat3(&result, v); } diff --git a/Windows/DirectXTK/SpriteBatch.h b/Windows/DirectXTK/SpriteBatch.h index 9c974e1..23c0b85 100644 --- a/Windows/DirectXTK/SpriteBatch.h +++ b/Windows/DirectXTK/SpriteBatch.h @@ -46,76 +46,98 @@ namespace DirectX { - #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) +#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) #define XM_CALLCONV __fastcall typedef const XMVECTOR& HXMVECTOR; typedef const XMMATRIX& FXMMATRIX; - #endif +#endif - enum SpriteSortMode - { - SpriteSortMode_Deferred, - SpriteSortMode_Immediate, - SpriteSortMode_Texture, - SpriteSortMode_BackToFront, - SpriteSortMode_FrontToBack, - }; - - - enum SpriteEffects - { - SpriteEffects_None = 0, - SpriteEffects_FlipHorizontally = 1, - SpriteEffects_FlipVertically = 2, - SpriteEffects_FlipBoth = SpriteEffects_FlipHorizontally | SpriteEffects_FlipVertically, - }; + enum SpriteSortMode + { + SpriteSortMode_Deferred, + SpriteSortMode_Immediate, + SpriteSortMode_Texture, + SpriteSortMode_BackToFront, + SpriteSortMode_FrontToBack, + }; - - class SpriteBatch - { - public: - explicit SpriteBatch(_In_ ID3D11DeviceContext* deviceContext); - SpriteBatch(SpriteBatch&& moveFrom); - SpriteBatch& operator= (SpriteBatch&& moveFrom); - virtual ~SpriteBatch(); - // Begin/End a batch of sprite drawing operations. - void XM_CALLCONV Begin(SpriteSortMode sortMode = SpriteSortMode_Deferred, _In_opt_ ID3D11BlendState* blendState = nullptr, _In_opt_ ID3D11SamplerState* samplerState = nullptr, _In_opt_ ID3D11DepthStencilState* depthStencilState = nullptr, _In_opt_ ID3D11RasterizerState* rasterizerState = nullptr, - _In_opt_ std::function setCustomShaders = nullptr, FXMMATRIX transformMatrix = MatrixIdentity); - void __cdecl End(); + enum SpriteEffects + { + SpriteEffects_None = 0, + SpriteEffects_FlipHorizontally = 1, + SpriteEffects_FlipVertically = 2, + SpriteEffects_FlipBoth = SpriteEffects_FlipHorizontally | SpriteEffects_FlipVertically, + }; - // Draw overloads specifying position, origin and scale as XMFLOAT2. - void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, FXMVECTOR color = Colors::White); - void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); - void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); - // Draw overloads specifying position, origin and scale via the first two components of an XMVECTOR. - void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, FXMVECTOR color = Colors::White); - void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); - void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); + class SpriteBatch + { + public: + explicit SpriteBatch(_In_ ID3D11DeviceContext* deviceContext); + SpriteBatch(SpriteBatch&& moveFrom); + SpriteBatch& operator=(SpriteBatch&& moveFrom); + virtual ~SpriteBatch(); - // Draw overloads specifying position as a RECT. - void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, FXMVECTOR color = Colors::White); - void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); + // Begin/End a batch of sprite drawing operations. + void XM_CALLCONV Begin(SpriteSortMode sortMode = SpriteSortMode_Deferred, + _In_opt_ ID3D11BlendState* blendState = nullptr, + _In_opt_ ID3D11SamplerState* samplerState = nullptr, + _In_opt_ ID3D11DepthStencilState* depthStencilState = nullptr, + _In_opt_ ID3D11RasterizerState* rasterizerState = nullptr, + _In_opt_ std::function setCustomShaders = nullptr, + FXMMATRIX transformMatrix = MatrixIdentity); + void __cdecl End(); - // Rotation mode to be applied to the sprite transformation - void __cdecl SetRotation( DXGI_MODE_ROTATION mode ); - DXGI_MODE_ROTATION __cdecl GetRotation() const; + // Draw overloads specifying position, origin and scale as XMFLOAT2. + void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, + FXMVECTOR color = Colors::White); + void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, + _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, + XMFLOAT2 const& origin = Float2Zero, float scale = 1, + SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); + void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, + _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, + XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, + float layerDepth = 0); - // Set viewport for sprite transformation - void __cdecl SetViewport( const D3D11_VIEWPORT& viewPort ); + // Draw overloads specifying position, origin and scale via the first two components of an XMVECTOR. + void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, + FXMVECTOR color = Colors::White); + void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, + _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, + FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, + float layerDepth = 0); + void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, + _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, FXMVECTOR origin, + GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); - private: - // Private implementation. - class Impl; + // Draw overloads specifying position as a RECT. + void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, + FXMVECTOR color = Colors::White); + void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, + _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, + XMFLOAT2 const& origin = Float2Zero, SpriteEffects effects = SpriteEffects_None, + float layerDepth = 0); - std::unique_ptr pImpl; + // Rotation mode to be applied to the sprite transformation + void __cdecl SetRotation(DXGI_MODE_ROTATION mode); + DXGI_MODE_ROTATION __cdecl GetRotation() const; - static const XMMATRIX MatrixIdentity; - static const XMFLOAT2 Float2Zero; + // Set viewport for sprite transformation + void __cdecl SetViewport(const D3D11_VIEWPORT& viewPort); - // Prevent copying. - SpriteBatch(SpriteBatch const&) DIRECTX_CTOR_DELETE - SpriteBatch& operator= (SpriteBatch const&) DIRECTX_CTOR_DELETE - }; + private: + // Private implementation. + class Impl; + + std::unique_ptr pImpl; + + static const XMMATRIX MatrixIdentity; + static const XMFLOAT2 Float2Zero; + + // Prevent copying. + SpriteBatch(SpriteBatch const&) DIRECTX_CTOR_DELETE + SpriteBatch& operator=(SpriteBatch const&) DIRECTX_CTOR_DELETE + }; } diff --git a/Windows/DirectXTK/SpriteFont.h b/Windows/DirectXTK/SpriteFont.h index 47db082..b9b1420 100644 --- a/Windows/DirectXTK/SpriteFont.h +++ b/Windows/DirectXTK/SpriteFont.h @@ -29,61 +29,72 @@ namespace DirectX { - class SpriteFont - { - public: - struct Glyph; + class SpriteFont + { + public: + struct Glyph; - SpriteFont(_In_ ID3D11Device* device, _In_z_ wchar_t const* fileName); - SpriteFont(_In_ ID3D11Device* device, _In_reads_bytes_(dataSize) uint8_t const* dataBlob, _In_ size_t dataSize); - SpriteFont(_In_ ID3D11ShaderResourceView* texture, _In_reads_(glyphCount) Glyph const* glyphs, _In_ size_t glyphCount, _In_ float lineSpacing); + SpriteFont(_In_ ID3D11Device* device, _In_z_ wchar_t const* fileName); + SpriteFont(_In_ ID3D11Device* device, _In_reads_bytes_(dataSize) uint8_t const* dataBlob, _In_ size_t dataSize); + SpriteFont(_In_ ID3D11ShaderResourceView* texture, _In_reads_(glyphCount) Glyph const* glyphs, + _In_ size_t glyphCount, _In_ float lineSpacing); - SpriteFont(SpriteFont&& moveFrom); - SpriteFont& operator= (SpriteFont&& moveFrom); - virtual ~SpriteFont(); + SpriteFont(SpriteFont&& moveFrom); + SpriteFont& operator=(SpriteFont&& moveFrom); + virtual ~SpriteFont(); - void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; - void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; - void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; - void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; + void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, + FXMVECTOR color = Colors::White, float rotation = 0, + XMFLOAT2 const& origin = Float2Zero, float scale = 1, + SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; + void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, + FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, + SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; + void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, + FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, + float scale = 1, SpriteEffects effects = SpriteEffects_None, + float layerDepth = 0) const; + void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, + FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, + SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; - XMVECTOR XM_CALLCONV MeasureString(_In_z_ wchar_t const* text) const; + XMVECTOR XM_CALLCONV MeasureString(_In_z_ wchar_t const* text) const; - // Spacing properties - float __cdecl GetLineSpacing() const; - void __cdecl SetLineSpacing(float spacing); + // Spacing properties + float __cdecl GetLineSpacing() const; + void __cdecl SetLineSpacing(float spacing); - // Font properties - wchar_t __cdecl GetDefaultCharacter() const; - void __cdecl SetDefaultCharacter(wchar_t character); + // Font properties + wchar_t __cdecl GetDefaultCharacter() const; + void __cdecl SetDefaultCharacter(wchar_t character); - bool __cdecl ContainsCharacter(wchar_t character) const; + bool __cdecl ContainsCharacter(wchar_t character) const; - // Custom layout/rendering - Glyph const* __cdecl FindGlyph(wchar_t character) const; - void GetSpriteSheet( ID3D11ShaderResourceView** texture ) const; + // Custom layout/rendering + Glyph const* __cdecl FindGlyph(wchar_t character) const; + void GetSpriteSheet(ID3D11ShaderResourceView** texture) const; - // Describes a single character glyph. - struct Glyph - { - uint32_t Character; - RECT Subrect; - float XOffset; - float YOffset; - float XAdvance; - }; + // Describes a single character glyph. + struct Glyph + { + uint32_t Character; + RECT Subrect; + float XOffset; + float YOffset; + float XAdvance; + }; - private: - // Private implementation. - class Impl; + private: + // Private implementation. + class Impl; - std::unique_ptr pImpl; + std::unique_ptr pImpl; - static const XMFLOAT2 Float2Zero; + static const XMFLOAT2 Float2Zero; - // Prevent copying. - SpriteFont(SpriteFont const&) DIRECTX_CTOR_DELETE - SpriteFont& operator= (SpriteFont const&) DIRECTX_CTOR_DELETE - }; + // Prevent copying. + SpriteFont(SpriteFont const&) DIRECTX_CTOR_DELETE + SpriteFont& operator=(SpriteFont const&) DIRECTX_CTOR_DELETE + }; } diff --git a/Windows/DirectXTK/VertexTypes.h b/Windows/DirectXTK/VertexTypes.h index 0ee7629..b999bc1 100644 --- a/Windows/DirectXTK/VertexTypes.h +++ b/Windows/DirectXTK/VertexTypes.h @@ -35,299 +35,318 @@ namespace DirectX { - #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) +#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) #define XM_CALLCONV __fastcall typedef const XMVECTOR& HXMVECTOR; typedef const XMMATRIX& FXMMATRIX; - #endif +#endif - // Vertex struct holding position and color information. - struct VertexPositionColor - { - VertexPositionColor() DIRECTX_CTOR_DEFAULT + // Vertex struct holding position and color information. + struct VertexPositionColor + { + VertexPositionColor() DIRECTX_CTOR_DEFAULT - VertexPositionColor(XMFLOAT3 const& position, XMFLOAT4 const& color) - : position(position), - color(color) - { } + VertexPositionColor(XMFLOAT3 const& position, XMFLOAT4 const& color) + : position(position), + color(color) + { + } - VertexPositionColor(FXMVECTOR position, FXMVECTOR color) - { - XMStoreFloat3(&this->position, position); - XMStoreFloat4(&this->color, color); - } + VertexPositionColor(FXMVECTOR position, FXMVECTOR color) + { + XMStoreFloat3(&this->position, position); + XMStoreFloat4(&this->color, color); + } - XMFLOAT3 position; - XMFLOAT4 color; + XMFLOAT3 position; + XMFLOAT4 color; - static const int InputElementCount = 2; - static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; - }; + static const int InputElementCount = 2; + static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; + }; - // Vertex struct holding position and texture mapping information. - struct VertexPositionTexture - { - VertexPositionTexture() DIRECTX_CTOR_DEFAULT + // Vertex struct holding position and texture mapping information. + struct VertexPositionTexture + { + VertexPositionTexture() DIRECTX_CTOR_DEFAULT - VertexPositionTexture(XMFLOAT3 const& position, XMFLOAT2 const& textureCoordinate) - : position(position), - textureCoordinate(textureCoordinate) - { } + VertexPositionTexture(XMFLOAT3 const& position, XMFLOAT2 const& textureCoordinate) + : position(position), + textureCoordinate(textureCoordinate) + { + } - VertexPositionTexture(FXMVECTOR position, FXMVECTOR textureCoordinate) - { - XMStoreFloat3(&this->position, position); - XMStoreFloat2(&this->textureCoordinate, textureCoordinate); - } + VertexPositionTexture(FXMVECTOR position, FXMVECTOR textureCoordinate) + { + XMStoreFloat3(&this->position, position); + XMStoreFloat2(&this->textureCoordinate, textureCoordinate); + } - XMFLOAT3 position; - XMFLOAT2 textureCoordinate; + XMFLOAT3 position; + XMFLOAT2 textureCoordinate; - static const int InputElementCount = 2; - static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; - }; + static const int InputElementCount = 2; + static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; + }; - // Vertex struct holding position and normal vector. - struct VertexPositionNormal - { - VertexPositionNormal() DIRECTX_CTOR_DEFAULT + // Vertex struct holding position and normal vector. + struct VertexPositionNormal + { + VertexPositionNormal() DIRECTX_CTOR_DEFAULT - VertexPositionNormal(XMFLOAT3 const& position, XMFLOAT3 const& normal) - : position(position), - normal(normal) - { } + VertexPositionNormal(XMFLOAT3 const& position, XMFLOAT3 const& normal) + : position(position), + normal(normal) + { + } - VertexPositionNormal(FXMVECTOR position, FXMVECTOR normal) - { - XMStoreFloat3(&this->position, position); - XMStoreFloat3(&this->normal, normal); - } + VertexPositionNormal(FXMVECTOR position, FXMVECTOR normal) + { + XMStoreFloat3(&this->position, position); + XMStoreFloat3(&this->normal, normal); + } - XMFLOAT3 position; - XMFLOAT3 normal; + XMFLOAT3 position; + XMFLOAT3 normal; - static const int InputElementCount = 2; - static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; - }; + static const int InputElementCount = 2; + static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; + }; - // Vertex struct holding position, color, and texture mapping information. - struct VertexPositionColorTexture - { - VertexPositionColorTexture() DIRECTX_CTOR_DEFAULT + // Vertex struct holding position, color, and texture mapping information. + struct VertexPositionColorTexture + { + VertexPositionColorTexture() DIRECTX_CTOR_DEFAULT - VertexPositionColorTexture(XMFLOAT3 const& position, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate) - : position(position), - color(color), - textureCoordinate(textureCoordinate) - { } + VertexPositionColorTexture(XMFLOAT3 const& position, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate) + : position(position), + color(color), + textureCoordinate(textureCoordinate) + { + } - VertexPositionColorTexture(FXMVECTOR position, FXMVECTOR color, FXMVECTOR textureCoordinate) - { - XMStoreFloat3(&this->position, position); - XMStoreFloat4(&this->color, color); - XMStoreFloat2(&this->textureCoordinate, textureCoordinate); - } + VertexPositionColorTexture(FXMVECTOR position, FXMVECTOR color, FXMVECTOR textureCoordinate) + { + XMStoreFloat3(&this->position, position); + XMStoreFloat4(&this->color, color); + XMStoreFloat2(&this->textureCoordinate, textureCoordinate); + } - XMFLOAT3 position; - XMFLOAT4 color; - XMFLOAT2 textureCoordinate; + XMFLOAT3 position; + XMFLOAT4 color; + XMFLOAT2 textureCoordinate; - static const int InputElementCount = 3; - static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; - }; + static const int InputElementCount = 3; + static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; + }; - // Vertex struct holding position, normal vector, and color information. - struct VertexPositionNormalColor - { - VertexPositionNormalColor() DIRECTX_CTOR_DEFAULT + // Vertex struct holding position, normal vector, and color information. + struct VertexPositionNormalColor + { + VertexPositionNormalColor() DIRECTX_CTOR_DEFAULT - VertexPositionNormalColor(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color) - : position(position), - normal(normal), - color(color) - { } + VertexPositionNormalColor(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color) + : position(position), + normal(normal), + color(color) + { + } - VertexPositionNormalColor(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color) - { - XMStoreFloat3(&this->position, position); - XMStoreFloat3(&this->normal, normal); - XMStoreFloat4(&this->color, color); - } + VertexPositionNormalColor(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color) + { + XMStoreFloat3(&this->position, position); + XMStoreFloat3(&this->normal, normal); + XMStoreFloat4(&this->color, color); + } - XMFLOAT3 position; - XMFLOAT3 normal; - XMFLOAT4 color; + XMFLOAT3 position; + XMFLOAT3 normal; + XMFLOAT4 color; - static const int InputElementCount = 3; - static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; - }; + static const int InputElementCount = 3; + static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; + }; - // Vertex struct holding position, normal vector, and texture mapping information. - struct VertexPositionNormalTexture - { - VertexPositionNormalTexture() DIRECTX_CTOR_DEFAULT + // Vertex struct holding position, normal vector, and texture mapping information. + struct VertexPositionNormalTexture + { + VertexPositionNormalTexture() DIRECTX_CTOR_DEFAULT - VertexPositionNormalTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT2 const& textureCoordinate) - : position(position), - normal(normal), - textureCoordinate(textureCoordinate) - { } + VertexPositionNormalTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT2 const& textureCoordinate) + : position(position), + normal(normal), + textureCoordinate(textureCoordinate) + { + } - VertexPositionNormalTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR textureCoordinate) - { - XMStoreFloat3(&this->position, position); - XMStoreFloat3(&this->normal, normal); - XMStoreFloat2(&this->textureCoordinate, textureCoordinate); - } + VertexPositionNormalTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR textureCoordinate) + { + XMStoreFloat3(&this->position, position); + XMStoreFloat3(&this->normal, normal); + XMStoreFloat2(&this->textureCoordinate, textureCoordinate); + } - XMFLOAT3 position; - XMFLOAT3 normal; - XMFLOAT2 textureCoordinate; + XMFLOAT3 position; + XMFLOAT3 normal; + XMFLOAT2 textureCoordinate; - static const int InputElementCount = 3; - static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; - }; + static const int InputElementCount = 3; + static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; + }; - // Vertex struct holding position, normal vector, color, and texture mapping information. - struct VertexPositionNormalColorTexture - { - VertexPositionNormalColorTexture() DIRECTX_CTOR_DEFAULT + // Vertex struct holding position, normal vector, color, and texture mapping information. + struct VertexPositionNormalColorTexture + { + VertexPositionNormalColorTexture() DIRECTX_CTOR_DEFAULT - VertexPositionNormalColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate) - : position(position), - normal(normal), - color(color), - textureCoordinate(textureCoordinate) - { } + VertexPositionNormalColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color, + XMFLOAT2 const& textureCoordinate) + : position(position), + normal(normal), + color(color), + textureCoordinate(textureCoordinate) + { + } - VertexPositionNormalColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color, CXMVECTOR textureCoordinate) - { - XMStoreFloat3(&this->position, position); - XMStoreFloat3(&this->normal, normal); - XMStoreFloat4(&this->color, color); - XMStoreFloat2(&this->textureCoordinate, textureCoordinate); - } + VertexPositionNormalColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color, + CXMVECTOR textureCoordinate) + { + XMStoreFloat3(&this->position, position); + XMStoreFloat3(&this->normal, normal); + XMStoreFloat4(&this->color, color); + XMStoreFloat2(&this->textureCoordinate, textureCoordinate); + } - XMFLOAT3 position; - XMFLOAT3 normal; - XMFLOAT4 color; - XMFLOAT2 textureCoordinate; + XMFLOAT3 position; + XMFLOAT3 normal; + XMFLOAT4 color; + XMFLOAT2 textureCoordinate; - static const int InputElementCount = 4; - static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; - }; + static const int InputElementCount = 4; + static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; + }; - // Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal, - // tangent, color (RGBA), and texture mapping information - struct VertexPositionNormalTangentColorTexture - { - VertexPositionNormalTangentColorTexture() DIRECTX_CTOR_DEFAULT + // Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal, + // tangent, color (RGBA), and texture mapping information + struct VertexPositionNormalTangentColorTexture + { + VertexPositionNormalTangentColorTexture() DIRECTX_CTOR_DEFAULT - XMFLOAT3 position; - XMFLOAT3 normal; - XMFLOAT4 tangent; - uint32_t color; - XMFLOAT2 textureCoordinate; + XMFLOAT3 position; + XMFLOAT3 normal; + XMFLOAT4 tangent; + uint32_t color; + XMFLOAT2 textureCoordinate; - VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, uint32_t rgba, XMFLOAT2 const& textureCoordinate) - : position(position), - normal(normal), - tangent(tangent), - color(rgba), - textureCoordinate(textureCoordinate) - { - } + VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, + uint32_t rgba, XMFLOAT2 const& textureCoordinate) + : position(position), + normal(normal), + tangent(tangent), + color(rgba), + textureCoordinate(textureCoordinate) + { + } - VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, CXMVECTOR textureCoordinate) - : color(rgba) - { - XMStoreFloat3(&this->position, position); - XMStoreFloat3(&this->normal, normal); - XMStoreFloat4(&this->tangent, tangent); - XMStoreFloat2(&this->textureCoordinate, textureCoordinate); - } + VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, + CXMVECTOR textureCoordinate) + : color(rgba) + { + XMStoreFloat3(&this->position, position); + XMStoreFloat3(&this->normal, normal); + XMStoreFloat4(&this->tangent, tangent); + XMStoreFloat2(&this->textureCoordinate, textureCoordinate); + } - VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate) - : position(position), - normal(normal), - tangent(tangent), - textureCoordinate(textureCoordinate) - { - SetColor( color ); - } + VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, + XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate) + : position(position), + normal(normal), + tangent(tangent), + textureCoordinate(textureCoordinate) + { + SetColor(color); + } - VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, CXMVECTOR textureCoordinate) - { - XMStoreFloat3(&this->position, position); - XMStoreFloat3(&this->normal, normal); - XMStoreFloat4(&this->tangent, tangent); - XMStoreFloat2(&this->textureCoordinate, textureCoordinate); + VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, + CXMVECTOR textureCoordinate) + { + XMStoreFloat3(&this->position, position); + XMStoreFloat3(&this->normal, normal); + XMStoreFloat4(&this->tangent, tangent); + XMStoreFloat2(&this->textureCoordinate, textureCoordinate); - SetColor( color ); - } + SetColor(color); + } - void __cdecl SetColor( XMFLOAT4 const& icolor ) { SetColor( XMLoadFloat4( &icolor ) ); } - void XM_CALLCONV SetColor( FXMVECTOR icolor ); + void __cdecl SetColor(XMFLOAT4 const& icolor) { SetColor(XMLoadFloat4(&icolor)); } + void XM_CALLCONV SetColor(FXMVECTOR icolor); - static const int InputElementCount = 5; - static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; - }; + static const int InputElementCount = 5; + static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; + }; - // Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal, - // tangent, color (RGBA), texture mapping information, and skinning weights - struct VertexPositionNormalTangentColorTextureSkinning : public VertexPositionNormalTangentColorTexture - { - VertexPositionNormalTangentColorTextureSkinning() DIRECTX_CTOR_DEFAULT + // Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal, + // tangent, color (RGBA), texture mapping information, and skinning weights + struct VertexPositionNormalTangentColorTextureSkinning : public VertexPositionNormalTangentColorTexture + { + VertexPositionNormalTangentColorTextureSkinning() DIRECTX_CTOR_DEFAULT - uint32_t indices; - uint32_t weights; + uint32_t indices; + uint32_t weights; - VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, uint32_t rgba, - XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, XMFLOAT4 const& weights) - : VertexPositionNormalTangentColorTexture(position,normal,tangent,rgba,textureCoordinate) - { - SetBlendIndices( indices ); - SetBlendWeights( weights ); - } + VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, + XMFLOAT4 const& tangent, uint32_t rgba, + XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, + XMFLOAT4 const& weights) + : VertexPositionNormalTangentColorTexture(position, normal, tangent, rgba, textureCoordinate) + { + SetBlendIndices(indices); + SetBlendWeights(weights); + } - VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, CXMVECTOR textureCoordinate, - XMUINT4 const& indices, CXMVECTOR weights) - : VertexPositionNormalTangentColorTexture(position,normal,tangent,rgba,textureCoordinate) - { - SetBlendIndices( indices ); - SetBlendWeights( weights ); - } + VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, + uint32_t rgba, CXMVECTOR textureCoordinate, + XMUINT4 const& indices, CXMVECTOR weights) + : VertexPositionNormalTangentColorTexture(position, normal, tangent, rgba, textureCoordinate) + { + SetBlendIndices(indices); + SetBlendWeights(weights); + } - VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, XMFLOAT4 const& color, - XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, XMFLOAT4 const& weights) - : VertexPositionNormalTangentColorTexture(position,normal,tangent,color,textureCoordinate) - { - SetBlendIndices( indices ); - SetBlendWeights( weights ); - } + VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, + XMFLOAT4 const& tangent, XMFLOAT4 const& color, + XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, + XMFLOAT4 const& weights) + : VertexPositionNormalTangentColorTexture(position, normal, tangent, color, textureCoordinate) + { + SetBlendIndices(indices); + SetBlendWeights(weights); + } - VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, CXMVECTOR textureCoordinate, - XMUINT4 const& indices, CXMVECTOR weights) - : VertexPositionNormalTangentColorTexture(position,normal,tangent,color,textureCoordinate) - { - SetBlendIndices( indices ); - SetBlendWeights( weights ); - } + VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, + CXMVECTOR color, CXMVECTOR textureCoordinate, + XMUINT4 const& indices, CXMVECTOR weights) + : VertexPositionNormalTangentColorTexture(position, normal, tangent, color, textureCoordinate) + { + SetBlendIndices(indices); + SetBlendWeights(weights); + } - void __cdecl SetBlendIndices( XMUINT4 const& iindices ); + void __cdecl SetBlendIndices(XMUINT4 const& iindices); - void __cdecl SetBlendWeights( XMFLOAT4 const& iweights ) { SetBlendWeights( XMLoadFloat4( &iweights ) ); } - void XM_CALLCONV SetBlendWeights( FXMVECTOR iweights ); + void __cdecl SetBlendWeights(XMFLOAT4 const& iweights) { SetBlendWeights(XMLoadFloat4(&iweights)); } + void XM_CALLCONV SetBlendWeights(FXMVECTOR iweights); - static const int InputElementCount = 7; - static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; - }; + static const int InputElementCount = 7; + static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; + }; } diff --git a/Windows/DirectXTK/WICTextureLoader.h b/Windows/DirectXTK/WICTextureLoader.h index ae8b705..e19f869 100644 --- a/Windows/DirectXTK/WICTextureLoader.h +++ b/Windows/DirectXTK/WICTextureLoader.h @@ -44,111 +44,111 @@ namespace DirectX { - // Standard version - HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice, - _In_reads_bytes_(wicDataSize) const uint8_t* wicData, - _In_ size_t wicDataSize, - _Out_opt_ ID3D11Resource** texture, - _Out_opt_ ID3D11ShaderResourceView** textureView, - _In_ size_t maxsize = 0 - ); + // Standard version + HRESULT __cdecl CreateWICTextureFromMemory(_In_ ID3D11Device* d3dDevice, + _In_reads_bytes_(wicDataSize) const uint8_t* wicData, + _In_ size_t wicDataSize, + _Out_opt_ ID3D11Resource** texture, + _Out_opt_ ID3D11ShaderResourceView** textureView, + _In_ size_t maxsize = 0 + ); - HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice, - _In_z_ const wchar_t* szFileName, - _Out_opt_ ID3D11Resource** texture, - _Out_opt_ ID3D11ShaderResourceView** textureView, - _In_ size_t maxsize = 0 - ); + HRESULT __cdecl CreateWICTextureFromFile(_In_ ID3D11Device* d3dDevice, + _In_z_ const wchar_t* szFileName, + _Out_opt_ ID3D11Resource** texture, + _Out_opt_ ID3D11ShaderResourceView** textureView, + _In_ size_t maxsize = 0 + ); - // Standard version with optional auto-gen mipmap support - #if defined(_XBOX_ONE) && defined(_TITLE) + // Standard version with optional auto-gen mipmap support +#if defined(_XBOX_ONE) && defined(_TITLE) HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11DeviceX* d3dDevice, _In_opt_ ID3D11DeviceContextX* d3dContext, - #else - HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice, - _In_opt_ ID3D11DeviceContext* d3dContext, - #endif - _In_reads_bytes_(wicDataSize) const uint8_t* wicData, - _In_ size_t wicDataSize, - _Out_opt_ ID3D11Resource** texture, - _Out_opt_ ID3D11ShaderResourceView** textureView, - _In_ size_t maxsize = 0 - ); +#else + HRESULT __cdecl CreateWICTextureFromMemory(_In_ ID3D11Device* d3dDevice, + _In_opt_ ID3D11DeviceContext* d3dContext, +#endif + _In_reads_bytes_(wicDataSize) const uint8_t* wicData, + _In_ size_t wicDataSize, + _Out_opt_ ID3D11Resource** texture, + _Out_opt_ ID3D11ShaderResourceView** textureView, + _In_ size_t maxsize = 0 + ); - #if defined(_XBOX_ONE) && defined(_TITLE) +#if defined(_XBOX_ONE) && defined(_TITLE) HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11DeviceX* d3dDevice, _In_opt_ ID3D11DeviceContextX* d3dContext, - #else - HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice, - _In_opt_ ID3D11DeviceContext* d3dContext, - #endif - _In_z_ const wchar_t* szFileName, - _Out_opt_ ID3D11Resource** texture, - _Out_opt_ ID3D11ShaderResourceView** textureView, - _In_ size_t maxsize = 0 - ); +#else + HRESULT __cdecl CreateWICTextureFromFile(_In_ ID3D11Device* d3dDevice, + _In_opt_ ID3D11DeviceContext* d3dContext, +#endif + _In_z_ const wchar_t* szFileName, + _Out_opt_ ID3D11Resource** texture, + _Out_opt_ ID3D11ShaderResourceView** textureView, + _In_ size_t maxsize = 0 + ); - // Extended version - HRESULT __cdecl CreateWICTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice, - _In_reads_bytes_(wicDataSize) const uint8_t* wicData, - _In_ size_t wicDataSize, - _In_ size_t maxsize, - _In_ D3D11_USAGE usage, - _In_ unsigned int bindFlags, - _In_ unsigned int cpuAccessFlags, - _In_ unsigned int miscFlags, - _In_ bool forceSRGB, - _Out_opt_ ID3D11Resource** texture, - _Out_opt_ ID3D11ShaderResourceView** textureView - ); + // Extended version + HRESULT __cdecl CreateWICTextureFromMemoryEx(_In_ ID3D11Device* d3dDevice, + _In_reads_bytes_(wicDataSize) const uint8_t* wicData, + _In_ size_t wicDataSize, + _In_ size_t maxsize, + _In_ D3D11_USAGE usage, + _In_ unsigned int bindFlags, + _In_ unsigned int cpuAccessFlags, + _In_ unsigned int miscFlags, + _In_ bool forceSRGB, + _Out_opt_ ID3D11Resource** texture, + _Out_opt_ ID3D11ShaderResourceView** textureView + ); - HRESULT __cdecl CreateWICTextureFromFileEx( _In_ ID3D11Device* d3dDevice, - _In_z_ const wchar_t* szFileName, - _In_ size_t maxsize, - _In_ D3D11_USAGE usage, - _In_ unsigned int bindFlags, - _In_ unsigned int cpuAccessFlags, - _In_ unsigned int miscFlags, - _In_ bool forceSRGB, - _Out_opt_ ID3D11Resource** texture, - _Out_opt_ ID3D11ShaderResourceView** textureView - ); + HRESULT __cdecl CreateWICTextureFromFileEx(_In_ ID3D11Device* d3dDevice, + _In_z_ const wchar_t* szFileName, + _In_ size_t maxsize, + _In_ D3D11_USAGE usage, + _In_ unsigned int bindFlags, + _In_ unsigned int cpuAccessFlags, + _In_ unsigned int miscFlags, + _In_ bool forceSRGB, + _Out_opt_ ID3D11Resource** texture, + _Out_opt_ ID3D11ShaderResourceView** textureView + ); - // Extended version with optional auto-gen mipmap support - #if defined(_XBOX_ONE) && defined(_TITLE) + // Extended version with optional auto-gen mipmap support +#if defined(_XBOX_ONE) && defined(_TITLE) HRESULT __cdecl CreateWICTextureFromMemoryEx( _In_ ID3D11DeviceX* d3dDevice, _In_opt_ ID3D11DeviceContextX* d3dContext, - #else - HRESULT __cdecl CreateWICTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice, - _In_opt_ ID3D11DeviceContext* d3dContext, - #endif - _In_reads_bytes_(wicDataSize) const uint8_t* wicData, - _In_ size_t wicDataSize, - _In_ size_t maxsize, - _In_ D3D11_USAGE usage, - _In_ unsigned int bindFlags, - _In_ unsigned int cpuAccessFlags, - _In_ unsigned int miscFlags, - _In_ bool forceSRGB, - _Out_opt_ ID3D11Resource** texture, - _Out_opt_ ID3D11ShaderResourceView** textureView - ); +#else + HRESULT __cdecl CreateWICTextureFromMemoryEx(_In_ ID3D11Device* d3dDevice, + _In_opt_ ID3D11DeviceContext* d3dContext, +#endif + _In_reads_bytes_(wicDataSize) const uint8_t* wicData, + _In_ size_t wicDataSize, + _In_ size_t maxsize, + _In_ D3D11_USAGE usage, + _In_ unsigned int bindFlags, + _In_ unsigned int cpuAccessFlags, + _In_ unsigned int miscFlags, + _In_ bool forceSRGB, + _Out_opt_ ID3D11Resource** texture, + _Out_opt_ ID3D11ShaderResourceView** textureView + ); - #if defined(_XBOX_ONE) && defined(_TITLE) +#if defined(_XBOX_ONE) && defined(_TITLE) HRESULT __cdecl CreateWICTextureFromFileEx( _In_ ID3D11DeviceX* d3dDevice, _In_opt_ ID3D11DeviceContextX* d3dContext, - #else - HRESULT __cdecl CreateWICTextureFromFileEx( _In_ ID3D11Device* d3dDevice, - _In_opt_ ID3D11DeviceContext* d3dContext, - #endif - _In_z_ const wchar_t* szFileName, - _In_ size_t maxsize, - _In_ D3D11_USAGE usage, - _In_ unsigned int bindFlags, - _In_ unsigned int cpuAccessFlags, - _In_ unsigned int miscFlags, - _In_ bool forceSRGB, - _Out_opt_ ID3D11Resource** texture, - _Out_opt_ ID3D11ShaderResourceView** textureView - ); -} \ No newline at end of file +#else + HRESULT __cdecl CreateWICTextureFromFileEx(_In_ ID3D11Device* d3dDevice, + _In_opt_ ID3D11DeviceContext* d3dContext, +#endif + _In_z_ const wchar_t* szFileName, + _In_ size_t maxsize, + _In_ D3D11_USAGE usage, + _In_ unsigned int bindFlags, + _In_ unsigned int cpuAccessFlags, + _In_ unsigned int miscFlags, + _In_ bool forceSRGB, + _Out_opt_ ID3D11Resource** texture, + _Out_opt_ ID3D11ShaderResourceView** textureView + ); +} diff --git a/Windows/DirectXTK/XboxDDSTextureLoader.h b/Windows/DirectXTK/XboxDDSTextureLoader.h index f303b67..aa3efef 100644 --- a/Windows/DirectXTK/XboxDDSTextureLoader.h +++ b/Windows/DirectXTK/XboxDDSTextureLoader.h @@ -31,31 +31,31 @@ namespace Xbox { - enum DDS_ALPHA_MODE - { - DDS_ALPHA_MODE_UNKNOWN = 0, - DDS_ALPHA_MODE_STRAIGHT = 1, - DDS_ALPHA_MODE_PREMULTIPLIED = 2, - DDS_ALPHA_MODE_OPAQUE = 3, - DDS_ALPHA_MODE_CUSTOM = 4, - }; + enum DDS_ALPHA_MODE + { + DDS_ALPHA_MODE_UNKNOWN = 0, + DDS_ALPHA_MODE_STRAIGHT = 1, + DDS_ALPHA_MODE_PREMULTIPLIED = 2, + DDS_ALPHA_MODE_OPAQUE = 3, + DDS_ALPHA_MODE_CUSTOM = 4, + }; - HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11DeviceX* d3dDevice, - _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, - _In_ size_t ddsDataSize, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _Outptr_ void** grfxMemory, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr, - _In_ bool forceSRGB = false - ); + HRESULT __cdecl CreateDDSTextureFromMemory(_In_ ID3D11DeviceX* d3dDevice, + _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, + _In_ size_t ddsDataSize, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _Outptr_ void** grfxMemory, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr, + _In_ bool forceSRGB = false + ); - HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11DeviceX* d3dDevice, - _In_z_ const wchar_t* szFileName, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _Outptr_ void** grfxMemory, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr, - _In_ bool forceSRGB = false - ); -} \ No newline at end of file + HRESULT __cdecl CreateDDSTextureFromFile(_In_ ID3D11DeviceX* d3dDevice, + _In_z_ const wchar_t* szFileName, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _Outptr_ void** grfxMemory, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr, + _In_ bool forceSRGB = false + ); +} diff --git a/Windows/Renderer.cpp b/Windows/Renderer.cpp index 65273ff..34bd6de 100644 --- a/Windows/Renderer.cpp +++ b/Windows/Renderer.cpp @@ -13,7 +13,8 @@ using namespace DirectX; -Renderer::Renderer(shared_ptr console, HWND hWnd, bool registerAsMessageManager) : BaseRenderer(console, registerAsMessageManager) +Renderer::Renderer(shared_ptr console, HWND hWnd, bool registerAsMessageManager) : BaseRenderer( + console, registerAsMessageManager) { _hWnd = hWnd; @@ -23,7 +24,8 @@ Renderer::Renderer(shared_ptr console, HWND hWnd, bool registerAsMessag Renderer::~Renderer() { shared_ptr videoRenderer = _console->GetVideoRenderer(); - if(videoRenderer) { + if (videoRenderer) + { videoRenderer->UnregisterRenderingDevice(this); } CleanupDevice(); @@ -31,7 +33,8 @@ Renderer::~Renderer() void Renderer::SetFullscreenMode(bool fullscreen, void* windowHandle, uint32_t monitorWidth, uint32_t monitorHeight) { - if(fullscreen != _fullscreen || _hWnd != (HWND)windowHandle) { + if (fullscreen != _fullscreen || _hWnd != (HWND)windowHandle) + { _hWnd = (HWND)windowHandle; _monitorWidth = monitorWidth; _monitorHeight = monitorHeight; @@ -43,21 +46,29 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height) { ScreenSize screenSize = _console->GetVideoDecoder()->GetScreenSize(false); VideoConfig cfg = _console->GetSettings()->GetVideoConfig(); - if(_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height || _nesFrameWidth != width || _newFullscreen != _fullscreen || _useBilinearInterpolation != cfg.UseBilinearInterpolation) { + if (_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height || + _nesFrameWidth != width || _newFullscreen != _fullscreen || _useBilinearInterpolation != cfg. + UseBilinearInterpolation) + { auto frameLock = _frameLock.AcquireSafe(); auto textureLock = _textureLock.AcquireSafe(); screenSize = _console->GetVideoDecoder()->GetScreenSize(false); - if(_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height || _nesFrameWidth != width || _newFullscreen != _fullscreen || _useBilinearInterpolation != cfg.UseBilinearInterpolation) { + if (_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height || + _nesFrameWidth != width || _newFullscreen != _fullscreen || _useBilinearInterpolation != cfg. + UseBilinearInterpolation) + { _nesFrameHeight = height; _nesFrameWidth = width; - _newFrameBufferSize = width*height; + _newFrameBufferSize = width * height; bool needReset = _fullscreen != _newFullscreen || _useBilinearInterpolation != cfg.UseBilinearInterpolation; bool fullscreenResizeMode = _fullscreen && _newFullscreen; - if(_pSwapChain && _fullscreen && !_newFullscreen) { + if (_pSwapChain && _fullscreen && !_newFullscreen) + { HRESULT hr = _pSwapChain->SetFullscreenState(FALSE, NULL); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("SetFullscreenState(FALSE) failed - Error:" + std::to_string(hr)); } } @@ -67,21 +78,26 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height) _screenHeight = screenSize.Height; _screenWidth = screenSize.Width; - if(_fullscreen) { + if (_fullscreen) + { _realScreenHeight = _monitorHeight; _realScreenWidth = _monitorWidth; //Ensure the screen width/height is smaller or equal to the fullscreen resolution, no matter the requested scale - if(_monitorHeight < _screenHeight || _monitorWidth < _screenWidth) { + if (_monitorHeight < _screenHeight || _monitorWidth < _screenWidth) + { double scale = (double)screenSize.Width / (double)screenSize.Height; _screenHeight = _monitorHeight; _screenWidth = (uint32_t)(scale * _screenHeight); - if(_monitorWidth < _screenWidth) { + if (_monitorWidth < _screenWidth) + { _screenWidth = _monitorWidth; _screenHeight = (uint32_t)(_screenWidth / scale); } } - } else { + } + else + { _realScreenHeight = screenSize.Height; _realScreenWidth = screenSize.Width; } @@ -89,15 +105,21 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height) _leftMargin = (_realScreenWidth - _screenWidth) / 2; _topMargin = (_realScreenHeight - _screenHeight) / 2; - _screenBufferSize = _realScreenHeight*_realScreenWidth; + _screenBufferSize = _realScreenHeight * _realScreenWidth; - if(!_pSwapChain || needReset) { + if (!_pSwapChain || needReset) + { Reset(); - } else { - if(fullscreenResizeMode) { + } + else + { + if (fullscreenResizeMode) + { ResetNesBuffers(); CreateNesBuffers(); - } else { + } + else + { ResetNesBuffers(); ReleaseRenderTargetView(); _pSwapChain->ResizeBuffers(1, _realScreenWidth, _realScreenHeight, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, 0); @@ -113,9 +135,12 @@ void Renderer::Reset() { auto lock = _frameLock.AcquireSafe(); CleanupDevice(); - if(FAILED(InitDevice())) { + if (FAILED(InitDevice())) + { CleanupDevice(); - } else { + } + else + { _console->GetVideoRenderer()->RegisterRenderingDevice(this); } } @@ -124,28 +149,34 @@ void Renderer::CleanupDevice() { ResetNesBuffers(); ReleaseRenderTargetView(); - if(_pAlphaEnableBlendingState) { + if (_pAlphaEnableBlendingState) + { _pAlphaEnableBlendingState->Release(); _pAlphaEnableBlendingState = nullptr; } - if(_pDepthDisabledStencilState) { + if (_pDepthDisabledStencilState) + { _pDepthDisabledStencilState->Release(); _pDepthDisabledStencilState = nullptr; } - if(_samplerState) { + if (_samplerState) + { _samplerState->Release(); _samplerState = nullptr; } - if(_pSwapChain) { + if (_pSwapChain) + { _pSwapChain->SetFullscreenState(false, nullptr); _pSwapChain->Release(); _pSwapChain = nullptr; } - if(_pDeviceContext) { + if (_pDeviceContext) + { _pDeviceContext->Release(); _pDeviceContext = nullptr; } - if(_pd3dDevice) { + if (_pd3dDevice) + { _pd3dDevice->Release(); _pd3dDevice = nullptr; } @@ -153,19 +184,23 @@ void Renderer::CleanupDevice() void Renderer::ResetNesBuffers() { - if(_pTexture) { + if (_pTexture) + { _pTexture->Release(); _pTexture = nullptr; } - if(_overlayTexture) { + if (_overlayTexture) + { _overlayTexture->Release(); _overlayTexture = nullptr; } - if(_pTextureSrv) { + if (_pTextureSrv) + { _pTextureSrv->Release(); _pTextureSrv = nullptr; } - if(_pOverlaySrv) { + if (_pOverlaySrv) + { _pOverlaySrv->Release(); _pOverlaySrv = nullptr; } @@ -178,7 +213,8 @@ void Renderer::ResetNesBuffers() void Renderer::ReleaseRenderTargetView() { - if(_pRenderTargetView) { + if (_pRenderTargetView) + { _pRenderTargetView->Release(); _pRenderTargetView = nullptr; } @@ -189,14 +225,16 @@ HRESULT Renderer::CreateRenderTargetView() // Create a render target view ID3D11Texture2D* pBackBuffer = nullptr; HRESULT hr = _pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("SwapChain::GetBuffer() failed - Error:" + std::to_string(hr)); return hr; } hr = _pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &_pRenderTargetView); pBackBuffer->Release(); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("D3DDevice::CreateRenderTargetView() failed - Error:" + std::to_string(hr)); return hr; } @@ -218,25 +256,29 @@ HRESULT Renderer::CreateNesBuffers() vp.TopLeftY = 0; _pDeviceContext->RSSetViewports(1, &vp); - _textureBuffer[0] = new uint8_t[_nesFrameWidth*_nesFrameHeight * 4]; - _textureBuffer[1] = new uint8_t[_nesFrameWidth*_nesFrameHeight * 4]; - memset(_textureBuffer[0], 0, _nesFrameWidth*_nesFrameHeight * 4); - memset(_textureBuffer[1], 0, _nesFrameWidth*_nesFrameHeight * 4); + _textureBuffer[0] = new uint8_t[_nesFrameWidth * _nesFrameHeight * 4]; + _textureBuffer[1] = new uint8_t[_nesFrameWidth * _nesFrameHeight * 4]; + memset(_textureBuffer[0], 0, _nesFrameWidth * _nesFrameHeight * 4); + memset(_textureBuffer[1], 0, _nesFrameWidth * _nesFrameHeight * 4); _pTexture = CreateTexture(_nesFrameWidth, _nesFrameHeight); - if(!_pTexture) { + if (!_pTexture) + { return S_FALSE; } _overlayTexture = CreateTexture(8, 8); - if(!_overlayTexture) { + if (!_overlayTexture) + { return S_FALSE; } _pTextureSrv = GetShaderResourceView(_pTexture); - if(!_pTextureSrv) { + if (!_pTextureSrv) + { return S_FALSE; } _pOverlaySrv = GetShaderResourceView(_overlayTexture); - if(!_pOverlaySrv) { + if (!_pOverlaySrv) + { return S_FALSE; } @@ -296,38 +338,49 @@ HRESULT Renderer::InitDevice() D3D_DRIVER_TYPE driverType = D3D_DRIVER_TYPE_NULL; D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_1; - for(UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++) { + for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++) + { driverType = driverTypes[driverTypeIndex]; featureLevel = D3D_FEATURE_LEVEL_11_1; - hr = D3D11CreateDeviceAndSwapChain(nullptr, driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &sd, &_pSwapChain, &_pd3dDevice, &featureLevel, &_pDeviceContext); + hr = D3D11CreateDeviceAndSwapChain(nullptr, driverType, nullptr, createDeviceFlags, featureLevels, + numFeatureLevels, D3D11_SDK_VERSION, &sd, &_pSwapChain, &_pd3dDevice, + &featureLevel, &_pDeviceContext); /*if(FAILED(hr)) { MessageManager::Log("D3D11CreateDeviceAndSwapChain() failed - Error:" + std::to_string(hr)); }*/ - if(hr == E_INVALIDARG) { + if (hr == E_INVALIDARG) + { // DirectX 11.0 platforms will not recognize D3D_FEATURE_LEVEL_11_1 so we need to retry without it featureLevel = D3D_FEATURE_LEVEL_11_0; - hr = D3D11CreateDeviceAndSwapChain(nullptr, driverType, nullptr, createDeviceFlags, &featureLevels[1], numFeatureLevels - 1, D3D11_SDK_VERSION, &sd, &_pSwapChain, &_pd3dDevice, &featureLevel, &_pDeviceContext); + hr = D3D11CreateDeviceAndSwapChain(nullptr, driverType, nullptr, createDeviceFlags, &featureLevels[1], + numFeatureLevels - 1, D3D11_SDK_VERSION, &sd, &_pSwapChain, &_pd3dDevice, + &featureLevel, &_pDeviceContext); } - if(SUCCEEDED(hr)) { + if (SUCCEEDED(hr)) + { break; } } - - if(FAILED(hr)) { + + if (FAILED(hr)) + { MessageManager::Log("D3D11CreateDeviceAndSwapChain() failed - Error:" + std::to_string(hr)); return hr; } - if(_fullscreen) { + if (_fullscreen) + { hr = _pSwapChain->SetFullscreenState(TRUE, NULL); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("SetFullscreenState(true) failed - Error:" + std::to_string(hr)); MessageManager::Log("Switching back to windowed mode"); hr = _pSwapChain->SetFullscreenState(FALSE, NULL); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("SetFullscreenState(false) failed - Error:" + std::to_string(hr)); return hr; } @@ -335,7 +388,8 @@ HRESULT Renderer::InitDevice() } hr = CreateRenderTargetView(); - if(FAILED(hr)) { + if (FAILED(hr)) + { return hr; } @@ -358,7 +412,8 @@ HRESULT Renderer::InitDevice() // Create the state using the device. hr = _pd3dDevice->CreateDepthStencilState(&depthDisabledStencilDesc, &_pDepthDisabledStencilState); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("D3DDevice::CreateDepthStencilState() failed - Error:" + std::to_string(hr)); return hr; } @@ -379,7 +434,8 @@ HRESULT Renderer::InitDevice() // Create the blend state using the description. hr = _pd3dDevice->CreateBlendState(&blendStateDescription, &_pAlphaEnableBlendingState); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("D3DDevice::CreateBlendState() failed - Error:" + std::to_string(hr)); return hr; } @@ -389,17 +445,19 @@ HRESULT Renderer::InitDevice() blendFactor[1] = 0.0f; blendFactor[2] = 0.0f; blendFactor[3] = 0.0f; - + _pDeviceContext->OMSetBlendState(_pAlphaEnableBlendingState, blendFactor, 0xffffffff); _pDeviceContext->OMSetDepthStencilState(_pDepthDisabledStencilState, 1); hr = CreateNesBuffers(); - if(FAILED(hr)) { + if (FAILED(hr)) + { return hr; } hr = CreateSamplerState(); - if(FAILED(hr)) { + if (FAILED(hr)) + { return hr; } @@ -425,7 +483,8 @@ HRESULT Renderer::CreateSamplerState() samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; HRESULT hr = _pd3dDevice->CreateSamplerState(&samplerDesc, &_samplerState); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("D3DDevice::CreateSamplerState() failed - Error:" + std::to_string(hr)); } @@ -452,7 +511,8 @@ ID3D11Texture2D* Renderer::CreateTexture(uint32_t width, uint32_t height) desc.MiscFlags = 0; HRESULT hr = _pd3dDevice->CreateTexture2D(&desc, nullptr, &texture); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("D3DDevice::CreateTexture() failed - Error:" + std::to_string(hr)); return nullptr; } @@ -461,9 +521,10 @@ ID3D11Texture2D* Renderer::CreateTexture(uint32_t width, uint32_t height) ID3D11ShaderResourceView* Renderer::GetShaderResourceView(ID3D11Texture2D* texture) { - ID3D11ShaderResourceView *shaderResourceView = nullptr; + ID3D11ShaderResourceView* shaderResourceView = nullptr; HRESULT hr = _pd3dDevice->CreateShaderResourceView(texture, nullptr, &shaderResourceView); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("D3DDevice::CreateShaderResourceView() failed - Error:" + std::to_string(hr)); return nullptr; } @@ -477,25 +538,29 @@ void Renderer::DrawString(string message, float x, float y, DirectX::FXMVECTOR c DrawString(textStr, x, y, color, scale, font); } -void Renderer::DrawString(std::wstring message, float x, float y, DirectX::FXMVECTOR color, float scale, SpriteFont* font) +void Renderer::DrawString(std::wstring message, float x, float y, DirectX::FXMVECTOR color, float scale, + SpriteFont* font) { - const wchar_t *text = message.c_str(); - if(font == nullptr) { + const wchar_t* text = message.c_str(); + if (font == nullptr) + { font = _font.get(); } - font->DrawString(_spriteBatch.get(), text, XMFLOAT2(x+_leftMargin, y+_topMargin), color, 0.0f, XMFLOAT2(0, 0), scale); + font->DrawString(_spriteBatch.get(), text, XMFLOAT2(x + _leftMargin, y + _topMargin), color, 0.0f, XMFLOAT2(0, 0), + scale); } -void Renderer::UpdateFrame(void *frameBuffer, uint32_t width, uint32_t height) +void Renderer::UpdateFrame(void* frameBuffer, uint32_t width, uint32_t height) { SetScreenSize(width, height); uint32_t bpp = 4; auto lock = _textureLock.AcquireSafe(); - if(_textureBuffer[0]) { + if (_textureBuffer[0]) + { //_textureBuffer[0] may be null if directx failed to initialize properly - memcpy(_textureBuffer[0], frameBuffer, width*height*bpp); + memcpy(_textureBuffer[0], frameBuffer, width * height * bpp); _needFlip = true; _frameChanged = true; } @@ -504,14 +569,16 @@ void Renderer::UpdateFrame(void *frameBuffer, uint32_t width, uint32_t height) void Renderer::DrawScreen() { //Swap buffers - emulator always writes to _textureBuffer[0], screen always draws _textureBuffer[1] - if(_needFlip) { + if (_needFlip) + { auto lock = _textureLock.AcquireSafe(); uint8_t* textureBuffer = _textureBuffer[0]; _textureBuffer[0] = _textureBuffer[1]; _textureBuffer[1] = textureBuffer; _needFlip = false; - if(_frameChanged) { + if (_frameChanged) + { _frameChanged = false; _renderedFrameCount++; } @@ -522,13 +589,15 @@ void Renderer::DrawScreen() uint32_t rowPitch = _nesFrameWidth * bpp; D3D11_MAPPED_SUBRESOURCE dd; HRESULT hr = _pDeviceContext->Map(_pTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &dd); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("DeviceContext::Map() failed - Error:" + std::to_string(hr)); return; } uint8_t* surfacePointer = (uint8_t*)dd.pData; uint8_t* videoBuffer = _textureBuffer[1]; - for(uint32_t i = 0, iMax = _nesFrameHeight; i < iMax; i++) { + for (uint32_t i = 0, iMax = _nesFrameHeight; i < iMax; i++) + { memcpy(surfacePointer, videoBuffer, rowPitch); videoBuffer += rowPitch; surfacePointer += dd.RowPitch; @@ -538,15 +607,15 @@ void Renderer::DrawScreen() RECT destRect; destRect.left = _leftMargin; destRect.top = _topMargin; - destRect.right = _screenWidth+_leftMargin; - destRect.bottom = _screenHeight+_topMargin; + destRect.right = _screenWidth + _leftMargin; + destRect.bottom = _screenHeight + _topMargin; _spriteBatch->Draw(_pTextureSrv, destRect); } void Renderer::DrawPauseScreen() { - const static XMVECTORF32 transparentBlue = { { { 1.0f, 0.6f, 0.0f, 0.66f } } }; + const static XMVECTORF32 transparentBlue = {{{1.0f, 0.6f, 0.0f, 0.66f}}}; DrawString("I", 15, 15, transparentBlue, 2.0f, _font.get()); DrawString("I", 32, 15, transparentBlue, 2.0f, _font.get()); } @@ -555,18 +624,22 @@ void Renderer::Render() { bool paused = _console->IsPaused(); - if(_noUpdateCount > 10 || _frameChanged || paused || IsMessageShown()) { + if (_noUpdateCount > 10 || _frameChanged || paused || IsMessageShown()) + { _noUpdateCount = 0; - + auto lock = _frameLock.AcquireSafe(); - if(_newFullscreen != _fullscreen) { + if (_newFullscreen != _fullscreen) + { SetScreenSize(_nesFrameWidth, _nesFrameHeight); } - if(_pDeviceContext == nullptr) { + if (_pDeviceContext == nullptr) + { //DirectX failed to initialize, try to init Reset(); - if(_pDeviceContext == nullptr) { + if (_pDeviceContext == nullptr) + { //Can't init, prevent crash return; } @@ -580,8 +653,10 @@ void Renderer::Render() //Draw screen DrawScreen(); - if(_console->IsRunning()) { - if(paused) { + if (_console->IsRunning()) + { + if (paused) + { DrawPauseScreen(); } DrawCounters(); @@ -595,23 +670,29 @@ void Renderer::Render() bool waitVSync = _console->GetSettings()->GetVideoConfig().VerticalSync; HRESULT hr = _pSwapChain->Present(waitVSync ? 1 : 0, 0); - if(FAILED(hr)) { + if (FAILED(hr)) + { MessageManager::Log("SwapChain::Present() failed - Error:" + std::to_string(hr)); - if(hr == DXGI_ERROR_DEVICE_REMOVED) { - MessageManager::Log("D3DDevice: GetDeviceRemovedReason: " + std::to_string(_pd3dDevice->GetDeviceRemovedReason())); + if (hr == DXGI_ERROR_DEVICE_REMOVED) + { + MessageManager::Log( + "D3DDevice: GetDeviceRemovedReason: " + std::to_string(_pd3dDevice->GetDeviceRemovedReason())); } MessageManager::Log("Trying to reset DX..."); Reset(); } - } else { + } + else + { _noUpdateCount++; } } void Renderer::DrawString(std::wstring message, int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t opacity) { - XMVECTORF32 color = { (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)opacity / 255.0f }; - _font->DrawString(_spriteBatch.get(), message.c_str(), XMFLOAT2((float)x+_leftMargin, (float)y+_topMargin), color); + XMVECTORF32 color = {(float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)opacity / 255.0f}; + _font->DrawString(_spriteBatch.get(), message.c_str(), XMFLOAT2((float)x + _leftMargin, (float)y + _topMargin), + color); } float Renderer::MeasureString(std::wstring text) @@ -624,4 +705,4 @@ float Renderer::MeasureString(std::wstring text) bool Renderer::ContainsCharacter(wchar_t character) { return _font->ContainsCharacter(character); -} \ No newline at end of file +} diff --git a/Windows/Renderer.h b/Windows/Renderer.h index 0d6e2bb..0959344 100644 --- a/Windows/Renderer.h +++ b/Windows/Renderer.h @@ -12,7 +12,8 @@ using namespace DirectX; class Console; -namespace DirectX { +namespace DirectX +{ class SpriteBatch; class SpriteFont; } @@ -20,33 +21,33 @@ namespace DirectX { class Renderer : public BaseRenderer, public IRenderingDevice { private: - HWND _hWnd = nullptr; + HWND _hWnd = nullptr; - ID3D11Device* _pd3dDevice = nullptr; - ID3D11DeviceContext* _pDeviceContext = nullptr; - IDXGISwapChain* _pSwapChain = nullptr; + ID3D11Device* _pd3dDevice = nullptr; + ID3D11DeviceContext* _pDeviceContext = nullptr; + IDXGISwapChain* _pSwapChain = nullptr; ID3D11RenderTargetView* _pRenderTargetView = nullptr; ID3D11DepthStencilState* _pDepthDisabledStencilState = nullptr; - ID3D11BlendState* _pAlphaEnableBlendingState = nullptr; + ID3D11BlendState* _pAlphaEnableBlendingState = nullptr; - ID3D11SamplerState* _samplerState = nullptr; - - atomic _needFlip = false; - uint8_t* _textureBuffer[2] = { nullptr, nullptr }; - ID3D11Texture2D* _pTexture = nullptr; - ID3D11ShaderResourceView* _pTextureSrv = nullptr; - ID3D11Texture2D* _overlayTexture = nullptr; - ID3D11ShaderResourceView* _pOverlaySrv = nullptr; + ID3D11SamplerState* _samplerState = nullptr; - bool _frameChanged = true; - SimpleLock _frameLock; - SimpleLock _textureLock; + atomic _needFlip = false; + uint8_t* _textureBuffer[2] = {nullptr, nullptr}; + ID3D11Texture2D* _pTexture = nullptr; + ID3D11ShaderResourceView* _pTextureSrv = nullptr; + ID3D11Texture2D* _overlayTexture = nullptr; + ID3D11ShaderResourceView* _pOverlaySrv = nullptr; + + bool _frameChanged = true; + SimpleLock _frameLock; + SimpleLock _textureLock; bool _useBilinearInterpolation = false; - unique_ptr _font; - unique_ptr _largeFont; - + unique_ptr _font; + unique_ptr _largeFont; + unique_ptr _spriteBatch; const uint32_t _bytesPerPixel = 4; @@ -77,9 +78,10 @@ private: ID3D11ShaderResourceView* GetShaderResourceView(ID3D11Texture2D* texture); void DrawScreen(); void DrawPauseScreen(); - + void DrawString(string message, float x, float y, DirectX::FXMVECTOR color, float scale, SpriteFont* font = nullptr); - void DrawString(std::wstring message, float x, float y, DirectX::FXMVECTOR color, float scale, SpriteFont* font = nullptr); + void DrawString(std::wstring message, float x, float y, DirectX::FXMVECTOR color, float scale, + SpriteFont* font = nullptr); void DrawString(std::wstring message, int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t opacity); float MeasureString(std::wstring text); @@ -100,5 +102,5 @@ public: void Reset(); void Render(); - void UpdateFrame(void *frameBuffer, uint32_t width, uint32_t height); -}; \ No newline at end of file + void UpdateFrame(void* frameBuffer, uint32_t width, uint32_t height); +}; diff --git a/Windows/SoundManager.cpp b/Windows/SoundManager.cpp index 53528a1..1d064c1 100644 --- a/Windows/SoundManager.cpp +++ b/Windows/SoundManager.cpp @@ -15,16 +15,20 @@ SoundManager::SoundManager(shared_ptr console, HWND hwnd) memset(&_audioDeviceID, 0, sizeof(_audioDeviceID)); - if(InitializeDirectSound(44100, true)) { + if (InitializeDirectSound(44100, true)) + { _console->GetSoundMixer()->RegisterAudioDevice(this); - } else { + } + else + { MessageManager::DisplayMessage("Error", "CouldNotInitializeAudioSystem"); } } SoundManager::~SoundManager() { - if(_console && _console->GetSoundMixer()) { + if (_console && _console->GetSoundMixer()) + { _console->GetSoundMixer()->RegisterAudioDevice(nullptr); } Release(); @@ -32,13 +36,16 @@ SoundManager::~SoundManager() bool CALLBACK SoundManager::DirectSoundEnumProc(LPGUID lpGUID, LPCWSTR lpszDesc, LPCSTR lpszDrvName, LPVOID lpContext) { - vector *devices = (vector*)lpContext; + vector* devices = (vector*)lpContext; SoundDeviceInfo deviceInfo; deviceInfo.description = utf8::utf8::encode(lpszDesc); - if(lpGUID != nullptr) { + if (lpGUID != nullptr) + { memcpy((void*)&deviceInfo.guid, lpGUID, 16); - } else { + } + else + { memset((void*)&deviceInfo.guid, 0, 16); } devices->push_back(deviceInfo); @@ -56,7 +63,8 @@ vector SoundManager::GetAvailableDeviceInfo() string SoundManager::GetAvailableDevices() { string deviceString; - for(SoundDeviceInfo device : GetAvailableDeviceInfo()) { + for (SoundDeviceInfo device : GetAvailableDeviceInfo()) + { deviceString += device.description + "||"s; } return deviceString; @@ -64,11 +72,15 @@ string SoundManager::GetAvailableDevices() void SoundManager::SetAudioDevice(string deviceName) { - if(_audioDeviceName != deviceName) { - for(SoundDeviceInfo device : GetAvailableDeviceInfo()) { - if(device.description.compare(deviceName) == 0) { + if (_audioDeviceName != deviceName) + { + for (SoundDeviceInfo device : GetAvailableDeviceInfo()) + { + if (device.description.compare(deviceName) == 0) + { _audioDeviceName = deviceName; - if(memcmp(&_audioDeviceID, &device.guid, 16) != 0) { + if (memcmp(&_audioDeviceID, &device.guid, 16) != 0) + { memcpy(&_audioDeviceID, &device.guid, 16); _needReset = true; } @@ -83,17 +95,19 @@ bool SoundManager::InitializeDirectSound(uint32_t sampleRate, bool isStereo) HRESULT result; DSBUFFERDESC bufferDesc; WAVEFORMATEX waveFormat; - + // Initialize the direct sound interface pointer for the default sound device. result = DirectSoundCreate8(&_audioDeviceID, &_directSound, NULL); - if(FAILED(result)) { + if (FAILED(result)) + { MessageManager::Log("[Audio] Failed to create direct sound device."); return false; } // Set the cooperative level to priority so the format of the primary sound buffer can be modified. result = _directSound->SetCooperativeLevel(_hWnd, DSSCL_PRIORITY); - if(FAILED(result)) { + if (FAILED(result)) + { MessageManager::Log("[Audio] Failed to set cooperative level."); return false; } @@ -108,7 +122,8 @@ bool SoundManager::InitializeDirectSound(uint32_t sampleRate, bool isStereo) // Get control of the primary sound buffer on the default sound device. result = _directSound->CreateSoundBuffer(&bufferDesc, &_primaryBuffer, NULL); - if(FAILED(result)) { + if (FAILED(result)) + { MessageManager::Log("[Audio] Failed to create primary sound buffer."); return false; } @@ -127,7 +142,8 @@ bool SoundManager::InitializeDirectSound(uint32_t sampleRate, bool isStereo) // Set the primary buffer to be the wave format specified. result = _primaryBuffer->SetFormat(&waveFormat); - if(FAILED(result)) { + if (FAILED(result)) + { MessageManager::Log("[Audio] Failed to set the sound format."); return false; } @@ -138,7 +154,8 @@ bool SoundManager::InitializeDirectSound(uint32_t sampleRate, bool isStereo) // Set the buffer description of the secondary sound buffer that the wave file will be loaded onto. bufferDesc.dwSize = sizeof(DSBUFFERDESC); - bufferDesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCSOFTWARE | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY; + bufferDesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | + DSBCAPS_LOCSOFTWARE | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY; bufferDesc.dwBufferBytes = _bufferSize; bufferDesc.dwReserved = 0; bufferDesc.lpwfxFormat = &waveFormat; @@ -147,21 +164,24 @@ bool SoundManager::InitializeDirectSound(uint32_t sampleRate, bool isStereo) // Create a temporary sound buffer with the specific buffer settings. IDirectSoundBuffer* tempBuffer; result = _directSound->CreateSoundBuffer(&bufferDesc, &tempBuffer, NULL); - if(FAILED(result)) { + if (FAILED(result)) + { MessageManager::Log("[Audio] Failed to create temporary sound buffer."); return false; } // Test the buffer format against the direct sound 8 interface and create the secondary buffer. result = tempBuffer->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)&_secondaryBuffer); - if(FAILED(result)) { + if (FAILED(result)) + { MessageManager::Log("[Audio] Failed to obtain secondary sound buffer."); return false; } // Set volume of the buffer to 100%. result = _secondaryBuffer->SetVolume(DSBVOLUME_MAX); - if(FAILED(result)) { + if (FAILED(result)) + { MessageManager::Log("[Audio] Failed to set volume of the secondary sound buffer."); return false; } @@ -180,17 +200,20 @@ void SoundManager::Release() _needReset = false; _lastWriteOffset = 0; - if(_secondaryBuffer) { + if (_secondaryBuffer) + { _secondaryBuffer->Release(); _secondaryBuffer = nullptr; } - if(_primaryBuffer) { + if (_primaryBuffer) + { _primaryBuffer->Release(); _primaryBuffer = nullptr; } - - if(_directSound) { + + if (_directSound) + { _directSound->Release(); _directSound = nullptr; } @@ -208,18 +231,20 @@ void SoundManager::ClearSecondaryBuffer() _lastWriteOffset = 0; } -void SoundManager::CopyToSecondaryBuffer(uint8_t *data, uint32_t size) +void SoundManager::CopyToSecondaryBuffer(uint8_t* data, uint32_t size) { uint8_t* bufferPtrA; uint8_t* bufferPtrB; DWORD bufferASize; DWORD bufferBSize; - _secondaryBuffer->Lock(_lastWriteOffset, size, (void**)&bufferPtrA, (DWORD*)&bufferASize, (void**)&bufferPtrB, (DWORD*)&bufferBSize, 0); + _secondaryBuffer->Lock(_lastWriteOffset, size, (void**)&bufferPtrA, (DWORD*)&bufferASize, (void**)&bufferPtrB, + (DWORD*)&bufferBSize, 0); _lastWriteOffset = (_lastWriteOffset + size) % _bufferSize; memcpy(bufferPtrA, data, bufferASize); - if(bufferPtrB && bufferBSize > 0) { + if (bufferPtrB && bufferBSize > 0) + { memcpy(bufferPtrB, data + bufferASize, bufferBSize); } @@ -228,7 +253,8 @@ void SoundManager::CopyToSecondaryBuffer(uint8_t *data, uint32_t size) void SoundManager::Pause() { - if(_secondaryBuffer) { + if (_secondaryBuffer) + { _secondaryBuffer->Stop(); } _playing = false; @@ -236,7 +262,8 @@ void SoundManager::Pause() void SoundManager::Stop() { - if(_secondaryBuffer) { + if (_secondaryBuffer) + { _secondaryBuffer->Stop(); ClearSecondaryBuffer(); } @@ -247,7 +274,8 @@ void SoundManager::Stop() void SoundManager::Play() { - if(_secondaryBuffer) { + if (_secondaryBuffer) + { _secondaryBuffer->Play(0, 0, DSBPLAY_LOOPING); _playing = true; } @@ -256,9 +284,12 @@ void SoundManager::Play() void SoundManager::ValidateWriteCursor(DWORD safeWriteCursor) { int32_t writeGap = _lastWriteOffset - safeWriteCursor; - if(writeGap < -10000) { + if (writeGap < -10000) + { writeGap += _bufferSize; - } else if(writeGap < 0) { + } + else if (writeGap < 0) + { _bufferUnderrunEventCount++; _lastWriteOffset = safeWriteCursor; } @@ -273,7 +304,8 @@ void SoundManager::ProcessEndOfFrame() uint32_t emulationSpeed = _console->GetSettings()->GetEmulationSpeed(); uint32_t targetRate = _sampleRate; - if(emulationSpeed > 0 && emulationSpeed < 100) { + if (emulationSpeed > 0 && emulationSpeed < 100) + { //Slow down playback when playing at less than 100% targetRate = (uint32_t)(targetRate * ((double)emulationSpeed / 100.0)); } @@ -284,17 +316,20 @@ void SoundManager::ProcessEndOfFrame() AudioConfig cfg = _console->GetSettings()->GetAudioConfig(); SetAudioDevice(cfg.AudioDevice); - if(_averageLatency > 0 && emulationSpeed <= 100 && emulationSpeed > 0 && std::abs(_averageLatency - cfg.AudioLatency) > 50) { + if (_averageLatency > 0 && emulationSpeed <= 100 && emulationSpeed > 0 && std::abs( + _averageLatency - cfg.AudioLatency) > 50) + { //Latency is way off (over 50ms gap), stop audio & start again Stop(); } } -void SoundManager::PlayBuffer(int16_t *soundBuffer, uint32_t sampleCount, uint32_t sampleRate, bool isStereo) +void SoundManager::PlayBuffer(int16_t* soundBuffer, uint32_t sampleCount, uint32_t sampleRate, bool isStereo) { uint32_t bytesPerSample = 2 * (isStereo ? 2 : 1); uint32_t latency = _console->GetSettings()->GetAudioConfig().AudioLatency; - if(_sampleRate != sampleRate || _isStereo != isStereo || _needReset || latency != _previousLatency) { + if (_sampleRate != sampleRate || _isStereo != isStereo || _needReset || latency != _previousLatency) + { _previousLatency = latency; Release(); InitializeDirectSound(sampleRate, isStereo); @@ -307,11 +342,13 @@ void SoundManager::PlayBuffer(int16_t *soundBuffer, uint32_t sampleCount, uint32 uint32_t soundBufferSize = sampleCount * bytesPerSample; CopyToSecondaryBuffer((uint8_t*)soundBuffer, soundBufferSize); - - if(!_playing) { + + if (!_playing) + { DWORD byteLatency = (int32_t)((float)(sampleRate * latency) / 1000.0f * bytesPerSample); - if(_lastWriteOffset >= byteLatency / 2) { + if (_lastWriteOffset >= byteLatency / 2) + { Play(); } } -} \ No newline at end of file +} diff --git a/Windows/SoundManager.h b/Windows/SoundManager.h index 3888b1a..c695ab1 100644 --- a/Windows/SoundManager.h +++ b/Windows/SoundManager.h @@ -19,8 +19,8 @@ public: void Release(); void ProcessEndOfFrame(); - void PlayBuffer(int16_t *soundBuffer, uint32_t bufferSize, uint32_t sampleRate, bool isStereo); - void Play(); + void PlayBuffer(int16_t* soundBuffer, uint32_t bufferSize, uint32_t sampleRate, bool isStereo); + void Play(); void Pause(); void Stop(); @@ -32,7 +32,7 @@ private: static bool CALLBACK DirectSoundEnumProc(LPGUID lpGUID, LPCWSTR lpszDesc, LPCSTR lpszDrvName, LPVOID lpContext); bool InitializeDirectSound(uint32_t sampleRate, bool isStereo); void ClearSecondaryBuffer(); - void CopyToSecondaryBuffer(uint8_t *data, uint32_t size); + void CopyToSecondaryBuffer(uint8_t* data, uint32_t size); void ValidateWriteCursor(DWORD safeWriteCursor); private: diff --git a/Windows/WindowsKeyManager.cpp b/Windows/WindowsKeyManager.cpp index 2abd719..f25417f 100644 --- a/Windows/WindowsKeyManager.cpp +++ b/Windows/WindowsKeyManager.cpp @@ -4,199 +4,207 @@ static vector _keyDefinitions = { //{ "VK_LBUTTON", 0x01, "Left mouse button", "" }, //{ "VK_RBUTTON", 0x02, "Right mouse button", "" }, - { "VK_CANCEL", 0x03, "Control-break processing", "" }, + {"VK_CANCEL", 0x03, "Control-break processing", ""}, //{ "VK_MBUTTON", 0x04, "Middle mouse button (three-button mouse)", "" }, //{ "VK_XBUTTON1", 0x05, "X1 mouse button", "" }, //{ "VK_XBUTTON2", 0x06, "X2 mouse button", "" }, - { "-", 0x07, "Undefined", "" }, - { "VK_BACK", 0x08, "Backspace", "" }, - { "VK_TAB", 0x09, "Tab", "" }, + {"-", 0x07, "Undefined", ""}, + {"VK_BACK", 0x08, "Backspace", ""}, + {"VK_TAB", 0x09, "Tab", ""}, //{ "-", 0x0A - 0B, "Reserved", "" }, - { "VK_CLEAR", 0x0C, "Numpad 5", "" }, - { "VK_RETURN", 0x0D, "Enter", "Numpad Enter" }, + {"VK_CLEAR", 0x0C, "Numpad 5", ""}, + {"VK_RETURN", 0x0D, "Enter", "Numpad Enter"}, //{ "-", 0x0E - 0F, "Undefined", "" }, - { "VK_SHIFT", 0x10, "Shift", "" }, - { "VK_CONTROL", 0x11, "Ctrl", "" }, - { "VK_MENU", 0x12, "Alt", "" }, - { "VK_PAUSE", 0x13, "Pause", "" }, - { "VK_CAPITAL", 0x14, "Caps Lock", "" }, - { "VK_KANA", 0x15, "IME Kana mode", "" }, - { "VK_HANGUEL", 0x15, "IME Hanguel mode", "" }, - { "VK_HANGUL", 0x15, "IME Hangul mode", "" }, + {"VK_SHIFT", 0x10, "Shift", ""}, + {"VK_CONTROL", 0x11, "Ctrl", ""}, + {"VK_MENU", 0x12, "Alt", ""}, + {"VK_PAUSE", 0x13, "Pause", ""}, + {"VK_CAPITAL", 0x14, "Caps Lock", ""}, + {"VK_KANA", 0x15, "IME Kana mode", ""}, + {"VK_HANGUEL", 0x15, "IME Hanguel mode", ""}, + {"VK_HANGUL", 0x15, "IME Hangul mode", ""}, //{ "-", 0x16, "Undefined", "" }, - { "VK_JUNJA", 0x17, "IME Junja mode", "" }, - { "VK_FINAL", 0x18, "IME final mode", "" }, - { "VK_HANJA", 0x19, "IME Hanja mode", "" }, - { "VK_KANJI", 0x19, "IME Kanji mode", "" }, + {"VK_JUNJA", 0x17, "IME Junja mode", ""}, + {"VK_FINAL", 0x18, "IME final mode", ""}, + {"VK_HANJA", 0x19, "IME Hanja mode", ""}, + {"VK_KANJI", 0x19, "IME Kanji mode", ""}, //{ "-", 0x1A, "Undefined", "" }, - { "VK_ESCAPE", 0x1B, "Esc", "" }, - { "VK_CONVERT", 0x1C, "IME convert", "" }, - { "VK_NONCONVERT", 0x1D, "IME nonconvert", "" }, - { "VK_ACCEPT", 0x1E, "IME accept", "" }, - { "VK_MODECHANGE", 0x1F, "IME mode change request", "" }, - { "VK_SPACE", 0x20, "Spacebar", "" }, - { "VK_PRIOR", 0x21, "Numpad 9", "Page Up" }, - { "VK_NEXT", 0x22, "Numpad 3", "Page Down" }, - { "VK_END", 0x23, "Numpad 1", "End" }, - { "VK_HOME", 0x24, "Numpad 7", "Home" }, - { "VK_LEFT", 0x25, "Numpad 4", "Left Arrow" }, - { "VK_UP", 0x26, "Numpad 8", "Up Arrow" }, - { "VK_RIGHT", 0x27, "Numpad 6", "Right Arrow" }, - { "VK_DOWN", 0x28, "Numpad 2", "Down Arrow" }, - { "VK_SELECT", 0x29, "Select", "" }, - { "VK_PRINT", 0x2A, "Print", "" }, - { "VK_EXECUTE", 0x2B, "Execute", "" }, - { "VK_SNAPSHOT", 0x2C, "Print Screen", "" }, - { "VK_INSERT", 0x2D, "Numpad 0", "Insert" }, - { "VK_DELETE", 0x2E, "Numpad .", "Delete" }, - { "VK_HELP", 0x2F, "Help", "" }, - { "0", 0x30, "0", "" }, - { "1", 0x31, "1", "" }, - { "2", 0x32, "2", "" }, - { "3", 0x33, "3", "" }, - { "4", 0x34, "4", "" }, - { "5", 0x35, "5", "" }, - { "6", 0x36, "6", "" }, - { "7", 0x37, "7", "" }, - { "8", 0x38, "8", "" }, - { "9", 0x39, "9", "" }, + {"VK_ESCAPE", 0x1B, "Esc", ""}, + {"VK_CONVERT", 0x1C, "IME convert", ""}, + {"VK_NONCONVERT", 0x1D, "IME nonconvert", ""}, + {"VK_ACCEPT", 0x1E, "IME accept", ""}, + {"VK_MODECHANGE", 0x1F, "IME mode change request", ""}, + {"VK_SPACE", 0x20, "Spacebar", ""}, + {"VK_PRIOR", 0x21, "Numpad 9", "Page Up"}, + {"VK_NEXT", 0x22, "Numpad 3", "Page Down"}, + {"VK_END", 0x23, "Numpad 1", "End"}, + {"VK_HOME", 0x24, "Numpad 7", "Home"}, + {"VK_LEFT", 0x25, "Numpad 4", "Left Arrow"}, + {"VK_UP", 0x26, "Numpad 8", "Up Arrow"}, + {"VK_RIGHT", 0x27, "Numpad 6", "Right Arrow"}, + {"VK_DOWN", 0x28, "Numpad 2", "Down Arrow"}, + {"VK_SELECT", 0x29, "Select", ""}, + {"VK_PRINT", 0x2A, "Print", ""}, + {"VK_EXECUTE", 0x2B, "Execute", ""}, + {"VK_SNAPSHOT", 0x2C, "Print Screen", ""}, + {"VK_INSERT", 0x2D, "Numpad 0", "Insert"}, + {"VK_DELETE", 0x2E, "Numpad .", "Delete"}, + {"VK_HELP", 0x2F, "Help", ""}, + {"0", 0x30, "0", ""}, + {"1", 0x31, "1", ""}, + {"2", 0x32, "2", ""}, + {"3", 0x33, "3", ""}, + {"4", 0x34, "4", ""}, + {"5", 0x35, "5", ""}, + {"6", 0x36, "6", ""}, + {"7", 0x37, "7", ""}, + {"8", 0x38, "8", ""}, + {"9", 0x39, "9", ""}, //{ "undefined", 0x3A - 40, "undefined", "" }, - { "A", 0x41, "A", "" }, - { "B", 0x42, "B", "" }, - { "C", 0x43, "C", "" }, - { "D", 0x44, "D", "" }, - { "E", 0x45, "E", "" }, - { "F", 0x46, "F", "" }, - { "G", 0x47, "G", "" }, - { "H", 0x48, "H", "" }, - { "I", 0x49, "I", "" }, - { "J", 0x4A, "J", "" }, - { "K", 0x4B, "K", "" }, - { "L", 0x4C, "L", "" }, - { "M", 0x4D, "M", "" }, - { "N", 0x4E, "N", "" }, - { "O", 0x4F, "O", "" }, - { "P", 0x50, "P", "" }, - { "Q", 0x51, "Q", "" }, - { "R", 0x52, "R", "" }, - { "S", 0x53, "S", "" }, - { "T", 0x54, "T", "" }, - { "U", 0x55, "U", "" }, - { "V", 0x56, "V", "" }, - { "W", 0x57, "W", "" }, - { "X", 0x58, "X", "" }, - { "Y", 0x59, "Y", "" }, - { "Z", 0x5A, "Z", "" }, - { "VK_LWIN", 0x5B, "Left Windows", "" }, - { "VK_RWIN", 0x5C, "Right Windows", "" }, - { "VK_APPS", 0x5D, "Applications Key", "" }, + {"A", 0x41, "A", ""}, + {"B", 0x42, "B", ""}, + {"C", 0x43, "C", ""}, + {"D", 0x44, "D", ""}, + {"E", 0x45, "E", ""}, + {"F", 0x46, "F", ""}, + {"G", 0x47, "G", ""}, + {"H", 0x48, "H", ""}, + {"I", 0x49, "I", ""}, + {"J", 0x4A, "J", ""}, + {"K", 0x4B, "K", ""}, + {"L", 0x4C, "L", ""}, + {"M", 0x4D, "M", ""}, + {"N", 0x4E, "N", ""}, + {"O", 0x4F, "O", ""}, + {"P", 0x50, "P", ""}, + {"Q", 0x51, "Q", ""}, + {"R", 0x52, "R", ""}, + {"S", 0x53, "S", ""}, + {"T", 0x54, "T", ""}, + {"U", 0x55, "U", ""}, + {"V", 0x56, "V", ""}, + {"W", 0x57, "W", ""}, + {"X", 0x58, "X", ""}, + {"Y", 0x59, "Y", ""}, + {"Z", 0x5A, "Z", ""}, + {"VK_LWIN", 0x5B, "Left Windows", ""}, + {"VK_RWIN", 0x5C, "Right Windows", ""}, + {"VK_APPS", 0x5D, "Applications Key", ""}, //{ "-", 0x5E, "Reserved", "" }, - { "VK_SLEEP", 0x5F, "Computer Sleep", "" }, - { "VK_NUMPAD0", 0x60, "Keypad 0", "" }, - { "VK_NUMPAD1", 0x61, "Keypad 1", "" }, - { "VK_NUMPAD2", 0x62, "Keypad 2", "" }, - { "VK_NUMPAD3", 0x63, "Keypad 3", "" }, - { "VK_NUMPAD4", 0x64, "Keypad 4", "" }, - { "VK_NUMPAD5", 0x65, "Keypad 5", "" }, - { "VK_NUMPAD6", 0x66, "Keypad 6", "" }, - { "VK_NUMPAD7", 0x67, "Keypad 7", "" }, - { "VK_NUMPAD8", 0x68, "Keypad 8", "" }, - { "VK_NUMPAD9", 0x69, "Keypad 9", "" }, - { "VK_MULTIPLY", 0x6A, "Numpad *", "" }, - { "VK_ADD", 0x6B, "Numpad +", "" }, - { "VK_SEPARATOR", 0x6C, "Separator", "" }, - { "VK_SUBTRACT", 0x6D, "Numpad -", "" }, - { "VK_DECIMAL", 0x6E, "Decimal", "" }, - { "VK_DIVIDE", 0x6F, "Numpad /", "" }, - { "VK_F1", 0x70, "F1", "" }, - { "VK_F2", 0x71, "F2", "" }, - { "VK_F3", 0x72, "F3", "" }, - { "VK_F4", 0x73, "F4", "" }, - { "VK_F5", 0x74, "F5", "" }, - { "VK_F6", 0x75, "F6", "" }, - { "VK_F7", 0x76, "F7", "" }, - { "VK_F8", 0x77, "F8", "" }, - { "VK_F9", 0x78, "F9", "" }, - { "VK_F10", 0x79, "F10", "" }, - { "VK_F11", 0x7A, "F11", "" }, - { "VK_F12", 0x7B, "F12", "" }, - { "VK_F13", 0x7C, "F13", "" }, - { "VK_F14", 0x7D, "F14", "" }, - { "VK_F15", 0x7E, "F15", "" }, - { "VK_F16", 0x7F, "F16", "" }, - { "VK_F17", 0x80, "F17", "" }, - { "VK_F18", 0x81, "F18", "" }, - { "VK_F19", 0x82, "F19", "" }, - { "VK_F20", 0x83, "F20", "" }, - { "VK_F21", 0x84, "F21", "" }, - { "VK_F22", 0x85, "F22", "" }, - { "VK_F23", 0x86, "F23", "" }, - { "VK_F24", 0x87, "F24", "" }, + {"VK_SLEEP", 0x5F, "Computer Sleep", ""}, + {"VK_NUMPAD0", 0x60, "Keypad 0", ""}, + {"VK_NUMPAD1", 0x61, "Keypad 1", ""}, + {"VK_NUMPAD2", 0x62, "Keypad 2", ""}, + {"VK_NUMPAD3", 0x63, "Keypad 3", ""}, + {"VK_NUMPAD4", 0x64, "Keypad 4", ""}, + {"VK_NUMPAD5", 0x65, "Keypad 5", ""}, + {"VK_NUMPAD6", 0x66, "Keypad 6", ""}, + {"VK_NUMPAD7", 0x67, "Keypad 7", ""}, + {"VK_NUMPAD8", 0x68, "Keypad 8", ""}, + {"VK_NUMPAD9", 0x69, "Keypad 9", ""}, + {"VK_MULTIPLY", 0x6A, "Numpad *", ""}, + {"VK_ADD", 0x6B, "Numpad +", ""}, + {"VK_SEPARATOR", 0x6C, "Separator", ""}, + {"VK_SUBTRACT", 0x6D, "Numpad -", ""}, + {"VK_DECIMAL", 0x6E, "Decimal", ""}, + {"VK_DIVIDE", 0x6F, "Numpad /", ""}, + {"VK_F1", 0x70, "F1", ""}, + {"VK_F2", 0x71, "F2", ""}, + {"VK_F3", 0x72, "F3", ""}, + {"VK_F4", 0x73, "F4", ""}, + {"VK_F5", 0x74, "F5", ""}, + {"VK_F6", 0x75, "F6", ""}, + {"VK_F7", 0x76, "F7", ""}, + {"VK_F8", 0x77, "F8", ""}, + {"VK_F9", 0x78, "F9", ""}, + {"VK_F10", 0x79, "F10", ""}, + {"VK_F11", 0x7A, "F11", ""}, + {"VK_F12", 0x7B, "F12", ""}, + {"VK_F13", 0x7C, "F13", ""}, + {"VK_F14", 0x7D, "F14", ""}, + {"VK_F15", 0x7E, "F15", ""}, + {"VK_F16", 0x7F, "F16", ""}, + {"VK_F17", 0x80, "F17", ""}, + {"VK_F18", 0x81, "F18", ""}, + {"VK_F19", 0x82, "F19", ""}, + {"VK_F20", 0x83, "F20", ""}, + {"VK_F21", 0x84, "F21", ""}, + {"VK_F22", 0x85, "F22", ""}, + {"VK_F23", 0x86, "F23", ""}, + {"VK_F24", 0x87, "F24", ""}, //{ "-", 0x88 - 8F, "Unassigned", "" }, - { "VK_NUMLOCK", 0x90, "Pause", "Num Lock" }, - { "VK_SCROLL", 0x91, "Scroll Lock", "" }, + {"VK_NUMLOCK", 0x90, "Pause", "Num Lock"}, + {"VK_SCROLL", 0x91, "Scroll Lock", ""}, //{"-", 0x92-96,"OEM specific"}, //{ "-", 0x97 - 9F, "Unassigned", "" }, - { "VK_LSHIFT", 0xA0, "Left Shift", "" }, - { "VK_RSHIFT", 0xA1, "Right Shift", "" }, - { "VK_LCONTROL", 0xA2, "Left Control", "" }, - { "VK_RCONTROL", 0xA3, "Right Control", "" }, - { "VK_LMENU", 0xA4, "Left Menu", "" }, - { "VK_RMENU", 0xA5, "Right Menu", "" }, - { "VK_BROWSER_BACK", 0xA6, "Browser Back", "" }, - { "VK_BROWSER_FORWARD", 0xA7, "Browser Forward", "" }, - { "VK_BROWSER_REFRESH", 0xA8, "Browser Refresh", "" }, - { "VK_BROWSER_STOP", 0xA9, "Browser Stop", "" }, - { "VK_BROWSER_SEARCH", 0xAA, "Browser Search", "" }, - { "VK_BROWSER_FAVORITES", 0xAB, "Browser Favorites", "" }, - { "VK_BROWSER_HOME", 0xAC, "Browser Start and Home", "" }, - { "VK_VOLUME_MUTE", 0xAD, "Volume Mute", "" }, - { "VK_VOLUME_DOWN", 0xAE, "Volume Down", "" }, - { "VK_VOLUME_UP", 0xAF, "Volume Up", "" }, - { "VK_MEDIA_NEXT_TRACK", 0xB0, "Next Track", "" }, - { "VK_MEDIA_PREV_TRACK", 0xB1, "Previous Track", "" }, - { "VK_MEDIA_STOP", 0xB2, "Stop Media", "" }, - { "VK_MEDIA_PLAY_PAUSE", 0xB3, "Play/Pause Media", "" }, - { "VK_LAUNCH_MAIL", 0xB4, "Start Mail", "" }, - { "VK_LAUNCH_MEDIA_SELECT", 0xB5, "Select Media", "" }, - { "VK_LAUNCH_APP1", 0xB6, "Start Application 1", "" }, - { "VK_LAUNCH_APP2", 0xB7, "Start Application 2", "" }, + {"VK_LSHIFT", 0xA0, "Left Shift", ""}, + {"VK_RSHIFT", 0xA1, "Right Shift", ""}, + {"VK_LCONTROL", 0xA2, "Left Control", ""}, + {"VK_RCONTROL", 0xA3, "Right Control", ""}, + {"VK_LMENU", 0xA4, "Left Menu", ""}, + {"VK_RMENU", 0xA5, "Right Menu", ""}, + {"VK_BROWSER_BACK", 0xA6, "Browser Back", ""}, + {"VK_BROWSER_FORWARD", 0xA7, "Browser Forward", ""}, + {"VK_BROWSER_REFRESH", 0xA8, "Browser Refresh", ""}, + {"VK_BROWSER_STOP", 0xA9, "Browser Stop", ""}, + {"VK_BROWSER_SEARCH", 0xAA, "Browser Search", ""}, + {"VK_BROWSER_FAVORITES", 0xAB, "Browser Favorites", ""}, + {"VK_BROWSER_HOME", 0xAC, "Browser Start and Home", ""}, + {"VK_VOLUME_MUTE", 0xAD, "Volume Mute", ""}, + {"VK_VOLUME_DOWN", 0xAE, "Volume Down", ""}, + {"VK_VOLUME_UP", 0xAF, "Volume Up", ""}, + {"VK_MEDIA_NEXT_TRACK", 0xB0, "Next Track", ""}, + {"VK_MEDIA_PREV_TRACK", 0xB1, "Previous Track", ""}, + {"VK_MEDIA_STOP", 0xB2, "Stop Media", ""}, + {"VK_MEDIA_PLAY_PAUSE", 0xB3, "Play/Pause Media", ""}, + {"VK_LAUNCH_MAIL", 0xB4, "Start Mail", ""}, + {"VK_LAUNCH_MEDIA_SELECT", 0xB5, "Select Media", ""}, + {"VK_LAUNCH_APP1", 0xB6, "Start Application 1", ""}, + {"VK_LAUNCH_APP2", 0xB7, "Start Application 2", ""}, //{ "-", 0xB8 - B9, "Reserved", "" }, - { "VK_OEM_1", 0xBA, ";", "" }, - { "VK_OEM_PLUS", 0xBB, "=", "" }, - { "VK_OEM_COMMA", 0xBC, ",", "" }, - { "VK_OEM_MINUS", 0xBD, "-", "" }, - { "VK_OEM_PERIOD", 0xBE, ".", "" }, - { "VK_OEM_2", 0xBF, "/", "Numpad /" }, - { "VK_OEM_3", 0xC0, "`", "" }, + {"VK_OEM_1", 0xBA, ";", ""}, + {"VK_OEM_PLUS", 0xBB, "=", ""}, + {"VK_OEM_COMMA", 0xBC, ",", ""}, + {"VK_OEM_MINUS", 0xBD, "-", ""}, + {"VK_OEM_PERIOD", 0xBE, ".", ""}, + {"VK_OEM_2", 0xBF, "/", "Numpad /"}, + {"VK_OEM_3", 0xC0, "`", ""}, //{ "-", 0xC1 - D7, "Reserved", "" }, //{ "-", 0xD8 - DA, "Unassigned", "" }, - { "VK_OEM_4", 0xDB, "[", "" }, - { "VK_OEM_5", 0xDC, "\\", "" }, - { "VK_OEM_6", 0xDD, "]", "" }, - { "VK_OEM_7", 0xDE, "'", "" }, - { "VK_OEM_8", 0xDF, "Used for miscellaneous characters; it can vary by keyboard.", "" }, + {"VK_OEM_4", 0xDB, "[", ""}, + {"VK_OEM_5", 0xDC, "\\", ""}, + {"VK_OEM_6", 0xDD, "]", ""}, + {"VK_OEM_7", 0xDE, "'", ""}, + {"VK_OEM_8", 0xDF, "Used for miscellaneous characters; it can vary by keyboard.", ""}, //{ "-", 0xE0, "Reserved", "" }, //{ "-", 0xE1, "OEM specific", "" }, - { "VK_OEM_102", 0xE2, "Pipe", "" }, + {"VK_OEM_102", 0xE2, "Pipe", ""}, //{ "-", 0xE3 - E4, "OEM specific", "" }, - { "VK_PROCESSKEY", 0xE5, "IME PROCESS", "" }, + {"VK_PROCESSKEY", 0xE5, "IME PROCESS", ""}, //{ "-", 0xE6, "OEM specific", "" }, - { "VK_PACKET", 0xE7, "Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP", "" }, + { + "VK_PACKET", 0xE7, + "Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP", + "" + }, //{ "-", 0xE8, "Unassigned", "" }, // {"-",0xE6,"OEM specific"}, - { "VK_PACKET", 0xE7, "Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP", "" }, + { + "VK_PACKET", 0xE7, + "Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP", + "" + }, // {"-",0xE8,"Unassigned"}, //{ "-", 0xE9 - F5, "OEM specific", "" }, - { "VK_ATTN", 0xF6, "Attn", "" }, - { "VK_CRSEL", 0xF7, "CrSel", "" }, - { "VK_EXSEL", 0xF8, "ExSel", "" }, - { "VK_EREOF", 0xF9, "Erase EOF", "Menu" }, - { "VK_PLAY", 0xFA, "Play", "" }, - { "VK_ZOOM", 0xFB, "Zoom", "" }, - { "VK_NONAME", 0xFC, "Reserved", "" }, - { "VK_PA1", 0xFD, "PA1", "" }, - { "VK_OEM_CLEAR", 0xFE, "Clear", "" } + {"VK_ATTN", 0xF6, "Attn", ""}, + {"VK_CRSEL", 0xF7, "CrSel", ""}, + {"VK_EXSEL", 0xF8, "ExSel", ""}, + {"VK_EREOF", 0xF9, "Erase EOF", "Menu"}, + {"VK_PLAY", 0xFA, "Play", ""}, + {"VK_ZOOM", 0xFB, "Zoom", ""}, + {"VK_NONAME", 0xFC, "Reserved", ""}, + {"VK_PA1", 0xFD, "PA1", ""}, + {"VK_OEM_CLEAR", 0xFE, "Clear", ""} }; WindowsKeyManager::WindowsKeyManager(shared_ptr console, HWND hWnd) @@ -207,35 +215,57 @@ WindowsKeyManager::WindowsKeyManager(shared_ptr console, HWND hWnd) ResetKeyState(); //Init XInput buttons - vector buttonNames = { "Up", "Down", "Left", "Right", "Start", "Back", "L3", "R3", "L1", "R1", "?", "?", "A", "B", "X", "Y", "L2", "R2", "RT Up", "RT Down", "RT Left", "RT Right", "LT Up", "LT Down", "LT Left", "LT Right" }; - for(int i = 0; i < 4; i++) { - for(int j = 0; j < (int)buttonNames.size(); j++) { - _keyDefinitions.push_back({ "", (uint32_t)(0xFFFF + i * 0x100 + j + 1), "Pad" + std::to_string(i + 1) + " " + buttonNames[j] }); + vector buttonNames = { + "Up", "Down", "Left", "Right", "Start", "Back", "L3", "R3", "L1", "R1", "?", "?", "A", "B", "X", "Y", "L2", "R2", + "RT Up", "RT Down", "RT Left", "RT Right", "LT Up", "LT Down", "LT Left", "LT Right" + }; + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < (int)buttonNames.size(); j++) + { + _keyDefinitions.push_back({ + "", (uint32_t)(0xFFFF + i * 0x100 + j + 1), "Pad" + std::to_string(i + 1) + " " + buttonNames[j] + }); } } //Init DirectInput buttons - vector diButtonNames = { "Y+", "Y-", "X-", "X+", "Y2+", "Y2-", "X2-", "X2+", "Z+", "Z-", "Z2+", "Z2-", "DPad Up", "DPad Down", "DPad Right", "DPad Left" }; - for(int i = 0; i < 16; i++) { - for(int j = 0; j < (int)diButtonNames.size(); j++) { - _keyDefinitions.push_back({ "", (uint32_t)(0x11000 + i * 0x100 + j), "Joy" + std::to_string(i + 1) + " " + diButtonNames[j] }); + vector diButtonNames = { + "Y+", "Y-", "X-", "X+", "Y2+", "Y2-", "X2-", "X2+", "Z+", "Z-", "Z2+", "Z2-", "DPad Up", "DPad Down", + "DPad Right", "DPad Left" + }; + for (int i = 0; i < 16; i++) + { + for (int j = 0; j < (int)diButtonNames.size(); j++) + { + _keyDefinitions.push_back({ + "", (uint32_t)(0x11000 + i * 0x100 + j), "Joy" + std::to_string(i + 1) + " " + diButtonNames[j] + }); } - for(int j = 0; j < 128; j++) { - _keyDefinitions.push_back({ "", (uint32_t)(0x11000 + i * 0x100 + j + 0x10), "Joy" + std::to_string(i + 1) + " But" + std::to_string(j+1)}); + for (int j = 0; j < 128; j++) + { + _keyDefinitions.push_back({ + "", (uint32_t)(0x11000 + i * 0x100 + j + 0x10), + "Joy" + std::to_string(i + 1) + " But" + std::to_string(j + 1) + }); } } - for(KeyDefinition& keyDef : _keyDefinitions) { + for (KeyDefinition& keyDef : _keyDefinitions) + { _keyNames[keyDef.keyCode] = keyDef.description; - _keyExtendedNames[keyDef.keyCode | 0x100] = keyDef.extDescription.empty() ? "Ext " + keyDef.description : keyDef.extDescription; + _keyExtendedNames[keyDef.keyCode | 0x100] = keyDef.extDescription.empty() + ? "Ext " + keyDef.description + : keyDef.extDescription; _keyCodes[keyDef.description] = keyDef.keyCode; - if(!keyDef.extDescription.empty()) { + if (!keyDef.extDescription.empty()) + { _keyCodes[keyDef.extDescription] = 0x100 | (keyDef.keyCode); } } - + StartUpdateDeviceThread(); } @@ -248,14 +278,17 @@ WindowsKeyManager::~WindowsKeyManager() void WindowsKeyManager::StartUpdateDeviceThread() { - _updateDeviceThread = std::thread([=]() { + _updateDeviceThread = std::thread([=]() + { _xInput.reset(new XInputManager(_console)); _directInput.reset(new DirectInputManager(_console, _hWnd)); - while(!_stopUpdateDeviceThread) { + while (!_stopUpdateDeviceThread) + { //Check for newly plugged in XInput controllers every 5 secs //Do not check for DirectInput controllers because this takes more time and sometimes causes issues/freezes - if(_xInput->NeedToUpdate()) { + if (_xInput->NeedToUpdate()) + { _xInput->UpdateDeviceList(); } _stopSignal.Wait(5000); @@ -265,7 +298,8 @@ void WindowsKeyManager::StartUpdateDeviceThread() void WindowsKeyManager::RefreshState() { - if(!_xInput || !_directInput) { + if (!_xInput || !_directInput) + { return; } @@ -275,27 +309,35 @@ void WindowsKeyManager::RefreshState() bool WindowsKeyManager::IsKeyPressed(uint32_t key) { - if(_disableAllKeys) { + if (_disableAllKeys) + { return false; } - if(key >= 0x10000) { - if(!_xInput || !_directInput) { + if (key >= 0x10000) + { + if (!_xInput || !_directInput) + { return false; } - if(key >= 0x11000) { + if (key >= 0x11000) + { //Directinput key uint8_t gamepadPort = (key - 0x11000) / 0x100; uint8_t gamepadButton = (key - 0x11000) % 0x100; return _directInput->IsPressed(gamepadPort, gamepadButton); - } else { + } + else + { //XInput key uint8_t gamepadPort = (key - 0xFFFF) / 0x100; uint8_t gamepadButton = (key - 0xFFFF) % 0x100; return _xInput->IsPressed(gamepadPort, gamepadButton); } - } else if(key < 0x200) { + } + else if (key < 0x200) + { return _keyState[key] != 0; } return false; @@ -303,10 +345,11 @@ bool WindowsKeyManager::IsKeyPressed(uint32_t key) bool WindowsKeyManager::IsMouseButtonPressed(MouseButton button) { - switch(button) { - case MouseButton::LeftButton: return _mouseState[0]; - case MouseButton::RightButton: return _mouseState[1]; - case MouseButton::MiddleButton: return _mouseState[2]; + switch (button) + { + case MouseButton::LeftButton: return _mouseState[0]; + case MouseButton::RightButton: return _mouseState[1]; + case MouseButton::MiddleButton: return _mouseState[2]; } return false; @@ -315,30 +358,39 @@ bool WindowsKeyManager::IsMouseButtonPressed(MouseButton button) vector WindowsKeyManager::GetPressedKeys() { vector result; - if(!_xInput || !_directInput) { + if (!_xInput || !_directInput) + { return result; } _xInput->RefreshState(); - for(int i = 0; i < XUSER_MAX_COUNT; i++) { - for(int j = 1; j <= 26; j++) { - if(_xInput->IsPressed(i, j)) { + for (int i = 0; i < XUSER_MAX_COUNT; i++) + { + for (int j = 1; j <= 26; j++) + { + if (_xInput->IsPressed(i, j)) + { result.push_back(0xFFFF + i * 0x100 + j); } } } _directInput->RefreshState(); - for(int i = _directInput->GetJoystickCount() - 1; i >= 0; i--) { - for(int j = 0; j < 16+128; j++) { - if(_directInput->IsPressed(i, j)) { + for (int i = _directInput->GetJoystickCount() - 1; i >= 0; i--) + { + for (int j = 0; j < 16 + 128; j++) + { + if (_directInput->IsPressed(i, j)) + { result.push_back(0x11000 + i * 0x100 + j); } } } - for(int i = 0; i < 0x200; i++) { - if(_keyState[i]) { + for (int i = 0; i < 0x200; i++) + { + if (_keyState[i]) + { result.push_back(i); } } @@ -349,7 +401,8 @@ string WindowsKeyManager::GetKeyName(uint32_t keyCode) { bool extendedKey = (keyCode <= 0xFFFF && (keyCode & 0x100)); auto keyDef = (extendedKey ? _keyExtendedNames : _keyNames).find(keyCode); - if(keyDef != (extendedKey ? _keyExtendedNames : _keyNames).end()) { + if (keyDef != (extendedKey ? _keyExtendedNames : _keyNames).end()) + { return keyDef->second; } return ""; @@ -358,7 +411,8 @@ string WindowsKeyManager::GetKeyName(uint32_t keyCode) uint32_t WindowsKeyManager::GetKeyCode(string keyName) { auto keyDef = _keyCodes.find(keyName); - if(keyDef != _keyCodes.end()) { + if (keyDef != _keyCodes.end()) + { return keyDef->second; } return 0; @@ -366,7 +420,8 @@ uint32_t WindowsKeyManager::GetKeyCode(string keyName) void WindowsKeyManager::UpdateDevices() { - if(!_xInput || !_directInput) { + if (!_xInput || !_directInput) + { return; } @@ -376,11 +431,15 @@ void WindowsKeyManager::UpdateDevices() void WindowsKeyManager::SetKeyState(uint16_t scanCode, bool state) { - if(scanCode > 0x1FF) { + if (scanCode > 0x1FF) + { _mouseState[scanCode & 0x03] = state; - } else { + } + else + { uint32_t keyCode = MapVirtualKeyEx(scanCode & 0xFF, MAPVK_VSC_TO_VK, GetKeyboardLayout(0)); - if(keyCode >= 0x10 && keyCode <= 0x12) { + if (keyCode >= 0x10 && keyCode <= 0x12) + { //Ignore "ext" flag for alt, ctrl & shift scanCode = MapVirtualKeyEx(keyCode, MAPVK_VK_TO_VSC, GetKeyboardLayout(0)); } @@ -397,4 +456,4 @@ void WindowsKeyManager::ResetKeyState() { memset(_mouseState, 0, sizeof(_mouseState)); memset(_keyState, 0, sizeof(_keyState)); -} \ No newline at end of file +} diff --git a/Windows/WindowsKeyManager.h b/Windows/WindowsKeyManager.h index 01594f3..4f4a327 100644 --- a/Windows/WindowsKeyManager.h +++ b/Windows/WindowsKeyManager.h @@ -8,7 +8,8 @@ #include "XInputManager.h" #include "DirectInputManager.h" -struct KeyDefinition { +struct KeyDefinition +{ string name; uint32_t keyCode; string description; @@ -19,40 +20,40 @@ class Console; class WindowsKeyManager : public IKeyManager { - private: - HWND _hWnd; - shared_ptr _console; +private: + HWND _hWnd; + shared_ptr _console; - bool _keyState[0x200]; - bool _mouseState[0x03]; - unique_ptr _directInput; - unique_ptr _xInput; - std::unordered_map _keyNames; - std::unordered_map _keyExtendedNames; - std::unordered_map _keyCodes; + bool _keyState[0x200]; + bool _mouseState[0x03]; + unique_ptr _directInput; + unique_ptr _xInput; + std::unordered_map _keyNames; + std::unordered_map _keyExtendedNames; + std::unordered_map _keyCodes; - AutoResetEvent _stopSignal; - - std::thread _updateDeviceThread; - atomic _stopUpdateDeviceThread = false; - bool _disableAllKeys = false; + AutoResetEvent _stopSignal; - void StartUpdateDeviceThread(); + std::thread _updateDeviceThread; + atomic _stopUpdateDeviceThread = false; + bool _disableAllKeys = false; - public: - WindowsKeyManager(shared_ptr console, HWND hWnd); - ~WindowsKeyManager(); + void StartUpdateDeviceThread(); - void RefreshState(); - bool IsKeyPressed(uint32_t key); - bool IsMouseButtonPressed(MouseButton button); - vector GetPressedKeys(); - string GetKeyName(uint32_t key); - uint32_t GetKeyCode(string keyName); +public: + WindowsKeyManager(shared_ptr console, HWND hWnd); + ~WindowsKeyManager(); - void SetKeyState(uint16_t scanCode, bool state); - void ResetKeyState(); - void SetDisabled(bool disabled); + void RefreshState(); + bool IsKeyPressed(uint32_t key); + bool IsMouseButtonPressed(MouseButton button); + vector GetPressedKeys(); + string GetKeyName(uint32_t key); + uint32_t GetKeyCode(string keyName); - void UpdateDevices(); + void SetKeyState(uint16_t scanCode, bool state); + void ResetKeyState(); + void SetDisabled(bool disabled); + + void UpdateDevices(); }; diff --git a/Windows/XInputManager.cpp b/Windows/XInputManager.cpp index c90053d..4a0ab5f 100644 --- a/Windows/XInputManager.cpp +++ b/Windows/XInputManager.cpp @@ -6,7 +6,8 @@ XInputManager::XInputManager(shared_ptr console) { _console = console; - for(int i = 0; i < XUSER_MAX_COUNT; i++) { + for (int i = 0; i < XUSER_MAX_COUNT; i++) + { _gamePadStates.push_back(shared_ptr(new XINPUT_STATE())); _gamePadConnected.push_back(true); } @@ -15,13 +16,18 @@ XInputManager::XInputManager(shared_ptr console) void XInputManager::RefreshState() { XINPUT_STATE state; - for(DWORD i = 0; i < XUSER_MAX_COUNT; i++) { - if(_gamePadConnected[i]) { - if(XInputGetState(i, &state) != ERROR_SUCCESS) { + for (DWORD i = 0; i < XUSER_MAX_COUNT; i++) + { + if (_gamePadConnected[i]) + { + if (XInputGetState(i, &state) != ERROR_SUCCESS) + { //XInputGetState is incredibly slow when no controller is plugged in ZeroMemory(_gamePadStates[i].get(), sizeof(XINPUT_STATE)); _gamePadConnected[i] = false; - } else { + } + else + { *_gamePadStates[i] = state; } } @@ -30,10 +36,13 @@ void XInputManager::RefreshState() bool XInputManager::NeedToUpdate() { - for(int i = 0; i < XUSER_MAX_COUNT; i++) { - if(!_gamePadConnected[i]) { + for (int i = 0; i < XUSER_MAX_COUNT; i++) + { + if (!_gamePadConnected[i]) + { XINPUT_STATE state; - if(XInputGetState(i, &state) == ERROR_SUCCESS) { + if (XInputGetState(i, &state) == ERROR_SUCCESS) + { return true; } } @@ -44,32 +53,38 @@ bool XInputManager::NeedToUpdate() void XInputManager::UpdateDeviceList() { //Periodically detect if a controller has been plugged in to allow controllers to be plugged in after the emu is started - for(int i = 0; i < XUSER_MAX_COUNT; i++) { + for (int i = 0; i < XUSER_MAX_COUNT; i++) + { _gamePadConnected[i] = true; } } bool XInputManager::IsPressed(uint8_t gamepadPort, uint8_t button) { - if(_gamePadConnected[gamepadPort]) { - XINPUT_GAMEPAD &gamepad = _gamePadStates[gamepadPort]->Gamepad; - if(button <= 16) { + if (_gamePadConnected[gamepadPort]) + { + XINPUT_GAMEPAD& gamepad = _gamePadStates[gamepadPort]->Gamepad; + if (button <= 16) + { WORD xinputButton = 1 << (button - 1); return (_gamePadStates[gamepadPort]->Gamepad.wButtons & xinputButton) != 0; - } else { + } + else + { double ratio = _console->GetSettings()->GetControllerDeadzoneRatio() * 2; - switch(button) { - case 17: return gamepad.bLeftTrigger > (XINPUT_GAMEPAD_TRIGGER_THRESHOLD * ratio); - case 18: return gamepad.bRightTrigger > (XINPUT_GAMEPAD_TRIGGER_THRESHOLD * ratio); - case 19: return gamepad.sThumbRY > (XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE * ratio); - case 20: return gamepad.sThumbRY < -(XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE * ratio); - case 21: return gamepad.sThumbRX < -(XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE * ratio); - case 22: return gamepad.sThumbRX > (XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE * ratio); - case 23: return gamepad.sThumbLY > (XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE * ratio); - case 24: return gamepad.sThumbLY < -(XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE * ratio); - case 25: return gamepad.sThumbLX < -(XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE * ratio); - case 26: return gamepad.sThumbLX > (XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE * ratio); + switch (button) + { + case 17: return gamepad.bLeftTrigger > (XINPUT_GAMEPAD_TRIGGER_THRESHOLD * ratio); + case 18: return gamepad.bRightTrigger > (XINPUT_GAMEPAD_TRIGGER_THRESHOLD * ratio); + case 19: return gamepad.sThumbRY > (XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE * ratio); + case 20: return gamepad.sThumbRY < -(XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE * ratio); + case 21: return gamepad.sThumbRX < -(XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE * ratio); + case 22: return gamepad.sThumbRX > (XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE * ratio); + case 23: return gamepad.sThumbLY > (XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE * ratio); + case 24: return gamepad.sThumbLY < -(XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE * ratio); + case 25: return gamepad.sThumbLX < -(XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE * ratio); + case 26: return gamepad.sThumbLX > (XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE * ratio); } } } diff --git a/Windows/XInputManager.h b/Windows/XInputManager.h index 019d343..93d990d 100644 --- a/Windows/XInputManager.h +++ b/Windows/XInputManager.h @@ -7,16 +7,16 @@ class Console; class XInputManager { - private: - shared_ptr _console; - vector> _gamePadStates; - vector _gamePadConnected; +private: + shared_ptr _console; + vector> _gamePadStates; + vector _gamePadConnected; - public: - XInputManager(shared_ptr console); +public: + XInputManager(shared_ptr console); - bool NeedToUpdate(); - void UpdateDeviceList(); - void RefreshState(); - bool IsPressed(uint8_t gamepadPort, uint8_t button); + bool NeedToUpdate(); + void UpdateDeviceList(); + void RefreshState(); + bool IsPressed(uint8_t gamepadPort, uint8_t button); }; diff --git a/Windows/stdafx.h b/Windows/stdafx.h index 4db3bd9..1fe9af6 100644 --- a/Windows/stdafx.h +++ b/Windows/stdafx.h @@ -44,4 +44,4 @@ using std::list; using std::vector; using std::shared_ptr; using std::string; -using namespace std::literals::string_literals; \ No newline at end of file +using namespace std::literals::string_literals;