WorldDemo.cpp, h
#include "stdafx.h"
#include "WorldDemo.h"
void WorldDemo::Initialize()
{
shader = new Shader(L"04_World.fxo");
{
vertices[0].Position = Vector3(-0.5f, -0.5f, +0.0f);
vertices[1].Position = Vector3(-0.5f, +0.5f, +0.0f);
vertices[2].Position = Vector3(+0.5f, -0.5f, +0.0f);
vertices[3].Position = Vector3(+0.5f, -0.5f, +0.0f);
vertices[4].Position = Vector3(-0.5f, +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 data = { 0 };
data.pSysMem = vertices;
Check(D3D::GetDevice()->CreateBuffer(&desc, &data, &vertexBuffer));
}
D3DXMatrixIdentity(&world);
}
void WorldDemo::Destroy()
{
SafeDelete(shader);
SafeRelease(vertexBuffer);
}
void WorldDemo::Update()
{
if (Keyboard::Get()->Press(VK_LSHIFT))
{
//크기 조절
if (Keyboard::Get()->Press(VK_RIGHT))
world._11 += 2.0f * Time::Delta();
else if (Keyboard::Get()->Press(VK_LEFT))
world._11 -= 2.0f * Time::Delta();
if (Keyboard::Get()->Press(VK_UP))
world._22 += 2.0f * Time::Delta();
else if (Keyboard::Get()->Press(VK_DOWN))
world._22 -= 2.0f * Time::Delta();
}
else
{
//키보드 이동
if (Keyboard::Get()->Press(VK_RIGHT))
world._41 += 2.0f * Time::Delta();
else if (Keyboard::Get()->Press(VK_LEFT))
world._41 -= 2.0f * Time::Delta();
if (Keyboard::Get()->Press(VK_UP))
world._42 += 2.0f * Time::Delta();
else if (Keyboard::Get()->Press(VK_DOWN))
world._42 -= 2.0f * Time::Delta();
}
//D3D::GetDC()->UpdateSubresource(vertexBuffer, NULL, NULL, &vertices, 0, 0);
shader->AsMatrix("World")->SetMatrix(world);
shader->AsMatrix("View")->SetMatrix(Context::Get()->View());
shader->AsMatrix("Projection")->SetMatrix(Context::Get()->Projection());
}
void WorldDemo::Render()
{
UINT stride = sizeof(Vertex);
UINT offset = 0;
D3D::GetDC()->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
D3D::GetDC()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
static UINT Pass = 0;
ImGui::InputInt("Pass", (int*)&Pass);
Pass = (UINT)Math::Clamp((float)Pass, 0, 1);
shader->Draw(0, Pass, 6);
}
#pragma once
#include "Systems/IExecute.h"
class WorldDemo : public IExecute
{
public:
virtual void Initialize() 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:
struct Vertex
{
Vector3 Position;
};
private:
Shader* shader;
Vertex vertices[6];
ID3D11Buffer* vertexBuffer;
Matrix world;
};
04_Wrold_fx
Matrix World, View ,Projection;
struct VertexInput
{
float4 Position : Position;
};
struct VertexOutput
{
float4 Position : SV_Position;
};
RasterizerState RS
{
Fillmode = WireFrame; // Wire(선)
};
VertexOutput VS(VertexInput input)
{
VertexOutput output;
//공간 변환
output.Position = mul(input.Position, World);
output.Position = mul(output.Position, View);
output.Position = mul(output.Position, Projection);
return output;
}
float4 PS(VertexOutput input) : SV_Target
{
return float4(1, 0, 0, 1);
}
technique11 T0
{
pass P0
{
SetVertexShader(CompileShader(vs_5_0, VS()));
SetPixelShader(CompileShader(ps_5_0, PS()));
}
pass P1
{
SetRasterizerState(RS);
SetVertexShader(CompileShader(vs_5_0, VS()));
SetPixelShader(CompileShader(ps_5_0, PS()));
}
}
실행
추가
World : 공간 상의 위치 (오브젝트 마다 가짐)
View : 바라볼 위치와 방향
Projection : 시야의 크기 (+시야각 FOV)
Perspective(3D용) , Orthographic (2D용)
Context : 카메라 관련(view, Projection) 공통자원이 정의된 클래스
'DirectX > DirectX 3D_(구)' 카테고리의 다른 글
07_Camera (0) | 2021.06.30 |
---|---|
06_Grid (0) | 2021.06.30 |
05_Index (0) | 2021.06.30 |
03_Triangle, Rect (0) | 2021.06.28 |
01_셋팅 및 02_Vertex (0) | 2021.06.28 |