Package snap.gfx3d

Class HitDetector

java.lang.Object
snap.gfx3d.HitDetector

public class HitDetector extends Object
Hit detection between Ray and Shape/VertexArray/Triangle.
  • 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

      public Shape3D getHitShape()
      Returns the last hit shape.
    • getHitTriangleArray

      public VertexArray getHitTriangleArray()
      Returns the last hit triangle VertexArray.
    • getHitTriangleIndexArray

      public int[] getHitTriangleIndexArray()
      Returns the array of index for hit triangle in triangle VertexArray.
    • getHitPoint

      public Point3D getHitPoint()
      Returns the last hit point.
    • getHitBarycentricPoint

      public Point3D getHitBarycentricPoint()
      Returns the last hit barycentric point.
    • getHitTexCoord

      public 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

      public boolean isRayHitShape(Point3D rayOrigin, Vector3D rayDir, Shape3D aShape)
      Returns whether ray hits shape.
    • isRayHitTriangleArray

      public boolean isRayHitTriangleArray(Point3D rayOrigin, Vector3D rayDir, VertexArray triangleArray)
      Returns whether ray hits VertexArray.
    • isRayHitTriangleArrayNoIndex

      public boolean isRayHitTriangleArrayNoIndex(Point3D rayOrigin, Vector3D rayDir, VertexArray triangleArray)
      Returns whether ray hits VertexArray.
    • isRayHitTriangle

      public boolean isRayHitTriangle(Point3D rayOrigin, Vector3D rayDir, boolean doubleSided)
      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.