34 GUIOSGView& callBack,
const Boundary& viewPort) :
36 myOrigWidth(viewPort.getWidth()),
37 myOrigHeight(viewPort.getHeight()),
80 osg::Vec3d lookFrom, lookAt, up;
88 osg::Vec3d lookFrom, lookAt, up;
96 osg::Vec3d lookFrom, lookAt, up;
130 osg::Vec3d lookFrom, lookAt, up, dir, orthoDir;
132 dir = lookAt - lookFrom;
134 if ((dir ^ osg::Z_AXIS).length() > 0) {
135 orthoDir[0] = -dir[1];
136 orthoDir[1] = dir[0];
139 orthoDir = -osg::X_AXIS;
142 orthoDir.normalize();
143 osg::Vec3d center(pos.
x(), pos.
y(), pos.
z());
144 osg::Vec3d leftBorder = center + orthoDir * radius;
146 double fovy, aspectRatio, zNear, zFar;
147 dynamic_cast<GUIOSGView&
>(
myCallback).myViewer->getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
148 double halfFovy =
DEG2RAD(.5 * fovy);
149 osg::Vec3d outerFov = dir * cos(halfFovy) + orthoDir * sin(halfFovy);
150 osg::Vec3d radiusVec = leftBorder - center;
151 int sign = ((outerFov ^ radiusVec) * (outerFov ^ dir) > 0) ? 1 : -1;
152 osg::Vec3d camUpdate = center + dir * sign * (outerFov ^ radiusVec).length() / (outerFov ^ dir).length();
155 dynamic_cast<GUIOSGView&
>(
myCallback).myViewer->home();
170 osg::Vec3d lookFrom, lookAt, up, dir;
172 dir = lookAt - lookFrom;
173 if ((dir.z() > 0. && lookFrom.z() >= 0.) || dir.z() == 0.) {
176 lookAt = lookFrom - osg::Vec3d(0., 0., 1.);
180 double factor = -lookFrom.z() / dir.z();
181 osg::Vec3d groundTarget = lookFrom + dir * factor;
182 shift[0] = xPos - groundTarget.x();
183 shift[1] = yPos - groundTarget.y();
188 m.makeLookAt(lookFrom, lookAt, up);
196 osg::Vec3d lookFrom, lookAt, up, dir;
208 double xMin, xMax, yMin, yMax;
209 xMin =
MIN4(bottomLeft.x(), bottomRight.x(), topLeft.x(), topRight.x());
210 xMax =
MAX4(bottomLeft.x(), bottomRight.x(), topLeft.x(), topRight.x());
211 yMin =
MIN4(bottomLeft.y(), bottomRight.y(), topLeft.y(), topRight.y());
212 yMax =
MAX4(bottomLeft.y(), bottomRight.y(), topLeft.y(), topRight.y());
219 osg::Matrix VP =
dynamic_cast<GUIOSGView&
>(
myCallback).myViewer->getCamera()->getViewMatrix() *
dynamic_cast<GUIOSGView&
>(
myCallback).myViewer->getCamera()->getProjectionMatrix();
220 osg::Matrix inverseVP;
221 inverseVP.invert(VP);
224 osg::Vec3d nearPoint(x, y, -1.);
225 osg::Vec3d farPoint(x, y, 1.);
226 osg::Vec3d nearPointWorld = nearPoint * inverseVP;
227 osg::Vec3d farPointWorld = farPoint * inverseVP;
230 osg::Vec3d ray = farPointWorld - nearPointWorld;
231 if (abs(ray.z()) > 0) {
232 return nearPointWorld + ray * (-nearPointWorld.z() / ray.z());
234 return osg::Vec3d(0., 0., 0.);
T MIN4(T a, T b, T c, T d)
T MAX4(T a, T b, T c, T d)
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.
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.
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.