Commit eeab8990 authored by Administrator's avatar Administrator
Browse files

added texture. need to debug for multipe images in same section.

parent c1f64ca7
...@@ -11,66 +11,72 @@ ...@@ -11,66 +11,72 @@
#include "TransformCBuf.h" #include "TransformCBuf.h"
#include "Graphics.h" #include "Graphics.h"
#include <DirectXMath.h> #include <DirectXMath.h>
#include "Texture.h"
#include "Sampler.h"
Box::Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger) Box::Box(Graphics& gfx, StructVertex vertices[], Logger& logger)
{ {
// Assign position values // Assign values for vertex and texture
for (int i = 0; i < 8; i++) /*for (int i = 0; i < 24; i++)
{ {
for (int j = 0; j < 3; j++) this->vertices[i] = vertices[i];
{ }*/
this->position[i][j] = position[i][j];
}
}
/************************************ /************************************
* 2.3 DefineVertexBuffer * 2.3 DefineVertexBuffer
************************************/ ************************************/
const std::vector<StructVertex> vertices = const std::vector<StructVertex> vb =
{
{ position[0][0], position[0][1], position[0][2] },
{ position[1][0], position[1][1], position[1][2] },
{ position[2][0], position[2][1], position[2][2] },
{ position[3][0], position[3][1], position[3][2] },
{ position[4][0], position[4][1], position[4][2] },
{ position[5][0], position[5][1], position[5][2] },
{ position[6][0], position[6][1], position[6][2] },
{ position[7][0], position[7][1], position[7][2] },
};
AddBind(std::make_unique<VertexBuffer>(gfx, vertices, logger));
// Assign color values
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 3; j++)
{
this->color[i][j] = color[i][j];
}
}
/************************************
* 2.6 DefineColorConstBuffer(PixelConstBuf)
************************************/
const StructPixelConstBuf cb2 =
{
{ {
{ color[0][0], color[0][1], color[0][2] }, { vertices[0] },
{ color[0][0], color[0][1], color[0][2] }, { vertices[1] },
{ color[1][0], color[1][1], color[1][2] }, { vertices[2] },
{ color[1][0], color[1][1], color[1][2] }, { vertices[3] },
{ color[2][0], color[2][1], color[2][2] }, { vertices[4] },
{ color[2][0], color[2][1], color[2][2] }, { vertices[5] },
{ color[3][0], color[3][1], color[3][2] }, { vertices[6] },
{ color[3][0], color[3][1], color[3][2] }, { vertices[7] },
{ color[4][0], color[4][1], color[4][2] }, { vertices[8] },
{ color[4][0], color[4][1], color[4][2] }, { vertices[9] },
{ color[5][0], color[5][1], color[5][2] }, { vertices[10] },
{ color[5][0], color[5][1], color[5][2] }, { vertices[11] },
} { vertices[12] },
{ vertices[13] },
{ vertices[14] },
{ vertices[15] },
{ vertices[16] },
{ vertices[17] },
{ vertices[18] },
{ vertices[19] },
{ vertices[20] },
{ vertices[21] },
{ vertices[22] },
{ vertices[23] },
}; };
AddBind(std::make_unique<PixelConstantBuffer<StructPixelConstBuf>>(gfx, cb2)); AddBind(std::make_unique<VertexBuffer>(gfx, vb, logger));
///************************************
//* 2.6 DefineColorConstBuffer(PixelConstBuf)
//************************************/
//const StructPixelConstBuf cb2 =
//{
// {
// { color[0][0], color[0][1], color[0][2] },
// { color[0][0], color[0][1], color[0][2] },
// { color[1][0], color[1][1], color[1][2] },
// { color[1][0], color[1][1], color[1][2] },
// { color[2][0], color[2][1], color[2][2] },
// { color[2][0], color[2][1], color[2][2] },
// { color[3][0], color[3][1], color[3][2] },
// { color[3][0], color[3][1], color[3][2] },
// { color[4][0], color[4][1], color[4][2] },
// { color[4][0], color[4][1], color[4][2] },
// { color[5][0], color[5][1], color[5][2] },
// { color[5][0], color[5][1], color[5][2] },
// }
//};
//AddBind(std::make_unique<PixelConstantBuffer<StructPixelConstBuf>>(gfx, cb2));
/************************************ /************************************
* 2.5 DefineTransConstBuffer * 2.5 DefineTransConstBuffer
...@@ -82,7 +88,8 @@ Box::Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger) ...@@ -82,7 +88,8 @@ Box::Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger)
/************************************ /************************************
* 2.7 DefineVertexShader * 2.7 DefineVertexShader
************************************/ ************************************/
auto pVertexShader = std::make_unique<VertexShader>(gfx, L"VertexShader.cso"); //auto pVertexShader = std::make_unique<VertexShader>(gfx, L"VertexShader.cso");
auto pVertexShader = std::make_unique<VertexShader>(gfx, L"TextureVS.cso");
auto pvsbc = pVertexShader->GetBytecode(); auto pvsbc = pVertexShader->GetBytecode();
//AddBind(std::move(pVertexShader)); //AddBind(std::move(pVertexShader));
AddStaticBind(std::move(pVertexShader)); AddStaticBind(std::move(pVertexShader));
...@@ -91,19 +98,20 @@ Box::Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger) ...@@ -91,19 +98,20 @@ Box::Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger)
* 2.8 DefinePixelShader * 2.8 DefinePixelShader
************************************/ ************************************/
//AddBind(std::make_unique<PixelShader>(gfx, L"PixelShader.cso")); //AddBind(std::make_unique<PixelShader>(gfx, L"PixelShader.cso"));
AddStaticBind(std::make_unique<PixelShader>(gfx, L"PixelShader.cso")); //AddStaticBind(std::make_unique<PixelShader>(gfx, L"PixelShader.cso"));
AddStaticBind(std::make_unique<PixelShader>(gfx, L"TexturePS.cso"));
/************************************ /************************************
* 2.4 DefineIndexBuffer * 2.4 DefineIndexBuffer
************************************/ ************************************/
const std::vector<unsigned short> indices = const std::vector<unsigned short> indices =
{ {
0,2,1, 2,3,1, 0,1,2, 2,1,3,
1,3,5, 3,7,5, 4,5,6, 6,5,7,
2,6,3, 3,6,7, 8,9,10, 10,9,11,
4,5,7, 4,7,6, 12,13,14, 14,13,15,
0,4,2, 2,4,6, 16,17,18, 18,17,19,
0,1,4, 1,5,4 20,21,22, 22,21,23,
}; };
//AddIndexBuffer(std::make_unique<IndexBuffer>(gfx, indices, logger)); //AddIndexBuffer(std::make_unique<IndexBuffer>(gfx, indices, logger));
...@@ -114,7 +122,10 @@ Box::Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger) ...@@ -114,7 +122,10 @@ Box::Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger)
************************************/ ************************************/
const std::vector<D3D11_INPUT_ELEMENT_DESC> ied = const std::vector<D3D11_INPUT_ELEMENT_DESC> ied =
{ {
//{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 }, { "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{ "TexCoord",0,DXGI_FORMAT_R32G32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0 },
{ "ImageSlot",0,DXGI_FORMAT_R32_UINT ,0,20,D3D11_INPUT_PER_VERTEX_DATA,0 },
}; };
//AddBind(std::make_unique<InputLayout>(gfx, ied, pvsbc)); //AddBind(std::make_unique<InputLayout>(gfx, ied, pvsbc));
AddStaticBind(std::make_unique<InputLayout>(gfx, ied, pvsbc)); AddStaticBind(std::make_unique<InputLayout>(gfx, ied, pvsbc));
...@@ -124,6 +135,18 @@ Box::Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger) ...@@ -124,6 +135,18 @@ Box::Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger)
************************************/ ************************************/
//AddBind(std::make_unique<Topology>(gfx, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST)); //AddBind(std::make_unique<Topology>(gfx, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST));
AddStaticBind(std::make_unique<Topology>(gfx, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST)); AddStaticBind(std::make_unique<Topology>(gfx, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST));
///************************************
//* 2.21 DefineTextureForEachSurface
//************************************/
//for (int i = 0; i < 6; i++) {
// AddStaticBind(std::make_unique<Texture>(gfx, surface[i]));
//}
/************************************
* 2.22 DefineSampler
************************************/
AddStaticBind(std::make_unique<Sampler>(gfx));
} }
else else
{ {
......
#pragma once #pragma once
#include "DrawableBase.h" #include "DrawableBase.h"
#include "Logger.h" #include "Logger.h"
#include "Structs.h"
#include "Surface.h"
class Box : public DrawableBase<Box> class Box : public DrawableBase<Box>
{ {
public: public:
Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger); Box(Graphics& gfx, StructVertex vertices[], Logger& logger);
void Update(float dt) noexcept override; void Update(float dt) noexcept override;
//void UpdateCamera(float sin, float cos) noexcept; //void UpdateCamera(float sin, float cos) noexcept;
//void SetCamera(DirectX::XMVECTOR upDirection, DirectX::XMVECTOR eyePosition, DirectX::XMVECTOR focusPosition) noexcept; //void SetCamera(DirectX::XMVECTOR upDirection, DirectX::XMVECTOR eyePosition, DirectX::XMVECTOR focusPosition) noexcept;
DirectX::XMMATRIX GetTransformXM() const noexcept override; DirectX::XMMATRIX GetTransformXM() const noexcept override;
private: private:
// positional //StructVertex vertices[24];
float position[8][3];
// color
float color[6][3];
// trasformation // trasformation
float dx = 0.0f; float dx = 0.0f;
float dy = 0.0f; float dy = 0.0f;
......
#pragma once #pragma once
#include "Ground.h" #include "Ground.h"
#include "Surface.h"
#include "Structs.h"
Ground::Ground(Graphics & gfx, Logger & logger) noexcept Ground::Ground(Graphics & gfx, Logger & logger) noexcept
{ {
// Init a 11 X 11 area as ground // Init 2 surfaces
for (int i = -5; i < 6; i++) Surface *yueyueSurface = new Surface();
{ yueyueSurface->LoadImageFromFile(gfx.getDevice(), gfx.getContext(), "resource\\img\\yueyue2.jpg");
for (int j = -5; j < 6; j++) UINT yueyueSlot = yueyueSurface->GetCurrSlot();
{
float boxPos[8][3] = Surface *ethanSurface = new Surface();
ethanSurface->LoadImageFromFile(gfx.getDevice(), gfx.getContext(), "resource\\img\\Ethan.png");
UINT ethanSlot = ethanSurface->GetCurrSlot();
for (int i = 0; i < 2; i+=2 )
for (int j = 0; j < 2; j+= 2)
{ {
// left bottom back
{ -1.0f + i, -1.0f, -1.0f + j }, StructVertex vertices[24] = {
// right bottom back
{ 1.0f + i, -1.0f, -1.0f + j }, // back surface
// left top back // left top back
{ -1.0f + i, 1.0f, -1.0f + j }, { XMFLOAT3(-1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(0.0f, 0.0f), yueyueSlot },
// right top back // right top back
{ 1.0f + i, 1.0f, -1.0f + j }, { XMFLOAT3(1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(1.0f, 0.0f), yueyueSlot },
// left bottom back
{ XMFLOAT3(-1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(0.0f, 1.0f), yueyueSlot },
// right bottom back
{ XMFLOAT3(1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(1.0f, 1.0f), yueyueSlot },
// left surface
// left top front
{ XMFLOAT3(-1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(0.0f, 0.0f), ethanSlot },
// left top back
{ XMFLOAT3(-1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(1.0f, 0.0f), ethanSlot },
// left bottom front // left bottom front
{ -1.0f + i, -1.0f, 1.0f + j }, { XMFLOAT3(-1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(0.0f, 1.0f), ethanSlot },
// left bottom back
{ XMFLOAT3(-1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(1.0f, 1.0f), ethanSlot },
// right surface
// right top back
{ XMFLOAT3(1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(0.0f, 0.0f), ethanSlot },
// right top front
{ XMFLOAT3(1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(1.0f, 0.0f), ethanSlot },
// right bottom back
{ XMFLOAT3(1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(0.0f, 1.0f), ethanSlot },
// right bottom front // right bottom front
{ 1.0f + i, -1.0f, 1.0f + j }, { XMFLOAT3(1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(1.0f, 1.0f), ethanSlot },
// top surface
// left top front // left top front
{ -1.0f + i, 1.0f, 1.0f + j }, { XMFLOAT3(-1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(0.0f, 0.0f), yueyueSlot },
// right top front // right top front
{ 1.0f + i, 1.0f, 1.0f + j }, { XMFLOAT3(1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(1.0f, 0.0f), yueyueSlot },
}; // left top back
float boxCol[6][3] = { XMFLOAT3(-1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(0.0f, 1.0f), yueyueSlot },
{ // right top back
{ 0.0f, 1.0f, 0.0f }, // Green { XMFLOAT3(1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(1.0f, 1.0f), yueyueSlot },
{ 1.0f, 1.0f, 0.0f }, // Yellow
{ 1.0f, 0.0f, 0.0f }, // Red // front surface
{ 0.0f, 0.0f, 1.0f }, // Blue // right top front
{ 0.0f, 1.0f, 1.0f }, // Cyan { XMFLOAT3(1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(0.0f, 0.0f), yueyueSlot },
{ 1.0f, 0.0f, 1.0f }, // Magenta // left top front
{ XMFLOAT3(-1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(1.0f, 0.0f), yueyueSlot },
// right bottom front
{ XMFLOAT3(1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(0.0f, 1.0f), yueyueSlot },
// left bottom front
{ XMFLOAT3(-1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(1.0f, 1.0f), yueyueSlot },
// bottom surface
// left bottom back
{ XMFLOAT3(-1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(0.0f, 0.0f), ethanSlot },
// right bottom back
{ XMFLOAT3(1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(1.0f, 0.0f), ethanSlot },
// left bottom front
{ XMFLOAT3(-1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(0.0f, 1.0f), ethanSlot },
// right bottom front
{ XMFLOAT3(1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(1.0f, 1.0f), ethanSlot },
}; };
shapes.push_back(std::make_unique<Box>(gfx, boxPos, boxCol, logger)); shapes.push_back(std::make_unique<Box>(gfx, vertices, logger));
}
} }
// Init a 11 X 11 area as ground
//for (int i = -5; i < 6; i++)
//{
// for (int j = -5; j < 6; j++)
// {
// float boxPos[8][3] =
// {
// // left bottom back
// { -1.0f + i, -1.0f, -1.0f + j },
// // right bottom back
// { 1.0f + i, -1.0f, -1.0f + j },
// // left top back
// { -1.0f + i, 1.0f, -1.0f + j },
// // right top back
// { 1.0f + i, 1.0f, -1.0f + j },
// // left bottom front
// { -1.0f + i, -1.0f, 1.0f + j },
// // right bottom front
// { 1.0f + i, -1.0f, 1.0f + j },
// // left top front
// { -1.0f + i, 1.0f, 1.0f + j },
// // right top front
// { 1.0f + i, 1.0f, 1.0f + j },
// };
// float boxCol[6][3] =
// {
// { 0.0f, 1.0f, 0.0f }, // Green
// { 1.0f, 1.0f, 0.0f }, // Yellow
// { 1.0f, 0.0f, 0.0f }, // Red
// { 0.0f, 0.0f, 1.0f }, // Blue
// { 0.0f, 1.0f, 1.0f }, // Cyan
// { 1.0f, 0.0f, 1.0f }, // Magenta
// };
// shapes.push_back(std::make_unique<Box>(gfx, boxPos, boxCol, logger));
// }
//}
//float boxPos2[8][3] = //float boxPos2[8][3] =
//{ //{
// // left bottom back // // left bottom back
......
...@@ -134,11 +134,14 @@ ...@@ -134,11 +134,14 @@
<ClCompile Include="DrawableBase.cpp" /> <ClCompile Include="DrawableBase.cpp" />
<ClCompile Include="Graphics.cpp" /> <ClCompile Include="Graphics.cpp" />
<ClCompile Include="Ground.cpp" /> <ClCompile Include="Ground.cpp" />
<ClCompile Include="Sampler.cpp" />
<ClCompile Include="Surface.cpp" />
<ClCompile Include="IndexBuffer.cpp" /> <ClCompile Include="IndexBuffer.cpp" />
<ClCompile Include="InputLayout.cpp" /> <ClCompile Include="InputLayout.cpp" />
<ClCompile Include="Logger.cpp" /> <ClCompile Include="Logger.cpp" />
<ClCompile Include="PixelShader.cpp" /> <ClCompile Include="PixelShader.cpp" />
<ClCompile Include="Section.cpp" /> <ClCompile Include="Section.cpp" />
<ClCompile Include="Texture.cpp" />
<ClCompile Include="Timer.cpp" /> <ClCompile Include="Timer.cpp" />
<ClCompile Include="Topology.cpp" /> <ClCompile Include="Topology.cpp" />
<ClCompile Include="TransformCBuf.cpp" /> <ClCompile Include="TransformCBuf.cpp" />
...@@ -158,6 +161,16 @@ ...@@ -158,6 +161,16 @@
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0</ShaderModel> <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.0</ShaderModel> <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.0</ShaderModel>
</FxCompile> </FxCompile>
<FxCompile Include="TexturePS.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)%(Filename).cso</ObjectFileOutput>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="TextureVS.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)%(Filename).cso</ObjectFileOutput>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="VertexShader.hlsl"> <FxCompile Include="VertexShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
...@@ -174,12 +187,15 @@ ...@@ -174,12 +187,15 @@
<ClInclude Include="DrawableBase.h" /> <ClInclude Include="DrawableBase.h" />
<ClInclude Include="Graphics.h" /> <ClInclude Include="Graphics.h" />
<ClInclude Include="Ground.h" /> <ClInclude Include="Ground.h" />
<ClInclude Include="Sampler.h" />
<ClInclude Include="Surface.h" />
<ClInclude Include="IndexBuffer.h" /> <ClInclude Include="IndexBuffer.h" />
<ClInclude Include="InputLayout.h" /> <ClInclude Include="InputLayout.h" />
<ClInclude Include="Logger.h" /> <ClInclude Include="Logger.h" />
<ClInclude Include="PixelShader.h" /> <ClInclude Include="PixelShader.h" />
<ClInclude Include="Section.h" /> <ClInclude Include="Section.h" />
<ClInclude Include="Structs.h" /> <ClInclude Include="Structs.h" />
<ClInclude Include="Texture.h" />
<ClInclude Include="Timer.h" /> <ClInclude Include="Timer.h" />
<ClInclude Include="Topology.h" /> <ClInclude Include="Topology.h" />
<ClInclude Include="TransformCBuf.h" /> <ClInclude Include="TransformCBuf.h" />
......
#include "Sampler.h"
Sampler::Sampler(Graphics& gfx)
{
D3D11_SAMPLER_DESC samplerDesc = {};
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
GetDevice(gfx)->CreateSamplerState(&samplerDesc, &pSampler);
}
void Sampler::Bind(Graphics& gfx, Logger& logger) noexcept
{
GetContext(gfx)->PSSetSamplers(0, 1, pSampler.GetAddressOf());
}
\ No newline at end of file
#pragma once
#include "Bindable.h"
#include "Logger.h"
class Sampler : public Bindable
{
public:
Sampler(Graphics& gfx);
void Bind(Graphics& gfx, Logger& logger) noexcept override;
protected:
Microsoft::WRL::ComPtr<ID3D11SamplerState> pSampler;
};
#pragma once #pragma once
#include <DirectXMath.h>
using DirectX::XMFLOAT2;
using DirectX::XMFLOAT3;
// 用于定义顶点的结构,三维坐标 // 用于定义顶点的结构,三维坐标
// position[3] + texture[2] + slot[1]
struct StructVertex struct StructVertex
{ {
struct DirectX::XMFLOAT3 pos;
{ DirectX::XMFLOAT2 texCoord;
float x; UINT slot;
float y;
float z;
} pos;
}; };
struct StructPixelConstBuf struct StructPixelConstBuf
......
#include "Surface.h"
IWICImagingFactory* Surface::wicFactory = nullptr;
int Surface::totalSlot = 0;
BYTE** imageData = nullptr;
DXGI_FORMAT Surface::GetDXGIFormatFromWICFormat(WICPixelFormatGUID& wicFormatGUID)
{
if (wicFormatGUID == GUID_WICPixelFormat128bppRGBAFloat) return DXGI_FORMAT_R32G32B32A32_FLOAT;
else if (wicFormatGUID == GUID_WICPixelFormat64bppRGBAHalf) return DXGI_FORMAT_R16G16B16A16_FLOAT;
else if (wicFormatGUID == GUID_WICPixelFormat64bppRGBA) return DXGI_FORMAT_R16G16B16A16_UNORM;
else if (wicFormatGUID == GUID_WICPixelFormat32bppRGBA) return DXGI_FORMAT_R8G8B8A8_UNORM;
else if (wicFormatGUID == GUID_WICPixelFormat32bppBGRA) return DXGI_FORMAT_B8G8R8A8_UNORM;
else if (wicFormatGUID == GUID_WICPixelFormat32bppBGR) return DXGI_FORMAT_B8G8R8X8_UNORM;
else if (wicFormatGUID == GUID_WICPixelFormat32bppRGBA1010102XR) return DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM;
else if (wicFormatGUID == GUID_WICPixelFormat32bppRGBA1010102) return DXGI_FORMAT_R10G10B10A2_UNORM;
else if (wicFormatGUID == GUID_WICPixelFormat16bppBGRA5551) return DXGI_FORMAT_B5G5R5A1_UNORM;
else if (wicFormatGUID == GUID_WICPixelFormat16bppBGR565) return DXGI_FORMAT_B5G6R5_UNORM;
else if (wicFormatGUID == GUID_WICPixelFormat32bppGrayFloat) return DXGI_FORMAT_R32_FLOAT;
else if (wicFormatGUID == GUID_WICPixelFormat16bppGrayHalf) return DXGI_FORMAT_R16_FLOAT;
else if (wicFormatGUID == GUID_WICPixelFormat16bppGray) return DXGI_FORMAT_R16_UNORM;
else if (wicFormatGUID == GUID_WICPixelFormat8bppGray) return DXGI_FORMAT_R8_UNORM;
else if (wicFormatGUID == GUID_WICPixelFormat8bppAlpha) return DXGI_FORMAT_A8_UNORM;
else return DXGI_FORMAT_UNKNOWN;
};
WICPixelFormatGUID Surface::GetConvertToWICFormat(WICPixelFormatGUID& wicFormatGUID)
{
if (wicFormatGUID == GUID_WICPixelFormatBlackWhite) return GUID_WICPixelFormat8bppGray;
else if (wicFormatGUID == GUID_WICPixelFormat1bppIndexed) return GUID_WICPixelFormat32bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat2bppIndexed) return GUID_WICPixelFormat32bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat4bppIndexed) return GUID_WICPixelFormat32bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat8bppIndexed) return GUID_WICPixelFormat32bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat2bppGray) return GUID_WICPixelFormat8bppGray;
else if (wicFormatGUID == GUID_WICPixelFormat4bppGray) return GUID_WICPixelFormat8bppGray;
else if (wicFormatGUID == GUID_WICPixelFormat16bppGrayFixedPoint) return GUID_WICPixelFormat16bppGrayHalf;
else if (wicFormatGUID == GUID_WICPixelFormat32bppGrayFixedPoint) return GUID_WICPixelFormat32bppGrayFloat;
else if (wicFormatGUID == GUID_WICPixelFormat16bppBGR555) return GUID_WICPixelFormat16bppBGRA5551;
else if (wicFormatGUID == GUID_WICPixelFormat32bppBGR101010) return GUID_WICPixelFormat32bppRGBA1010102;
else if (wicFormatGUID == GUID_WICPixelFormat24bppBGR) return GUID_WICPixelFormat32bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat24bppRGB) return GUID_WICPixelFormat32bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat32bppPBGRA) return GUID_WICPixelFormat32bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat32bppPRGBA) return GUID_WICPixelFormat32bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat48bppRGB) return GUID_WICPixelFormat64bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat48bppBGR) return GUID_WICPixelFormat64bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat64bppBGRA) return GUID_WICPixelFormat64bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat64bppPRGBA) return GUID_WICPixelFormat64bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat64bppPBGRA) return GUID_WICPixelFormat64bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat48bppRGBFixedPoint) return GUID_WICPixelFormat64bppRGBAHalf;
else if (wicFormatGUID == GUID_WICPixelFormat48bppBGRFixedPoint) return GUID_WICPixelFormat64bppRGBAHalf;
else if (wicFormatGUID == GUID_WICPixelFormat64bppRGBAFixedPoint) return GUID_WICPixelFormat64bppRGBAHalf;
else if (wicFormatGUID == GUID_WICPixelFormat64bppBGRAFixedPoint) return GUID_WICPixelFormat64bppRGBAHalf;
else if (wicFormatGUID == GUID_WICPixelFormat64bppRGBFixedPoint) return GUID_WICPixelFormat64bppRGBAHalf;
else if (wicFormatGUID == GUID_WICPixelFormat64bppRGBHalf) return GUID_WICPixelFormat64bppRGBAHalf;
else if (wicFormatGUID == GUID_WICPixelFormat48bppRGBHalf) return GUID_WICPixelFormat64bppRGBAHalf;
else if (wicFormatGUID == GUID_WICPixelFormat128bppPRGBAFloat) return GUID_WICPixelFormat128bppRGBAFloat;
else if (wicFormatGUID == GUID_WICPixelFormat128bppRGBFloat) return GUID_WICPixelFormat128bppRGBAFloat;
else if (wicFormatGUID == GUID_WICPixelFormat128bppRGBAFixedPoint) return GUID_WICPixelFormat128bppRGBAFloat;
else if (wicFormatGUID == GUID_WICPixelFormat128bppRGBFixedPoint) return GUID_WICPixelFormat128bppRGBAFloat;
else if (wicFormatGUID == GUID_WICPixelFormat32bppRGBE) return GUID_WICPixelFormat128bppRGBAFloat;
else if (wicFormatGUID == GUID_WICPixelFormat32bppCMYK) return GUID_WICPixelFormat32bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat64bppCMYK) return GUID_WICPixelFormat64bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat40bppCMYKAlpha) return GUID_WICPixelFormat64bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat80bppCMYKAlpha) return GUID_WICPixelFormat64bppRGBA;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
else if (wicFormatGUID == GUID_WICPixelFormat32bppRGB) return GUID_WICPixelFormat32bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat64bppRGB) return GUID_WICPixelFormat64bppRGBA;
else if (wicFormatGUID == GUID_WICPixelFormat64bppPRGBAHalf) return GUID_WICPixelFormat64bppRGBAHalf;
#endif
else return GUID_WICPixelFormatDontCare;
};
int Surface::GetDXGIFormatBitsPerPixel(DXGI_FORMAT& dxgiFormat)
{
if (dxgiFormat == DXGI_FORMAT_R32G32B32A32_FLOAT) return 128;
else if (dxgiFormat == DXGI_FORMAT_R16G16B16A16_FLOAT) return 64;
else if (dxgiFormat == DXGI_FORMAT_R16G16B16A16_UNORM) return 64;
else if (dxgiFormat == DXGI_FORMAT_R8G8B8A8_UNORM) return 32;
else if (dxgiFormat == DXGI_FORMAT_B8G8R8A8_UNORM) return 32;
else if (dxgiFormat == DXGI_FORMAT_B8G8R8X8_UNORM) return 32;
else if (dxgiFormat == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM) return 32;
else if (dxgiFormat == DXGI_FORMAT_R10G10B10A2_UNORM) return 32;
else if (dxgiFormat == DXGI_FORMAT_B5G5R5A1_UNORM) return 16;
else if (dxgiFormat == DXGI_FORMAT_B5G6R5_UNORM) return 16;
else if (dxgiFormat == DXGI_FORMAT_R32_FLOAT) return 32;
else if (dxgiFormat == DXGI_FORMAT_R16_FLOAT) return 16;
else if (dxgiFormat == DXGI_FORMAT_R16_UNORM) return 16;
else if (dxgiFormat == DXGI_FORMAT_R8_UNORM) return 8;
else if (dxgiFormat == DXGI_FORMAT_A8_UNORM) return 8;
};
UINT Surface::GetHeight()
{
return this->height;
};
UINT Surface::GetWidth()
{
return this->width;
};
DXGI_FORMAT Surface::GetDxgiFormat()
{
return this->dxgiFormat;
};
UINT Surface::GetBytesPerRow()
{
return this->bytesPerRow;
};
BYTE* Surface::GetImageData()
{
return this->imageData;
};
UINT Surface::GetCurrSlot()
{
return this->currSlot;
};
/************************************
* Texture 01
* Load the data from the image file
* and decrypt it to a bitmap format
* compatible with DXGI formats (rgba)
************************************/
void Surface::LoadImageFromFile(
Microsoft::WRL::ComPtr<ID3D11Device> dev,
Microsoft::WRL::ComPtr<ID3D11DeviceContext> devcon,
std::string imageFile)
{
// reset decoder, frame and converter since these will be different for each image we load
IWICBitmapDecoder* wicDecoder = NULL;
IWICBitmapFrameDecode* wicFrame = NULL;
IWICFormatConverter* wicConverter = NULL;
HRESULT hr;
std::wstring wsImageFile = std::wstring(imageFile.begin(), imageFile.end());
/************************************
* 1 Initialize the COM library
************************************/
if (wicFactory == nullptr)
{
hr = CoInitialize(wicFactory);
}
/************************************
* 2 Create WIC Factory
************************************/
hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&wicFactory));
/************************************
* 3 Create the Bitmap Decoder
************************************/
hr = wicFactory->CreateDecoderFromFilename(
wsImageFile.c_str(), // Image we want to load in
NULL, // This is a vendor ID, we do not prefer a specific one so set to null
GENERIC_READ, // We want to read from this file
WICDecodeMetadataCacheOnLoad, // We will cache the metadata right away, rather than when needed, which might be unknown
&wicDecoder // the wic decoder to be created)
);
/************************************
* 4 Grab the first frame in the image
************************************/
hr = wicDecoder->GetFrame(0, &wicFrame);
/************************************
* 5 Get WIC Pixel Format From Frame
************************************/
WICPixelFormatGUID pixelFormat;
hr = wicFrame->GetPixelFormat(&pixelFormat);
/************************************
* 6 Get Size of the image
************************************/
hr = wicFrame->GetSize(&width, &height);
/************************************
* 7 Get Compatible DXGI Format
************************************/
// convert wic pixel format to dxgi pixel format
DXGI_FORMAT dxgiFormat = GetDXGIFormatFromWICFormat(pixelFormat);
/************************************
* 8 Convert image to DXGI format if necessary
************************************/
bool imageConverted = false;
// if the format of the image is not a supported dxgi format, try to convert it
if (dxgiFormat == DXGI_FORMAT_UNKNOWN)
{
// get a dxgi compatible wic format from the current image format
WICPixelFormatGUID convertToPixelFormat = GetConvertToWICFormat(pixelFormat);
// return if no dxgi compatible format was found
//if (convertToPixelFormat == GUID_WICPixelFormatDontCare) return 0;
// set the dxgi format
dxgiFormat = GetDXGIFormatFromWICFormat(convertToPixelFormat);
// create the format converter
hr = wicFactory->CreateFormatConverter(&wicConverter);
//if (FAILED(hr)) return 0;
// make sure we can convert to the dxgi compatible format
BOOL canConvert = FALSE;
hr = wicConverter->CanConvert(pixelFormat, convertToPixelFormat, &canConvert);
//if (FAILED(hr) || !canConvert) return 0;
// do the conversion (wicConverter will contain the converted image)
hr = wicConverter->Initialize(wicFrame, convertToPixelFormat, WICBitmapDitherTypeErrorDiffusion, 0, 0, WICBitmapPaletteTypeCustom);
//if (FAILED(hr)) return 0;
// this is so we know to get the image data from the wicConverter (otherwise we will get from wicFrame)
imageConverted = true;
}
/************************************
* 9 Get image size information
************************************/
int bitsPerPixel = GetDXGIFormatBitsPerPixel(dxgiFormat); // number of bits per pixel
bytesPerRow = (width * bitsPerPixel) / 8; // number of bytes in each row of the image data
int imageSize = bytesPerRow * height; // total image size in bytes
/************************************
* 10 Get the pixel data (CopyPixel)
************************************/
// allocate enough memory for the raw image data, and set imageData to point to that memory
imageData = (BYTE*)malloc(imageSize);
// copy (decoded) raw image data into the newly allocated memory (imageData)
if (imageConverted)
{
// if image format needed to be converted, the wic converter will contain the converted image
hr = wicConverter->CopyPixels(0, bytesPerRow, imageSize, imageData);
//if (FAILED(hr)) return 0;
}
else
{
// no need to convert, just copy data from the wic frame
hr = wicFrame->CopyPixels(0, bytesPerRow, imageSize, imageData);
//if (FAILED(hr)) return 0;
}
/************************************
* 11 Create Texture Resource
************************************/
// create texture resource
D3D11_TEXTURE2D_DESC textureDesc = {};
textureDesc.Width = width;
textureDesc.Height = height;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = dxgiFormat;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA sd = {};
sd.pSysMem = imageData; // s.GetBufferPtr();
sd.SysMemPitch = bytesPerRow; // s.GetWidth() * sizeof(Surface::Color);
sd.SysMemSlicePitch = bytesPerRow * height;
// wrl::ComPtr<ID3D11Texture2D> pTexture;
ID3D11Texture2D* pTexture2D = nullptr;
hr = dev->CreateTexture2D(&textureDesc, &sd, &pTexture2D);
/************************************
* 12 Create the resource view on the texture
************************************/
ID3D11ShaderResourceView* pTextureView = nullptr;
if (hr == S_OK)
{
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Format = textureDesc.Format;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = 1;
hr = dev->CreateShaderResourceView(pTexture2D, &srvDesc, &pTextureView);
}
/************************************
* 13 Bind shader resource view to pipeline
************************************/
currSlot = (++totalSlot) - 1;
devcon->PSSetShaderResources(currSlot, 1, &pTextureView);
};
\ No newline at end of file
#pragma once
#include <Windows.h>
#include <d3d11.h>
#include <wincodec.h>
#include <memory>
#include <wrl.h>
#include <string>
class Surface
{
public:
void LoadImageFromFile(
Microsoft::WRL::ComPtr<ID3D11Device> dev,
Microsoft::WRL::ComPtr<ID3D11DeviceContext> devcon,
std::string filename);
UINT GetWidth();
UINT GetHeight();
DXGI_FORMAT GetDxgiFormat();
UINT GetBytesPerRow();
BYTE* GetImageData();
UINT GetCurrSlot();
private:
DXGI_FORMAT GetDXGIFormatFromWICFormat(WICPixelFormatGUID& wicFormatGUID);
WICPixelFormatGUID GetConvertToWICFormat(WICPixelFormatGUID& wicFormatGUID);
int GetDXGIFormatBitsPerPixel(DXGI_FORMAT& dxgiFormat);
private:
static IWICImagingFactory* wicFactory;
static int totalSlot;
UINT height;
UINT width;
DXGI_FORMAT dxgiFormat;
UINT bytesPerRow;
BYTE* imageData;
UINT currSlot;
};
\ No newline at end of file
#include "Texture.h"
namespace wrl = Microsoft::WRL;
Texture::Texture(Graphics& gfx, Surface& surface)
{
// create texture resource
D3D11_TEXTURE2D_DESC textureDesc = {};
textureDesc.Width = surface.GetWidth();
textureDesc.Height = surface.GetHeight();
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA sd = {};
sd.pSysMem = surface.GetImageData();
sd.SysMemPitch = surface.GetBytesPerRow();
sd.SysMemSlicePitch = surface.GetBytesPerRow() * surface.GetHeight();
wrl::ComPtr<ID3D11Texture2D> pTexture;
GetDevice(gfx)->CreateTexture2D(
&textureDesc, &sd, &pTexture
);
// create the resource view on the texture
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Format = textureDesc.Format;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = 1;
GetDevice(gfx)->CreateShaderResourceView(
pTexture.Get(), &srvDesc, &pTextureView
);
}
void Texture::Bind(Graphics& gfx, UINT slot, Logger& logger)
{
for (auto& surface : surfaces)
{
GetContext(gfx)->PSSetShaderResources(surface->GetCurrSlot(), 1u, pTextureView.GetAddressOf());
}
}
\ No newline at end of file
#pragma once
#include "Bindable.h"
#include "Graphics.h"
#include "Surface.h"
#include <Windows.h>
#include "Logger.h"
#include <vector>
#include <memory>
class Texture : public Bindable
{
public:
Texture(Graphics& gfx, Surface& surface);
void Bind(Graphics& gfx, UINT slot, Logger& logger);
protected:
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> pTextureView;
std::vector<std::unique_ptr<Surface>> surfaces;
};
\ No newline at end of file
Texture2D tex0 : register(t0);
Texture2D tex1 : register(t1);
struct PSInput
{
float2 tex : TexCoord;
float slot : ImageSlot;
};
SamplerState splr;
float4 main(PSInput input) : SV_Target
{
//return tex.Sample(splr,tc);
if (input.slot == 1.0f)
{
return tex1.Sample(splr, input.tex);
}
else
{
return tex0.Sample(splr, input.tex);
}
}
\ No newline at end of file
cbuffer CBuf
{
matrix transform;
};
struct VSInput
{
float3 pos : Position;
float2 tex : TexCoord;
float slot : ImageSlot;
};
struct VSOut
{
float2 tex : TexCoord;
float4 pos : SV_Position;
float slot : ImageSlot;
};
VSOut main(VSInput input)
{
VSOut vso;
vso.pos = mul(float4(input.pos, 1.0f), transform);
vso.tex = input.tex;
vso.slot = input.slot;
return vso;
}
...@@ -11,45 +11,45 @@ ...@@ -11,45 +11,45 @@
#include "TransformCBuf.h" #include "TransformCBuf.h"
#include "Graphics.h" #include "Graphics.h"
Triangle::Triangle(Graphics& gfx, float position[][3], float color[][3], Logger& logger) Triangle::Triangle(Graphics& gfx, StructVertex vertices[], Logger& logger)
{ {
// Assign position values // Assign position values
for (int i = 0; i < 3; i++) //for (int i = 0; i < 3; i++)
{ //{
for (int j = 0; j < 3; j++) // for (int j = 0; j < 3; j++)
{ // {
this->position[i][j] = position[i][j]; // this->position[i][j] = position[i][j];
} // }
} //}
// Assign color values //// Assign color values
for (int i = 0; i < 1; i++) //for (int i = 0; i < 1; i++)
{ //{
for (int j = 0; j < 3; j++) // for (int j = 0; j < 3; j++)
{ // {
this->color[i][j] = color[i][j]; // this->color[i][j] = color[i][j];
} // }
} //}
/************************************ /************************************
* 2.3 DefineVertexBuffer * 2.3 DefineVertexBuffer
************************************/ ************************************/
const std::vector<StructVertex> vertices = const std::vector<StructVertex> vb =
{ {
{ position[0][0], position[0][1], position[0][2] }, { vertices[0] },
{ position[1][0], position[1][1], position[1][2] }, { vertices[1] },
{ position[2][0], position[2][1], position[2][2] } { vertices[2] }
}; };
AddBind(std::make_unique<VertexBuffer>(gfx, vertices, logger)); AddBind(std::make_unique<VertexBuffer>(gfx, vb, logger));
for (int i = 0; i < 3; i++) /*for (int i = 0; i < 3; i++)
{ {
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
{ {
logger.PutLog("Triangle::Triangle", std::to_string(this->position[i][j])); logger.PutLog("Triangle::Triangle", std::to_string(this->position[i][j]));
} }
} }*/
/************************************ /************************************
* 2.7 DefineVertexShader * 2.7 DefineVertexShader
...@@ -95,12 +95,12 @@ Triangle::Triangle(Graphics& gfx, float position[][3], float color[][3], Logger& ...@@ -95,12 +95,12 @@ Triangle::Triangle(Graphics& gfx, float position[][3], float color[][3], Logger&
{ 0.0f,1.0f,1.0f }, { 0.0f,1.0f,1.0f },
} }
};*/ };*/
const StructPixelConstBuf cb2 = /*const StructPixelConstBuf cb2 =
{ {
{ color[0][0], color[0][1], color[0][2] } { color[0][0], color[0][1], color[0][2] }
}; };
AddBind(std::make_unique<PixelConstantBuffer<StructPixelConstBuf>>(gfx, cb2)); AddBind(std::make_unique<PixelConstantBuffer<StructPixelConstBuf>>(gfx, cb2));*/
/************************************ /************************************
* 2.9 DefineInputLayout * 2.9 DefineInputLayout
......
#pragma once #pragma once
#include "Drawable.h" #include "Drawable.h"
#include "Logger.h" #include "Logger.h"
#include "Structs.h"
#include "Surface.h"
class Triangle : public Drawable class Triangle : public Drawable
{ {
public: public:
Triangle(Graphics& gfx, float position[][3], float color[][3], Logger& logger); Triangle(Graphics& gfx, StructVertex vertices[], Logger& logger);
void Update(float dt) noexcept override; void Update(float dt) noexcept override;
DirectX::XMMATRIX GetTransformXM() const noexcept override; DirectX::XMMATRIX GetTransformXM() const noexcept override;
private: private:
// positional // positional
float position[3][3]; //float position[3][3];
// color // color
float color[1][3]; //float color[1][3];
// trasformation // trasformation
float dx = 0.0f; float dx = 0.0f;
float dy = 0.0f; float dy = 0.0f;
......
...@@ -693,43 +693,43 @@ int WINAPI WinMain(HINSTANCE hInstance, ...@@ -693,43 +693,43 @@ int WINAPI WinMain(HINSTANCE hInstance,
Graphics gfx(hWnd); Graphics gfx(hWnd);
gfx.SetProjection(DirectX::XMMatrixPerspectiveLH(1.0f, 3.0f / 4.0f, 0.5f, 40.0f)); gfx.SetProjection(DirectX::XMMatrixPerspectiveLH(1.0f, 3.0f / 4.0f, 0.5f, 40.0f));
std::vector<std::unique_ptr<Box>> boxes; //std::vector<std::unique_ptr<Box>> boxes;
for (int i = -5; i < 6; i++) //for (int i = -5; i < 6; i++)
{ //{
for (int j = -5; j < 6; j++) // for (int j = -5; j < 6; j++)
{ // {
float boxPos[8][3] = // float boxPos[8][3] =
{ // {
// left bottom back // // left bottom back
{ -1.0f + i, -1.0f, -1.0f + j }, // { -1.0f + i, -1.0f, -1.0f + j },
// right bottom back // // right bottom back
{ 1.0f + i, -1.0f, -1.0f + j }, // { 1.0f + i, -1.0f, -1.0f + j },
// left top back // // left top back
{ -1.0f + i, 1.0f, -1.0f + j }, // { -1.0f + i, 1.0f, -1.0f + j },
// right top back // // right top back
{ 1.0f + i, 1.0f, -1.0f + j }, // { 1.0f + i, 1.0f, -1.0f + j },
// left bottom front // // left bottom front
{ -1.0f + i, -1.0f, 1.0f + j }, // { -1.0f + i, -1.0f, 1.0f + j },
// right bottom front // // right bottom front
{ 1.0f + i, -1.0f, 1.0f + j }, // { 1.0f + i, -1.0f, 1.0f + j },
// left top front // // left top front
{ -1.0f + i, 1.0f, 1.0f + j }, // { -1.0f + i, 1.0f, 1.0f + j },
// right top front // // right top front
{ 1.0f + i, 1.0f, 1.0f + j }, // { 1.0f + i, 1.0f, 1.0f + j },
}; // };
float boxCol[6][3] = // float boxCol[6][3] =
{ // {
{ 0.0f, 1.0f, 0.0f }, // Green // { 0.0f, 1.0f, 0.0f }, // Green
{ 1.0f, 1.0f, 0.0f }, // Yellow // { 1.0f, 1.0f, 0.0f }, // Yellow
{ 1.0f, 0.0f, 0.0f }, // Red // { 1.0f, 0.0f, 0.0f }, // Red
{ 0.0f, 0.0f, 1.0f }, // Blue // { 0.0f, 0.0f, 1.0f }, // Blue
{ 0.0f, 1.0f, 1.0f }, // Cyan // { 0.0f, 1.0f, 1.0f }, // Cyan
{ 1.0f, 0.0f, 1.0f }, // Magenta // { 1.0f, 0.0f, 1.0f }, // Magenta
}; // };
boxes.push_back(std::make_unique<Box>(gfx, boxPos, boxCol, logger)); // boxes.push_back(std::make_unique<Box>(gfx, boxPos, boxCol, logger));
} // }
} //}
Ground ground(gfx, logger); Ground ground(gfx, logger);
double seed = 0; double seed = 0;
...@@ -767,11 +767,11 @@ int WINAPI WinMain(HINSTANCE hInstance, ...@@ -767,11 +767,11 @@ int WINAPI WinMain(HINSTANCE hInstance,
logger.PutLog("seed", std::to_string(seed)); logger.PutLog("seed", std::to_string(seed));
logger.PutLog("dt", std::to_string(dt)); logger.PutLog("dt", std::to_string(dt));
auto sinValue = sin(seed / 1000); auto sinValue = sin(seed / 5000);
auto cosValue = cos(seed / 1000); auto cosValue = cos(seed / 5000);
// Set camera // Set camera
DirectX::XMVECTOR eyePosition = DirectX::XMVectorSet(20.0f * sinValue, 10.0f, -20.0f * cosValue, 1.0f); DirectX::XMVECTOR eyePosition = DirectX::XMVectorSet(5.0f * sinValue, 2.0f, -5.0f * cosValue, 1.0f);
DirectX::XMVECTOR focusPosition = DirectX::XMVectorZero(); DirectX::XMVECTOR focusPosition = DirectX::XMVectorZero();
DirectX::XMVECTOR upDirection = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f); DirectX::XMVECTOR upDirection = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);
......
This image diff could not be displayed because it is too large. You can view the blob instead.
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