Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
PracticeDx
Commits
0da6faac
Commit
0da6faac
authored
Dec 23, 2022
by
Administrator
Browse files
add DirectXMath for rotation
parent
6f2417ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
PracticeDx/VertexShader.hlsl
View file @
0da6faac
...
...
@@ -6,7 +6,7 @@ struct VSOut
cbuffer
CBuf
{
row_major
matrix
transform
;
matrix
transform
;
};
VSOut
main
(
float2
pos
:
Position
,
float3
color
:
Color
)
...
...
PracticeDx/WinMain.cpp
View file @
0da6faac
...
...
@@ -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.3
f
/
0.4
f
;
float
angle
=
0.0
f
;
ConstantBuffer
cb
=
{
{
heightWidthRatio
*
std
::
cos
(
angle
),
-
std
::
sin
(
angle
),
0.0
f
,
0.0
f
,
heightWidthRatio
*
std
::
sin
(
angle
),
std
::
cos
(
angle
),
0.0
f
,
0.0
f
,
0.0
f
,
0.0
f
,
1.0
f
,
0.0
f
,
0.0
f
,
0.0
f
,
0
.0
f
,
1.0
f
,
}
// transpose the matrix to change from row_major to column_major
dx
::
XMMatrixTranspose
(
// rotate Z axis
dx
::
XMMatrixRotationZ
(
-
angle
)
*
dx
::
XMMatrixScaling
(
heightWidthRatio
,
1
.0
f
,
1.0
f
)
)
};
// 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.0
f
,
1.0
f
)
)
};
D3D11_BUFFER_DESC
cbd
=
{};
cbd
.
BindFlags
=
D3D11_BIND_CONSTANT_BUFFER
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment