#pragma once #include "Box.h" #include "Bindable.h" #include "VertexBuffer.h" #include "IndexBuffer.h" #include "VertexShader.h" #include "PixelShader.h" #include "ConstantBuffer.h" #include "InputLayout.h" #include "Topology.h" #include "TransformCBuf.h" #include "Graphics.h" #include Box::Box(Graphics& gfx, float position[][3], float color[][3], Logger& logger) { // Assign position values for (int i = 0; i < 8; i++) { for (int j = 0; j < 3; j++) { this->position[i][j] = position[i][j]; } } // 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.3 DefineVertexBuffer ************************************/ const std::vector vertices = { { 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(gfx, vertices, logger)); /************************************ * 2.7 DefineVertexShader ************************************/ auto pVertexShader = std::make_unique(gfx, L"VertexShader.cso"); auto pvsbc = pVertexShader->GetBytecode(); AddBind(std::move(pVertexShader)); /************************************ * 2.8 DefinePixelShader ************************************/ AddBind(std::make_unique(gfx, L"PixelShader.cso")); /************************************ * 2.4 DefineIndexBuffer ************************************/ const std::vector indices = { 0,2,1, 2,3,1, 1,3,5, 3,7,5, 2,6,3, 3,6,7, 4,5,7, 4,7,6, 0,4,2, 2,4,6, 0,1,4, 1,5,4 }; AddIndexBuffer(std::make_unique(gfx, indices, 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>(gfx, cb2)); /************************************ * 2.9 DefineInputLayout ************************************/ const std::vector ied = { { "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 }, }; AddBind(std::make_unique(gfx, ied, pvsbc)); /************************************ * 2.10 DefinePrimitiveTopology ************************************/ AddBind(std::make_unique(gfx, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST)); /************************************ * 2.5 DefineTransConstBuffer ************************************/ AddBind(std::make_unique(gfx, *this)); } void Box::Update(float dt) noexcept { /*roll += droll * dt; pitch += dpitch * dt; yaw += dyaw * dt; theta += dtheta * dt; phi += dphi * dt; chi += dchi * dt;*/ //dx = dt; //dy = dt; //dz = dt * 10.0f; } //void Box::UpdateCamera(float sin, float cos) noexcept //{ // using namespace DirectX; // upDirection = XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f); // focusPosition = XMVectorZero(); // eyePosition = XMVectorSet(20.0f * sin, 10.0f, -20.0f * cos, 1.0f); //}; DirectX::XMMATRIX Box::GetTransformXM() const noexcept { /*return DirectX::XMMatrixRotationRollPitchYaw(pitch, yaw, roll) * DirectX::XMMatrixTranslation(r, 0.0f, 0.0f) * DirectX::XMMatrixRotationRollPitchYaw(theta, phi, chi) * DirectX::XMMatrixTranslation(0.0f, 0.0f, 20.0f);*/ return DirectX::XMMatrixTranslation(dx, dy, dz) * DirectX::XMMatrixLookAtLH(eyePosition, focusPosition, upDirection); }