Menu

Using TGLHudText for objects label

Help
LefjuCabro
2016-11-08
2016-11-18
  • LefjuCabro

    LefjuCabro - 2016-11-08

    Hello,

    In my scene I have spheres and for each spheres I want to display their labels near them.

    TGLFlatText don't convince me because it is in 3D so I am using TGLHudText which is in 2D.

    My problem is that TGLHudText don't move when I move camera. In order to fix that, in each camera moves, I destroy then create new TGLHudText. The result is good but not really optimised when I have a lot of spheres (500).

    Is there any proper method to move TGLHudText when I moved the scene.

    Attached, here is an example of my issue.

    Thanks

    Delphi Berlin Upd1 and GLScene 1.4.1.

     

    Last edit: LefjuCabro 2016-11-08
  • Jerome.D (BeanzMaster)

    hello for what you want to do you must use TGLFlatText create it as a child of your sphere and set options to twosidelighting and set depthtest to false (no z write) see GLGizmoEx units and demo TGLFlattext work well

     
  • LefjuCabro

    LefjuCabro - 2016-11-15

    Hello,

    I tried your method, it works but this is not the result I want: I always want labels in front of me whatever the camera position. I don't want "mirror" labels for users.

    Is there something I can do with TGLFlatText to do that ?

    Regards

     
  • Jerome.D (BeanzMaster)

    Hi can you post a sample source and some screenshots, please. I'll can get in touch when i'll have a little time.

     
  • LefjuCabro

    LefjuCabro - 2016-11-17

    Hi here is an example in "Labels.7z".

    In this project, I had 2 labels (1 TGLFlatText and 1 TGLHUDText) on each spheres. I show one of these labels with the checkbox.

    TGLFlatText:
    OK: this item moves automatically when camera turns and when zoom in/out.
    KO: mirror label according to camera position. Is there a way to have visible not mirrored TGLFlatText whatever camera position ?

    TGLHudText
    OK: this item moves when camera turns but I have to implement the new position on each moves.
    KO: zoom in/out. TGLHudText don't "follow" the sphere

    Regarding to this project, I don't know if I had better to use TGLFlatText or TGLHudText.

     
  • Jerome.D (BeanzMaster)

    You need update HUDText's position under GLSceneViewerMouseWheel

    procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    var
     objPos, winPos : TAffineVector;
    begin
        GLSceneViewer1.Camera.AdjustDistanceToTarget(Power(1.1, WheelDelta/120));
      if (not CheckBox1.Checked) then
        begin
          if Assigned(HUD_Sphere1) then
          begin
            objPos.V[0]:= GLSphere1.Position.X ;
            objPos.V[1]:= GLSphere1.Position.Y ;
            objPos.V[2]:= GLSphere1.Position.Z ;
            winPos := GLSceneViewer1.Buffer.WorldToScreen (objPos) ;
    
            HUD_Sphere1.Position.X:= winPos.V[0] ;
            HUD_Sphere1.Position.Y:= GLSceneViewer1.Height - Round(winPos.V[1]) ;
            HUD_Sphere1.Position.Z:= winPos.V[2] ;
          end;
          //
          if Assigned(HUD_Sphere2) then
          begin
            objPos.V[0]:= GLSphere2.Position.X ;
            objPos.V[1]:= GLSphere2.Position.Y ;
            objPos.V[2]:= GLSphere2.Position.Z ;
            winPos := GLSceneViewer1.Buffer.WorldToScreen (objPos) ;
    
            HUD_Sphere2.Position.X:= winPos.V[0] ;
            HUD_Sphere2.Position.Y:= GLSceneViewer1.Height - Round(winPos.V[1]) ;
            HUD_Sphere2.Position.Z:= winPos.V[2] ;
          end;
        end;
    end;
    
     
  • LefjuCabro

    LefjuCabro - 2016-11-18

    Quite simply... Thanks

    RESOLVED

     

    Last edit: LefjuCabro 2016-11-18

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.