X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fvaluenode_blinecalctangent.cpp;h=74b4b57e5a12c5af27ef6c80ec51f4bcb79e0291;hb=47a979c060132d120dbc8160aa9ae2e8c9d900c0;hp=e8fc826cdd5177e8ba548476a138b6c456c51972;hpb=37600b4b217caa5e316984ec0b035c5e8f9698af;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp index e8fc826..74b4b57 100644 --- a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp @@ -1,12 +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 Chris Moore +** 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 @@ -58,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* @@ -85,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)); + const std::vector bline((*bline_)(t).get_list()); 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--; @@ -100,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(); } @@ -127,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 @@ -157,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