1 /* === S I N F G =========================================================== */
2 /*! \file valuenode_timedswap.cpp
3 ** \brief Template File
5 ** $Id: valuenode_timedswap.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
32 #include "valuenode_timedswap.h"
33 #include "valuenode_const.h"
39 /* === U S I N G =========================================================== */
43 using namespace sinfg;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 ValueNode_TimedSwap::ValueNode_TimedSwap(ValueBase::Type type):
54 LinkableValueNode(type)
56 set_before(ValueNode_Const::create(type));
57 set_after(ValueNode_Const::create(type));
58 set_swap_time_real(1.0);
59 set_swap_length_real(1.0);
65 ValueNode_TimedSwap::create(const ValueBase& x)
67 return new ValueNode_TimedSwap(x.get_type());
72 ValueNode_TimedSwap::create_new()const
74 return new ValueNode_TimedSwap(get_type());
78 sinfg::ValueNode_TimedSwap::~ValueNode_TimedSwap()
86 ValueNode_TimedSwap::set_before(const ValueNode::Handle &x)
88 if(!x || x->get_type()!=get_type()
89 && !PlaceholderValueNode::Handle::cast_dynamic(x))
98 ValueNode_TimedSwap::get_before()const
105 ValueNode_TimedSwap::set_after(const ValueNode::Handle &x)
107 if(!x || x->get_type()!=get_type()
108 && !PlaceholderValueNode::Handle::cast_dynamic(x))
117 ValueNode_TimedSwap::get_after()const
124 ValueNode_TimedSwap::set_swap_time_real(Time x)
126 set_swap_time(ValueNode_Const::create(x));
130 ValueNode_TimedSwap::set_swap_time(const ValueNode::Handle &x)
133 || !ValueBase(ValueBase::TYPE_TIME).same_as(x->get_type())
134 && !PlaceholderValueNode::Handle::cast_dynamic(x)
142 ValueNode_TimedSwap::get_swap_time()const
148 ValueNode_TimedSwap::set_swap_length_real(Time x)
150 set_swap_length(ValueNode_Const::create(x));
154 ValueNode_TimedSwap::set_swap_length(const ValueNode::Handle &x)
157 !ValueBase(ValueBase::TYPE_TIME).same_as(x->get_type())
158 && !PlaceholderValueNode::Handle::cast_dynamic(x)
167 ValueNode_TimedSwap::get_swap_length()const
175 sinfg::ValueNode_TimedSwap::operator()(Time t)const
177 Time swptime=(*swap_time)(t).get(Time());
178 Time swplength=(*swap_length)(t).get(Time());
183 if(t<=swptime && t>swptime-swplength)
185 Real amount=(swptime-t)/swplength;
186 // if amount==0.0, then we are after
187 // if amount==1.0, then we are before
191 case ValueBase::TYPE_REAL:
193 Real a=(*after)(t).get(Real());
194 Real b=(*before)(t).get(Real());
195 return (b-a)*amount+a;
197 case ValueBase::TYPE_VECTOR:
199 Vector a=(*after)(t).get(Vector());
200 Vector b=(*before)(t).get(Vector());
201 return (b-a)*amount+a;
203 case ValueBase::TYPE_ANGLE:
205 Angle a=(*after)(t).get(Angle());
206 Angle b=(*before)(t).get(Angle());
207 return (b-a)*amount+a;
209 case ValueBase::TYPE_COLOR:
211 Color a=(*after)(t).get(Color());
212 Color b=(*before)(t).get(Color());
213 // note: Shouldn't this use a straight blend?
214 return (b-a)*amount+a;
216 case ValueBase::TYPE_INTEGER:
218 float a=(float)(*after)(t).get(int());
219 float b=(float)(*before)(t).get(int());
220 return static_cast<int>((b-a)*amount+a+0.5f);
228 /*! \todo this should interpolate from
229 ** before to after over the period defined
237 ValueNode_TimedSwap::set_link_vfunc(int i,ValueNode::Handle x)
243 return set_before(x);
247 return set_swap_time(x);
249 return set_swap_length(x);
254 ValueNode::LooseHandle
255 ValueNode_TimedSwap::get_link_vfunc(int i)const
265 return get_swap_time();
267 return get_swap_length();
273 ValueNode_TimedSwap::link_count()const
279 ValueNode_TimedSwap::link_local_name(int i)const
289 return _("Swap Time");
291 return _("Swap Duration");
297 ValueNode_TimedSwap::link_name(int i)const
315 ValueNode_TimedSwap::get_link_index_from_name(const String &name)const
326 throw Exception::BadLinkName(name);
330 ValueNode_TimedSwap::get_name()const
336 ValueNode_TimedSwap::get_local_name()const
338 return _("Timed Swap");
342 ValueNode_TimedSwap::check_type(ValueBase::Type type)