Commit db7a5eb3 authored by Administrator's avatar Administrator
Browse files

added lines and rectangle as drawable; added shader by fixed color; used...

added lines and rectangle as drawable; added shader by fixed color; used template for VertexBuffer; added icon for app
parent 8b194540
...@@ -9,3 +9,6 @@ x64/ ...@@ -9,3 +9,6 @@ x64/
# Exclude log.txt # Exclude log.txt
*/log.txt */log.txt
# Exclude imgui status file
PracticeDx/imgui.ini
\ No newline at end of file
...@@ -14,44 +14,16 @@ ...@@ -14,44 +14,16 @@
#include "Texture.h" #include "Texture.h"
#include "Sampler.h" #include "Sampler.h"
Box::Box(Graphics& gfx, StructVertex vertices[], Logger& logger) Box::Box(Graphics& gfx, StructVertexWithTexture vertices[], Logger& logger)
{ {
// Assign values for vertex and texture
/*for (int i = 0; i < 24; i++)
{
this->vertices[i] = vertices[i];
}*/
/************************************ /************************************
* 2.3 DefineVertexBuffer * 2.3 DefineVertexBuffer
************************************/ ************************************/
const std::vector<StructVertex> vb = std::vector<StructVertexWithTexture> vb;
for (int i = 0; i < 24; i++)
{ {
{ vertices[0] }, vb.push_back(vertices[i]);
{ vertices[1] }, }
{ vertices[2] },
{ vertices[3] },
{ vertices[4] },
{ vertices[5] },
{ vertices[6] },
{ vertices[7] },
{ vertices[8] },
{ vertices[9] },
{ vertices[10] },
{ vertices[11] },
{ vertices[12] },
{ vertices[13] },
{ vertices[14] },
{ vertices[15] },
{ vertices[16] },
{ vertices[17] },
{ vertices[18] },
{ vertices[19] },
{ vertices[20] },
{ vertices[21] },
{ vertices[22] },
{ vertices[23] },
};
AddBind(std::make_unique<VertexBuffer>(gfx, vb, logger)); AddBind(std::make_unique<VertexBuffer>(gfx, vb, logger));
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
class Box : public DrawableBase<Box> class Box : public DrawableBase<Box>
{ {
public: public:
Box(Graphics& gfx, StructVertex vertices[], Logger& logger); Box(Graphics& gfx, StructVertexWithTexture vertices[], Logger& logger);
void Update(float dt) noexcept override; void Update(float dt) noexcept override;
//void UpdateCamera(float sin, float cos) noexcept; //void UpdateCamera(float sin, float cos) noexcept;
//void SetCamera(DirectX::XMVECTOR upDirection, DirectX::XMVECTOR eyePosition, DirectX::XMVECTOR focusPosition) noexcept; //void SetCamera(DirectX::XMVECTOR upDirection, DirectX::XMVECTOR eyePosition, DirectX::XMVECTOR focusPosition) noexcept;
......
struct PSInput
{
float3 color : Color;
};
float4 main(PSInput input) : SV_Target
{
return float4(input.color, 1.0f);
}
\ No newline at end of file
cbuffer CBuf
{
matrix transform;
};
struct VSInput
{
float3 pos : Position;
float3 color : Color;
};
struct VSOut
{
float4 pos : SV_Position;
float3 color : Color;
};
VSOut main(VSInput input)
{
VSOut vso;
vso.pos = mul(float4(input.pos, 1.0f), transform);
vso.color = input.color;
return vso;
}
...@@ -48,37 +48,37 @@ void CoreHandler::processEvents(Window& window, Graphics& gfx, HWND& hWnd, Logge ...@@ -48,37 +48,37 @@ void CoreHandler::processEvents(Window& window, Graphics& gfx, HWND& hWnd, Logge
{ {
cameraDeltaY = 80 - cameraY; cameraDeltaY = 80 - cameraY;
} }
if (cameraY + cameraDeltaY <= -80) if (cameraY + cameraDeltaY <= 40)
{ {
cameraDeltaY = -80 - cameraY; cameraDeltaY = 40 - cameraY;
} }
} }
oss << " | ViewAt(" << cameraX << "," << cameraY << ")"; oss << " | ViewAt(" << cameraX << "," << cameraY << ")";
oss << " | Dragging(" << cameraDeltaX << "," << cameraDeltaY << ")"; oss << " | Dragging(" << cameraDeltaX << "," << cameraDeltaY << ")";
oss << " | vSinValue(" << sin((cameraY + cameraDeltaY) / 100.0f) << ")"; oss << " | vSinValue(" << sin((cameraY + cameraDeltaY) / 100.0f) << ")";
window.SetTitle(hWnd, oss.str()); //window.SetTitle(hWnd, oss.str());
break; break;
} }
case (Mouse::MouseEvent::Type::LClick): case (Mouse::MouseEvent::Type::LClick):
{ {
std::ostringstream oss; std::ostringstream oss;
oss << "(" << mouseEvent.GetX() << "," << mouseEvent.GetY() << "): Mouse Left Clicked"; oss << "(" << mouseEvent.GetX() << "," << mouseEvent.GetY() << "): Mouse Left Clicked";
window.SetTitle(hWnd, oss.str()); //window.SetTitle(hWnd, oss.str());
break; break;
} }
case (Mouse::MouseEvent::Type::LRelease): case (Mouse::MouseEvent::Type::LRelease):
{ {
std::ostringstream oss; std::ostringstream oss;
oss << "(" << mouseEvent.GetX() << "," << mouseEvent.GetY() << "): Mouse Left Released"; oss << "(" << mouseEvent.GetX() << "," << mouseEvent.GetY() << "): Mouse Left Released";
window.SetTitle(hWnd, oss.str()); //window.SetTitle(hWnd, oss.str());
break; break;
} }
case (Mouse::MouseEvent::Type::RClick): case (Mouse::MouseEvent::Type::RClick):
{ {
std::ostringstream oss; std::ostringstream oss;
oss << "(" << mouseEvent.GetX() << "," << mouseEvent.GetY() << "): Mouse Right Clicked"; oss << "(" << mouseEvent.GetX() << "," << mouseEvent.GetY() << "): Mouse Right Clicked";
window.SetTitle(hWnd, oss.str()); //window.SetTitle(hWnd, oss.str());
break; break;
} }
case (Mouse::MouseEvent::Type::RRelease): case (Mouse::MouseEvent::Type::RRelease):
...@@ -92,7 +92,7 @@ void CoreHandler::processEvents(Window& window, Graphics& gfx, HWND& hWnd, Logge ...@@ -92,7 +92,7 @@ void CoreHandler::processEvents(Window& window, Graphics& gfx, HWND& hWnd, Logge
cameraDeltaY = 0; cameraDeltaY = 0;
oss << "(" << mouseEvent.GetX() << "," << mouseEvent.GetY() << "): Mouse Right Released"; oss << "(" << mouseEvent.GetX() << "," << mouseEvent.GetY() << "): Mouse Right Released";
window.SetTitle(hWnd, oss.str()); //window.SetTitle(hWnd, oss.str());
break; break;
} }
case (Mouse::MouseEvent::Type::Wheel): case (Mouse::MouseEvent::Type::Wheel):
...@@ -104,7 +104,7 @@ void CoreHandler::processEvents(Window& window, Graphics& gfx, HWND& hWnd, Logge ...@@ -104,7 +104,7 @@ void CoreHandler::processEvents(Window& window, Graphics& gfx, HWND& hWnd, Logge
oss << "(" << mouseEvent.GetX() << "," << mouseEvent.GetY() << "): Mouse WheelUp"; oss << "(" << mouseEvent.GetX() << "," << mouseEvent.GetY() << "): Mouse WheelUp";
oss << " | cameraDeltaZ(" << cameraDeltaZ << ")"; oss << " | cameraDeltaZ(" << cameraDeltaZ << ")";
window.SetTitle(hWnd, oss.str()); //window.SetTitle(hWnd, oss.str());
break; break;
} }
} }
...@@ -132,8 +132,9 @@ void CoreHandler::CoreProcess(Window& window, Graphics& gfx, HWND& hWnd, Logger& ...@@ -132,8 +132,9 @@ void CoreHandler::CoreProcess(Window& window, Graphics& gfx, HWND& hWnd, Logger&
// render imgui // render imgui
auto imIO = ImGui::GetIO(); auto imIO = ImGui::GetIO();
ImGui::Text("camera Y : [ %.2f ]", cameraY); //ImGui::Text("camera Y : [ %.2f ]", cameraY);
ImGui::Text("camera Delta Y : [ %.2f ]", cameraDeltaY); //ImGui::Text("camera Delta Y : [ %.2f ]", cameraDeltaY);
//ImGui::Text("wheelDelta : [ %d ]", window.mouse.GetWheelDelta());
ImGui::Text("Framerate : [ %.2f ]", imIO.Framerate); ImGui::Text("Framerate : [ %.2f ]", imIO.Framerate);
ImGui::Text("MS per Frame : [ %.3f ]", 1000.0f / imIO.Framerate); ImGui::Text("MS per Frame : [ %.3f ]", 1000.0f / imIO.Framerate);
ImGui::Render(); ImGui::Render();
......
...@@ -18,7 +18,7 @@ private: ...@@ -18,7 +18,7 @@ private:
double seed; double seed;
float cameraX = 80.0f; float cameraX = 80.0f;
float cameraY = 60.0f; float cameraY = 60.0f;
float cameraZ = 5.0f; float cameraZ = 20.0f;
float cameraDeltaX = 0; float cameraDeltaX = 0;
float cameraDeltaY = 0; float cameraDeltaY = 0;
float cameraDeltaZ = 0; float cameraDeltaZ = 0;
......
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
#include "Ground.h" #include "Ground.h"
#include "Surface.h" #include "Surface.h"
#include "Structs.h" #include "Structs.h"
#include "Lines.h"
#include "Rectangle.h"
Ground::Ground(Graphics & gfx, Logger & logger) noexcept Ground::Ground(Graphics & gfx, Logger & logger) noexcept
{ {
// Init 2 surfaces // Init 2 surfaces
Surface *yueyueSurface = new Surface(); /*Surface *yueyueSurface = new Surface();
yueyueSurface->LoadImageFromFile(gfx.getDevice(), gfx.getContext(), "resource\\img\\yueyue.jpg"); yueyueSurface->LoadImageFromFile(gfx.getDevice(), gfx.getContext(), "resource\\img\\yueyue.jpg");
float yueyueSlot = yueyueSurface->GetCurrSlot(); float yueyueSlot = yueyueSurface->GetCurrSlot();
...@@ -16,76 +18,128 @@ Ground::Ground(Graphics & gfx, Logger & logger) noexcept ...@@ -16,76 +18,128 @@ Ground::Ground(Graphics & gfx, Logger & logger) noexcept
Surface* ethanAndYueyueSurface = new Surface(); Surface* ethanAndYueyueSurface = new Surface();
ethanAndYueyueSurface->LoadImageFromFile(gfx.getDevice(), gfx.getContext(), "resource\\img\\Ethan_and_yueyue.png"); ethanAndYueyueSurface->LoadImageFromFile(gfx.getDevice(), gfx.getContext(), "resource\\img\\Ethan_and_yueyue.png");
float ethanAndYueyueSlot = ethanAndYueyueSurface->GetCurrSlot(); float ethanAndYueyueSlot = ethanAndYueyueSurface->GetCurrSlot();*/
Surface* grass = new Surface();
grass->LoadImageFromFile(gfx.getDevice(), gfx.getContext(), "resource\\img\\Grass.jpeg");
float grassSlot = grass->GetCurrSlot();
// Draw grass ground
for (int i = 0; i < 2; i+=2 ) for (int i = 0; i < 2; i+=2 )
for (int j = 0; j < 2; j+= 2) for (int j = 0; j < 2; j+= 2)
{ {
StructVertex vertices[24] = { StructVertexWithTexture vertices[24] = {
// back surface // back surface
// left top back // left top back
{ XMFLOAT3(-1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(0.0f, 0.0f), yueyueSlot }, { XMFLOAT3(-10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
// right top back // right top back
{ XMFLOAT3(1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(1.0f, 0.0f), yueyueSlot }, { XMFLOAT3(10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
// left bottom back // left bottom back
{ XMFLOAT3(-1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(0.0f, 1.0f), yueyueSlot }, { XMFLOAT3(-10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
// right bottom back // right bottom back
{ XMFLOAT3(1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(1.0f, 1.0f), yueyueSlot }, { XMFLOAT3(10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },
// left surface // left surface
// left top front // left top front
{ XMFLOAT3(-1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(0.0f, 0.0f), ethanSlot }, { XMFLOAT3(-10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
// left top back // left top back
{ XMFLOAT3(-1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(1.0f, 0.0f), ethanSlot }, { XMFLOAT3(-10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
// left bottom front // left bottom front
{ XMFLOAT3(-1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(0.0f, 1.0f), ethanSlot }, { XMFLOAT3(-10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
// left bottom back // left bottom back
{ XMFLOAT3(-1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(1.0f, 1.0f), ethanSlot }, { XMFLOAT3(-10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },
// right surface // right surface
// right top back // right top back
{ XMFLOAT3(1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(0.0f, 0.0f), ethanSlot }, { XMFLOAT3(10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
// right top front // right top front
{ XMFLOAT3(1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(1.0f, 0.0f), ethanSlot }, { XMFLOAT3(10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
// right bottom back // right bottom back
{ XMFLOAT3(1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(0.0f, 1.0f), ethanSlot }, { XMFLOAT3(10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
// right bottom front // right bottom front
{ XMFLOAT3(1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(1.0f, 1.0f), ethanSlot }, { XMFLOAT3(10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },
// top surface // top surface
// left top front // left top front
{ XMFLOAT3(-1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(0.0f, 0.0f), ethanAndYueyueSlot }, { XMFLOAT3(-10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
// right top front // right top front
{ XMFLOAT3(1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(1.0f, 0.0f), ethanAndYueyueSlot }, { XMFLOAT3(10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
// left top back // left top back
{ XMFLOAT3(-1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(0.0f, 1.0f), ethanAndYueyueSlot }, { XMFLOAT3(-10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
// right top back // right top back
{ XMFLOAT3(1.0f + i, 1.0f, -1.0f + j), XMFLOAT2(1.0f, 1.0f), ethanAndYueyueSlot }, { XMFLOAT3(10.0f + i, 1.0f, -10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },
// front surface // front surface
// right top front // right top front
{ XMFLOAT3(1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(0.0f, 0.0f), yueyueSlot }, { XMFLOAT3(10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
// left top front // left top front
{ XMFLOAT3(-1.0f + i, 1.0f, 1.0f + j), XMFLOAT2(1.0f, 0.0f), yueyueSlot }, { XMFLOAT3(-10.0f + i, 1.0f, 10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
// right bottom front // right bottom front
{ XMFLOAT3(1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(0.0f, 1.0f), yueyueSlot }, { XMFLOAT3(10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
// left bottom front // left bottom front
{ XMFLOAT3(-1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(1.0f, 1.0f), yueyueSlot }, { XMFLOAT3(-10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },
// bottom surface // bottom surface
// left bottom back // left bottom back
{ XMFLOAT3(-1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(0.0f, 0.0f), ethanAndYueyueSlot }, { XMFLOAT3(-10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(0.0f, 0.0f), grassSlot },
// right bottom back // right bottom back
{ XMFLOAT3(1.0f + i, -1.0f, -1.0f + j), XMFLOAT2(1.0f, 0.0f), ethanAndYueyueSlot }, { XMFLOAT3(10.0f + i, -1.0f, -10.0f + j), XMFLOAT2(1.0f, 0.0f), grassSlot },
// left bottom front // left bottom front
{ XMFLOAT3(-1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(0.0f, 1.0f), ethanAndYueyueSlot }, { XMFLOAT3(-10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(0.0f, 1.0f), grassSlot },
// right bottom front // right bottom front
{ XMFLOAT3(1.0f + i, -1.0f, 1.0f + j), XMFLOAT2(1.0f, 1.0f), ethanAndYueyueSlot }, { XMFLOAT3(10.0f + i, -1.0f, 10.0f + j), XMFLOAT2(1.0f, 1.0f), grassSlot },
}; };
shapes.push_back(std::make_unique<Box>(gfx, vertices, logger)); shapes.push_back(std::make_unique<Box>(gfx, vertices, logger));
} }
XMFLOAT3 black = XMFLOAT3(1.0f, 1.0f, 1.0f);
StructVertexWithColor vertices[22];
// Draw horizon lines
for (int i = 0; i < 11; i++)
{
vertices[i*2] = { XMFLOAT3(-10.0f, 1.01f, -10.0f + i*2), black };
vertices[i*2 + 1] = { XMFLOAT3(10.0f, 1.01f, -10.0f + i * 2), black };
}
shapes.push_back(std::make_unique<Lines>(gfx, vertices, 22, logger));
// Draw vertical lines
for (int i = 0; i < 11; i++)
{
vertices[i * 2] = { XMFLOAT3(-10.0f + i * 2, 1.01f, -10.0f), black };
vertices[i * 2 + 1] = { XMFLOAT3(-10.0f + i * 2, 1.01f, 10.0f), black };
}
shapes.push_back(std::make_unique<Lines>(gfx, vertices, 22, logger));
// Draw horizon lines using Rectangle
//XMFLOAT3 black = XMFLOAT3(1.0f, 1.0f, 1.0f);
//float width = 0.02f;
//for (int i = 0; i < 21; i++)
//{
// StructVertexWithColor vertices[4];
// vertices[0] = { XMFLOAT3(-10.0f, 1.01f, -10.0f - width + i), black };
// vertices[1] = { XMFLOAT3(-10.0f, 1.01f, -10.0f + width + i), black };
// vertices[2] = { XMFLOAT3(10.0f, 1.01f, -10.0f - width + i), black };
// vertices[3] = { XMFLOAT3(10.0f, 1.01f, -10.0f + width + i), black };
// shapes.push_back(std::make_unique<class Rectangle>(gfx, vertices, logger));
//}
//// Draw vertical lines using Rectangle
//for (int i = 0; i < 21; i++)
//{
// StructVertexWithColor vertices[4];
// vertices[0] = { XMFLOAT3(-10.0f + width + i, 1.01f, -10.0f), black };
// vertices[1] = { XMFLOAT3(-10.0f - width + i, 1.01f, -10.0f), black };
// vertices[2] = { XMFLOAT3(-10.0f + width + i, 1.01f, 10.0f), black };
// vertices[3] = { XMFLOAT3(-10.0f - width + i, 1.01f, 10.0f), black };
// shapes.push_back(std::make_unique<class Rectangle>(gfx, vertices, logger));
//}
}; };
#pragma once
#include "Lines.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 <DirectXMath.h>
#include "Texture.h"
#include "Sampler.h"
Lines::Lines(Graphics& gfx, StructVertexWithColor vertices[], int vertexSize, Logger& logger)
{
/************************************
* 2.3 DefineVertexBuffer
************************************/
std::vector<StructVertexWithColor> vb;
for (int i = 0; i < vertexSize; i++)
{
vb.push_back(vertices[i]);
}
AddBind(std::make_unique<VertexBuffer>(gfx, vb, 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<PixelConstantBuffer<StructPixelConstBuf>>(gfx, cb2));
/************************************
* 2.5 DefineTransConstBuffer
************************************/
AddBind(std::make_unique<TransformCbuf>(gfx, *this));
if (!IsStaticInitialized())
{
/************************************
* 2.7 DefineVertexShader
************************************/
//auto pVertexShader = std::make_unique<VertexShader>(gfx, L"VertexShader.cso");
auto pVertexShader = std::make_unique<VertexShader>(gfx, L"ColorVS.cso");
auto pvsbc = pVertexShader->GetBytecode();
//AddBind(std::move(pVertexShader));
AddStaticBind(std::move(pVertexShader));
/************************************
* 2.8 DefinePixelShader
************************************/
//AddBind(std::make_unique<PixelShader>(gfx, L"PixelShader.cso"));
//AddStaticBind(std::make_unique<PixelShader>(gfx, L"PixelShader.cso"));
AddStaticBind(std::make_unique<PixelShader>(gfx, L"ColorPS.cso"));
/************************************
* 2.4 DefineIndexBuffer
************************************/
std::vector<unsigned short> indices;
for (int i = 0; i < vertexSize; i+=2)
{
indices.push_back(i);
indices.push_back(i+1);
}
/*const std::vector<unsigned short> indices =
{
0,1,2, 2,1,3,
4,5,6, 6,5,7,
8,9,10, 10,9,11,
12,13,14, 14,13,15,
16,17,18, 18,17,19,
20,21,22, 22,21,23,
};*/
//AddIndexBuffer(std::make_unique<IndexBuffer>(gfx, indices, logger));
AddStaticIndexBuffer(std::make_unique<IndexBuffer>(gfx, indices, logger));
/************************************
* 2.9 DefineInputLayout
************************************/
const std::vector<D3D11_INPUT_ELEMENT_DESC> ied =
{
//{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{ "Color",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0 },
};
//AddBind(std::make_unique<InputLayout>(gfx, ied, pvsbc));
AddStaticBind(std::make_unique<InputLayout>(gfx, ied, pvsbc));
/************************************
* 2.10 DefinePrimitiveTopology
************************************/
//AddBind(std::make_unique<Topology>(gfx, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST));
AddStaticBind(std::make_unique<Topology>(gfx, D3D11_PRIMITIVE_TOPOLOGY_LINELIST));
///************************************
//* 2.21 DefineTextureForEachSurface
//************************************/
//for (int i = 0; i < 6; i++) {
// AddStaticBind(std::make_unique<Texture>(gfx, surface[i]));
//}
/************************************
* 2.22 DefineSampler
************************************/
//AddStaticBind(std::make_unique<Sampler>(gfx));
}
else
{
SetIndexFromStatic();
}
}
void Lines::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 Lines::GetTransformXM(Graphics& gfx) 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);*/
DirectX::XMMATRIX lookAtMatrix = gfx.getLookAtMatrix();
return
DirectX::XMMatrixTranslation(dx, dy, dz)
//* DirectX::XMMatrixLookAtLH(eyePosition, focusPosition, upDirection);
* lookAtMatrix;
}
\ No newline at end of file
#pragma once
#include "DrawableBase.h"
#include "Logger.h"
#include "Structs.h"
#include "Surface.h"
class Lines : public DrawableBase<Lines>
{
public:
Lines(Graphics& gfx, StructVertexWithColor vertices[], int vertexSize, Logger& logger);
void Update(float dt) noexcept override;
DirectX::XMMATRIX GetTransformXM(Graphics& gfx) const noexcept override;
private:
//StructVertex vertices[24];
// trasformation
float dx = 0.0f;
float dy = 0.0f;
float dz = 0.0f;
};
\ No newline at end of file
...@@ -112,13 +112,13 @@ void Mouse::OnRightRelease(int newX, int newY) ...@@ -112,13 +112,13 @@ void Mouse::OnRightRelease(int newX, int newY)
void Mouse::OnWheelDelta(int x, int y, int delta) void Mouse::OnWheelDelta(int x, int y, int delta)
{ {
wheelDelta += delta; wheelDelta += delta;
if (wheelDelta >= 2.0f * WHEEL_DELTA) if (wheelDelta >= 12.0f * WHEEL_DELTA)
{ {
wheelDelta = 2.0f * WHEEL_DELTA; wheelDelta = 12.0f * WHEEL_DELTA;
} }
if (wheelDelta <= -120.0f * WHEEL_DELTA) if (wheelDelta <= -8.0f * WHEEL_DELTA)
{ {
wheelDelta = -120.0f * WHEEL_DELTA; wheelDelta = -8.0f * WHEEL_DELTA;
} }
mouseEvents.push(Mouse::MouseEvent(Mouse::MouseEvent::Type::Wheel, *this)); mouseEvents.push(Mouse::MouseEvent(Mouse::MouseEvent::Type::Wheel, *this));
......
B// Microsoft Visual C++ generated resource script. B// Microsoft Visual C++ generated resource script.
...@@ -142,7 +142,9 @@ ...@@ -142,7 +142,9 @@
<ClCompile Include="imgui\imgui_impl_win32.cpp" /> <ClCompile Include="imgui\imgui_impl_win32.cpp" />
<ClCompile Include="imgui\imgui_tables.cpp" /> <ClCompile Include="imgui\imgui_tables.cpp" />
<ClCompile Include="imgui\imgui_widgets.cpp" /> <ClCompile Include="imgui\imgui_widgets.cpp" />
<ClCompile Include="Lines.cpp" />
<ClCompile Include="Mouse.cpp" /> <ClCompile Include="Mouse.cpp" />
<ClCompile Include="Rectangle.cpp" />
<ClCompile Include="Sampler.cpp" /> <ClCompile Include="Sampler.cpp" />
<ClCompile Include="Scene.cpp" /> <ClCompile Include="Scene.cpp" />
<ClCompile Include="Stage.cpp" /> <ClCompile Include="Stage.cpp" />
...@@ -163,6 +165,16 @@ ...@@ -163,6 +165,16 @@
<ClCompile Include="WinMain.cpp" /> <ClCompile Include="WinMain.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<FxCompile Include="ColorPS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0_level_9_3</ShaderModel>
</FxCompile>
<FxCompile Include="ColorVS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0_level_9_3</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)%(Filename).cso</ObjectFileOutput>
</FxCompile>
<FxCompile Include="PixelShader.hlsl"> <FxCompile Include="PixelShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
...@@ -208,7 +220,10 @@ ...@@ -208,7 +220,10 @@
<ClInclude Include="imgui\imstb_rectpack.h" /> <ClInclude Include="imgui\imstb_rectpack.h" />
<ClInclude Include="imgui\imstb_textedit.h" /> <ClInclude Include="imgui\imstb_textedit.h" />
<ClInclude Include="imgui\imstb_truetype.h" /> <ClInclude Include="imgui\imstb_truetype.h" />
<ClInclude Include="Lines.h" />
<ClInclude Include="Mouse.h" /> <ClInclude Include="Mouse.h" />
<ClInclude Include="Rectangle.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Sampler.h" /> <ClInclude Include="Sampler.h" />
<ClInclude Include="Scene.h" /> <ClInclude Include="Scene.h" />
<ClInclude Include="Stage.h" /> <ClInclude Include="Stage.h" />
...@@ -228,6 +243,12 @@ ...@@ -228,6 +243,12 @@
<ClInclude Include="VertexShader.h" /> <ClInclude Include="VertexShader.h" />
<ClInclude Include="Window.h" /> <ClInclude Include="Window.h" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ResourceCompile Include="PracticeDx.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="resource\img\oasis.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
......
...@@ -123,9 +123,6 @@ ...@@ -123,9 +123,6 @@
<ClCompile Include="CoreHandler.cpp"> <ClCompile Include="CoreHandler.cpp">
<Filter>Source Files\Common</Filter> <Filter>Source Files\Common</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Mouse.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="imgui\imgui.cpp"> <ClCompile Include="imgui\imgui.cpp">
<Filter>imgui</Filter> <Filter>imgui</Filter>
</ClCompile> </ClCompile>
...@@ -153,6 +150,15 @@ ...@@ -153,6 +150,15 @@
<ClCompile Include="Stage.cpp"> <ClCompile Include="Stage.cpp">
<Filter>Source Files\Scenes</Filter> <Filter>Source Files\Scenes</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Lines.cpp">
<Filter>Source Files\Drawables</Filter>
</ClCompile>
<ClCompile Include="Mouse.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="Rectangle.cpp">
<Filter>Source Files\Drawables</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<FxCompile Include="PixelShader.hlsl"> <FxCompile Include="PixelShader.hlsl">
...@@ -167,6 +173,12 @@ ...@@ -167,6 +173,12 @@
<FxCompile Include="TextureVS.hlsl"> <FxCompile Include="TextureVS.hlsl">
<Filter>Shaders</Filter> <Filter>Shaders</Filter>
</FxCompile> </FxCompile>
<FxCompile Include="ColorPS.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
<FxCompile Include="ColorVS.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Bindable.h"> <ClInclude Include="Bindable.h">
...@@ -271,5 +283,24 @@ ...@@ -271,5 +283,24 @@
<ClInclude Include="Stage.h"> <ClInclude Include="Stage.h">
<Filter>Header Files\Scenes</Filter> <Filter>Header Files\Scenes</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Lines.h">
<Filter>Header Files\Drawables</Filter>
</ClInclude>
<ClInclude Include="Rectangle.h">
<Filter>Header Files\Drawables</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Resource Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="PracticeDx.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="resource\img\oasis.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
#pragma once
#include "Rectangle.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 <DirectXMath.h>
#include "Texture.h"
#include "Structs.h"
Rectangle::Rectangle(Graphics& gfx, StructVertexWithColor vertices[], Logger& logger)
{
/************************************
* 2.3 DefineVertexBuffer
************************************/
std::vector<StructVertexWithColor> vb;
for (int i = 0; i < 4; i++)
{
vb.push_back(vertices[i]);
}
AddBind(std::make_unique<VertexBuffer>(gfx, vb, logger));
//AddBind(std::make_unique<PixelConstantBuffer<StructPixelConstBuf>>(gfx, cb2));
/************************************
* 2.5 DefineTransConstBuffer
************************************/
AddBind(std::make_unique<TransformCbuf>(gfx, *this));
if (!IsStaticInitialized())
{
/************************************
* 2.7 DefineVertexShader
************************************/
auto pVertexShader = std::make_unique<VertexShader>(gfx, L"ColorVS.cso");
auto pvsbc = pVertexShader->GetBytecode();
//AddBind(std::move(pVertexShader));
AddStaticBind(std::move(pVertexShader));
/************************************
* 2.8 DefinePixelShader
************************************/
AddStaticBind(std::make_unique<PixelShader>(gfx, L"ColorPS.cso"));
/************************************
* 2.4 DefineIndexBuffer
************************************/
const std::vector<unsigned short> indices =
{
0,1,2, 2,1,3,
};
AddStaticIndexBuffer(std::make_unique<IndexBuffer>(gfx, indices, logger));
/************************************
* 2.9 DefineInputLayout
************************************/
const std::vector<D3D11_INPUT_ELEMENT_DESC> ied =
{
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{ "Color",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0 },
};
AddStaticBind(std::make_unique<InputLayout>(gfx, ied, pvsbc));
/************************************
* 2.10 DefinePrimitiveTopology
************************************/
AddStaticBind(std::make_unique<Topology>(gfx, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST));
}
else
{
SetIndexFromStatic();
}
}
void Rectangle::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 Rectangle::GetTransformXM(Graphics& gfx) const noexcept
{
DirectX::XMMATRIX lookAtMatrix = gfx.getLookAtMatrix();
return
DirectX::XMMatrixTranslation(dx, dy, dz)
* lookAtMatrix;
}
\ No newline at end of file
#pragma once
#include "DrawableBase.h"
#include "Logger.h"
#include "Structs.h"
#include "Surface.h"
class Rectangle : public DrawableBase<class Rectangle>
{
public:
Rectangle(Graphics& gfx, StructVertexWithColor vertices[], Logger& logger);
void Update(float dt) noexcept override;
DirectX::XMMATRIX GetTransformXM(Graphics& gfx) const noexcept override;
private:
float dx = 0.0f;
float dy = 0.0f;
float dz = 0.0f;
};
\ No newline at end of file
...@@ -4,15 +4,23 @@ ...@@ -4,15 +4,23 @@
using DirectX::XMFLOAT2; using DirectX::XMFLOAT2;
using DirectX::XMFLOAT3; using DirectX::XMFLOAT3;
// 用于定义顶点的结构,三维坐标 // 用于定义带有贴图的顶点的结构,三维坐标+纹理坐标映射+纹理编号
// position[3] + texture[2] + slot[1] // position[3] + texture[2] + slot[1]
struct StructVertex struct StructVertexWithTexture
{ {
DirectX::XMFLOAT3 pos; DirectX::XMFLOAT3 pos;
DirectX::XMFLOAT2 texCoord; DirectX::XMFLOAT2 texCoord;
float slot; float slot;
}; };
// 用于定义固定色彩的顶点的结构,三维坐标+色彩RGB
// position[3] + color[3]
struct StructVertexWithColor
{
DirectX::XMFLOAT3 pos;
DirectX::XMFLOAT3 color;
};
struct StructPixelConstBuf struct StructPixelConstBuf
{ {
struct struct
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "TransformCBuf.h" #include "TransformCBuf.h"
#include "Graphics.h" #include "Graphics.h"
Triangle::Triangle(Graphics& gfx, StructVertex vertices[], Logger& logger) Triangle::Triangle(Graphics& gfx, StructVertexWithTexture vertices[], Logger& logger)
{ {
// Assign position values // Assign position values
//for (int i = 0; i < 3; i++) //for (int i = 0; i < 3; i++)
...@@ -34,7 +34,7 @@ Triangle::Triangle(Graphics& gfx, StructVertex vertices[], Logger& logger) ...@@ -34,7 +34,7 @@ Triangle::Triangle(Graphics& gfx, StructVertex vertices[], Logger& logger)
/************************************ /************************************
* 2.3 DefineVertexBuffer * 2.3 DefineVertexBuffer
************************************/ ************************************/
const std::vector<StructVertex> vb = const std::vector<StructVertexWithTexture> vb =
{ {
{ vertices[0] }, { vertices[0] },
{ vertices[1] }, { vertices[1] },
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
class Triangle : public Drawable class Triangle : public Drawable
{ {
public: public:
Triangle(Graphics& gfx, StructVertex vertices[], Logger& logger); Triangle(Graphics& gfx, StructVertexWithTexture vertices[], Logger& logger);
void Update(float dt) noexcept override; void Update(float dt) noexcept override;
DirectX::XMMATRIX GetTransformXM(Graphics& gfx) const noexcept override; DirectX::XMMATRIX GetTransformXM(Graphics& gfx) const noexcept override;
private: private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment