vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PointAdd.h
Go to the documentation of this file.
1 #ifndef _POINT_ADD_H
2 #define _POINT_ADD_H
3 
4 #include "Tool.h"
5 
6 namespace APRoomEdit {
7 
8  // tool that splits a wall into two walls
9  class PointAdd : public Tool {
10  public:
12  virtual ~PointAdd(void) {}
13 
14  virtual void init(osgUtil::LineSegmentIntersector::Intersection* intersection, WG_Wall* curWall, WG_Point* curPoint, PointType type, vrecko::EnvironmentObject* pEOOwner, std::vector<osg::ref_ptr<WG_Wall> >* walls, std::vector<osg::ref_ptr<WG_Point> >* points, osg::Geode* pOSGGeode, osg::Vec3Array* pOSGVertexArray) {
15  if (curWall != NULL) {
16  WG_Wall* newWall;
17  WG_Point* newPoint;
18 
19  osg::Vec2 iPoint = osg::Vec2(intersection->getLocalIntersectPoint().x(), intersection->getLocalIntersectPoint().z());
20  osg::Vec2 iNormal = curWall->getVector(WG_Q_POINT);
21 
22  osg::Vec2 curNormal(-curWall->getVector(WG_Q_POINT).y(),curWall->getVector(WG_Q_POINT).x());
23 
24  osg::Vec2 crossPoint;
25  WG_Geometry::getCrossingPoint(crossPoint, curWall->getPoint(WG_Q_POINT)->getPosition(), curNormal, iPoint, iNormal, false);
26 
27  WG_Point* Q = curWall->getPoint(WG_Q_POINT);
28  WG_Point* R = curWall->getPoint(WG_R_POINT);
29 
30  osg::Vec2 qVec = Q->getPosition() - crossPoint;
31  osg::Vec2 rVec = R->getPosition() - crossPoint;
32 
33  osg::Vec2 mpVector;
34 
35  if ((qVec.length() < RE_MIN_LENGTH) || (rVec.length() < RE_MIN_LENGTH)) {
36  logger.warningLog("Cannot split selected wall. Too close to the edge.");
37  }
38  else {
39  newPoint = new WG_Point(crossPoint);
40  newPoint->setId(points->size());
41  points->push_back(newPoint);
42  curWall->setPoint(newPoint, WG_R_POINT);
43  newWall = new WG_Wall(newPoint, R);
44  newWall->setId(walls->size());
45  walls->push_back(newWall);
46  }
47  }
48 
49  setDirty(true);
50  }
51  };
52 
53 }
54 
55 #endif
56