[bb] Wireframe x-ray target by BlitzSupport [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:38

Previous topic - Next topic

BlitzBot

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) Select
; --------------------------------------------------------------
; WireBox Demo... james @ hi - toro . com
; --------------------------------------------------------------
; Just plug right into your existing code to see it really rocking ;)
; --------------------------------------------------------------
; Use mouse to move wirebox...
; --------------------------------------------------------------

; --------------------------------------------------------------
; WireBox stuff...
; --------------------------------------------------------------

; x pos, y pos, width, height, image...
Global wireX, wireY, wireWidth, wireHeight, wireBox

; Call at start of main loop * after setting wireX and wireY *...
Function GetWireBox (width, height)
WireFrame 1
RenderWorld
wireWidth = width: wireHeight = height
wireBox = CreateImage (wireWidth, wireHeight)
MaskImage wireBox, 255, 0, 255
GrabImage wireBox, wireX, wireY
WireFrame 0
End Function

; Call just before 'Flip'...
Function DrawWireBox ()
If wireBox
DrawImage wireBox, wireX, wireY
FreeImage wireBox
EndIf
End Function

; --------------------------------------------------------------

AppTitle "Move mouse over cube..."
HidePointer ()

Graphics3D 640, 480
SetBuffer BackBuffer ()

cube = CreateCube ()

Global light = CreateLight ()
LightColor light, 255, 0, 0

cam = CreateCamera ()
MoveEntity cam, 0, 0.75, -5

Color 0, 255, 0 ; Just for on-screen 'target'...

Repeat

; --------------------------------------------------------------
; **** WireBox part 1, at start of main loop ****
; --------------------------------------------------------------
wireX = MouseX () - (wireWidth / 2): wireY = MouseY () - (wireHeight / 2)
GetWireBox (64, 64)
; --------------------------------------------------------------

TurnEntity cube, 0, 0.5, 0

UpdateWorld
RenderWorld

; --------------------------------------------------------------
; **** WireBox part 2, just before 'Flip' ****
; --------------------------------------------------------------
DrawWireBox ()
; --------------------------------------------------------------

; Quick target thing...
Rect wireX - 1, wireY - 1, wireWidth + 2, wireHeight + 2, 0
Line wireX + (wireWidth / 2) - 4, wireY + (wireHeight / 2), wireX + (wireWidth / 2) + 4, wireY + (wireHeight / 2)
Line wireX + (wireWidth / 2), wireY + (wireHeight / 2) - 4, wireX + (wireWidth / 2), wireY + (wireHeight / 2) + 4

Flip

Until KeyHit (1)

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.