zhg115 Posted July 14, 2016 Share Posted July 14, 2016 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. Quote Link to comment Share on other sites More sharing options...
georage Posted July 14, 2016 Share Posted July 14, 2016 This seems related? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.