2004-03-25 15:55:25 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2004 \/)\/ *
|
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
|
|
History
|
|
|
|
|
|
|
|
$Log: not supported by cvs2svn $
|
2004-10-04 14:33:02 +02:00
|
|
|
Revision 1.5 2004/09/28 10:23:28 ponchio
|
|
|
|
Various generic changes.
|
|
|
|
|
2004-09-28 12:23:28 +02:00
|
|
|
Revision 1.4 2004/05/12 20:55:18 ponchio
|
|
|
|
*** empty log message ***
|
|
|
|
|
2004-05-12 22:55:18 +02:00
|
|
|
Revision 1.3 2004/03/31 15:06:41 ponchio
|
|
|
|
#include <camera> -> #include <view>
|
|
|
|
|
2004-03-31 17:06:41 +02:00
|
|
|
Revision 1.2 2004/03/25 14:55:25 ponchio
|
|
|
|
Adding copyright.
|
|
|
|
|
2004-03-25 15:55:25 +01:00
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
2004-03-25 15:50:08 +01:00
|
|
|
#ifndef FRUSTUM_H
|
|
|
|
#define FRUSTUM_H
|
|
|
|
|
2004-03-31 17:06:41 +02:00
|
|
|
#include <wrap/gui/view.h>
|
2004-03-25 15:50:08 +01:00
|
|
|
#include <vcg/space/plane3.h>
|
|
|
|
#include <vcg/space/line3.h>
|
|
|
|
|
2004-10-04 14:33:02 +02:00
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
2004-03-25 15:50:08 +01:00
|
|
|
|
|
|
|
namespace vcg {
|
|
|
|
|
2004-09-28 12:23:28 +02:00
|
|
|
template <class T> class Frustum: public View<T> {
|
2004-03-25 15:50:08 +01:00
|
|
|
public:
|
|
|
|
void GetView();
|
2004-05-12 22:55:18 +02:00
|
|
|
Point3<T> ViewPoint();
|
2004-09-28 12:23:28 +02:00
|
|
|
T Resolution(float dist = 1);
|
2004-03-25 15:50:08 +01:00
|
|
|
bool IsOutside(Point3<T> &point);
|
|
|
|
bool IsOutside(Point3<T> &point, T radius);
|
|
|
|
T Distance(Point3<T> &point, int plane);
|
2004-05-12 22:55:18 +02:00
|
|
|
|
2004-03-25 15:50:08 +01:00
|
|
|
protected:
|
|
|
|
T resolution;
|
|
|
|
Plane3<T> planes[6];
|
|
|
|
Point3<T> view_point;
|
|
|
|
};
|
|
|
|
|
2004-09-28 12:23:28 +02:00
|
|
|
|
2004-05-12 22:55:18 +02:00
|
|
|
typedef Frustum<float> Frustumf;
|
|
|
|
typedef Frustum<double> Frustumd;
|
|
|
|
|
2004-03-25 15:50:08 +01:00
|
|
|
|
|
|
|
//Implementation
|
|
|
|
template <class T> Point3<T> Frustum<T>::ViewPoint() {
|
|
|
|
return view_point;
|
|
|
|
}
|
|
|
|
|
2004-09-28 12:23:28 +02:00
|
|
|
template <class T> T Frustum<T>::Resolution(float dist) {
|
|
|
|
return resolution * dist;
|
2004-05-12 22:55:18 +02:00
|
|
|
}
|
|
|
|
|
2004-03-25 15:50:08 +01:00
|
|
|
template <class T> bool Frustum<T>::IsOutside(Point3<T> &point) {
|
|
|
|
Point3<T> r = Project(point);
|
|
|
|
if(r[0] < viewport[0] || r[0] > viewport[0]+viewport[2] ||
|
|
|
|
r[1] < viewport[1] || r[1] > viewport[1]+viewport[3])
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> bool Frustum<T>::IsOutside(Point3<T> &point, T radius) {
|
|
|
|
for(int i = 0; i < 4; i++) {
|
2004-10-04 14:33:02 +02:00
|
|
|
T dist = Distance(point, i);
|
2004-03-25 15:50:08 +01:00
|
|
|
if(dist < -radius)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> T Frustum<T>::Distance(Point3<T> &point, int plane) {
|
2004-10-04 14:33:02 +02:00
|
|
|
return vcg::Distance(planes[plane], point);
|
2004-03-25 15:50:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> void Frustum<T>::GetView() {
|
2004-09-28 12:23:28 +02:00
|
|
|
View<T>::GetView();
|
2004-03-25 15:50:08 +01:00
|
|
|
|
|
|
|
int t = viewport[1] + viewport[3];
|
|
|
|
int b = viewport[1];
|
|
|
|
int r = viewport[0] + viewport[2];
|
|
|
|
int l = viewport[0];
|
2004-10-04 14:33:02 +02:00
|
|
|
|
2004-09-28 12:23:28 +02:00
|
|
|
Point3<T> nw = UnProject(Point3<T>(l, b, 0));
|
|
|
|
Point3<T> sw = UnProject(Point3<T>(l, t, 0));
|
|
|
|
Point3<T> ne = UnProject(Point3<T>(r, b, 0));
|
|
|
|
Point3<T> se = UnProject(Point3<T>(r, t, 0));
|
|
|
|
Point3<T> NW = UnProject(Point3<T>(l, b, 1));
|
|
|
|
Point3<T> SW = UnProject(Point3<T>(l, t, 1));
|
|
|
|
Point3<T> NE = UnProject(Point3<T>(r, b, 1));
|
|
|
|
Point3<T> SE = UnProject(Point3<T>(r, t, 1));
|
|
|
|
|
|
|
|
view_point = View<T>::ViewPoint();
|
2004-10-04 14:33:02 +02:00
|
|
|
|
|
|
|
planes[0].Init(nw, NW, NE);
|
|
|
|
planes[1].Init(ne, NE, SE);
|
|
|
|
planes[2].Init(se, SE, SW);
|
|
|
|
planes[3].Init(sw, SW, NW);
|
2004-09-28 12:23:28 +02:00
|
|
|
planes[4].Init(se, sw, nw);
|
|
|
|
planes[5].Init(SW, SE, NE);
|
2004-03-25 15:50:08 +01:00
|
|
|
|
2004-10-04 14:33:02 +02:00
|
|
|
//compute resolution: sizeo of a pixel unitary distance from view_point
|
|
|
|
resolution = ((ne + NE) - (nw + NW)).Norm() /
|
|
|
|
(viewport[2] * ((ne + NE) - view_point).Norm());
|
2004-03-25 15:50:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}//namespace
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|