Commit 7617146f authored by Administrator's avatar Administrator
Browse files

add DirectXMath

parent afffc70c
...@@ -25,6 +25,10 @@ void App::DoFrame() ...@@ -25,6 +25,10 @@ void App::DoFrame()
{ {
const float c = sin(timer.Peek()) / 2.0f + 0.5f; const float c = sin(timer.Peek()) / 2.0f + 0.5f;
wnd.Gfx().ClearBuffer(c, c, 1.0f); wnd.Gfx().ClearBuffer(c, c, 1.0f);
wnd.Gfx().DrawTestTriangle( timer.Peek() ); wnd.Gfx().DrawTestTriangle(
timer.Peek(),
wnd.mouse.GetPosX() / 400.0f - 1.0f,
- wnd.mouse.GetPosY() / 300.0f + 1.0f
);
wnd.Gfx().EndFrame(); wnd.Gfx().EndFrame();
} }
\ No newline at end of file
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
#include "dxerr.h" #include "dxerr.h"
#include <sstream> #include <sstream>
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <DirectXMath.h>
namespace dx = DirectX;
namespace wrl = Microsoft::WRL; namespace wrl = Microsoft::WRL;
...@@ -102,7 +105,7 @@ void Graphics::ClearBuffer(float red, float green, float blue) noexcept ...@@ -102,7 +105,7 @@ void Graphics::ClearBuffer(float red, float green, float blue) noexcept
pContext->ClearRenderTargetView(pTarget.Get(), color); pContext->ClearRenderTargetView(pTarget.Get(), color);
} }
void Graphics::DrawTestTriangle(float angle) void Graphics::DrawTestTriangle(float angle, float x, float y)
{ {
namespace wrl = Microsoft::WRL; namespace wrl = Microsoft::WRL;
HRESULT hr; HRESULT hr;
...@@ -179,21 +182,23 @@ void Graphics::DrawTestTriangle(float angle) ...@@ -179,21 +182,23 @@ void Graphics::DrawTestTriangle(float angle)
// Create constant buffer for transformation matrix // Create constant buffer for transformation matrix
struct ConstantBuffer struct ConstantBuffer
{ {
struct // Use extended mathematics matrix which is optmized for SIMD
{ // SIMD (Single Instruction Multiple Data) is available in mordern processors
float element[4][4]; dx::XMMATRIX transform;
} transformation;
}; };
const float heightWidthRatio = 0.3f / 0.4f; const float heightWidthRatio = 0.3f / 0.4f;
const ConstantBuffer cb = const ConstantBuffer cb =
{ {
{ // transpose the matrix to change from row_major to column_major
heightWidthRatio * std::cos(angle), -std::sin(angle), 0.0f, 0.0f, dx::XMMatrixTranspose(
heightWidthRatio * std::sin(angle), std::cos(angle), 0.0f, 0.0f, // rotate Z axis
0.0f, 0.0f, 1.0f, 0.0f, dx::XMMatrixRotationZ(-angle)
0.0f, 0.0f, 0.0f, 1.0f, // scale to avoid distortion
} * dx::XMMatrixScaling(3.0f / 4.0f, 1.0f, 1.0f)
// attach the image to mouse
* dx::XMMatrixTranslation( x, y, 0.0f )
)
}; };
wrl::ComPtr<ID3D11Buffer> pConstantBuffer; wrl::ComPtr<ID3D11Buffer> pConstantBuffer;
D3D11_BUFFER_DESC cbd = {}; D3D11_BUFFER_DESC cbd = {};
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
void EndFrame(); void EndFrame();
// 刷新RGB // 刷新RGB
void ClearBuffer(float red, float green, float blue) noexcept; void ClearBuffer(float red, float green, float blue) noexcept;
void DrawTestTriangle(float angle); void DrawTestTriangle(float angle, float x, float y);
private: private:
#ifndef NDEBUG #ifndef NDEBUG
DxgiInfoManager infoManager; DxgiInfoManager infoManager;
......
...@@ -6,7 +6,7 @@ struct VSOut ...@@ -6,7 +6,7 @@ struct VSOut
cbuffer CBuf cbuffer CBuf
{ {
row_major matrix transform; matrix transform;
}; };
VSOut main( float2 pos : Position, float3 color : Color ) VSOut main( float2 pos : Position, float3 color : Color )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment