March 06, 2021, 05:43:35 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Like stats
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
3D Graphics - Effects
»
[bb] Realistic Camera Shake by ClayPigeon [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Realistic Camera Shake by ClayPigeon [ 1+ years ago ] (Read 614 times)
BlitzBot
Jr. Member
Posts: 1
Total likes: 0
[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
Graphics3D
640
,
480
,
0
,
2
SetBuffer
BackBuffer
(
)
SeedRnd
MilliSecs
(
)
Global
period# =
8
Global
timer% =
0
Global
amp# =
1
Global
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
,-
3
Global
cube% =
CreateCube
(
)
While
Not
KeyHit
(
1
)
Cls
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
RotateEntity
camera,CubicInterpolate
(
y0,y1,y2,y3,
Float
(
timer/period
)
)
,CubicInterpolate
(
x0,x1,x2,x3,
Float
(
timer/period
)
)
,
0
UpdateWorld
RenderWorld
Flip
Wend
End
Function
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+a3
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
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
3D Graphics - Effects
»
[bb] Realistic Camera Shake by ClayPigeon [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal