diff --git a/CPU.cpp b/Core/CPU.cpp
similarity index 99%
rename from CPU.cpp
rename to Core/CPU.cpp
index 809741d7..4c108fb8 100644
--- a/CPU.cpp
+++ b/Core/CPU.cpp
@@ -102,7 +102,7 @@ void CPU::RunBenchmark()
{
std::ifstream romFile("6502_functional_test.bin", std::ios::in | std::ios::binary);
if(!romFile) {
- std::cout << "Error";
+ return;
}
uint8_t *romMemory = new uint8_t[65536];
diff --git a/CPU.h b/Core/CPU.h
similarity index 100%
rename from CPU.h
rename to Core/CPU.h
diff --git a/Core.vcxproj b/Core/Core.vcxproj
similarity index 96%
rename from Core.vcxproj
rename to Core/Core.vcxproj
index 2c6af3b0..80231db1 100644
--- a/Core.vcxproj
+++ b/Core/Core.vcxproj
@@ -18,13 +18,13 @@
- Application
+ StaticLibrary
true
v120
Unicode
- Application
+ StaticLibrary
false
v120
true
@@ -84,9 +84,7 @@
-
-
-
+
@@ -94,6 +92,7 @@
+
diff --git a/Core.vcxproj.filters b/Core/Core.vcxproj.filters
similarity index 90%
rename from Core.vcxproj.filters
rename to Core/Core.vcxproj.filters
index 6660044d..6d743a7c 100644
--- a/Core.vcxproj.filters
+++ b/Core/Core.vcxproj.filters
@@ -14,9 +14,6 @@
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
-
-
Header Files
@@ -33,6 +30,9 @@
Header Files
+
+ Header Files
+
@@ -47,5 +47,8 @@
Source Files
+
+ Source Files
+
\ No newline at end of file
diff --git a/EventHandler.h b/Core/EventHandler.h
similarity index 100%
rename from EventHandler.h
rename to Core/EventHandler.h
diff --git a/Memory.h b/Core/Memory.h
similarity index 100%
rename from Memory.h
rename to Core/Memory.h
diff --git a/Timer.h b/Core/Timer.h
similarity index 82%
rename from Timer.h
rename to Core/Timer.h
index 20738930..96f30f14 100644
--- a/Timer.h
+++ b/Core/Timer.h
@@ -19,6 +19,13 @@ class Timer
_start = li;
}
+ void Reset()
+ {
+ LARGE_INTEGER li;
+ QueryPerformanceCounter(&li);
+ _start = li;
+ }
+
double GetElapsedMS()
{
LARGE_INTEGER li;
diff --git a/main.cpp b/Core/main.cpp
similarity index 100%
rename from main.cpp
rename to Core/main.cpp
diff --git a/stdafx.h b/Core/stdafx.h
similarity index 100%
rename from stdafx.h
rename to Core/stdafx.h
diff --git a/targetver.h b/Core/targetver.h
similarity index 100%
rename from targetver.h
rename to Core/targetver.h
diff --git a/GUI/DirectXTK/Audio.h b/GUI/DirectXTK/Audio.h
new file mode 100644
index 00000000..d5624e3f
--- /dev/null
+++ b/GUI/DirectXTK/Audio.h
@@ -0,0 +1,682 @@
+//--------------------------------------------------------------------------------------
+// File: Audio.h
+//
+// DirectXTK for Audio header
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// http://go.microsoft.com/fwlink/?LinkId=248929
+//--------------------------------------------------------------------------------------
+
+#pragma once
+
+#include
+#include
+#include
+
+#if defined(_XBOX_ONE) && defined(_TITLE)
+#include
+#pragma comment(lib,"acphal.lib")
+#endif
+
+#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+#pragma comment(lib,"PhoneAudioSes.lib")
+#endif
+
+#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
+#if defined(_MSC_VER) && (_MSC_VER < 1700)
+#error DirectX Tool Kit for Audio does not support VS 2010 without the DirectX SDK
+#endif
+#include
+#include
+#include
+#include
+#pragma comment(lib,"xaudio2.lib")
+#else
+// Using XAudio 2.7 requires the DirectX SDK
+#include
+#include
+#include
+#include
+#pragma warning(push)
+#pragma warning( disable : 4005 )
+#include
+#pragma warning(pop)
+#pragma comment(lib,"x3daudio.lib")
+#pragma comment(lib,"xapofx.lib")
+#endif
+
+#include
+
+#pragma warning(push)
+#pragma warning(disable : 4005)
+#include
+#pragma warning(pop)
+
+#include
+#include
+#include
+#include
+
+#pragma warning(push)
+#pragma warning(disable : 4481)
+// VS 2010 considers 'override' to be a extension, but it's part of C++11 as of VS 2012
+
+namespace DirectX
+{
+ #if (DIRECTXMATH_VERSION < 305) && !defined(XM_CALLCONV)
+ #define XM_CALLCONV __fastcall
+ typedef const XMVECTOR& HXMVECTOR;
+ typedef const XMMATRIX& FXMMATRIX;
+ #endif
+
+ 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
+#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 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 OnCriticalError() = 0;
+ // Notification that the audio engine encountered a critical error
+
+ virtual void OnReset() = 0;
+ // Notification of an audio engine reset
+
+ virtual void OnUpdate() = 0;
+ // Notification of an audio engine per-frame update (opt-in)
+
+ virtual void OnDestroyEngine() = 0;
+ // Notification that the audio engine is being destroyed
+
+ virtual void OnTrim() = 0;
+ // Notification of a request to trim the voice pool
+
+ virtual void GatherStatistics( AudioStatistics& stats ) const = 0;
+ // Contribute to statistics request
+ };
+
+ //----------------------------------------------------------------------------------
+ enum AUDIO_ENGINE_FLAGS
+ {
+ AudioEngine_Default = 0x0,
+
+ AudioEngine_EnvironmentalReverb = 0x1,
+ AudioEngine_ReverbUseFilters = 0x2,
+ AudioEngine_UseMasteringLimiter = 0x4,
+
+ 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) ); }
+
+ enum SOUND_EFFECT_INSTANCE_FLAGS
+ {
+ SoundEffectInstance_Default = 0x0,
+
+ SoundEffectInstance_Use3D = 0x1,
+ SoundEffectInstance_ReverbUseFilters = 0x2,
+ SoundEffectInstance_NoSetPitch = 0x4,
+
+ 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) ); }
+
+ 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
+ };
+
+
+ //----------------------------------------------------------------------------------
+ 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();
+
+ bool Update();
+ // Performs per-frame processing for the audio engine, returns false if in 'silent mode'
+
+ bool 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 Suspend();
+ void Resume();
+ // Suspend/resumes audio processing (i.e. global pause/resume)
+
+ void SetReverb( AUDIO_ENGINE_REVERB reverb );
+ void SetReverb( _In_opt_ const XAUDIO2FX_REVERB_PARAMETERS* native );
+ // Sets environmental reverb for 3D positional audio (if active)
+
+ void SetMasteringLimit( int release, int loudness );
+ // Sets the mastering volume limiter properties (if active)
+
+ AudioStatistics GetStatistics() const;
+ // Gathers audio engine statistics
+
+ WAVEFORMATEXTENSIBLE GetOutputFormat() const;
+ // Returns the format consumed by the mastering voice (which is the same as the device output if defaults are used)
+
+ uint32_t GetChannelMask() const;
+ // Returns the output channel mask
+
+ int GetOutputChannels() const;
+ // Returns the number of output channels
+
+ bool IsAudioDevicePresent() const;
+ // Returns true if the audio graph is operating normally, false if in 'silent mode'
+
+ bool 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 SetDefaultSampleRate( int sampleRate );
+ // Sample rate for voices in the reuse pool (defaults to 44100)
+
+ void 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 TrimVoicePool();
+ // Releases any currently unused voices
+
+ void AllocateVoice( _In_ const WAVEFORMATEX* wfx, SOUND_EFFECT_INSTANCE_FLAGS flags, bool oneshot, _Outptr_result_maybenull_ IXAudio2SourceVoice** voice );
+
+ void DestroyVoice( _In_ IXAudio2SourceVoice* voice );
+ // Should only be called for instance voices, not one-shots
+
+ void RegisterNotify( _In_ IVoiceNotify* notify, bool usesUpdate );
+ void UnregisterNotify( _In_ IVoiceNotify* notify, bool usesOneShots, bool usesUpdate );
+
+ // XAudio2 interface access
+ IXAudio2* GetInterface() const;
+ IXAudio2MasteringVoice* GetMasterVoice() const;
+ IXAudio2SubmixVoice* GetReverbVoice() const;
+ X3DAUDIO_HANDLE& Get3DHandle() const;
+
+ struct RendererDetail
+ {
+ std::wstring deviceId;
+ std::wstring description;
+ };
+
+ static std::vector GetRendererDetails();
+ // Returns a list of valid audio endpoint devices
+
+ private:
+ // Private implementation.
+ class Impl;
+ std::unique_ptr pImpl;
+
+ // Prevent copying.
+ AudioEngine(AudioEngine const&);
+ AudioEngine& operator= (AudioEngine const&);
+ };
+
+
+ //----------------------------------------------------------------------------------
+ class WaveBank
+ {
+ public:
+ WaveBank( _In_ AudioEngine* engine, _In_z_ const wchar_t* wbFileName );
+
+ WaveBank(WaveBank&& moveFrom);
+ WaveBank& operator= (WaveBank&& moveFrom);
+ virtual ~WaveBank();
+
+ void Play( int index );
+ void Play( _In_z_ const char* name );
+
+ std::unique_ptr CreateInstance( int index, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
+ std::unique_ptr CreateInstance( _In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
+
+ bool IsPrepared() const;
+ bool IsInUse() const;
+ bool IsStreamingBank() const;
+
+ size_t GetSampleSizeInBytes( int index ) const;
+ // Returns size of wave audio data
+
+ size_t GetSampleDuration( int index ) const;
+ // Returns the duration in samples
+
+ size_t GetSampleDurationMS( int index ) const;
+ // Returns the duration in milliseconds
+
+ const WAVEFORMATEX* GetFormat( int index, _Out_writes_bytes_(maxsize) WAVEFORMATEX* wfx, size_t maxsize ) const;
+
+ int Find( _In_z_ const char* name ) const;
+
+#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8)
+ bool FillSubmitBuffer( int index, _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer ) const;
+#else
+ void FillSubmitBuffer( int index, _Out_ XAUDIO2_BUFFER& buffer ) const;
+#endif
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::unique_ptr pImpl;
+
+ // Prevent copying.
+ WaveBank(WaveBank const&);
+ WaveBank& operator= (WaveBank const&);
+
+ // Private interface
+ void UnregisterInstance( _In_ SoundEffectInstance* instance );
+
+ friend class SoundEffectInstance;
+ };
+
+
+ //----------------------------------------------------------------------------------
+ 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,
+ uint32_t loopStart, uint32_t loopLength );
+
+#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8)
+
+ 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();
+
+ void Play();
+
+ std::unique_ptr CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
+
+ bool IsInUse() const;
+
+ size_t GetSampleSizeInBytes() const;
+ // Returns size of wave audio data
+
+ size_t GetSampleDuration() const;
+ // Returns the duration in samples
+
+ size_t GetSampleDurationMS() const;
+ // Returns the duration in milliseconds
+
+ const WAVEFORMATEX* GetFormat() const;
+
+#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8)
+ bool FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer ) const;
+#else
+ void FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer ) const;
+#endif
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::unique_ptr pImpl;
+
+ // Prevent copying.
+ SoundEffect(SoundEffect const&);
+ SoundEffect& operator= (SoundEffect const&);
+
+ // Private interface
+ void UnregisterInstance( _In_ SoundEffectInstance* instance );
+
+ friend class SoundEffectInstance;
+ };
+
+
+ //----------------------------------------------------------------------------------
+ struct AudioListener : public X3DAUDIO_LISTENER
+ {
+ AudioListener()
+ {
+ memset( this, 0, sizeof(X3DAUDIO_LISTENER) );
+
+ OrientFront.z =
+ OrientTop.y = 1.f;
+ }
+
+ void XM_CALLCONV SetPosition( FXMVECTOR v )
+ {
+ XMStoreFloat3( reinterpret_cast( &Position ), v );
+ }
+ void 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 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 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 =
+ 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 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 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 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 Play( bool loop = false );
+ void Stop( bool immediate = true );
+ void Pause();
+ void Resume();
+
+ void SetVolume( float volume );
+ void SetPitch( float pitch );
+ void SetPan( float pan );
+
+ void Apply3D( const AudioListener& listener, const AudioEmitter& emitter );
+
+ bool IsLooped() const;
+
+ SoundState GetState();
+
+ // Notifications.
+ void 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 SoundEffect::CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS );
+ friend std::unique_ptr WaveBank::CreateInstance( int, SOUND_EFFECT_INSTANCE_FLAGS );
+
+ // Prevent copying.
+ SoundEffectInstance(SoundEffectInstance const&);
+ SoundEffectInstance& operator= (SoundEffectInstance const&);
+ };
+
+
+ //----------------------------------------------------------------------------------
+ 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 Play();
+ void Stop( bool immediate = true );
+ void Pause();
+ void Resume();
+
+ void SetVolume( float volume );
+ void SetPitch( float pitch );
+ void SetPan( float pan );
+
+ void Apply3D( const AudioListener& listener, const AudioEmitter& emitter );
+
+ void SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, size_t audioBytes );
+ void SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, uint32_t offset, size_t audioBytes );
+
+ SoundState GetState();
+
+ size_t GetSampleDuration( size_t bytes ) const;
+ // Returns duration in samples of a buffer of a given size
+
+ size_t GetSampleDurationMS( size_t bytes ) const;
+ // Returns duration in milliseconds of a buffer of a given size
+
+ size_t GetSampleSizeInBytes( uint64_t duration ) const;
+ // Returns size of a buffer for a duration given in milliseconds
+
+ int GetPendingBufferCount() const;
+
+ const WAVEFORMATEX* GetFormat() const;
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::unique_ptr pImpl;
+
+ // Prevent copying.
+ DynamicSoundEffectInstance(DynamicSoundEffectInstance const&);
+ DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance const&);
+ };
+}
+
+#pragma warning(pop)
\ No newline at end of file
diff --git a/GUI/DirectXTK/CommonStates.h b/GUI/DirectXTK/CommonStates.h
new file mode 100644
index 00000000..2c280906
--- /dev/null
+++ b/GUI/DirectXTK/CommonStates.h
@@ -0,0 +1,70 @@
+//--------------------------------------------------------------------------------------
+// File: CommonStates.h
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// http://go.microsoft.com/fwlink/?LinkId=248929
+//--------------------------------------------------------------------------------------
+
+#pragma once
+
+#if defined(_XBOX_ONE) && defined(_TITLE) && MONOLITHIC
+#include
+#else
+#include
+#endif
+
+#include
+
+
+namespace DirectX
+{
+ class CommonStates
+ {
+ public:
+ explicit CommonStates(_In_ ID3D11Device* device);
+ CommonStates(CommonStates&& moveFrom);
+ CommonStates& operator= (CommonStates&& moveFrom);
+ virtual ~CommonStates();
+
+ // Blend states.
+ ID3D11BlendState* Opaque() const;
+ ID3D11BlendState* AlphaBlend() const;
+ ID3D11BlendState* Additive() const;
+ ID3D11BlendState* NonPremultiplied() const;
+
+ // Depth stencil states.
+ ID3D11DepthStencilState* DepthNone() const;
+ ID3D11DepthStencilState* DepthDefault() const;
+ ID3D11DepthStencilState* DepthRead() const;
+
+ // Rasterizer states.
+ ID3D11RasterizerState* CullNone() const;
+ ID3D11RasterizerState* CullClockwise() const;
+ ID3D11RasterizerState* CullCounterClockwise() const;
+ ID3D11RasterizerState* Wireframe() const;
+
+ // Sampler states.
+ ID3D11SamplerState* PointWrap() const;
+ ID3D11SamplerState* PointClamp() const;
+ ID3D11SamplerState* LinearWrap() const;
+ ID3D11SamplerState* LinearClamp() const;
+ ID3D11SamplerState* AnisotropicWrap() const;
+ ID3D11SamplerState* AnisotropicClamp() const;
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::shared_ptr pImpl;
+
+ // Prevent copying.
+ CommonStates(CommonStates const&);
+ CommonStates& operator= (CommonStates const&);
+ };
+}
diff --git a/GUI/DirectXTK/DDSTextureLoader.h b/GUI/DirectXTK/DDSTextureLoader.h
new file mode 100644
index 00000000..9c3ca141
--- /dev/null
+++ b/GUI/DirectXTK/DDSTextureLoader.h
@@ -0,0 +1,142 @@
+//--------------------------------------------------------------------------------------
+// File: DDSTextureLoader.h
+//
+// Functions for loading a DDS texture and creating a Direct3D 11 runtime resource for it
+//
+// Note these functions are useful as a light-weight runtime loader for DDS files. For
+// a full-featured DDS file reader, writer, and texture processing pipeline see
+// the 'Texconv' sample and the 'DirectXTex' library.
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// http://go.microsoft.com/fwlink/?LinkId=248926
+// http://go.microsoft.com/fwlink/?LinkId=248929
+//--------------------------------------------------------------------------------------
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+#if defined(_XBOX_ONE) && defined(_TITLE) && MONOLITHIC
+#include
+#else
+#include
+#endif
+
+#pragma warning(push)
+#pragma warning(disable : 4005)
+#include
+#pragma warning(pop)
+
+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,
+ };
+
+ // Standard version
+ HRESULT 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 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
+ HRESULT CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice,
+ _In_opt_ ID3D11DeviceContext* d3dContext,
+ _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 CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice,
+ _In_opt_ ID3D11DeviceContext* d3dContext,
+ _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 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 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
+ HRESULT CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
+ _In_opt_ ID3D11DeviceContext* d3dContext,
+ _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 CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
+ _In_opt_ ID3D11DeviceContext* d3dContext,
+ _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
diff --git a/GUI/DirectXTK/DirectXHelpers.h b/GUI/DirectXTK/DirectXHelpers.h
new file mode 100644
index 00000000..e3d8ecdd
--- /dev/null
+++ b/GUI/DirectXTK/DirectXHelpers.h
@@ -0,0 +1,120 @@
+//--------------------------------------------------------------------------------------
+// File: DirectXHelpers.h
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// http://go.microsoft.com/fwlink/?LinkId=248929
+//--------------------------------------------------------------------------------------
+
+#pragma once
+
+#if defined(_XBOX_ONE) && defined(_TITLE) && MONOLITHIC
+#include
+#define NO_D3D11_DEBUG_NAME
+#else
+#include
+#endif
+
+#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
+#pragma comment(lib,"dxguid.lib")
+#endif
+
+#include
+
+#pragma warning(push)
+#pragma warning(disable : 4005)
+#include
+#pragma warning(pop)
+
+//
+// The core Direct3D headers provide the following helper C++ classes
+// CD3D11_RECT
+// CD3D11_BOX
+// CD3D11_DEPTH_STENCIL_DESC
+// CD3D11_BLEND_DESC, CD3D11_BLEND_DESC1
+// CD3D11_RASTERIZER_DESC, CD3D11_RASTERIZER_DESC1
+// CD3D11_BUFFER_DESC
+// CD3D11_TEXTURE1D_DESC
+// CD3D11_TEXTURE2D_DESC
+// CD3D11_TEXTURE3D_DESC
+// CD3D11_SHADER_RESOURCE_VIEW_DESC
+// CD3D11_RENDER_TARGET_VIEW_DESC
+// CD3D11_VIEWPORT
+// CD3D11_DEPTH_STENCIL_VIEW_DESC
+// CD3D11_UNORDERED_ACCESS_VIEW_DESC
+// CD3D11_SAMPLER_DESC
+// CD3D11_QUERY_DESC
+// CD3D11_COUNTER_DESC
+//
+
+
+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();
+ }
+ }
+
+ ~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* 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 );
+ }
+
+ 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) )
+ resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
+ #else
+ UNREFERENCED_PARAMETER(resource);
+ UNREFERENCED_PARAMETER(name);
+ #endif
+ }
+}
\ No newline at end of file
diff --git a/GUI/DirectXTK/Effects.h b/GUI/DirectXTK/Effects.h
new file mode 100644
index 00000000..212cf7b6
--- /dev/null
+++ b/GUI/DirectXTK/Effects.h
@@ -0,0 +1,598 @@
+//--------------------------------------------------------------------------------------
+// File: Effects.h
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// http://go.microsoft.com/fwlink/?LinkId=248929
+//--------------------------------------------------------------------------------------
+
+#pragma once
+
+#if defined(_XBOX_ONE) && defined(_TITLE) && MONOLITHIC
+#include
+#else
+#include
+#endif
+
+#include
+#include
+
+#pragma warning(push)
+#pragma warning(disable : 4481)
+// VS 2010 considers 'override' to be a extension, but it's part of C++11 as of VS 2012
+
+namespace DirectX
+{
+ #if (DIRECTXMATH_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 Apply(_In_ ID3D11DeviceContext* deviceContext) = 0;
+
+ virtual void 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 SetLightingEnabled(bool value) = 0;
+ virtual void SetPerPixelLighting(bool value) = 0;
+ virtual void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) = 0;
+
+ virtual void 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 EnableDefaultLighting() = 0;
+
+ static const int MaxDirectionalLights = 3;
+ };
+
+
+ // Abstract interface for effects which support fog.
+ class IEffectFog
+ {
+ public:
+ virtual ~IEffectFog() { }
+
+ virtual void SetFogEnabled(bool value) = 0;
+ virtual void SetFogStart(float value) = 0;
+ virtual void 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 SetWeightsPerVertex(int value) = 0;
+ virtual void SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) = 0;
+ virtual void 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 Apply(_In_ ID3D11DeviceContext* deviceContext) override;
+
+ void 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 SetSpecularPower(float value);
+ void DisableSpecular();
+ void SetAlpha(float value);
+
+ // Light settings.
+ void SetLightingEnabled(bool value) override;
+ void SetPerPixelLighting(bool value) override;
+ void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
+
+ void 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 EnableDefaultLighting() override;
+
+ // Fog settings.
+ void SetFogEnabled(bool value) override;
+ void SetFogStart(float value) override;
+ void SetFogEnd(float value) override;
+ void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
+
+ // Vertex color setting.
+ void SetVertexColorEnabled(bool value);
+
+ // Texture setting.
+ void SetTextureEnabled(bool value);
+ void SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::unique_ptr pImpl;
+
+ // Prevent copying.
+ BasicEffect(BasicEffect const&);
+ BasicEffect& operator= (BasicEffect const&);
+ };
+
+
+
+ // 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 Apply(_In_ ID3D11DeviceContext* deviceContext) override;
+
+ void 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 SetAlpha(float value);
+
+ // Fog settings.
+ void SetFogEnabled(bool value) override;
+ void SetFogStart(float value) override;
+ void SetFogEnd(float value) override;
+ void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
+
+ // Vertex color setting.
+ void SetVertexColorEnabled(bool value);
+
+ // Texture setting.
+ void SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
+
+ // Alpha test settings.
+ void SetAlphaFunction(D3D11_COMPARISON_FUNC value);
+ void SetReferenceAlpha(int value);
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::unique_ptr pImpl;
+
+ // Prevent copying.
+ AlphaTestEffect(AlphaTestEffect const&);
+ AlphaTestEffect& operator= (AlphaTestEffect const&);
+ };
+
+
+
+ // 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 Apply(_In_ ID3D11DeviceContext* deviceContext) override;
+
+ void 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 SetAlpha(float value);
+
+ // Fog settings.
+ void SetFogEnabled(bool value) override;
+ void SetFogStart(float value) override;
+ void SetFogEnd(float value) override;
+ void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
+
+ // Vertex color setting.
+ void SetVertexColorEnabled(bool value);
+
+ // Texture settings.
+ void SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
+ void SetTexture2(_In_opt_ ID3D11ShaderResourceView* value);
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::unique_ptr pImpl;
+
+ // Prevent copying.
+ DualTextureEffect(DualTextureEffect const&);
+ DualTextureEffect& operator= (DualTextureEffect const&);
+ };
+
+
+
+ // 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 Apply(_In_ ID3D11DeviceContext* deviceContext) override;
+
+ void 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 SetAlpha(float value);
+
+ // Light settings.
+ void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
+
+ void 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 EnableDefaultLighting() override;
+
+ // Fog settings.
+ void SetFogEnabled(bool value) override;
+ void SetFogStart(float value) override;
+ void SetFogEnd(float value) override;
+ void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
+
+ // Texture setting.
+ void SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
+
+ // Environment map settings.
+ void SetEnvironmentMap(_In_opt_ ID3D11ShaderResourceView* value);
+ void SetEnvironmentMapAmount(float value);
+ void XM_CALLCONV SetEnvironmentMapSpecular(FXMVECTOR value);
+ void SetFresnelFactor(float value);
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::unique_ptr pImpl;
+
+ // Unsupported interface methods.
+ void SetLightingEnabled(bool value) override;
+ void SetPerPixelLighting(bool value) override;
+ void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
+
+ // Prevent copying.
+ EnvironmentMapEffect(EnvironmentMapEffect const&);
+ EnvironmentMapEffect& operator= (EnvironmentMapEffect const&);
+ };
+
+
+
+ // 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 Apply(_In_ ID3D11DeviceContext* deviceContext) override;
+
+ void 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 SetSpecularPower(float value);
+ void DisableSpecular();
+ void SetAlpha(float value);
+
+ // Light settings.
+ void SetPerPixelLighting(bool value) override;
+ void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
+
+ void 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 EnableDefaultLighting() override;
+
+ // Fog settings.
+ void SetFogEnabled(bool value) override;
+ void SetFogStart(float value) override;
+ void SetFogEnd(float value) override;
+ void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
+
+ // Texture setting.
+ void SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
+
+ // Animation settings.
+ void SetWeightsPerVertex(int value) override;
+ void SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override;
+ void ResetBoneTransforms() override;
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::unique_ptr pImpl;
+
+ // Unsupported interface method.
+ void SetLightingEnabled(bool value) override;
+
+ // Prevent copying.
+ SkinnedEffect(SkinnedEffect const&);
+ SkinnedEffect& operator= (SkinnedEffect const&);
+ };
+
+
+
+ //----------------------------------------------------------------------------------
+ // 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 Apply(_In_ ID3D11DeviceContext* deviceContext) override;
+
+ void 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 SetSpecularPower(float value);
+ void DisableSpecular();
+ void SetAlpha(float value);
+
+ // Additional settings.
+ void XM_CALLCONV SetUVTransform(FXMMATRIX value);
+ void SetViewport( float width, float height );
+ void SetTime( float time );
+ void SetAlphaDiscardEnable(bool value);
+
+ // Light settings.
+ void SetLightingEnabled(bool value) override;
+ void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
+
+ void 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 EnableDefaultLighting() override;
+
+ static const int MaxDirectionalLights = 4;
+
+ // Vertex color setting.
+ void SetVertexColorEnabled(bool value);
+
+ // Texture settings.
+ void SetTextureEnabled(bool value);
+ void SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
+ void SetTexture(int whichTexture, _In_opt_ ID3D11ShaderResourceView* value);
+
+ static const int MaxTextures = 8;
+
+ // Animation setting.
+ void SetWeightsPerVertex(int value) override;
+ void SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override;
+ void ResetBoneTransforms() override;
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::unique_ptr pImpl;
+
+ // Unsupported interface methods.
+ void SetPerPixelLighting(bool value) override;
+
+ // Prevent copying.
+ DGSLEffect(DGSLEffect const&);
+ DGSLEffect& operator= (DGSLEffect const&);
+ };
+
+
+
+ //----------------------------------------------------------------------------------
+ // Abstract interface to factory for sharing effects and texture resources
+ class IEffectFactory
+ {
+ public:
+ virtual ~IEffectFactory() {}
+
+ struct EffectInfo
+ {
+ const WCHAR* name;
+ bool perVertexColor;
+ bool enableSkinning;
+ float specularPower;
+ float alpha;
+ DirectX::XMFLOAT3 ambientColor;
+ DirectX::XMFLOAT3 diffuseColor;
+ DirectX::XMFLOAT3 specularColor;
+ DirectX::XMFLOAT3 emissiveColor;
+ const WCHAR* texture;
+
+ EffectInfo() { memset( this, 0, sizeof(EffectInfo) ); };
+ };
+
+ virtual std::shared_ptr CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) = 0;
+
+ virtual void 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 CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override;
+ virtual void CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override;
+
+ // Settings.
+ void ReleaseCache();
+
+ void SetSharing( bool enabled );
+
+ void SetDirectory( _In_opt_z_ const WCHAR* path );
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::shared_ptr pImpl;
+
+ // Prevent copying.
+ EffectFactory(EffectFactory const&);
+ EffectFactory& operator= (EffectFactory const&);
+ };
+
+
+ // 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();
+
+ // IEffectFactory methods.
+ virtual std::shared_ptr CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override;
+ virtual void CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override;
+
+ // DGSL methods.
+ struct DGSLEffectInfo : public EffectInfo
+ {
+ const WCHAR* textures[7];
+ const WCHAR* pixelShader;
+
+ DGSLEffectInfo() { memset( this, 0, sizeof(DGSLEffectInfo) ); };
+ };
+
+ virtual std::shared_ptr CreateDGSLEffect( _In_ const DGSLEffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext );
+
+ virtual void CreatePixelShader( _In_z_ const WCHAR* shader, _Outptr_ ID3D11PixelShader** pixelShader );
+
+ // Settings.
+ void ReleaseCache();
+
+ void SetSharing( bool enabled );
+
+ void SetDirectory( _In_opt_z_ const WCHAR* path );
+
+ private:
+ // Private implementation.
+ class Impl;
+
+ std::shared_ptr pImpl;
+
+ // Prevent copying.
+ DGSLEffectFactory(DGSLEffectFactory const&);
+ DGSLEffectFactory& operator= (DGSLEffectFactory const&);
+ };
+
+}
+
+#pragma warning(pop)
diff --git a/GUI/DirectXTK/GeometricPrimitive.h b/GUI/DirectXTK/GeometricPrimitive.h
new file mode 100644
index 00000000..94310a23
--- /dev/null
+++ b/GUI/DirectXTK/GeometricPrimitive.h
@@ -0,0 +1,77 @@
+//--------------------------------------------------------------------------------------
+// File: GeometricPrimitive.h
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// http://go.microsoft.com/fwlink/?LinkId=248929
+//--------------------------------------------------------------------------------------
+
+#pragma once
+
+#if defined(_XBOX_ONE) && defined(_TITLE) && MONOLITHIC
+#include
+#else
+#include
+#endif
+
+#include
+#include
+#include
+#include
+
+
+namespace DirectX
+{
+ #if (DIRECTXMATH_VERSION < 305) && !defined(XM_CALLCONV)
+ #define XM_CALLCONV __fastcall
+ typedef const XMVECTOR& HXMVECTOR;
+ typedef const XMMATRIX& FXMMATRIX;
+ #endif
+
+ class IEffect;
+
+ class GeometricPrimitive
+ {
+ public:
+ ~GeometricPrimitive();
+
+ // Factory methods.
+ static std::unique_ptr CreateCube (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
+ static std::unique_ptr CreateSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 16, bool rhcoords = true);
+ static std::unique_ptr CreateGeoSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 3, bool rhcoords = true);
+ static std::unique_ptr CreateCylinder (_In_ ID3D11DeviceContext* deviceContext, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true);
+ static std::unique_ptr CreateCone (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true);
+ static std::unique_ptr CreateTorus (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true);
+ static std::unique_ptr CreateTetrahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
+ static std::unique_ptr CreateOctahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
+ static std::unique_ptr CreateDodecahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
+ static std::unique_ptr CreateIcosahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
+ static std::unique_ptr CreateTeapot (_In_ ID3D11DeviceContext* deviceContext, float size = 1, size_t tessellation = 8, bool rhcoords = true);
+
+ // 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);
+
+ // Draw the primitive using a custom effect.
+ void Draw( _In_ IEffect* effect, _In_ ID3D11InputLayout* inputLayout, bool alpha = false, bool wireframe = false, _In_opt_ std::function setCustomState = nullptr );
+
+ // Create input layout for drawing with a custom effect.
+ void CreateInputLayout( _In_ IEffect* effect, _Outptr_ ID3D11InputLayout** inputLayout );
+
+ private:
+ GeometricPrimitive();
+
+ // Private implementation.
+ class Impl;
+
+ std::unique_ptr pImpl;
+
+ // Prevent copying.
+ GeometricPrimitive(GeometricPrimitive const&);
+ GeometricPrimitive& operator= (GeometricPrimitive const&);
+ };
+}
diff --git a/GUI/DirectXTK/Model.h b/GUI/DirectXTK/Model.h
new file mode 100644
index 00000000..ff2a5709
--- /dev/null
+++ b/GUI/DirectXTK/Model.h
@@ -0,0 +1,141 @@
+//--------------------------------------------------------------------------------------
+// File: Model.h
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// http://go.microsoft.com/fwlink/?LinkId=248929
+//--------------------------------------------------------------------------------------
+
+#pragma once
+
+#if defined(_XBOX_ONE) && defined(_TITLE) && MONOLITHIC
+#include
+#else
+#include
+#endif
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#pragma warning(push)
+#pragma warning(disable : 4005)
+#include
+#include
+#pragma warning(pop)
+
+#include
+
+namespace DirectX
+{
+ #if (DIRECTXMATH_VERSION < 305) && !defined(XM_CALLCONV)
+ #define XM_CALLCONV __fastcall
+ typedef const XMVECTOR& HXMVECTOR;
+ typedef const XMMATRIX& FXMMATRIX;
+ #endif
+
+ class IEffect;
+ class IEffectFactory;
+ class CommonStates;
+ class ModelMesh;
+
+ // Each mesh part is a submesh with a single effect
+ class ModelMeshPart
+ {
+ public:
+ 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;
+
+ typedef std::vector> Collection;
+
+ // Draw mesh part with custom effect
+ void Draw( _In_ ID3D11DeviceContext* deviceContext, _In_ IEffect* effect, _In_ ID3D11InputLayout* inputLayout,
+ _In_opt_ std::function setCustomState = nullptr ) const;
+
+ // Create input layout for drawing with a custom effect.
+ void CreateInputLayout( _In_ ID3D11Device* d3dDevice, _In_ IEffect* effect, _Outptr_ ID3D11InputLayout** inputLayout );
+
+ // Change effect used by part and regenerate input layout (be sure to call Model::Modified as well)
+ void ModifyEffect( _In_ ID3D11Device* d3dDevice, _In_ std::shared_ptr& effect, bool isalpha = false );
+ };
+
+
+ // A mesh consists of one or more model parts
+ class ModelMesh
+ {
+ public:
+ ModelMesh();
+
+ BoundingSphere boundingSphere;
+ BoundingBox boundingBox;
+ ModelMeshPart::Collection meshParts;
+ std::wstring name;
+ bool ccw;
+ bool pmalpha;
+
+ typedef std::vector> Collection;
+
+ // Setup states for drawing mesh
+ void 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;
+ };
+
+
+ // A model consists of one or more meshes
+ class Model
+ {
+ public:
+ 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;
+
+ // Notify model that effects, parts list, or mesh list has changed
+ void Modified() { mEffectCache.clear(); }
+
+ // Update all effects used by the model
+ void UpdateEffects( _In_ std::function setEffect );
+
+ // Loads a model from a Visual Studio Starter Kit .CMO file
+ static std::unique_ptr 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 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 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 CreateFromSDKMESH( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
+ _In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false );
+
+ private:
+ std::set mEffectCache;
+ };
+ }
\ No newline at end of file
diff --git a/GUI/DirectXTK/PrimitiveBatch.h b/GUI/DirectXTK/PrimitiveBatch.h
new file mode 100644
index 00000000..8e1ccc23
--- /dev/null
+++ b/GUI/DirectXTK/PrimitiveBatch.h
@@ -0,0 +1,147 @@
+//--------------------------------------------------------------------------------------
+// File: PrimitiveBatch.h
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// http://go.microsoft.com/fwlink/?LinkId=248929
+//--------------------------------------------------------------------------------------
+
+#pragma once
+
+#if defined(_XBOX_ONE) && defined(_TITLE) && MONOLITHIC
+#include
+#else
+#include
+#endif
+
+#include
+#include
+
+#pragma warning(push)
+#pragma warning(disable: 4005)
+#include
+#pragma warning(pop)
+
+
+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();
+
+ public:
+ // Begin/End a batch of primitive drawing operations.
+ void Begin();
+ void End();
+
+ protected:
+ // Internal, untyped drawing method.
+ void 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;
+
+ std::unique_ptr pImpl;
+
+ // Prevent copying.
+ PrimitiveBatchBase(PrimitiveBatchBase const&);
+ PrimitiveBatchBase& operator= (PrimitiveBatchBase const&);
+ };
+ }
+
+
+ // 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))
+ { }
+
+ PrimitiveBatch(PrimitiveBatch&& moveFrom)
+ : PrimitiveBatchBase(std::move(moveFrom))
+ { }
+
+ PrimitiveBatch& operator= (PrimitiveBatch&& moveFrom)
+ {
+ PrimitiveBatchBase::operator=(std::move(moveFrom));
+ return *this;
+ }
+
+
+ // Similar to the D3D9 API DrawPrimitiveUP.
+ void Draw(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount)
+ {
+ void* mappedVertices;
+
+ PrimitiveBatchBase::Draw(topology, false, nullptr, 0, vertexCount, &mappedVertices);
+
+ memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex));
+ }
+
+
+ // Similar to the D3D9 API DrawIndexedPrimitiveUP.
+ void 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);
+
+ memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex));
+ }
+
+
+ void DrawLine(TVertex const& v1, TVertex const& v2)
+ {
+ TVertex* mappedVertices;
+
+ PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_LINELIST, false, nullptr, 0, 2, reinterpret_cast(&mappedVertices));
+
+ mappedVertices[0] = v1;
+ mappedVertices[1] = v2;
+ }
+
+
+ void 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));
+
+ mappedVertices[0] = v1;
+ mappedVertices[1] = v2;
+ mappedVertices[2] = v3;
+ }
+
+
+ void 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;
+
+ 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;
+ }
+ };
+}
diff --git a/GUI/DirectXTK/ScreenGrab.h b/GUI/DirectXTK/ScreenGrab.h
new file mode 100644
index 00000000..7c8d8581
--- /dev/null
+++ b/GUI/DirectXTK/ScreenGrab.h
@@ -0,0 +1,57 @@
+//--------------------------------------------------------------------------------------
+// File: ScreenGrab.h
+//
+// Function for capturing a 2D texture and saving it to a file (aka a 'screenshot'
+// when used on a Direct3D 11 Render Target).
+//
+// Note these functions are useful as a light-weight runtime screen grabber. For
+// full-featured texture capture, DDS writer, and texture processing pipeline,
+// see the 'Texconv' sample and the 'DirectXTex' library.
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// http://go.microsoft.com/fwlink/?LinkId=248926
+// http://go.microsoft.com/fwlink/?LinkId=248929
+//--------------------------------------------------------------------------------------
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+#if defined(_XBOX_ONE) && defined(_TITLE) && MONOLITHIC
+#include
+#else
+#include
+#endif
+
+#include
+
+#pragma warning(push)
+#pragma warning(disable : 4005)
+#include
+#pragma warning(pop)
+
+#include
+
+namespace DirectX
+{
+ HRESULT 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 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/GUI/DirectXTK/SimpleMath.h b/GUI/DirectXTK/SimpleMath.h
new file mode 100644
index 00000000..dbe560c1
--- /dev/null
+++ b/GUI/DirectXTK/SimpleMath.h
@@ -0,0 +1,796 @@
+//-------------------------------------------------------------------------------------
+// SimpleMath.h -- Simplified C++ Math wrapper for DirectXMath
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// http://go.microsoft.com/fwlink/?LinkId=248929
+//-------------------------------------------------------------------------------------
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+#include
+#include
+
+#include "DirectXMath.h"
+#include "DirectXPackedVector.h"
+#include "DirectXCollision.h"
+
+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 ) {}
+ Vector2(float _x, float _y) : XMFLOAT2(_x, _y) {}
+ explicit Vector2(_In_reads_(2) const float *pArray) : XMFLOAT2(pArray) {}
+ Vector2(FXMVECTOR V) { XMStoreFloat2( this, V ); }
+
+ operator XMVECTOR() const { return XMLoadFloat2( this ); }
+
+ // Comparision 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 Vector2& V);
+ Vector2& operator-= (const Vector2& V);
+ Vector2& operator*= (const Vector2& V);
+ Vector2& operator*= (float S);
+ Vector2& operator/= (float S);
+
+ // Urnary 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 );
+};
+
+// 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 ); }
+
+ operator XMVECTOR() const { return XMLoadFloat3( this ); }
+
+ // Comparision 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 Vector3& V);
+ Vector3& operator-= (const Vector3& V);
+ Vector3& operator*= (const Vector3& V);
+ Vector3& operator*= (float S);
+ Vector3& operator/= (float S);
+
+ // Urnary 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 );
+};
+
+// 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 ); }
+
+ operator XMVECTOR() const { return XMLoadFloat4( this ); }
+
+ // Comparision 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 Vector4& V);
+ Vector4& operator-= (const Vector4& V);
+ Vector4& operator*= (const Vector4& V);
+ Vector4& operator*= (float S);
+ Vector4& operator/= (float S);
+
+ // Urnary 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 );
+};
+
+// 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 ) {}
+ explicit Matrix(_In_reads_(16) const float *pArray) : XMFLOAT4X4(pArray) {}
+ Matrix( CXMMATRIX M ) { XMStoreFloat4x4( this, M ); }
+
+ operator XMMATRIX() const { return XMLoadFloat4x4( this ); }
+
+ // Comparision 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 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
+
+ // Urnary 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 Identity();
+
+ 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 );
+};
+
+// 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 ); }
+
+ operator XMVECTOR() const { return XMLoadFloat4( this ); }
+
+ // Comparision 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; }
+
+ // 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 ); }
+
+ operator XMVECTOR() const { return XMLoadFloat4( this ); }
+
+ // Comparision 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 Quaternion& q);
+ Quaternion& operator-= (const Quaternion& q);
+ Quaternion& operator*= (const Quaternion& q);
+ Quaternion& operator*= (float S);
+ Quaternion& operator/= (const Quaternion& q);
+
+ // Urnary 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 );
+};
+
+// 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 ); }
+
+ 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); }
+
+ // Comparision 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 Color& c);
+ Color& operator-= (const Color& c);
+ Color& operator*= (const Color& c);
+ Color& operator*= (float S);
+ Color& operator/= (const Color& c);
+
+ // Urnary 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) {}
+
+ // Comparision 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;
+};
+
+#include "SimpleMath.inl"
+
+}; // 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::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::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;
+ }
+ };
+
+ 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::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;
+
+ 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;
+ }
+ };
+
+} // namespace std
diff --git a/GUI/DirectXTK/SimpleMath.inl b/GUI/DirectXTK/SimpleMath.inl
new file mode 100644
index 00000000..564d53c7
--- /dev/null
+++ b/GUI/DirectXTK/SimpleMath.inl
@@ -0,0 +1,3303 @@
+//-------------------------------------------------------------------------------------
+// SimpleMath.inl -- Simplified C++ Math wrapper for DirectXMath
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// http://go.microsoft.com/fwlink/?LinkId=248929
+//-------------------------------------------------------------------------------------
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+/****************************************************************************
+ *
+ * Vector2
+ *
+ ****************************************************************************/
+
+//------------------------------------------------------------------------------
+// Comparision operators
+//------------------------------------------------------------------------------
+
+inline bool Vector2::operator == ( const Vector2& V ) const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat2( this );
+ XMVECTOR v2 = XMLoadFloat2( &V );
+ return XMVector2Equal( v1, v2 );
+}
+
+inline bool Vector2::operator != ( const Vector2& V ) const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat2( this );
+ XMVECTOR v2 = XMLoadFloat2( &V );
+ return XMVector2NotEqual( v1, v2 );
+}
+
+//------------------------------------------------------------------------------
+// Assignment operators
+//------------------------------------------------------------------------------
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+inline Vector2& Vector2::operator*= (float S)
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat2( this );
+ XMVECTOR X = XMVectorScale(v1,S);
+ XMStoreFloat2( this, X );
+ return *this;
+}
+
+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;
+}
+
+//------------------------------------------------------------------------------
+// Binary operators
+//------------------------------------------------------------------------------
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+//------------------------------------------------------------------------------
+// Vector operations
+//------------------------------------------------------------------------------
+
+inline bool Vector2::InBounds( const Vector2& Bounds ) const
+{
+ 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 );
+}
+
+inline float Vector2::LengthSquared() const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat2( this );
+ XMVECTOR X = XMVector2LengthSq( v1 );
+ return XMVectorGetX( X );
+}
+
+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 );
+}
+
+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 );
+}
+
+inline Vector2 Vector2::Cross( const Vector2& V ) const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat2( this );
+ XMVECTOR v2 = XMLoadFloat2( &V );
+ XMVECTOR R = XMVector2Cross( v1, v2 );
+
+ 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 );
+}
+
+inline void Vector2::Normalize( Vector2& result ) const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat2( this );
+ XMVECTOR X = XMVector2Normalize( v1 );
+ XMStoreFloat2( &result, X );
+}
+
+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 );
+}
+
+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 );
+}
+
+//------------------------------------------------------------------------------
+// Static functions
+//------------------------------------------------------------------------------
+
+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 );
+}
+
+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 );
+}
+
+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 );
+}
+
+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 );
+
+ Vector2 result;
+ XMStoreFloat2( &result, X );
+ return 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 );
+}
+
+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 );
+
+ Vector2 result;
+ XMStoreFloat2( &result, X );
+ return 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 );
+}
+
+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 );
+
+ Vector2 result;
+ XMStoreFloat2( &result, X );
+ return 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 );
+}
+
+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 );
+
+ 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 )
+{
+ 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 )
+{
+ 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;
+}
+
+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 );
+}
+
+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 );
+
+ 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 )
+{
+ 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 )
+{
+ 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;
+}
+
+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 );
+}
+
+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 );
+
+ Vector2 result;
+ XMStoreFloat2( &result, X );
+ return 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 );
+}
+
+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 );
+
+ Vector2 result;
+ XMStoreFloat2( &result, X );
+ return 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 );
+}
+
+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 );
+
+ Vector2 result;
+ XMStoreFloat2( &result, X );
+ return 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 );
+}
+
+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 );
+
+ 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 )
+{
+ 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 )
+{
+ 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 )
+{
+ 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 )
+{
+ 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 )
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat2( &v );
+ XMMATRIX M = XMLoadFloat4x4( &m );
+ XMVECTOR X = XMVector2TransformNormal( v1, M );
+
+ 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 )
+{
+ using namespace DirectX;
+ XMMATRIX M = XMLoadFloat4x4( &m );
+ XMVector2TransformNormalStream( resultArray, sizeof(XMFLOAT2), varray, sizeof(XMFLOAT2), count, M );
+}
+
+
+/****************************************************************************
+ *
+ * Vector3
+ *
+ ****************************************************************************/
+
+//------------------------------------------------------------------------------
+// Comparision operators
+//------------------------------------------------------------------------------
+
+inline bool Vector3::operator == ( const Vector3& V ) const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat3( this );
+ XMVECTOR v2 = XMLoadFloat3( &V );
+ return XMVector3Equal( v1, v2 );
+}
+
+inline bool Vector3::operator != ( const Vector3& V ) const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat3( this );
+ XMVECTOR v2 = XMLoadFloat3( &V );
+ return XMVector3NotEqual( v1, v2 );
+}
+
+//------------------------------------------------------------------------------
+// Assignment operators
+//------------------------------------------------------------------------------
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+inline Vector3& Vector3::operator*= (float S)
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat3( this );
+ XMVECTOR X = XMVectorScale(v1,S);
+ XMStoreFloat3( this, X );
+ return *this;
+}
+
+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;
+}
+
+//------------------------------------------------------------------------------
+// Urnary operators
+//------------------------------------------------------------------------------
+
+inline Vector3 Vector3::operator- () const
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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
+{
+ 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 );
+}
+
+inline float Vector3::LengthSquared() const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat3( this );
+ XMVECTOR X = XMVector3LengthSq( v1 );
+ return XMVectorGetX( X );
+}
+
+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 );
+}
+
+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 );
+}
+
+inline Vector3 Vector3::Cross( const Vector3& V ) const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat3( this );
+ XMVECTOR v2 = XMLoadFloat3( &V );
+ XMVECTOR R = XMVector3Cross( v1, v2 );
+
+ 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 );
+}
+
+inline void Vector3::Normalize( Vector3& result ) const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat3( this );
+ XMVECTOR X = XMVector3Normalize( v1 );
+ XMStoreFloat3( &result, X );
+}
+
+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 );
+}
+
+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 );
+}
+
+//------------------------------------------------------------------------------
+// Static functions
+//------------------------------------------------------------------------------
+
+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 );
+}
+
+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 );
+}
+
+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 );
+}
+
+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 );
+
+ Vector3 result;
+ XMStoreFloat3( &result, X );
+ return 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 );
+}
+
+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 );
+
+ Vector3 result;
+ XMStoreFloat3( &result, X );
+ return 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 );
+}
+
+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 );
+
+ Vector3 result;
+ XMStoreFloat3( &result, X );
+ return 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 );
+}
+
+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 );
+
+ 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 )
+{
+ 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 )
+{
+ 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;
+}
+
+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 );
+}
+
+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 );
+
+ 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 )
+{
+ 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 )
+{
+ 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;
+}
+
+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 );
+}
+
+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 );
+
+ Vector3 result;
+ XMStoreFloat3( &result, X );
+ return 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 );
+}
+
+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 );
+
+ Vector3 result;
+ XMStoreFloat3( &result, X );
+ return 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 );
+}
+
+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 );
+
+ Vector3 result;
+ XMStoreFloat3( &result, X );
+ return 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 );
+}
+
+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 );
+
+ 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 )
+{
+ 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 )
+{
+ 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 )
+{
+ 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 )
+{
+ 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 )
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat3( &v );
+ XMMATRIX M = XMLoadFloat4x4( &m );
+ XMVECTOR X = XMVector3TransformNormal( v1, M );
+
+ 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 )
+{
+ using namespace DirectX;
+ XMMATRIX M = XMLoadFloat4x4( &m );
+ XMVector3TransformNormalStream( resultArray, sizeof(XMFLOAT3), varray, sizeof(XMFLOAT3), count, M );
+}
+
+
+/****************************************************************************
+ *
+ * Vector4
+ *
+ ****************************************************************************/
+
+//------------------------------------------------------------------------------
+// Comparision operators
+//------------------------------------------------------------------------------
+
+inline bool Vector4::operator == ( const Vector4& V ) const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat4( this );
+ XMVECTOR v2 = XMLoadFloat4( &V );
+ return XMVector4Equal( v1, v2 );
+}
+
+inline bool Vector4::operator != ( const Vector4& V ) const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat4( this );
+ XMVECTOR v2 = XMLoadFloat4( &V );
+ return XMVector4NotEqual( v1, v2 );
+}
+
+//------------------------------------------------------------------------------
+// Assignment operators
+//------------------------------------------------------------------------------
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+inline Vector4& Vector4::operator*= (float S)
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat4( this );
+ XMVECTOR X = XMVectorScale(v1,S);
+ XMStoreFloat4( this, X );
+ return *this;
+}
+
+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;
+}
+
+//------------------------------------------------------------------------------
+// Urnary operators
+//------------------------------------------------------------------------------
+
+inline Vector4 Vector4::operator- () const
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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
+{
+ 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 );
+}
+
+inline float Vector4::LengthSquared() const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat4( this );
+ XMVECTOR X = XMVector4LengthSq( v1 );
+ return XMVectorGetX( X );
+}
+
+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 );
+}
+
+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 );
+}
+
+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 );
+
+ 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 );
+}
+
+inline void Vector4::Normalize( Vector4& result ) const
+{
+ using namespace DirectX;
+ XMVECTOR v1 = XMLoadFloat4( this );
+ XMVECTOR X = XMVector4Normalize( v1 );
+ XMStoreFloat4( &result, X );
+}
+
+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 );
+}
+
+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 );
+}
+
+//------------------------------------------------------------------------------
+// Static functions
+//------------------------------------------------------------------------------
+
+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 );
+}
+
+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 );
+}
+
+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 );
+}
+
+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 );
+
+ Vector4 result;
+ XMStoreFloat4( &result, X );
+ return 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 );
+}
+
+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 );
+
+ Vector4 result;
+ XMStoreFloat4( &result, X );
+ return 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 );
+}
+
+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 );
+
+ Vector4 result;
+ XMStoreFloat4( &result, X );
+ return 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 );
+}
+
+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 );
+
+ 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 )
+{
+ 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 )
+{
+ 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;
+}
+
+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 );
+}
+
+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 );
+
+ 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 )
+{
+ 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 )
+{
+ 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;
+}
+
+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 );
+}
+
+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 );
+
+ Vector4 result;
+ XMStoreFloat4( &result, X );
+ return 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 );
+}
+
+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 );
+
+ Vector4 result;
+ XMStoreFloat4( &result, X );
+ return 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 );
+}
+
+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
+
+ Vector4 result;
+ XMStoreFloat4( &result, X );
+ return 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 );
+}
+
+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
+
+ Vector4 result;
+ XMStoreFloat4( &result, X );
+ return 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 );
+}
+
+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
+
+ Vector4 result;
+ XMStoreFloat4( &result, X );
+ return 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 );
+}
+
+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 );
+
+ 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 )
+{
+ using namespace DirectX;
+ XMMATRIX M = XMLoadFloat4x4( &m );
+ XMVector4TransformStream( resultArray, sizeof(XMFLOAT4), varray, sizeof(XMFLOAT4), count, M );
+}
+
+
+/****************************************************************************
+ *
+ * Matrix
+ *
+ ****************************************************************************/
+
+//------------------------------------------------------------------------------
+// Comparision operators
+//------------------------------------------------------------------------------
+
+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) );
+
+ 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;
+}
+
+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) );
+
+ 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;
+}
+
+//------------------------------------------------------------------------------
+// Assignment operators
+//------------------------------------------------------------------------------
+
+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) );
+
+ 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 );
+
+ 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)
+{
+ 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) );
+
+ 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;
+}
+
+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;
+}
+
+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) );
+
+ 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;
+}
+
+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) );
+
+ float rs = 1.f / S;
+
+ 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;
+}
+
+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) );
+
+ 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 );
+
+ 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
+{
+ 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 );
+
+ 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)
+{
+ 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