Panda3D
lwoPoints.cxx
1 // Filename: lwoPoints.cxx
2 // Created by: drose (24Apr01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "lwoPoints.h"
16 #include "lwoInputFile.h"
17 
18 #include "dcast.h"
19 #include "indent.h"
20 
21 TypeHandle LwoPoints::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: LwoPoints::get_num_points
25 // Access: Public
26 // Description: Returns the number of points of this group.
27 ////////////////////////////////////////////////////////////////////
28 int LwoPoints::
29 get_num_points() const {
30  return _points.size();
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: LwoPoints::get_point
35 // Access: Public
36 // Description: Returns the nth point of this group.
37 ////////////////////////////////////////////////////////////////////
38 const LPoint3 &LwoPoints::
39 get_point(int n) const {
40  nassertr(n >= 0 && n < (int)_points.size(), LPoint3::zero());
41  return _points[n];
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: LwoPoints::read_iff
46 // Access: Public, Virtual
47 // Description: Reads the data of the chunk in from the given input
48 // file, if possible. The ID and length of the chunk
49 // have already been read. stop_at is the byte position
50 // of the file to stop at (based on the current position
51 // at in->get_bytes_read()). Returns true on success,
52 // false otherwise.
53 ////////////////////////////////////////////////////////////////////
54 bool LwoPoints::
55 read_iff(IffInputFile *in, size_t stop_at) {
56  LwoInputFile *lin = DCAST(LwoInputFile, in);
57 
58  while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
59  LPoint3 point = lin->get_vec3();
60  _points.push_back(point);
61  }
62 
63  return (lin->get_bytes_read() == stop_at);
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: LwoPoints::write
68 // Access: Public, Virtual
69 // Description:
70 ////////////////////////////////////////////////////////////////////
71 void LwoPoints::
72 write(ostream &out, int indent_level) const {
73  indent(out, indent_level)
74  << get_id() << " { " << _points.size() << " points }\n";
75 }
int get_num_points() const
Returns the number of points of this group.
Definition: lwoPoints.cxx:29
LVecBase3 get_vec3()
Reads a three-component vector of floats.
static const LPoint3f & zero()
Returns a zero-length point.
Definition: lpoint3.h:259
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
Definition: iffInputFile.I:56
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
const LPoint3 & get_point(int n) const
Returns the nth point of this group.
Definition: lwoPoints.cxx:39
virtual bool read_iff(IffInputFile *in, size_t stop_at)
Reads the data of the chunk in from the given input file, if possible.
Definition: lwoPoints.cxx:55
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:33
A specialization of IffInputFile to handle reading a Lightwave Object file.
Definition: lwoInputFile.h:29
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:31
bool is_eof() const
Returns true if the last read operation failed because of reaching EOF, false otherwise.
Definition: iffInputFile.I:45