7 #include <xercesc/parsers/XercesDOMParser.hpp>
8 #include <xercesc/dom/DOM.hpp>
9 #include <xercesc/sax/HandlerBase.hpp>
10 #include <xercesc/util/XMLString.hpp>
11 #include <xercesc/util/PlatformUtils.hpp>
13 #include <osg/Geometry>
16 #include <osg/ref_ptr>
20 #define RE_DEFAULT_HEIGHT 20.0
21 #define RE_DEFAULT_BOTTOM 0.0
22 #define RE_DEFAULT_2_WIDTH 0.75
23 #define RE_MIN_LENGTH 5.0
24 #define RE_DEFAULT_COLOR osg::Vec3(1.0, 1.0, 1.0)
25 #define RE_MIN_ANGLE(x,y) ((x)<(y) ? 2*(RE_DEG_2_RAD_RATIO)*asin((RE_DEFAULT_2_WIDTH)/(x)) : 2*(RE_DEG_2_RAD_RATIO)*asin((RE_DEFAULT_2_WIDTH)/(y)))
27 #define RE_DEG_2_RAD_RATIO (180.0 / 3.141592653589793238)
29 #define RE_WALL_ANGLES_COMPUTED 1
30 #define RE_WALL_DRAWN 2
32 using namespace vrecko;
48 static bool getCrossingPoint(osg::Vec2& destPoint, osg::Vec2 pPoint, osg::Vec2 pNormal, osg::Vec2 rPoint, osg::Vec2 rNormal,
bool justStroke) {
50 float resultX, resultY;
53 d1 = -1*(pPoint.x() * pNormal.x() + pPoint.y() * pNormal.y());
54 d2 = -1*(rPoint.x() * rNormal.x() + rPoint.y() * rNormal.y());
55 div = (rNormal.x() * pNormal.y() - pNormal.x() * rNormal.y());
60 resultX = (d1 * rNormal.y() - d2 * pNormal.y()) / div;
62 resultY = (-d2 - rNormal.x() * resultX) / rNormal.y();
65 resultY = (-d1 - pNormal.x() * resultX) / pNormal.y();
69 param = (resultX - pPoint.x()) / pNormal.y();
71 param = (resultY - pPoint.y()) / (-pNormal.x());
74 tparam = (resultX - rPoint.x()) / rNormal.y();
76 tparam = (resultY - rPoint.y()) / (-rNormal.x());
78 destPoint = osg::Vec2(resultX, resultY);
80 result = ((param > 0.000009) && (param < 0.999999) && (tparam > 0.000009) && (tparam < 0.999999));
95 float dot00 = v0 * v0,
102 float invDenom = 1 / (dot00 * dot11 - dot01 * dot01),
103 u = (dot11 * dot02 - dot01 * dot12) * invDenom,
104 v = (dot00 * dot12 - dot01 * dot02) * invDenom;
107 return (u >= 0) && (v >= 0) && (u + v <= 1);
113 float angle, toSum = 0;
115 if (vector.y() >= 0) {
123 if (vector.x() >= 0) {
131 if ((vector.x() > 0) && (vector.y() > 0)) {
134 else if ((vector.x() < 0) && (vector.y() > 0)) {
137 else if ((vector.x() < 0) && (vector.y() < 0)) {
182 osg::Vec3 topCWVertex;
183 osg::Vec3 topCCWVertex;
184 osg::Vec3 bottomCWVertex;
185 osg::Vec3 bottomCCWVertex;
187 osg::Vec2 normalCWVertex;
188 osg::Vec2 normalCCWVertex;
199 virtual ~WG_Point() { plusVertices.clear(); plusNormals.clear(); plusColors.clear(); }
204 this->position = position;
210 void addWall(
WG_Wall* wall,
PointType connectionPointType,
bool compute =
true);
211 void removeWall(
WG_Wall* wall);
214 void setId(
unsigned int i) {
id = i; }
229 bool getWallNeighbours(
WG_Wall* wall, std::pair<osg::ref_ptr<WG_Wall>,
PointType>& wallCW, std::pair<osg::ref_ptr<WG_Wall>,
PointType>& wallCCW);
237 std::vector<std::pair<osg::ref_ptr<WG_Wall>,
PointType> > walls;
239 unsigned int indexTop;
240 unsigned int indexBottom;
242 std::vector<osg::Vec3> plusVertices;
243 std::vector<osg::Vec3> plusNormals;
244 std::vector<osg::Vec3> plusColors;
258 this->position = position;
260 this->height = height;
271 void setY(
float y) { this->y = y; }
277 void setWidth(
float width) { this->width = width; }
303 flag = 0; q = qPoint; r = rPoint;
306 computeAttrVectorsAndAngles();
312 computeAttrVertices();
319 q->removeWall(
this); r->removeWall(
this);
320 q = qPoint; r = rPoint;
321 computeAttrVectorsAndAngles();
324 computeAttrVertices();
331 computeAttrVectorsAndAngles();
337 computeAttrVectorsAndAngles();
340 computeAttrVertices();
353 void setId(
unsigned int i) {
id = i; }
368 std::vector<WG_Hole>*
getHoles() {
return &holes; }
372 void computeAttrVectorsAndAngles();
380 bool computeAttrNormals();
381 void computeHoleVertices();
384 struct PointRelatedAttr {
392 osg::ref_ptr<WG_Point> q;
393 PointRelatedAttr qAttr;
395 osg::ref_ptr<WG_Point> r;
396 PointRelatedAttr rAttr;
402 osg::Vec3 bottomNormal;
406 std::vector<WG_Hole> holes;
410 void setVectorAndAngle(WG_Point* P1, WG_Point* P2, PointRelatedAttr* attr);
414 osg::Vec3 computeNormal(osg::Vec3 V1, osg::Vec3 V2, osg::Vec3 V3) {
415 osg::Vec3 A = V1 - V2;
416 osg::Vec3 B = V3 - V2;
417 osg::Vec3 normal = osg::Vec3((A.y() * B.z() - A.z() * B.y()), (A.z() * B.x() - A.x() * B.z()), (A.x() * B.y() - A.y() * B.x()));