DirectX/DirectX 2D_(구)

DX 공간 결합

컴맹학자 2020. 11. 5. 19:28
728x90

1. 코드

Execute.cpp 

//Create World view Projection (공간)
{
D3DXMatrixIdentity(&world); //항등행열 만들어지는곳
D3DXMatrixIdentity(&view);
D3DXMatrixIdentity(&projection);
//가상으로 만들어지는 카메라(눈) ,왼손 좌표(LH) , 오른손(RH)
//넣을 좌표, 눈의 위치, 바라볼 대상
D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0, 0, 0), &D3DXVECTOR3(0, 0, 1), &D3DXVECTOR3(0, 1, 0));
//원근, 직교 투영 2가지 방식이 존재 현재는 직교투영
//넣을 좌표, 윈도우사이즈 x, y, 시야 0 , 1
D3DXMatrixOrthoLH(&projection,Settings::Get().GetWidth(), Settings::Get().GetHight(), 0, 1);
std::cout << "View Matrix " << std::endl;
std::cout << view._11 <<" " << view._12 << " "<< view._13 << " " << view._14 <<" "<< std::endl;
std::cout << view._21 <<" " << view._22 << " "<< view._23 << " " << view._24 <<" "<< std::endl;
std::cout << view._31 <<" " << view._32 << " "<< view._33 << " " << view._34 <<" "<< std::endl;
std::cout << view._41 <<" " << view._42 << " "<< view._43 << " " << view._44 <<" "<< std::endl;
std::cout << std::endl;
std::cout << "projection Matrix " << std::endl;
std::cout << projection._11 << " " << projection._12 << " " << projection._13 << " " << projection._14 << " " << std::endl;
std::cout << projection._21 << " " << projection._22 << " " << projection._23 << " " << projection._24 << " " << std::endl;
std::cout << projection._31 << " " << projection._32 << " " << projection._33 << " " << projection._34 << " " << std::endl;
std::cout << projection._41 << " " << projection._42 << " " << projection._43 << " " << projection._44 << " " << std::endl;
// world 크기, 사이즈 별도로 넣고 결합
D3DXMATRIX S;
D3DXMATRIX T;
D3DXMATRIX R;
D3DXMatrixScaling(&S, 100, 100 , 1);
D3DXMatrixTranslation(&T, 100, 100, 0);
D3DXMatrixRotationZ(&R, static_cast<float>(D3DXToRadian(45)));
// 곱하는 순서 주의 해야함 위치부터 곱하면 크기가 생략이됨
//스 * 자 * 이 * 공전 * 부모
// S 크기 * R 회전 * T 위치
world = S * R * T;
}
//create constant buffer
{
D3D11_BUFFER_DESC desc;
ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC));
desc.Usage = D3D11_USAGE_DYNAMIC; // cpu쓰고 , gpu읽기
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
desc.ByteWidth = sizeof(TRANSFROM_DATA);
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
auto hr = graphics->GetDevice()->CreateBuffer(&desc, nullptr, &gpu_buffer);
assert(SUCCEEDED(hr));
}
}
Execute::~Execute()
{
SAFE_RELEASE(gpu_buffer);\
SAFE_RELEASE(pixel_shader);
SAFE_RELEASE(ps_blob);
SAFE_RELEASE(input_layout);
SAFE_RELEASE(vertex_shader);
SAFE_RELEASE(vs_blob);
SAFE_DELETE_ARRAY(indices);
SAFE_RELEASE(index_buffer);
SAFE_RELEASE(vertexbuffer);
SAFE_DELETE(graphics);
SAFE_DELETE_ARRAY(vertics);
}
void Execute::Update()
{
//부모 행열 3D에서 사용
static float radian = 0.0f;
radian += 0.01f;
D3DXMATRIX P;
D3DXMatrixRotationZ(&P, radian);
world *= P;
D3DXMatrixTranspose(&cpu_buffer.world , &world);
D3DXMatrixTranspose(&cpu_buffer.view, &view);
D3DXMatrixTranspose(&cpu_buffer.projection, &projection);
// 상수 버퍼 자원을 갱신
D3D11_MAPPED_SUBRESOURCE mpped_subresource;
graphics->GetDeviceContext()->Map
(
gpu_buffer,
0,
D3D11_MAP_WRITE_DISCARD,
0,
&mpped_subresource
);
//카피
memcpy(mpped_subresource.pData, &cpu_buffer, sizeof(TRANSFROM_DATA));
graphics->GetDeviceContext()->Unmap(gpu_buffer, 0);
}

2. 실행

 


3. 추가 및 요약

 

1. 함수
D3DXMatrixScaling : 공간의 크기를 바꿀수 있음
D3DXMatrixTranslation : 공간의 위치 변경
D3DXMatrixRotationZ : 회전

2. 행열 결합
 스케일 행열에는 0이 들어가면 안된다.
 행열은 교환 법칙이 안들어가 있다.

 

'DirectX > DirectX 2D_(구)' 카테고리의 다른 글

DX sampler_state  (0) 2020.11.06
DX Raterizer  (0) 2020.11.05
DX 공간 변환  (0) 2020.11.05
DX indexbuffer, 공간변환(이론)  (0) 2020.11.05
DX Render  (0) 2020.11.05