Az előadás letöltése folymat van. Kérjük, várjon

Az előadás letöltése folymat van. Kérjük, várjon

Kamera, 3D, transzformációk Szécsi László

Hasonló előadás


Az előadások a következő témára: "Kamera, 3D, transzformációk Szécsi László"— Előadás másolata:

1 Kamera, 3D, transzformációk Szécsi László
GraphGame ggl005-Cam Kamera, 3D, transzformációk Szécsi László

2 Egg bővítése Math.zip kibontása az Egg projectkönyvtárba
float2, foat3, float4 típusok, HLSL-ben megszokott műveletekkel float4x4 típus Cam.zip kibontása az Egg projectkönyvtárba Egg::Cam::Base – kamera interface Egg::Cam::FirstPerson – WASD + egér Math, Cam filterek létrehozása, forrásfileok hozzáadása az Egg projecthez

3 Min, max A windows.h-ben definiált makrók nem kellenek
ezért van az stdafx.h-ban az #include <windows.h> (vagy wrl.h) előtt #define NOMINMAX és nem akad össze a Math::min, Math::max-xal

4 gg005-Cam project copy-paste-rename gg004-Mesh folder
vcxproj, filters átnevezés solution/add existing project build, run

5 #6.0 Game.cpp ComPtr<ID3DBlob> vertexShaderByteCode = loadShaderCode("vsIdleTrafo.cso");

6 Shaders/vsTrafo.hlsl #5.0 cbuffer perObject{ float4x4 modelMatrix;
float4x4 modelMatrixInverse; float4x4 modelViewProjMatrix; };

7 Shaders/vsTrafo.hlsl #5.1 struct IaosTrafo { float4 pos : POSITION;
float3 normal : NORMAL; float2 tex : TEXCOORD; }; struct VsosTrafo float4 pos : SV_POSITION; float4 worldPos : WORLDPOS; float3 normal : NORMAL; float2 tex : TEXCOORD;

8 Shaders/vsTrafo.hlsl #5.2 VsosTrafo vsTrafo(IaosTrafo input) {
VsosTrafo output = (VsosTrafo)0; output.pos = mul(input.pos, modelViewProjMatrix); output.worldPos = mul(input.pos, modelMatrix); output.normal = mul(modelMatrixInverse, float4(input.normal.xyz, 0.0)); output.tex = input.tex; return output; }

9 #6.0 Game.h Microsoft::WRL::ComPtr<ID3D11Buffer> perObjectConstantBuffer;

10 #6.0 Game.cpp using namespace Egg::Math; struct float3

11 Game.cpp #6.0 D3D11_BUFFER_DESC constantBufferDesc;
constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; constantBufferDesc.ByteWidth = sizeof(Egg::Math::float4x4) * 3; constantBufferDesc.CPUAccessFlags = 0; constantBufferDesc.MiscFlags = 0; constantBufferDesc.StructureByteStride = 0; constantBufferDesc.Usage = D3D11_USAGE_DEFAULT; Egg::ThrowOnFail("Failed to create constant buffer.", __FILE__, __LINE__) ^ device->CreateBuffer(&constantBufferDesc, nullptr, perObjectConstantBuffer.GetAddressOf());

12 #6.0 Game.cpp material->setCb(Egg::Mesh::ShaderStageFlag::Vertex, 0, perObjectConstantBuffer);

13 Game.cpp - render #6.0 float4x4 perObjectMatrices[3];
perObjectMatrices[2] = float4x4::scaling( float3(0.5, 0.5, 1)); perObjectMatrices[1] = float4x4::identity; perObjectMatrices[0] = float4x4::identity; context->UpdateSubresource(perObjectConstantBuffer.Get(), 0, nullptr, perObjectMatrices, 0, 0);

14 main.cpp if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
app->processMessage(hwnd, msg.message, msg.wParam, msg.lParam); TranslateMessage(&msg); DispatchMessage(&msg); } else { auto currentTime = std::chrono::system_clock::now(); std::chrono::duration<double> timeStep = currentTime - time; std::chrono::duration<double> timeSinceStart = currentTime - startTime; app->animate(timeStep.count(), timeSinceStart.count()); app->render(context); Egg::ThrowOnFail("Failed to present swap chain.", __FILE__, __LINE__) ^ swapChain->Present(0, 0); }

15 Game osztályba #include "Cam/FirstPerson.h"
Egg::Cam::FirstPerson::P firstPersonCam; firstPersonCam = Egg::Cam::FirstPerson::create(); void animate(double dt, double t); bool processMessage( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

16 Game.cpp void Game::animate(double dt, double t) {
if(!firstPersonCam) return; firstPersonCam->animate(dt); } bool Game::processMessage( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if(!firstPersonCam) return false; firstPersonCam->processMessage(hWnd, uMsg, wParam, lParam); return false;

17 #6.0 Game.cpp - render // perObjectMatrices beállítása kamera alapján

18 Itt tartunk, kamera mozgatható


Letölteni ppt "Kamera, 3D, transzformációk Szécsi László"

Hasonló előadás


Google Hirdetések