three.js testbed

with orbitControls, XZgrid, info

by jmchen

HTML

<div id="info">demo page</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/3587259/Code/Threejs/OrbitControls.js">
    
</script>

CSS

#info {
    position: absolute;
    top: 0px;
    width: 100%;
    padding: 10px;
    text-align: center;
    color: #ffff00
}
body {
    overflow: hidden;
}

JavaScript

function Proj (u, V) { // project V on u
    // u must be unit vector
    return u.clone().multiplyScalar (u.dot(V));
}

var Plane = function (pos, normal) {
    this.pos = pos;
    this.normal = normal;
};

// method of Person
Plane.prototype.isPointOut = function (point) {
    //var proj = this.normal.dot (point.clone().sub (this.pos));
    var xMp = point.clone().sub(this.pos);
    var proj = Proj (this.normal, xMp);
    var inOut = proj.dot(this.normal) >= 0;
    
    if (inOut == false) { 
       // position correction
       // point = xMp - proj + this.pos;
        xMp.sub (proj) .add(this.pos);
        point.copy (xMp);
        
        // velocity correction...
    }
    return inOut;
};

var pp = new Plane (new THREE.Vector3(), new THREE.Vector3(0,1,0));
var point = new THREE.Vector3 (10,-60,30);

console.log (pp.isPointOut (point));
console.log (point);