vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HoleRemove.h
Go to the documentation of this file.
1 #ifndef _HOLE_REMOVE_H
2 #define _HOLE_REMOVE_H
3 
4 #include "Tool.h"
5 
6 namespace APRoomEdit {
7 
8  // tool for removing holes from curWall
9  class HoleRemove : public Tool {
10  public:
12  virtual ~HoleRemove(void) {}
13 
14  virtual void init(osgUtil::LineSegmentIntersector::Intersection* intersection,
15  WG_Wall* curWall,
16  WG_Point* curPoint,
18  vrecko::EnvironmentObject* pEOOwner,
19  std::vector<osg::ref_ptr<WG_Wall> >* walls,
20  std::vector<osg::ref_ptr<WG_Point> >* points,
21  osg::Geode* pOSGGeode,
22  osg::Vec3Array* pOSGVertexArray) {
23 
24  if (curWall != NULL) {
25 
26  osg::Vec2 iPoint = osg::Vec2(intersection->getLocalIntersectPoint().x(), intersection->getLocalIntersectPoint().z());
27  osg::Vec2 vector = iPoint - curWall->getPoint(WG_Q_POINT)->getPosition();
28  float length = vector.length();
29  float minLength = curWall->getVector(WG_Q_POINT).length(), curLength = 0.0;
30  unsigned int delIndex = curWall->getHoles()->size();
31 
32  // find the nearest hole
33  for (unsigned int i = 0; i < curWall->getHoles()->size(); i++) {
34  curLength = abs(length - curWall->getHoles()->at(i).getPosition());
35  if (curLength < minLength) {
36  minLength = curLength;
37  delIndex = i;
38  }
39  }
40 
41  // if any hole found then remove it
42  if (delIndex < curWall->getHoles()->size()) {
43  curWall->getHoles()->erase(curWall->getHoles()->begin()+delIndex);
44  }
45 
46  }
47  setDirty(true);
48  }
49  };
50 
51 }
52 
53 #endif
54