16 #include "collisionSegment.h"
17 #include "collisionHandler.h"
18 #include "collisionEntry.h"
19 #include "config_collide.h"
24 #include "geometricBoundingVolume.h"
26 #include "datagramIterator.h"
27 #include "bamReader.h"
28 #include "bamWriter.h"
30 #include "geomLines.h"
31 #include "boundingSphere.h"
32 #include "boundingHexahedron.h"
33 #include "geomVertexWriter.h"
56 return entry.get_into()->test_intersection_from_segment(entry);
90 void CollisionSegment::
91 output(ostream &out)
const {
92 out <<
"segment, a (" << _a <<
"), b (" << _b <<
")";
112 if (!proj->
extrude(point, _a, _b)) {
118 mark_internal_bounds_stale();
130 compute_internal_bounds()
const {
137 if (d2 < collision_parabola_bounds_threshold * collision_parabola_bounds_threshold) {
138 LPoint3 pmid = (_a + _b) * 0.5f;
143 look_at(from_segment, pdelta,
LPoint3(0,0,1), CS_zup_right);
146 PN_stdfloat max_y = sqrt(d2) + 0.01;
149 LPoint3(0.01, max_y, 0.01), LPoint3(-0.01, max_y, 0.01),
150 LPoint3(-0.01, -0.01, -0.01), LPoint3(0.01, 0.01, -0.01),
151 LPoint3(0.01, -0.01, 0.01), LPoint3(-0.01, -0.01, 0.01));
153 volume->xform(from_segment);
165 if (collide_cat.is_debug()) {
167 <<
"Recomputing viz for " << *
this <<
"\n";
171 ("collision", GeomVertexFormat::get_v3cp(),
175 vertex.add_data3(_a);
176 vertex.add_data3(_b);
179 line->add_next_vertices(2);
180 line->close_primitive();
183 geom->add_primitive(line);
185 _viz_geom->add_geom(geom, get_other_viz_state());
186 _bounds_viz_geom->add_geom(geom, get_other_bounds_viz_state());
196 register_with_read_factory() {
209 _a.write_datagram(dg);
227 parse_params(params, scan, manager);
228 node->fillin(scan, manager);
240 void CollisionSegment::
242 CollisionSolid::fillin(scan, manager);
243 _a.read_datagram(scan);
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
bool set_from_lens(LensNode *camera, const LPoint2 &point)
Accepts a LensNode and a 2-d point in the range [-1,1].
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
A base class for any number of different kinds of lenses, linear and otherwise.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void read_datagram(DatagramIterator &source)
Reads the vector from the Datagram using get_stdfloat().
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 node that contains a Lens.
CollisionSegment()
Creates an invalid segment.
This defines a bounding sphere, consisting of a center and a radius.
virtual void xform(const LMatrix4 &mat)
Transforms the solid by the indicated matrix.
Base class for objects that can be written to and read from Bam files.
float length_squared() const
Returns the square of the vector's length, cheap and easy.
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 ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
static const LPoint3f & origin(CoordinateSystem cs=CS_default)
Returns the origin of the indicated coordinate system.
static LVector3f forward(CoordinateSystem cs=CS_default)
Returns the forward vector for the given coordinate system.
bool extrude(const LPoint2 &point2d, LPoint3 &near_point, LPoint3 &far_point) const
Given a 2-d point in the range (-1,1) in both dimensions, where (0,0) is the center of the lens and (...
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
A finite line segment, with two specific endpoints but no thickness.
This is a 4-by-4 transform matrix.
Defines a single collision event.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Defines a series of disconnected line segments.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
virtual void xform(const LMatrix4 &mat)
Transforms the solid by the indicated matrix.
void set_row(int row, const LVecBase4f &v)
Replaces the indicated row of the matrix.
A class to retrieve the individual data elements previously stored in a Datagram. ...
This is a two-component point in space.
virtual LPoint3 get_collision_origin() const
Returns the point in space deemed to be the "origin" of the solid for collision purposes.
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void write_datagram(Datagram &destination) const
Writes the vector to the Datagram using add_stdfloat().
This defines a bounding convex hexahedron.
Lens * get_lens(int index=0) const
Returns a pointer to the particular Lens associated with this LensNode, or NULL if there is not yet a...