The CLIP_Line_Intersect_Plane function in the above code will tell you where a line intersects a plane in global space. A cube has six planes. You'll get a point for each one that tells where the line passed through that plane.
Since planes are infinite, some of these points may not lie on the surface of the cube.
You can figure out which points are on the surface of the cube by using CLIP_Point_Inside_Plane.
If you set up all your planes so the normals point outwards from the middle of the cube, then for each side calculate the intersection point. For each of the four adjacent sides, but not the side on the other side of the cube, check to see if that point is on their inside side. You're basically seeing if the point is inside a four sided infinitely long cylinder. If it is, then it's on the surface of that cube on that side. Otherwise it's off the surface of the cube.
Do this for all six sides/intersection points. For each point, store the U cordinate returned that tells you where the point is along the line. Once you know all the points which are on the surface of the cube, pick the one with the lowest U coordinate, the one which is closest to the start point of your ray, and that is your first intersection point. I think you should only have two points that are on the surface of the cube, so the other one is your exit point, if that's of any use to you. You can use the distance between them to calculate how much of the cube you passed through too, which would be useful for transparency effects.
Didn't you make a stencil shadow system? I'd think you'd have to know this stuff to do that.
Since planes are infinite, some of these points may not lie on the surface of the cube.
You can figure out which points are on the surface of the cube by using CLIP_Point_Inside_Plane.
If you set up all your planes so the normals point outwards from the middle of the cube, then for each side calculate the intersection point. For each of the four adjacent sides, but not the side on the other side of the cube, check to see if that point is on their inside side. You're basically seeing if the point is inside a four sided infinitely long cylinder. If it is, then it's on the surface of that cube on that side. Otherwise it's off the surface of the cube.
Do this for all six sides/intersection points. For each point, store the U cordinate returned that tells you where the point is along the line. Once you know all the points which are on the surface of the cube, pick the one with the lowest U coordinate, the one which is closest to the start point of your ray, and that is your first intersection point. I think you should only have two points that are on the surface of the cube, so the other one is your exit point, if that's of any use to you. You can use the distance between them to calculate how much of the cube you passed through too, which would be useful for transparency effects.
Didn't you make a stencil shadow system? I'd think you'd have to know this stuff to do that.