00001 // Filename: eggJointNodePointer.cxx 00002 // Created by: drose (26Feb01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "eggJointNodePointer.h" 00020 00021 #include "dcast.h" 00022 #include "eggObject.h" 00023 #include "eggGroup.h" 00024 #include "pointerTo.h" 00025 00026 00027 TypeHandle EggJointNodePointer::_type_handle; 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: EggJointNodePointer::Constructor 00031 // Access: Public 00032 // Description: 00033 //////////////////////////////////////////////////////////////////// 00034 EggJointNodePointer:: 00035 EggJointNodePointer(EggObject *object) { 00036 _joint = DCAST(EggGroup, object); 00037 00038 if (_joint != (EggGroup *)NULL) { 00039 // Quietly insist that the joint has a transform, for neatness. If 00040 // it does not, give it the identity transform. 00041 if (!_joint->has_transform()) { 00042 _joint->set_transform(LMatrix4d::ident_mat()); 00043 } 00044 } 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: EggJointNodePointer::get_num_frames 00049 // Access: Public, Virtual 00050 // Description: Returns the number of frames of animation for this 00051 // particular joint. 00052 // 00053 // In the case of a EggJointNodePointer, which just 00054 // stores a pointer to a <Joint> entry for a character 00055 // model (not an animation table), there is always 00056 // exactly one frame: the rest pose. 00057 //////////////////////////////////////////////////////////////////// 00058 int EggJointNodePointer:: 00059 get_num_frames() const { 00060 return 1; 00061 } 00062 00063 //////////////////////////////////////////////////////////////////// 00064 // Function: EggJointNodePointer::get_frame 00065 // Access: Public, Virtual 00066 // Description: Returns the transform matrix corresponding to this 00067 // joint position in the nth frame. 00068 // 00069 // In the case of a EggJointNodePointer, which just 00070 // stores a pointer to a <Joint> entry for a character 00071 // model (not an animation table), there is always 00072 // exactly one frame: the rest pose. 00073 //////////////////////////////////////////////////////////////////// 00074 LMatrix4d EggJointNodePointer:: 00075 get_frame(int n) const { 00076 nassertr(n == 0, LMatrix4d::ident_mat()); 00077 return _joint->get_transform(); 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: EggJointNodePointer::set_frame 00082 // Access: Public, Virtual 00083 // Description: Sets the transform matrix corresponding to this 00084 // joint position in the nth frame. 00085 // 00086 // In the case of a EggJointNodePointer, which just 00087 // stores a pointer to a <Joint> entry for a character 00088 // model (not an animation table), there is always 00089 // exactly one frame: the rest pose. 00090 //////////////////////////////////////////////////////////////////// 00091 void EggJointNodePointer:: 00092 set_frame(int n, const LMatrix4d &mat) { 00093 nassertv(n == 0); 00094 _joint->set_transform(mat); 00095 } 00096 00097 //////////////////////////////////////////////////////////////////// 00098 // Function: EggJointNodePointer::add_rebuild_frame 00099 // Access: Public, Virtual 00100 // Description: Adds a new frame to the set of rebuild frames. See 00101 // begin_rebuild() and do_rebuild(). Returns true if 00102 // this is valid, false otherwise (e.g. adding multiple 00103 // frames to a static joint). 00104 //////////////////////////////////////////////////////////////////// 00105 bool EggJointNodePointer:: 00106 add_rebuild_frame(const LMatrix4d &mat) { 00107 if (!_rebuild_frames.empty()) { 00108 // Only one frame may be added to a <Joint>. 00109 return false; 00110 } 00111 return EggJointPointer::add_rebuild_frame(mat); 00112 } 00113 00114 //////////////////////////////////////////////////////////////////// 00115 // Function: EggJointNodePointer::do_rebuild 00116 // Access: Public, Virtual 00117 // Description: Rebuilds the entire table all at once, based on the 00118 // frames added by repeated calls to add_rebuild_frame() 00119 // since the last call to begin_rebuild(). 00120 // 00121 // Until do_rebuild() is called, the animation table is 00122 // not changed. 00123 // 00124 // The return value is true if all frames are 00125 // acceptable, or false if there is some problem. 00126 //////////////////////////////////////////////////////////////////// 00127 bool EggJointNodePointer:: 00128 do_rebuild() { 00129 if (_rebuild_frames.empty()) { 00130 return true; 00131 } 00132 00133 if (_rebuild_frames.size() != 1) { 00134 return false; 00135 } 00136 00137 _joint->set_transform(_rebuild_frames[0]); 00138 _rebuild_frames.clear(); 00139 return true; 00140 }