33 GUIOSGView& callBack,
const Boundary& viewPort) :
35 myOrigWidth(viewPort.getWidth()),
36 myOrigHeight(viewPort.getHeight()),
69 osg::Vec3d lookFrom, lookAt, up;
77 osg::Vec3d lookFrom, lookAt, up;
85 osg::Vec3d lookFrom, lookAt, up;
119 osg::Vec3d lookFrom, lookAt, up, dir, orthoDir;
121 dir = lookAt - lookFrom;
123 if (dir * osg::Z_AXIS != 0) {
124 orthoDir = -osg::X_AXIS;
127 orthoDir[0] = -dir[1];
128 orthoDir[1] = dir[0];
131 orthoDir.normalize();
132 osg::Vec3d center(pos.
x(), pos.
y(), pos.
z());
133 osg::Vec3d leftBorder = center + orthoDir * radius;
135 double fovy, aspectRatio, zNear, zFar;
136 dynamic_cast<GUIOSGView&
>(
myCallback).myViewer->getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
137 double halfFovy =
DEG2RAD(.5 * fovy);
138 osg::Vec3d outerFov = dir * cos(halfFovy) + orthoDir * sin(halfFovy);
139 osg::Vec3d radiusVec = leftBorder - center;
140 int sign = ((outerFov ^ radiusVec) * (outerFov ^ dir) > 0) ? 1 : -1;
141 osg::Vec3d camUpdate = center + dir * sign * (outerFov ^ radiusVec).length() / (outerFov ^ dir).length();
144 dynamic_cast<GUIOSGView&
>(
myCallback).myViewer->home();
159 osg::Vec3d lookFrom, lookAt, up, dir;
161 dir = lookAt - lookFrom;
162 if ((dir.z() > 0. && lookFrom.z() >= 0.) || dir.z() == 0.) {
165 lookAt = lookFrom - osg::Vec3d(0., 0., 1.);
169 double factor = -lookFrom.z() / dir.z();
170 osg::Vec3d groundTarget = lookFrom + dir * factor;
171 shift[0] = xPos - groundTarget.x();
172 shift[1] = yPos - groundTarget.y();
177 m.makeLookAt(lookFrom, lookAt, up);
185 osg::Vec3d lookFrom, lookAt, up, dir;
195 myViewPort.
set(bottomLeft.x(), bottomLeft.y(), topRight.x(), topRight.y());
201 osg::Matrix VP =
dynamic_cast<GUIOSGView&
>(
myCallback).myViewer->getCamera()->getViewMatrix() *
dynamic_cast<GUIOSGView&
>(
myCallback).myViewer->getCamera()->getProjectionMatrix();
202 osg::Matrix inverseVP;
203 inverseVP.invert(VP);
206 osg::Vec3d nearPoint(x, y, -1.);
207 osg::Vec3d farPoint(x, y, 1.);
208 osg::Vec3d nearPointWorld = nearPoint * inverseVP;
209 osg::Vec3d farPointWorld = farPoint * inverseVP;
212 osg::Vec3d ray = farPointWorld - nearPointWorld;
213 if (abs(ray.z()) > 0) {
214 return nearPointWorld + ray * (-nearPointWorld.z() / ray.z());
216 return osg::Vec3d(0., 0., 0.);
A class that stores a 2D geometrical boundary.
Position getCenter() const
Returns the center of the boundary.
void set(double xmin, double ymin, double xmax, double ymax)
Sets the boundary to the given values.
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.
~GUIOSGPerspectiveChanger()
Destructor.
double zPos2Zoom(double zPos) const
Returns the zoom level that is achieved at a given camera height.
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
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....
void changeCanvasSizeLeft(int change)
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
GUISUMOAbstractView & myCallback
The parent window (canvas to scale)
Boundary myViewPort
the intended viewport
A point in 2D or 3D with translation and scaling methods.
double x() const
Returns the x-position.
double z() const
Returns the z-position.
double y() const
Returns the y-position.