December 04, 2020, 11:18:12 AM

Author Topic: [bb] Wireframe x-ray target by BlitzSupport [ 1+ years ago ]  (Read 587 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Wireframe x-ray target
Author : BlitzSupport
Posted : 1+ years ago

Description : This code grabs a section of the screen, rendered in wireframe mode to the backbuffer (but not shown), then draws it over the 3D scene, giving the effect of a small wireframe box over... the... uh...

Just try it! The only problem is that wireframe isn't guaranteed to work on all graphics cards, sadly, but there's all sorts of other neat stuff you can do with variations on this trick :)


Code :
Code: BlitzBasic
  1. ; --------------------------------------------------------------
  2. ; WireBox Demo... james @ hi - toro . com
  3. ; --------------------------------------------------------------
  4. ; Just plug right into your existing code to see it really rocking ;)
  5. ; --------------------------------------------------------------
  6. ; Use mouse to move wirebox...
  7. ; --------------------------------------------------------------
  8.  
  9. ; --------------------------------------------------------------
  10. ; WireBox stuff...
  11. ; --------------------------------------------------------------
  12.  
  13. ; x pos, y pos, width, height, image...
  14. Global wireX, wireY, wireWidth, wireHeight, wireBox
  15.  
  16. ; Call at start of main loop * after setting wireX and wireY *...
  17. Function GetWireBox (width, height)
  18.         WireFrame 1
  19.         RenderWorld
  20.         wireWidth = width: wireHeight = height
  21.         wireBox = CreateImage (wireWidth, wireHeight)
  22.         MaskImage wireBox, 255, 0, 255
  23.         GrabImage wireBox, wireX, wireY
  24.         WireFrame 0
  25. End Function
  26.  
  27. ; Call just before 'Flip'...
  28. Function DrawWireBox ()
  29.         If wireBox
  30.                 DrawImage wireBox, wireX, wireY        
  31.                 FreeImage wireBox
  32.         EndIf
  33. End Function
  34.  
  35. ; --------------------------------------------------------------
  36.  
  37. AppTitle "Move mouse over cube..."
  38. HidePointer ()
  39.  
  40. Graphics3D 640, 480
  41. SetBuffer BackBuffer ()
  42.  
  43. cube = CreateCube ()
  44.  
  45. Global light = CreateLight ()
  46. LightColor light, 255, 0, 0
  47.  
  48. cam = CreateCamera ()
  49. MoveEntity cam, 0, 0.75, -5
  50.  
  51. Color 0, 255, 0 ; Just for on-screen 'target'...
  52.  
  53. Repeat
  54.  
  55.         ; --------------------------------------------------------------
  56.         ; **** WireBox part 1, at start of main loop ****
  57.         ; --------------------------------------------------------------
  58.         wireX = MouseX () - (wireWidth / 2): wireY = MouseY () - (wireHeight / 2)
  59.         GetWireBox (64, 64)
  60.         ; --------------------------------------------------------------
  61.  
  62.         TurnEntity cube, 0, 0.5, 0
  63.        
  64.         UpdateWorld    
  65.         RenderWorld
  66.  
  67.         ; --------------------------------------------------------------
  68.         ; **** WireBox part 2, just before 'Flip' ****
  69.         ; --------------------------------------------------------------
  70.         DrawWireBox ()
  71.         ; --------------------------------------------------------------
  72.  
  73.         ; Quick target thing...
  74.         Rect wireX - 1, wireY - 1, wireWidth + 2, wireHeight + 2, 0
  75.         Line wireX + (wireWidth / 2) - 4, wireY + (wireHeight / 2), wireX + (wireWidth / 2) + 4, wireY + (wireHeight / 2)
  76.         Line wireX + (wireWidth / 2), wireY + (wireHeight / 2) - 4, wireX + (wireWidth / 2), wireY + (wireHeight / 2) + 4
  77.  
  78.         Flip
  79.  
  80. Until KeyHit (1)
  81.  
  82. End


Comments :


chwaga(Posted 1+ years ago)

 very nice, I could think of tons of uses for this


Oiduts Studios(Posted 1+ years ago)

 AMAZING, there are so many uses like HUDs and scopes.


WildCat(Posted 1+ years ago)

 Big respect!


_PJ_(Posted 1+ years ago)

 Very nice, seems quite smooth too.I might see if I can improvise on this and get the images drawn as 3D sprites instead, to avoid possible 2D slowdowns


Blitzplotter(Posted 1+ years ago)

 just tried this, very cool.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal