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

add DirectXMath

parent afffc70c
......@@ -25,6 +25,10 @@ void App::DoFrame()
{
const float c = sin(timer.Peek()) / 2.0f + 0.5f;
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();
}
\ No newline at end of file
......@@ -2,6 +2,9 @@
#include "dxerr.h"
#include <sstream>
#include <d3dcompiler.h>
#include <DirectXMath.h>
namespace dx = DirectX;
namespace wrl = Microsoft::WRL;
......@@ -102,7 +105,7 @@ void Graphics::ClearBuffer(float red, float green, float blue) noexcept
pContext->ClearRenderTargetView(pTarget.Get(), color);
}
void Graphics::DrawTestTriangle(float angle)
void Graphics::DrawTestTriangle(float angle, float x, float y)
{
namespace wrl = Microsoft::WRL;
HRESULT hr;
......@@ -179,21 +182,23 @@ void Graphics::DrawTestTriangle(float angle)
// Create constant buffer for transformation matrix
struct ConstantBuffer
{
struct
{
float element[4][4];
} transformation;
// Use extended mathematics matrix which is optmized for SIMD
// SIMD (Single Instruction Multiple Data) is available in mordern processors
dx::XMMATRIX transform;
};
const float heightWidthRatio = 0.3f / 0.4f;
const ConstantBuffer cb =
{
{
heightWidthRatio * std::cos(angle), -std::sin(angle), 0.0f, 0.0f,
heightWidthRatio * std::sin(angle), std::cos(angle), 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
}
// transpose the matrix to change from row_major to column_major
dx::XMMatrixTranspose(
// rotate Z axis
dx::XMMatrixRotationZ(-angle)
// 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;
D3D11_BUFFER_DESC cbd = {};
......
......@@ -53,7 +53,7 @@ public:
void EndFrame();
// 刷新RGB
void ClearBuffer(float red, float green, float blue) noexcept;
void DrawTestTriangle(float angle);
void DrawTestTriangle(float angle, float x, float y);
private:
#ifndef NDEBUG
DxgiInfoManager infoManager;
......
......@@ -6,7 +6,7 @@ struct VSOut
cbuffer CBuf
{
row_major matrix transform;
matrix transform;
};
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