mpwassler Posted October 13, 2016 Share Posted October 13, 2016 I have a sprite in my scene which the user clicks on and then the camera moves. The problem is I need to overlay an html element on that sprite after the camera moves. Is there any way to project the sprite position to x, y canvas coordinates? The Vector3.Project function doesn't seem to work for me beacuse I can't compute the worldMatrix from the sprite ( at least not that I know of ). Here is what I tried. The this context here is the sprite. var transformationMatrix = camera.getViewMatrix().multiply(camera.getProjectionMatrix()); var position = this.position var projectedPosition = BABYLON.Vector3.Project(position, this.computeWorldMatrix(true), transformationMatrix, camera.viewport.toGlobal(camera.getEngine())); Thanks! Quote Link to comment Share on other sites More sharing options...
mpwassler Posted October 13, 2016 Author Share Posted October 13, 2016 Never mind I figured this out my use of the project method was simply wrong. This works! var position = this.position var projectedPosition = BABYLON.Vector3.Project( position, BABYLON.Matrix.Identity(), this.scene.getTransformMatrix(), camera.viewport.toGlobal(990, 450) // size of my canvas ); GameMonetize 1 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.