~rebel/horde3d/trunk

« back to all changes in this revision

Viewing changes to trunk/Tools/Dependencies/RecastNavigation/RecastDemo/Source/NavMeshTesterTool.cpp

  • Committer: felix
  • Date: 2015-07-07 12:57:07 UTC
  • Revision ID: svn-v4:5ce291ac-9df0-446f-9e4f-d57731c4dda7::1699
- Updated RecastNavigation to latest version and fixed multiple issues.
- Adapted GameDetourComponent, GameDetourCrowdComponent, DetourCrowdDemo and AAA accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
        return req+size;
106
106
}
107
107
 
 
108
// This function checks if the path has a small U-turn, that is,
 
109
// a polygon further in the path is adjacent to the first polygon
 
110
// in the path. If that happens, a shortcut is taken.
 
111
// This can happen if the target (T) location is at tile boundary,
 
112
// and we're (S) approaching it parallel to the tile edge.
 
113
// The choice at the vertex can be arbitrary, 
 
114
//  +---+---+
 
115
//  |:::|:::|
 
116
//  +-S-+-T-+
 
117
//  |:::|   | <-- the step can end up in here, resulting U-turn path.
 
118
//  +---+---+
 
119
static int fixupShortcuts(dtPolyRef* path, int npath, dtNavMeshQuery* navQuery)
 
120
{
 
121
        if (npath < 3)
 
122
                return npath;
 
123
 
 
124
        // Get connected polygons
 
125
        static const int maxNeis = 16;
 
126
        dtPolyRef neis[maxNeis];
 
127
        int nneis = 0;
 
128
 
 
129
        const dtMeshTile* tile = 0;
 
130
        const dtPoly* poly = 0;
 
131
        if (dtStatusFailed(navQuery->getAttachedNavMesh()->getTileAndPolyByRef(path[0], &tile, &poly)))
 
132
                return npath;
 
133
        
 
134
        for (unsigned int k = poly->firstLink; k != DT_NULL_LINK; k = tile->links[k].next)
 
135
        {
 
136
                const dtLink* link = &tile->links[k];
 
137
                if (link->ref != 0)
 
138
                {
 
139
                        if (nneis < maxNeis)
 
140
                                neis[nneis++] = link->ref;
 
141
                }
 
142
        }
 
143
 
 
144
        // If any of the neighbour polygons is within the next few polygons
 
145
        // in the path, short cut to that polygon directly.
 
146
        static const int maxLookAhead = 6;
 
147
        int cut = 0;
 
148
        for (int i = dtMin(maxLookAhead, npath) - 1; i > 1 && cut == 0; i--) {
 
149
                for (int j = 0; j < nneis; j++)
 
150
                {
 
151
                        if (path[i] == neis[j]) {
 
152
                                cut = i;
 
153
                                break;
 
154
                        }
 
155
                }
 
156
        }
 
157
        if (cut > 1)
 
158
        {
 
159
                int offset = cut-1;
 
160
                npath -= offset;
 
161
                for (int i = 1; i < npath; i++)
 
162
                        path[i] = path[i+offset];
 
163
        }
 
164
 
 
165
        return npath;
 
166
}
 
167
 
108
168
static bool getSteerTarget(dtNavMeshQuery* navQuery, const float* startPos, const float* endPos,
109
169
                                                   const float minTargetDist,
110
170
                                                   const dtPolyRef* path, const int pathSize,
450
510
                if (m_pathIterPolyCount)
451
511
                {
452
512
                        // Iterate over the path to find smooth path on the detail mesh surface.
453
 
                        m_navQuery->closestPointOnPoly(m_startRef, m_spos, m_iterPos);
454
 
                        m_navQuery->closestPointOnPoly(m_pathIterPolys[m_pathIterPolyCount-1], m_epos, m_targetPos);
 
513
                        m_navQuery->closestPointOnPoly(m_startRef, m_spos, m_iterPos, 0);
 
514
                        m_navQuery->closestPointOnPoly(m_pathIterPolys[m_pathIterPolyCount-1], m_epos, m_targetPos, 0);
455
515
                        
456
516
                        m_nsmoothPath = 0;
457
517
                        
507
567
        m_navQuery->moveAlongSurface(m_pathIterPolys[0], m_iterPos, moveTgt, &m_filter,
508
568
                                                                 result, visited, &nvisited, 16);
509
569
        m_pathIterPolyCount = fixupCorridor(m_pathIterPolys, m_pathIterPolyCount, MAX_POLYS, visited, nvisited);
 
570
        m_pathIterPolyCount = fixupShortcuts(m_pathIterPolys, m_pathIterPolyCount, m_navQuery);
 
571
 
510
572
        float h = 0;
511
573
        m_navQuery->getPolyHeight(m_pathIterPolys[0], result, &h);
512
574
        result[1] = h;
592
654
                                float epos[3];
593
655
                                dtVcopy(epos, m_epos);
594
656
                                if (m_polys[m_npolys-1] != m_endRef)
595
 
                                m_navQuery->closestPointOnPoly(m_polys[m_npolys-1], m_epos, epos);
 
657
                                m_navQuery->closestPointOnPoly(m_polys[m_npolys-1], m_epos, epos, 0);
596
658
 
597
659
                                m_navQuery->findStraightPath(m_spos, epos, m_polys, m_npolys,
598
660
                                                                                         m_straightPath, m_straightPathFlags,
599
 
                                                                                         m_straightPathPolys, &m_nstraightPath, MAX_POLYS);
 
661
                                                                                         m_straightPathPolys, &m_nstraightPath, MAX_POLYS, DT_STRAIGHTPATH_ALL_CROSSINGS);
600
662
                        }
601
663
                         
602
664
                        m_pathFindStatus = DT_FAILURE;
657
719
                                int npolys = m_npolys;
658
720
                                
659
721
                                float iterPos[3], targetPos[3];
660
 
                                m_navQuery->closestPointOnPoly(m_startRef, m_spos, iterPos);
661
 
                                m_navQuery->closestPointOnPoly(polys[npolys-1], m_epos, targetPos);
 
722
                                m_navQuery->closestPointOnPoly(m_startRef, m_spos, iterPos, 0);
 
723
                                m_navQuery->closestPointOnPoly(polys[npolys-1], m_epos, targetPos, 0);
662
724
                                
663
725
                                static const float STEP_SIZE = 0.5f;
664
726
                                static const float SLOP = 0.01f;
687
749
                                        // Find movement delta.
688
750
                                        float delta[3], len;
689
751
                                        dtVsub(delta, steerPos, iterPos);
690
 
                                        len = dtSqrt(dtVdot(delta,delta));
 
752
                                        len = dtMathSqrtf(dtVdot(delta, delta));
691
753
                                        // If the steer target is end of path or off-mesh link, do not move past the location.
692
754
                                        if ((endOfPath || offMeshConnection) && len < STEP_SIZE)
693
755
                                                len = 1;
702
764
                                        int nvisited = 0;
703
765
                                        m_navQuery->moveAlongSurface(polys[0], iterPos, moveTgt, &m_filter,
704
766
                                                                                                 result, visited, &nvisited, 16);
705
 
                                                                                                                           
 
767
 
706
768
                                        npolys = fixupCorridor(polys, npolys, MAX_POLYS, visited, nvisited);
 
769
                                        npolys = fixupShortcuts(polys, npolys, m_navQuery);
 
770
 
707
771
                                        float h = 0;
708
772
                                        m_navQuery->getPolyHeight(polys[0], result, &h);
709
773
                                        result[1] = h;
795
859
                                float epos[3];
796
860
                                dtVcopy(epos, m_epos);
797
861
                                if (m_polys[m_npolys-1] != m_endRef)
798
 
                                        m_navQuery->closestPointOnPoly(m_polys[m_npolys-1], m_epos, epos);
 
862
                                        m_navQuery->closestPointOnPoly(m_polys[m_npolys-1], m_epos, epos, 0);
799
863
                                
800
864
                                m_navQuery->findStraightPath(m_spos, epos, m_polys, m_npolys,
801
865
                                                                                         m_straightPath, m_straightPathFlags,
820
884
                        m_npolys = 0;
821
885
                        m_nstraightPath = 0;
822
886
                        
823
 
                        m_pathFindStatus = m_navQuery->initSlicedFindPath(m_startRef, m_endRef, m_spos, m_epos, &m_filter);
 
887
                        m_pathFindStatus = m_navQuery->initSlicedFindPath(m_startRef, m_endRef, m_spos, m_epos, &m_filter, DT_FINDPATH_ANY_ANGLE);
824
888
                }
825
889
                else
826
890
                {
854
918
                        else
855
919
                        {
856
920
                                // Hit
857
 
                                m_hitPos[0] = m_spos[0] + (m_epos[0] - m_spos[0]) * t;
858
 
                                m_hitPos[1] = m_spos[1] + (m_epos[1] - m_spos[1]) * t;
859
 
                                m_hitPos[2] = m_spos[2] + (m_epos[2] - m_spos[2]) * t;
860
 
                                if (m_npolys)
861
 
                                {
862
 
                                        float h = 0;
863
 
                                        m_navQuery->getPolyHeight(m_polys[m_npolys-1], m_hitPos, &h);
864
 
                                        m_hitPos[1] = h;
865
 
                                }
 
921
                                dtVlerp(m_hitPos, m_spos, m_epos, t);
866
922
                                m_hitResult = true;
867
923
                        }
 
924
                        // Adjust height.
 
925
                        if (m_npolys > 0)
 
926
                        {
 
927
                                float h = 0;
 
928
                                m_navQuery->getPolyHeight(m_polys[m_npolys-1], m_hitPos, &h);
 
929
                                m_hitPos[1] = h;
 
930
                        }
868
931
                        dtVcopy(&m_straightPath[3], m_hitPos);
869
932
                }
870
933
        }
1084
1147
                        dd.begin(DU_DRAW_LINES, 2.0f);
1085
1148
                        for (int i = 0; i < m_nstraightPath-1; ++i)
1086
1149
                        {
1087
 
                                unsigned int col = 0;
 
1150
                                unsigned int col;
1088
1151
                                if (m_straightPathFlags[i] & DT_STRAIGHTPATH_OFFMESH_CONNECTION)
1089
1152
                                        col = offMeshCol;
1090
1153
                                else
1097
1160
                        dd.begin(DU_DRAW_POINTS, 6.0f);
1098
1161
                        for (int i = 0; i < m_nstraightPath; ++i)
1099
1162
                        {
1100
 
                                unsigned int col = 0;
 
1163
                                unsigned int col;
1101
1164
                                if (m_straightPathFlags[i] & DT_STRAIGHTPATH_START)
1102
1165
                                        col = startCol;
1103
 
                                else if (m_straightPathFlags[i] & DT_STRAIGHTPATH_START)
 
1166
                                else if (m_straightPathFlags[i] & DT_STRAIGHTPATH_END)
1104
1167
                                        col = endCol;
1105
1168
                                else if (m_straightPathFlags[i] & DT_STRAIGHTPATH_OFFMESH_CONNECTION)
1106
1169
                                        col = offMeshCol;
1107
1170
                                else
1108
1171
                                        col = spathCol;
1109
 
                                dd.vertex(m_straightPath[i*3], m_straightPath[i*3+1]+0.4f, m_straightPath[i*3+2], spathCol);
 
1172
                                dd.vertex(m_straightPath[i*3], m_straightPath[i*3+1]+0.4f, m_straightPath[i*3+2], col);
1110
1173
                        }
1111
1174
                        dd.end();
1112
1175
                        dd.depthMask(true);
1302
1365
                for (int i = 0; i < m_nrandPoints; i++)
1303
1366
                {
1304
1367
                        const float* p = &m_randPoints[i*3];
1305
 
                        dd.vertex(p[0],p[1]+0.1,p[2], duRGBA(220,32,16,192));
 
1368
                        dd.vertex(p[0],p[1]+0.1f,p[2], duRGBA(220,32,16,192));
1306
1369
                } 
1307
1370
                dd.end();
1308
1371