Esempio n. 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;
}
Esempio n. 2
0
/** Returns the world matrix **/
void VRTransform::getWorldMatrix(Matrix& _m, bool parentOnly) {
    //if (checkWorldChange()) {
    if (true) {
        vector<Matrix> tv;

        Matrix m;
        VRObject* obj = this;
        if (parentOnly and obj->getParent() != 0) obj = obj->getParent();

        VRTransform* tmp;
        while(true) {
            if (obj->hasAttachment("transform")) {
                tmp = (VRTransform*)obj;
                tmp->getMatrix(m);
                //cout << "\nPARENT: " << tmp->getName();
                //cout << "\n" << m;
                tv.push_back(m);
            }

            if (obj->getParent() == 0) break;
            else obj = obj->getParent();
        }

        WorldTransformation = computeMatrixVector(tv);
    }

    _m = WorldTransformation;
    //if (getName() == "Box") cout << WorldTransformation << endl;
    //cout << "\nGETWM: " << getName() << endl << _m << endl;
}
Esempio n. 3
0
void VRMesure::check() {//check spheres for change of position
    Vec3f p1, p2;

    VRCamera* cam = scene->getActiveCamera();
    VRTransform* user = VRSetupManager::getCurrent()->getUser();

    p1 = s1->getWorldPosition();
    p2 = s2->getWorldPosition();

    processBar(p1, p2);
    if (user == 0) processLabel(p1, p2, cam->getWorldPosition());
    else processLabel(p1, p2, user->getWorldPosition());
}
Esempio n. 4
0
void VRSnappingEngine::update() {
    for (auto dev : VRSetupManager::getCurrent()->getDevices()) { // get dragged objects
        VRTransform* obj = dev.second->getDraggedObject();
        VRTransform* gobj = dev.second->getDraggedGhost();
        if (obj == 0 || gobj == 0) continue;
        if (objects.count(obj) == 0) continue;

        Matrix m = gobj->getWorldMatrix();
        Vec3f p = Vec3f(m[3]);

        for (auto ri : rules) {
            Rule* r = ri.second;
            if (r->csys == obj) continue;

            if (anchors.count(obj)) {
                for (auto a : anchors[obj]) {
                    Matrix maL = a->getMatrix();
                    Matrix maW = m; maW.mult(maL);
                    Vec3f pa = Vec3f(maW[3]);
                    Vec3f paL = r->local( Vec3f(maW[3]) );
                    Vec3f psnap = r->getSnapPoint(pa);
                    float D = (psnap-paL).length(); // check distance
                    //cout << "dist " << D << " " << pa[1] << " " << paL[1] << " " << psnap[1] << endl;
                    if (!r->inRange(D)) continue;

                    r->snap(m);
                    maL.invert();
                    m.mult(maL);
                    event->set(obj, r->csys, m, dev.second);
                    snapSignal->trigger<EventSnap>(event);
                    break;
                }
            } else {
                Vec3f p2 = r->getSnapPoint(p);
                float D = (p2-p).length(); // check distance
                if (!r->inRange(D)) continue;
                r->snap(m);
                event->set(obj, r->csys, m, dev.second);
                snapSignal->trigger<EventSnap>(event);
            }
        }

        obj->setWorldMatrix(m);
    }

    // update geo
    if (!hintGeo->isVisible()) return;
}
Esempio n. 5
0
    void snap(Matrix& m) {
        if (csys) C = csys->getWorldMatrix();

        if (orientation == POINT) {
            MatrixLookAt(m, snapP, snapP+Vec3f(prim_o.getPosition()), prim_o.getDirection());
            m.multLeft(C);
        }
    }
Esempio n. 6
0
 Vec3f local(Vec3f p) {
     if (csys) {
         C = csys->getWorldMatrix();
         C.invert();
         Pnt3f pL;
         C.mult(p,pL);
         return Vec3f(pL);
     } else return p;
 }
Esempio n. 7
0
/** Print the positions of all the subtree **/
void VRTransform::printTransformationTree(int indent) {
    if(indent == 0) cout << "\nPrint Transformation Tree : ";

    cout << "\n";
    for (int i=0;i<indent;i++) cout << "  ";
    if (getType() == "Transform" or getType() == "Geometry") {
        VRTransform* _this = (VRTransform*) this;
        _this->printPos();
    }

    for (uint i=0;i<getChildrenCount();i++) {
        if (getChild(i)->getType() == "Transform" or getChild(i)->getType() == "Geometry") {
            VRTransform* tmp = (VRTransform*) getChild(i);
            tmp->printTransformationTree(indent+1);
        }
    }

    if(indent == 0) cout << "\n";
}
Esempio n. 8
0
bool FObject::move(FNode* n, float dx) {
    bool done = false;
    VRTransform* trans = getTransformation();
    if (trans == 0) return true;
    if (n->getTransform() == 0) return true;

    Vec3f p = trans->getFrom();
    Vec3f c = n->getTransform()->getFrom();


    Vec3f d = c-p;
    if (d.length() < dx) { p = c; done = true; }
    else { d.normalize(); p = p+d*dx; }

    //cout << "MOVE " << p << "   " << c << endl;
    trans->setFrom(p);
    //trans->setDir(Vec3f(1,0,0));

    return done;
}
Esempio n. 9
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;
}
Esempio n. 10
0
void VRSceneManager::newScene(string path) {
    removeScene(getCurrent());

    VRScene* scene = new VRScene();
    scene->setPath(path);
    setWorkdir(scene->getWorkdir());
    scene->setName(scene->getFileName());
    VRTransform* cam = scene->addCamera("Default");

    VRLight* headlight = scene->addLight("Headlight");
    headlight->setType("point");
    VRLightBeacon* headlight_B = new VRLightBeacon("Headlight_beacon");
    headlight->setBeacon(headlight_B);
    VRTransform* user = VRSetupManager::getCurrent()->getUser();
    scene->add(headlight);
    headlight->addChild(cam);
    if (user) user->addChild(headlight_B);
    else cam->addChild(headlight_B);

    cam->setFrom(Vec3f(0,0,3));
    addScene(scene);
}
Esempio n. 11
0
PyObject* VRScriptManager::loadGeometry(VRScriptManager* self, PyObject *args) {
    PyObject* path = 0;
    PyObject *preset = 0;
    int ignoreCache = 0;

    if (pySize(args) == 1) if (! PyArg_ParseTuple(args, "O", &path)) return NULL;
    if (pySize(args) == 2) if (! PyArg_ParseTuple(args, "Oi", &path, &ignoreCache)) return NULL;
    if (pySize(args) == 3) if (! PyArg_ParseTuple(args, "OiO", &path, &ignoreCache, &preset)) return NULL;
    if (pySize(args) < 1 || pySize(args) > 3) { PyErr_SetString(err, "VRScriptManager::loadGeometry: wrong number of arguments"); return NULL; }

    string p = PyString_AsString(path);
    string pre = "OSG";
    if (preset) pre = PyString_AsString(preset);

    VRTransform* obj = VRImport::get()->load( p, 0, ignoreCache, pre);
    if (obj == 0) {
        VRGuiManager::get()->printInfo("Warning: " + p + " not found.\n");
        Py_RETURN_NONE;
    }
    obj->setPersistency(0);
    return VRPyTypeCaster::cast(obj);
}
Esempio n. 12
0
VRObject* VRTransform::copy(vector<VRObject*> children) {
    VRTransform* geo = new VRTransform(getBaseName());
    geo->setPickable(isPickable());
    geo->setMatrix(getMatrix());
    return geo;
}