Panda3D
|
00001 // Filename: collisionLine.cxx 00002 // Created by: drose (05Jan05) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 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 // Function: CollisionLine::make_copy 00037 // Access: Public, Virtual 00038 // Description: 00039 //////////////////////////////////////////////////////////////////// 00040 CollisionSolid *CollisionLine:: 00041 make_copy() { 00042 return new CollisionLine(*this); 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function: CollisionLine::test_intersection 00047 // Access: Public, Virtual 00048 // Description: 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 // Function: CollisionLine::output 00057 // Access: Public, Virtual 00058 // Description: 00059 //////////////////////////////////////////////////////////////////// 00060 void CollisionLine:: 00061 output(ostream &out) const { 00062 out << "line, o (" << get_origin() << "), d (" << get_direction() << ")"; 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: CollisionLine::fill_viz_geom 00067 // Access: Protected, Virtual 00068 // Description: Fills the _viz_geom GeomNode up with Geoms suitable 00069 // for rendering this solid. 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 // Function: CollisionLine::register_with_read_factory 00108 // Access: Public, Static 00109 // Description: Tells the BamReader how to create objects of type 00110 // CollisionLine. 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 // Function: CollisionLine::write_datagram 00119 // Access: Public, Virtual 00120 // Description: Writes the contents of this object to the datagram 00121 // for shipping out to a Bam file. 00122 //////////////////////////////////////////////////////////////////// 00123 void CollisionLine:: 00124 write_datagram(BamWriter *manager, Datagram &dg) { 00125 CollisionRay::write_datagram(manager, dg); 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: CollisionLine::make_from_bam 00130 // Access: Protected, Static 00131 // Description: This function is called by the BamReader's factory 00132 // when a new object of type CollisionLine is encountered 00133 // in the Bam file. It should create the CollisionLine 00134 // and extract its information from the file. 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 // Function: CollisionLine::fillin 00150 // Access: Protected 00151 // Description: This internal function is called by make_from_bam to 00152 // read in all of the relevant data from the BamFile for 00153 // the new CollisionLine. 00154 //////////////////////////////////////////////////////////////////// 00155 void CollisionLine:: 00156 fillin(DatagramIterator &scan, BamReader *manager) { 00157 CollisionRay::fillin(scan, manager); 00158 }