Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
Set camera bounds from go properties
Browse files Browse the repository at this point in the history
- Create test in `test_bounds.collection`
- Update README.md with new camera settings
- Change debug varnames to camel case
- Set version string to `2.0-pre3`
  • Loading branch information
lukas-kasticky committed Apr 9, 2020
1 parent 3461359 commit a83c0f8
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 32 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,31 @@ If checked, the "View Area" setting will be used to calculate the initial area o
#### View Area <kbd>vector3</kbd>
The dimensions in world space that the camera will show, if "Use View Area" is checked. They will be measured at "2d World Z" (usually 0). If using a fixed aspect ratio, the view area Y value will be overwritten based on the X value if they don't match the specified aspect ratio.

### View Scale Modes:
The last four checkbox settings determine the scale mode used to calculate how the view changes anytime the window resolution is changed (including on init if your camera settings don't match your display settings in game.project). Only the first mode checked will be used (and a default is used if none are checked). Note that Fixed Area, Fixed Width, and Fixed Height all work exactly the same if you're using a fixed aspect ratio (since the aspect ratio locks the viewport dimensions together).
#### View Scale Modes:
The next four checkbox settings determine the scale mode used to calculate how the view changes anytime the window resolution is changed (including on init if your camera settings don't match your display settings in game.project). Only the first mode checked will be used (and a default is used if none are checked). Note that Fixed Area, Fixed Width, and Fixed Height all work exactly the same if you're using a fixed aspect ratio (since the aspect ratio locks the viewport dimensions together).

#### Expand View
##### Expand View <kbd>bool</kbd>
The view area will expand and contract with the window size, keeping the world at the same size on-screen. If you set your camera view area to 800x600, but your game starts with a window size of 1600x900 (as set in game.project), then the view will expand to fill the window and show a 1600x900 area of the world. Likewise if the window size is smaller---the camera will simply show less of the world.

#### Fixed Area
##### Fixed Area <kbd>bool</kbd>
The camera will zoom in or out to show exactly the same _area_ of the game world. This works great for a wide range of window or display proportions, if you don't need either dimension to be exactly the same for everyone.

#### Fixed Width
##### Fixed Width <kbd>bool</kbd>
The camera will always show the same width of game world, the height is adjusted to fit. If the window is stretched vertically, it will show more space on top and bottom.

#### Fixed Height
##### Fixed Height <kbd>bool</kbd>
Like "Fixed Width", but switched. The camera will always show the same height of the game world, and the width will vary with the window proportion. If you make the window tall and skinny, you'll see the same distance up and down, but very little side to side.

#### Camera bounds:

##### Use Camera Bounds <kbd>bool</kbd>

If checked, limits for the camera's position in its local X/Y are set. The camera will not be allowed to move outside the specified rectangle bounds (except movement due to camera shake and recoil).

##### Camera Bounds {Left, Right, Top, Bottom} <kbd>number</kbd>

Sets the boundaries of the limit rectangle, in coordinates local to the camera.

## Camera Functions & Messages
To use the other features of Rendercam you need to call module functions from a script. First, require the rendercam module in your script:
```lua
Expand Down
2 changes: 1 addition & 1 deletion game.project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
title = Rendercam
version = 1.0
version = 2.0-pre3
dependencies =

[bootstrap]
Expand Down
8 changes: 4 additions & 4 deletions main/main.collection
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ instances {
component_properties {
id: "script"
properties {
id: "debug_bounds"
id: "debugBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "debug_camera_name"
id: "debugCameraName"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
Expand Down Expand Up @@ -124,12 +124,12 @@ instances {
component_properties {
id: "script"
properties {
id: "debug_bounds"
id: "debugBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "debug_camera_name"
id: "debugCameraName"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
Expand Down
37 changes: 32 additions & 5 deletions rendercam/camera.script
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ local debugdraw = require "rendercam.debug-draw"
local rdebug = rendercam.debug
local simplex = require "rendercam.simplex2d"

go.property("debug_bounds", false)
go.property("debug_camera_name", false)
go.property("debugBounds", false)
go.property("debugCameraName", false)
go.property("parent", msg.url())
go.property("active", true)
go.property("orthographic", true)
Expand All @@ -34,6 +34,13 @@ go.property("fixedArea", true)
go.property("fixedWidth", false)
go.property("fixedHeight", false)

-- vector4 would show up as X Y Z W, which is confusing
go.property("useCameraBounds", false)
go.property("cameraBoundsLeft", 0)
go.property("cameraBoundsRight", 0)
go.property("cameraBoundsTop", 0)
go.property("cameraBoundsBottom", 0)

local TWO_PI = math.pi * 2
local FORWARDVEC = vmath.vector3(0, 0, -1)
local UPVEC = vmath.vector3(0, 1, 0)
Expand All @@ -46,8 +53,8 @@ local SET_BOUNDS = hash("set_bounds")

function init(self)
-- set debug values
rdebug.bounds = self.debug_bounds
rdebug.show_camera_name = self.debug_camera_name
rdebug.bounds = self.debugBounds
rdebug.show_camera_name = self.debugCameraName

-- Get initial scale mode
for i,v in ipairs({ "expandView", "fixedArea", "fixedWidth", "fixedHeight" }) do
Expand Down Expand Up @@ -112,6 +119,25 @@ function init(self)
end
end

-- set viewport bounds
self.viewportBounds = nil
if self.useCameraBounds then
local left = self.cameraBoundsLeft
local right = self.cameraBoundsRight
local top = self.cameraBoundsTop
local bottom = self.cameraBoundsBottom
self.viewportBounds = {
-- see rendercam.lua:227
lt = left, rt = right, top = top, bot = bottom,
width = right - left, height = top - bottom,
centerX = left + (right - left)/2,
centerY = bottom + (top - bottom)/2,
topRight = vmath.vector3(right, top, 0),
bottomLeft = vmath.vector3(left, bottom, 0),
}
end


-- Put all camera data into a table for rendercam module and init camera.
self.data = {
active = self.active,
Expand Down Expand Up @@ -143,7 +169,8 @@ function init(self)
follows = {},
following = false,
hasFollowDeadzone = false,
followDeadzone= vmath.vector4(0, 0, 0, 0)
followDeadzone = vmath.vector4(0, 0, 0, 0),
viewportBounds = self.viewportBounds
}
rendercam.camera_init(self.id, self.data)

Expand Down
12 changes: 6 additions & 6 deletions tests/visual/animate with shake/test_anim with shake.collection
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ instances {
component_properties {
id: "script"
properties {
id: "debug_bounds"
id: "debugBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "debug_camera_name"
id: "debugCameraName"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
Expand Down Expand Up @@ -56,12 +56,12 @@ instances {
component_properties {
id: "script"
properties {
id: "debug_bounds"
id: "debugBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "debug_camera_name"
id: "debugCameraName"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
Expand Down Expand Up @@ -124,12 +124,12 @@ instances {
component_properties {
id: "script"
properties {
id: "debug_bounds"
id: "debugBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "debug_camera_name"
id: "debugCameraName"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
Expand Down
76 changes: 72 additions & 4 deletions tests/visual/bounds/test_bounds.collection
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ instances {
component_properties {
id: "script"
properties {
id: "debug_bounds"
id: "debugBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "debug_camera_name"
id: "debugCameraName"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
Expand Down Expand Up @@ -74,12 +74,12 @@ instances {
component_properties {
id: "script"
properties {
id: "debug_bounds"
id: "debugBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "debug_camera_name"
id: "debugCameraName"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
Expand All @@ -90,6 +90,69 @@ instances {
z: 1.0
}
}
instances {
id: "camera3"
prototype: "/rendercam/camera.go"
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.64278764
w: 0.76604444
}
component_properties {
id: "script"
properties {
id: "debugBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "debugCameraName"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "active"
value: "false"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "useCameraBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "cameraBoundsLeft"
value: "-1170.0"
type: PROPERTY_TYPE_NUMBER
}
properties {
id: "cameraBoundsRight"
value: "500.0"
type: PROPERTY_TYPE_NUMBER
}
properties {
id: "cameraBoundsTop"
value: "200.0"
type: PROPERTY_TYPE_NUMBER
}
properties {
id: "cameraBoundsBottom"
value: "-200.0"
type: PROPERTY_TYPE_NUMBER
}
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
scale_along_z: 0
embedded_instances {
id: "test"
Expand All @@ -112,6 +175,11 @@ embedded_instances {
" value: \"/camera2\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"camera3\"\n"
" value: \"/camera3\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
"}\n"
"components {\n"
" id: \"basic test controls gui\"\n"
Expand Down
2 changes: 2 additions & 0 deletions tests/visual/bounds/test_bounds.script
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- camera1: set bounds with function call
-- camera3: set bounds with object properties

local rendercam = require 'rendercam.rendercam'

Expand Down
8 changes: 4 additions & 4 deletions tests/visual/shake/test_shake.collection
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ instances {
component_properties {
id: "script"
properties {
id: "debug_bounds"
id: "debugBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "debug_camera_name"
id: "debugCameraName"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
Expand Down Expand Up @@ -56,12 +56,12 @@ instances {
component_properties {
id: "script"
properties {
id: "debug_bounds"
id: "debugBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "debug_camera_name"
id: "debugCameraName"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
Expand Down
4 changes: 2 additions & 2 deletions tests/visual/transform/test transform.collection
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ instances {
component_properties {
id: "script"
properties {
id: "debug_bounds"
id: "debugBounds"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
properties {
id: "debug_camera_name"
id: "debugCameraName"
value: "true"
type: PROPERTY_TYPE_BOOLEAN
}
Expand Down

0 comments on commit a83c0f8

Please sign in to comment.