00001 #include <esg/explorer/NExtentsExplorer.h> 00002 00003 using namespace esg; 00004 00005 00006 bool NExtentsExplorer::_process_leaf(SceneGraphObject& obj) 00007 { 00008 Geometry * pGeom = obj.geometry(); 00009 00010 if (!pGeom) return false; 00011 00012 for (register unsigned i = 0; i < _nDirs; i++) { 00013 Interval ext = pGeom->extent(_trDirs[i]); 00014 ext.min *= _scale[i]; 00015 ext.max *= _scale[i]; 00016 ext.min += _translate[i]; 00017 ext.max += _translate[i]; 00018 //ext.min *= _scale; 00019 //ext.max *= _scale; 00020 if (ext.max > _results[i].max) _results[i].max = ext.max; 00021 if (ext.min < _results[i].min) _results[i].min = ext.min; 00022 } 00023 00024 return true; 00025 } 00026 00027 void NExtentsExplorer::_accept_new_transformation(const Matrix4& trMat) 00028 { 00029 static Matrix3 rMat; 00030 static Vector3 tVec; 00031 static Vector3 sVec; 00032 00033 trMat.get(rMat, tVec, sVec); 00034 rMat.transpose(); 00035 00036 for (register unsigned i = 0; i < _nDirs; i++) { 00037 _translate[i] = _dirs[i].dot(tVec); 00038 rMat.transform(_dirs[i], _trDirs[i]); // rotate direction 00039 _scale[i] = (sVec.x * _trDirs[i].x * _trDirs[i].x + 00040 sVec.y * _trDirs[i].y * _trDirs[i].y + 00041 sVec.z * _trDirs[i].z * _trDirs[i].z); 00042 } 00043 } 00044 00045 00046 00047 00048 00049 NExtentsExplorer::NExtentsExplorer(const float (*dirs)[3], unsigned nDirs) 00050 : _nDirs(nDirs) 00051 { 00052 _results = new Interval[nDirs]; 00053 _dirs = new Vector3[nDirs]; 00054 _trDirs = new Vector3[nDirs]; 00055 _translate = new float[nDirs]; 00056 _scale = new float[nDirs]; 00057 00058 for (register unsigned i = 0; i < _nDirs; i++) { 00059 _results[i].max = -MAXFLOAT; _results[i].min = MAXFLOAT; 00060 _dirs[i].set(dirs[i][0], dirs[i][1], dirs[i][2]); 00061 _trDirs[i].set(dirs[i][0], dirs[i][1], dirs[i][2]); 00062 _translate[i] = 0; 00063 _scale[i] = 1; 00064 } 00065 } 00066 00067 NExtentsExplorer::NExtentsExplorer(const Vector3* dirs, unsigned nDirs) 00068 : _nDirs(nDirs) 00069 { 00070 _results = new Interval[nDirs]; 00071 _dirs = new Vector3[nDirs]; 00072 _trDirs = new Vector3[nDirs]; 00073 _translate = new float[nDirs]; 00074 _scale = new float[nDirs]; 00075 00076 for (register unsigned i = 0; i < _nDirs; i++) { 00077 _results[i].max = -MAXFLOAT; _results[i].min = MAXFLOAT; 00078 _dirs[i].set(dirs[i]); 00079 _trDirs[i].set(dirs[i]); 00080 _translate[i] = 0; 00081 _scale[i] = 1; 00082 } 00083 } 00084 00085 NExtentsExplorer::~NExtentsExplorer() 00086 { 00087 delete [] _results; 00088 delete [] _dirs; 00089 delete [] _trDirs; 00090 delete [] _translate; 00091 delete [] _scale; 00092 } 00093 00094 Interval NExtentsExplorer::result(unsigned i) const 00095 { 00096 if (i < _nDirs) return _results[i]; 00097 else return Interval(); 00098 } 00099