Directx::XMFLOAT3 이런 녀석들은 뭐 계산좀 하려고 하면 일일이 XMVECTOR로 변환해서 사용해야해서 짜증나서 그냥 내가 Vector 클래스를 만들기로 했다.
뭐.. 그냥 손 많이 가는 노가다니까 따로 설명은 하지 않는다. 헤더파일의 모습은 이렇게 되어있다.
#pragma once
class Vector
{
public:
Vector(float x = 0) :
x(x) {}
Vector(const class Vector2& v);
Vector(const class Vector3& v);
//Vector& operator=(const Vector& v);
Vector& operator+(const Vector& v);
Vector& operator-(const Vector& v);
Vector& operator*(float s);
Vector& operator*=(float s);
public:
float x;
public:
READONLY_PROPERTY(float, size);
GET(size) { return x; }
};
class Vector2
{
public:
Vector2(float x = 0, float y = 0) :
x(x), y(y) {}
Vector2(const Vector& v, float y = 0) :
Vector2(v.x, y) {}
Vector2(const class Vector3& v);
//Vector2& operator=(const Vector2& v);
Vector2& operator+(const Vector2& v);
Vector2& operator-(const Vector2& v);
Vector2& operator*(float s);
Vector2& operator*=(float s);
public:
float x, y;
public:
READONLY_PROPERTY(float, size);
GET(size) { return sqrt(x * x + y * y); }
};
class Vector3
{
public:
public:
static const Vector3 Forward;
static const Vector3 Back;
static const Vector3 Up;
static const Vector3 Down;
static const Vector3 Left;
static const Vector3 Right;
public:
Vector3(float x = 0, float y = 0, float z = 0) :
x(x), y(y), z(z) {}
Vector3(const Vector2& v, float z =0) :
Vector3(v.x, v.y, z) {}
//Vector3& operator=(const Vector3& v);
Vector3 operator+(const Vector3& v);
Vector3 operator-(const Vector3& v);
Vector3 operator*(float scala);
Vector3& operator*=(float scala);
Vector3 operator/(float s);
Vector3& operator/=(float s);
Vector3& Normalize();
public:
float x, y, z;
public:
READONLY_PROPERTY(float, size);
GET(size) { return sqrt(x * x + y * y + z * z); }
};
class Vector4
{
public:
Vector4(float x = 0, float y = 0, float z = 0, float w = 0) :
x(x), y(y), z(z), w(w) {}
Vector4(const Vector3& v, float w =0) :
Vector4(v.x, v.y, v.z, w)
{}
//Vector4& operator=(const Vector4& v);
Vector4 operator+(const Vector4& v);
Vector4 operator-(const Vector4& v);
Vector4 operator*(float s);
Vector4& operator*=(float s);
public:
float x, y, z, w;
};
using Quaternion = Vector4;
Vector3& operator*(float s, Vector3& v);
Vector1 부터 Vector4까지 모조리 정의해주었다. 처음에는 상속으로 할까 하다가 디버깅시 현재 클래스의 멤버만 보이길래 그냥 독립 클래스로 만들어 버렸다.
그리고 이제 내가 만든 이러한 커스텀 구조체, 클래스를 한 곳에 모아서 해당 헤더를 포함시키면 모두 쓸 수 있도록 만들고자 했다. Structs.h 헤더 파일을 제작했는데 이런 모습이다.
#include "Color.h"
#include "Vector.h"
//dx11 호환
namespace dx = DirectX;
dx::XMFLOAT3& To_XMFLOAT3(Vector3& v);
dx::XMFLOAT4& To_XMFLOAT4(Vector4& v);
dx::XMVECTOR To_XMVECTOR(const Vector3& v);
dx::XMVECTOR To_XMVECTOR(const Vector4& v);
Vector3 To_Vector3(dx::XMVECTOR& v);
Vector3 To_Vector3(dx::XMVECTOR v);
Vector4 To_Vector4(dx::XMVECTOR& v);
Vector3 To_Vector3(dx::XMVECTOR v);
#include "Material.h"
#include "Ray.h"
Directx와 호환되도록 하기 위해서 변환 함수를 전역으로 만들어 주었다. 어차피 강제 형 변환을 통해 서로 변환이 가능하다.
결과 : 여러 텍스쳐를 불러오는 데에는 성공했으나 결과가 이상하게 나옴.
20200219 : 해결했다. 이유는 UV가 Directx와 반대로 되어있어서 그랬다. FlipUV를 해주었더니 잘 동작하더라. 눈 부분이 하얀 이유는 앞에 표정 표현을 위한 mesh가 눈을 가리고 있어서 그렇다.
'진행과정 기록 > GameEngine' 카테고리의 다른 글
20200219 (0) | 2020.02.19 |
---|---|
20200211 Node Tree (0) | 2020.02.11 |
규칙 (0) | 2020.02.09 |
20200207 Picking (0) | 2020.02.07 |
20200206 어떻게 다른 타입의 클래스포인터를 한곳에 저장하고, 또 꺼낼 수 있을까? (0) | 2020.02.06 |