grafika-lights kezdő
This commit is contained in:
parent
c9fcc60c35
commit
b1cba59ea8
@ -363,6 +363,7 @@ namespace eg3d {
|
||||
{
|
||||
inputElements = {
|
||||
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
|
||||
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}
|
||||
//{"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}
|
||||
// TODO további elemek létrehozása
|
||||
};
|
||||
@ -418,7 +419,7 @@ namespace eg3d {
|
||||
|
||||
psoD.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
|
||||
//psoD.RasterizerState.CullMode = D3D12_CULL_MODE_NONE;
|
||||
psoD.RasterizerState.FillMode = D3D12_FILL_MODE_WIREFRAME;
|
||||
//psoD.RasterizerState.FillMode = D3D12_FILL_MODE_WIREFRAME;
|
||||
psoD.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
|
||||
psoD.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT);
|
||||
psoD.SampleMask = UINT_MAX;
|
||||
|
13
Geometry.cpp
13
Geometry.cpp
@ -141,11 +141,20 @@ namespace eg3d {
|
||||
STLTriangle triangle;
|
||||
inFile.read(reinterpret_cast<char *>(&triangle), 50); // egy háromszög betöltése
|
||||
|
||||
for (auto& vertex : triangle.vertices)
|
||||
for (auto& stlVertex : triangle.vertices)
|
||||
{
|
||||
if (pIAD != nullptr) {
|
||||
pIAD(vertex);
|
||||
pIAD(stlVertex);
|
||||
}
|
||||
|
||||
// koordináták másolása
|
||||
Vertex vertex = stlVertex;
|
||||
|
||||
// normálvektorok hozzárendelése TODO szebben!
|
||||
vertex.nx = triangle.normal.x;
|
||||
vertex.ny = triangle.normal.y;
|
||||
vertex.nz = triangle.normal.z;
|
||||
|
||||
vertices.emplace_back(vertex);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
struct VSInput // vertex shader bemeneti struktúra
|
||||
{
|
||||
float3 position_D : POSITION;
|
||||
//float3 color : COLOR;
|
||||
float3 normal : NORMAL;
|
||||
};
|
||||
|
||||
struct VSOutput // vertex shader kimeneti struktúra
|
||||
@ -29,6 +29,8 @@ VSOutput vs_main(VSInput input)
|
||||
output.position_H = mul(float4(input.position_D, 1.0), mul(worldMatrix, mul(viewMatrix, projMatrix)));
|
||||
output.color = color;
|
||||
|
||||
// TODO fények
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
13
Vertex.cpp
13
Vertex.cpp
@ -18,3 +18,16 @@ eg3d::Vertex::Vertex(std::initializer_list<float> initList) {
|
||||
z = pParams[2];
|
||||
}
|
||||
}
|
||||
|
||||
eg3d::Vertex::Vertex (const Vertex& other)
|
||||
{
|
||||
// koordináták másolása
|
||||
x = other.x;
|
||||
y = other.y;
|
||||
z = other.z;
|
||||
|
||||
// normálvektor másolása
|
||||
nx = other.nx;
|
||||
ny = other.ny;
|
||||
nz = other.nz;
|
||||
}
|
2
Vertex.h
2
Vertex.h
@ -13,11 +13,13 @@ namespace eg3d {
|
||||
struct Vertex {
|
||||
public:
|
||||
float x, y, z; // koordináták
|
||||
float nx, ny, nz; // normálvektor koordinátái
|
||||
// float nx, ny, nz; // normálvektorok TODO
|
||||
|
||||
Vertex(); // default konstruktor
|
||||
Vertex(const DirectX::XMFLOAT3 xmf3); // betöltés XMFLOAT3-ból
|
||||
Vertex(std::initializer_list<float> initList); // konstruktor struktúraszerû inicializációval
|
||||
Vertex(const Vertex& other); // másolókonstruktor
|
||||
};
|
||||
|
||||
}
|
||||
|
51
main.cpp
51
main.cpp
@ -14,6 +14,7 @@
|
||||
#include "Timer.h"
|
||||
#include "Geometry.h"
|
||||
#include "Entity.h"
|
||||
#include <random>
|
||||
|
||||
// FPS-mérés
|
||||
size_t gFrames = 0;
|
||||
@ -31,6 +32,7 @@ using namespace eg3d;
|
||||
|
||||
Cam gCam; // virtuális kamera
|
||||
DrawablePool gDrawables; // geometriák halmaza
|
||||
DrawablePool gTeapots;
|
||||
|
||||
// ÁLLAPOTVÁLTOZÓK
|
||||
bool gMoveForward = false;
|
||||
@ -83,9 +85,44 @@ void mouseCB(EventHandlerCBData * pCBData)
|
||||
pTeapot->loadBinarySTL("assets/utahteapot.stl", ImportAdapters::IAD_SwapYZ_RH);
|
||||
pTeapot->setEntitySRT(srtProps);
|
||||
|
||||
pTeapot->setColor(0.8f, 0.8f, 0.1f);
|
||||
// szín random generálása
|
||||
std::random_device rndDevice;
|
||||
std::uniform_real_distribution<float> dist(0.0f, 1.0f);
|
||||
|
||||
gDrawables.push_back(pTeapot);
|
||||
float r = dist(rndDevice);
|
||||
float g = dist(rndDevice);
|
||||
float b = dist(rndDevice);
|
||||
|
||||
pTeapot->setColor(r, g, b);
|
||||
|
||||
gTeapots.push_back(pTeapot);
|
||||
}
|
||||
|
||||
void randomizeColor()
|
||||
{
|
||||
std::random_device rndDevice;
|
||||
std::uniform_real_distribution<float> dist(0.0f, 1.0f);
|
||||
|
||||
for (auto teapot : gTeapots)
|
||||
{
|
||||
auto pTeapot = static_cast<Entity *>(teapot.get());
|
||||
|
||||
float r = dist(rndDevice);
|
||||
float g = dist(rndDevice);
|
||||
float b = dist(rndDevice);
|
||||
|
||||
pTeapot->setColor(r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
void lMouseCB(EventHandlerCBData * pCbData)
|
||||
{
|
||||
randomizeColor();
|
||||
}
|
||||
|
||||
void timedRandomizeColor(eg3d::Timer *pTimer, const double *pTrigTimeElapsed, void *ptr)
|
||||
{
|
||||
randomizeColor();
|
||||
}
|
||||
|
||||
void moveForward_H(EventHandlerCBData * pCBData)
|
||||
@ -141,6 +178,7 @@ void regEventHandlers(EventHandler * pEH)
|
||||
|
||||
// kattintás
|
||||
pEH->regMouseCB(mouseCB, nullptr, { ET_RMouseDown });
|
||||
pEH->regMouseCB(lMouseCB, nullptr, { ET_LMouseDown });
|
||||
|
||||
// mozgás
|
||||
pEH->regKeyCB('W', moveForward_H, nullptr, { ET_KeyDown, ET_KeyUp }); // előre
|
||||
@ -180,6 +218,9 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszA
|
||||
timerCBData.ptr = nullptr;
|
||||
gTmr1s.reg(timerCBData);
|
||||
|
||||
timerCBData.callBackFn = timedRandomizeColor;
|
||||
gTmr1s.reg(timerCBData);
|
||||
|
||||
std::vector<Vertex> vertices = { // vertexek
|
||||
{ -0.5f, -0.5f, 1.0f },
|
||||
{ 0.5f, -0.5f, 1.0f },
|
||||
@ -250,7 +291,11 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszA
|
||||
std::string winTitle = "Open world game - P: (" + std::to_string(position.x) + "; " + std::to_string(position.y) + "; " + std::to_string(position.z) + "), " +
|
||||
"yaw: " + std::to_string(yaw) + "°, pitch: " +std::to_string(pitch) + "° ---- " + gFPS_FT_msg;
|
||||
win.setTitle(winTitle);
|
||||
win.Draw(gDrawables); // kirajzolás
|
||||
|
||||
DrawablePool mergedDrawables = gDrawables;
|
||||
mergedDrawables.insert(mergedDrawables.end(), gTeapots.begin(), gTeapots.end());
|
||||
|
||||
win.Draw(mergedDrawables); // kirajzolás
|
||||
|
||||
gFrames++; // képkockaszám léptetése
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user