A package for rendering simple scenes primarily consisting of cars on roadways using Cairo.
The main function is
render(scene)
where scene is an iterable of renderable objects including cars and roadways.
Example:
roadway = gen_straight_roadway(3, 100.0)
car = ArrowCar([0.0, 0.0], 0.0, color=colorant"blue") # [north, east], angle
render([roadway, car, "some text"])
What does it mean to be "renderable"?
An object is directly renderable if the function render!(rm::RenderModel, object)
is implemented for it.
An object is renderable by conversion if convert(Renderable, object)
returns a directly renderable object.
When render()
is invoked, direct renderability is checked with isrenderable(object)
, which defaults to method_exists(render!, Tuple{RenderModel, typeof(object)})
. If this check fails, a conversion attempt is made with convert(Renderable, object)
.
The primary basic directly renderable types are Roadway
(now from AutomotiveDrivingModels; soon from Roadways.jl
) and ArrowCar
.
ArrowCar
s are the pink cars with arrows that are in everyone's videos. The type will look like this:
@with_kw struct ArrowCar{A<:AbstractArray{Float64}, C<:Color}
pos::A = SVector(0.0, 0.0)
angle::Float64 = 0.0
color::C = PINK
text::String = "" # some debugging text to print by the car
id::Int = 0
end
ArrowCar(pos::AbstractArray, angle::Float64=0.0; color=PINK, text="", id=0) = ArrowCar(pos, angle, color, "", id)
There are two ways to make renderable types.
- You can make your existing types renderable by conversion by defining
convert(::Type{Renderable}, ::MyType)
which should return a directly renderable object, e.g. anArrowCar
. - You can make types directly renderable by defining
render!(::RenderModel, ::MyType)
. To make things easier for the compiler, you can also defineisrenderable(::Type{MyType}) = true
. If you want to allow others to convert to this type to make their types renderable by conversion, make your type a subtype ofRenderable
.
Overlays will function as in the previous version of AutoViz. They will be rendered last with render!(rendermodel, overlay, scene)
.
The following additional keyword arguments will accepted by render()
:
canvas_width
canvas_height
rendermodel
cam
- a camera controlling the field of view as in the previous version of AutoViz
Is the
Renderable
type defined in Cairo?