namespace Msp::Game {
Camera::Camera(Handle<Entity> e, const CameraSetup &s):
- Component(e),
- setup(s),
- fov_y(setup.field_of_view_y),
- size(setup.size),
- near_clip(setup.near_clip),
- far_clip(setup.far_clip)
+ BufferedComponent<CameraData>(e),
+ setup(s)
{
- if(!is_orthographic())
- size = { get_aspect(), 1.0f };
+ CameraData &d = write();
+ d.fov_y = setup.field_of_view_y;
+ d.size = setup.size;
+ d.near_clip = setup.near_clip;
+ d.far_clip = setup.far_clip;
+
+ if(!d.is_orthographic())
+ d.size = { d.get_aspect(), 1.0f };
}
void Camera::set_field_of_view(Geometry::Angle<float> f, float a)
{
- if(is_orthographic())
+ Data &d = write();
+ if(d.is_orthographic())
throw logic_error("Camera is not perspective");
- fov_y = f;
- size = { a, 1.0f };
+ d.fov_y = f;
+ d.size = { a, 1.0f };
}
void Camera::set_size(const LinAl::Vector<float, 2> &s)
{
- if(!is_orthographic())
+ Data &d = write();
+ if(!d.is_orthographic())
throw logic_error("Camera is not orthographic");
- size = s;
+ d.size = s;
}
} // namespace Msp::Game