Plane
平面との交差を考えていく.
今回やるのは無限平面で、範囲制限はない.
まず最初に平面を点a
と法線n
とする.
また、Rayの交差する点をr
とすると、法線と平面と平行なベクトルr
−a
は垂直なので0になるはず.
(r
−a
)⋅n
=0
さて、光線はr
=o
+td
だった.
なのでこれを入れると、
(r
−a
)⋅n
=0(o
+td
−a
)⋅n
=0(td
)⋅n
=(a
−o
)⋅n
t=d
⋅n
(a
−o
)⋅n
あとはこれを式に落とし込めばOK.
hlslで実装したものが以下である.
bool IntersectToPlane(float3 center, float3 normal, out float thit)
{
float t = dot((center - ObjectRayOrigin()), normal) / dot(ObjectRayDirection(), normal);
if (t > EPSILON)
{
thit = t;
return true;
}
return false;
}
結果は以下のような感じ.
動画のしか残ってなかったので、文字があるけど許してね.