Panda3D
Loading...
Searching...
No Matches
collisionPolygon.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file collisionPolygon.h
10 * @author drose
11 * @date 2000-04-25
12 */
13
14#ifndef COLLISIONPOLYGON_H
15#define COLLISIONPOLYGON_H
16
17#include "pandabase.h"
18
19#include "collisionPlane.h"
20#include "clipPlaneAttrib.h"
21#include "look_at.h"
22#include "pvector.h"
23
24class GeomNode;
25
26/**
27 *
28 */
29class EXPCL_PANDA_COLLIDE CollisionPolygon : public CollisionPlane {
30PUBLISHED:
31 INLINE CollisionPolygon(const LVecBase3 &a, const LVecBase3 &b,
32 const LVecBase3 &c);
33 INLINE CollisionPolygon(const LVecBase3 &a, const LVecBase3 &b,
34 const LVecBase3 &c, const LVecBase3 &d);
35
36private:
37 INLINE CollisionPolygon();
38
39public:
40 INLINE CollisionPolygon(const LPoint3 *begin, const LPoint3 *end);
42
43 virtual CollisionSolid *make_copy();
44
45 static bool verify_points(const LPoint3 *begin, const LPoint3 *end);
46
47PUBLISHED:
48 virtual LPoint3 get_collision_origin() const;
49
50 INLINE size_t get_num_points() const;
51 INLINE LPoint3 get_point(size_t n) const;
52 MAKE_SEQ(get_points, get_num_points, get_point);
53
54
55 INLINE static bool verify_points(const LPoint3 &a, const LPoint3 &b,
56 const LPoint3 &c);
57 INLINE static bool verify_points(const LPoint3 &a, const LPoint3 &b,
58 const LPoint3 &c, const LPoint3 &d);
59
60 bool is_valid() const;
61 bool is_concave() const;
62
63PUBLISHED:
64 MAKE_SEQ_PROPERTY(points, get_num_points, get_point);
65 MAKE_PROPERTY(valid, is_valid);
66 MAKE_PROPERTY(concave, is_concave);
67
68public:
69 virtual void xform(const LMatrix4 &mat);
70
71 virtual PT(PandaNode) get_viz(const CullTraverser *trav,
72 const CullTraverserData &data,
73 bool bounds_only) const;
74
77
78 virtual void output(std::ostream &out) const;
79 virtual void write(std::ostream &out, int indent_level = 0) const;
80
81 INLINE static void flush_level();
82
83protected:
84 virtual PT(BoundingVolume) compute_internal_bounds() const;
85
86 virtual PT(CollisionEntry)
87 test_intersection_from_sphere(const CollisionEntry &entry) const;
88 virtual PT(CollisionEntry)
89 test_intersection_from_line(const CollisionEntry &entry) const;
90 virtual PT(CollisionEntry)
91 test_intersection_from_ray(const CollisionEntry &entry) const;
92 virtual PT(CollisionEntry)
93 test_intersection_from_segment(const CollisionEntry &entry) const;
94 virtual PT(CollisionEntry)
95 test_intersection_from_capsule(const CollisionEntry &entry) const;
96 virtual PT(CollisionEntry)
97 test_intersection_from_parabola(const CollisionEntry &entry) const;
98 virtual PT(CollisionEntry)
99 test_intersection_from_box(const CollisionEntry &entry) const;
100
101 virtual void fill_viz_geom();
102
103private:
104 INLINE static bool is_right(const LVector2 &v1, const LVector2 &v2);
105 INLINE static PN_stdfloat dist_to_line(const LPoint2 &p,
106 const LPoint2 &f, const LVector2 &v);
107 static PN_stdfloat dist_to_line_segment(const LPoint2 &p,
108 const LPoint2 &f, const LPoint2 &t,
109 const LVector2 &v);
110
111private:
112 class PointDef {
113 public:
114 INLINE PointDef(const LPoint2 &p, const LVector2 &v);
115 INLINE PointDef(PN_stdfloat x, PN_stdfloat y);
116 INLINE PointDef(const PointDef &copy);
117 INLINE void operator = (const PointDef &copy);
118
119 LPoint2 _p; // the point in 2-d space
120 LVector2 _v; // the normalized vector to the next point
121 };
122 typedef pvector<PointDef> Points;
123
124 static void compute_vectors(Points &points);
125 void draw_polygon(GeomNode *viz_geom_node, GeomNode *bounds_viz_geom_node,
126 const Points &points) const;
127
128 bool point_is_inside(const LPoint2 &p, const Points &points) const;
129 PN_stdfloat dist_to_polygon(const LPoint2 &p, const Points &points) const;
130 void project(const LVector3 &axis, PN_stdfloat &center, PN_stdfloat &extent) const;
131
132 void setup_points(const LPoint3 *begin, const LPoint3 *end);
133 INLINE LPoint2 to_2d(const LVecBase3 &point3d) const;
134 INLINE void calc_to_3d_mat(LMatrix4 &to_3d_mat) const;
135 INLINE void rederive_to_3d_mat(LMatrix4 &to_3d_mat) const;
136 INLINE static LPoint3 to_3d(const LVecBase2 &point2d, const LMatrix4 &to_3d_mat);
137 LPoint3 legacy_to_3d(const LVecBase2 &point2d, int axis) const;
138
139 bool clip_polygon(Points &new_points, const Points &source_points,
140 const LPlane &plane) const;
141 bool apply_clip_plane(Points &new_points, const ClipPlaneAttrib *cpa,
142 const TransformState *net_transform) const;
143
144private:
145 Points _points;
146 LMatrix4 _to_2d_mat;
147
148 static PStatCollector _volume_pcollector;
149 static PStatCollector _test_pcollector;
150
151public:
152 static void register_with_read_factory();
153 virtual void write_datagram(BamWriter* manager, Datagram &me);
154
155 static TypedWritable *make_CollisionPolygon(const FactoryParams &params);
156
157protected:
158 void fillin(DatagramIterator& scan, BamReader* manager);
159
160public:
161 static TypeHandle get_class_type() {
162 return _type_handle;
163 }
164 static void init_type() {
165 CollisionPlane::init_type();
166 register_type(_type_handle, "CollisionPolygon",
167 CollisionPlane::get_class_type());
168 }
169 virtual TypeHandle get_type() const {
170 return get_class_type();
171 }
172 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
173
174private:
175 static TypeHandle _type_handle;
176};
177
178#include "collisionPolygon.I"
179
180#endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
This functions similarly to a LightAttrib.
Defines a single collision event.
virtual LPoint3 get_collision_origin() const
Returns the point in space deemed to be the "origin" of the solid for collision purposes.
static void register_with_read_factory()
Factory method to generate a CollisionPlane object.
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
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.
static void flush_level()
Flushes the PStatCollectors used during traversal.
virtual PStatCollector & get_volume_pcollector()
Returns a PStatCollector that is used to count the number of bounding volume tests made against a sol...
The abstract base class for all things that can collide with other things in the world,...
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
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 ...
Definition datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
A node that holds Geom objects, renderable pieces of geometry.
Definition geomNode.h:34
A lightweight class that represents a single element that may be timed and/or counted via stats.
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
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.
bool is_right(const LVector2 &v1, const LVector2 &v2)
Returns true if the 2-d v1 is to the right of v2.
Definition pgItem.cxx:51
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...