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

mouse translation dxmath

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