X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fvaluenode_blinecalctangent.cpp;h=3a3c2cc209797ddde008cc78e3d6d5d287b80b1b;hb=ecff046513a5c0bd64db58b69fdd2fb42736bca7;hp=778fb429ad43a70c61b911792b2c90f521311a1c;hpb=1e9792b864c8565ac9d05796eb91fb03fb09a64d;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp index 778fb42..3a3c2cc 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,19 +58,22 @@ using namespace synfig; ValueNode_BLineCalcTangent::ValueNode_BLineCalcTangent(const ValueBase::Type &x): LinkableValueNode(x) { - if(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* ValueNode_BLineCalcTangent::create_new()const { - return new ValueNode_BLineCalcTangent(ValueBase::TYPE_VECTOR); + return new ValueNode_BLineCalcTangent(get_type()); } ValueNode_BLineCalcTangent* @@ -84,18 +88,30 @@ 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)); + if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS")) + printf("%s:%d operator()\n", __FILE__, __LINE__); + + 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--; - if (size < 1) return Vector(); + if (size < 1) + 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(); + } if (loop) { amount = amount - int(amount); @@ -120,11 +136,31 @@ ValueNode_BLineCalcTangent::operator()(Time t)const blinepoint0.get_tangent2(), blinepoint1.get_tangent1()); etl::derivative< etl::hermite > deriv(curve); -#ifdef ETL_FIXED_DERIVATIVE - return deriv(amount-from_vertex)*(0.5); -#else - return deriv(amount-from_vertex)*(-0.5); -#endif + switch (get_type()) + { + 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(); + } +} + +ValueBase +ValueNode_BLineCalcTangent::operator()(Time t)const +{ + Real amount((*amount_)(t).get(Real())); + return (*this)(t, amount); } String @@ -140,23 +176,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