eggScalarTablePointer.cxx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include "eggScalarTablePointer.h"
  14. #include "dcast.h"
  15. TypeHandle EggScalarTablePointer::_type_handle;
  16. /**
  17. *
  18. */
  19. EggScalarTablePointer::
  20. EggScalarTablePointer(EggObject *object) {
  21. _data = DCAST(EggSAnimData, object);
  22. }
  23. /**
  24. * Returns the stated frame rate of this particular joint, or 0.0 if it
  25. * doesn't state.
  26. */
  27. double EggScalarTablePointer::
  28. get_frame_rate() const {
  29. if (_data == nullptr || !_data->has_fps()) {
  30. return 0.0;
  31. } else {
  32. return _data->get_fps();
  33. }
  34. }
  35. /**
  36. * Returns the number of frames of animation for this particular slider.
  37. */
  38. int EggScalarTablePointer::
  39. get_num_frames() const {
  40. if (_data == nullptr) {
  41. return 0;
  42. } else {
  43. return _data->get_num_rows();
  44. }
  45. }
  46. /**
  47. * Extends the table to the indicated number of frames.
  48. */
  49. void EggScalarTablePointer::
  50. extend_to(int num_frames) {
  51. nassertv(_data != nullptr);
  52. int num_rows = _data->get_num_rows();
  53. double last_value;
  54. if (num_rows == 0) {
  55. last_value = 0.0;
  56. } else {
  57. last_value = _data->get_value(num_rows - 1);
  58. }
  59. while (num_rows < num_frames) {
  60. _data->add_data(last_value);
  61. num_rows++;
  62. }
  63. }
  64. /**
  65. * Returns the value corresponding to this slider position in the nth frame.
  66. */
  67. double EggScalarTablePointer::
  68. get_frame(int n) const {
  69. if (get_num_frames() == 1) {
  70. // If we have exactly one frame, then we have as many frames as we want;
  71. // just repeat the first frame.
  72. n = 0;
  73. }
  74. nassertr(n >= 0 && n < get_num_frames(), 0.0);
  75. return _data->get_value(n);
  76. }
  77. /**
  78. * Applies the indicated name change to the egg file.
  79. */
  80. void EggScalarTablePointer::
  81. set_name(const std::string &name) {
  82. // Actually, let's not rename the slider table (yet), because we haven't
  83. // written the code to rename all of the morph targets.
  84. // _data->set_name(name);
  85. }