00001 // Filename: sequenceNode.I 00002 // Created by: drose (06Mar02) 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 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: SequenceNode::CData::Constructor 00022 // Access: Public 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE SequenceNode::CData:: 00026 CData() { 00027 _cycle_rate = 0.0f; 00028 _frame_offset = 0.0f; 00029 _start_time = 0.0f; 00030 } 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Function: SequenceNode::CData::Copy Constructor 00034 // Access: Public 00035 // Description: 00036 //////////////////////////////////////////////////////////////////// 00037 INLINE SequenceNode::CData:: 00038 CData(const SequenceNode::CData ©) : 00039 _cycle_rate(copy._cycle_rate), 00040 _frame_offset(copy._frame_offset), 00041 _start_time(copy._start_time) 00042 { 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function: SequenceNode::Constructor 00047 // Access: Published 00048 // Description: 00049 //////////////////////////////////////////////////////////////////// 00050 INLINE SequenceNode:: 00051 SequenceNode(float cycle_rate, const string &name) : 00052 SelectiveChildNode(name) 00053 { 00054 CDWriter cdata(_cycler); 00055 cdata->_cycle_rate = cycle_rate; 00056 cdata->_frame_offset = 0.0f; 00057 00058 float now = ClockObject::get_global_clock()->get_frame_time(); 00059 cdata->_start_time = now; 00060 } 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: SequenceNode::set_cycle_rate 00064 // Access: Published 00065 // Description: Sets the rate of cycling for the children of the 00066 // SequenceNode, in cycles per second. 00067 //////////////////////////////////////////////////////////////////// 00068 INLINE void SequenceNode:: 00069 set_cycle_rate(float cycle_rate) { 00070 // Do some fussing so we keep the same frame visible while we 00071 // change this. 00072 CDWriter cdata(_cycler); 00073 float now = ClockObject::get_global_clock()->get_frame_time(); 00074 cdata->_frame_offset = calc_frame(now); 00075 cdata->_start_time = now; 00076 cdata->_cycle_rate = cycle_rate; 00077 } 00078 00079 //////////////////////////////////////////////////////////////////// 00080 // Function: SequenceNode::get_cycle_rate 00081 // Access: Published 00082 // Description: Returns the rate of cycling for the children of the 00083 // SequenceNode, in cycles per second. 00084 //////////////////////////////////////////////////////////////////// 00085 INLINE float SequenceNode:: 00086 get_cycle_rate() const { 00087 CDReader cdata(_cycler); 00088 return cdata->_cycle_rate; 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: SequenceNode::set_visible_child 00093 // Access: Published 00094 // Description: Sets the particular child that this SequenceNode will 00095 // display this frame. Future frames will proceed from 00096 // here. 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE void SequenceNode:: 00099 set_visible_child(int index) { 00100 int num_children = get_num_children(); 00101 if (num_children != 0) { 00102 CDWriter cdata(_cycler); 00103 float now = ClockObject::get_global_clock()->get_frame_time(); 00104 cdata->_frame_offset = (index - (now - cdata->_start_time) * cdata->_cycle_rate); 00105 } 00106 } 00107 00108 //////////////////////////////////////////////////////////////////// 00109 // Function: SequenceNode::calc_frame 00110 // Access: Private 00111 // Description: Returns the floating-point frame number at the 00112 // indicated time. 00113 //////////////////////////////////////////////////////////////////// 00114 INLINE float SequenceNode:: 00115 calc_frame(float now) const { 00116 CDReader cdata(_cycler); 00117 return (now - cdata->_start_time) * cdata->_cycle_rate + cdata->_frame_offset; 00118 } 00119 00120 //////////////////////////////////////////////////////////////////// 00121 // Function: SequenceNode::calc_frame 00122 // Access: Private 00123 // Description: Returns the floating-point frame number at the 00124 // current time. 00125 //////////////////////////////////////////////////////////////////// 00126 INLINE float SequenceNode:: 00127 calc_frame() const { 00128 return calc_frame(ClockObject::get_global_clock()->get_frame_time()); 00129 }