zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Projector.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
60 #ifndef ZENI_PROJECTOR_H
61 #define ZENI_PROJECTOR_H
62 
63 #include <Zeni/Camera.h>
64 #include <Zeni/Coordinate.h>
65 #include <Zeni/Vector3f.h>
66 #include <Zeni/Matrix4f.h>
67 #include <Zeni/Video.h>
68 
69 namespace Zeni {
70 
71  class ZENI_GRAPHICS_DLL Projector {
72  protected:
73  inline Projector(const std::pair<Point2i, Point2i> &viewport = std::make_pair(Point2i(), get_Video().get_render_target_size()));
74  inline ~Projector();
75 
76  inline void init(const std::pair<Point2i, Point2i> &viewport);
77 
78  inline const Vector3f & offset() const;
79  inline const Vector3f & size() const;
80 
81  private:
82  Vector3f m_offset;
83  Vector3f m_size;
84  };
85 
86  class ZENI_GRAPHICS_DLL Projector2D : public Projector {
87  public:
88  inline Projector2D(
89  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))),
90  const std::pair<Point2i, Point2i> &viewport = std::make_pair(Point2i(), get_Video().get_render_target_size()));
91 
92  inline Vector3f project(const Vector3f &world_coord) const;
93  inline Point3f project(const Point3f &world_coord) const;
94  inline Point2f project(const Point2f &world_coord) const;
95 
96  inline Vector3f unproject(const Vector3f &screen_coord) const;
97  inline Point3f unproject(const Point3f &screen_coord) const;
98  inline Point2f unproject(const Point2f &screen_coord) const;
99 
100  private:
101  inline void init(
102  const std::pair<Point2f, Point2f> &camera2d,
103  const std::pair<Point2i, Point2i> &viewport);
104 
105  Matrix4f m_world_to_screen;
106  Matrix4f m_screen_to_world;
107  };
108 
109  class ZENI_GRAPHICS_DLL Projector3D : public Projector {
110  public:
111  inline Projector3D(
112  const Camera &camera3d = Camera(),
113  const std::pair<Point2i, Point2i> &viewport = std::make_pair(Point2i(), get_Video().get_render_target_size()));
114 
115  inline Vector3f project(const Vector3f &world_coord) const;
116  inline Point3f project(const Point3f &world_coord) const;
117 
118  inline Vector3f unproject(const Vector3f &screen_coord) const;
119  inline Point3f unproject(const Point3f &screen_coord) const;
120 
121  private:
122  inline void init(
123  const Camera &camera3d,
124  const std::pair<Point2i, Point2i> &viewport);
125 
126  Matrix4f m_world_to_camera;
127  Matrix4f m_camera_to_world;
128 
129  Vector3f m_uln;
130  Vector3f m_uln2lrf;
131 
132  float m_near2far;
133  };
134 
135 }
136 
137 #endif
Projector Base Class.
Definition: Projector.h:71
Camera / Point of View.
Definition: Camera.h:49
GLclampf f
Definition: glew.h:3390
EGLSurface EGLint x
Definition: eglext.h:293
static void init(struct bs2b *bs2b)
Definition: bs2b.c:46
A 3D Point represented with floats.
Definition: Coordinate.h:133
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
The 3D Projector.
Definition: Projector.h:109
The 2D Projector.
Definition: Projector.h:86
EGLSurface EGLint EGLint y
Definition: eglext.h:293
GLintptr offset
Definition: glew.h:1668
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
A Featureful 4-Space Matrix Class.
Definition: Matrix4f.h:47
A 2D Point represented with floats.
Definition: Coordinate.h:98
GLsizei size
Definition: gl2ext.h:1467
A 2D Point represented with integers.
Definition: Coordinate.h:85