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

add DirectXMath for rotation

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