[SOLVED]Text over 3d entities

Just starting out? Need help? Post your questions and find answers here.
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

[SOLVED]Text over 3d entities

Post by einander »

Image
I need to draw over each ball of this example:
http://www.purebasic.fr/english/viewtop ... 12&t=48467
a text label, like the one on the image. Any hint?
Thanks in advance.
Last edited by einander on Mon Dec 12, 2011 12:08 am, edited 1 time in total.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Text over 3d entities

Post by IdeasVacuum »

...can't tell from the image what you want to do - just a 2d label over the image? Or a label on each ball? Couldn't the label be a small surface, 'attached' logically to it's ball but always parallel and orientated to the screen, using a texture for the text?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Re: Text over 3d entities

Post by einander »

Couldn't the label be a small surface, 'attached' logically to it's ball but always parallel and orientated to the screen, using a texture for the text?
Yes, that is what I need.

I've tried this with Billboards; each BillBoardGroup (one for each Billboard) with the text is always facing the screen, and moving with his ball. I can move the BillBoardGroup inside the ball, or around the ball; but I'm failing to put the text always on the visible surface side of the ball (as in the image).

Attach a small surface with text to a ball seems the good way. But how?

Thanks for your interest.
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Text over 3d entities

Post by idle »

guess you'll just have to texture the sphere with the symbols and rotate them to the camera
user rotates camera around the ball and stick model then you loop through the balls and rotate them
to face the camera

What does rotatematerial do? doesn't specify an axis so I guess it's only screen view.
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Re: Text over 3d entities

Post by einander »

Thanks Idle.
I'll investigate further on RotateMaterial (never used it before) and on how to found the correct angle for #PB_Material_Fixed to face the screen.
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Text over 3d entities

Post by Comtois »

with a billboard
- 1 - get direction btw an entity and camera

Code: Select all

      Direction\x = CameraX(0) - EntityX(0)
      Direction\y = CameraY(0) - EntityY(0)
      Direction\z = CameraZ(0) - EntityZ(0)
- 2 - Normalize Direction
- 3 - BillBoardPosition (or what you want) = Position Entity + Direction * Distance (Distance = Rayon + Delta)

Code: Select all

#CameraSpeed = 2
Enumeration
  #MainWindow 
  #Editor
EndEnumeration

Structure Vector3
  x.f
  y.f
  z.f
EndStructure

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY, Rayon = 5, Distance 
Distance = Rayon + 0.5

Define.Vector3 Direction 

Declare Normalize(*V.Vector3)

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    KeyboardMode(#PB_Keyboard_International)  
    
    ; First create materials
    ;
    CreateMaterial(0, LoadTexture(0,"Dirt.jpg"))
    CreateMaterial(1, LoadTexture(1,"viseur-jeux.png"))
    MaterialBlendingMode(1, #PB_Material_AlphaBlend)

    
    ; Meshes
    ;
    CreateSphere(0, Rayon, 40, 40)


    ; Entities
    ;
    CreateEntity(0, MeshID(0), MaterialID(0))
    
    ;-Billboard
    CreateBillboardGroup(0, MaterialID(1), Rayon/4, Rayon/4)
    AddBillboard(#PB_Any, 0, 0, 0, 0)
    
    ; Camera
    ;
    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0, 0, 3, 20)
    CameraLookAt(0, 0, 3, 0)
    
    ; Light
    ;
    CreateLight(0, RGB(255, 255, 255), 560, 90, 500)
    AmbientColor($888888)
    
    Repeat
      Screen3DEvents()
           
      If ExamineMouse()
        MouseX = MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf  
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
                  
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf

      EndIf
      
      RotateEntity(0, 1, 1, 1, #PB_Relative)
      
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(0, KeyX, 0, KeyY)
          
      Direction\x = CameraX(0) - EntityX(0)
      Direction\y = CameraY(0) - EntityY(0)
      Direction\z = CameraZ(0) - EntityZ(0)
      
      Normalize(@Direction)
      BillboardGroupLocate(0, EntityX(0) + Direction\x * Distance, EntityY(0) + Direction\y * Distance, EntityZ(0) + Direction\z * Distance) 
      RenderWorld()
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Procedure Normalize(*V.Vector3)
  Define.f magSq, oneOverMag 
  
  magSq = *V\x * *V\x + *V\y * *V\y + *V\z * *V\z 
  If magsq > 0
    oneOverMag = 1.0 / Sqr(magSq)
    *V\x * oneOverMag
    *V\y * oneOverMag
    *V\z * oneOverMag
  EndIf  
  
EndProcedure
Please correct my english
http://purebasic.developpez.com/
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Re: Text over 3d entities

Post by einander »

Thanks Comtois!
Your great example does what I was looking for. And more! :D
Cheers!
Post Reply