00001 // Filename: lwoPoints.cxx 00002 // Created by: drose (24Apr01) 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 "lwoPoints.h" 00016 #include "lwoInputFile.h" 00017 00018 #include "dcast.h" 00019 #include "indent.h" 00020 00021 TypeHandle LwoPoints::_type_handle; 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: LwoPoints::get_num_points 00025 // Access: Public 00026 // Description: Returns the number of points of this group. 00027 //////////////////////////////////////////////////////////////////// 00028 int LwoPoints:: 00029 get_num_points() const { 00030 return _points.size(); 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: LwoPoints::get_point 00035 // Access: Public 00036 // Description: Returns the nth point of this group. 00037 //////////////////////////////////////////////////////////////////// 00038 const LPoint3 &LwoPoints:: 00039 get_point(int n) const { 00040 nassertr(n >= 0 && n < (int)_points.size(), LPoint3::zero()); 00041 return _points[n]; 00042 } 00043 00044 //////////////////////////////////////////////////////////////////// 00045 // Function: LwoPoints::read_iff 00046 // Access: Public, Virtual 00047 // Description: Reads the data of the chunk in from the given input 00048 // file, if possible. The ID and length of the chunk 00049 // have already been read. stop_at is the byte position 00050 // of the file to stop at (based on the current position 00051 // at in->get_bytes_read()). Returns true on success, 00052 // false otherwise. 00053 //////////////////////////////////////////////////////////////////// 00054 bool LwoPoints:: 00055 read_iff(IffInputFile *in, size_t stop_at) { 00056 LwoInputFile *lin = DCAST(LwoInputFile, in); 00057 00058 while (lin->get_bytes_read() < stop_at && !lin->is_eof()) { 00059 LPoint3 point = lin->get_vec3(); 00060 _points.push_back(point); 00061 } 00062 00063 return (lin->get_bytes_read() == stop_at); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: LwoPoints::write 00068 // Access: Public, Virtual 00069 // Description: 00070 //////////////////////////////////////////////////////////////////// 00071 void LwoPoints:: 00072 write(ostream &out, int indent_level) const { 00073 indent(out, indent_level) 00074 << get_id() << " { " << _points.size() << " points }\n"; 00075 }