World Matrix

 


 

View Projection 행렬

 

4x4 행렬

Identity

1  0  0  0

0  1  0  0

0  0  1  0

0  0  0  1

 


World.fx 코드

 

08_World.fx

더보기
matrix World;
matrix View;
matrix Projection;
struct VertexInput
{
float4 Position : Position;
};
struct VertexOutput
{
float4 Position : SV_Position;
};
float4 VS(VertexInput input) : SV_Position
{
// float4의 위치(=input.Position)에 W V P를 곱하여 output.Position 반환
VertexOutput output;
output.Position = mul(input.Position, World);
output.Position = mul(output.Position, View);
output.Position = mul(output.Position, Projection);
return output;
}
float4 PS_R(VertexOutput input) : SV_Target
{
return float4(1, 0, 0, 1);
}
RasterizerState FillMode_Wireframe
{
FillMode = Wireframe;
};
technique11 T0
{
pass P0
{
SetVertexShader(CompileShader(vs_5_0, VS()));
SetPixelShader(CompileShader(ps_5_0, PS_R()));
}
pass P1
{
SetRasterizerState(FillMode_Wireframe);
SetVertexShader(CompileShader(vs_5_0, VS()));
SetPixelShader(CompileShader(ps_5_0, PS_R()));
}
}

 

WorldDemo 코드

 

WorldDemo.h

더보기
#pragma once
#include "Systems/IExecute.h"
class WorldDemo : public IExecute
{
public:
virtual void Initialize() override;
virtual void Ready() override {}
virtual void Destroy() override;
virtual void Update() override;
virtual void PreRender() override {}
virtual void Render() override;
virtual void PostRender() override {}
virtual void ResizeScreen() override {}
private:
Shader* shader;
Vertex vertices[6];
ID3D11Buffer* vertexBuffer;
Matrix world;
};

 

WorldDemo.cpp

더보기
#include "stdafx.h"
#include "WorldDemo.h"
void WorldDemo::Initialize()
{
shader = new Shader(L"08_World.fx");
vertices[0].Position = Vector3(+0.0f, +0.0f, 0.0f);
vertices[1].Position = Vector3(+0.0f, +0.5f, 0.0f);
vertices[2].Position = Vector3(+0.5f, +0.0f, 0.0f);
vertices[3].Position = Vector3(+0.5f, +0.0f, 0.0f);
vertices[4].Position = Vector3(+0.0f, +0.5f, 0.0f);
vertices[5].Position = Vector3(+0.5f, +0.5f, 0.0f);
D3D11_BUFFER_DESC desc;
ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC));
desc.ByteWidth = sizeof(Vertex) * 6;
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
D3D11_SUBRESOURCE_DATA subResource = { 0 };
subResource.pSysMem = vertices;
Check(D3D::GetDevice()->CreateBuffer(&desc, &subResource, &vertexBuffer));
D3DXMatrixIdentity(&world);
}
void WorldDemo::Destroy()
{
SafeDelete(shader);
SafeRelease(vertexBuffer);
}
void WorldDemo::Update()
{
if (Keyboard::Get()->Press(VK_RIGHT))
{
world._11 += 2.0f * Time::Delta();
world._22 += 2.0f * Time::Delta();
}
else if (Keyboard::Get()->Press(VK_LEFT))
{
world._11 -= 2.0f * Time::Delta();
world._22 -= 2.0f * Time::Delta();
}
}
void WorldDemo::Render()
{
shader->AsMatrix("World")->SetMatrix(world);
shader->AsMatrix("View")->SetMatrix(Context::Get()->View());
shader->AsMatrix("Projection")->SetMatrix(Context::Get()->Projection());
UINT stride = sizeof(Vertex);
UINT offset = 0;
D3D::GetDC()->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
D3D::GetDC()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
shader->Draw(0, 0, 6);
}

 

Main.cpp

더보기
#include "stdafx.h"
#include "Main.h"
#include "Systems/Window.h"
#include "WorldDemo.h"
#include "UserInterfaceDemo.h"
#include "TriangleList.h"
#include "Vertex_Line2.h"
#include "Vertex_Line.h"
void Main::Initialize()
{
Push(new WorldDemo());
}
void Main::Ready()
{
}
void Main::Destroy()
{
for (IExecute* exe : executes)
{
exe->Destroy();
SafeDelete(exe);
}
}
void Main::Update()
{
for (IExecute* exe : executes)
exe->Update();
}
void Main::PreRender()
{
for (IExecute* exe : executes)
exe->PreRender();
}
void Main::Render()
{
for (IExecute* exe : executes)
exe->Render();
}
void Main::PostRender()
{
for (IExecute* exe : executes)
exe->PostRender();
}
void Main::ResizeScreen()
{
for (IExecute* exe : executes)
exe->ResizeScreen();
}
void Main::Push(IExecute * execute)
{
executes.push_back(execute);
execute->Initialize();
}
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR param, int command)
{
D3DDesc desc;
desc.AppName = L"D3D Game";
desc.Instance = instance;
desc.bFullScreen = false;
desc.bVsync = false;
desc.Handle = NULL;
desc.Width = 1280;
desc.Height = 720;
desc.Background = Color(0.3f, 0.3f, 0.3f, 1.0f);
D3D::SetDesc(desc);
Main* main = new Main();
WPARAM wParam = Window::Run(main);
SafeDelete(main);
return wParam;
}

 

실행화면

 


 

'⭐ DirectX > DirectX11 3D' 카테고리의 다른 글

[DirectX11] 011 Index  (0) 2023.01.10
[DirectX11] 010 World  (1) 2023.01.09
[DirectX11] 008 User Interface  (1) 2023.01.07
[DirectX11] 006~007 사각형 띄우기  (0) 2023.01.06
[DirectX11] 001~005 DirectX11 기초, NDC 좌표계  (0) 2023.01.04