Stick model to other objects

Hi
Is there any possible way to stick model to other objects in AR? What i mean? I have desk and when i place this desk near to wall, there is a gap beetwen desk and wall. I want that desk to be as close as in you can place desk in real life. :smiley:

this code calculate touched position of wall live time without raycast

 var Edge = function (p1, p2, fun ,ref) {

    this.p1 = { x:  p1.x, y: p1.y, z: p1.z ,h:p1.h};
    this.p2 = { x:  p2.x, y: p2.y, z: p2.z ,h:p2.h};
    this.helper = [];
    this.ref = ref;
    if (fun) fun(this);

};
 Edge.prototype = {
    p1: {},
    p2: {},
    ref: {},
    helper: [],
    cross2D: function (p, inside, func,ref) {
        var th = this;
        var a = pow(pow(this.p1.x - p.x) + pow(this.p1.z - p.z), 0.5);
        var b = pow(pow(this.p2.x - p.x) + pow(this.p2.z - p.z), 0.5);
        var c = pow(pow(this.p2.x - this.p1.x) + pow(this.p2.z - this.p1.z), 0.5);

        var beta = acos((pow(a) + pow(c) - pow(b)) / ((2 * a * c) + 0.000001));

        var len = a * cos(beta);

        var pn = norm({ x: this.p2.x - this.p1.x, y: 0., z: this.p2.z - this.p1.z });
        pn.x *= len;
        pn.z *= len;

        var pn1 = { x: this.p1.x + pn.x, y: 0, z: this.p1.z + pn.z };

        if (inside) {
            var nrm1 = norm({ x: this.p1.x - pn1.x, y: 0., z: this.p1.z - pn1.z });
            var nrm2 = norm({ x: this.p2.x - pn1.x, y: 0., z: this.p2.z - pn1.z });

            var di = function (n) {
                return floor(n * 1.2 / (abs(n) + 0.0001));
            }

            if (di(nrm1.x) == di(nrm2.x) && di(nrm1.z) == di(nrm2.z)) {
                if (func) func(th); return null;
            }
        }

        var len1 = pow(pow(pn1.x - p.x) + pow(pn1.z - p.z), 0.5);
        if (func) func(th, pn1, len1,ref);

        return { point: pn1, length: len1 };
    }
};



    var WallDetails = function () { this.edgs = []; };
    WallDetails.prototype = {
        edgs: [],
        addEdge: function (p1, p2, fun, ref) {

            this.edgs.push(new  Edge(p1, p2, fun, ref));
        }
    };
2 Likes