Panda3D
eggScalarTablePointer.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 eggScalarTablePointer.cxx
10  * @author drose
11  * @date 2003-07-18
12  */
13 
14 #include "eggScalarTablePointer.h"
15 
16 #include "dcast.h"
17 
18 TypeHandle EggScalarTablePointer::_type_handle;
19 
20 /**
21  *
22  */
23 EggScalarTablePointer::
24 EggScalarTablePointer(EggObject *object) {
25  _data = DCAST(EggSAnimData, object);
26 }
27 
28 /**
29  * Returns the stated frame rate of this particular joint, or 0.0 if it
30  * doesn't state.
31  */
33 get_frame_rate() const {
34  if (_data == nullptr || !_data->has_fps()) {
35  return 0.0;
36  } else {
37  return _data->get_fps();
38  }
39 }
40 
41 /**
42  * Returns the number of frames of animation for this particular slider.
43  */
45 get_num_frames() const {
46  if (_data == nullptr) {
47  return 0;
48  } else {
49  return _data->get_num_rows();
50  }
51 }
52 
53 /**
54  * Extends the table to the indicated number of frames.
55  */
57 extend_to(int num_frames) {
58  nassertv(_data != nullptr);
59  int num_rows = _data->get_num_rows();
60  double last_value;
61  if (num_rows == 0) {
62  last_value = 0.0;
63  } else {
64  last_value = _data->get_value(num_rows - 1);
65  }
66 
67  while (num_rows < num_frames) {
68  _data->add_data(last_value);
69  num_rows++;
70  }
71 }
72 
73 /**
74  * Returns the value corresponding to this slider position in the nth frame.
75  */
77 get_frame(int n) const {
78  if (get_num_frames() == 1) {
79  // If we have exactly one frame, then we have as many frames as we want;
80  // just repeat the first frame.
81  n = 0;
82  }
83 
84  nassertr(n >= 0 && n < get_num_frames(), 0.0);
85  return _data->get_value(n);
86 }
87 
88 /**
89  * Applies the indicated name change to the egg file.
90  */
92 set_name(const std::string &name) {
93  // Actually, let's not rename the slider table (yet), because we haven't
94  // written the code to rename all of the morph targets.
95 
96  // _data->set_name(name);
97 }
virtual void set_name(const std::string &name)
Applies the indicated name change to the egg file.
virtual void extend_to(int num_frames)
Extends the table to the indicated number of frames.
Corresponding to an <S$Anim> entry, this stores a single column of numbers, for instance for a morph ...
Definition: eggSAnimData.h:25
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual double get_frame_rate() const
Returns the stated frame rate of this particular joint, or 0.0 if it doesn't state.
virtual double get_frame(int n) const
Returns the value corresponding to this slider position in the nth frame.
virtual int get_num_frames() const
Returns the number of frames of animation for this particular slider.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
The highest-level base class in the egg directory.
Definition: eggObject.h:29