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/plane.h"
20 #include "nel/misc/uv.h"
30 //============================================================
31 void CPlane::make(const CVector
&normal
, const CVector
&p
)
33 CVector v
= normal
.normed();
37 d
=-(v
*p
); // d=- (ax+by+cz).
39 void CPlane::make(const CVector
&p0
, const CVector
&p1
, const CVector
&p2
)
48 //============================================================
49 bool CPlane::clipSegmentBack(CVector
&p0
, CVector
&p1
) const
61 decal
= (0-d0
) / (d1
-d0
);
62 proj
= p0
+ (p1
-p0
)*decal
;
69 bool CPlane::clipSegmentFront(CVector
&p0
, CVector
&p1
) const
81 decal
= (0-d0
) / (d1
-d0
);
82 proj
= p0
+ (p1
-p0
)*decal
;
90 //============================================================
91 sint
CPlane::clipPolygonBack(CVector in
[], CVector out
[], sint nIn
) const
101 if ( (*this)*in
[p
] < 0 )
103 if ( (*this)*in
[s
] >= 0 )
104 out
[nOut
++]= intersect(in
[s
],in
[p
]);
109 if ( (*this)*in
[s
] < 0 )
110 out
[nOut
++]= intersect(in
[s
],in
[p
]);
118 //============================================================
119 sint
CPlane::clipPolygonBack(const CVector in
[], const CUV inUV
[], CVector out
[], CUV outUV
[], sint nIn
) const
129 float dp3Curr
= (*this)*in
[p
];
130 float dp3Prev
= (*this)*in
[s
];
135 float lambda
= favoid0((float) ((double) dp3Prev
/ ((double) dp3Prev
- (double) dp3Curr
)));
136 out
[nOut
] = blend(in
[s
], in
[p
], lambda
);
137 outUV
[nOut
++] = blend(inUV
[s
], inUV
[p
], lambda
);
140 outUV
[nOut
++]=inUV
[p
];
146 float lambda
= favoid0((float) ((double) dp3Prev
/ ((double) dp3Prev
- (double) dp3Curr
)));
147 out
[nOut
] = blend(in
[s
], in
[p
], lambda
);
148 outUV
[nOut
++] = blend(inUV
[s
], inUV
[p
], lambda
);
157 //============================================================
158 sint
CPlane::clipPolygonFront(CVector in
[], CVector out
[], sint nIn
) const
168 if ( (*this)*in
[p
] > 0 )
170 if ( (*this)*in
[s
] <= 0 )
171 out
[nOut
++]= intersect(in
[s
],in
[p
]);
176 if ( (*this)*in
[s
] > 0 )
177 out
[nOut
++]= intersect(in
[s
],in
[p
]);
186 //============================================================
187 CPlane
CPlane::inverted() const
189 return CPlane(-a
, -b
, -c
, -d
);
192 //============================================================
193 void CPlane::invert()