November 30, 2020, 02:13:16 AM

Author Topic: [bb] Gradually shrink camera viewport. by Zethrax [ 1+ years ago ]  (Read 604 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Gradually shrink camera viewport.
Author : Zethrax
Posted : 1+ years ago

Description : The first function gradually shrinks the camera viewport(s) to give the effect that the viewport is moving away from you. The aspect ratio of the viewport is preserved as it shrinks. You can specify a parameter (in seconds) which determines how long the shrinking process takes.

The effect is probably best suited to end of game, or death, scenes.

This function is meant to be used as a self contained routine, but it could be adapted to work as inline code in your main loop. You could also adapt it for use with 2D viewports.

The second function simply resets the viewport(s) to the specified size. If you only had one viewport to reset and no 'tidy up' rendering to do then you could simply use the 'CameraViewport' command directly.

Code: [Select]
Function shrink_camera_viewports_to_zero_size( the_vertical_shrink_time#, the_viewport_width, the_viewport_height )
; NOTES:-
; 'the_vertical_shrink_time#' is the time, in seconds, that the effect should take to complete, assuming that the viewport is wider than it is high.
; 'the_viewport_width' and 'the_viewport_height' are the viewport width and height.
; This code is designed to be used with viewports that take up all the window or full screen drawing area. The code should be adapted for other arrangements.

x# = 0
y# = 0
w# = the_viewport_width
h# = the_viewport_height

the_main_step# = the_viewport_height / the_vertical_shrink_time#
the_aspect_ratio# = Float ( the_viewport_width ) / Float ( the_viewport_height )

ClsColor 0, 0, 0 ; The background color. You can remove this if you don't use 'Cls' below.

the_old_millisecs_time = MilliSecs ()

While ( w# > 0 ) And ( h# > 0 ) And ( Not KeyHit ( 1 ) )
CameraViewport camera_1, x#, y#, w#, h# ; Changes the viewport size of your main camera.
CameraViewport HUD_camera, x#, y#, w#, h# ; Changes the viewport size of your HUD camera, if you've got one. Remove if not.
Cls ; Comment this out to get a paint streak effect.
RenderWorld
Delay ( 1 ) ; This is here to give Windows some breathing room.
VWait
Flip False

; -- Calculate the delta time to regulate the speed of the effect.
the_millisecs_time = MilliSecs ()
the_time_taken = the_millisecs_time - the_old_millisecs_time
If the_time_taken > 100 Then the_time_taken = 100 ; Stop abrupt jumps from occurring due to disk accesses, etc.
the_delta_time# = the_time_taken / 1000.0
the_old_millisecs_time = the_millisecs_time
;^^^^^^


the_step# = the_main_step# * the_delta_time#

h# = h# - the_step#
w# = h# * the_aspect_ratio#
x# = ( the_viewport_width - w# ) / 2.0
y# = ( the_viewport_height - h# ) / 2.0

Wend

End Function

; --- Reset the viewports to their original size. ---
Function reset_the_camera_viewports( the_viewport_width, the_viewport_height )
; NOTES:-
; 'the_viewport_width' and 'the_viewport_height' are the viewport width and height.

CameraViewport camera_1, 0, 0, the_viewport_width, the_viewport_height ; Changes the viewport size of your main camera.
CameraViewport HUD_camera, 0, 0, the_viewport_width, the_viewport_height ; Changes the viewport size of your HUD camera, if you've got one. Remove if not.
RenderWorld : VWait : Flip False ; You can remove this line if you want to do the rendering elsewhere.
End Function


Code :
Code: BlitzBasic
  1. ; The code is at: http://www.blitzbasic.com/codearcs/codearcs.php?code=909


Comments :


asdfasdf(Posted 1+ years ago)

 It doesn't do any thing


Zethrax(Posted 1+ years ago)

 Sorry, there's no example code in there so it won't do anything by itself. The code is heavily commented so you should be able to work out how to use it by reading through it, though.In the first function above, the lines:-CameraViewport camera_1, x#, y#, w#, h# ; Changes the viewport size of your main camera.CameraViewport HUD_camera, x#, y#, w#, h# ; Changes the viewport size of your HUD camera, if you've got one. Remove if not.should be edited so that the names for the camera handles (camera_1 and HUD_camera in the code above) are the same as the ones you use in your code. Remove the second line above if you don't have a second camera. Do the same in the second function.I'll add an example and some more detailed comments sometime soon.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal