c++ - How to check if a point is inside a quad in perspective projection? -


i want test if given point in world on quad/plane? quad/plane can translated/rotated/scaled values still should able detect if given point on it. need location point should have been, if quad not applied rotation/scale/translation.

for example, consider quad @ 0, 0, 0 size 100x100, rotated @ angle of 45 degrees along z axis. if mouse location in world @ ( x, y, 0, ), need know if point falls on quad in current transformation? if yes, need know if no transformations applied quad, point have been on it? code sample of great help

a ray-casting approach simplest:

  1. use gluunproject() world-space direction of ray cast scene. ray's origin camera position.
  2. put ray object space transforming inverse of rectangle's transform. note need transform both ray's origin point , direction vector.
  3. compute intersection point between ray , xy plane standard ray-plane intersection test.
  4. check intersection point's x , y values within rectangle's bounds, if that's desired result.

a math library such glm helpful if aren't confident of math involved here, has corresponding functions such glm::unproject() functions invert matrices , other transformations you'd need.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -