Hello, I have two scenes. One for the hud using the orthographic camera and another for the general scene using the perspective camera.
I have a legend on the hud scene that I would like to place always in the top left corner, regardless the canvas size (i.e. if I change the window’s size, then the legend will stay in the intended place). How can I achieve that ?
Check out how the red circles are always rendered at the same position relative to the window. The relevant code is in createHUDSprites() and updateHUDSprites():
function createHUDSprites( texture ) {
var material = new THREE.SpriteMaterial( { map: texture } );
var width = material.map.image.width;
var height = material.map.image.height;
spriteTL = new THREE.Sprite( material );
spriteTL.center.set( 0.0, 1.0 );
spriteTL.scale.set( width, height, 1 );
sceneOrtho.add( spriteTL );
spriteTR = new THREE.Sprite( material );
spriteTR.center.set( 1.0, 1.0 );
spriteTR.scale.set( width, height, 1 );
sceneOrtho.add( spriteTR );
spriteBL = new THREE.Sprite( material );
spriteBL.center.set( 0.0, 0.0 );
spriteBL.scale.set( width, height, 1 );
sceneOrtho.add( spriteBL );
spriteBR = new THREE.Sprite( material );
spriteBR.center.set( 1.0, 0.0 );
spriteBR.scale.set( width, height, 1 );
sceneOrtho.add( spriteBR );
spriteC = new THREE.Sprite( material );
spriteC.center.set( 0.5, 0.5 );
spriteC.scale.set( width, height, 1 );
sceneOrtho.add( spriteC );
updateHUDSprites();
}
function updateHUDSprites() {
var width = window.innerWidth / 2;
var height = window.innerHeight / 2;
spriteTL.position.set( - width, height, 1 ); // top left
spriteTR.position.set( width, height, 1 ); // top right
spriteBL.position.set( - width, - height, 1 ); // bottom left
spriteBR.position.set( width, - height, 1 ); // bottom right
spriteC.position.set( 0, 0, 1 ); // center
}