November 25, 2020, 06:14:02 AM

Author Topic: [bb] Simple lensflare by Rob [ 1+ years ago ]  (Read 558 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Simple lensflare by Rob [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Simple lensflare
Author : Rob
Posted : 1+ years ago

Description : Compatible with various 2D in 3D sprite libs and so forth for ease of use.

Code :
Code: BlitzBasic
  1. ;lensflare example for 2D and 3D
  2. ;rob@redflame.net
  3.  
  4. Graphics3D 640,480,16,2
  5.  
  6. ;required
  7. Global viewx=GraphicsWidth(),viewy=GraphicsHeight()
  8.  
  9. camera=CreateCamera()
  10. CameraRange camera,1,2000
  11. HidePointer()
  12.  
  13. ;make a sun
  14. sun=CreateSphere()
  15. EntityColor sun,255,255,0
  16. EntityFX sun,1
  17. ScaleEntity sun,100,100,100
  18. PositionEntity sun,800,600,800
  19.  
  20. ;level
  21. p=CreatePlane()
  22. PositionEntity p,0,-10,0
  23.  
  24. While Not KeyHit(1)
  25.  
  26.         ;mouse
  27.         mxspd#=MouseXSpeed()*0.25
  28.         myspd#=MouseYSpeed()*0.25
  29.         MoveMouse viewx/2,viewy/2
  30.  
  31.         ;rotate view
  32.         pitch#=pitch#+myspd#
  33.         If pitch#<-90 Then pitch#=-90
  34.         If pitch#>90 Then pitch#=90
  35.         yaw#=yaw#-mxspd#
  36.         RotateEntity camera,pitch#,yaw#,0
  37.  
  38.        
  39.         RenderWorld
  40.        
  41.         ;update flare (if using 3D, place before renderworld)
  42.         updateflare(camera,sun)
  43.        
  44.         Flip           
  45. Wend
  46. End
  47.  
  48. Function updateflare(camera,source)
  49.         CameraProject camera,EntityX(source,1),EntityY(source,1),EntityZ(source,1)
  50.         x#=ProjectedX()/viewx
  51.         y#=ProjectedY()/viewy
  52.  
  53.         ;if on screen  
  54.         If (x>0 And x<=1) And (y>0 And y<=1)
  55.                
  56.                 ;-1 to 1
  57.                 xoffset# = (x-0.5)*2
  58.                 yoffset# = (y-0.5)*2
  59.  
  60.                 ;notes:        
  61.                
  62.                 ;Flares: (use sprites and a sprite lib to translate from 3D to 2D.
  63.                 ;For now, we use 2D to illustrate. Multiply offsets however you like.
  64.                 ;Oval coords corrected for offset - not needed with 3D sprites.
  65.  
  66.                
  67.                 ;flare 1
  68.                 flare1_x# = (viewx/2) - (xoffset*640)
  69.                 flare1_y# = (viewy/2) - (yoffset*320)
  70.                 Oval flare1_x-16,flare1_y-16,32,32,0
  71.                
  72.                 ;flare 2
  73.                 flare2_x# = (viewx/2) - (xoffset*64)
  74.                 flare2_y# = (viewy/2) - (yoffset*32)
  75.                 Oval flare2_x-100,flare2_y-100,200,200,0
  76.                
  77.                 ;flare 3
  78.                 flare3_x# = (viewx/2) - (xoffset*500)
  79.                 flare3_y# = (viewy/2) - (yoffset*250)
  80.                 Oval flare3_x-64,flare3_y-64,128,128,0
  81.                
  82.                                
  83.         EndIf
  84. End Function


Comments :


psychicbottle(Posted 1+ years ago)

 huh this is very cool and useful


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal