hi everyone!

I'm looking for a ray -> box intersection function for my raytracer. if anyone knows one or has one, please let me know.

here is the one i have yet (ported from other code). the problem is, that no picked coordinates and normals are returned.

variables:

XYZ - Cube positions

Width, Height, Depth - Cube size

thanx in advanceCode:public bool Pick(double ray_x, double ray_y, double ray_z, double ray_nx, double ray_ny, double ray_nz) { double bminx = X - Width / 2; double bminy = Y - Height / 2; double bminz = Z - Depth / 2; double bmaxx = X + Width / 2; double bmaxy = Y + Height / 2; double bmaxz = Z + Depth / 2; double txmin = 0, txmax = 0, tymin = 0, tymax = 0, tzmin = 0, tzmax = 0; if (ray_nx > 0) { txmin = (bminx - ray_x) / ray_nx; txmax = (bmaxx - ray_x) / ray_nx; } else { txmin = (bmaxx - ray_x) / ray_nx; txmax = (bminx - ray_x) / ray_nx; } if (ray_ny > 0) { tymin = (bminy - ray_y) / ray_ny; tymax = (bmaxy - ray_y) / ray_ny; } else { tymin = (bmaxy - ray_y) / ray_ny; tymax = (bminy - ray_y) / ray_ny; } if (txmin > tymax || tymin > txmax) return false; if (tymin > txmin) txmin = tymin; if (tymax < txmax) txmax = tymax; if (ray_nz > 0) { tzmin = (bminz - ray_z) / ray_nz; tzmax = (bmaxz - ray_z) / ray_nz; } else { tzmin = (bmaxz - ray_z) / ray_nz; tzmax = (bminz - ray_z) / ray_nz; } if (txmin > tzmax || tzmin > txmax) return false; return true; }