19 CollisionBox(
const LPoint3 ¢er, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) :
20 _center(center), _x(x), _y(y), _z(z)
22 _min = LPoint3(_center.get_x() - _x, _center.get_y() - _y, _center.get_z() - _z);
23 _max = LPoint3(_center.get_x() + _x, _center.get_y() + _y, _center.get_z() + _z);
24 _radius = sqrt(_x*_x + _y*_y + _z*_z);
25 for(
int v = 0; v < 8; v++)
27 for(
int p = 0; p < 6; p++)
36 CollisionBox(
const LPoint3 &min,
const LPoint3 &max) :
39 _center = (_min + _max) / 2;
40 _x = _center.get_x() - _min.get_x();
41 _y = _center.get_y() - _min.get_y();
42 _z = _center.get_z() - _min.get_z();
43 _radius = sqrt(_x*_x + _y*_y + _z*_z);
44 for(
int v = 0; v < 8; v++)
46 for(
int p = 0; p < 6; p++)
64 _center(copy._center),
70 _radius(copy._radius )
72 for(
int v = 0; v < 8; v++)
73 _vertex[v] = copy._vertex[v];
74 for(
int p = 0; p < 6; p++)
75 _planes[p] = copy._planes[p];
84 _volume_pcollector.flush_level();
85 _test_pcollector.flush_level();
91 INLINE
void CollisionBox::
92 set_center(
const LPoint3 ¢er) {
94 mark_internal_bounds_stale();
101 INLINE
void CollisionBox::
102 set_center(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
103 set_center(LPoint3(x, y, z));
109 INLINE
const LPoint3 &CollisionBox::
117 INLINE
const LPoint3 &CollisionBox::
125 INLINE
const LPoint3 &CollisionBox::
133 INLINE LVector3 CollisionBox::
134 get_dimensions()
const {
151 nassertr(n >= 0 && n < 8, LPoint3::zero());
161 nassertr(n >= 0 && n < 8, LPoint3::zero());
165 const LPoint3 *a = &_min;
166 return LPoint3(a[(n>>2)&1][0], a[(n>>1)&1][1], a[(n)&1][2]);
182 nassertr(n >= 0 && n < 6, LPlane());
191 nassertr(n >= 0 && n < 6, LPlane());
192 return LPlane(
get_point(plane_def[n][0]),
201 INLINE
bool CollisionBox::
202 is_right(
const LVector2 &v1,
const LVector2 &v2) {
203 return (v1[0] * v2[1] - v1[1] * v2[0]) > 1.0e-6f;
211 INLINE PN_stdfloat CollisionBox::
212 dist_to_line(
const LPoint2 &p,
213 const LPoint2 &f,
const LVector2 &v) {
214 LVector2 v1 = (p - f);
215 return (v1[0] * v[1] - v1[1] * v[0]);
223 to_2d(
const LVecBase3 &point3d,
int plane)
const {
224 LPoint3 point = LPoint3(point3d) * _to_2d_mat[plane];
225 return LPoint2(point[0], point[2]);
241 look_at(to_3d_mat, -
get_plane(plane).get_normal(),
242 LVector3(0.0f, 0.0f, 1.0f), CS_zup_right);
257 to_3d_mat.invert_from(_to_2d_mat[plane]);
265 to_3d(
const LVecBase2 &point2d,
const LMatrix4 &to_3d_mat) {
266 return LPoint3(point2d[0], 0.0f, point2d[1]) * to_3d_mat;
272 INLINE CollisionBox::PointDef::
273 PointDef(
const LPoint2 &p,
const LVector2 &v) : _p(p), _v(v) {
279 INLINE CollisionBox::PointDef::
280 PointDef(PN_stdfloat x, PN_stdfloat y) : _p(x, y), _v(0.0f, 0.0f) {
286 INLINE CollisionBox::PointDef::
293 INLINE
void CollisionBox::PointDef::
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 setup_box()
Compute parameters for each of the box's sides.
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).
A cuboid collision volume or object.
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 ...
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.
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.
int get_num_planes() const
Returns 6: the number of faces of a rectangular solid.
LPlane set_plane(int n) const
Creates the nth face of the rectangular solid.
LPlane get_plane(int n) const
Returns the nth face of the rectangular solid.
static void flush_level()
Flushes the PStatCollectors used during traversal.
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
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 ...