November 30, 2020, 01:26:57 AM

Author Topic: [bb] 3D Camera Fade by Dragon57 [ 1+ years ago ]  (Read 569 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] 3D Camera Fade by Dragon57 [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : 3D Camera Fade
Author : Dragon57
Posted : 1+ years ago

Description : Fade a specified camera in or out to a specified RGB color

Code :
Code: BlitzBasic
  1. Function fade(dir$,camera,secs#=2,R=0,G=0,B=0,distance#=1.00001)
  2. ; 3D Fade, V1.0 by Martin A. Parrott (parrottm@hotmail.com)
  3. ; This is a quick piece of code to do a fade in/out in BlitzBasic3D
  4. ; This is camera based, so it will not work for all circumstances
  5. ; This code is based on code originally written in Dark Basic
  6. ; Note: This code works differently on various 3D graphics cards
  7. ;       so use at your own risk and test it for usability in your
  8. ;       own program
  9. ;
  10. ; This code is free to use, but if you modify it, please send the
  11. ; changes to the above email address so I can continue to release
  12. ; updates so others can benefit.
  13. ;
  14. ; Parameters are:
  15. ; dir$ - The direction to fade, either in or out
  16. ; camera - The camera to fade
  17. ; secs# - The number of seconds for the fade
  18. ; R - The 'red' value of the color to fade to
  19. ; G - The 'green' value of the color to fade to
  20. ; B - The 'blue' value of the color to fade to
  21. ; distance# - This is how far in front of the camera to put the object
  22. ;             Make this a small amount more than the minimum camera range
  23.  
  24.   Select Lower$(dir$) ; Set a flag so we know later whether to fade in or out
  25.  
  26.     Case Lower("in")
  27.       state=1
  28.  
  29.     Case Lower("out")
  30.       state=0
  31.  
  32.     Default ; Return if this is called without the correct parameters
  33.       Return
  34.  
  35.   End Select
  36.  
  37.   If camera=0 Return
  38.   If secs#=0 Return
  39.  
  40.   Delay#=secs#*1000 ; Calculate delay in milliseconds
  41.  
  42.   camplane=CreateMesh(camera) ; Create an object to put in front of the camera
  43.   camsurf=CreateSurface(camplane)
  44.   AddVertex(camsurf,-10,-10,0) ; Create 4 corners of a square
  45.   AddVertex(camsurf,-10,10,0)
  46.   AddVertex(camsurf,10,10,0)
  47.   AddVertex(camsurf,10,-10,0)
  48.   AddTriangle(camsurf,0,1,2) ; Connect the dots!
  49.   AddTriangle(camsurf,0,2,3)
  50.  
  51.   MoveEntity camplane,0,0,distance# ; Position the plane in front of the camera
  52.   EntityAlpha camplane,state ; Make the plane visible/invisible to start with, depending on how the routine is called
  53.   EntityColor camplane,R,G,B ; Color the plane to what the user wants
  54.  
  55.   starttime#=MilliSecs() ; Get our start time
  56.  
  57.   Select state
  58.  
  59.   Case 0
  60.     While MilliSecs() < starttime#+Delay# ; Loop for the delay# time adjusting our alpha amount toward opacity
  61.       newtime#=MilliSecs()
  62.       alpha#=(newtime#-starttime#)/Delay#
  63.       EntityAlpha camplane,alpha#
  64.       UpdateWorld
  65.       RenderWorld
  66.       Flip
  67.     Wend
  68.  
  69.   Case 1
  70.     While MilliSecs() < starttime#+Delay# ; Loop for the delay# time adjusting our alpha amount toward invisibility
  71.       newtime#=MilliSecs()
  72.       alpha#=((starttime#+Delay#)-newtime#)/Delay#
  73.       EntityAlpha camplane,alpha#
  74.       UpdateWorld
  75.       RenderWorld
  76.       Flip
  77.     Wend
  78.  
  79.   End Select
  80.  
  81.   EntityAlpha camplane,state ; Because of roundoff error, make sure our plane is totally invisible/opaque
  82.   FreeEntity camplane ; Clean up
  83.  
  84. End Function
  85.  
  86. Function fadein(camera,secs#=2,R=0,G=0,B=0,distance#=1.00001)
  87. ; Semi-redundant way to call the main function. Sometimes I want to use fade and sometimes fadein as a command. ;)
  88.  
  89.   fade("in",camera,secs#,R,G,B,distance#)
  90.  
  91. End Function
  92.  
  93. Function fadeout(camera,secs#=2,R=0,G=0,B=0,distance#=1.00001)
  94. ; Semi-redundant way to call the main function. Sometimes I want to use fade and sometimes fadeout as a command. ;)
  95.  
  96.   fade("out",camera,secs#,R,G,B,distance#)
  97.  
  98. End Function
  99.  


Comments :


Rob Pearmain(Posted 1+ years ago)

 Great code, add  EntityFX camplane,1To get the fade to full bright


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal