|
|
@@ -38,136 +38,136 @@ namespace crown
|
|
|
{
|
|
|
|
|
|
Camera::Camera(SceneGraph& sg, int32_t node, ProjectionType::Enum type, float near, float far)
|
|
|
- : m_scene_graph(sg)
|
|
|
- , m_node(node)
|
|
|
- , m_projection_type(type)
|
|
|
- , m_near(near)
|
|
|
- , m_far(far)
|
|
|
+ : _scene_graph(sg)
|
|
|
+ , _node(node)
|
|
|
+ , _projection_type(type)
|
|
|
+ , _near(near)
|
|
|
+ , _far(far)
|
|
|
{
|
|
|
update_projection_matrix();
|
|
|
}
|
|
|
|
|
|
Vector3 Camera::local_position() const
|
|
|
{
|
|
|
- return m_scene_graph.local_position(m_node);
|
|
|
+ return _scene_graph.local_position(_node);
|
|
|
}
|
|
|
|
|
|
Quaternion Camera::local_rotation() const
|
|
|
{
|
|
|
- return m_scene_graph.local_rotation(m_node);
|
|
|
+ return _scene_graph.local_rotation(_node);
|
|
|
}
|
|
|
|
|
|
Matrix4x4 Camera::local_pose() const
|
|
|
{
|
|
|
- return m_scene_graph.local_pose(m_node);
|
|
|
+ return _scene_graph.local_pose(_node);
|
|
|
}
|
|
|
|
|
|
Vector3 Camera::world_position() const
|
|
|
{
|
|
|
- return m_scene_graph.world_position(m_node);
|
|
|
+ return _scene_graph.world_position(_node);
|
|
|
}
|
|
|
|
|
|
Quaternion Camera::world_rotation() const
|
|
|
{
|
|
|
- return m_scene_graph.world_rotation(m_node);
|
|
|
+ return _scene_graph.world_rotation(_node);
|
|
|
}
|
|
|
|
|
|
Matrix4x4 Camera::world_pose() const
|
|
|
{
|
|
|
- return m_scene_graph.world_pose(m_node);
|
|
|
+ return _scene_graph.world_pose(_node);
|
|
|
}
|
|
|
|
|
|
void Camera::set_local_position(Unit* unit, const Vector3& pos)
|
|
|
{
|
|
|
- unit->set_local_position(m_node, pos);
|
|
|
+ unit->set_local_position(_node, pos);
|
|
|
}
|
|
|
|
|
|
void Camera::set_local_rotation(Unit* unit, const Quaternion& rot)
|
|
|
{
|
|
|
- unit->set_local_rotation(m_node, rot);
|
|
|
+ unit->set_local_rotation(_node, rot);
|
|
|
}
|
|
|
|
|
|
void Camera::set_local_pose(Unit* unit, const Matrix4x4& pose)
|
|
|
{
|
|
|
- unit->set_local_pose(m_node, pose);
|
|
|
+ unit->set_local_pose(_node, pose);
|
|
|
}
|
|
|
|
|
|
void Camera::set_projection_type(ProjectionType::Enum type)
|
|
|
{
|
|
|
- m_projection_type = type;
|
|
|
+ _projection_type = type;
|
|
|
update_projection_matrix();
|
|
|
}
|
|
|
|
|
|
ProjectionType::Enum Camera::projection_type() const
|
|
|
{
|
|
|
- return m_projection_type;
|
|
|
+ return _projection_type;
|
|
|
}
|
|
|
|
|
|
const Matrix4x4& Camera::projection_matrix() const
|
|
|
{
|
|
|
- return m_projection;
|
|
|
+ return _projection;
|
|
|
}
|
|
|
|
|
|
float Camera::fov() const
|
|
|
{
|
|
|
- return m_FOV;
|
|
|
+ return _FOV;
|
|
|
}
|
|
|
|
|
|
void Camera::set_fov(float fov)
|
|
|
{
|
|
|
- m_FOV = fov;
|
|
|
+ _FOV = fov;
|
|
|
update_projection_matrix();
|
|
|
}
|
|
|
|
|
|
float Camera::aspect() const
|
|
|
{
|
|
|
- return m_aspect;
|
|
|
+ return _aspect;
|
|
|
}
|
|
|
|
|
|
void Camera::set_aspect(float aspect)
|
|
|
{
|
|
|
- m_aspect = aspect;
|
|
|
+ _aspect = aspect;
|
|
|
update_projection_matrix();
|
|
|
}
|
|
|
|
|
|
float Camera::near_clip_distance() const
|
|
|
{
|
|
|
- return m_near;
|
|
|
+ return _near;
|
|
|
}
|
|
|
|
|
|
void Camera::set_near_clip_distance(float near)
|
|
|
{
|
|
|
- m_near = near;
|
|
|
+ _near = near;
|
|
|
update_projection_matrix();
|
|
|
}
|
|
|
|
|
|
float Camera::far_clip_distance() const
|
|
|
{
|
|
|
- return m_far;
|
|
|
+ return _far;
|
|
|
}
|
|
|
|
|
|
void Camera::set_far_clip_distance(float far)
|
|
|
{
|
|
|
- m_far = far;
|
|
|
+ _far = far;
|
|
|
update_projection_matrix();
|
|
|
}
|
|
|
|
|
|
void Camera::set_orthographic_metrics(float left, float right, float bottom, float top)
|
|
|
{
|
|
|
- m_left = left;
|
|
|
- m_right = right;
|
|
|
- m_bottom = bottom;
|
|
|
- m_top = top;
|
|
|
+ _left = left;
|
|
|
+ _right = right;
|
|
|
+ _bottom = bottom;
|
|
|
+ _top = top;
|
|
|
|
|
|
update_projection_matrix();
|
|
|
}
|
|
|
|
|
|
void Camera::set_viewport_metrics(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
|
|
|
{
|
|
|
- m_view_x = x;
|
|
|
- m_view_y = y;
|
|
|
- m_view_width = width;
|
|
|
- m_view_height = height;
|
|
|
+ _view_x = x;
|
|
|
+ _view_y = y;
|
|
|
+ _view_width = width;
|
|
|
+ _view_height = height;
|
|
|
}
|
|
|
|
|
|
Vector3 Camera::screen_to_world(const Vector3& pos)
|
|
|
@@ -176,11 +176,11 @@ Vector3 Camera::screen_to_world(const Vector3& pos)
|
|
|
|
|
|
Matrix4x4 world_inv = world_pose();
|
|
|
invert(world_inv);
|
|
|
- Matrix4x4 mvp = world_inv * m_projection;
|
|
|
+ Matrix4x4 mvp = world_inv * _projection;
|
|
|
invert(mvp);
|
|
|
|
|
|
- Vector4 ndc( (2 * (pos.x - 0)) / m_view_width - 1,
|
|
|
- (2 * (m_view_height - pos.y)) / m_view_height - 1,
|
|
|
+ Vector4 ndc( (2 * (pos.x - 0)) / _view_width - 1,
|
|
|
+ (2 * (_view_height - pos.y)) / _view_height - 1,
|
|
|
(2 * pos.z) - 1, 1);
|
|
|
|
|
|
Vector4 tmp = ndc * mvp;
|
|
|
@@ -196,25 +196,25 @@ Vector3 Camera::world_to_screen(const Vector3& pos)
|
|
|
Matrix4x4 world_inv = world_pose();
|
|
|
invert(world_inv);
|
|
|
|
|
|
- Vector3 ndc = pos * (world_inv * m_projection);
|
|
|
+ Vector3 ndc = pos * (world_inv * _projection);
|
|
|
|
|
|
- return Vector3( (m_view_x + m_view_width * (ndc.x + 1.0f)) / 2.0f,
|
|
|
- (m_view_y + m_view_height * (ndc.y + 1.0f)) / 2.0f,
|
|
|
+ return Vector3( (_view_x + _view_width * (ndc.x + 1.0f)) / 2.0f,
|
|
|
+ (_view_y + _view_height * (ndc.y + 1.0f)) / 2.0f,
|
|
|
(ndc.z + 1.0f) / 2.0f);
|
|
|
}
|
|
|
|
|
|
void Camera::update_projection_matrix()
|
|
|
{
|
|
|
- switch (m_projection_type)
|
|
|
+ switch (_projection_type)
|
|
|
{
|
|
|
case ProjectionType::ORTHOGRAPHIC:
|
|
|
{
|
|
|
- matrix4x4::set_orthographic(m_projection, m_left, m_right, m_bottom, m_top, m_near, m_far);
|
|
|
+ matrix4x4::set_orthographic(_projection, _left, _right, _bottom, _top, _near, _far);
|
|
|
break;
|
|
|
}
|
|
|
case ProjectionType::PERSPECTIVE:
|
|
|
{
|
|
|
- matrix4x4::set_perspective(m_projection, m_FOV, m_aspect, m_near, m_far);
|
|
|
+ matrix4x4::set_perspective(_projection, _FOV, _aspect, _near, _far);
|
|
|
break;
|
|
|
}
|
|
|
default:
|
|
|
@@ -228,7 +228,7 @@ void Camera::update_projection_matrix()
|
|
|
void Camera::update_frustum()
|
|
|
{
|
|
|
// TODO
|
|
|
- //m_frustum.from_matrix(m_projection * m_view);
|
|
|
+ //m_frustum.from_matrix(_projection * m_view);
|
|
|
}
|
|
|
|
|
|
} // namespace crown
|