forked from Shell4026/ShellEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSMath.cpp
More file actions
28 lines (23 loc) · 797 Bytes
/
Copy pathSMath.cpp
File metadata and controls
28 lines (23 loc) · 797 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
#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>
{
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;
}
}