Package snap.gfx3d
Class HitDetector
java.lang.Object
snap.gfx3d.HitDetector
Hit detection between Ray and Shape/VertexArray/Triangle.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the last hit barycentric point.Returns the last hit point.Returns the last hit shape.Returns the Texture coord of hit point.Returns the last hit triangle VertexArray.int[]
Returns the array of index for hit triangle in triangle VertexArray.int
Returns the vertex index of the vertex closest to hit point.boolean
Returns whether this hit detector finds only first hit.boolean
isRayHitShape
(Point3D rayOrigin, Vector3D rayDir, Shape3D aShape) Returns whether ray hits shape.boolean
isRayHitTriangle
(Point3D rayOrigin, Vector3D rayDir, boolean doubleSided) Returns whether ray hits triangle defined by TriangleArray vertex points.boolean
isRayHitTriangleArray
(Point3D rayOrigin, Vector3D rayDir, VertexArray triangleArray) Returns whether ray hits VertexArray.boolean
isRayHitTriangleArrayNoIndex
(Point3D rayOrigin, Vector3D rayDir, VertexArray triangleArray) Returns whether ray hits VertexArray.void
reset()
Resets the hit detect for reuse.void
setFindFirstHit
(boolean aValue) Sets whether this hit detector finds only first hit.
-
Constructor Details
-
HitDetector
public HitDetector()Constructor.
-
-
Method Details
-
isFindFirstHit
public boolean isFindFirstHit()Returns whether this hit detector finds only first hit. -
setFindFirstHit
public void setFindFirstHit(boolean aValue) Sets whether this hit detector finds only first hit. -
getHitShape
Returns the last hit shape. -
getHitTriangleArray
Returns the last hit triangle VertexArray. -
getHitTriangleIndexArray
public int[] getHitTriangleIndexArray()Returns the array of index for hit triangle in triangle VertexArray. -
getHitPoint
Returns the last hit point. -
getHitBarycentricPoint
Returns the last hit barycentric point. -
getHitTexCoord
Returns the Texture coord of hit point. -
getHitVertexIndex
public int getHitVertexIndex()Returns the vertex index of the vertex closest to hit point. -
isRayHitShape
Returns whether ray hits shape. -
isRayHitTriangleArray
Returns whether ray hits VertexArray. -
isRayHitTriangleArrayNoIndex
public boolean isRayHitTriangleArrayNoIndex(Point3D rayOrigin, Vector3D rayDir, VertexArray triangleArray) Returns whether ray hits VertexArray. -
isRayHitTriangle
Returns whether ray hits triangle defined by TriangleArray vertex points. Uses Moller–Trumbore from wiki: https://en.wikipedia.org/wiki/Möller–Trumbore_intersection_algorithm Also described at scratchapixel: https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/ ./moller-trumbore-ray-triangle-intersection -
reset
public void reset()Resets the hit detect for reuse.
-