Skip to content

Commit

Permalink
added default position for CarFollowCamera
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Untergassmair committed Nov 5, 2019
1 parent a66ee13 commit c0ef5cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/cameras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ camera_set!(rendermodel::RenderModel, cam::FitToContentCamera, scene, canvas_wid
Camera which follows the vehicle with ID `targetid`.
By default, the target vehicle is tracked in x and y direction.
Tracking in either direction can be disabled by setting the
`follow_x` and `follow_y` keywords to false.
`follow_x` and `follow_y` keywords to false, in which case the
position defaults to `pos_default`.
The `zoom` keyword specifies the zoom level in pixels per meter.
"""
@with_kw mutable struct CarFollowCamera{I} <: Camera
targetid::I
zoom::Float64 = 3.0 # [pix/meter]
pos_default::VecE2 = VecE2(0.,0.)
follow_x::Bool = true
follow_y::Bool = true
end
Expand All @@ -54,6 +56,8 @@ function camera_set!(rendermodel::RenderModel, cam::CarFollowCamera{I}, scene::E
if veh_index != nothing
if cam.follow_x
camera_set_pos!(rendermodel, VecE2(scene[veh_index].state.s, 0.0))
else
camera_set_pos!(rendermodel, VecE2(cam.pos_default.x, 0.0))
end
camera_setzoom!(rendermodel, cam.zoom)
else
Expand All @@ -68,7 +72,10 @@ function camera_set!(rendermodel::RenderModel, cam::CarFollowCamera{I}, scene::E
veh_index = findfirst(cam.targetid, scene)
if veh_index != nothing
target_pos = scene[veh_index].state.posG
camera_pos = VecSE2(cam.follow_x ? target_pos.x : 0., cam.follow_y ? target_pos.y : 0.)
camera_pos = VecSE2(
cam.follow_x ? target_pos.x : cam.pos_default.x,
cam.follow_y ? target_pos.y : cam.pos_default.y
)
camera_set_pos!(rendermodel, camera_pos)
camera_setzoom!(rendermodel, cam.zoom)
else
Expand Down
2 changes: 1 addition & 1 deletion src/overlays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ end
Display the ID on top of each entity in a scene.
The text can be customized with the `color::Colorant` (default=white) and `font_size::Int64` (default=15) keywords.
The position of the ID can be adjusted using `x_off::Float64` and `y_off::Float64`.
The position of the ID can be adjusted using `x_off::Float64` and `y_off::Float64` (in camera coordinates).
"""
@with_kw mutable struct IDOverlay <: SceneOverlay
color::Colorant = colorant"white"
Expand Down

0 comments on commit c0ef5cc

Please sign in to comment.