Skip to main content

HUD that adapts to window size

No replies
dragon73North
Offline
Joined: 2012-08-23
Points: 0

I'm trying to create a heads-up-display that can deal with changes to the display size (i.e., the user re-sizes the JPanel containing the Canvas). The problem is that this action causes the location of the HUD to shift relative to the user's field of vision. Sometimes the HUD is 'off screen' as a result.

I am hanging the HUD's BranchGroup off of the PlatformGeometry:

TransformGroup ptTG ;

public HudManager(ViewingPlatform vp) {
PlatformGeometry pg = new PlatformGeometry();

        /* WHERE THE PROBLEM OCCURS... */
Vector3f posVec = new Vector3f(xShift, yShift, zShift);

Transform3D positioningTransform = new Transform3D();
positioningTransform.setTranslation(posVec);
ptTG = new TransformGroup();
ptTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
ptTG.setCapability(Group.ALLOW_CHILDREN_EXTEND);
ptTG.setCapability(Group.ALLOW_CHILDREN_WRITE);
ptTG.setCapability(BranchGroup.ALLOW_DETACH);
ptTG.setTransform(positioningTransform);
location2TGrpMap.put(location, ptTG);
BranchGroup wrapperBG = new BranchGroup();
wrapperBG.addChild(ptTG);
pg.addChild(wrapperBG);
vp.setPlatformGeometry(pg);
}

public void setHUD(BranchGroup hudDisplay){
ptTG.addChild(hudRootBGrp);
}

The issue is figuring out the correct location of the posVec. I want it to be always at a fixed location relative to the edge of the Canvas (e.g., along the left side). The problem I have is figuring out where the edge is in terms of the x/y/z coordinates of the 3d universe given that the user is allowed to resize the display.

Any suggestions or tips would be appreciated. I can't help thinking this is a common problem.

Thanks