Rem Project: MultiCameras Tutorial
Rem Created: 4/24/2003 9:37:56 PM
Rem Created By: Alasdair Macleod (newbi2basic)
Rem Enhanced Comments: Dan Heenan (Silent)
Rem ***** Main Source File *****
Rem Use Timer() as our Randomize Seed will almost ensure that
Rem each run will result in a different set of numbers. It is
Rem good practice to use this anytime you need random numbers Randomize timer()
Rem Set Display Mode can be set in the Side Control Panel, but
Rem some users may not realise that they've defaulted to some-
Rem thing else, and this will ensure that the screen will show
Rem the same way we originally set it up. Set display mode800,600,32
Rem This is the General Game Setup, nearly all games will use
Rem the same style, turning on manual Sync to try and get the
Rem best refresh rate possible, or just to display certain
Rem items whenever we want. The Sync Rate has been set to a
Rem maximum of 30 to ensure that users with 'Super-Computers'
Rem and most other computers will run at the same speed. This
Rem is useful for many reasons, but it mostly to stop the
Rem advantage/disadvantages some users may have. Autocam Off
Rem is used so that the Field Of View(FOV) is not changed by
Rem the loading of media and therefore we will not had a
Rem stretched viewing angle, beyond the normal range of the
Rem eye.
Sync on
Sync rate 30
Autocam off
Rem Set up our World. Certain user will require a different
Rem set of manipulation options for their land/sea, and can
Rem choose which suits them out of an Object or a Matrix.
Rem In this case we are using a simple to create Matrix,
Rem with a size of 1000 units horizontally(X-Axis), and 1000
Rem units 'into the screen'(Z-Axis), this is then split into
Rem 52 tiles by 52 tiles, all equally sized. Make matrix1,1000,1000,52,52
Rem We have created our Matrix, now we need to give it some
Rem character. In this case we will use the Random(Rnd)
Rem command to generate a height value between 0 and 13.
Rem This is run in a loop, 1 to 52 in both the X and Z axis
Rem so that each tile is set to the height of that Random
Rem Number, this will give us a 'bumpy' Matrix. For x = 1to52 For Z = 1to52 Set matrix height1,x,z,Rnd(13) Next z Next X
Rem This command is simply used to update ANY changes we
Rem have made to our Matrix, in our case it's our height
Rem changes. Update matrix1
Rem Here we will create our Multiple Cameras. We run this in
Rem a loop to save on typing, and/or to make out code neater
Rem This loop will create 3 cameras, all with the default
Rem settings. For i = 1to3 Make camera i next i
Rem Currently, our newly created cameras are all covering
Rem each other, so we will now set their Viewport, that is,
Rem the area in which our specific camera will render to
Rem the screen. We have to specify the camera number we
Rem want to change the viewport of, and also the left,top,
Rem right, and bottom co-ordinates of the viewing area.
Rem So this code will set, Camera 0 (Default) to the Upper
Rem Left corner of the screen, Camera 1 (User Created) to
Rem the Lower Left, Camera 2 (User Created) to the Upper
Rem Right, and Camera 3 (User Created) to the Lower Right. Set camera view0,0,0,400,300 Set camera view1,0,300,400,600 Set Camera view2,400,0,800,300 Set Camera view3,400,300,800,600
Rem We will now re-position each of the cameras, as currently
Rem they are all at the same position (0,0,0). There's not much
Rem to explain here, but we set the X-Axis(Horizontal), Y-Axis
Rem (Vertical), and Z-Axis('Into the Screen'). In general the
Rem Cameras are positioned to show off your scene, and multiple
Rem cameras are positioned in different areas to show it from a
Rem different angle, eg. In a racer you could use your default
Rem camera for normal view, and a second camera for a rear-view
Rem mirror effect. Position Camera0,0,15,0 Position Camera1,0,15,0 Position Camera2,1000,15,1000 Position Camera3,1000,15,0
Rem We now start our main loop. This is a Do...Loop loop, where
Rem we will run the code inside forever, unless the user quits
Rem or the Exit command is sent. The rest of the commands will
Rem be explained as we come across them.
Do
Rem Here will spin the camera on the spot, we are only going to
Rem rotate on the Y-Axis(Vertical), so we will use the command
Rem YRotate Camera, rather than the XRotate/ZRotate/Rotate Camera
Rem command. As we are spinning, we can only spin 360°, so we
Rem use the Wrapvalue command, as this will automatically 'wrap'
Rem the value we give it around back to 0+ if we give it a value
Rem more than 360°. The value we pass it here, is the current
Rem camera Y angle, plus the speed we want it to rotate at,
Rem basically how many degrees per frame. YRotate Camera0,Wrapvalue(Camera Angle Y(0) + 1)
Rem We are now going to rotate Camera 2 (Although it's numbered 1)
Rem around the Y-axis, but this time based on the horizontal move-
Rem ment of the mouse, using MouseMoveX(). Here we have to divide
Rem the value returned by 2, otherwise we will be given a value too
Rem large resulting in an uncontrollable camera. We will also check
Rem for a Left Mouseclick using MouseClick(). This function will
Rem return a value based on which mouse buttons, if any are being
Rem pressed, in the following way:
Rem Returns Why?
Rem 0 No Buttons Pressed
Rem 1 Left Mouse Button
Rem 2 Right Mouse Button
Rem 3 Left and Right Buttons (Returned values added)
Rem 4 Middle Mouse Button
Rem 5+ Other buttons your mouse may have, although
Rem these are not normally used in games due to
Rem varying configurations. YRotate Camera1,Wrapvalue(Camera Angle Y(1) + (MouseMoveX() / 2.0)) If MouseClick() = 1then Move Camera1,2
Rem With Camera 3, we will raise and lower it based on the value in
Rem our height# variable. We will also modify our height# value based
Rem on the value in our direction variable, this being -1 for going
Rem down or anything(<> but -1) else for going up. We do a quick check
Rem before moving the camera to see if we are too high or low and then
Rem change the direction varible based on the results. We check whether
Rem the height# is more than(>)50 and if so, change the direction to -1
Rem we also check for height# being less than(<) 15, and if so, change
Rem direction to 1, although this doesn't really matter and could be
Rem anything but -1. After our checks we finally re-position our camera.
Rem Using Camera Position X(), and Camera Position Z() to retrieve the
Rem X and Z position of the camera as we are not modifying this, and set
Rem the Y position to the value of height#. If direction <> -1then height# = height# + 0.5 If direction = -1then height# = height# - 0.5 If height# > 75.0then direction = -1 If height# < 15.0then direction = 1 Position Camera2,Camera Position X(2),height#,Camera Position Z(2)
Rem Our Fourth and Last Camera will be controlled by use using the Arrow
Rem Keys. Although there is a command in DarkBasic Professional that will
Rem do this for us, it is more flexible if we use our own code. Using the
Rem commands Upkey(), Downkey(), Leftkey(), and Rightkey(), we can check
Rem which of the arrowkeys are currently being pressed. They will return
Rem 1 if True, or 0 if False. We pass 1 to the Move Camera command so
Rem that it will move 1 unit in whatever direction it is facing, we pass
Rem -1 when checking the Downkey so that we move back 1 unit. We are
Rem again using Wrapvalue and Camera Angle Y() to turn/rotate the camera.
Rem In the Leftkey() check we use -1 as if you are turning left, you will
Rem turn Anti-Clockwise. The Rightkey() uses +1 to turn in a clockwise
Rem direction. If Upkey() = 1then Move Camera3,1 If Downkey() = 1then Move Camera3,-1 If Leftkey() = 1then YRotate Camera3,Wrapvalue(Camera Angle Y(3) - 1) If Rightkey() = 1then YRotate Camera3,Wrapvalue(Camera Angle Y(3) + 1)
Rem This is the end of our loop, here we Sync so that all the changes we
Rem have made, except for Matrix manipulation are displayed. It is best
Rem to only have 1 or as little as possible Sync's in your code, as this
Rem will provide an optimal running rate. This is due to the whole scene
Rem not having to be rendered over and over. We then get to the loop,
Rem where the whole process after the Do command is run again. This will
Rem continue till the user pressed the Escape[Esc] key.
Sync
Loop
All content found on this website are copyrights of Banded Software. Copyright 2002-2006 Banded Software. All Rights Reserved.
Original Site Design by Southeast Creations