Panda3D

nodePathLerps.cxx

00001 // Filename: nodePathLerps.cxx
00002 // Created by:  frang (01Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "nodePathLerps.h"
00016 
00017 TypeHandle PosLerpFunctor::_type_handle;
00018 TypeHandle HprLerpFunctor::_type_handle;
00019 TypeHandle ScaleLerpFunctor::_type_handle;
00020 TypeHandle ColorLerpFunctor::_type_handle;
00021 TypeHandle PosHprLerpFunctor::_type_handle;
00022 TypeHandle HprScaleLerpFunctor::_type_handle;
00023 TypeHandle PosHprScaleLerpFunctor::_type_handle;
00024 TypeHandle ColorScaleLerpFunctor::_type_handle;
00025 
00026 
00027 PosLerpFunctor::PosLerpFunctor(const PosLerpFunctor& c)
00028   : LPoint3fLerpFunctor(c), _node_path(c._node_path) {}
00029 
00030 PosLerpFunctor::~PosLerpFunctor()
00031 {
00032 }
00033 
00034 PosLerpFunctor& PosLerpFunctor::operator=(const PosLerpFunctor& c) {
00035   _node_path = c._node_path;
00036   LPoint3fLerpFunctor::operator=(c);
00037   return *this;
00038 }
00039 
00040 void PosLerpFunctor::operator()(float t) {
00041   if (_is_wrt)
00042     _node_path.set_pos(_wrt_path, interpolate(t));
00043   else
00044     _node_path.set_pos(interpolate(t));
00045 }
00046 
00047 HprLerpFunctor::HprLerpFunctor(const HprLerpFunctor& c)
00048   : LVecBase3fLerpFunctor(c), _node_path(c._node_path) {}
00049 
00050 void HprLerpFunctor::take_shortest() {
00051   // so long as these are actually degrees
00052   for (int i=0; i!=3; ++i)
00053     if (this->_diff_cache[i] < -180.)
00054       _start[i] -= 360.;
00055     else if (this->_diff_cache[i] > 180.)
00056       _start[i] += 360.;
00057   this->_diff_cache = this->_end - this->_start;
00058 }
00059 
00060 void HprLerpFunctor::take_longest() {
00061   // so long as these are actually degrees
00062   for (int i=0; i!=3; ++i)
00063     if ((this->_diff_cache[i] < 0.) && (this->_diff_cache[i] > -180.))
00064       _start[i] -= 360.;
00065     else if ((this->_diff_cache[i] >= 0.) && (this->_diff_cache[i] < 180))
00066       _start[i] += 360.;
00067   this->_diff_cache = this->_end - this->_start;
00068 }
00069 
00070 HprLerpFunctor::~HprLerpFunctor()
00071 {
00072 }
00073 
00074 HprLerpFunctor& HprLerpFunctor::operator=(const HprLerpFunctor& c) {
00075   _node_path = c._node_path;
00076   LVecBase3fLerpFunctor::operator=(c);
00077   return *this;
00078 }
00079 
00080 void HprLerpFunctor::operator()(float t) {
00081   if (_is_wrt)
00082     _node_path.set_hpr(_wrt_path, interpolate(t));
00083   else
00084     _node_path.set_hpr(interpolate(t));
00085 }
00086 
00087 ScaleLerpFunctor::ScaleLerpFunctor(const ScaleLerpFunctor& c)
00088   : LVecBase3fLerpFunctor(c), _node_path(c._node_path) {}
00089 
00090 ScaleLerpFunctor::~ScaleLerpFunctor()
00091 {
00092 }
00093 
00094 ScaleLerpFunctor& ScaleLerpFunctor::operator=(const ScaleLerpFunctor& c) {
00095   _node_path = c._node_path;
00096   LVecBase3fLerpFunctor::operator=(c);
00097   return *this;
00098 }
00099 
00100 void ScaleLerpFunctor::operator()(float t) {
00101   if (_is_wrt)
00102     _node_path.set_scale(_wrt_path, interpolate(t));
00103   else
00104     _node_path.set_scale(interpolate(t));
00105 }
00106 
00107 ColorLerpFunctor::ColorLerpFunctor(const ColorLerpFunctor& c)
00108   : LVecBase4fLerpFunctor(c), _node_path(c._node_path) {}
00109 
00110 ColorLerpFunctor::~ColorLerpFunctor()
00111 {
00112 }
00113 
00114 ColorLerpFunctor& ColorLerpFunctor::operator=(const ColorLerpFunctor& c) {
00115   _node_path = c._node_path;
00116   LVecBase4fLerpFunctor::operator=(c);
00117   return *this;
00118 }
00119 
00120 void ColorLerpFunctor::operator()(float t) {
00121         _node_path.set_color(interpolate(t));
00122 }
00123 
00124 
00125 PosHprLerpFunctor::PosHprLerpFunctor(const PosHprLerpFunctor& c)
00126   : LerpFunctor(c), _node_path(c._node_path) {}
00127 
00128 void PosHprLerpFunctor::take_shortest() {
00129   // so long as these are actually degrees
00130   for (int i=0; i!=3; ++i)
00131     if (this->_hdiff_cache[i] < -180.)
00132       _hstart[i] -= 360.;
00133     else if (this->_hdiff_cache[i] > 180.)
00134       _hstart[i] += 360.;
00135   this->_hdiff_cache = this->_hend - this->_hstart;
00136 }
00137 
00138 void PosHprLerpFunctor::take_longest() {
00139   // so long as these are actually degrees
00140   for (int i=0; i!=3; ++i)
00141     if ((this->_hdiff_cache[i] < 0.) && (this->_hdiff_cache[i] > -180.))
00142       _hstart[i] -= 360.;
00143     else if ((this->_hdiff_cache[i] >= 0.) && (this->_hdiff_cache[i] < 180))
00144       _hstart[i] += 360.;
00145   this->_hdiff_cache = this->_hend - this->_hstart;
00146 }
00147 
00148 PosHprLerpFunctor::~PosHprLerpFunctor()
00149 {
00150 }
00151 
00152 PosHprLerpFunctor& PosHprLerpFunctor::operator=(const PosHprLerpFunctor& c) {
00153   _node_path = c._node_path;
00154   _pstart = c._pstart;
00155   _pend = c._pend;
00156   _pdiff_cache = c._pdiff_cache;
00157   _hstart = c._hstart;
00158   _hend = c._hend;
00159   _hdiff_cache = c._hdiff_cache;
00160   LerpFunctor::operator=(c);
00161   return *this;
00162 }
00163 
00164 void PosHprLerpFunctor::operator()(float t) {
00165   LPoint3f p = ((t * _pdiff_cache) + _pstart);
00166   LVecBase3f h = ((t * _hdiff_cache) + _hstart);
00167   if (_is_wrt)
00168     _node_path.set_pos_hpr(_wrt_path, p, h);
00169   else
00170     _node_path.set_pos_hpr(p, h);
00171 }
00172 
00173 HprScaleLerpFunctor::HprScaleLerpFunctor(const HprScaleLerpFunctor& c)
00174   : LerpFunctor(c), _node_path(c._node_path) {}
00175 
00176 void HprScaleLerpFunctor::take_shortest() {
00177   // so long as these are actually degrees
00178   for (int i=0; i!=3; ++i)
00179     if (this->_hdiff_cache[i] < -180.)
00180       _hstart[i] -= 360.;
00181     else if (this->_hdiff_cache[i] > 180.)
00182       _hstart[i] += 360.;
00183   this->_hdiff_cache = this->_hend - this->_hstart;
00184 }
00185 
00186 void HprScaleLerpFunctor::take_longest() {
00187   // so long as these are actually degrees
00188   for (int i=0; i!=3; ++i)
00189     if ((this->_hdiff_cache[i] < 0.) && (this->_hdiff_cache[i] > -180.))
00190       _hstart[i] -= 360.;
00191     else if ((this->_hdiff_cache[i] >= 0.) && (this->_hdiff_cache[i] < 180))
00192       _hstart[i] += 360.;
00193   this->_hdiff_cache = this->_hend - this->_hstart;
00194 }
00195 
00196 HprScaleLerpFunctor::~HprScaleLerpFunctor()
00197 {
00198 }
00199 
00200 HprScaleLerpFunctor&
00201 HprScaleLerpFunctor::operator=(const HprScaleLerpFunctor& c) {
00202   _node_path = c._node_path;
00203   _hstart = c._hstart;
00204   _hend = c._hend;
00205   _hdiff_cache = c._hdiff_cache;
00206   _sstart = c._sstart;
00207   _send = c._send;
00208   _sdiff_cache = c._sdiff_cache;
00209   LerpFunctor::operator=(c);
00210   return *this;
00211 }
00212 
00213 void HprScaleLerpFunctor::operator()(float t) {
00214   LVecBase3f h = ((t * _hdiff_cache) + _hstart);
00215   LVecBase3f s = ((t * _sdiff_cache) + _sstart);
00216   if (_is_wrt)
00217     _node_path.set_hpr_scale(_wrt_path, h, s);
00218   else
00219     _node_path.set_hpr_scale(h, s);
00220 }
00221 
00222 PosHprScaleLerpFunctor::PosHprScaleLerpFunctor(const PosHprScaleLerpFunctor& c)
00223   : LerpFunctor(c), _node_path(c._node_path) {}
00224 
00225 void PosHprScaleLerpFunctor::take_shortest() {
00226   // so long as these are actually degrees
00227   for (int i=0; i!=3; ++i)
00228     if (this->_hdiff_cache[i] < -180.)
00229       _hstart[i] -= 360.;
00230     else if (this->_hdiff_cache[i] > 180.)
00231       _hstart[i] += 360.;
00232   this->_hdiff_cache = this->_hend - this->_hstart;
00233 }
00234 
00235 void PosHprScaleLerpFunctor::take_longest() {
00236   // so long as these are actually degrees
00237   for (int i=0; i!=3; ++i)
00238     if ((this->_hdiff_cache[i] < 0.) && (this->_hdiff_cache[i] > -180.))
00239       _hstart[i] -= 360.;
00240     else if ((this->_hdiff_cache[i] >= 0.) && (this->_hdiff_cache[i] < 180))
00241       _hstart[i] += 360.;
00242   this->_hdiff_cache = this->_hend - this->_hstart;
00243 }
00244 
00245 PosHprScaleLerpFunctor::~PosHprScaleLerpFunctor()
00246 {
00247 }
00248 
00249 PosHprScaleLerpFunctor&
00250 PosHprScaleLerpFunctor::operator=(const PosHprScaleLerpFunctor& c) {
00251   _node_path = c._node_path;
00252   _pstart = c._pstart;
00253   _pend = c._pend;
00254   _pdiff_cache = c._pdiff_cache;
00255   _hstart = c._hstart;
00256   _hend = c._hend;
00257   _hdiff_cache = c._hdiff_cache;
00258   _sstart = c._sstart;
00259   _send = c._send;
00260   _sdiff_cache = c._sdiff_cache;
00261   LerpFunctor::operator=(c);
00262   return *this;
00263 }
00264 
00265 void PosHprScaleLerpFunctor::operator()(float t) {
00266   LPoint3f p = ((t * _pdiff_cache) + _pstart);
00267   LVecBase3f h = ((t * _hdiff_cache) + _hstart);
00268   LVecBase3f s = ((t * _sdiff_cache) + _sstart);
00269   if (_is_wrt)
00270     _node_path.set_pos_hpr_scale(_wrt_path, p, h, s);
00271   else
00272     _node_path.set_pos_hpr_scale(p, h, s);
00273 }
00274 
00275 ColorScaleLerpFunctor::ColorScaleLerpFunctor(const ColorScaleLerpFunctor& c)
00276   : LVecBase4fLerpFunctor(c), _node_path(c._node_path) {}
00277 
00278 ColorScaleLerpFunctor::~ColorScaleLerpFunctor()
00279 {
00280 }
00281 
00282 ColorScaleLerpFunctor& ColorScaleLerpFunctor::operator=(const ColorScaleLerpFunctor& c) {
00283   _node_path = c._node_path;
00284   LVecBase4fLerpFunctor::operator=(c);
00285   return *this;
00286 }
00287 
00288 void ColorScaleLerpFunctor::operator()(float t) {
00289   _node_path.set_color_scale(interpolate(t));
00290 }
00291 
00292 
 All Classes Functions Variables Enumerations