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
StudyDx
Commits
7617146f
Commit
7617146f
authored
Dec 23, 2022
by
Administrator
Browse files
add DirectXMath
parent
afffc70c
Changes
4
Hide whitespace changes
Inline
Side-by-side
StudyDx/App.cpp
View file @
7617146f
...
@@ -25,6 +25,10 @@ void App::DoFrame()
...
@@ -25,6 +25,10 @@ void App::DoFrame()
{
{
const
float
c
=
sin
(
timer
.
Peek
())
/
2.0
f
+
0.5
f
;
const
float
c
=
sin
(
timer
.
Peek
())
/
2.0
f
+
0.5
f
;
wnd
.
Gfx
().
ClearBuffer
(
c
,
c
,
1.0
f
);
wnd
.
Gfx
().
ClearBuffer
(
c
,
c
,
1.0
f
);
wnd
.
Gfx
().
DrawTestTriangle
(
timer
.
Peek
()
);
wnd
.
Gfx
().
DrawTestTriangle
(
timer
.
Peek
(),
wnd
.
mouse
.
GetPosX
()
/
400.0
f
-
1.0
f
,
-
wnd
.
mouse
.
GetPosY
()
/
300.0
f
+
1.0
f
);
wnd
.
Gfx
().
EndFrame
();
wnd
.
Gfx
().
EndFrame
();
}
}
\ No newline at end of file
StudyDx/Graphics.cpp
View file @
7617146f
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
#include "dxerr.h"
#include "dxerr.h"
#include <sstream>
#include <sstream>
#include <d3dcompiler.h>
#include <d3dcompiler.h>
#include <DirectXMath.h>
namespace
dx
=
DirectX
;
namespace
wrl
=
Microsoft
::
WRL
;
namespace
wrl
=
Microsoft
::
WRL
;
...
@@ -102,7 +105,7 @@ void Graphics::ClearBuffer(float red, float green, float blue) noexcept
...
@@ -102,7 +105,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
)
{
{
namespace
wrl
=
Microsoft
::
WRL
;
namespace
wrl
=
Microsoft
::
WRL
;
HRESULT
hr
;
HRESULT
hr
;
...
@@ -179,21 +182,23 @@ void Graphics::DrawTestTriangle(float angle)
...
@@ -179,21 +182,23 @@ void Graphics::DrawTestTriangle(float angle)
// Create constant buffer for transformation matrix
// Create constant buffer for transformation matrix
struct
ConstantBuffer
struct
ConstantBuffer
{
{
struct
// Use extended mathematics matrix which is optmized for SIMD
{
// SIMD (Single Instruction Multiple Data) is available in mordern processors
float
element
[
4
][
4
];
dx
::
XMMATRIX
transform
;
}
transformation
;
};
};
const
float
heightWidthRatio
=
0.3
f
/
0.4
f
;
const
float
heightWidthRatio
=
0.3
f
/
0.4
f
;
const
ConstantBuffer
cb
=
const
ConstantBuffer
cb
=
{
{
{
// transpose the matrix to change from row_major to column_major
heightWidthRatio
*
std
::
cos
(
angle
),
-
std
::
sin
(
angle
),
0.0
f
,
0.0
f
,
dx
::
XMMatrixTranspose
(
heightWidthRatio
*
std
::
sin
(
angle
),
std
::
cos
(
angle
),
0.0
f
,
0.0
f
,
// rotate Z axis
0.0
f
,
0.0
f
,
1.0
f
,
0.0
f
,
dx
::
XMMatrixRotationZ
(
-
angle
)
0.0
f
,
0.0
f
,
0.0
f
,
1.0
f
,
// scale to avoid distortion
}
*
dx
::
XMMatrixScaling
(
3.0
f
/
4.0
f
,
1.0
f
,
1.0
f
)
// attach the image to mouse
*
dx
::
XMMatrixTranslation
(
x
,
y
,
0.0
f
)
)
};
};
wrl
::
ComPtr
<
ID3D11Buffer
>
pConstantBuffer
;
wrl
::
ComPtr
<
ID3D11Buffer
>
pConstantBuffer
;
D3D11_BUFFER_DESC
cbd
=
{};
D3D11_BUFFER_DESC
cbd
=
{};
...
...
StudyDx/Graphics.h
View file @
7617146f
...
@@ -53,7 +53,7 @@ public:
...
@@ -53,7 +53,7 @@ public:
void
EndFrame
();
void
EndFrame
();
// 刷新RGB
// 刷新RGB
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
;
...
...
StudyDx/VertexShader.hlsl
View file @
7617146f
...
@@ -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
)
...
...
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