파일 위치: Engine/99.Headers/Math/Primitive3D.h
#pragma once
도형은 하나의 클래스로 모으기보다 각 도형별로 구조체로 분리하여 선언됩니다.
using Point3D = Vec3;
Vec3(float x, y, z) 벡터로 3D 좌표 표현Point3D들을 조합해서 만들어짐struct Line3D {
Point3D start;
Point3D end;
float Length() { return Vec3::Distance(start, end); }
float LengthSq() { return Vec3::DistanceSquared(start, end); }
};
Length(): 거리 계산LengthSq(): 제곱 거리 (루트 연산 생략, 빠름)struct Ray3D {
Point3D origin;
Vec3 direction;
void NormalizeDirection() { direction.Normalize(); }
static Ray3D FromPoints(const Point3D& from, const Point3D& to) {
return Ray3D{ from, to - from };
}
};
NormalizeDirection()으로 방향을 정규화해서 사용FromPoints()로 두 점으로부터 생성 가능struct Sphere3D {
Point3D position;
float radius;
};
struct AABB3D {
Point3D position;
Vec3 size;
static Vec3 GetMin(const AABB3D& aabb);
static Vec3 GetMax(const AABB3D& aabb);
static AABB3D FromMinMax(const Vec3& min, const Vec3& max);
};
GetMin(), GetMax(): 좌표 최솟값과 최댓값 계산FromMinMax(): 두 점(min/max)으로 AABB 생성struct OBB3D {
Point3D position;
Vec3 size;
Matrix orientation;
};
AABB와 구조는 같지만, 회전(orientation) 이 포함됨Matrix를 사용하여 회전 정보 저장struct Plane3D {
Vec3 normal;
float distance;
};
struct Triangle3D {
union {
struct {
Point3D a;
Point3D b;
Point3D c;
};
Point3D points[3];
float values[9];
};
};
union으로 다양한 접근 방식 지원a, b, c: 이름 기반 접근points[]: 배열 접근values[]: 메모리 순차 접근삼각형은 메시(mesh)의 최소 단위이며, 모든 복잡한 형상도 삼각형으로 쪼개져 표현됩니다.
struct Interval3D {
float min;
float max;
};
| 도형 | 활용 예시 |
|---|---|
Point3D | 좌표 표현, 삼각형의 꼭짓점 |
Line3D | 거리 측정, 디버그 선 |
Ray3D | Picking, 충돌, 광선 추적 |
Sphere3D | 단순 충돌 감지, 거리 기반 탐지 |
AABB3D | 빠른 박스 충돌 테스트, 공간 분할 |
OBB3D | 회전 가능한 정확한 충돌 |
Plane3D | 반사, 거리 판정, 절단 |
Triangle3D | 메시 기반 연산, 렌더링, 지형 처리 |
Interval3D | 투영 기반 충돌 연산 |