23 CollisionBox(
const LPoint3 ¢er, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) :
24 _center(center), _x(x), _y(y), _z(z)
26 _min =
LPoint3(_center.get_x() - _x, _center.get_y() - _y, _center.get_z() - _z);
27 _max =
LPoint3(_center.get_x() + _x, _center.get_y() + _y, _center.get_z() + _z);
28 _radius = sqrt(_x*_x + _y*_y + _z*_z);
29 for(
int v = 0; v < 8; v++)
31 for(
int p = 0; p < 6; p++)
45 _center = (_min + _max) / 2;
46 _x = _center.get_x() - _min.get_x();
47 _y = _center.get_y() - _min.get_y();
48 _z = _center.get_z() - _min.get_z();
49 _radius = sqrt(_x*_x + _y*_y + _z*_z);
50 for(
int v = 0; v < 8; v++)
52 for(
int p = 0; p < 6; p++)
75 _center(copy._center),
81 _radius(copy._radius )
83 for(
int v = 0; v < 8; v++)
84 _vertex[v] = copy._vertex[v];
85 for(
int p = 0; p < 6; p++)
86 _planes[p] = copy._planes[p];
97 _volume_pcollector.flush_level();
98 _test_pcollector.flush_level();
106 INLINE
void CollisionBox::
107 set_center(
const LPoint3 ¢er) {
109 mark_internal_bounds_stale();
118 INLINE
void CollisionBox::
119 set_center(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
128 INLINE
const LPoint3 &CollisionBox::
138 INLINE PN_stdfloat CollisionBox::
177 return LPoint3(a[(n>>2)&1][0], a[(n>>1)&1][1], a[(n)&1][2]);
197 nassertr(n >= 0 && n < 6, LPlane());
208 nassertr(n >= 0 && n < 6, LPlane());
209 return LPlane(
get_point(plane_def[n][0]),
220 INLINE
bool CollisionBox::
222 return (v1[0] * v2[1] - v1[1] * v2[0]) > 1.0e-6f;
233 INLINE PN_stdfloat CollisionBox::
237 return (v1[0] * v[1] - v1[1] * v[0]);
250 return LPoint2(point[0], point[2]);
270 look_at(to_3d_mat, -
get_plane(plane).get_normal(),
271 LVector3(0.0f, 0.0f, 1.0f), CS_zup_right);
302 return LPoint3(point2d[0], 0.0f, point2d[1]) * to_3d_mat;
310 INLINE CollisionBox::PointDef::
319 INLINE CollisionBox::PointDef::
320 PointDef(PN_stdfloat x, PN_stdfloat y) : _p(x, y), _v(0.0f, 0.0f) {
328 INLINE CollisionBox::PointDef::
337 INLINE
void CollisionBox::PointDef::
void rederive_to_3d_mat(LMatrix4 &to_3d_mat, int plane) const
Fills the indicated matrix with the appropriate rotation transform to move points from the 2-d plane ...
void setup_box()
Compute parameters for each of the box's sides.
This is the base class for all three-component vectors and points.
LPoint2 to_2d(const LVecBase3 &point3d, int plane) const
Assuming the indicated point in 3-d space lies within the polygon's plane, returns the corresponding ...
LPoint3 get_point_aabb(int n) const
Returns the nth vertex of the Axis Aligned Bounding Box.
int get_num_points() const
Returns 8: the number of vertices of a rectangular solid.
The abstract base class for all things that can collide with other things in the world, and all the things they can collide with (except geometry).
static const LPoint3f & zero()
Returns a zero-length point.
A cuboid collision volume or object.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
static LPoint3 to_3d(const LVecBase2 &point2d, const LMatrix4 &to_3d_mat)
Extrude the indicated point in the polygon's 2-d definition space back into 3-d coordinates.
LPlane get_plane(int n) const
Returns the nth face of the rectangular solid.
This is a 4-by-4 transform matrix.
bool invert_from(const LMatrix4f &other)
Computes the inverse of the other matrix, and stores the result in this matrix.
This is the base class for all two-component vectors and points.
int get_num_planes() const
Returns 6: the number of faces of a rectangular solid.
static void flush_level()
Flushes the PStatCollectors used during traversal.
This is a two-component vector offset.
void calc_to_3d_mat(LMatrix4 &to_3d_mat, int plane) const
Fills the indicated matrix with the appropriate rotation transform to move points from the 2-d plane ...
void set_row(int row, const LVecBase4f &v)
Replaces the indicated row of the matrix.
LPlane set_plane(int n) const
Creates the nth face of the rectangular solid.
This is a two-component point in space.
LPoint3 get_point(int n) const
Returns the nth vertex of the OBB.
Points get_plane_points(int n)
returns the points that form the nth plane