Eclipse SUMO - Simulation of Urban MObility
GUIOSGPerspectiveChanger.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // Implementation of GUIPerspectiveChanger for OSG 3D views
19 /****************************************************************************/
20 #pragma once
21 #include <config.h>
22 
23 #include <utils/geom/Position.h>
25 #include "GUIOSGHeader.h"
26 #include "GUIOSGView.h"
27 
28 
29 // ===========================================================================
30 // class declarations
31 // ===========================================================================
32 class Boundary;
33 
35 public:
36 
37  /* Constructor
38  * @param[in] callBack The view to be udpated upon changes
39  */
40  GUIOSGPerspectiveChanger(GUIOSGView& callBack, const Boundary& viewPort);
41 
44 
46 
47  bool onLeftBtnRelease(void* data);
49 
51  bool onRightBtnRelease(void* data);
52 
54  bool onMiddleBtnRelease(void* data);
55 
57  void onMouseMove(void* data);
59 
61  double getRotation() const;
62 
64  double getXPos() const;
65 
67  double getYPos() const;
68 
70  double getZoom() const;
71 
73  double getZPos() const;
74 
76  double zoom2ZPos(double zoom) const;
77 
79  double zPos2Zoom(double zPos) const;
80 
82  void centerTo(const Position& pos, double radius, bool applyZoom = true);
83 
85  void setViewport(double zoom, double xPos, double yPos);
86 
88  void setViewportFrom(double xPos, double yPos, double zPos);
89 
91  void setRotation(double rotation);
92 
93  /* @brief Adapts the viewport so that a change in canvass size keeps most of the
94  * view intact (by showing more / less instead of zooming)
95  * The canvass is clipped/enlarged on the left side of the screen
96  *
97  * @param[in] change The horizontal change in canvas size in pixels
98  */
99  void changeCanvasSizeLeft(int change);
100 
102  void setViewport(const Boundary& viewPort);
103 
105  void updateViewport();
106 
107 private:
109  void updateViewport(osg::Vec3d& lookFrom);
110 
112  osg::Vec3d getPositionOnGround(double x, double y);
113 private:
116 
118  double myRotation;
119 
121  osg::ref_ptr<osgGA::TerrainManipulator> myCameraManipulator;
122 
125 
128 };
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
void setRotation(double rotation)
Sets the rotation.
double getYPos() const
Returns the y-offset of the field to show stored in this changer.
void updateViewport()
update the min/max coordinates of the view on the ground plane after changing the camera pos / direct...
GUIOSGPerspectiveChanger(GUIOSGView &callBack, const Boundary &viewPort)
void setViewportFrom(double xPos, double yPos, double zPos)
Alternative method for setting the viewport.
double getRotation() const
Returns the rotation of the canvas stored in this changer.
osg::Vec3d getPositionOnGround(double x, double y)
calculate the position on the ground (in world coordinates) given a normalised view coordinate (x,...
double getZPos() const
Returns the camera height corresponding to the current zoom factor.
double getXPos() const
Returns the x-offset of the field to show stored in this changer.
bool onMiddleBtnRelease(void *data)
called when user releases middle button
double zPos2Zoom(double zPos) const
Returns the zoom level that is achieved at a given camera height.
double myOrigWidth
the original viewport dimensions in m which serve as the reference point for 100% zoom
GUIOSGPerspectiveChanger & operator=(const GUIOSGPerspectiveChanger &)
Invalidated assignment operator.
bool onRightBtnRelease(void *data)
called when user releases right button
double zoom2ZPos(double zoom) const
Returns the camera height at which the given zoom level is reached.
osg::ref_ptr< osgGA::TerrainManipulator > myCameraManipulator
the OSG camera structure to gather the view coordinates
double myRotation
the current rotation
GUIOSGPerspectiveChanger(const GUIOSGPerspectiveChanger &)
Invalidated copy constructor.
void centerTo(const Position &pos, double radius, bool applyZoom=true)
Centers the view to the given position, setting it to a size that covers the radius....
bool onLeftBtnRelease(void *data)
mouse functions
void setViewport(double zoom, double xPos, double yPos)
Sets the viewport Used for: Adapting a new viewport.
double getZoom() const
Returns the zoom factor computed stored in this changer.
void onMouseMove(void *data)
called when user moves mouse
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37