Пример #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;
}
Пример #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;
}
Пример #3
0
void VRScript::update() {
    if (type == "HTML") {
        VRMobile* mob = (VRMobile*)VRSetupManager::getCurrent()->getDevice(mobile);
        if (mob) mob->addWebSite(getName(), core);
    }

    VRScene* scene = VRSceneManager::getCurrent();

    for (t_itr = trigs.begin(); t_itr != trigs.end(); t_itr++) {
        trig* t = t_itr->second;
        if (t->trigger == "on_timeout") {
            int i = toInt(t->param.c_str());
            scene->addTimeoutFkt(cbfkt_sys, 0, i);
            continue;
        }

        if (t->trigger == "on_device") {
            VRDevice* dev = VRSetupManager::getCurrent()->getDevice(t->dev);
            int state = -1;
            if (t->state == "Released") state = 0;
            if (t->state == "Pressed") state = 1;
            if (t->state == "Drag") state = 2;
            if (t->state == "Drop") state = 3;
            if (t->state == "To edge") state = 4;
            if (t->state == "From edge") state = 5;
            if (state == -1) continue;

            if (dev != 0) {
                if (state <= 1) t->sig = dev->addSignal(t->key, state);
                if (state == 2) t->sig = dev->getDragSignal();
                if (state == 3) t->sig = dev->getDropSignal();
                if (state == 4) t->sig = dev->getToEdgeSignal();
                if (state == 5) t->sig = dev->getFromEdgeSignal();
                if (t->sig == 0) continue;
                t->sig->add(cbfkt_dev);
            }

            // add dev argument
            if (args.count("dev") == 0) args["dev"] = new arg(VRName::getName(), "dev");
            arg* a = args["dev"];
            a->type = "VRPyDeviceType";
            a->val = "";
            a->trig = true;
            t->a = a;
            continue;
        }

        if (t->trigger == "on_socket") {
            t->soc = scene->getSocket(t->dev);
            if (t->soc == 0) continue;
            t->soc->setTCPCallback(cbfkt_soc);

            // add msg argument
            arg* a = new arg(VRName::getName(), "msg");
            args[a->getName()] = a;
            a->type = "str";
            a->val = "";
            t->a = a;
            a->trig = true;
            continue;
        }
    }

    // update args namespaces && map
    map<string, arg*> tmp_args;
    for (auto _a : args) {
        arg* a = _a.second;
        a->setNameSpace(VRName::getName());
        tmp_args[a->getName()] = a;
        changeArgValue(a->getName(), a->val);
    }
    args = tmp_args;

    // update head
    head = "";
    if (type == "Python") {
        head = "def " + name + "(";
        int i=0;
        for (a_itr = args.begin(); a_itr != args.end(); a_itr++, i++) {
            if (i != 0) head += ", ";
            head += a_itr->second->getName();
        }
        head += "):\n";
    }
}