Panda3D
eggSliderData.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 eggSliderData.cxx
10  * @author drose
11  * @date 2001-02-26
12  */
13 
14 #include "eggSliderData.h"
15 #include "eggVertexPointer.h"
16 #include "eggScalarTablePointer.h"
17 #include "eggSliderPointer.h"
18 #include "dcast.h"
19 #include "eggPrimitive.h"
20 #include "eggVertex.h"
21 #include "eggSAnimData.h"
22 #include "indent.h"
23 
24 TypeHandle EggSliderData::_type_handle;
25 
26 /**
27  *
28  */
29 EggSliderData::
30 EggSliderData(EggCharacterCollection *collection,
31  EggCharacterData *char_data) :
32  EggComponentData(collection, char_data)
33 {
34 }
35 
36 /**
37  * Returns the value corresponding to this slider position in the nth frame in
38  * the indicated model.
39  */
40 double EggSliderData::
41 get_frame(int model_index, int n) const {
42  EggBackPointer *back = get_model(model_index);
43  if (back == nullptr) {
44  return 0.0;
45  }
46 
47  EggSliderPointer *slider;
48  DCAST_INTO_R(slider, back, 0.0);
49 
50  return slider->get_frame(n);
51 }
52 
53 /**
54  * Adds the indicated vertex, primitive, or morph table to the data.
55  */
56 void EggSliderData::
57 add_back_pointer(int model_index, EggObject *egg_object) {
58  if (egg_object->is_of_type(EggPrimitive::get_class_type())) {
59  // A primitive!
60  EggBackPointer *back = get_model(model_index);
61  if (back == nullptr) {
62  back = new EggVertexPointer(egg_object);
63  set_model(model_index, back);
64  }
65 
66  } else if (egg_object->is_of_type(EggVertex::get_class_type())) {
67  // A vertex!
68  EggBackPointer *back = get_model(model_index);
69  if (back == nullptr) {
70  back = new EggVertexPointer(egg_object);
71  set_model(model_index, back);
72  }
73 
74  } else if (egg_object->is_of_type(EggSAnimData::get_class_type())) {
75  // A slider animation table! Woo hoo!
76  EggBackPointer *back = get_model(model_index);
77  if (back == nullptr) {
78  back = new EggScalarTablePointer(egg_object);
79  set_model(model_index, back);
80  }
81 
82  } else {
83  nout << "Invalid object added to slider for back pointer.\n";
84  }
85 }
86 
87 /**
88  *
89  */
90 void EggSliderData::
91 write(std::ostream &out, int indent_level) const {
92  indent(out, indent_level)
93  << "Slider " << get_name()
94  << " (models:";
95  int num_models = get_num_models();
96  for (int model_index = 0; model_index < num_models; model_index++) {
97  if (has_model(model_index)) {
98  out << " " << model_index;
99  }
100  }
101  out << ")\n";
102 }
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the base class of both EggJointData and EggSliderData.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:28
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
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:29
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This stores a pointer back to a <Vertex>, or to a particular pritimive like a <Polygon>,...