17 INLINE CollisionPolygon::
18 CollisionPolygon(
const LVecBase3 &a,
const LVecBase3 &b,
24 setup_points(array, array + 3);
30 INLINE CollisionPolygon::
31 CollisionPolygon(
const LVecBase3 &a,
const LVecBase3 &b,
32 const LVecBase3 &c,
const LVecBase3 &d) {
38 setup_points(array, array + 4);
45 INLINE CollisionPolygon::
46 CollisionPolygon(
const LPoint3 *begin,
const LPoint3 *end) {
47 setup_points(begin, end);
53 INLINE CollisionPolygon::
60 INLINE
size_t CollisionPolygon::
61 get_num_points()
const {
62 return _points.size();
70 nassertr(n < _points.size(), LPoint3::zero());
72 rederive_to_3d_mat(to_3d_mat);
73 return to_3d(_points[n]._p, to_3d_mat);
98 const LPoint3 &c,
const LPoint3 &d) {
112 _volume_pcollector.flush_level();
113 _test_pcollector.flush_level();
119 INLINE
bool CollisionPolygon::
120 is_right(
const LVector2 &v1,
const LVector2 &v2) {
121 return (v1[0] * v2[1] - v1[1] * v2[0]) > 1.0e-6f;
129 INLINE PN_stdfloat CollisionPolygon::
130 dist_to_line(
const LPoint2 &p,
131 const LPoint2 &f,
const LVector2 &v) {
132 LVector2 v1 = (p - f);
133 return (v1[0] * v[1] - v1[1] * v[0]);
140 INLINE LPoint2 CollisionPolygon::
141 to_2d(
const LVecBase3 &point3d)
const {
142 LPoint3 point = LPoint3(point3d) * _to_2d_mat;
143 return LPoint2(point[0], point[2]);
150 INLINE
void CollisionPolygon::
151 calc_to_3d_mat(LMatrix4 &to_3d_mat)
const {
159 look_at(to_3d_mat, -get_plane().get_normal(),
160 LVector3(0.0f, 0.0f, 1.0f), CS_zup_right);
161 to_3d_mat.set_row(3, get_plane().
get_point());
173 INLINE
void CollisionPolygon::
174 rederive_to_3d_mat(LMatrix4 &to_3d_mat)
const {
175 to_3d_mat.invert_from(_to_2d_mat);
182 INLINE LPoint3 CollisionPolygon::
183 to_3d(
const LVecBase2 &point2d,
const LMatrix4 &to_3d_mat) {
184 return LPoint3(point2d[0], 0.0f, point2d[1]) * to_3d_mat;
190 INLINE CollisionPolygon::PointDef::
191 PointDef(
const LPoint2 &p,
const LVector2 &v) : _p(p), _v(v) {
197 INLINE CollisionPolygon::PointDef::
198 PointDef(PN_stdfloat x, PN_stdfloat y) : _p(x, y), _v(0.0f, 0.0f) {
204 INLINE CollisionPolygon::PointDef::
205 PointDef(
const CollisionPolygon::PointDef ©) : _p(copy._p), _v(copy._v) {
211 INLINE
void CollisionPolygon::PointDef::
212 operator = (
const CollisionPolygon::PointDef ©) {
static bool verify_points(const LPoint3 &a, const LPoint3 &b, const LPoint3 &c)
Verifies that the indicated set of points will define a valid CollisionPolygon: that is,...
get_point
Returns the nth vertex of the CollisionPolygon, expressed in 3-D space.
static void flush_level()
Flushes the PStatCollectors used during traversal.