Jump to content

check camera can see the point


zhg115
 Share

Recommended Posts

hi.  I want to check the camera can see the point.  and I caculate the worldviewProject like which is the Vertex shader has.

the code: 

// worldViewProjectionMatrix = world * view * projection

// worldViewProjectionMatrix * vector

var viewport = camera.viewport.toGlobal(engine);
    
    var cw = viewport.width;
    var ch = viewport.height;
    var cx = viewport.x;
    var cy = viewport.y;
    var viewportMatrix = BABYLON.Vector3._viewportMatrixCache ? BABYLON.Vector3._viewportMatrixCache : (BABYLON.Vector3._viewportMatrixCache = new BABYLON.Matrix());
    BABYLON.Matrix.FromValuesToRef(cw / 2.0, 0, 0, 0, 0, -ch / 2.0, 0, 0, 0, 0, 1, 0, cx + cw / 2.0, ch / 2.0 + cy, 0, 1, viewportMatrix);
    var matrix = BABYLON.Vector3._matrixCache ? BABYLON.Vector3._matrixCache : (BABYLON.Vector3._matrixCache = new BABYLON.Matrix());

   BABYLON.Matrix.Identity().multiplyToRef( viewportMatrix , matrix);
     matrix.multiplyToRef(camera.getProjectionMatrix(), matrix);
     
     
     var p2 = BABYLON.Vector3.TransformCoordinates(vector, matrix)

//BABYLON.Vector3.Project(vector, world, transform, viewport) 

var p = BABYLON.Vector3.Project(vector, 
            BABYLON.Matrix.Identity(), 
           scene.getTransformMatrix(),   //scene.getTransformMatrix(), 
            camera.viewport.toGlobal(engine));

console.log(p);

console.log(p2);

// p and p2 xy not like

help.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...