Panda3D
lwoPoints.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 lwoPoints.cxx
10  * @author drose
11  * @date 2001-04-24
12  */
13 
14 #include "lwoPoints.h"
15 #include "lwoInputFile.h"
16 
17 #include "dcast.h"
18 #include "indent.h"
19 
20 TypeHandle LwoPoints::_type_handle;
21 
22 /**
23  * Returns the number of points of this group.
24  */
25 int LwoPoints::
26 get_num_points() const {
27  return _points.size();
28 }
29 
30 /**
31  * Returns the nth point of this group.
32  */
33 const LPoint3 &LwoPoints::
34 get_point(int n) const {
35  nassertr(n >= 0 && n < (int)_points.size(), LPoint3::zero());
36  return _points[n];
37 }
38 
39 /**
40  * Reads the data of the chunk in from the given input file, if possible. The
41  * ID and length of the chunk have already been read. stop_at is the byte
42  * position of the file to stop at (based on the current position at
43  * in->get_bytes_read()). Returns true on success, false otherwise.
44  */
45 bool LwoPoints::
46 read_iff(IffInputFile *in, size_t stop_at) {
47  LwoInputFile *lin = DCAST(LwoInputFile, in);
48 
49  while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
50  LPoint3 point = lin->get_vec3();
51  _points.push_back(point);
52  }
53 
54  return (lin->get_bytes_read() == stop_at);
55 }
56 
57 /**
58  *
59  */
60 void LwoPoints::
61 write(std::ostream &out, int indent_level) const {
62  indent(out, indent_level)
63  << get_id() << " { " << _points.size() << " points }\n";
64 }
int get_num_points() const
Returns the number of points of this group.
Definition: lwoPoints.cxx:26
LVecBase3 get_vec3()
Reads a three-component vector of floats.
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
Definition: iffInputFile.I:44
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const LPoint3 & get_point(int n) const
Returns the nth point of this group.
Definition: lwoPoints.cxx:34
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:46
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:30
A specialization of IffInputFile to handle reading a Lightwave Object file.
Definition: lwoInputFile.h:26
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:25
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool is_eof() const
Returns true if the last read operation failed because of reaching EOF, false otherwise.
Definition: iffInputFile.I:36