Line data Source code
1 :
2 : /* Copyright (c) 2006-2011, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #ifndef EQFABRIC_WALL_H
20 : #define EQFABRIC_WALL_H
21 :
22 : #include <eq/fabric/api.h>
23 : #include <eq/fabric/types.h>
24 : #include <iostream>
25 :
26 : namespace eq
27 : {
28 : namespace fabric
29 : {
30 : /**
31 : * A wall defining a view frustum.
32 : *
33 : * The three points describe the bottom left, bottom right and top left
34 : * coordinate of the wall in real-world coordinates (meters).
35 : */
36 1436 : class Wall
37 : {
38 : public:
39 : /** Construct a new wall description. */
40 : EQFABRIC_API Wall();
41 :
42 : /** Construct a new wall description with default values. */
43 : EQFABRIC_API Wall( const Vector3f& bottomLeft,
44 : const Vector3f& bottomRight,
45 : const Vector3f& topLeft );
46 :
47 : /**
48 : * Resize the wall horizontally.
49 : *
50 : * @param ratio the amount by which the wall is grown or shrunk.
51 : * @version 1.0
52 : */
53 : EQFABRIC_API void resizeHorizontal( const float ratio );
54 :
55 : /**
56 : * Resize the wall vertically.
57 : *
58 : * @param ratio the amount by which the wall is grown or shrunk.
59 : * @version 1.0
60 : */
61 : EQFABRIC_API void resizeVertical( const float ratio );
62 :
63 : /**
64 : * Resize the wall on the left side.
65 : *
66 : * @param ratio the amount by which the wall is grown or shrunk.
67 : * @version 1.0
68 : */
69 : EQFABRIC_API void resizeLeft( const float ratio );
70 :
71 : /**
72 : * Resize the wall on the right side.
73 : *
74 : * @param ratio the amount by which the wall is grown or shrunk.
75 : * @version 1.0
76 : */
77 : EQFABRIC_API void resizeRight( const float ratio );
78 :
79 : /**
80 : * Resize the wall on the top side.
81 : *
82 : * @param ratio the amount by which the wall is grown or shrunk.
83 : * @version 1.0
84 : */
85 : EQFABRIC_API void resizeTop( const float ratio );
86 :
87 : /**
88 : * Resize the wall on the bottom side.
89 : *
90 : * @param ratio the amount by which the wall is grown or shrunk.
91 : * @version 1.0
92 : */
93 : EQFABRIC_API void resizeBottom( const float ratio );
94 :
95 : /**
96 : * Resize the wall horizontally to match the given aspect ratio.
97 : *
98 : * @param aspectRatio the destination aspect ratio.
99 : * @version 1.1.2
100 : */
101 : EQFABRIC_API void resizeHorizontalToAR( const float aspectRatio );
102 :
103 : /**
104 : * Resize the wall by the given ratio as observed from the eye position.
105 : *
106 : * Each wall corner is moved by ratio along the vector eye -> wall
107 : * corner.
108 : *
109 : * @param eye the observer position
110 : * @param ratio the relative ratio to the current position
111 : * @version 1.1
112 : */
113 : EQFABRIC_API void moveFocus( const Vector3f& eye, const float ratio );
114 :
115 : /**
116 : * Compute the sub-frustum for a 2D area on the full wall.
117 : * @version 1.0
118 : */
119 : EQFABRIC_API void apply( const Viewport& viewport);
120 :
121 : /**
122 : * Move each wall corner by the given ratio.
123 : * @version 1.3.1
124 : */
125 : EQFABRIC_API void scale( const float ratio );
126 :
127 : /**
128 : * Set the wall parameters from a projection description.
129 : * @version 1.0
130 : */
131 : EQFABRIC_API Wall& operator = ( const Projection& projection );
132 :
133 : /**
134 : * Set the wall parameters from an inverse projection matrix.
135 : * @version 1.5.2
136 : */
137 : EQFABRIC_API Wall& operator = ( const Matrix4f& xfm );
138 :
139 : /** @return the width of the wall. @version 1.0 */
140 1 : float getWidth() const { return (bottomRight - bottomLeft).length(); }
141 :
142 : /** @return the height of the wall. @version 1.0 */
143 1 : float getHeight() const { return (topLeft - bottomLeft).length(); }
144 :
145 : /** @return true if the two walls are identical. @version 1.0 */
146 : EQFABRIC_API bool operator == ( const Wall& rhs ) const;
147 :
148 : /** @return true if the two walls are not identical. @version 1.0 */
149 : EQFABRIC_API bool operator != ( const Wall& rhs ) const;
150 :
151 : /** @return the horizontal vector. @version 1.1 */
152 0 : Vector3f getU() const { return bottomRight - bottomLeft; }
153 :
154 : /** @return the vertical vector. @version 1.1 */
155 0 : Vector3f getV() const { return topLeft - bottomLeft; }
156 :
157 : /** @return the perpendicular vector. @version 1.1 */
158 0 : Vector3f getW() const { return getU().cross( getV( )); }
159 :
160 : Vector3f bottomLeft; //!< The bottom-left corner
161 : Vector3f bottomRight; //!< The bottom-right corner
162 : Vector3f topLeft; //!< The top-left corner
163 :
164 : /** The reference system type of the wall. */
165 : enum Type
166 : {
167 : TYPE_FIXED, //!< A fixed mounted projection wall
168 : TYPE_HMD //!< A wall fixed to the observer (head-mounted display)
169 : };
170 : Type type; //!< The wall type
171 : };
172 :
173 : EQFABRIC_API std::ostream& operator << ( std::ostream&, const Wall& );
174 : EQFABRIC_API std::ostream& operator << ( std::ostream&, const Wall::Type& );
175 : }
176 : }
177 :
178 : namespace lunchbox
179 : {
180 0 : template<> inline void byteswap( eq::fabric::Wall::Type& value )
181 : {
182 0 : byteswap( reinterpret_cast< uint32_t& >( value ));
183 0 : }
184 :
185 0 : template<> inline void byteswap( eq::fabric::Wall& value )
186 : {
187 0 : byteswap( value.bottomLeft );
188 0 : byteswap( value.bottomRight );
189 0 : byteswap( value.topLeft );
190 0 : byteswap( value.type );
191 0 : }
192 : }
193 : #endif // EQFABRIC_WALL_H
|