Example #1
0
    RealTime ModelContainer::getIntersectionTime(const Ray& pRay, bool pExitAtFirst, float pMaxDist) const
    {
        #ifdef _DEBUG_VMAPS
        for(unsigned int i=0; i<getNSubModel(); i++)
        {
            SubModel model = getSubModel(i);
            bool insiteOk;
            Vector3 mynormal;
            Vector3 location;
            bool hitval = MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
                pRay.origin, pRay.direction,
                model.getAABoxBounds(),
                location,insiteOk, mynormal);
            if(hitval)
            {
                float len2 = (location - pRay.origin).squaredLength();
                int a = 0;                                  // just to be able to set a breakpoint
            }
        }
        TreeNode tn = getTreeNode(0);
        for(int i=0; i<tn.getNValues(); i++)
        {
            SubModel mysm = getSubModel(tn.getStartPosition() + i);
            AABox testbox = mysm.getAABoxBounds();
            gBoxArray.append(AABox(testbox.low(), testbox.high()));
        }
        #endif

        double  firstDistance = inf();
        Ray relativeRay = Ray::fromOriginAndDirection(pRay.origin - getBasePosition(), pRay.direction);
        const IT end = endRayIntersection();
        IT obj = beginRayIntersection(pRay, pMaxDist);
        for ( ;obj != end; ++obj)                           // (preincrement is *much* faster than postincrement!)
        {
            /*
            Call your accurate intersection test here.  It is guaranteed
            that the ray hits the bounding box of obj.  (*obj) has type T,
            so you can call methods directly using the "->" operator.
            */
            SubModel const *model =  &(*obj);

            RealTime t = model->getIntersectionTime(pRay, pExitAtFirst, pMaxDist);
            if(t > 0 && t < inf())
            {
                obj.markBreakNode();
                if(firstDistance > t && pMaxDist >= t)
                {
                    firstDistance = t;
                    if(pExitAtFirst) { break; }
                }
            }
        }
        return(firstDistance);
    }
Example #2
0
    float MapTree::getIntersectionTime(const Ray& pRay, float pMaxDist, bool pStopAtFirstHit)
    {
        double  firstDistance = inf();

        const IT end = iTree->endRayIntersection();
        IT obj = iTree->beginRayIntersection(pRay, pMaxDist);

        for ( ;obj != end; ++obj)                           // (preincrement is *much* faster than postincrement!)
        {
            /*
            Call your accurate intersection test here.  It is guaranteed
            that the ray hits the bounding box of obj.  (*obj) has type T,
            so you can call methods directly using the "->" operator.
            */
            ModelContainer *model = (ModelContainer *) (*obj);

            float t = model->getIntersectionTime(pRay, pStopAtFirstHit, pMaxDist);

            // just for visual debugging with an external debug class
            #ifdef _DEBUG_VMAPS
            if(gCount3 == gCount1)
            {
                AABox testBox;
                testBox = model->getAABoxBounds();
                gBoxArray.append(testBox);
            }
            ++gCount3;
            #endif
            if(t > 0 && t < inf())
            {
                obj.markBreakNode();
                if(firstDistance > t && pMaxDist >= t)
                {
                    firstDistance = t;
                    if(pStopAtFirstHit) break;
                }
            }
        }
        return firstDistance;
    }
Example #3
0
    RealTime SubModel::getIntersectionTime(const Ray& pRay, bool pExitAtFirst, float pMaxDist) const
    {
        TriangleBox const *firstObject;
        double  firstDistance = inf();

        #ifdef _DEBUG_VMAPS
        int debugCount =0;
        #endif
        Ray relativeRay = Ray::fromOriginAndDirection(pRay.origin - getBasePosition(), pRay.direction);

        const IT end = endRayIntersection();
        IT obj = beginRayIntersection(relativeRay,pMaxDist,false);

        Triangle testT;
        for ( ;obj != end; ++obj)                           // (preincrement is *much* faster than postincrement!)
        {
            /*
            Call your accurate intersection test here.  It is guaranteed
            that the ray hits the bounding box of obj.  (*obj) has type T,
            so you can call methods directly using the "->" operator.
            */
            const TriangleBox *tri = &(*obj);

            testT = Triangle(tri->vertex(0).getVector3(),tri->vertex(1).getVector3(),tri->vertex(2).getVector3());
            double t = testIntersectionWithTriangle(obj,testT, relativeRay);
            #ifdef _DEBUG_VMAPS
            if(debugCount == 5)
            {
                firstObject = tri;
                firstDistance = 1;
            }
            ++debugCount;
            #endif
            if(t != inf())
            {
                /*
                Tell the iterator that we've found at least one
                intersection.  It will finish looking at all
                objects in this node and then terminate.
                */
                obj.markBreakNode();
                if(firstDistance > t && pMaxDist >= t)
                {
                    firstDistance = t;
                    firstObject   = tri;
                    if(pExitAtFirst) break;
                }
            }
            else
            {
                // This might the wrong side of the triangle... Turn it and test again
                testT = Triangle(tri->vertex(2).getVector3(),tri->vertex(1).getVector3(),tri->vertex(0).getVector3());
                t = testIntersectionWithTriangle(obj, testT,relativeRay);
                if(t != inf())
                {
                    obj.markBreakNode();
                    if(firstDistance > t && pMaxDist >= t)
                    {
                        firstDistance = t;
                        firstObject   = tri;
                        if(pExitAtFirst) break;
                    }
                }
            }
        }
        #ifdef _DEBUG_VMAPS
        if(firstDistance < inf())
        {
            myfound = true;
            p1 = firstObject->vertex(0).getVector3()+ getBasePosition();
            p2 = firstObject->vertex(1).getVector3()+ getBasePosition();
            p3 = firstObject->vertex(2).getVector3()+ getBasePosition();
            p4 = relativeRay.origin + getBasePosition();
            p5 =  relativeRay.intersection(testT.plane()) + getBasePosition();
            float dist1 = (p5-p4).magnitude();
            double dist2 = relativeRay.intersectionTime(testT);
            float dist3 = relativeRay.direction.magnitude();
            double dist4 = relativeRay.intersectionTime(testT);
        }
        #endif

        return(firstDistance);
    }