18 #ifndef ZENI_PROJECTOR_HXX
19 #define ZENI_PROJECTOR_HXX
43 m_offset =
Vector3f(
float(viewport.first.x),
float(viewport.first.y), 0.0f);
44 m_size =
Vector3f(
float(viewport.second.x - viewport.first.x),
float(viewport.second.y - viewport.first.y), 1.0f);
56 const std::pair<Point2f, Point2f> &camera2d,
57 const std::pair<Point2i, Point2i> &viewport)
59 init(camera2d, viewport);
63 return m_world_to_screen * world_coord;
75 return m_screen_to_world * screen_coord;
86 void Projector2D::init(
87 const std::pair<Point2f, Point2f> &camera2d,
88 const std::pair<Point2i, Point2i> &viewport)
93 Matrix4f::Orthographic(
float(viewport.first.x),
float(viewport.second.x),
float(viewport.second.y),
float(viewport.first.y), -1.0f, 1.0f).
inverted() *
94 Matrix4f::Orthographic(camera2d.first.x, camera2d.second.x, camera2d.second.y, camera2d.first.y, -1.0f, 1.0f);
96 m_screen_to_world = m_world_to_screen.
inverted();
101 const std::pair<Point2i, Point2i> &viewport)
103 init(camera3d, viewport);
107 const float z_value = (
Vector3f(m_world_to_camera * world_coord - m_uln).
divide_by(m_uln2lrf)).
k;
108 const float scale = z_value * m_near2far + 1.0f - z_value;
109 return (((m_world_to_camera * world_coord).divide_by(
Vector3f(scale, scale, 1.0
f)) - m_uln).divide_by(m_uln2lrf)).multiply_by(
size()) +
offset();
117 const float scale = screen_coord.
k * m_near2far + 1.0f - screen_coord.
k;
118 return m_camera_to_world * ((screen_coord -
offset()).divide_by(
size()).multiply_by(m_uln2lrf) + m_uln).multiply_by(
Vector3f(scale, scale, 1.0
f));
125 void Projector3D::init(
127 const std::pair<Point2i, Point2i> &viewport)
132 m_camera_to_world = m_world_to_camera.
inverted();
143 m_uln =
Vector3f(left, top, -tunneled_near_clip);
144 m_uln2lrf =
Vector3f(right, bottom, -tunneled_far_clip) - m_uln;
146 m_near2far = tunneled_far_clip / tunneled_near_clip;
Vector3f project(const Vector3f &world_coord) const
Map coordinates in the viewing frustum to screen coordinates ([viewport.first.x, viewport.second.x], [viewport.first.y, viewport.second.y], [0, 1])
Vector3f unproject(const Vector3f &screen_coord) const
Map screen coordinates ([viewport.first.x, viewport.second.x], [viewport.first.y, viewport...
const Vector3f & offset() const
Vector3f divide_by(const Vector3f &rhs) const
Divide corresponding members.
Projector3D(const Camera &camera3d=Camera(), const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get_Video().get_render_target_size()))
A 3D Point represented with floats.
A Featureful 3-Space Vector Class.
void init(const std::pair< Point2i, Point2i > &viewport)
static Matrix4f Orthographic(const float &left, const float &right, const float &bottom, const float &top, const float &near, const float &far)
Similar to gluOrtho.
GLfloat GLfloat GLfloat top
GLenum GLenum GLenum GLenum GLenum scale
const Vector3f & size() const
Vector3f unproject(const Vector3f &screen_coord) const
Map screen coordinates ([viewport.first.x, viewport.second.x], [viewport.first.y, viewport...
float get_tunneled_near_clip() const
Get the near clip shifted by tunnel vision.
float get_tunneled_far_clip() const
Get the far clip shifted by tunnel vision.
Projector(const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get_Video().get_render_target_size()))
Matrix4f inverted() const
Get the inverse.
Projector2D(const std::pair< Point2f, Point2f > &camera2d=std::make_pair(Point2f(0.0f, 0.0f), Point2f(float(get_Video().get_render_target_size().x), float(get_Video().get_render_target_size().y))), const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get_Video().get_render_target_size()))
Matrix4f get_view_matrix() const
Equivalent to gluLookAt + tunnel_vision_factor.
A 2D Point represented with floats.
Vector3f project(const Vector3f &world_coord) const
Map coordinates in the viewing area to screen coordinates ([viewport.first.x, viewport.second.x], [viewport.first.y, viewport.second.y], [-1, 1])