00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "collisionLine.h"
00016 #include "collisionHandler.h"
00017 #include "collisionEntry.h"
00018 #include "config_collide.h"
00019 #include "geom.h"
00020 #include "geomNode.h"
00021 #include "boundingLine.h"
00022 #include "lensNode.h"
00023 #include "lens.h"
00024 #include "datagram.h"
00025 #include "datagramIterator.h"
00026 #include "bamReader.h"
00027 #include "bamWriter.h"
00028 #include "geom.h"
00029 #include "geomLinestrips.h"
00030 #include "geomVertexWriter.h"
00031
00032 TypeHandle CollisionLine::_type_handle;
00033
00034
00035
00036
00037
00038
00039
00040 CollisionSolid *CollisionLine::
00041 make_copy() {
00042 return new CollisionLine(*this);
00043 }
00044
00045
00046
00047
00048
00049
00050 PT(CollisionEntry) CollisionLine::
00051 test_intersection(const CollisionEntry &entry) const {
00052 return entry.get_into()->test_intersection_from_line(entry);
00053 }
00054
00055
00056
00057
00058
00059
00060 void CollisionLine::
00061 output(ostream &out) const {
00062 out << "line, o (" << get_origin() << "), d (" << get_direction() << ")";
00063 }
00064
00065
00066
00067
00068
00069
00070
00071 void CollisionLine::
00072 fill_viz_geom() {
00073 if (collide_cat.is_debug()) {
00074 collide_cat.debug()
00075 << "Recomputing viz for " << *this << "\n";
00076 }
00077
00078 static const int num_points = 100;
00079 static const double scale = 100.0;
00080
00081 PT(GeomVertexData) vdata = new GeomVertexData
00082 ("collision", GeomVertexFormat::get_v3cp(),
00083 Geom::UH_static);
00084 GeomVertexWriter vertex(vdata, InternalName::get_vertex());
00085 GeomVertexWriter color(vdata, InternalName::get_color());
00086
00087 for (int i = 0; i < num_points; i++) {
00088 double t = ((double)i / (double)num_points - 0.5) * 2.0;
00089 vertex.add_data3(get_origin() + t * scale * get_direction());
00090
00091 color.add_data4(LColor(1.0f, 1.0f, 1.0f, 1.0f) +
00092 fabs(t) * LColor(0.0f, 0.0f, 0.0f, -1.0f));
00093 }
00094
00095 PT(GeomLinestrips) line = new GeomLinestrips(Geom::UH_static);
00096 line->add_next_vertices(num_points);
00097 line->close_primitive();
00098
00099 PT(Geom) geom = new Geom(vdata);
00100 geom->add_primitive(line);
00101
00102 _viz_geom->add_geom(geom, get_other_viz_state());
00103 _bounds_viz_geom->add_geom(geom, get_other_bounds_viz_state());
00104 }
00105
00106
00107
00108
00109
00110
00111
00112 void CollisionLine::
00113 register_with_read_factory() {
00114 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00115 }
00116
00117
00118
00119
00120
00121
00122
00123 void CollisionLine::
00124 write_datagram(BamWriter *manager, Datagram &dg) {
00125 CollisionRay::write_datagram(manager, dg);
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 TypedWritable *CollisionLine::
00137 make_from_bam(const FactoryParams ¶ms) {
00138 CollisionLine *node = new CollisionLine();
00139 DatagramIterator scan;
00140 BamReader *manager;
00141
00142 parse_params(params, scan, manager);
00143 node->fillin(scan, manager);
00144
00145 return node;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155 void CollisionLine::
00156 fillin(DatagramIterator &scan, BamReader *manager) {
00157 CollisionRay::fillin(scan, manager);
00158 }