X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fvaluenode_blinecalctangent.cpp;h=67c1775aa17691c59b2ac0526d4824ffa3c753fc;hb=071939c9c44d0080e0843381adc19a6600f0fd69;hp=b7bf0d43a7c839367cd8e89217f1cdcc277ae80a;hpb=bfcc4388320d55a365d6bc427d58f47f359d2ac3;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp index b7bf0d4..67c1775 100644 --- a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp @@ -1,11 +1,12 @@ /* === S Y N F I G ========================================================= */ /*! \file valuenode_blinecalctangent.cpp -** \brief Template File +** \brief Implementation of the "BLine Tangent" valuenode conversion. ** ** $Id$ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007, 2008 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -57,13 +58,16 @@ using namespace synfig; ValueNode_BLineCalcTangent::ValueNode_BLineCalcTangent(const ValueBase::Type &x): LinkableValueNode(x) { - if(x!=ValueBase::TYPE_ANGLE && x!=ValueBase::TYPE_VECTOR) - throw Exception::BadType(ValueBase::type_name(x)); + if(x!=ValueBase::TYPE_ANGLE && x!=ValueBase::TYPE_REAL && x!=ValueBase::TYPE_VECTOR) + throw Exception::BadType(ValueBase::type_local_name(x)); ValueNode_BLine* value_node(new ValueNode_BLine()); set_link("bline",value_node); set_link("loop",ValueNode_Const::create(bool(false))); set_link("amount",ValueNode_Const::create(Real(0.5))); + set_link("offset",ValueNode_Const::create(Angle::deg(0))); + set_link("scale",ValueNode_Const::create(Real(1.0))); + set_link("fixed_length",ValueNode_Const::create(bool(false))); } LinkableValueNode* @@ -84,14 +88,16 @@ ValueNode_BLineCalcTangent::~ValueNode_BLineCalcTangent() } ValueBase -ValueNode_BLineCalcTangent::operator()(Time t)const +ValueNode_BLineCalcTangent::operator()(Time t, Real amount)const { const std::vector bline((*bline_)(t)); handle bline_value_node(bline_); const bool looped(bline_value_node->get_loop()); int size = bline.size(), from_vertex; bool loop((*loop_)(t).get(bool())); - Real amount((*amount_)(t).get(Real())); + Angle offset((*offset_)(t).get(Angle())); + Real scale((*scale_)(t).get(Real())); + bool fixed_length((*fixed_length_)(t).get(bool())); BLinePoint blinepoint0, blinepoint1; if (!looped) size--; @@ -99,6 +105,7 @@ ValueNode_BLineCalcTangent::operator()(Time t)const switch (get_type()) { case ValueBase::TYPE_ANGLE: return Angle(); + case ValueBase::TYPE_REAL: return Real(); case ValueBase::TYPE_VECTOR: return Vector(); default: assert(0); return ValueBase(); } @@ -126,21 +133,31 @@ ValueNode_BLineCalcTangent::operator()(Time t)const blinepoint0.get_tangent2(), blinepoint1.get_tangent1()); etl::derivative< etl::hermite > deriv(curve); -#ifdef ETL_FIXED_DERIVATIVE switch (get_type()) { - case ValueBase::TYPE_ANGLE: return (deriv(amount-from_vertex)*(0.5)).angle(); - case ValueBase::TYPE_VECTOR: return deriv(amount-from_vertex)*(0.5); - default: assert(0); return ValueBase(); - } -#else - switch (get_type()) - { - case ValueBase::TYPE_ANGLE: return (deriv(amount-from_vertex)*(-0.5)).angle(); - case ValueBase::TYPE_VECTOR: return deriv(amount-from_vertex)*(-0.5); + case ValueBase::TYPE_ANGLE: return deriv(amount-from_vertex).angle() + offset; + case ValueBase::TYPE_REAL: + { + if (fixed_length) return scale; + return deriv(amount-from_vertex).mag() * scale; + } + case ValueBase::TYPE_VECTOR: + { + Vector tangent(deriv(amount-from_vertex)); + Angle angle(tangent.angle() + offset); + Real mag = fixed_length ? scale : (tangent.mag() * scale); + return Vector(Angle::cos(angle).get()*mag, + Angle::sin(angle).get()*mag); + } default: assert(0); return ValueBase(); } -#endif +} + +ValueBase +ValueNode_BLineCalcTangent::operator()(Time t)const +{ + Real amount((*amount_)(t).get(Real())); + return (*this)(t, amount); } String @@ -156,23 +173,18 @@ ValueNode_BLineCalcTangent::get_local_name()const } bool -ValueNode_BLineCalcTangent::set_link_vfunc(int i,ValueNode::Handle x) +ValueNode_BLineCalcTangent::set_link_vfunc(int i,ValueNode::Handle value) { assert(i>=0 && i=0 && i=0 && i=0 && i