|
|
#ifndef _XJV3D_VIEWER_
|
|
|
#define _XJV3D_VIEWER_
|
|
|
|
|
|
#include "ViewExport.h"
|
|
|
#include "XJObjectManager/XJObjectManager.h"
|
|
|
#include <osgViewer/Viewer>
|
|
|
#include <osg/Matrixd>
|
|
|
|
|
|
namespace OSGView
|
|
|
{
|
|
|
|
|
|
//ÆÁÄ»Éϵij¤·½ÐÎ
|
|
|
class ViewRect
|
|
|
{
|
|
|
public:
|
|
|
|
|
|
ViewRect()
|
|
|
{
|
|
|
x = 0;
|
|
|
y = 1;
|
|
|
width = height = 1;
|
|
|
}
|
|
|
|
|
|
ViewRect(int l, int b, int r, int t)
|
|
|
{
|
|
|
x = l;
|
|
|
y = b;
|
|
|
width = abs(r - l);
|
|
|
height = abs(t - b);
|
|
|
}
|
|
|
|
|
|
~ViewRect(){}
|
|
|
|
|
|
bool IsInsideRect(int pX, int pY)
|
|
|
{
|
|
|
if(pX > x && pX < x+width &&
|
|
|
pY > y && pY < y+height)
|
|
|
return true;
|
|
|
else
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
int x, y;
|
|
|
int width, height;
|
|
|
};
|
|
|
|
|
|
|
|
|
class XJOSGVIEWEXPORT XJV3D_Viewer : public osgViewer::Viewer
|
|
|
{
|
|
|
public:
|
|
|
XJV3D_Viewer(void);
|
|
|
~XJV3D_Viewer(void);
|
|
|
|
|
|
/** check to see if the new frame is required, called by run(..) when FrameScheme is set to ON_DEMAND.*/
|
|
|
virtual bool checkNeedToDoFrame();
|
|
|
|
|
|
//! Converts the projected point into a point
|
|
|
//! in the reference frame of the view corresponding
|
|
|
//! to the intersection with the projection plane
|
|
|
//! of the eye/view point vector.
|
|
|
void Convert(int x, int y, osg::Vec3& pnt) const;
|
|
|
|
|
|
//convert pt from world to window
|
|
|
void projecObjectIntoWindowXY(osg::Vec3 pnt, int& x, int& y);
|
|
|
|
|
|
/** Calculate, via glUnProject, the object coordinates of a window x,y
|
|
|
when projected onto the near planes.*/
|
|
|
void projectWindowXYIntoObject(int x, int y, osg::Vec3& pnt) const;
|
|
|
|
|
|
/** Calculate, via glUnProject, the object coordinates of a window x,y
|
|
|
when projected onto the near and far planes.
|
|
|
Note, current implementation requires that SceneView::draw() has been previously called
|
|
|
for projectWindowIntoObject to produce valid values. As per OpenGL
|
|
|
windows coordinates are calculated relative to the bottom left of the window.*/
|
|
|
bool projectWindowXYIntoObject(int x, int y, osg::Vec3d& near_point, osg::Vec3d& far_point, bool yInverse = true);
|
|
|
|
|
|
/** Calculate, via glUnProject, the object coordinates of a window x,y
|
|
|
when projected onto the near planes.*/
|
|
|
void projectWindowIntoObject(const osg::Vec3& windowPt, osg::Vec3& pnt) const;
|
|
|
|
|
|
//½«×ø±ê´Ó´°¿Ú×ø±êϵת»¯µ½¹éÒ»»¯Éè±¸×ø±êϵ£¨NDC£©
|
|
|
void projectWindowXYIntoProjection(int x, int y, osg::Vec3& projPnt) const;
|
|
|
|
|
|
/** Calculate, via glUnProject, the object coordinates of a window x,y
|
|
|
when projected onto the near planes.*/
|
|
|
void projectWindowXYIntoViewPoint(int x, int y, osg::Vec3& viewPortPt) const;
|
|
|
|
|
|
/** Calculate, via glUnProject, the object coordinates of a window x,y
|
|
|
when projected onto the near planes.*/
|
|
|
void ProjectViewpointIntoObject(const osg::Vec3& viewpoint, osg::Vec3& worldpt) const;
|
|
|
|
|
|
/** Calculate, via glUnProject, the object coordinates of a window x,y
|
|
|
when projected onto the near planes.*/
|
|
|
osg::Vec3 GetCameraNormal();
|
|
|
|
|
|
//get the viewport position and size
|
|
|
void GetViewRect(ViewRect& rect);
|
|
|
|
|
|
/** Get the const view matrix. */
|
|
|
const osg::Matrixd& getViewMatrix() const { return _camera->getViewMatrix(); }
|
|
|
|
|
|
/** Get the view matrix. */
|
|
|
osg::Matrixd& getViewMatrix() { return _camera->getViewMatrix(); }
|
|
|
|
|
|
/** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */
|
|
|
void getViewMatrixAsLookAt(osg::Vec3& eye,osg::Vec3& center,osg::Vec3& up,float lookDistance=1.0f) const;
|
|
|
|
|
|
/** Get the projection matrix.*/
|
|
|
osg::Matrixd& getProjectionMatrix() { return _camera->getProjectionMatrix(); }
|
|
|
|
|
|
/** Get the const projection matrix.*/
|
|
|
const osg::Matrixd& getProjectionMatrix() const { return _camera->getProjectionMatrix(); }
|
|
|
|
|
|
/** Get the orthographic settings of the orthographic projection matrix.
|
|
|
* Returns false if matrix is not an orthographic matrix, where parameter values are undefined.*/
|
|
|
bool getProjectionMatrixAsOrtho(double& left, double& right,
|
|
|
double& bottom, double& top,
|
|
|
double& zNear, double& zFar) const;
|
|
|
|
|
|
/** Get the frustum setting of a perspective projection matrix.
|
|
|
* Returns false if matrix is not a perspective matrix, where parameter values are undefined.*/
|
|
|
bool getProjectionMatrixAsFrustum(double& left, double& right,
|
|
|
double& bottom, double& top,
|
|
|
double& zNear, double& zFar) const;
|
|
|
|
|
|
/** Get the frustum setting of a symmetric perspective projection matrix.
|
|
|
* Returns false if matrix is not a perspective matrix, where parameter values are undefined.
|
|
|
* Note, if matrix is not a symmetric perspective matrix then the shear will be lost.
|
|
|
* Asymmetric matrices occur when stereo, power walls, caves and reality center display are used.
|
|
|
* In these configurations one should use the 'getProjectionMatrixAsFrustum' method instead.*/
|
|
|
bool getProjectionMatrixAsPerspective(double& fovy,double& aspectRatio,
|
|
|
double& zNear, double& zFar) const;
|
|
|
|
|
|
//get the near plane and far plane from eye
|
|
|
bool getNearAndFarPlaneDistance(double& nearDis, double& farDis);
|
|
|
|
|
|
//pan camera to cur window postion
|
|
|
void panCamera(const osg::Vec2 curpos);
|
|
|
|
|
|
//»ñȡͶӰ¾ØÕóÖеĿí¸ß±È
|
|
|
float getProjectionAspectRatio();
|
|
|
|
|
|
//scale Project Window(used for box zoom)
|
|
|
void ScaleProjectWindow(const float scale);
|
|
|
|
|
|
const osg::Matrix computeMVPWInverse() const;
|
|
|
|
|
|
const osg::Matrix computeMVPW() const;
|
|
|
|
|
|
const osg::Matrix computePW() const;
|
|
|
|
|
|
/** Get the viewport. */
|
|
|
osg::Viewport* getViewport() { return (_camera->getViewport()!=0) ? _camera->getViewport() : 0; }
|
|
|
|
|
|
/** Get the const viewport. */
|
|
|
const osg::Viewport* getViewport() const { return (_camera->getViewport()!=0) ? _camera->getViewport() : 0; }
|
|
|
|
|
|
//×ø±êµÄת»¯
|
|
|
static Point3D Vec3ToPoint3D(const osg::Vec3& value);
|
|
|
static osg::Vec3 Point3DToVec3(const Point3D& value);
|
|
|
};
|
|
|
|
|
|
} //end namespace
|
|
|
|
|
|
#endif
|
|
|
|