목차

     

     


     

     

    MeshCube

     

     


    MeshCube

     

    MeshCube.h

    더보기
    #pragma once
    
    class MeshCube : public Mesh
    {
    public:
    	MeshCube(Shader* shader);
    	~MeshCube();
    
    private:
    	void Create() override; //Mesh.h에 있는 Create() 재정의
    };

     

     

    MeshCube.cpp

    더보기
    #include "Framework.h"
    #include "MeshCube.h"
    
    MeshCube::MeshCube(Shader * shader)
    	: Mesh(shader)
    {
    }
    
    MeshCube::~MeshCube()
    {
    }
    
    void MeshCube::Create()
    {
    	float w = 0.5f;
    	float h = 0.5f;
    	float d = 0.5f;
    
    	vector<MeshVertex> v;
    
    	//Front
    	v.push_back(MeshVertex(-w, -h, -d, 0, 1, 0, 0, -1));
    	v.push_back(MeshVertex(-w, +h, -d, 0, 0, 0, 0, -1));
    	v.push_back(MeshVertex(+w, +h, -d, 1, 0, 0, 0, -1));
    	v.push_back(MeshVertex(+w, -h, -d, 1, 1, 0, 0, -1));
    
    	//Back
    	v.push_back(MeshVertex(-w, -h, +d, 1, 1, 0, 0, 1));
    	v.push_back(MeshVertex(+w, -h, +d, 0, 1, 0, 0, 1));
    	v.push_back(MeshVertex(+w, +h, +d, 0, 0, 0, 0, 1));
    	v.push_back(MeshVertex(-w, +h, +d, 1, 0, 0, 0, 1));
    
    	//Top
    	v.push_back(MeshVertex(-w, +h, -d, 0, 1, 0, 1, 0));
    	v.push_back(MeshVertex(-w, +h, +d, 0, 0, 0, 1, 0));
    	v.push_back(MeshVertex(+w, +h, +d, 1, 0, 0, 1, 0));
    	v.push_back(MeshVertex(+w, +h, -d, 1, 1, 0, 1, 0));
    
    	//Bottom
    	v.push_back(MeshVertex(-w, -h, -d, 1, 1, 0, -1, 0));
    	v.push_back(MeshVertex(+w, -h, -d, 0, 1, 0, -1, 0));
    	v.push_back(MeshVertex(+w, -h, +d, 0, 0, 0, -1, 0));
    	v.push_back(MeshVertex(-w, -h, +d, 1, 0, 0, -1, 0));
    
    	//Left
    	v.push_back(MeshVertex(-w, -h, +d, 0, 1, -1, 0, 0));
    	v.push_back(MeshVertex(-w, +h, +d, 0, 0, -1, 0, 0));
    	v.push_back(MeshVertex(-w, +h, -d, 1, 0, -1, 0, 0));
    	v.push_back(MeshVertex(-w, -h, -d, 1, 1, -1, 0, 0));
    
    	//Right
    	v.push_back(MeshVertex(+w, -h, -d, 0, 1, 1, 0, 0));
    	v.push_back(MeshVertex(+w, +h, -d, 0, 0, 1, 0, 0));
    	v.push_back(MeshVertex(+w, +h, +d, 1, 0, 1, 0, 0));
    	v.push_back(MeshVertex(+w, -h, +d, 1, 1, 1, 0, 0));
    
    
    	vertices = new MeshVertex[v.size()];
    	vertexCount = v.size();
    
    	copy(v.begin(), v.end(), stdext::checked_array_iterator<MeshVertex *>(vertices, vertexCount));
    
    
    	indexCount = 36;
    	this->indices = new UINT[indexCount]
    	{
    		0, 1, 2, 0, 2, 3,
    		4, 5, 6, 4, 6, 7,
    		8, 9, 10, 8, 10, 11,
    		12, 13, 14, 12, 14, 15,
    		16, 17, 18, 16, 18, 19,
    		20, 21, 22, 20, 22, 23
    	};
    }

     

     


     

    MeshGrid

     

    MeshGrid.h

    더보기
    #pragma once
    
    class MeshGrid : public Mesh
    {
    public:
    	//Texture UV에 대한 비율
    	MeshGrid(Shader* shader, float u = 1.0f, float v = 1.0f);
    	~MeshGrid();
    
    private:
    	void Create() override; //Mesh.h에 있는 Create() 재정의
    
    	float offsetU, offsetV; //보정값
    };

     

     

    MeshGrid.h

    더보기
    #include "Framework.h"
    #include "MeshGrid.h"
    
    MeshGrid::MeshGrid(Shader* shader, float u, float v)
    	: Mesh(shader), offsetU(offsetU), offsetV(offsetV)
    {
    }
    
    MeshGrid::~MeshGrid()
    {
    }
    
    void MeshGrid::Create()
    {
    	UINT countX = 11;
    	UINT countZ = 11;
    
    	float w = ((float)countX - 1) * 0.5f;
    	float h = ((float)countZ - 1) * 0.5f;
    
    	vector<MeshVertex> v;
    	for (UINT z = 0; z < countZ; z++)
    	{
    		for (UINT x = 0; x < countX; x++)
    		{
    			MeshVertex vertex;
    			vertex.Position = Vector3((float)x - w, 0, (float)z - h);
    			vertex.Normal = Vector3(0, 1, 0);
    			vertex.Uv.x = (float)x / (float)(countX - 1) * offsetU;
    			vertex.Uv.y = (float)z / (float)(countZ - 1) * offsetV;
    
    			v.push_back(vertex);
    		}
    	}
    
    	vertices = new MeshVertex[v.size()];
    	vertexCount = v.size();
    
    	copy(v.begin(), v.end(), stdext::checked_array_iterator <MeshVertex *>(vertices, vertexCount));
    
    	vector<UINT> i;
    	for (UINT z = 0; z < countZ - 1; z++)
    	{
    		for (UINT x = 0; x < countX - 1; x++)
    		{
    			i.push_back(countX * z + x);
    			i.push_back(countX * (z + 1) + x);
    			i.push_back(countX * z + x + 1);
    
    			i.push_back(countX * z + x + 1);
    			i.push_back(countX * (z + 1) + x);
    			i.push_back(countX * (z + 1) + x + 1);
    		}
    	}
    
    	indices = new UINT[i.size()];
    	indexCount = i.size();
    
    	copy(i.begin(), i.end(), stdext::checked_array_iterator <UINT *>(indices, vertexCount));
    }

     


     

    MeshDemo

     

    MeshDemo.h

    더보기
    #pragma once
    #include "Systems/IExecute.h"
    
    class MeshDemo : public IExecute
    {
    public:
    	virtual void Initialize() override;
    	virtual void Ready() override {}
    	virtual void Destroy() override;
    	virtual void Update() override;
    	virtual void PreRender() override {}
    	virtual void Render() override;
    	virtual void PostRender() override {}
    	virtual void ResizeScreen() override {}
    
    private:
    	Shader* shader;
    
    	Vector3 direction = Vector3(-1, -1, 1);
    	ID3DX11EffectVectorVariable* sDirection;
    
    	//MeshQuad* quad;
    	MeshCube* cube;
    	MeshGrid* grid;
    };

     

     

    MeshDemo.cpp

    더보기
    #include "stdafx.h"
    #include "MeshDemo.h"
    
    void MeshDemo::Initialize()
    {
    	Context::Get()->GetCamera()->RotationDegree(20, 0, 0);
    	Context::Get()->GetCamera()->Position(1, 36, -85);
    
    	shader = new Shader(L"25_Mesh.fx");
    	sDirection = shader->AsVector("Direction");
    	
    	//quad = new MeshQuad(shader);
    	//quad->Scale(2, 2, 2);
    	//quad->Position(0, 1, 0);
    	//quad->DiffuseMap(L"Box.png");
    
    	cube = new MeshCube(shader);
    	cube->Position(0, 5, 0);
    	cube->Scale(20, 10, 20);
    	cube->DiffuseMap(L"Stone.png");
    
    	grid = new MeshGrid(shader, 6, 6);
    	grid->Scale(12, 1, 12);
    	grid->DiffuseMap(L"Floor.png");
    }
    
    void MeshDemo::Destroy()
    {
    	SafeDelete(shader);
    	//SafeDelete(quad);
    	SafeDelete(cube);
    	SafeDelete(grid);
    }
    
    void MeshDemo::Update()
    {
    	//Vector3 scale;
    	//quad->Scale(&scale);
    
    	//ImGui::SliderFloat2("Scale", scale, -3, 3);
    	//quad->Scale(scale);
    
    	//quad->Update();
    
    	cube->Update();
    	grid->Update();
    }
    
    void MeshDemo::Render()
    {
    	sDirection->SetFloatVector(direction);
    
    	//quad->Render();
    	cube->Render();
    
    	static int pass = 1;
    	ImGui::InputInt("Pass", &pass);
    	pass %= 2;
    
    	grid->Pass(1);
    	grid->Render();
    }

     


     

    실행화면