Please forgive the triple post but it was neccessary because of the attachments.
I had some spare time so I knocked up a working demo for
binocular view. Attached is an EXE with media and source code.
Use the arrow keys and mouse to move around and press 'B' to use binoculars.
I have also implemented a zoom function, so that instead of just flicking between normal and binocular views, there is a transition between them.
Here is the code (in case you want to see what I have done without having to download anything)
`Project : Terrain Demo
`=========================
`Author : Craig McFarlane
`=========================
`Started : 23rd July 2006
`Types
`Arrays
`Constants
`Booleans
Global Yes as boolean = 1
Global No as Boolean = 0
Global LastUnderWater as boolean = 0
Global Binocular as boolean = 0
`Floats
Global Speed as float = 0.40
Global Turn as float = 0.3
Global CameraAngleX as float = 0.0
Global CameraAngleY as float = 0.0
Global OldCameraAngleX as float = 0.0
Global OldCameraAngleY as float = 30.0
Global WaterRipple as float = 20.0
Global Height as float = 0.0
Global FOV as float = 90.0
Global ZoomRate as float = 10.0
`Integers
Global tTerrain as integer = 1
Global WaterLevel as integer = 25
`Objects
Global oWater as integer = 2
Global oSkyBox as integer = 3
Global oBinocularMask as integer = 4
`Images
Global iWater as integer = 1
Global iTexture as integer = 2
Global iDetail as integer = 3
Global iBinocularMask as integer = 4
`Sprites
Global sBinocularMask as integer = 1
`Sounds
`Bitmaps
`Memblocks
`-------------------
` LOAD IMAGES
`-------------------
load image "media/texture.bmp", iTexture
load image "media/detail.tga", iDetail
load image "media/Water.jpg" , iWater , 1
load image "media/Binocular Mask.png" , ibinocularMask
`-------------------
` LOAD OBJECTS
`-------------------
load object "media/skybox2.x", oSkyBox
set object light oSkyBox , 0
set object texture oSkyBox , 3, 1
position object oSkyBox , 1000, 2000, 4000
scale object oSkyBox , 30000, 30000, 30000
`-------------------
` MAKE OBJECTS
`-------------------
Make object plain oWater , 5000 , 5000
texture object oWater , iWater
xrotate object oWater , 90
position object oWater , 0 , WaterLevel + 3 , 0
set object texture oWater , 2 , 1
fade object oWater , 5
set object ambience oWater , rgb(255,255,255)
scale object texture oWater , 20 , 20
`-------------------
` LOAD SOUNDS
`-------------------
`-------------------
` SET TERRAIN
`-------------------
make object terrain tTerrain ` create the terrain object
set terrain heightmap tTerrain , "media/map.bmp" ` set the heightmap
set terrain scale tTerrain , 12, 0.5, 12 ` set the scale
set terrain split tTerrain , 4 ` split value by 16 * 16
set terrain tiling tTerrain , 4 ` detail map tiling
set terrain light tTerrain , 1, -0.25, 0, 1, 1, 0.75, 0.5 ` light - xdir, ydir, zdir, red, green, blue, intensity
set terrain texture tTerrain , iTexture , iDetail ` base and detail texture
build terrain tTerrain
`-------------------
` SET SPRITES
`-------------------
Sprite sBinocularMask , 0 , 0 , iBinocularMask
Hide Sprite sBinocularMask
Size Sprite sBinocularMask , 640 , 480
`-------------------
` SET WORLD
`-------------------
sync on
sync rate 60
set ambient light 100
position camera 410,23,130
backdrop on
autocam off
set camera range 0.5, 30000
`************************************************************************************
`* *
`* S T A R T O F M A I N L O O P *
`* *
`************************************************************************************
do
GetUserInput()
CheckForUnderWater()
UpdateWorld()
_DeBug()
sync
loop
`***********************************************************************************
`* *
`* E N D O F M A I N L O O P *
`* *
`***********************************************************************************
`-------------------
` DEBUG
`-------------------
function _DeBug()
` text 0,0,"FPS : "+str$(Screen fps())
endfunction
`-------------------
` GET USER INPUT
`-------------------
function GetUserInput()
` move around with arrow keys
control camera using arrowkeys 0, Speed, Turn
` store old camera angle
OldCamAngleY = CameraAngleY
OldCamAngleX = CameraAngleX
` store new camera angle
CameraAngleY = wrapvalue ( CameraAngleY + mousemovex ( ) * 0.4 )
CameraAngleX = wrapvalue ( CameraAngleX + mousemovey ( ) * 0.4 )
` rotate camera
yrotate camera curveangle ( CameraAngleY, OldCamAngleY, 24 )
xrotate camera curveangle ( CameraAngleX, OldCamAngleX, 24 )
` speed up movement
if inkey$ ( ) = "+"
if Speed < 1000
Inc Speed , 0.01
endif
endif
` slow down movement
if inkey$ ( ) = "-"
if Speed > 0.002
dec Speed , 0.001
endif
endif
`Binocular Vision?
if keystate(48)
Binocular = Yes
else
Binocular = No
endif
endfunction
`-------------------
` UPDATE WORLD
`-------------------
function UpdateWorld()
`Camera
Height = get terrain ground height( tTerrain, camera position x( ), camera position z( ) )
position camera camera position x( ), Height + 3, camera position z()
`Water
scroll object texture oWater , sin(WaterRipple) / 1000 , cos(WaterRipple) / 1000
inc WaterRipple , 0.01
`Binocular Vision
if Binocular = Yes
if FOV > 10 then dec FOV , ZoomRate
set camera fov FOV
show sprite sBinocularMask
else
if FOV < 90 then inc FOV , ZoomRate
set camera fov FOV
hide sprite sBinocularMask
endif
`Terrain
Update Terrain
endfunction
`-------------------
` UNDERWATER?
`-------------------
Function CheckForUnderWater()
GroundHeight = get terrain ground height( tTerrain , camera position x( ), camera position z( ) )
if GroundHeight < WaterLevel
UnderWater = Yes
else
UnderWater = No
endif
if UnderWater = Yes and LastUnderWater = No
`color ambient light rgb(0,100,128)
fog on
fog color 0,100,128
fog distance 35
endif
if UnderWater = No and LastUnderWater = Yes
color ambient light rgb(255,255,255)
fog off
fog color 255,255,255
fog distance 10000
endif
LastUnderWater = UnderWater
EndFunction
And here is what it looks like running:
Normal View:
Zoomed View: