@silverman:
Quote: "but only Latch has done"
I haven't thought about this for a while! Nice job, Silverman! Very Clean. The last thing I remember working on with this was using sprites to mask areas of the screen to capture for reflection.
This example is a variation of what you posted. I tried to squeeze some speed out of the idea by not using bitmaps and using a sprite to hide the area on screen. Also, I added a timer to only call the reflection code every 30 milliseconds. While this will help other processes in the game to have more time to run, because of the refresh (sync) in the reflect code, it may look choppy.
Lower this time and it'll smooth it out, but also notice the fall in FPS.
I also use a goto _flip to control the main loop. This allows me to reduce the number of times I call SYNC. If too many syncs are called in a row, it changes the reported FPS.
remstart
==============================================================
= Title : Mirror Test
= Author : latch
= Date : 05/10/2012
= Update :
= Version: .01
==============================================================
Comments
==============================================================
remend
rem =============================================================
rem = SET UP DISPLAY
rem =============================================================
autocam off
set display mode 640,480,32
sync on
sync rate 0
rem =============================================================
rem = MAIN
rem =============================================================
_main:
gosub _init
_flip:
text 0,0,str$(screen fps())
text 0,20,"Actual Iterations per second : "+str$(1000/(timer()-tpassed))
text 0,40,real_fps()
tpassed=timer()
rem move a cone around independent of the reflection
gosub _move_cone
rem control how often the reflection is updated
if timer()-tim > 30
gosub _reflect
tim=timer()
goto _flip
endif
sync
goto _flip
end
rem =============================================================
rem = SUBROUTINES - PROCEDURES
rem =============================================================
_init:
rem create a sprite of the effect size. Sprites aren't captured
rem by Get Image so we can use it to cover part of the screen
rem without worries.
get image 1,0,0,256,256
sprite 1,-900,-900,1
set sprite 1,0,0
rem make matrix for 0,0,0 reference
make matrix 1,1000,1000,25,25
position matrix 1,-500,-30,-500
rem make a red sphere that represents the camera
make object sphere 1,5
color object 1,rgb(255,0,0)
rem make a plane to display the rglection on
`make object plain 2,25,25
make object cube 2,50
position object 2,50,0,0
rem make sure the plane is fully bright
set object emissive 2,rgb(255,255,255)
rem make a cube to put in the scene
make object cube 3,25
position object 3,-25,0,0
rem a cone that will move independently of the reflection code
make object cone 4,20
color object 4,rgb(0,255,0)
rem set the initial camera position
position camera 0,0,-100
hide object 2
sync
rem first capture a little piece of the screen where we will
rem paste the hidden reflection
get image 1,screen width()-256,0,screen width(),256
sync
show object 2
return
`================================================================
_reflect:
rem put the sprite there to cover up the corner
sprite 1,screen width()-256,0,1
rem position the camera
position object 1,-25,0,0
yrotate object 1,wrapvalue(object angle y(1)+1)
move object 1,-50
position camera object position x(1),object position y(1),object position z(1)
point camera -25,0,0
rem set camera view to area hidden under sprite and capture that image
set camera view bitmap width(0)-256,0,bitmap width(0),256
get image 2,bitmap width(0)-256,0,bitmap width(0),256
sync
texture object 2,2
rem reposition the camera to start
position camera 0,0,-120
rotate camera 0,0,0
set camera view 0,0,bitmap width(0),bitmap height(0)
rem get the image in the corner for the sprite
get image 1,screen width()-256,0,screen width(),256
return
`================================================================
_move_cone:
position object 4,-25,0,0
turn object left 4,1
move object 4,-40
return
`================================================================
Rem fps function by Silverman
function real_fps()
inc fps
if real=0
t=timer()
real=1
result$="0"
else
if timer()-t>=1000
inc t,1000
result$=str$(fps)
fps=0
endif
endif
endfunction result$
Enjoy your day.