OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Viewport.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSG_VIEWPORT
15 #define OSG_VIEWPORT 1
16 
17 #include <osg/StateAttribute>
18 #include <osg/Matrix>
19 
20 namespace osg {
21 
24 {
25  public :
26 
27 #if 0
28  typedef int value_type;
29 #else
30  typedef double value_type;
31 #endif
32  Viewport();
33 
34  Viewport(value_type x,value_type y,value_type width,value_type height):
35  _x(x),
36  _y(y),
37  _width(width),
38  _height(height) {}
39 
40 
42  Viewport(const Viewport& vp,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
43  StateAttribute(vp,copyop),
44  _x(vp._x),
45  _y(vp._y),
46  _width(vp._width),
47  _height(vp._height) {}
48 
49  META_StateAttribute(osg, Viewport,VIEWPORT);
50 
52  virtual int compare(const StateAttribute& sa) const
53  {
54  // check the types are equal and then create the rhs variable
55  // used by the COMPARE_StateAttribute_Parameter macros below.
57 
58  // compare each parameter in turn against the rhs.
63 
64  return 0; // passed all the above comparison macros, must be equal.
65  }
66 
67  Viewport& operator = (const Viewport& rhs)
68  {
69  if (&rhs==this) return *this;
70 
71  _x = rhs._x;
72  _y = rhs._y;
73  _width = rhs._width;
74  _height = rhs._height;
75 
76  return *this;
77  }
78 
79  inline void setViewport(value_type x,value_type y,value_type width,value_type height)
80  {
81  _x = x;
82  _y = y;
83  _width = width;
84  _height = height;
85  }
86 
87 #if 0
88  void getViewport(int& x,int& y,int& width,int& height) const
89  {
90  x = _x;
91  y = _y;
92  width = _width;
93  height = _height;
94  }
95 
96  void getViewport(double& x,double& y,double& width,double& height) const
97  {
98  x = _x;
99  y = _y;
100  width = _width;
101  height = _height;
102  }
103 #endif
104  inline value_type& x() { return _x; }
105  inline value_type x() const { return _x; }
106 
107  inline value_type& y() { return _y; }
108  inline value_type y() const { return _y; }
109 
110  inline value_type& width() { return _width; }
111  inline value_type width() const { return _width; }
112 
113  inline value_type& height() { return _height; }
114  inline value_type height() const { return _height; }
115 
116  inline bool valid() const { return _width>0 && _height>0; }
117 
121  inline double aspectRatio() const { if (_height!=0) return (double)_width/(double)_height; else return 1.0; }
122 
129  inline const osg::Matrix computeWindowMatrix() const
130  {
131  return osg::Matrix::translate(1.0,1.0,1.0)*osg::Matrix::scale(0.5*width(),0.5*height(),0.5f)*osg::Matrix::translate(x(),y(),0.0f);
132  }
133 
134  virtual void apply(State& state) const;
135 
136  protected:
137 
138  virtual ~Viewport();
139 
140  value_type _x;
141  value_type _y;
142  value_type _width;
143  value_type _height;
144 
145 };
146 
147 }
148 
149 #endif
#define OSG_EXPORT
Definition: Export.h:43
value_type width() const
Definition: Viewport.h:111
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
static Matrixd translate(const Vec3f &dv)
Definition: Matrixd.h:469
value_type _x
Definition: Viewport.h:140
bool valid() const
Definition: Viewport.h:116
void setViewport(value_type x, value_type y, value_type width, value_type height)
Definition: Viewport.h:79
const osg::Matrix computeWindowMatrix() const
Definition: Viewport.h:129
value_type x() const
Definition: Viewport.h:105
value_type height() const
Definition: Viewport.h:114
value_type & x()
Definition: Viewport.h:104
double aspectRatio() const
Definition: Viewport.h:121
GLint GLenum GLsizei width
Definition: GLU.h:71
value_type & height()
Definition: Viewport.h:113
double value_type
Definition: Viewport.h:30
value_type y() const
Definition: Viewport.h:108
Viewport(value_type x, value_type y, value_type width, value_type height)
Definition: Viewport.h:34
#define META_StateAttribute(library, name, type)
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71
value_type & y()
Definition: Viewport.h:107
static Matrixd scale(const Vec3f &sv)
Definition: Matrixd.h:452
Definition: AlphaFunc.h:19
value_type _height
Definition: Viewport.h:143
value_type & width()
Definition: Viewport.h:110
#define COMPARE_StateAttribute_Parameter(parameter)
value_type _y
Definition: Viewport.h:141
virtual int compare(const StateAttribute &sa) const
Definition: Viewport.h:52
Viewport(const Viewport &vp, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition: Viewport.h:42
value_type _width
Definition: Viewport.h:142