Panda3D
eggSliderData.cxx
1 // Filename: eggSliderData.cxx
2 // Created by: drose (26Feb01)
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 "eggSliderData.h"
16 #include "eggVertexPointer.h"
17 #include "eggScalarTablePointer.h"
18 #include "eggSliderPointer.h"
19 #include "dcast.h"
20 #include "eggPrimitive.h"
21 #include "eggVertex.h"
22 #include "eggSAnimData.h"
23 #include "indent.h"
24 
25 TypeHandle EggSliderData::_type_handle;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: EggSliderData::Constructor
29 // Access: Public
30 // Description:
31 ////////////////////////////////////////////////////////////////////
32 EggSliderData::
33 EggSliderData(EggCharacterCollection *collection,
34  EggCharacterData *char_data) :
35  EggComponentData(collection, char_data)
36 {
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: EggSliderData::get_frame
41 // Access: Public
42 // Description: Returns the value corresponding to this slider
43 // position in the nth frame in the indicated model.
44 ////////////////////////////////////////////////////////////////////
45 double EggSliderData::
46 get_frame(int model_index, int n) const {
47  EggBackPointer *back = get_model(model_index);
48  if (back == (EggBackPointer *)NULL) {
49  return 0.0;
50  }
51 
52  EggSliderPointer *slider;
53  DCAST_INTO_R(slider, back, 0.0);
54 
55  return slider->get_frame(n);
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: EggSliderData::add_back_pointer
60 // Access: Public, Virtual
61 // Description: Adds the indicated vertex, primitive, or morph table
62 // to the data.
63 ////////////////////////////////////////////////////////////////////
64 void EggSliderData::
65 add_back_pointer(int model_index, EggObject *egg_object) {
66  if (egg_object->is_of_type(EggPrimitive::get_class_type())) {
67  // A primitive!
68  EggBackPointer *back = get_model(model_index);
69  if (back == (EggBackPointer *)NULL) {
70  back = new EggVertexPointer(egg_object);
71  set_model(model_index, back);
72  }
73 
74  } else if (egg_object->is_of_type(EggVertex::get_class_type())) {
75  // A vertex!
76  EggBackPointer *back = get_model(model_index);
77  if (back == (EggBackPointer *)NULL) {
78  back = new EggVertexPointer(egg_object);
79  set_model(model_index, back);
80  }
81 
82  } else if (egg_object->is_of_type(EggSAnimData::get_class_type())) {
83  // A slider animation table! Woo hoo!
84  EggBackPointer *back = get_model(model_index);
85  if (back == (EggBackPointer *)NULL) {
86  back = new EggScalarTablePointer(egg_object);
87  set_model(model_index, back);
88  }
89 
90  } else {
91  nout << "Invalid object added to slider for back pointer.\n";
92  }
93 }
94 
95 ////////////////////////////////////////////////////////////////////
96 // Function: EggSliderData::write
97 // Access: Public, Virtual
98 // Description:
99 ////////////////////////////////////////////////////////////////////
100 void EggSliderData::
101 write(ostream &out, int indent_level) const {
102  indent(out, indent_level)
103  << "Slider " << get_name()
104  << " (models:";
105  int num_models = get_num_models();
106  for (int model_index = 0; model_index < num_models; model_index++) {
107  if (has_model(model_index)) {
108  out << " " << model_index;
109  }
110  }
111  out << ")\n";
112 }
void set_model(int model_index, EggBackPointer *back)
Sets the back_pointer associated with the given model_index.
This stores a pointer back to an EggSAnimData table (i.e.
virtual void add_back_pointer(int model_index, EggObject *egg_object)
Adds the indicated vertex, primitive, or morph table to the data.
int get_num_models() const
Returns the maximum number of back pointers this component may have.
EggBackPointer * get_model(int model_index) const
Returns the back pointer to an egg file for the indicated model if it exists, or NULL if it does not...
This is the base class of both EggJointData and EggSliderData.
This is a base class for EggVertexPointer and EggScalarTablePointer.
Represents a set of characters, as read and collected from possibly several model and/or animation eg...
bool has_model(int model_index) const
Returns true if the component has a back pointer to an egg file somewhere for the indicated model...
Represents a single character, as read and collected from several models and animation files...
double get_frame(int model_index, int n) const
Returns the value corresponding to this slider position in the nth frame in the indicated model...
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition: typedObject.I:63
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This stores a pointer from an EggJointData or EggSliderData object back to the referencing data in an...
The highest-level base class in the egg directory.
Definition: eggObject.h:31
This stores a pointer back to a <Vertex>, or to a particular pritimive like a <Polygon>, representing a morph offset.