Panda3D
collisionLine.cxx
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 collisionLine.cxx
10  * @author drose
11  * @date 2005-01-05
12  */
13 
14 #include "collisionLine.h"
15 #include "collisionHandler.h"
16 #include "collisionEntry.h"
17 #include "config_collide.h"
18 #include "geom.h"
19 #include "geomNode.h"
20 #include "boundingLine.h"
21 #include "lensNode.h"
22 #include "lens.h"
23 #include "datagram.h"
24 #include "datagramIterator.h"
25 #include "bamReader.h"
26 #include "bamWriter.h"
27 #include "geom.h"
28 #include "geomLinestrips.h"
29 #include "geomVertexWriter.h"
30 
31 TypeHandle CollisionLine::_type_handle;
32 
33 
34 /**
35  *
36  */
37 CollisionSolid *CollisionLine::
38 make_copy() {
39  return new CollisionLine(*this);
40 }
41 
42 /**
43  *
44  */
45 PT(CollisionEntry) CollisionLine::
46 test_intersection(const CollisionEntry &entry) const {
47  return entry.get_into()->test_intersection_from_line(entry);
48 }
49 
50 /**
51  *
52  */
53 void CollisionLine::
54 output(std::ostream &out) const {
55  out << "line, o (" << get_origin() << "), d (" << get_direction() << ")";
56 }
57 
58 /**
59  * Fills the _viz_geom GeomNode up with Geoms suitable for rendering this
60  * solid.
61  */
62 void CollisionLine::
63 fill_viz_geom() {
64  if (collide_cat.is_debug()) {
65  collide_cat.debug()
66  << "Recomputing viz for " << *this << "\n";
67  }
68 
69  static const int num_points = 100;
70  static const double scale = 100.0;
71 
72  PT(GeomVertexData) vdata = new GeomVertexData
73  ("collision", GeomVertexFormat::get_v3cp(),
74  Geom::UH_static);
75  GeomVertexWriter vertex(vdata, InternalName::get_vertex());
76  GeomVertexWriter color(vdata, InternalName::get_color());
77 
78  for (int i = 0; i < num_points; i++) {
79  double t = ((double)i / (double)num_points - 0.5) * 2.0;
80  vertex.add_data3(get_origin() + t * scale * get_direction());
81 
82  color.add_data4(LColor(1.0f, 1.0f, 1.0f, 1.0f) +
83  fabs(t) * LColor(0.0f, 0.0f, 0.0f, -1.0f));
84  }
85 
86  PT(GeomLinestrips) line = new GeomLinestrips(Geom::UH_static);
87  line->add_next_vertices(num_points);
88  line->close_primitive();
89 
90  PT(Geom) geom = new Geom(vdata);
91  geom->add_primitive(line);
92 
93  _viz_geom->add_geom(geom, get_other_viz_state());
94  _bounds_viz_geom->add_geom(geom, get_other_bounds_viz_state());
95 }
96 
97 /**
98  * Tells the BamReader how to create objects of type CollisionLine.
99  */
102  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
103 }
104 
105 /**
106  * Writes the contents of this object to the datagram for shipping out to a
107  * Bam file.
108  */
110 write_datagram(BamWriter *manager, Datagram &dg) {
111  CollisionRay::write_datagram(manager, dg);
112 }
113 
114 /**
115  * This function is called by the BamReader's factory when a new object of
116  * type CollisionLine is encountered in the Bam file. It should create the
117  * CollisionLine and extract its information from the file.
118  */
119 TypedWritable *CollisionLine::
120 make_from_bam(const FactoryParams &params) {
121  CollisionLine *node = new CollisionLine();
122  DatagramIterator scan;
123  BamReader *manager;
124 
125  parse_params(params, scan, manager);
126  node->fillin(scan, manager);
127 
128  return node;
129 }
130 
131 /**
132  * This internal function is called by make_from_bam to read in all of the
133  * relevant data from the BamFile for the new CollisionLine.
134  */
135 void CollisionLine::
136 fillin(DatagramIterator &scan, BamReader *manager) {
137  CollisionRay::fillin(scan, manager);
138 }
Geom
A container for geometry primitives.
Definition: geom.h:54
geomVertexWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GeomVertexData
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
Definition: geomVertexData.h:68
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
CollisionEntry
Defines a single collision event.
Definition: collisionEntry.h:42
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
GeomVertexWriter
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
Definition: geomVertexWriter.h:55
collisionLine.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CollisionLine
An infinite line, similar to a CollisionRay, except that it extends in both directions.
Definition: collisionLine.h:25
BamReader::get_factory
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
bamReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GeomLinestrips
Defines a series of line strips.
Definition: geomLinestrips.h:23
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
boundingLine.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
collisionHandler.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CollisionLine::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: collisionLine.cxx:110
CollisionLine::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type CollisionLine.
Definition: collisionLine.cxx:101
datagram.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
geom.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Factory::register_factory
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:73
CollisionSolid
The abstract base class for all things that can collide with other things in the world,...
Definition: collisionSolid.h:45
collisionEntry.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lensNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
geomLinestrips.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CollisionEntry::get_into
get_into
Returns the CollisionSolid pointer for the particular solid was collided into.
Definition: collisionEntry.h:98
datagramIterator.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
geomNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
config_collide.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CollisionLine::CollisionLine
CollisionLine()
Creates an invalid line.
Definition: collisionLine.I:20
bamWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GeomVertexFormat::get_v3cp
static const GeomVertexFormat * get_v3cp()
Returns a standard vertex format with a packed color and a 3-component vertex position.
Definition: geomVertexFormat.I:287
parse_params
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition: bamReader.I:275
CollisionRay::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: collisionRay.cxx:168
PT
PT(CollisionEntry) CollisionLine
Fills the _viz_geom GeomNode up with Geoms suitable for rendering this solid.
Definition: collisionLine.cxx:45
lens.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.