// // Created by Epagris on 2020. 03. 19.. // #include "Entity.h" eg3d::Entity::Entity(const ComPtr &device) : Geometry(device) { createConstantBuffer(); loadDefaults(); } eg3d::Entity::Entity(const Entity& other): Geometry(other.device) { createConstantBuffer(); setEntitySRT(other.getEntitySRT()); } void eg3d::Entity::loadDefaults() { mConstBuf.color = { 1.0f, 1.0f, 1.0f, 1.0f }; XMStoreFloat4x4(&mConstBuf.worldMatrix, XMMatrixIdentity()); // egységmátrix betöltése a világ-mátrixba mSRTProps.loadDefaults(); constructWorldMatrix(); } void eg3d::Entity::setEntitySRT(const eg3d::SRTProps &srtProps) { mSRTProps = srtProps; constructWorldMatrix(); } eg3d::SRTProps eg3d::Entity::getEntitySRT() const { return mSRTProps; } void eg3d::Entity::draw(ComPtr commandList) const { // TODO konstansbuffer becsatolása commandList->SetGraphicsRootConstantBufferView(1, mConstBufRes->GetGPUVirtualAddress()); Geometry::draw(commandList); } void eg3d::Entity::constructWorldMatrix() { // TODO (Cam alapján) auto scaling = mSRTProps.scaling; auto rotation = mSRTProps.rotation; auto translation = mSRTProps.translation; XMMATRIX w = XMMatrixTranslation(translation.x, translation.y, translation.z) * XMMatrixRotationX(rotation.x) * XMMatrixRotationY(rotation.y) * XMMatrixRotationZ(rotation.z) * XMMatrixScaling(scaling.x, scaling.y, scaling.z); w = XMMatrixTranspose(w); XMStoreFloat4x4(&mConstBuf.worldMatrix, w); // konstansbuffer felmásolása a videokártyára updateConstantBuffer(); } void eg3d::Entity::createConstantBuffer() { mConstBufRes = createBuffer_UH(device, calc256AlignedSize(sizeof(CB_Entity))); } void eg3d::Entity::updateConstantBuffer() { bufferMapCopy(mConstBufRes, static_cast(&mConstBuf), sizeof(CB_Entity)); } void eg3d::Entity::setColor(float r, float g, float b) { mConstBuf.color = { r, g, b, 1.0f }; updateConstantBuffer(); } // ---------------------- eg3d::SRTProps::SRTProps() { loadDefaults(); } void eg3d::SRTProps::loadDefaults() { scaling = { 1.0f, 1.0f, 1.0f }; rotation = { 0.0f, 0.0f, 0.0f }; translation = {0.0f, 0.0f, 0.0f }; }