Skip to content

Commit

Permalink
메쉬, 트랜스폼 등등.. 만들기
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnjiwoo committed Sep 22, 2024
1 parent f063ebd commit 2d09435
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 0 deletions.
Binary file added Binaries/Debug/LightPixelShader.cso
Binary file not shown.
Binary file added Binaries/Debug/LightVertexShader.cso
Binary file not shown.
Binary file added Binaries/Debug/MyD3DFramework.exe
Binary file not shown.
Binary file added Binaries/Debug/SimplePixelShader.cso
Binary file not shown.
Binary file added Binaries/Debug/SimpleVertexShader.cso
Binary file not shown.
Binary file added Binaries/Debug/xaudio2_9redist.dll
Binary file not shown.
3 changes: 3 additions & 0 deletions MyD3DFramework/Mesh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "pch.h"
#include "Mesh.h"

43 changes: 43 additions & 0 deletions MyD3DFramework/Mesh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

class Mesh
{
public:
template<typename VertexType>
inline void SetVertexBuffer(ID3D11Device* inDivice, const std::vector<VertexType>& inVertices);

inline void SetIndexBuffer(ID3D11Device* inDivice, const std::vector<UINT>& inIndices);

private:
ComPtr<ID3D11Buffer> m_indexBuffer = nullptr;
ComPtr<ID3D11Buffer> m_vertexBuffer = nullptr;
};

template<typename VertexType>
inline void Mesh::SetVertexBuffer(ID3D11Device* inDivice, const std::vector<VertexType>& inVertices)
{
D3D11_BUFFER_DESC desc = {};
ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC));
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
desc.ByteWidth = inVertices.size() * sizeof(VertexType);
desc.Usage = D3D11_USAGE_DEFAULT;

D3D11_SUBRESOURCE_DATA subData = {};
subData.pSysMem = inVertices.data();

CHECK_FAILED(inDivice->CreateBuffer(&desc, &subData, m_vertexBuffer.GetAddressOf()));
}

inline void Mesh::SetIndexBuffer(ID3D11Device* inDivice, const std::vector<UINT>& inIndices)
{
D3D11_BUFFER_DESC desc = {};
ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC));
desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
desc.ByteWidth = inIndices.size() * sizeof(UINT);
desc.Usage = D3D11_USAGE_DEFAULT;

D3D11_SUBRESOURCE_DATA subData = {};
subData.pSysMem = inIndices.data();

CHECK_FAILED(inDivice->CreateBuffer(&desc, &subData, m_vertexBuffer.GetAddressOf()));
}
2 changes: 2 additions & 0 deletions MyD3DFramework/RenderableObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "pch.h"
#include "RenderableObject.h"
14 changes: 14 additions & 0 deletions MyD3DFramework/RenderableObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

class RenderableObject
{
public:
RenderableObject() = default;
virtual ~RenderableObject() = default;

private:
Mesh m_mesh = {};

Transform m_transform = {};
};

3 changes: 3 additions & 0 deletions MyD3DFramework/Transform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "pch.h"
#include "Transform.h"

73 changes: 73 additions & 0 deletions MyD3DFramework/Transform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma once

class Transform final
{
public:
Transform() = default;
~Transform() = default;

inline void SetPosition(const Vector3& inVector);
inline void SetRotateDegree(float inYaw, float inPitch, float inRoll);
inline void SetRotate(float inYaw, float inPitch, float inRoll);
inline void SetScale(const Vector3& inScale);

inline void AddPosition(const Vector3& inVector);
inline void AddRotateDegree(float inYaw, float inPitch, float inRoll);
inline void AddRotate(float inYaw, float inPitch, float inRoll);
inline void AddScale(const Vector3& inScale);

inline Vector3 GetPosition() const { return m_translate; }
inline Quaternion GetRotate() const { return m_rotate; }
inline Vector3 GetScale() const { return m_scaling; }

private:
Vector3 m_translate = Vector3::Zero;
Quaternion m_rotate = Quaternion::Identity;
Vector3 m_scaling = Vector3::One;
};

inline void Transform::SetPosition(const Vector3& inVector)
{
m_translate = inVector;
}

inline void Transform::SetRotateDegree(float inYaw, float inPitch, float inRoll)
{
inYaw = ::XMConvertToRadians(inYaw);
inPitch = ::XMConvertToRadians(inPitch);
inRoll = ::XMConvertToRadians(inRoll);
m_rotate = Quaternion::CreateFromYawPitchRoll(inYaw, inPitch, inRoll);
}

inline void Transform::SetRotate(float inYaw, float inPitch, float inRoll)
{
m_rotate = Quaternion::CreateFromYawPitchRoll(inYaw, inPitch, inRoll);
}

inline void Transform::SetScale(const Vector3& inScale)
{
m_scaling = inScale;
}

inline void Transform::AddPosition(const Vector3& inVector)
{
m_translate += inVector;
}

inline void Transform::AddRotateDegree(float inYaw, float inPitch, float inRoll)
{
inYaw = ::XMConvertToRadians(inYaw);
inPitch = ::XMConvertToRadians(inPitch);
inRoll = ::XMConvertToRadians(inRoll);
m_rotate *= Quaternion::CreateFromYawPitchRoll(inYaw, inPitch, inRoll);
}

inline void Transform::AddRotate(float inYaw, float inPitch, float inRoll)
{
m_rotate *= Quaternion::CreateFromYawPitchRoll(inYaw, inPitch, inRoll);
}

inline void Transform::AddScale(const Vector3& inScale)
{
m_scaling += inScale;
}
Binary file added MyD3DFramework/x64/Debug/Mesh.obj
Binary file not shown.
Binary file added MyD3DFramework/x64/Debug/RenderableObject.obj
Binary file not shown.
Binary file added MyD3DFramework/x64/Debug/Transform.obj
Binary file not shown.

0 comments on commit 2d09435

Please sign in to comment.