Commit 0da6faac authored by Administrator's avatar Administrator
Browse files

add DirectXMath for rotation

parent 6f2417ad
...@@ -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)
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include <wrl.h> #include <wrl.h>
#include <DirectXMath.h>
namespace dx = DirectX;
#include <array> // to usd std::size #include <array> // to usd std::size
#include <cmath> // to use std::sin and std::cos #include <cmath> // to use std::sin and std::cos
#include "Timer.h" // to use timer #include "Timer.h" // to use timer
...@@ -72,22 +76,19 @@ Microsoft::WRL::ComPtr<ID3D11Buffer> pConstantBuffer; ...@@ -72,22 +76,19 @@ Microsoft::WRL::ComPtr<ID3D11Buffer> pConstantBuffer;
// Create constant buffer struct // Create constant buffer struct
struct ConstantBuffer struct ConstantBuffer
{ {
struct dx::XMMATRIX transform;
{
float element[4][4];
} transformation;
}; };
// create constant buffer // create constant buffer
const float heightWidthRatio = 0.3f / 0.4f; const float heightWidthRatio = 0.3f / 0.4f;
float angle = 0.0f; float angle = 0.0f;
ConstantBuffer cb = 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, * dx::XMMatrixScaling(heightWidthRatio, 1.0f, 1.0f)
} )
}; };
// Define input layout // Define input layout
...@@ -128,10 +129,15 @@ void DefineVertexBuffer() ...@@ -128,10 +129,15 @@ void DefineVertexBuffer()
void DefineConstantBuffer(float angle) void DefineConstantBuffer(float angle)
{ {
cb.transformation.element[0][0] = heightWidthRatio * std::cos(angle); cb =
cb.transformation.element[0][1] = -std::sin(angle); {
cb.transformation.element[1][0] = heightWidthRatio * std::sin(angle); // transpose the matrix to change from row_major to column_major
cb.transformation.element[1][1] = std::cos(angle); dx::XMMatrixTranspose(
// rotate Z axis
dx::XMMatrixRotationZ(-angle)
* dx::XMMatrixScaling(heightWidthRatio, 1.0f, 1.0f)
)
};
D3D11_BUFFER_DESC cbd = {}; D3D11_BUFFER_DESC cbd = {};
cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
......
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