Panda3D

eggScalarTablePointer.cxx

00001 // Filename: eggScalarTablePointer.cxx
00002 // Created by:  drose (18Jul03)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "eggScalarTablePointer.h"
00016 
00017 #include "dcast.h"
00018 
00019 TypeHandle EggScalarTablePointer::_type_handle;
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: EggScalarTablePointer::Constructor
00023 //       Access: Public
00024 //  Description:
00025 ////////////////////////////////////////////////////////////////////
00026 EggScalarTablePointer::
00027 EggScalarTablePointer(EggObject *object) {
00028   _data = DCAST(EggSAnimData, object);
00029 }
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //     Function: EggScalarTablePointer::get_frame_rate
00033 //       Access: Public, Virtual
00034 //  Description: Returns the stated frame rate of this particular
00035 //               joint, or 0.0 if it doesn't state.
00036 ////////////////////////////////////////////////////////////////////
00037 double EggScalarTablePointer::
00038 get_frame_rate() const {
00039   if (_data == (EggSAnimData *)NULL || !_data->has_fps()) {
00040     return 0.0;
00041   } else {
00042     return _data->get_fps();
00043   }
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: EggScalarTablePointer::get_num_frames
00048 //       Access: Public, Virtual
00049 //  Description: Returns the number of frames of animation for this
00050 //               particular slider.
00051 ////////////////////////////////////////////////////////////////////
00052 int EggScalarTablePointer::
00053 get_num_frames() const {
00054   if (_data == (EggSAnimData *)NULL) {
00055     return 0;
00056   } else {
00057     return _data->get_num_rows();
00058   }
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: EggScalarTablePointer::extend_to
00063 //       Access: Public, Virtual
00064 //  Description: Extends the table to the indicated number of frames.
00065 ////////////////////////////////////////////////////////////////////
00066 void EggScalarTablePointer::
00067 extend_to(int num_frames) {
00068   nassertv(_data != (EggSAnimData *)NULL);
00069   int num_rows = _data->get_num_rows();
00070   double last_value;
00071   if (num_rows == 0) {
00072     last_value = 0.0;
00073   } else {
00074     last_value = _data->get_value(num_rows - 1);
00075   }
00076 
00077   while (num_rows < num_frames) {
00078     _data->add_data(last_value);
00079     num_rows++;
00080   }
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: EggScalarTablePointer::get_frame
00085 //       Access: Public, Virtual
00086 //  Description: Returns the value corresponding to this
00087 //               slider position in the nth frame.
00088 ////////////////////////////////////////////////////////////////////
00089 double EggScalarTablePointer::
00090 get_frame(int n) const {
00091   if (get_num_frames() == 1) {
00092     // If we have exactly one frame, then we have as many frames as we
00093     // want; just repeat the first frame.
00094     n = 0;
00095   }
00096 
00097   nassertr(n >= 0 && n < get_num_frames(), 0.0);
00098   return _data->get_value(n);
00099 }
00100 
00101 ////////////////////////////////////////////////////////////////////
00102 //     Function: EggScalarTablePointer::set_name
00103 //       Access: Public, Virtual
00104 //  Description: Applies the indicated name change to the egg file.
00105 ////////////////////////////////////////////////////////////////////
00106 void EggScalarTablePointer::
00107 set_name(const string &name) {
00108   // Actually, let's not rename the slider table (yet), because we
00109   // haven't written the code to rename all of the morph targets.
00110 
00111   //  _data->set_name(name);
00112 }
 All Classes Functions Variables Enumerations