matrix - convert Point3D To Screen2D get wrong result in three.js -


i use function in three.js 69

  function point3dtoscreen2d(point3d,camera){     var p = point3d.clone();     var vector = p.project(camera);      vector.x = (vector.x + 1) / 2 * window.innerwidth;     vector.y = -(vector.y - 1) / 2 * window.innerheight;      return vector;    } 

it works fine when keep scene still. when rotate scene made mistake , return wrong position in screen.it occurs when rotate how 180 degrees.it shoudn't have position in screen showed.

i set position var tmpv=point3dtoscreen2d(new three.vector3(-67,1033,-2500),camera); in update , show css3d.and when rotate 180 degrees less 360 , point shows in screen again.obviously it's wrong position can telled scene , haven't rotate 360 degrees.

i know little matrix,so don't know how project works.

here source of project in three.js:

project: function () {          var matrix;          return function ( camera ) {              if ( matrix === undefined ) matrix = new three.matrix4();              matrix.multiplymatrices( camera.projectionmatrix, matrix.getinverse( camera.matrixworld ) );             return this.applyprojection( matrix );          };      }() 

is matrix.getinverse( camera.matrixworld ) redundant? tried delete , didn't work. can me?thanks.

you projecting 3d point world space screen space using pattern one:

var vector = new three.vector3(); var canvas = renderer.domelement;  vector.set( 1, 2, 3 );  // map normalized device coordinate (ndc) space vector.project( camera );  // map 2d screen space vector.x = math.round( (   vector.x + 1 ) * canvas.width  / 2 ), vector.y = math.round( ( - vector.y + 1 ) * canvas.height / 2 ); vector.z = 0; 

however, using approach, points behind camera projected screen space, too.

you said want filter out points behind camera. that, can use pattern first:

var matrix = new three.matrix4(); // create once , reuse  ...  // matrix maps world space camera space matrix.getinverse( camera.matrixworld );  // transform point world space camera space p.applymatrix( matrix ); 

since camera located @ origin in camera space, , since camera looking down negative-z axis in camera space, points behind camera have z-coordinate greater zero.

// check if point behind camera if ( p.z > 0 ) ... 

three.js r.71


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -