Commit 6a82d758 authored by chili's avatar chili
Browse files

mouse translation dxmath

parent 109d48f3
......@@ -23,6 +23,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
......@@ -3,8 +3,10 @@
#include <sstream>
#include <d3dcompiler.h>
#include <cmath>
#include <DirectXMath.h>
namespace wrl = Microsoft::WRL;
namespace dx = DirectX;
#pragma comment(lib,"d3d11.lib")
#pragma comment(lib,"D3DCompiler.lib")
......@@ -99,7 +101,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 )
{
HRESULT hr;
......@@ -175,18 +177,16 @@ void Graphics::DrawTestTriangle( float angle )
// create constant buffer for transformation matrix
struct ConstantBuffer
{
struct
{
float element[4][4];
} transformation;
dx::XMMATRIX transform;
};
const ConstantBuffer cb =
{
{
(3.0f / 4.0f) * std::cos( angle ), std::sin( angle ), 0.0f, 0.0f,
(3.0f / 4.0f) * -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,
dx::XMMatrixTranspose(
dx::XMMatrixRotationZ( angle ) *
dx::XMMatrixScaling( 3.0f / 4.0f,1.0f,1.0f ) *
dx::XMMatrixTranslation( x,y,0.0f )
)
}
};
wrl::ComPtr<ID3D11Buffer> pConstantBuffer;
......
......@@ -52,7 +52,7 @@ public:
~Graphics() = default;
void EndFrame();
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