*** empty log message ***
This commit is contained in:
parent
45154f0716
commit
02aee67598
|
@ -23,6 +23,8 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
History
|
History
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
<<<<<<< camera.h
|
||||||
|
=======
|
||||||
Revision 1.8 2004/11/23 10:15:38 cignoni
|
Revision 1.8 2004/11/23 10:15:38 cignoni
|
||||||
removed comment in comment gcc warning
|
removed comment in comment gcc warning
|
||||||
|
|
||||||
|
@ -32,6 +34,7 @@ Point?.h to point?.h
|
||||||
Revision 1.6 2004/11/03 09:32:50 ganovelli
|
Revision 1.6 2004/11/03 09:32:50 ganovelli
|
||||||
SetPerspective and SetFrustum added (same parameters as in opengl)
|
SetPerspective and SetFrustum added (same parameters as in opengl)
|
||||||
|
|
||||||
|
>>>>>>> 1.8
|
||||||
Revision 1.4 2004/10/07 14:39:57 fasano
|
Revision 1.4 2004/10/07 14:39:57 fasano
|
||||||
Remove glew.h include
|
Remove glew.h include
|
||||||
|
|
||||||
|
@ -57,8 +60,8 @@ creation
|
||||||
#define __VCGLIB_CAMERA
|
#define __VCGLIB_CAMERA
|
||||||
|
|
||||||
// VCG
|
// VCG
|
||||||
#include <vcg/space/point3.h>
|
#include <vcg/space/Point3.h>
|
||||||
#include <vcg/space/point2.h>
|
#include <vcg/space/Point2.h>
|
||||||
#include <vcg/math/similarity.h>
|
#include <vcg/math/similarity.h>
|
||||||
|
|
||||||
namespace vcg{
|
namespace vcg{
|
||||||
|
@ -79,6 +82,7 @@ public:
|
||||||
S farend; // farend end of frustum (it doesn influence the projection )
|
S farend; // farend end of frustum (it doesn influence the projection )
|
||||||
vcg::Point2<S> s; // Scale factor of the image (nei casi in cui a senso)
|
vcg::Point2<S> s; // Scale factor of the image (nei casi in cui a senso)
|
||||||
vcg::Point2<S> c; // pin-hole position
|
vcg::Point2<S> c; // pin-hole position
|
||||||
|
|
||||||
vcg::Point2<int> viewport; // Size viewport (in pixels)
|
vcg::Point2<int> viewport; // Size viewport (in pixels)
|
||||||
S k[4]; // 1st & 2nd order radial lens distortion coefficient
|
S k[4]; // 1st & 2nd order radial lens distortion coefficient
|
||||||
|
|
||||||
|
@ -95,14 +99,15 @@ public:
|
||||||
char & UberFlags() {return _flags;}
|
char & UberFlags() {return _flags;}
|
||||||
|
|
||||||
/// set the camera specifying the perspecive view
|
/// set the camera specifying the perspecive view
|
||||||
inline void SetPerspective(S angle, S ratio, S nearend, S farend,vcg::Point2<S> viewport=vcg::Point2<S>(500,-1) );
|
inline void SetPerspective(S angle, S ratio, S near, S farend,vcg::Point2<S> viewport=vcg::Point2<S>(500,-1) );
|
||||||
|
|
||||||
/// set the camera specifying the frustum view
|
/// set the camera specifying the frustum view
|
||||||
inline void SetFrustum(S dx, S sx, S bt, S tp, S nearend, S farend,vcg::Point2<S> viewport=vcg::Point2<S>(500,-1));
|
inline void SetFrustum(S dx, S sx, S bt, S tp, S near, S farend,vcg::Point2<S> viewport=vcg::Point2<S>(500,-1));
|
||||||
|
|
||||||
/// project a point from space 3d (in the reference system of the camera) to the camera's plane
|
/// project a point from space 3d (in the reference system of the camera) to the camera's plane
|
||||||
/// the result is in absolute coordinates
|
/// the result is in absolute coordinates
|
||||||
inline vcg::Point2<S> Project(const vcg::Point3<S> & p);
|
inline vcg::Point2<S> Project(const vcg::Point3<S> & p);
|
||||||
|
inline vcg::Point3<S> UnProject(const vcg::Point2<S> & p);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// project a point in the camera plane
|
/// project a point in the camera plane
|
||||||
|
@ -132,19 +137,38 @@ vcg::Point2<S> Camera<S>::Project(const vcg::Point3<S> & p){
|
||||||
}
|
}
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
/// unproject a point from the camera plane
|
||||||
|
template<class S>
|
||||||
|
vcg::Point3<S> Camera<S>::UnProject(const vcg::Point2<S> & p){
|
||||||
|
S tx = p.X();
|
||||||
|
S ty = p.Y();
|
||||||
|
|
||||||
/// set the camera specifying the perspecive view
|
vcg::Point3<S> q(0,0,0);
|
||||||
template<class S>
|
|
||||||
void Camera<S>::SetPerspective(S angle, S ratio, S nr, S _farend,vcg::Point2<S> vp){
|
if(!IsOrtho())
|
||||||
|
{
|
||||||
|
tx = (tx-c.X())*s.X();
|
||||||
|
ty = (tx-c.Y())*s.Y();
|
||||||
|
|
||||||
|
q[0] = tx/f;
|
||||||
|
q[1] = ty/f;
|
||||||
|
q[2] = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return q;
|
||||||
|
}
|
||||||
|
/// set the camera specifying the perspective view
|
||||||
|
template<class S>
|
||||||
|
void Camera<S>::SetPerspective(S angle, S ratio, S nr, S _far,vcg::Point2<S> vp){
|
||||||
S halfsize[2];
|
S halfsize[2];
|
||||||
halfsize[1] = tan(math::ToRad(angle/2)) * nr;
|
halfsize[1] = tan(math::ToRad(angle/2)) * nr;
|
||||||
halfsize[0] = halfsize[1]*ratio;
|
halfsize[0] = halfsize[1]*ratio;
|
||||||
SetFrustum(-halfsize[0],halfsize[0],-halfsize[1],halfsize[1],nr,_farend,vp);
|
SetFrustum(-halfsize[0],halfsize[0],-halfsize[1],halfsize[1],nr,_far,vp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// set the camera specifying the frustum view
|
/// set the camera specifying the frustum view
|
||||||
template<class S>
|
template<class S>
|
||||||
void Camera<S>::SetFrustum(S sx, S dx, S bt, S tp, S nr, S _farend,vcg::Point2<S> vp){
|
void Camera<S>::SetFrustum(S sx, S dx, S bt, S tp, S nr, S _far,vcg::Point2<S> vp){
|
||||||
S vpt[2];
|
S vpt[2];
|
||||||
vpt[0] = dx-sx;
|
vpt[0] = dx-sx;
|
||||||
vpt[1] = tp-bt;
|
vpt[1] = tp-bt;
|
||||||
|
@ -162,7 +186,7 @@ vcg::Point2<S> Camera<S>::Project(const vcg::Point3<S> & p){
|
||||||
c[1] = -bt/vpt[1] * viewport[1];
|
c[1] = -bt/vpt[1] * viewport[1];
|
||||||
|
|
||||||
f =nr;
|
f =nr;
|
||||||
farend = _farend;
|
farend = _far;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.21 2004/10/22 14:41:30 ponchio
|
||||||
|
return in operator+ added.
|
||||||
|
|
||||||
Revision 1.20 2004/10/18 15:03:14 fiorin
|
Revision 1.20 2004/10/18 15:03:14 fiorin
|
||||||
Updated interface: all Matrix classes have now the same interface
|
Updated interface: all Matrix classes have now the same interface
|
||||||
|
|
||||||
|
@ -193,8 +196,10 @@ public:
|
||||||
void operator*=( const Matrix44 & m );
|
void operator*=( const Matrix44 & m );
|
||||||
void operator*=( const T k );
|
void operator*=( const T k );
|
||||||
|
|
||||||
void ToMatrix(Matrix44 & m) const {for(int i = 0; i < 16; i++) m.V()[i]=V()[i];}
|
template <class Matrix44Type>
|
||||||
void FromMatrix(const Matrix44 & m){for(int i = 0; i < 16; i++) V()[i]=m.V()[i];}
|
void ToMatrix(Matrix44Type & m) const {for(int i = 0; i < 16; i++) m.V()[i]=V()[i];}
|
||||||
|
template <class Matrix44Type>
|
||||||
|
void FromMatrix(const Matrix44Type & m){for(int i = 0; i < 16; i++) V()[i]=m.V()[i];}
|
||||||
void SetZero();
|
void SetZero();
|
||||||
void SetIdentity();
|
void SetIdentity();
|
||||||
void SetDiagonal(const T k);
|
void SetDiagonal(const T k);
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.9 2004/10/22 14:35:42 ponchio
|
||||||
|
m.element(x, y) -> m[x][y]
|
||||||
|
|
||||||
Revision 1.8 2004/10/07 13:54:03 ganovelli
|
Revision 1.8 2004/10/07 13:54:03 ganovelli
|
||||||
added SetIdentity
|
added SetIdentity
|
||||||
|
|
||||||
|
@ -32,6 +35,9 @@ updated access to matrix44 elements through V() instead simple []
|
||||||
|
|
||||||
Revision 1.6 2004/03/25 14:57:49 ponchio
|
Revision 1.6 2004/03/25 14:57:49 ponchio
|
||||||
Microerror. ($LOG$ -> $Log: not supported by cvs2svn $
|
Microerror. ($LOG$ -> $Log: not supported by cvs2svn $
|
||||||
|
Microerror. ($LOG$ -> Revision 1.9 2004/10/22 14:35:42 ponchio
|
||||||
|
Microerror. ($LOG$ -> m.element(x, y) -> m[x][y]
|
||||||
|
Microerror. ($LOG$ ->
|
||||||
Microerror. ($LOG$ -> Revision 1.8 2004/10/07 13:54:03 ganovelli
|
Microerror. ($LOG$ -> Revision 1.8 2004/10/07 13:54:03 ganovelli
|
||||||
Microerror. ($LOG$ -> added SetIdentity
|
Microerror. ($LOG$ -> added SetIdentity
|
||||||
Microerror. ($LOG$ ->
|
Microerror. ($LOG$ ->
|
||||||
|
@ -191,6 +197,27 @@ template <class S> void Quaternion<S>::ToMatrix(Matrix44<S> &m) const {
|
||||||
S q22 = V(3)*V(3);
|
S q22 = V(3)*V(3);
|
||||||
S q23 = V(3)*V(0);
|
S q23 = V(3)*V(0);
|
||||||
|
|
||||||
|
/* <<<<<<< quaternion.h
|
||||||
|
m[0][ 0] = (S)(1.0-(q11 + q22)*2.0);
|
||||||
|
m[1][ 0] = (S)((q01 - q23)*2.0);
|
||||||
|
m[2][ 0] = (S)((q02 + q13)*2.0);
|
||||||
|
m[3][ 0] = (S)0.0;
|
||||||
|
|
||||||
|
m[0][ 1] = (S)((q01 + q23)*2.0);
|
||||||
|
m[1][ 1] = (S)(1.0-(q22 + q00)*2.0);
|
||||||
|
m[2][ 1] = (S)((q12 - q03)*2.0);
|
||||||
|
m[3][ 1] = (S)0.0;
|
||||||
|
|
||||||
|
m[0][ 2] = (S)((q02 - q13)*2.0);
|
||||||
|
m[1][ 2] = (S)((q12 + q03)*2.0);
|
||||||
|
m[2][ 2] = (S)(1.0-(q11 + q00)*2.0);
|
||||||
|
m[3][ 2] = (S)0.0;
|
||||||
|
|
||||||
|
m[0][ 3] = (S)0.0;
|
||||||
|
m[1][ 3] = (S)0.0;
|
||||||
|
m[2][ 3] = (S)0.0;
|
||||||
|
m[3][ 3] = (S)1.0;
|
||||||
|
=======*/
|
||||||
m[0][0] = (S)(1.0-(q11 + q22)*2.0);
|
m[0][0] = (S)(1.0-(q11 + q22)*2.0);
|
||||||
m[1][0] = (S)((q01 - q23)*2.0);
|
m[1][0] = (S)((q01 - q23)*2.0);
|
||||||
m[2][0] = (S)((q02 + q13)*2.0);
|
m[2][0] = (S)((q02 + q13)*2.0);
|
||||||
|
@ -210,6 +237,7 @@ template <class S> void Quaternion<S>::ToMatrix(Matrix44<S> &m) const {
|
||||||
m[1][3] = (S)0.0;
|
m[1][3] = (S)0.0;
|
||||||
m[2][3] = (S)0.0;
|
m[2][3] = (S)0.0;
|
||||||
m[3][3] = (S)1.0;
|
m[3][3] = (S)1.0;
|
||||||
|
//>>>>>>> 1.9
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,15 +23,6 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
History
|
History
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
Revision 1.7 2004/11/23 10:15:38 cignoni
|
|
||||||
removed comment in comment gcc warning
|
|
||||||
|
|
||||||
Revision 1.6 2004/11/03 09:25:52 ganovelli
|
|
||||||
replaced Matrix44f to Matrix44<S>, added LookAt
|
|
||||||
|
|
||||||
Revision 1.5 2004/10/22 14:29:40 ponchio
|
|
||||||
#include <...Point --> #include <...point
|
|
||||||
|
|
||||||
Revision 1.4 2004/10/07 14:41:31 fasano
|
Revision 1.4 2004/10/07 14:41:31 fasano
|
||||||
Little fix on ViewPoint() method
|
Little fix on ViewPoint() method
|
||||||
|
|
||||||
|
@ -50,14 +41,17 @@ Revision 1.2 2004/09/06 21:41:30 ganovelli
|
||||||
Revision 1.1 2004/09/03 13:01:51 ganovelli
|
Revision 1.1 2004/09/03 13:01:51 ganovelli
|
||||||
creation
|
creation
|
||||||
|
|
||||||
****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __VCGLIB_SHOT
|
#ifndef __VCGLIB_SHOT
|
||||||
#define __VCGLIB_SHOT
|
#define __VCGLIB_SHOT
|
||||||
|
|
||||||
#include <vcg/space/point2.h>
|
// #include <vector>
|
||||||
#include <vcg/space/point3.h>
|
// #include <vcg/Matrix44.h>
|
||||||
|
// #include <vcg/Box3.h>
|
||||||
|
#include <vcg/space/Point2.h>
|
||||||
|
#include <vcg/space/Point3.h>
|
||||||
#include <vcg/math/similarity.h>
|
#include <vcg/math/similarity.h>
|
||||||
#include <vcg/math/camera.h>
|
#include <vcg/math/camera.h>
|
||||||
|
|
||||||
|
@ -105,9 +99,14 @@ public:
|
||||||
/// convert a 3d point in camera coordinates
|
/// convert a 3d point in camera coordinates
|
||||||
vcg::Point3<S> ConvertToCameraCoordinates(const vcg::Point3<S> & p) const;
|
vcg::Point3<S> ConvertToCameraCoordinates(const vcg::Point3<S> & p) const;
|
||||||
|
|
||||||
|
/// convert a 3d point in camera coordinates
|
||||||
|
vcg::Point3<S> ConvertToWorldCoordinates(const vcg::Point3<S> & p) const;
|
||||||
|
|
||||||
/// project onto the camera plane
|
/// project onto the camera plane
|
||||||
vcg::Point2<S> Project(const vcg::Point3<S> & p) const;
|
vcg::Point2<S> Project(const vcg::Point3<S> & p) const;
|
||||||
|
|
||||||
|
vcg::Point3<S> UnProject(const vcg::Point2<S> & p) const;
|
||||||
|
|
||||||
/// take the distance from the point p and the plane parallel to the camera plane and passing through the view
|
/// take the distance from the point p and the plane parallel to the camera plane and passing through the view
|
||||||
/// point. The would be z depth
|
/// point. The would be z depth
|
||||||
S Depth(const vcg::Point3<S> & p)const;
|
S Depth(const vcg::Point3<S> & p)const;
|
||||||
|
@ -125,7 +124,7 @@ template <class S>
|
||||||
vcg::Point3<S> Shot<S>::Axis(const int & i) const {
|
vcg::Point3<S> Shot<S>::Axis(const int & i) const {
|
||||||
vcg::Matrix44<S> m;
|
vcg::Matrix44<S> m;
|
||||||
similarity.rot.ToMatrix(m);
|
similarity.rot.ToMatrix(m);
|
||||||
vcg::Point3f aa = m.Row3(i);
|
vcg::Point3<S> aa = m.Row3(i);
|
||||||
return aa;
|
return aa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +143,7 @@ void Shot<S>::LookAt(const S & eye_x,const S & eye_y,const S & eye_z,const S & a
|
||||||
const S & up_x,const S & up_y,const S & up_z){
|
const S & up_x,const S & up_y,const S & up_z){
|
||||||
SetViewPoint(Point3<S>(eye_x,eye_y,eye_z));
|
SetViewPoint(Point3<S>(eye_x,eye_y,eye_z));
|
||||||
LookAt(Point3<S>(at_x,at_y,at_z),Point3<S>(up_x,up_y,up_z));
|
LookAt(Point3<S>(at_x,at_y,at_z),Point3<S>(up_x,up_y,up_z));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class S>
|
template <class S>
|
||||||
|
@ -168,18 +167,28 @@ vcg::Point3<S> Shot<S>::ConvertToCameraCoordinates(const vcg::Point3<S> & p) con
|
||||||
cp[2]=-cp[2];
|
cp[2]=-cp[2];
|
||||||
return cp;
|
return cp;
|
||||||
}
|
}
|
||||||
|
template <class S>
|
||||||
|
vcg::Point3<S> Shot<S>::ConvertToWorldCoordinates(const vcg::Point3<S> & p) const{
|
||||||
|
vcg::Point3<S> cp = Inverse(similarity.Matrix())*p;
|
||||||
|
// note: the World reference system is left handed
|
||||||
|
cp[2]=-cp[2];
|
||||||
|
return cp;
|
||||||
|
}
|
||||||
template <class S>
|
template <class S>
|
||||||
vcg::Point2<S> Shot<S>::Project(const vcg::Point3<S> & p) const{
|
vcg::Point2<S> Shot<S>::Project(const vcg::Point3<S> & p) const{
|
||||||
return camera.Project(ConvertToCameraCoordinates(p));
|
return camera.Project(ConvertToCameraCoordinates(p));
|
||||||
}
|
}
|
||||||
|
template <class S>
|
||||||
|
vcg::Point3<S> Shot<S>::UnProject(const vcg::Point2<S> & p) const{
|
||||||
|
vcg::Point3<S> q = camera.UnProject(p);
|
||||||
|
return ConvertToWorldCoordinates(q);
|
||||||
|
}
|
||||||
template <class S>
|
template <class S>
|
||||||
S Shot<S>::Depth(const vcg::Point3<S> & p)const {
|
S Shot<S>::Depth(const vcg::Point3<S> & p)const {
|
||||||
return ConvertToCameraCoordinates(p).Z();
|
return ConvertToCameraCoordinates(p).Z();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,10 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.10 2004/10/07 13:55:47 ganovelli
|
||||||
|
templated on the kind of class used to implement rotation
|
||||||
|
(default is QUternion but it can be Matrix44 as well)
|
||||||
|
|
||||||
Revision 1.9 2004/06/04 13:35:07 cignoni
|
Revision 1.9 2004/06/04 13:35:07 cignoni
|
||||||
added InverseMatrix,
|
added InverseMatrix,
|
||||||
|
|
||||||
|
@ -35,6 +39,10 @@ unified to the gl stlyle matix*vector. removed vector*matrix operator
|
||||||
|
|
||||||
Revision 1.6 2004/03/25 14:57:49 ponchio
|
Revision 1.6 2004/03/25 14:57:49 ponchio
|
||||||
Microerror. ($LOG$ -> $Log: not supported by cvs2svn $
|
Microerror. ($LOG$ -> $Log: not supported by cvs2svn $
|
||||||
|
Microerror. ($LOG$ -> Revision 1.10 2004/10/07 13:55:47 ganovelli
|
||||||
|
Microerror. ($LOG$ -> templated on the kind of class used to implement rotation
|
||||||
|
Microerror. ($LOG$ -> (default is QUternion but it can be Matrix44 as well)
|
||||||
|
Microerror. ($LOG$ ->
|
||||||
Microerror. ($LOG$ -> Revision 1.9 2004/06/04 13:35:07 cignoni
|
Microerror. ($LOG$ -> Revision 1.9 2004/06/04 13:35:07 cignoni
|
||||||
Microerror. ($LOG$ -> added InverseMatrix,
|
Microerror. ($LOG$ -> added InverseMatrix,
|
||||||
Microerror. ($LOG$ ->
|
Microerror. ($LOG$ ->
|
||||||
|
@ -154,9 +162,9 @@ template <class S,class RotationType> void Similarity<S,RotationType>::FromMatri
|
||||||
assert(sca != 0);
|
assert(sca != 0);
|
||||||
Matrix44<S> t = m * Matrix44<S>().SetScale(1/sca, 1/sca, 1/sca);
|
Matrix44<S> t = m * Matrix44<S>().SetScale(1/sca, 1/sca, 1/sca);
|
||||||
rot.FromMatrix(t);
|
rot.FromMatrix(t);
|
||||||
tra[0] = t.element(3, 0);
|
tra[0] = t.ElementAt(3, 0);
|
||||||
tra[1] = t.element(3, 1);
|
tra[1] = t.ElementAt(3, 1);
|
||||||
tra[2] = t.element(3, 2);
|
tra[2] = t.ElementAt(3, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class S,class RotationType> Similarity<S,RotationType> &Invert(Similarity<S,RotationType> &a) {
|
template <class S,class RotationType> Similarity<S,RotationType> &Invert(Similarity<S,RotationType> &a) {
|
||||||
|
|
127
wrap/gl/camera.h
127
wrap/gl/camera.h
|
@ -23,6 +23,9 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
History
|
History
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.3 2004/11/03 09:38:21 ganovelli
|
||||||
|
added SetSubView, some comment and put the class back(!)
|
||||||
|
|
||||||
Revision 1.2 2004/10/05 19:04:44 ganovelli
|
Revision 1.2 2004/10/05 19:04:44 ganovelli
|
||||||
changed from classes to functions
|
changed from classes to functions
|
||||||
|
|
||||||
|
@ -40,6 +43,7 @@ creation
|
||||||
// opengl
|
// opengl
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
//<<<<<<< camera.h
|
||||||
|
|
||||||
template <class CameraType>
|
template <class CameraType>
|
||||||
struct GlCamera{
|
struct GlCamera{
|
||||||
|
@ -47,9 +51,20 @@ struct GlCamera{
|
||||||
typedef typename CameraType::ScalarType ScalarType;
|
typedef typename CameraType::ScalarType ScalarType;
|
||||||
typedef typename CameraType::ScalarType S;
|
typedef typename CameraType::ScalarType S;
|
||||||
|
|
||||||
/// returns the opengl matrix corresponding to the camera
|
|
||||||
static vcg::Matrix44<ScalarType>
|
static vcg::Matrix44<ScalarType>
|
||||||
MatrixGL(const vcg::Camera<ScalarType> & cam, vcg::Matrix44<ScalarType> &m){
|
MatrixGL(const vcg::Camera<S> & cam, vcg::Matrix44<S> &m){
|
||||||
|
//=======
|
||||||
|
//
|
||||||
|
//template <class CameraType>
|
||||||
|
//struct GlCamera{
|
||||||
|
//
|
||||||
|
// typedef typename CameraType::ScalarType ScalarType;
|
||||||
|
// typedef typename CameraType::ScalarType S;
|
||||||
|
//
|
||||||
|
// /// returns the opengl matrix corresponding to the camera
|
||||||
|
//static vcg::Matrix44<ScalarType>
|
||||||
|
//MatrixGL(const vcg::Camera<ScalarType> & cam, vcg::Matrix44<ScalarType> &m){
|
||||||
|
//>>>>>>> 1.3
|
||||||
glPushAttrib(GL_TRANSFORM_BIT);
|
glPushAttrib(GL_TRANSFORM_BIT);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -61,18 +76,16 @@ MatrixGL(const vcg::Camera<ScalarType> & cam, vcg::Matrix44<ScalarType> &m){
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// computes the parametrs as to call the glFrustum(..)
|
//<<<<<<< camera.h
|
||||||
static void
|
static void GetFrustum(const CameraType & camera,
|
||||||
GetFrustum(const CameraType & camera,
|
typename S & sx,
|
||||||
typename CameraType::ScalarType & sx,
|
typename S & dx,
|
||||||
typename CameraType::ScalarType & dx,
|
typename S & bt,
|
||||||
typename CameraType::ScalarType & bt,
|
typename S & tp,
|
||||||
typename CameraType::ScalarType & tp,
|
typename S & f ,
|
||||||
typename CameraType::ScalarType & f ,
|
typename S & fr
|
||||||
typename CameraType::ScalarType & fr
|
){
|
||||||
)
|
dx = camera.c.X()*camera.s.X(); //scaled center
|
||||||
{
|
|
||||||
dx = camera.c.X()*camera.s.X();
|
|
||||||
sx = -( camera.viewport.X() - camera.c.X() ) * camera.s.X();
|
sx = -( camera.viewport.X() - camera.c.X() ) * camera.s.X();
|
||||||
|
|
||||||
bt = -camera.c.Y()*camera.s.Y();
|
bt = -camera.c.Y()*camera.s.Y();
|
||||||
|
@ -82,29 +95,89 @@ GetFrustum(const CameraType & camera,
|
||||||
fr = camera.farend;
|
fr = camera.farend;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// perform the opengl trasformatino correponding to the camera
|
//=======
|
||||||
static void TransformGL(const vcg::Camera<ScalarType> & camera,typename ScalarType farDist = -1 ) {
|
// /// computes the parametrs as to call the glFrustum(..)
|
||||||
ScalarType sx,dx,bt,tp,nr,fr;
|
//static void
|
||||||
|
//GetFrustum(const CameraType & camera,
|
||||||
|
// typename CameraType::ScalarType & sx,
|
||||||
|
// typename CameraType::ScalarType & dx,
|
||||||
|
// typename CameraType::ScalarType & bt,
|
||||||
|
// typename CameraType::ScalarType & tp,
|
||||||
|
// typename CameraType::ScalarType & f ,
|
||||||
|
// typename CameraType::ScalarType & fr
|
||||||
|
// )
|
||||||
|
//{
|
||||||
|
// dx = camera.c.X()*camera.s.X();
|
||||||
|
// sx = -( camera.viewport.X() - camera.c.X() ) * camera.s.X();
|
||||||
|
//>>>>>>> 1.3
|
||||||
|
|
||||||
|
//<<<<<<< camera.h
|
||||||
|
static void TransformGL(const vcg::Camera<S> & camera,typename S farDist = -1 ) {
|
||||||
|
S sx,dx,bt,tp,nr,fr;
|
||||||
GetFrustum(camera,sx,dx,bt,tp,nr,fr);
|
GetFrustum(camera,sx,dx,bt,tp,nr,fr);
|
||||||
assert(glGetError()==0);
|
assert(glGetError()==0);
|
||||||
glFrustum(sx,dx,bt,tp,nr,(farDist == -1)?fr:farDist);
|
glFrustum(sx,dx,bt,tp,nr,(farDist == -1)?fr:farDist);
|
||||||
assert(glGetError()==0);
|
assert(glGetError()==0);
|
||||||
}
|
};
|
||||||
|
//=======
|
||||||
|
// bt = -camera.c.Y()*camera.s.Y();
|
||||||
|
// tp = ( camera.viewport.Y() - camera.c.Y() ) * camera.s.Y();
|
||||||
|
//>>>>>>> 1.3
|
||||||
|
|
||||||
/// set the view as from the camera but only in a portion of the view (c0,c1 in [0,1]x[0,1]
|
//<<<<<<< camera.h
|
||||||
static void SetSubView(const CameraType & camera,vcg::Point2<S> c0,vcg::Point2<S> c1){
|
static void GetViewSize(const vcg::Camera<S> & camera, typename S &width, typename S &height) {
|
||||||
typedef typename CameraType::ScalarType S;
|
|
||||||
S sx,dx,bt,tp,nr,fr;
|
S sx,dx,bt,tp,nr,fr;
|
||||||
GetFrustum(camera,sx,dx,bt,tp,nr,fr);
|
GetFrustum(camera,sx,dx,bt,tp,nr,fr);
|
||||||
|
width = dx-sx; //right - left = width
|
||||||
|
height = tp-bt; //top - bottom = height
|
||||||
|
};
|
||||||
|
//=======
|
||||||
|
// f = camera.f;
|
||||||
|
// fr = camera.farend;
|
||||||
|
//}
|
||||||
|
//>>>>>>> 1.3
|
||||||
|
|
||||||
S cv[2];
|
//<<<<<<< camera.h
|
||||||
cv[0] = dx-sx;
|
static void SetSubView(const CameraType & camera,vcg::Point2<S> p0,vcg::Point2<S> p1){
|
||||||
cv[1] = tp-bt;
|
//typedef typename CameraType::ScalarType S;
|
||||||
glFrustum(sx + cv[0]* c0[0],sx + cv[0] * c1[0],
|
S sx,dx,bt,tp,nr,fr;
|
||||||
bt + cv[1]* c0[1],bt + cv[1] * c1[1],
|
GetFrustum(camera,sx,dx,bt,tp,nr,fr);
|
||||||
|
//=======
|
||||||
|
///// perform the opengl trasformatino correponding to the camera
|
||||||
|
//static void TransformGL(const vcg::Camera<ScalarType> & camera,typename ScalarType farDist = -1 ) {
|
||||||
|
// ScalarType sx,dx,bt,tp,nr,fr;
|
||||||
|
// GetFrustum(camera,sx,dx,bt,tp,nr,fr);
|
||||||
|
// assert(glGetError()==0);
|
||||||
|
// glFrustum(sx,dx,bt,tp,nr,(farDist == -1)?fr:farDist);
|
||||||
|
// assert(glGetError()==0);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
///// set the view as from the camera but only in a portion of the view (c0,c1 in [0,1]x[0,1]
|
||||||
|
//static void SetSubView(const CameraType & camera,vcg::Point2<S> c0,vcg::Point2<S> c1){
|
||||||
|
// typedef typename CameraType::ScalarType S;
|
||||||
|
// S sx,dx,bt,tp,nr,fr;
|
||||||
|
// GetFrustum(camera,sx,dx,bt,tp,nr,fr);
|
||||||
|
//>>>>>>> 1.3
|
||||||
|
|
||||||
|
//<<<<<<< camera.h
|
||||||
|
S width = dx-sx; //right - left = width
|
||||||
|
S height = tp-bt; //top - bottom = height
|
||||||
|
glFrustum(
|
||||||
|
width* p0[0]+ sx, width* p1[0]+ sx,
|
||||||
|
height* p0[1]+ bt, height* p1[1]+ bt,
|
||||||
nr,fr);
|
nr,fr);
|
||||||
assert(glGetError()==0);
|
assert(glGetError()==0);
|
||||||
}
|
};
|
||||||
|
//=======
|
||||||
|
// S cv[2];
|
||||||
|
// cv[0] = dx-sx;
|
||||||
|
// cv[1] = tp-bt;
|
||||||
|
// glFrustum(sx + cv[0]* c0[0],sx + cv[0] * c1[0],
|
||||||
|
// bt + cv[1]* c0[1],bt + cv[1] * c1[1],
|
||||||
|
// nr,fr);
|
||||||
|
// assert(glGetError()==0);
|
||||||
|
//}
|
||||||
|
//>>>>>>> 1.3
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
History
|
History
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.3 2004/11/03 09:41:57 ganovelli
|
||||||
|
added FromTrackball and fixed include names (Poiint to point)
|
||||||
|
|
||||||
Revision 1.2 2004/10/05 19:04:45 ganovelli
|
Revision 1.2 2004/10/05 19:04:45 ganovelli
|
||||||
changed from classes to functions
|
changed from classes to functions
|
||||||
|
|
||||||
|
@ -41,11 +44,11 @@ creation
|
||||||
#ifndef __VCGLIB_GLSHOT
|
#ifndef __VCGLIB_GLSHOT
|
||||||
#define __VCGLIB_GLSHOT
|
#define __VCGLIB_GLSHOT
|
||||||
|
|
||||||
|
|
||||||
// include vcg stuff
|
// include vcg stuff
|
||||||
#include <vcg/space/point2.h>
|
#include <vcg/space/point2.h>
|
||||||
#include <vcg/space/point3.h>
|
#include <vcg/space/point3.h>
|
||||||
#include <vcg/math/similarity.h>
|
#include <vcg/math/similarity.h>
|
||||||
|
|
||||||
#include <vcg/math/shot.h>
|
#include <vcg/math/shot.h>
|
||||||
|
|
||||||
// include wrap stuff
|
// include wrap stuff
|
||||||
|
@ -59,20 +62,17 @@ struct GlShot {
|
||||||
typedef typename ShotType::ScalarType ScalarType;
|
typedef typename ShotType::ScalarType ScalarType;
|
||||||
typedef typename GlCamera<typename ShotType::CameraType> GlCameraType;
|
typedef typename GlCamera<typename ShotType::CameraType> GlCameraType;
|
||||||
|
|
||||||
/// takes the opengl matrix corresponding to the shot
|
static void MatrixGL(const ShotType & shot,vcg::Matrix44<ScalarType> & m) {
|
||||||
static void MatrixGL(const ShotType & shot,vcg::Matrix44<typename ShotType::ScalarType> & m) {
|
|
||||||
m = shot.similarity.Matrix();
|
m = shot.similarity.Matrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// perform the model transformation correspoding to the shot
|
static void TransformGL(const vcg::Shot<ScalarType> & shot){
|
||||||
static void TransformGL(const vcg::Shot<typename ShotType::ScalarType> & shot){
|
|
||||||
vcg::Matrix44<ScalarType> m;
|
vcg::Matrix44<ScalarType> m;
|
||||||
MatrixGL(shot,m);
|
MatrixGL(shot,m);
|
||||||
glMultMatrix(m);
|
glMultMatrix(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// set the view as from the shot
|
static void SetView(const vcg::Shot<ScalarType> & shot){
|
||||||
static void SetView(const vcg::Shot<typename ShotType::ScalarType> & shot){
|
|
||||||
assert(glGetError() == 0);
|
assert(glGetError() == 0);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -86,34 +86,54 @@ static void SetView(const vcg::Shot<typename ShotType::ScalarType> & shot){
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
vcg::Matrix44<ScalarType> m;
|
GlShot<ShotType>::TransformGL(shot); // apply similarity/modelview transformation
|
||||||
TransformGL(shot); // apply similarity/modelview transformation
|
assert(glGetError() == 0);
|
||||||
|
}
|
||||||
|
static void SetSubView(vcg::Shot<ScalarType> & shot,
|
||||||
|
vcg::Point2<ScalarType> p1,
|
||||||
|
vcg::Point2<ScalarType> p2)
|
||||||
|
{
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glPushMatrix();
|
||||||
|
glLoadIdentity();
|
||||||
|
assert(glGetError() == 0);
|
||||||
|
GlCameraType::SetSubView(shot.Camera(),p1,p2);
|
||||||
|
assert(glGetError() == 0);
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glPushMatrix();
|
||||||
|
glLoadIdentity();
|
||||||
|
GlShot<ShotType>::TransformGL(shot); // apply similarity/modelview transformation
|
||||||
assert(glGetError() == 0);
|
assert(glGetError() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// unset the view
|
static void UnsetView()
|
||||||
static void UnsetView(){
|
{
|
||||||
glPushAttrib(GL_TRANSFORM_BIT);
|
glPushAttrib(GL_TRANSFORM_BIT);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
}
|
|
||||||
|
|
||||||
/// takes a shot and a trackball and retur the shot corresponding to the transformation
|
|
||||||
/// applied by the trackball
|
|
||||||
static void FromTrackball(const vcg::Trackball & tr, const vcg::Shot<typename ShotType::ScalarType> & sShot,
|
|
||||||
vcg::Shot<ScalarType> & shot ){
|
|
||||||
vcg::Point3<ScalarType> vp = sShot.ViewPoint()-tr.center;
|
|
||||||
vcg::Point3<ScalarType> nvp ;
|
|
||||||
|
|
||||||
vcg::Matrix44<ScalarType> trInv = tr.track.InverseMatrix();
|
|
||||||
nvp = trInv*vp;
|
|
||||||
shot.SetViewPoint(nvp+tr.center);
|
|
||||||
shot.similarity.rot = trInv*sShot.similarity.rot;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// takes a shot and a trackball and retursn the shot corresponding to the transformation
|
||||||
|
// applied by the trackball
|
||||||
|
static void FromTrackball(const vcg::Trackball & tr,
|
||||||
|
const vcg::Shot<ScalarType> & sShot,
|
||||||
|
vcg::Shot<ScalarType> & shot )
|
||||||
|
{
|
||||||
|
vcg::Point3<ScalarType> vp = sShot.ViewPoint();
|
||||||
|
vcg::Point3<float> vpf = vcg::Point3<float>(vp[0],vp[1],vp[2]);
|
||||||
|
vcg::Matrix44<float> trInvM = tr.track.InverseMatrix();
|
||||||
|
|
||||||
|
vcg::Matrix44<ScalarType> trM; /*=*/ trM.FromMatrix(tr.track.Matrix());
|
||||||
|
|
||||||
|
vcg::Point3<float> nvp = trInvM*vpf;// nvp = shInvM*nvp;
|
||||||
|
|
||||||
|
shot.SetViewPoint(vcg::Point3<ScalarType>(nvp[0],nvp[1],nvp[2]));
|
||||||
|
shot.similarity.rot = sShot.similarity.rot*trM;
|
||||||
|
shot.similarity.sca = sShot.similarity.sca*tr.track.sca;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.4 2004/09/30 01:40:39 ponchio
|
||||||
|
<gl/glew.h> --> <GL/glew.h>
|
||||||
|
|
||||||
Revision 1.3 2004/07/13 11:25:57 pietroni
|
Revision 1.3 2004/07/13 11:25:57 pietroni
|
||||||
changed order of initial include ( it had problems with extension of openGL)
|
changed order of initial include ( it had problems with extension of openGL)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue