i trying @ polygon's center in 3d space convert points 2d screen coordinates. code doesn't work. appreciated.
//calculate center var center = new three.vector3(); (var = 0; < positions.length; i++) { center.add(positions[i]); } center.multiplyscalar(1 / positions.length); //look @ center var camera = new three.perspectivecamera(75, width / height, 0.1, 1000); camera.lookat(center); //calculate screen coordinates (var = 0; < positions.length; i++) { screenpositions.push(toscreenxy(positions[i], camera, width, height)); } function toscreenxy(position, camera, width, height) { var pos = position.clone(); pos.project(camera); var halfwidth = width / 2, halfheight = height / 2; return { x: (pos.x + 1) * halfwidth + halfwidth, y: (-pos.y + 1) * halfheight + halfheight }; } it though camera transformations have no effect on projection
since changed camera's rotation, need update camera's world matrix, because method project() references it.
camera.position.set( x, y, z ); camera.lookat( center ); camera.updatematrixworld(); // add the renderer calls camera.updatematrixworld() in renderer.render(), in case, have call yourself.
three.js r.71
Comments
Post a Comment