示例#1
0
 Vec3f Grid::snapTowards(const Vec3f& p, const Vec3f& d, bool skip) const {
     if (!snap())
         return p;
     Vec3f result;
     if (Math<float>::pos(d.x()))        result[0] = snapUp(p.x(), skip);
     else if(Math<float>::neg(d.x()))    result[0] = snapDown(p.x(), skip);
     else                                result[0] = snap(p.x());
     if (Math<float>::pos(d.y()))        result[1] = snapUp(p.y(), skip);
     else if(Math<float>::neg(d.y()))    result[1] = snapDown(p.y(), skip);
     else                                result[1] = snap(p.y());
     if (Math<float>::pos(d.z()))        result[2] = snapUp(p.z(), skip);
     else if(Math<float>::neg(d.z()))    result[2] = snapDown(p.z(), skip);
     else                                result[2] = snap(p.z());
     return result;
 }
示例#2
0
 Vec3f Grid::snapTowards(const Vec3f& p, const Vec3f& d, bool skip) const {
     if (!snap())
         return p;
     Vec3f result;
     if (Math::pos(d.x))         result.x = snapUp(p.x, skip);
     else if(Math::neg(d.x))     result.x = snapDown(p.x, skip);
     else                        result.x = snap(p.x);
     if (Math::pos(d.y))         result.y = snapUp(p.y, skip);
     else if(Math::neg(d.y))     result.y = snapDown(p.y, skip);
     else                        result.y = snap(p.y);
     if (Math::pos(d.z))         result.z = snapUp(p.z, skip);
     else if(Math::neg(d.z))     result.z = snapDown(p.z, skip);
     else                        result.z = snap(p.z);
     return result;
 }
示例#3
0
 Vec3f Grid::snapDown(const Vec3f& p, bool skip) const {
     if (!snap())
         return p;
     return Vec3f(snapDown(p.x(), skip), snapDown(p.y(), skip), snapDown(p.z(), skip));
 }
示例#4
0
        float Grid::intersectWithRay(const Rayf& ray, unsigned int skip) const {
            Vec3f planeAnchor;
            
            for (size_t i = 0; i < 3; i++)
                planeAnchor[i] = ray.direction[i] > 0.0f ? snapUp(ray.origin[i], true) + skip * actualSize() : snapDown(ray.origin[i], true) - skip * actualSize();

            Planef plane(Vec3f::PosX, planeAnchor);
            float distX = plane.intersectWithRay(ray);
            
            plane = Planef(Vec3f::PosY, planeAnchor);
            float distY = plane.intersectWithRay(ray);
            
            plane = Planef(Vec3f::PosZ, planeAnchor);
            float distZ = plane.intersectWithRay(ray);
            
            float dist = distX;
            if (!Math<float>::isnan(distY) && (Math<float>::isnan(dist) || std::abs(distY) < std::abs(dist)))
                dist = distY;
            if (!Math<float>::isnan(distZ) && (Math<float>::isnan(dist) || std::abs(distZ) < std::abs(dist)))
                dist = distZ;
            
            return dist;
        }
示例#5
0
        float Grid::intersectWithRay(const Ray& ray, unsigned int skip) const {
            Vec3f planeAnchor;
            
            planeAnchor.x = ray.direction.x > 0 ? snapUp(ray.origin.x, true) + skip * actualSize() : snapDown(ray.origin.x, true) - skip * actualSize();
            planeAnchor.y = ray.direction.y > 0 ? snapUp(ray.origin.y, true) + skip * actualSize() : snapDown(ray.origin.y, true) - skip * actualSize();
            planeAnchor.z = ray.direction.z > 0 ? snapUp(ray.origin.z, true) + skip * actualSize() : snapDown(ray.origin.z, true) - skip * actualSize();

            Plane plane(Vec3f::PosX, planeAnchor);
            float distX = plane.intersectWithRay(ray);
            
            plane = Plane(Vec3f::PosY, planeAnchor);
            float distY = plane.intersectWithRay(ray);
            
            plane = Plane(Vec3f::PosZ, planeAnchor);
            float distZ = plane.intersectWithRay(ray);
            
            float dist = distX;
            if (!Math::isnan(distY) && (Math::isnan(dist) || std::abs(distY) < std::abs(dist)))
                dist = distY;
            if (!Math::isnan(distZ) && (Math::isnan(dist) || std::abs(distZ) < std::abs(dist)))
                dist = distZ;
            
            return dist;
        }