#include "Box.h" #include "BindableBase.h" #include "GraphicsThrowMacros.h" Box::Box( Graphics& gfx, std::mt19937& rng, std::uniform_real_distribution& adist, std::uniform_real_distribution& ddist, std::uniform_real_distribution& odist, std::uniform_real_distribution& rdist ) : r( rdist( rng ) ), droll( ddist( rng ) ), dpitch( ddist( rng ) ), dyaw( ddist( rng ) ), dphi( odist( rng ) ), dtheta( odist( rng ) ), dchi( odist( rng ) ), chi( adist( rng ) ), theta( adist( rng ) ), phi( adist( rng ) ) { struct Vertex { struct { float x; float y; float z; } pos; }; const std::vector vertices = { { -1.0f,-1.0f,-1.0f }, { 1.0f,-1.0f,-1.0f }, { -1.0f,1.0f,-1.0f }, { 1.0f,1.0f,-1.0f }, { -1.0f,-1.0f,1.0f }, { 1.0f,-1.0f,1.0f }, { -1.0f,1.0f,1.0f }, { 1.0f,1.0f,1.0f }, }; AddBind( std::make_unique( gfx,vertices ) ); auto pvs = std::make_unique( gfx,L"VertexShader.cso" ); auto pvsbc = pvs->GetBytecode(); AddBind( std::move( pvs ) ); AddBind( std::make_unique( gfx,L"PixelShader.cso" ) ); 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 ) ); struct ConstantBuffer2 { struct { float r; float g; float b; float a; } face_colors[6]; }; const ConstantBuffer2 cb2 = { { { 1.0f,0.0f,1.0f }, { 1.0f,0.0f,0.0f }, { 0.0f,1.0f,0.0f }, { 0.0f,0.0f,1.0f }, { 1.0f,1.0f,0.0f }, { 0.0f,1.0f,1.0f }, } }; AddBind( std::make_unique>( gfx,cb2 ) ); 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 ) ); AddBind( std::make_unique( gfx,D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ) ); 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; } 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 ); }