Panda3D
eggScalarTablePointer.cxx
1 // Filename: eggScalarTablePointer.cxx
2 // Created by: drose (18Jul03)
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 "eggScalarTablePointer.h"
16 
17 #include "dcast.h"
18 
19 TypeHandle EggScalarTablePointer::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: EggScalarTablePointer::Constructor
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 EggScalarTablePointer::
27 EggScalarTablePointer(EggObject *object) {
28  _data = DCAST(EggSAnimData, object);
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: EggScalarTablePointer::get_frame_rate
33 // Access: Public, Virtual
34 // Description: Returns the stated frame rate of this particular
35 // joint, or 0.0 if it doesn't state.
36 ////////////////////////////////////////////////////////////////////
38 get_frame_rate() const {
39  if (_data == (EggSAnimData *)NULL || !_data->has_fps()) {
40  return 0.0;
41  } else {
42  return _data->get_fps();
43  }
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: EggScalarTablePointer::get_num_frames
48 // Access: Public, Virtual
49 // Description: Returns the number of frames of animation for this
50 // particular slider.
51 ////////////////////////////////////////////////////////////////////
53 get_num_frames() const {
54  if (_data == (EggSAnimData *)NULL) {
55  return 0;
56  } else {
57  return _data->get_num_rows();
58  }
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: EggScalarTablePointer::extend_to
63 // Access: Public, Virtual
64 // Description: Extends the table to the indicated number of frames.
65 ////////////////////////////////////////////////////////////////////
67 extend_to(int num_frames) {
68  nassertv(_data != (EggSAnimData *)NULL);
69  int num_rows = _data->get_num_rows();
70  double last_value;
71  if (num_rows == 0) {
72  last_value = 0.0;
73  } else {
74  last_value = _data->get_value(num_rows - 1);
75  }
76 
77  while (num_rows < num_frames) {
78  _data->add_data(last_value);
79  num_rows++;
80  }
81 }
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: EggScalarTablePointer::get_frame
85 // Access: Public, Virtual
86 // Description: Returns the value corresponding to this
87 // slider position in the nth frame.
88 ////////////////////////////////////////////////////////////////////
90 get_frame(int n) const {
91  if (get_num_frames() == 1) {
92  // If we have exactly one frame, then we have as many frames as we
93  // want; just repeat the first frame.
94  n = 0;
95  }
96 
97  nassertr(n >= 0 && n < get_num_frames(), 0.0);
98  return _data->get_value(n);
99 }
100 
101 ////////////////////////////////////////////////////////////////////
102 // Function: EggScalarTablePointer::set_name
103 // Access: Public, Virtual
104 // Description: Applies the indicated name change to the egg file.
105 ////////////////////////////////////////////////////////////////////
107 set_name(const string &name) {
108  // Actually, let's not rename the slider table (yet), because we
109  // haven't written the code to rename all of the morph targets.
110 
111  // _data->set_name(name);
112 }
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:28
virtual void set_name(const string &name)
Applies the indicated name change to the egg file.
virtual double get_frame_rate() const
Returns the stated frame rate of this particular joint, or 0.0 if it doesn&#39;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.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
The highest-level base class in the egg directory.
Definition: eggObject.h:31