added method to get Projection matrix given near and far.
This commit is contained in:
parent
f16b821dc0
commit
0ac7034397
|
@ -206,6 +206,9 @@ public:
|
|||
inline void SetFrustum(S dx, S sx, S bt, S tp, S Focal, vcg::Point2<int> Viewport);
|
||||
//------------------
|
||||
|
||||
/// returns the projection matrix
|
||||
vcg::Matrix44<S> GetMatrix(S nearVal, S farVal);
|
||||
|
||||
/// returns the frustum
|
||||
inline void GetFrustum(S & sx, S & dx, S & bt, S & tp, S & nr);
|
||||
|
||||
|
@ -270,6 +273,41 @@ vcg::Point2<S> Camera<S>::Project(const vcg::Point3<S> & p) const
|
|||
return q;
|
||||
}
|
||||
|
||||
template <class S> vcg::Matrix44<S> Camera<S>::GetMatrix(S nearVal, S farVal) {
|
||||
S left, right, bottom, top, nr;
|
||||
GetFrustum(left, right, bottom,top, nr);
|
||||
|
||||
if(cameraType == PERSPECTIVE) {
|
||||
S ratio = nearVal/nr;
|
||||
left *= ratio;
|
||||
right *= ratio;
|
||||
bottom *= ratio;
|
||||
top *= ratio;
|
||||
}
|
||||
vcg::Matrix44<S> m;
|
||||
m[0][0] = 2.0*nearVal/(right - left);
|
||||
m[0][1] = 0;
|
||||
m[0][2] = (right + left)/(right - left);
|
||||
m[0][3] = 0;
|
||||
|
||||
m[1][0] = 0;
|
||||
m[1][1] = 2*nearVal/(top - bottom);
|
||||
m[1][2] = (top + bottom)/(top - bottom);
|
||||
m[1][3] = 0;
|
||||
|
||||
m[2][0] = 0;
|
||||
m[2][1] = 0;
|
||||
m[2][2] = -(farVal + nearVal)/(farVal - nearVal);
|
||||
m[2][3] = - 2*farVal*nearVal/(farVal - nearVal);
|
||||
|
||||
m[3][0] = 0;
|
||||
m[3][1] = 0;
|
||||
m[3][2] = -1;
|
||||
m[3][3] = 0;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/// unproject a point from the camera 2d plane [-1,-1]x[1,1] (plus depth) to 3d CAMERA space
|
||||
template<class S>
|
||||
vcg::Point3<S> Camera<S>::UnProject(const vcg::Point2<S> & p, const S & d) const
|
||||
|
@ -358,7 +396,7 @@ vcg::Point2<S> Camera<S>::LocalTo_neg1_1(const vcg::Point2<S> & p) const
|
|||
/// transforms an undistorted 2D camera plane point in a distorted 2D camera plane point
|
||||
template<class Scalar>
|
||||
vcg::Point2<Scalar> Camera<Scalar>::UndistortedToDistorted(vcg::Point2<Scalar> u) const
|
||||
{
|
||||
{
|
||||
vcg::Point2<Scalar> dis;
|
||||
vcg::Point2<Scalar> dc=ViewportPxTo_neg1_1(DistorCenterPx);
|
||||
const Scalar SQRT3 = Scalar(1.732050807568877293527446341505872366943);
|
||||
|
@ -417,12 +455,12 @@ vcg::Point2<Scalar> Camera<Scalar>::UndistortedToDistorted(vcg::Point2<Scalar>
|
|||
dis[1] = u[1] * lambda;
|
||||
|
||||
return dis;
|
||||
}
|
||||
}
|
||||
|
||||
/// transforms a distorted 2D camera plane point in an undistorted 2D camera plane point
|
||||
template<class S>
|
||||
vcg::Point2<S> Camera<S>::DistortedToUndistorted(vcg::Point2<S> d) const
|
||||
{
|
||||
{
|
||||
vcg::Point2<S> u;
|
||||
vcg::Point2<S> dc=ViewportPxTo_neg1_1(DistorCenterPx);
|
||||
S r=sqrt(pow((d[0]-dc[0]),2)+pow((d[1]-dc[1]),2));
|
||||
|
@ -431,7 +469,7 @@ vcg::Point2<S> Camera<S>::DistortedToUndistorted(vcg::Point2<S> d) const
|
|||
|
||||
return u;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--- basic camera setup (GL-like)
|
||||
|
|
Loading…
Reference in New Issue