-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSMath.cpp
More file actions
32 lines (26 loc) · 981 Bytes
/
Copy pathSMath.cpp
File metadata and controls
32 lines (26 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "PCH.h"
#include "SMath.h"
namespace sh::game
{
SH_GAME_API auto SMath::GetPlaneCollisionPoint(const glm::vec3& linePoint, const glm::vec3& lineDir, const glm::vec3& planePoint, const glm::vec3& planeNormal) -> std::optional<glm::vec3>
{
// 직선의 방정식 L = p + t x d
// 평면의 방정식 (x - p0) x n = 0
// 평면의 방정식에 직선의 방정식을 대입해 t를 구하는 코드.
float cos = glm::dot(planeNormal, lineDir);
if (glm::abs(cos) < 0.000001f)
{
if (glm::dot(planeNormal, linePoint - planePoint) == 0.0f)
{
return {}; // 선이 평면 위에 있음
}
else {
return {}; // 교차점 없음
}
}
float t = glm::dot(planeNormal, planePoint - linePoint) / cos;
// 교차점 계산
glm::vec3 intersection = linePoint + t * lineDir;
return intersection;
}
}