   how to tell if a line passes though a square
  this is really more of a math question but i was wondering how to tell if a line passes though a OpenGL quad, the reason i'm asking is because in the game i'm making you shoot stuff. my idea was to (conceptually speaking) make a line from the player to arrow and the see if that line went though anything, if so do something because something was hit by a bullet.   
  Hey,yes this is more of a math question.Is it in 3D?I do it by making ray-plane intersection (google that). Find the plane equation that represents your triangle (in your case, square) and generate the vector for your "shooting" (in your case, the vector from the player to the end of your viewing frustum) (see gluUnProject for that). Find the intersection point between them.Having that point, check if it is inside the square boundaries. If so, you hit it.This is a good reference I found and bookmarked when I was first doing this: http://www.devmaster.net/forums/archive/index.php/t-371.html   ;  A line has a startPoint and an endPoint. Simply check if the endPoint(assumming the startPoint is where the shot took place) is inside the square. For example :class Line{ Vector3 startPos; Vector4 endPos;public: Line(const Vector3& begin, const Vector3& end) : startPos(begin), endPos(end){} //... more stuff};bool checkLineAndSquareIntersection(const Line& line, const Square& square){  Vector3 endPoint = line.getEndPoint();  //is it within the x axis of the square  if( endPoint.x() < square.topLeftPoint().x() ) return false;  if( endPoint.x() > square.topRightPoint().x() ) return false;  //is it within the y axis of the square  if(endPoint.y() > square.topLeftPoint().y() ) return false;  if(endPoint.y() < square.bottomLeftPoint().y() ) return false;  return true;}You can do even better, by just "fakely" extending the line, when shot, andsee if it collides with the square. Thus you wont have to check every frame.And know the answer before hand.   ;Quote:Original post by ConcentrateA line has a startPoint and an endPoint. Simply check if the endPoint(assumming the startPoint is where the shot took place) is inside the square. For example :class Line{ Vector3 startPos; Vector4 endPos;public: Line(const Vector3& begin, const Vector3& end) : startPos(begin), endPos(end){} //... more stuff};bool checkLineAndSquareIntersection(const Line& line, const Square& square){  Vector3 endPoint = line.getEndPoint();  //is it within the x axis of the square  if( endPoint.x() < square.topLeftPoint().x() ) return false;  if( endPoint.x() > square.topRightPoint().x() ) return false;  //is it within the y axis of the square  if(endPoint.y() > square.topLeftPoint().y() ) return false;  if(endPoint.y() < square.bottomLeftPoint().y() ) return false;  return true;}The OP didn't specify whether this is a 2-d or 3-d problem, but even if it is 2-d, your solution will only work for axis-aligned rectangles, and will miss cases where the segment intersects the rectangle but the segment endpoint does not fall inside the rectangle.   