|
JK2eA
|
00001 #pragma once 00002 00003 #include <vector> 00004 #include <utility> 00005 #include <algorithm> 00006 #include <Vector.h> 00007 00008 00009 #include "Controller.h" 00010 #include "ControllerPriorityMixerSlerp.h" 00011 00012 00020 template<class CntType> 00021 class CControllerPriorityMixerSlerp : public CControllerPriorityMixer<CntType, vec4> { 00022 protected: 00023 00024 00025 public: 00030 CControllerPriorityMixerSlerp(const std::string& name); 00034 virtual ~CControllerPriorityMixerSlerp(void); 00035 00042 virtual void Update(float dt); 00043 00044 CNTRL_CLASS_NAME(CControllerMixer); 00045 }; 00046 00047 template<class CntType> 00048 CControllerPriorityMixerSlerp<CntType>::CControllerPriorityMixerSlerp(const std::string& name) : CControllerPriorityMixer(name) 00049 { 00050 } 00051 00052 template<class CntType> 00053 CControllerPriorityMixerSlerp<CntType>::~CControllerPriorityMixerSlerp() 00054 { 00055 } 00056 00057 /* 00058 Inherited 00059 */ 00060 template<class CntType> 00061 void CControllerPriorityMixerSlerp<CntType>::Update(float dt) 00062 { 00063 float weight_remaining = 1.0f; // zbyvajici vaha, pokud nektery controller vypotrebuje vsechno (z 1.0f), na ostatni se jiz nedostane 00064 bool first = true; 00065 float curr_weight; 00066 00067 00068 for(size_t i = 0; i < m_controllers.size(); i++) { 00069 if(weight_remaining < 0.0f) break; 00070 00071 MIX_NODE& curr = m_controllers[i]; 00072 00073 // celkova vaha nesmi prekrocit 1 00074 if(weight_remaining - *curr.weight < 0.0f) { 00075 curr_weight = weight_remaining; 00076 } else { 00077 curr_weight = *curr.weight; 00078 } 00079 weight_remaining -= *curr.weight; 00080 // 00081 00082 if((*curr.weight) <= 0.0f) continue; 00083 00084 curr.controller->Update(dt); 00085 00086 if(first) { 00087 m_accumulated_param = (*curr.controller->GetParameter()) * (curr_weight); 00088 first = false; 00089 } else { 00090 m_accumulated_param.QuaternionSlerp(m_accumulated_param, *curr.controller->GetParameter(), curr_weight); 00091 } 00092 } 00093 if(!m_controllers.empty() && first == false) { 00094 *m_controllers[0].controller->GetParameter() = m_accumulated_param; 00095 } 00096 } 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107
1.8.0