26 PStatCollector CollisionCone::_volume_pcollector(
"Collision Volumes:CollisionCone");
27 PStatCollector CollisionCone::_test_pcollector(
"Collision Tests:CollisionCone");
42 xform(
const LMatrix4 &mat) {
43 CollisionSolid::xform(mat);
53 return LPoint3::origin();
62 return _volume_pcollector;
71 return _test_pcollector;
78 output(std::ostream &out)
const {
79 out <<
"ccone, (" << _radius <<
")";
86 compute_internal_bounds()
const {
87 return new BoundingSphere(LPoint3(0, 0, 0), std::max(_radius, _apex[2]) * 2);
96 DCAST_INTO_R(sphere, entry.
get_from(),
nullptr);
98 const LMatrix4 &wrt_mat = entry.get_wrt_mat();
100 LPoint3 from_center = sphere->get_center() * wrt_mat;
101 LVector3 from_radius_v =
102 LVector3(sphere->get_radius(), 0.0f, 0.0f) * wrt_mat;
103 PN_stdfloat from_radius = length(from_radius_v);
106 PN_stdfloat dist_to_line = from_center.get_xy().length();
107 if (dist_to_line > _radius + from_radius) {
111 if (from_center.get_z() > _apex.get_z() + from_radius) {
115 LPlane side(LPoint3(_radius, 1, 0), LPoint3(_radius, 0, 0), _apex);
117 PN_stdfloat dist_bottom = from_center.get_z() + from_radius;
118 PN_stdfloat dist_side = side.dist_to_plane(LPoint3(dist_to_line, 0, from_center.get_z())) + from_radius;
120 std::cerr << dist_side <<
" " << dist_to_line <<
"\n";
123 if (dist_bottom < 0 || dist_side < 0) {
127 if (collide_cat.is_debug()) {
134 LPoint3 surface_point;
135 LVector3 surface_normal;
137 if (dist_bottom < dist_side) {
138 surface_normal = LVector3(0, 0, -1);
139 surface_point = LPoint3(from_center[0], from_center[1], 0);
140 if (dist_to_line > _radius) {
141 surface_point = surface_point * (_radius / dist_to_line);
145 surface_normal = side.get_normal();
146 surface_point = get_apex();
153 new_entry->set_surface_normal(normal);
154 new_entry->set_surface_point(surface_point);
166 if (collide_cat.is_debug()) {
168 <<
"Recomputing viz for " << *
this <<
"\n";
171 static int num_base_vertices = 8;
176 vdata->unclean_set_num_rows(num_base_vertices + 2);
180 double factor = MathNumbers::pi * 2.0 / (double)num_base_vertices;
181 for (
int i = 0; i < num_base_vertices; ++i) {
182 double angle = i * factor;
183 vertex.set_data3(ccos(angle) * _radius, csin(angle) * _radius, 0);
185 vertex.set_data3(0, 0, 0);
186 vertex.set_data3(get_apex());
190 body->add_vertex(num_base_vertices);
192 for (
int i = num_base_vertices - 1; i >= 0; --i) {
195 body->close_primitive();
197 body->add_vertex(num_base_vertices + 1);
198 body->add_consecutive_vertices(0, num_base_vertices);
200 body->close_primitive();
203 border->add_consecutive_vertices(0, num_base_vertices);
204 border->add_vertex(0);
205 border->add_vertex(num_base_vertices + 1);
206 border->add_vertex(num_base_vertices / 2);
207 border->close_primitive();
210 geom1->add_primitive(body);
213 geom2->add_primitive(border);
215 _viz_geom->add_geom(geom1, get_solid_viz_state());
216 _viz_geom->add_geom(geom2, get_wireframe_viz_state());
217 _viz_geom->set_effect(BillboardEffect::make_axis());
219 _bounds_viz_geom->add_geom(geom1, get_solid_bounds_viz_state());
220 _bounds_viz_geom->add_geom(geom2, get_wireframe_bounds_viz_state());
221 _bounds_viz_geom->set_effect(BillboardEffect::make_axis());
242 CollisionSolid::fillin(scan, manager);
256 me->fillin(scan, manager);
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
This defines a bounding sphere, consisting of a center and a radius.
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
This implements a conical solid consisting a circular base with a pointy tip.
virtual LPoint3 get_collision_origin() const
Returns the point in space deemed to be the "origin" of the solid for collision purposes.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Function to write the important information in the particular object to a Datagram.
virtual PStatCollector & get_volume_pcollector()
Returns a PStatCollector that is used to count the number of bounding volume tests made against a sol...
static void register_with_read_factory()
Factory method to generate a CollisionCone object.
virtual PStatCollector & get_test_pcollector()
Returns a PStatCollector that is used to count the number of intersection tests made against a solid ...
virtual void xform(const LMatrix4 &mat)
Transforms the solid by the indicated matrix.
Defines a single collision event.
get_from_node_path
Returns the NodePath that represents the CollisionNode that contains the CollisionSolid that triggere...
get_into_node_path
Returns the NodePath that represents the specific CollisionNode or GeomNode instance that was collide...
get_from
Returns the CollisionSolid pointer for the particular solid that triggered this collision.
The abstract base class for all things that can collide with other things in the world,...
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
bool has_effective_normal() const
Returns true if a special normal was set by set_effective_normal(), false otherwise.
const LVector3 & get_effective_normal() const
Returns the normal that was set by set_effective_normal().
get_respect_effective_normal
See set_respect_effective_normal().
A spherical collision volume or object.
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
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, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Defines a series of line strips.
Defines a series of triangle fans.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
A container for geometry primitives.
A lightweight class that represents a single element that may be timed and/or counted via stats.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PT(BoundingVolume) CollisionCone
Fills the _viz_geom GeomNode up with Geoms suitable for rendering this solid.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.