openscenegraph
Viewport
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
20namespace osg {
21
24{
25 public :
26
27#if 0
28 typedef int value_type;
29#else
30 typedef double value_type;
31#endif
33
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
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
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
144
145};
146
147}
148
149#endif
#define COMPARE_StateAttribute_Parameter(parameter)
Definition StateAttribute:69
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
Definition StateAttribute:57
Definition CopyOp:41
Definition Matrixd:27
static Matrixd scale(const Vec3f &sv)
Definition Matrixd:458
static Matrixd translate(const Vec3f &dv)
Definition Matrixd:475
Definition StateAttribute:77
Definition State:80
Definition Viewport:24
void setViewport(value_type x, value_type y, value_type width, value_type height)
Definition Viewport:79
value_type & y()
Definition Viewport:107
double value_type
Definition Viewport:30
value_type & width()
Definition Viewport:110
Viewport(const Viewport &vp, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition Viewport:42
value_type x() const
Definition Viewport:105
value_type & height()
Definition Viewport:113
double aspectRatio() const
Definition Viewport:121
value_type _y
Definition Viewport:141
virtual void apply(State &state) const
virtual ~Viewport()
value_type _width
Definition Viewport:142
value_type _height
Definition Viewport:143
const osg::Matrix computeWindowMatrix() const
Definition Viewport:129
value_type y() const
Definition Viewport:108
value_type height() const
Definition Viewport:114
value_type _x
Definition Viewport:140
Viewport(value_type x, value_type y, value_type width, value_type height)
Definition Viewport:34
value_type width() const
Definition Viewport:111
virtual int compare(const StateAttribute &sa) const
Definition Viewport:52
value_type & x()
Definition Viewport:104
META_StateAttribute(osg, Viewport, VIEWPORT)
bool valid() const
Definition Viewport:116
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
#define OSG_EXPORT
Definition osg/Export:39