Exemple #1
0
//VRIntersection VRIntersect::intersect(VRTransform* caster, VRObject* tree, VRDevice* dev) {
VRIntersection VRIntersect::intersect(VRObject* tree) {
    VRDevice* dev = (VRDevice*)this;
    VRTransform* caster = dev->getBeacon();
    Line ray = caster->castRay();
    IntersectActionRefPtr iAct = IntersectAction::create();
    iAct->setLine(ray);

    if (tree == 0) tree = dynTree;
    if (tree == 0) return VRIntersection();

    VRIntersection ins = intersections[tree];
    uint now = VRGlobals::get()->CURRENT_FRAME;
    if (ins.hit && ins.time == now) return ins; // allready found it
    ins.time = now;

    iAct->apply(tree->getNode());
    ins.hit = iAct->didHit();
    if (!ins.hit) { intersections[tree] = ins; lastIntersection = ins; return ins; }

    ins.object = tree->find(iAct->getHitObject()->getParent());
    ins.point = iAct->getHitPoint();
    ins.normal = iAct->getHitNormal();
    ins.triangle = iAct->getHitTriangle();
    ins.texel = VRIntersect_computeTexel(ins, iAct->getHitObject());
    intersections[tree] = ins;
    lastIntersection = ins;

    if (showHit) cross->setWorldPosition(Vec3f(ins.point));
    //cout << "VRIntersect::intersect " << obj << endl;

    return ins;
}
Exemple #2
0
VRIntersection VRIntersect::intersect(VRObject* tree) {
    VRDevice* dev = (VRDevice*)this;
    VRTransform* caster = dev->getBeacon();
    VRIntersection ins;
    if (caster == 0) { cout << "Warning: VRIntersect::intersect, caster is 0!\n"; return ins; }
    if (tree == 0) tree = dynTree;
    if (tree == 0) return ins;

    if (intersections.count(tree)) ins = intersections[tree];
    uint now = VRGlobals::get()->CURRENT_FRAME;
    if (ins.hit && ins.time == now) return ins; // allready found it
    ins.time = now;

    Line ray = caster->castRay(tree);
    VRIntersectAction iAct;
    //IntersectActionRefPtr iAct = IntersectAction::create();
    iAct.setTravMask(8);
    iAct.setLine(ray);
    iAct.apply(tree->getNode());

    ins.hit = iAct.didHit();
    if (ins.hit) {
        ins.object = tree->find(iAct.getHitObject()->getParent());
        ins.point = iAct.getHitPoint();
        ins.normal = iAct.getHitNormal();
        if (tree->getParent()) tree->getParent()->getNode()->getToWorld().mult( ins.point, ins.point );
        if (tree->getParent()) tree->getParent()->getNode()->getToWorld().mult( ins.normal, ins.normal );
        ins.triangle = iAct.getHitTriangle();
        ins.texel = VRIntersect_computeTexel(ins, iAct.getHitObject());
        lastIntersection = ins;
    } else {
        ins.object = 0;
        if (lastIntersection.time < ins.time) lastIntersection = ins;
    }

    intersections[tree] = ins;

    if (showHit) cross->setWorldPosition(Vec3f(ins.point));
    return ins;
}