1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "nel/misc/grid_traversal.h"
20 #include "nel/misc/vector_2f.h"
29 // ********************************************************************************************************************************
30 void CGridTraversal::startTraverse(const NLMISC::CVector2f
&start
, sint
&nextX
, sint
&nextY
)
32 nextX
= (sint
) floorf(start
.x
);
33 nextY
= (sint
) floorf(start
.y
);
36 // ********************************************************************************************************************************
37 bool CGridTraversal::traverse(const NLMISC::CVector2f
&start
, const NLMISC::CVector2f
&dir
, sint
&x
, sint
&y
)
41 float lambdaX
= (x
+ 1.f
- start
.x
) / dir
.x
;
44 float lambdaY
= (y
+ 1 - start
.y
) / dir
.y
;
45 if (lambdaX
< lambdaY
)
47 if (lambdaX
> 1.f
) return false;
53 if (lambdaY
> 1.f
) return false;
60 float lambdaY
= (y
- start
.y
) / dir
.y
;
61 if (lambdaX
< lambdaY
)
63 if (lambdaX
> 1.f
) return false;
69 if (lambdaY
> 1.f
) return false;
75 return x
<= (sint
) floorf(start
.x
+ dir
.x
);
79 float lambdaX
= (x
- start
.x
) / dir
.x
;
82 float lambdaY
= (y
+ 1.f
- start
.y
) / dir
.y
;
83 if (lambdaX
< lambdaY
)
85 if (lambdaX
> 1.f
) return false;
91 if (lambdaY
> 1.f
) return false;
98 float lambdaY
= (y
- start
.y
) / dir
.y
;
99 if (lambdaX
< lambdaY
)
101 if (lambdaX
> 1.f
) return false;
107 if (lambdaY
> 1.f
) return false;
113 return x
>= (sint
) floorf(start
.x
+ dir
.x
);
119 return y
<= (sint
) floorf(start
.y
+ dir
.y
);
122 else if (dir
.y
< 0.f
)
125 return y
>= (sint
) floorf(start
.y
+ dir
.y
);