Ooops
November 25, 2020, 06:16:59 AM

Author Topic: [bb] Realistic Camera Shake by ClayPigeon [ 1+ years ago ]  (Read 585 times)

Offline BlitzBot

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

Description : This code uses cubic interpolation to smooth noise values and creates a realistic camera shaking effect. Useful for if the camera is zoomed in, or if the room is shaking, or an earthquake effect. Change the "period" variable to increase or decrease the shake speed. Adjust the "amp" variable to get more violent shaking.

Code :
Code: BlitzBasic
  1. Graphics3D 640,480,0,2
  2. SetBuffer BackBuffer()
  3. SeedRnd MilliSecs()
  4.  
  5. Global period# = 8
  6. Global timer% = 0
  7. Global amp# = 1
  8. Global x0#,x1#,x2#,x3#,y0#,y1#,y2#,y3#
  9. x0 = Rnd#(-amp,amp)
  10. x1 = Rnd#(-amp,amp)
  11. x2 = Rnd#(-amp,amp)
  12. x3 = Rnd#(-amp,amp)
  13. y0 = Rnd#(-amp,amp)
  14. y1 = Rnd#(-amp,amp)
  15. y2 = Rnd#(-amp,amp)
  16. y3 = Rnd#(-amp,amp)
  17.  
  18. Global camera% = CreateCamera()
  19. PositionEntity camera,0,0,-3
  20.  
  21. Global cube% = CreateCube()
  22.  
  23. While Not KeyHit(1)
  24.         Cls
  25.        
  26.         If timer = period
  27.                 timer = 0
  28.                 x0 = x1
  29.                 x1 = x2
  30.                 x2 = x3
  31.                 x3 = Rnd#(-amp,amp)
  32.                 y0 = y1
  33.                 y1 = y2
  34.                 y2 = y3
  35.                 y3 = Rnd#(-amp,amp)
  36.         Else
  37.                 timer = timer+1
  38.         EndIf
  39.        
  40.         RotateEntity camera,CubicInterpolate(y0,y1,y2,y3,Float(timer/period)),CubicInterpolate(x0,x1,x2,x3,Float(timer/period)),0
  41.        
  42.         UpdateWorld
  43.         RenderWorld
  44.        
  45.         Flip
  46. Wend
  47.  
  48. End
  49.  
  50. Function CubicInterpolate#(x0#,x1#,x2#,x3#,mu#)
  51.    Local a0#,a1#,a2#,a3#,mu2#
  52.  
  53.    mu2 = mu*mu
  54.    a0 = x3-x2-x0+x1
  55.    a1 = x0-x1-a0
  56.    a2 = x2-x0
  57.    a3 = x1
  58.    
  59.    Return a0*mu*mu2+a1*mu2+a2*mu+a3
  60. End Function


Comments :


Cubed Inc.(Posted 1+ years ago)

 nice


virtualjesus(Posted 1+ years ago)

 Excellent!!!very useful, Thank You!!!


Happy Llama(Posted 1+ years ago)

 Very Nice!


virtualjesus(Posted 1+ years ago)

 ;CAMRA SHAKE IMPLEMENTEDGraphics3D 640,480,0,2SetBuffer BackBuffer()SeedRnd MilliSecs()Global period# = 8Global timer% = 0Global amp# = 1Global x0#,x1#,x2#,x3#,y0#,y1#,y2#,y3#x0 = Rnd#(-amp,amp)x1 = Rnd#(-amp,amp)x2 = Rnd#(-amp,amp)x3 = Rnd#(-amp,amp)y0 = Rnd#(-amp,amp)y1 = Rnd#(-amp,amp)y2 = Rnd#(-amp,amp)y3 = Rnd#(-amp,amp)Global camera% = CreateCamera()PositionEntity camera,0,0,-3Global cube% = CreateCube()While Not KeyHit(1)   Cls   ;*********   ;HERE UPDATE YOUR MOVES CUSTOM CAMERA    ;*********   If timer = period      timer = 0      x0 = x1      x1 = x2      x2 = x3      x3 = Rnd#(-amp,amp)      y0 = y1      y1 = y2      y2 = y3      y3 = Rnd#(-amp,amp)   Else      timer = timer+1   EndIf      TurnEntity camera,CubicInterpolate(y0,y1,y2,y3,Float(timer/period)),CubicInterpolate(x0,x1,x2,x3,Float(timer/period)),0      UpdateWorld   RenderWorld      FlipWendEndFunction CubicInterpolate#(x0#,x1#,x2#,x3#,mu#)   Local a0#,a1#,a2#,a3#,mu2#   mu2 = mu*mu   a0 = x3-x2-x0+x1   a1 = x0-x1-a0   a2 = x2-x0   a3 = x1      Return a0*mu*mu2+a1*mu2+a2*mu+a3End Function


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal