User Tools

Site Tools


en:guides:beginners:viewport_and_camera

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:guides:beginners:viewport_and_camera [2018/02/13 20:47 (6 years ago)] – ↷ Page moved from guides:beginners:viewport_and_camera to en:guides:beginners:viewport_and_camera iarwainen:guides:beginners:viewport_and_camera [2020/08/19 12:15 (4 years ago)] (current) – Viewport -> MainViewport to match the changes in init's template iarwain
Line 5: Line 5:
 A viewport is the rectangle that we can view the game world through. And a camera allows us to see all or part of that world at a time. A viewport is the rectangle that we can view the game world through. And a camera allows us to see all or part of that world at a time.
  
-Take a look at your Project.ini and you'll see that a [Viewport] section has already been specified for you. There are some commented out options like Size and BackgroundColor:+Take a look at your MyGame.ini and you'll see that a ''[MainViewport]'' section has already been specified for you.
  
 <code=ini> <code=ini>
-[Viewport+[MainViewport
-Camera             Camera +Camera             MainCamera
-;RelativePosition  = bottom right +
-;Position          = (100, 100, 0); NB: Position is in pixels and will be ignored if RelativePosition is specified +
-;RelativeSize      = (0.5, 0.5, 0.0) +
-;Size              = (200, 150, 0) NB: Size is in pixels and will be ignored if RelativeSize is specified +
-;BackgroundColor   = (255, 180, 0)+
 </code> </code>
  
-Our game will have a blue sky as a background, so change the config to be:+Let's give our game a blue sky as a background, by adding the ''BackgroundColor'' property to the config:
  
 <code=ini> <code=ini>
-[Viewport+[MainViewport
-Camera            = Camera+Camera            = MainCamera
 BackgroundColor   = (0, 180, 255) BackgroundColor   = (0, 180, 255)
 </code> </code>
  
-Secondly, notice the Camera parameter is set to Camera? This means it is set to the [Camera] section, which has also already been defined for you:+Secondly, notice the Camera parameter is set to ''MainCamera''? This means it is set to the ''[MainCamera]'' section, which has also already been defined for you:
  
 <code=ini> <code=ini>
-[Camera+[MainCamera
-FrustumWidth  @Display.ScreenWidth +FrustumWidth    1280 
-FrustumHeight = @Display.ScreenHeight +FrustumHeight   720 
-FrustumFar    1.0 +FrustumFar      2.0 
-FrustumNear   = 0.0 +FrustumNear     = 0.0 
-Position      = (0.0, 0.0, -1.0)+Position        = (0.0, 0.0, -1.0) ; Objects with -1 <= Z <= 1 will be visible
 </code> </code>
  
-Change the camera position first:+The ''Position'' is set to 0,0 which is in the center of the screen so that the whole screen can be viewed. The Z position is -1.0 which means the camera is set back a little from the action.         
 + 
 +Let's change the screen width and height so that it makes working through the tutorial easier (and easier to take screenshots :) ):
  
 <code=ini> <code=ini>
-[Camera+[MainCamera
-FrustumWidth  @Display.ScreenWidth +FrustumWidth    800 
-FrustumHeight = @Display.ScreenHeight +FrustumHeight   600 
-FrustumFar    1.0 +FrustumFar      2.0 
-FrustumNear   = 0.0 +FrustumNear     = 0.0 
-Position      = (400300, -1.0)+Position        = (0.00.0, -1.0) ; Objects with -1 <= Z <= 1 will be visible
 </code> </code>
  
-The camera is positioned into the center of the screen (400300) so that the whole screen can be viewed.+A frustum width and height does not have to be the same size as your screen, but for our game, we want it to be. So the ''ScreenWidth'' and ''ScreenHeight'' values from the ''[Display]'' section are being inherited from the ''FrustumWidth'' and ''FrustumHeight'' values, as you can see at:
  
-A frustum width and height does not have to be the same size as your screen, but for our game, we want it to be. So the width and height values are being inherited from the ScreenWidth and ScreenHeight parameters in the [Display] section.+<code ini> 
 +[Display] 
 +ScreenWidth     = @MainCamera.FrustumWidth 
 +ScreenHeight    = @MainCamera.FrustumHeight 
 +... 
 +</code>
  
-The viewport needs to be created when our game runs, so let's take a look at the Project.cpp code:+The viewport needs to be created when our game runs, so let's take a look at the MyGame.cpp code:
  
 <code=cpp> <code=cpp>
Line 57: Line 59:
 { {
  
-    orxViewport_CreateFromConfig("Viewport");+    orxViewport_CreateFromConfig("MainViewport");
 </code> </code>
  
Line 63: Line 65:
  
  
-The "Viewport" parameter specified in that function is the same name as the [Viewport] section in the config.+The "MainViewportstring parameter specified in that function is the same name as the ''[MainViewport]'' section in the config.
  
-Because the camera was specified in the [Viewport] section, we do not need to create a camera in code.+Because the camera was specified in the ''[MainViewport]'' section, we do not need to create a camera in code.
  
-Final thing for this step is to name our game. This name will show in the window title. Set this with the Title property in the [Display] section:+Final thing for this step is to name our game. This name will show in the window title. Set this with the ''Title'' property in the ''[Display]'' section. Also while you are here, set the ''Smoothing'' to false:
  
 <code=ini> <code=ini>
 [Display] [Display]
-ScreenWidth   800 +ScreenWidth     @MainCamera.FrustumWidth 
-ScreenHeight  600 +ScreenHeight    @MainCamera.FrustumHeight 
-Title         = Platform Hero+Title           = Platform Hero 
 +FullScreen      = false 
 +Smoothing       = false 
 +VSync           = true 
 +</code> 
 + 
 +This will change the name in the window title, but only if you are compiling in Release mode. You'll most likely be compiling in Debug mode right now. So you'll also need to change the title in the ''MyGamed.ini'' file: 
 + 
 +<code ini> 
 +[Display] 
 +Title           = Platform Hero (Debug) 
 +ShowFPS         = true
 </code> </code>
  
-Compile and run to see your game window with a blue background and a default object in the top left of the screen. This because of the position of the camera, and that the default object is at position (0,0) by default:+Compile and run to see your game window with a blue background and a default object in the center of the screen:
  
 {{:guides:beginners:beginners-19-object-position.png?nolink|}} {{:guides:beginners:beginners-19-object-position.png?nolink|}}
Line 82: Line 95:
 ---- ----
  
-Next: [[guides:beginners:objects|Part 6 – Objects]]+Next: [[en:guides:beginners:objects|Part 6 – Objects]]
  
-{{section>guides:beginners:toc&noheader&nofooter&noeditbutton}}+{{section>en:guides:beginners:toc&noheader&nofooter&noeditbutton}}
en/guides/beginners/viewport_and_camera.1518583674.txt.gz · Last modified: 2018/02/14 00:47 (6 years ago) (external edit)